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.

204 lines
8.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_MOUSEINPUTSOURCE_H_INCLUDED
  18. #define JUCE_MOUSEINPUTSOURCE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Represents a linear source of mouse events from a mouse device or individual finger
  22. in a multi-touch environment.
  23. Each MouseEvent object contains a reference to the MouseInputSource that generated
  24. it. In an environment with a single mouse for input, all events will come from the
  25. same source, but in a multi-touch system, there may be multiple MouseInputSource
  26. obects active, each representing a stream of events coming from a particular finger.
  27. Events coming from a single MouseInputSource are always sent in a fixed and predictable
  28. order: a mouseMove will never be called without a mouseEnter having been sent beforehand,
  29. the only events that can happen between a mouseDown and its corresponding mouseUp are
  30. mouseDrags, etc.
  31. When there are multiple touches arriving from multiple MouseInputSources, their
  32. event streams may arrive in an interleaved order, so you should use the getIndex()
  33. method to find out which finger each event came from.
  34. @see MouseEvent
  35. */
  36. class JUCE_API MouseInputSource
  37. {
  38. public:
  39. //==============================================================================
  40. MouseInputSource (const MouseInputSource&) noexcept;
  41. MouseInputSource& operator= (const MouseInputSource&) noexcept;
  42. ~MouseInputSource() noexcept;
  43. //==============================================================================
  44. bool operator== (const MouseInputSource& other) const noexcept { return pimpl == other.pimpl; }
  45. bool operator!= (const MouseInputSource& other) const noexcept { return pimpl != other.pimpl; }
  46. //==============================================================================
  47. /** Returns true if this object represents a normal desk-based mouse device. */
  48. bool isMouse() const noexcept;
  49. /** Returns true if this object represents a source of touch events - i.e. a finger or stylus. */
  50. bool isTouch() const noexcept;
  51. /** Returns true if this source has an on-screen pointer that can hover over
  52. items without clicking them.
  53. */
  54. bool canHover() const noexcept;
  55. /** Returns true if this source may have a scroll wheel. */
  56. bool hasMouseWheel() const noexcept;
  57. /** Returns this source's index in the global list of possible sources.
  58. If the system only has a single mouse, there will only be a single MouseInputSource
  59. with an index of 0.
  60. If the system supports multi-touch input, then the index will represent a finger
  61. number, starting from 0. When the first touch event begins, it will have finger
  62. number 0, and then if a second touch happens while the first is still down, it
  63. will have index 1, etc.
  64. */
  65. int getIndex() const noexcept;
  66. /** Returns true if this device is currently being pressed. */
  67. bool isDragging() const noexcept;
  68. /** Returns the last-known screen position of this source. */
  69. Point<float> getScreenPosition() const noexcept;
  70. /** Returns a set of modifiers that indicate which buttons are currently
  71. held down on this device.
  72. */
  73. ModifierKeys getCurrentModifiers() const noexcept;
  74. /** Returns the device's current touch or pen pressure.
  75. The range is 0 (soft) to 1 (hard).
  76. If the input device doesn't provide any pressure data, it may return a negative
  77. value here, or 0.0 or 1.0, depending on the platform.
  78. */
  79. float getCurrentPressure() const noexcept;
  80. /** Returns true if the current pressure value is meaningful. */
  81. bool isPressureValid() const noexcept;
  82. /** Returns the component that was last known to be under this pointer. */
  83. Component* getComponentUnderMouse() const;
  84. /** Tells the device to dispatch a mouse-move or mouse-drag event.
  85. This is asynchronous - the event will occur on the message thread.
  86. */
  87. void triggerFakeMove() const;
  88. /** Returns the number of clicks that should be counted as belonging to the
  89. current mouse event.
  90. So the mouse is currently down and it's the second click of a double-click, this
  91. will return 2.
  92. */
  93. int getNumberOfMultipleClicks() const noexcept;
  94. /** Returns the time at which the last mouse-down occurred. */
  95. Time getLastMouseDownTime() const noexcept;
  96. /** Returns the screen position at which the last mouse-down occurred. */
  97. Point<float> getLastMouseDownPosition() const noexcept;
  98. /** Returns true if this mouse is currently down, and if it has been dragged more
  99. than a couple of pixels from the place it was pressed.
  100. */
  101. bool hasMouseMovedSignificantlySincePressed() const noexcept;
  102. /** Returns true if this input source uses a visible mouse cursor. */
  103. bool hasMouseCursor() const noexcept;
  104. /** Changes the mouse cursor, (if there is one). */
  105. void showMouseCursor (const MouseCursor& cursor);
  106. /** Hides the mouse cursor (if there is one). */
  107. void hideCursor();
  108. /** Un-hides the mouse cursor if it was hidden by hideCursor(). */
  109. void revealCursor();
  110. /** Forces an update of the mouse cursor for whatever component it's currently over. */
  111. void forceMouseCursorUpdate();
  112. /** Returns true if this mouse can be moved indefinitely in any direction without running out of space. */
  113. bool canDoUnboundedMovement() const noexcept;
  114. /** Allows the mouse to move beyond the edges of the screen.
  115. Calling this method when the mouse button is currently pressed will remove the cursor
  116. from the screen and allow the mouse to (seem to) move beyond the edges of the screen.
  117. This means that the coordinates returned to mouseDrag() will be unbounded, and this
  118. can be used for things like custom slider controls or dragging objects around, where
  119. movement would be otherwise be limited by the mouse hitting the edges of the screen.
  120. The unbounded mode is automatically turned off when the mouse button is released, or
  121. it can be turned off explicitly by calling this method again.
  122. @param isEnabled whether to turn this mode on or off
  123. @param keepCursorVisibleUntilOffscreen if set to false, the cursor will immediately be
  124. hidden; if true, it will only be hidden when it
  125. is moved beyond the edge of the screen
  126. */
  127. void enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen = false) const;
  128. /** Returns true if this source is currently in "unbounded" mode. */
  129. bool isUnboundedMouseMovementEnabled() const;
  130. /** Attempts to set this mouse pointer's screen position. */
  131. void setScreenPosition (Point<float> newPosition);
  132. /** A default value for pressure, which is used when a device doesn't support it, or for
  133. mouse-moves, mouse-ups, etc.
  134. */
  135. static const float invalidPressure;
  136. private:
  137. //==============================================================================
  138. friend class ComponentPeer;
  139. friend class Desktop;
  140. friend class MouseInputSourceInternal;
  141. MouseInputSourceInternal* pimpl;
  142. struct SourceList;
  143. explicit MouseInputSource (MouseInputSourceInternal*) noexcept;
  144. void handleEvent (ComponentPeer&, Point<float>, int64 time, ModifierKeys, float);
  145. void handleWheel (ComponentPeer&, Point<float>, int64 time, const MouseWheelDetails&);
  146. void handleMagnifyGesture (ComponentPeer&, Point<float>, int64 time, float scaleFactor);
  147. static Point<float> getCurrentRawMousePosition();
  148. static void setRawMousePosition (Point<float>);
  149. JUCE_LEAK_DETECTOR (MouseInputSource)
  150. };
  151. #endif // JUCE_MOUSEINPUTSOURCE_H_INCLUDED