The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

188 lines
7.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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_JUCEHEADER__
  18. #define __JUCE_MOUSEINPUTSOURCE_JUCEHEADER__
  19. #include "../keyboard/juce_ModifierKeys.h"
  20. #include "../components/juce_Desktop.h"
  21. class MouseInputSourceInternal;
  22. //==============================================================================
  23. /**
  24. Represents a linear source of mouse events from a mouse device or individual finger
  25. in a multi-touch environment.
  26. Each MouseEvent object contains a reference to the MouseInputSource that generated
  27. it. In an environment with a single mouse for input, all events will come from the
  28. same source, but in a multi-touch system, there may be multiple MouseInputSource
  29. obects active, each representing a stream of events coming from a particular finger.
  30. Events coming from a single MouseInputSource are always sent in a fixed and predictable
  31. order: a mouseMove will never be called without a mouseEnter having been sent beforehand,
  32. the only events that can happen between a mouseDown and its corresponding mouseUp are
  33. mouseDrags, etc.
  34. When there are multiple touches arriving from multiple MouseInputSources, their
  35. event streams may arrive in an interleaved order, so you should use the getIndex()
  36. method to find out which finger each event came from.
  37. @see MouseEvent
  38. */
  39. class JUCE_API MouseInputSource
  40. {
  41. public:
  42. //==============================================================================
  43. /** Creates a MouseInputSource.
  44. You should never actually create a MouseInputSource in your own code - the
  45. library takes care of managing these objects.
  46. */
  47. MouseInputSource (int index, bool isMouseDevice);
  48. /** Destructor. */
  49. ~MouseInputSource();
  50. //==============================================================================
  51. /** Returns true if this object represents a normal desk-based mouse device. */
  52. bool isMouse() const;
  53. /** Returns true if this object represents a source of touch events - i.e. a finger or stylus. */
  54. bool isTouch() const;
  55. /** Returns true if this source has an on-screen pointer that can hover over
  56. items without clicking them.
  57. */
  58. bool canHover() const;
  59. /** Returns true if this source may have a scroll wheel. */
  60. bool hasMouseWheel() const;
  61. /** Returns this source's index in the global list of possible sources.
  62. If the system only has a single mouse, there will only be a single MouseInputSource
  63. with an index of 0.
  64. If the system supports multi-touch input, then the index will represent a finger
  65. number, starting from 0. When the first touch event begins, it will have finger
  66. number 0, and then if a second touch happens while the first is still down, it
  67. will have index 1, etc.
  68. */
  69. int getIndex() const;
  70. /** Returns true if this device is currently being pressed. */
  71. bool isDragging() const;
  72. /** Returns the last-known screen position of this source. */
  73. Point<int> getScreenPosition() const;
  74. /** Returns a set of modifiers that indicate which buttons are currently
  75. held down on this device.
  76. */
  77. ModifierKeys getCurrentModifiers() const;
  78. /** Returns the component that was last known to be under this pointer. */
  79. Component* getComponentUnderMouse() const;
  80. /** Tells the device to dispatch a mouse-move or mouse-drag event.
  81. This is asynchronous - the event will occur on the message thread.
  82. */
  83. void triggerFakeMove() const;
  84. /** Returns the number of clicks that should be counted as belonging to the
  85. current mouse event.
  86. So the mouse is currently down and it's the second click of a double-click, this
  87. will return 2.
  88. */
  89. int getNumberOfMultipleClicks() const noexcept;
  90. /** Returns the time at which the last mouse-down occurred. */
  91. Time getLastMouseDownTime() const noexcept;
  92. /** Returns the screen position at which the last mouse-down occurred. */
  93. Point<int> getLastMouseDownPosition() const noexcept;
  94. /** Returns true if this mouse is currently down, and if it has been dragged more
  95. than a couple of pixels from the place it was pressed.
  96. */
  97. bool hasMouseMovedSignificantlySincePressed() const noexcept;
  98. /** Returns true if this input source uses a visible mouse cursor. */
  99. bool hasMouseCursor() const noexcept;
  100. /** Changes the mouse cursor, (if there is one). */
  101. void showMouseCursor (const MouseCursor& cursor);
  102. /** Hides the mouse cursor (if there is one). */
  103. void hideCursor();
  104. /** Un-hides the mouse cursor if it was hidden by hideCursor(). */
  105. void revealCursor();
  106. /** Forces an update of the mouse cursor for whatever component it's currently over. */
  107. void forceMouseCursorUpdate();
  108. /** Returns true if this mouse can be moved indefinitely in any direction without running out of space. */
  109. bool canDoUnboundedMovement() const noexcept;
  110. /** Allows the mouse to move beyond the edges of the screen.
  111. Calling this method when the mouse button is currently pressed will remove the cursor
  112. from the screen and allow the mouse to (seem to) move beyond the edges of the screen.
  113. This means that the co-ordinates returned to mouseDrag() will be unbounded, and this
  114. can be used for things like custom slider controls or dragging objects around, where
  115. movement would be otherwise be limited by the mouse hitting the edges of the screen.
  116. The unbounded mode is automatically turned off when the mouse button is released, or
  117. it can be turned off explicitly by calling this method again.
  118. @param isEnabled whether to turn this mode on or off
  119. @param keepCursorVisibleUntilOffscreen if set to false, the cursor will immediately be
  120. hidden; if true, it will only be hidden when it
  121. is moved beyond the edge of the screen
  122. */
  123. void enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen = false);
  124. //==============================================================================
  125. /** @internal */
  126. void handleEvent (ComponentPeer*, Point<int>, int64 time, const ModifierKeys);
  127. /** @internal */
  128. void handleWheel (ComponentPeer*, Point<int>, int64 time, const MouseWheelDetails&);
  129. /** @internal */
  130. void handleMagnifyGesture (ComponentPeer*, Point<int>, int64 time, float scaleFactor);
  131. private:
  132. //==============================================================================
  133. friend class Desktop;
  134. friend class ComponentPeer;
  135. friend class MouseInputSourceInternal;
  136. ScopedPointer<MouseInputSourceInternal> pimpl;
  137. static Point<int> getCurrentMousePosition();
  138. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MouseInputSource)
  139. };
  140. #endif // __JUCE_MOUSEINPUTSOURCE_JUCEHEADER__