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.

187 lines
8.0KB

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