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.

juce_MouseInputSource.h 8.2KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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_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;
  49. /** Returns true if this object represents a source of touch events - i.e. a finger or stylus. */
  50. bool isTouch() const;
  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;
  55. /** Returns true if this source may have a scroll wheel. */
  56. bool hasMouseWheel() const;
  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;
  66. /** Returns true if this device is currently being pressed. */
  67. bool isDragging() const;
  68. /** Returns the last-known screen position of this source. */
  69. Point<float> getScreenPosition() const;
  70. /** Returns a set of modifiers that indicate which buttons are currently
  71. held down on this device.
  72. */
  73. ModifierKeys getCurrentModifiers() const;
  74. /** Returns the component that was last known to be under this pointer. */
  75. Component* getComponentUnderMouse() const;
  76. /** Tells the device to dispatch a mouse-move or mouse-drag event.
  77. This is asynchronous - the event will occur on the message thread.
  78. */
  79. void triggerFakeMove() const;
  80. /** Returns the number of clicks that should be counted as belonging to the
  81. current mouse event.
  82. So the mouse is currently down and it's the second click of a double-click, this
  83. will return 2.
  84. */
  85. int getNumberOfMultipleClicks() const noexcept;
  86. /** Returns the time at which the last mouse-down occurred. */
  87. Time getLastMouseDownTime() const noexcept;
  88. /** Returns the screen position at which the last mouse-down occurred. */
  89. Point<float> getLastMouseDownPosition() const noexcept;
  90. /** Returns true if this mouse is currently down, and if it has been dragged more
  91. than a couple of pixels from the place it was pressed.
  92. */
  93. bool hasMouseMovedSignificantlySincePressed() const noexcept;
  94. /** Returns true if this input source uses a visible mouse cursor. */
  95. bool hasMouseCursor() const noexcept;
  96. /** Changes the mouse cursor, (if there is one). */
  97. void showMouseCursor (const MouseCursor& cursor);
  98. /** Hides the mouse cursor (if there is one). */
  99. void hideCursor();
  100. /** Un-hides the mouse cursor if it was hidden by hideCursor(). */
  101. void revealCursor();
  102. /** Forces an update of the mouse cursor for whatever component it's currently over. */
  103. void forceMouseCursorUpdate();
  104. /** Returns true if this mouse can be moved indefinitely in any direction without running out of space. */
  105. bool canDoUnboundedMovement() const noexcept;
  106. /** Allows the mouse to move beyond the edges of the screen.
  107. Calling this method when the mouse button is currently pressed will remove the cursor
  108. from the screen and allow the mouse to (seem to) move beyond the edges of the screen.
  109. This means that the coordinates returned to mouseDrag() will be unbounded, and this
  110. can be used for things like custom slider controls or dragging objects around, where
  111. movement would be otherwise be limited by the mouse hitting the edges of the screen.
  112. The unbounded mode is automatically turned off when the mouse button is released, or
  113. it can be turned off explicitly by calling this method again.
  114. @param isEnabled whether to turn this mode on or off
  115. @param keepCursorVisibleUntilOffscreen if set to false, the cursor will immediately be
  116. hidden; if true, it will only be hidden when it
  117. is moved beyond the edge of the screen
  118. */
  119. void enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen = false) const;
  120. /** Returns true if this source is currently in "unbounded" mode. */
  121. bool isUnboundedMouseMovementEnabled() const;
  122. /** Attempts to set this mouse pointer's screen position. */
  123. void setScreenPosition (Point<float> newPosition);
  124. private:
  125. //==============================================================================
  126. friend class ComponentPeer;
  127. friend class Desktop;
  128. friend class MouseInputSourceInternal;
  129. MouseInputSourceInternal* pimpl;
  130. struct SourceList;
  131. explicit MouseInputSource (MouseInputSourceInternal*) noexcept;
  132. void handleEvent (ComponentPeer&, Point<float>, int64 time, ModifierKeys);
  133. void handleWheel (ComponentPeer&, Point<float>, int64 time, const MouseWheelDetails&);
  134. void handleMagnifyGesture (ComponentPeer&, Point<float>, int64 time, float scaleFactor);
  135. static Point<float> getCurrentRawMousePosition();
  136. static void setRawMousePosition (Point<float>);
  137. JUCE_LEAK_DETECTOR (MouseInputSource)
  138. };
  139. #endif // JUCE_MOUSEINPUTSOURCE_H_INCLUDED