Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

257 lines
11KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. Represents a linear source of mouse events from a mouse device or individual finger
  24. in a multi-touch environment.
  25. Each MouseEvent object contains a reference to the MouseInputSource that generated
  26. it. In an environment with a single mouse for input, all events will come from the
  27. same source, but in a multi-touch system, there may be multiple MouseInputSource
  28. obects active, each representing a stream of events coming from a particular finger.
  29. Events coming from a single MouseInputSource are always sent in a fixed and predictable
  30. order: a mouseMove will never be called without a mouseEnter having been sent beforehand,
  31. the only events that can happen between a mouseDown and its corresponding mouseUp are
  32. mouseDrags, etc.
  33. When there are multiple touches arriving from multiple MouseInputSources, their
  34. event streams may arrive in an interleaved order, so you should use the getIndex()
  35. method to find out which finger each event came from.
  36. @see MouseEvent
  37. */
  38. class JUCE_API MouseInputSource
  39. {
  40. public:
  41. /** Possible mouse input sources. */
  42. enum InputSourceType
  43. {
  44. mouse,
  45. touch,
  46. pen
  47. };
  48. //==============================================================================
  49. MouseInputSource (const MouseInputSource&) noexcept;
  50. MouseInputSource& operator= (const MouseInputSource&) noexcept;
  51. ~MouseInputSource() noexcept;
  52. //==============================================================================
  53. bool operator== (const MouseInputSource& other) const noexcept { return pimpl == other.pimpl; }
  54. bool operator!= (const MouseInputSource& other) const noexcept { return pimpl != other.pimpl; }
  55. //==============================================================================
  56. /** Returns the type of input source that this object represents. */
  57. MouseInputSource::InputSourceType getType() const noexcept;
  58. /** Returns true if this object represents a normal desk-based mouse device. */
  59. bool isMouse() const noexcept;
  60. /** Returns true if this object represents a source of touch events. */
  61. bool isTouch() const noexcept;
  62. /** Returns true if this object represents a pen device. */
  63. bool isPen() const noexcept;
  64. /** Returns true if this source has an on-screen pointer that can hover over
  65. items without clicking them.
  66. */
  67. bool canHover() const noexcept;
  68. /** Returns true if this source may have a scroll wheel. */
  69. bool hasMouseWheel() const noexcept;
  70. /** Returns this source's index in the global list of possible sources.
  71. If the system only has a single mouse, there will only be a single MouseInputSource
  72. with an index of 0.
  73. If the system supports multi-touch input, then the index will represent a finger
  74. number, starting from 0. When the first touch event begins, it will have finger
  75. number 0, and then if a second touch happens while the first is still down, it
  76. will have index 1, etc.
  77. */
  78. int getIndex() const noexcept;
  79. /** Returns true if this device is currently being pressed. */
  80. bool isDragging() const noexcept;
  81. /** Returns the last-known screen position of this source. */
  82. Point<float> getScreenPosition() const noexcept;
  83. /** Returns the last-known screen position of this source without any scaling applied. */
  84. Point<float> getRawScreenPosition() const noexcept;
  85. /** Returns a set of modifiers that indicate which buttons are currently
  86. held down on this device.
  87. */
  88. ModifierKeys getCurrentModifiers() const noexcept;
  89. /** Returns the device's current touch or pen pressure.
  90. The range is 0 (soft) to 1 (hard).
  91. If the input device doesn't provide any pressure data, it may return a negative
  92. value here, or 0.0 or 1.0, depending on the platform.
  93. */
  94. float getCurrentPressure() const noexcept;
  95. /** Returns the device's current orientation in radians. 0 indicates a touch pointer
  96. aligned with the x-axis and pointing from left to right; increasing values indicate
  97. rotation in the clockwise direction. Only reported by a touch pointer.
  98. */
  99. float getCurrentOrientation() const noexcept;
  100. /** Returns the device's current rotation. Indicates the clockwise rotation, or twist, of the pointer
  101. in radians. The default is 0. Only reported by a pen pointer.
  102. */
  103. float getCurrentRotation() const noexcept;
  104. /** Returns the angle of tilt of the pointer in a range of -1.0 to 1.0 either in the x- or y-axis. The default is 0.
  105. If x-axis, a positive value indicates a tilt to the right and if y-axis, a positive value indicates a tilt toward the user.
  106. Only reported by a pen pointer.
  107. */
  108. float getCurrentTilt (bool tiltX) const noexcept;
  109. /** Returns true if the current pressure value is meaningful. */
  110. bool isPressureValid() const noexcept;
  111. /** Returns true if the current orientation value is meaningful. */
  112. bool isOrientationValid() const noexcept;
  113. /** Returns true if the current rotation value is meaningful. */
  114. bool isRotationValid() const noexcept;
  115. /** Returns true if the current tilt value (either x- or y-axis) is meaningful. */
  116. bool isTiltValid (bool tiltX) const noexcept;
  117. /** Returns the component that was last known to be under this pointer. */
  118. Component* getComponentUnderMouse() const;
  119. /** Tells the device to dispatch a mouse-move or mouse-drag event.
  120. This is asynchronous - the event will occur on the message thread.
  121. */
  122. void triggerFakeMove() const;
  123. /** Returns the number of clicks that should be counted as belonging to the
  124. current mouse event.
  125. So the mouse is currently down and it's the second click of a double-click, this
  126. will return 2.
  127. */
  128. int getNumberOfMultipleClicks() const noexcept;
  129. /** Returns the time at which the last mouse-down occurred. */
  130. Time getLastMouseDownTime() const noexcept;
  131. /** Returns the screen position at which the last mouse-down occurred. */
  132. Point<float> getLastMouseDownPosition() const noexcept;
  133. /** Returns true if this mouse is currently down, and if it has been dragged more
  134. than a couple of pixels from the place it was pressed.
  135. */
  136. bool hasMouseMovedSignificantlySincePressed() const noexcept;
  137. /** Returns true if this input source uses a visible mouse cursor. */
  138. bool hasMouseCursor() const noexcept;
  139. /** Changes the mouse cursor, (if there is one). */
  140. void showMouseCursor (const MouseCursor& cursor);
  141. /** Hides the mouse cursor (if there is one). */
  142. void hideCursor();
  143. /** Un-hides the mouse cursor if it was hidden by hideCursor(). */
  144. void revealCursor();
  145. /** Forces an update of the mouse cursor for whatever component it's currently over. */
  146. void forceMouseCursorUpdate();
  147. /** Returns true if this mouse can be moved indefinitely in any direction without running out of space. */
  148. bool canDoUnboundedMovement() const noexcept;
  149. /** Allows the mouse to move beyond the edges of the screen.
  150. Calling this method when the mouse button is currently pressed will remove the cursor
  151. from the screen and allow the mouse to (seem to) move beyond the edges of the screen.
  152. This means that the coordinates returned to mouseDrag() will be unbounded, and this
  153. can be used for things like custom slider controls or dragging objects around, where
  154. movement would be otherwise be limited by the mouse hitting the edges of the screen.
  155. The unbounded mode is automatically turned off when the mouse button is released, or
  156. it can be turned off explicitly by calling this method again.
  157. @param isEnabled whether to turn this mode on or off
  158. @param keepCursorVisibleUntilOffscreen if set to false, the cursor will immediately be
  159. hidden; if true, it will only be hidden when it
  160. is moved beyond the edge of the screen
  161. */
  162. void enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen = false) const;
  163. /** Returns true if this source is currently in "unbounded" mode. */
  164. bool isUnboundedMouseMovementEnabled() const;
  165. /** Attempts to set this mouse pointer's screen position. */
  166. void setScreenPosition (Point<float> newPosition);
  167. /** A default value for pressure, which is used when a device doesn't support it, or for
  168. mouse-moves, mouse-ups, etc.
  169. */
  170. static const float invalidPressure;
  171. /** A default value for orientation, which is used when a device doesn't support it */
  172. static const float invalidOrientation;
  173. /** A default value for rotation, which is used when a device doesn't support it */
  174. static const float invalidRotation;
  175. /** Default values for tilt, which are used when a device doesn't support it */
  176. static const float invalidTiltX;
  177. static const float invalidTiltY;
  178. private:
  179. //==============================================================================
  180. friend class ComponentPeer;
  181. friend class Desktop;
  182. friend class MouseInputSourceInternal;
  183. MouseInputSourceInternal* pimpl;
  184. struct SourceList;
  185. explicit MouseInputSource (MouseInputSourceInternal*) noexcept;
  186. void handleEvent (ComponentPeer&, Point<float>, int64 time, ModifierKeys, float, float, const PenDetails&);
  187. void handleWheel (ComponentPeer&, Point<float>, int64 time, const MouseWheelDetails&);
  188. void handleMagnifyGesture (ComponentPeer&, Point<float>, int64 time, float scaleFactor);
  189. static Point<float> getCurrentRawMousePosition();
  190. static void setRawMousePosition (Point<float>);
  191. JUCE_LEAK_DETECTOR (MouseInputSource)
  192. };
  193. } // namespace juce