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.

454 lines
19KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. Contains position and status information about a mouse event.
  23. @see MouseListener, Component::mouseMove, Component::mouseEnter, Component::mouseExit,
  24. Component::mouseDown, Component::mouseUp, Component::mouseDrag
  25. @tags{GUI}
  26. */
  27. class JUCE_API MouseEvent final
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a MouseEvent.
  32. Normally an application will never need to use this.
  33. @param source the source that's invoking the event
  34. @param position the position of the mouse, relative to the component that is passed-in
  35. @param modifiers the key modifiers at the time of the event
  36. @param pressure the pressure of the touch or stylus, in the range 0 to 1. Devices that
  37. do not support force information may return 0.0, 1.0, or a negative value,
  38. depending on the platform
  39. @param orientation the orientation of the touch input for this event in radians. The default is 0
  40. @param rotation the rotation of the pen device for this event in radians. The default is 0
  41. @param tiltX the tilt of the pen device along the x-axis between -1.0 and 1.0. The default is 0
  42. @param tiltY the tilt of the pen device along the y-axis between -1.0 and 1.0. The default is 0
  43. @param eventComponent the component that the mouse event applies to
  44. @param originator the component that originally received the event
  45. @param eventTime the time the event happened
  46. @param mouseDownPos the position of the corresponding mouse-down event (relative to the component that is passed-in).
  47. If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be
  48. the same as the current mouse-x position.
  49. @param mouseDownTime the time at which the corresponding mouse-down event happened
  50. If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be
  51. the same as the current mouse-event time.
  52. @param numberOfClicks how many clicks, e.g. a double-click event will be 2, a triple-click will be 3, etc
  53. @param mouseWasDragged whether the mouse has been dragged significantly since the previous mouse-down
  54. */
  55. MouseEvent (MouseInputSource source,
  56. Point<float> position,
  57. ModifierKeys modifiers,
  58. float pressure,
  59. float orientation, float rotation,
  60. float tiltX, float tiltY,
  61. Component* eventComponent,
  62. Component* originator,
  63. Time eventTime,
  64. Point<float> mouseDownPos,
  65. Time mouseDownTime,
  66. int numberOfClicks,
  67. bool mouseWasDragged) noexcept;
  68. /** Destructor. */
  69. ~MouseEvent() noexcept;
  70. //==============================================================================
  71. /** The position of the mouse when the event occurred.
  72. This value is relative to the top-left of the component to which the
  73. event applies (as indicated by the MouseEvent::eventComponent field).
  74. This is a more accurate floating-point version of the position returned by
  75. getPosition() and the integer x and y member variables.
  76. */
  77. const Point<float> position;
  78. /** The x-position of the mouse when the event occurred.
  79. This value is relative to the top-left of the component to which the
  80. event applies (as indicated by the MouseEvent::eventComponent field).
  81. For a floating-point coordinate, see MouseEvent::position
  82. */
  83. const int x;
  84. /** The y-position of the mouse when the event occurred.
  85. This value is relative to the top-left of the component to which the
  86. event applies (as indicated by the MouseEvent::eventComponent field).
  87. For a floating-point coordinate, see MouseEvent::position
  88. */
  89. const int y;
  90. /** The key modifiers associated with the event.
  91. This will let you find out which mouse buttons were down, as well as which
  92. modifier keys were held down.
  93. When used for mouse-up events, this will indicate the state of the mouse buttons
  94. just before they were released, so that you can tell which button they let go of.
  95. */
  96. const ModifierKeys mods;
  97. /** The pressure of the touch or stylus for this event.
  98. The range is 0 (soft) to 1 (hard).
  99. If the input device doesn't provide any pressure data, it may return a negative
  100. value here, or 0.0 or 1.0, depending on the platform.
  101. */
  102. const float pressure;
  103. /** The orientation of the touch input for this event in radians where 0 indicates a touch aligned with the x-axis
  104. and pointing from left to right; increasing values indicate rotation in the clockwise direction. The default is 0.
  105. */
  106. const float orientation;
  107. /** The rotation of the pen device for this event in radians. Indicates the clockwise
  108. rotation, or twist, of the pen. The default is 0.
  109. */
  110. const float rotation;
  111. /** The tilt of the pen device along the x-axis between -1.0 and 1.0. A positive value indicates
  112. a tilt to the right. The default is 0.
  113. */
  114. const float tiltX;
  115. /** The tilt of the pen device along the y-axis between -1.0 and 1.0. A positive value indicates
  116. a tilt toward the user. The default is 0.
  117. */
  118. const float tiltY;
  119. /** The coordinates of the last place that a mouse button was pressed.
  120. The coordinates are relative to the component specified in MouseEvent::component.
  121. @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
  122. */
  123. const Point<float> mouseDownPosition;
  124. /** The component that this event applies to.
  125. This is usually the component that the mouse was over at the time, but for mouse-drag
  126. events the mouse could actually be over a different component and the events are
  127. still sent to the component that the button was originally pressed on.
  128. The x and y member variables are relative to this component's position.
  129. If you use getEventRelativeTo() to retarget this object to be relative to a different
  130. component, this pointer will be updated, but originalComponent remains unchanged.
  131. @see originalComponent
  132. */
  133. Component* const eventComponent;
  134. /** The component that the event first occurred on.
  135. If you use getEventRelativeTo() to retarget this object to be relative to a different
  136. component, this value remains unchanged to indicate the first component that received it.
  137. @see eventComponent
  138. */
  139. Component* const originalComponent;
  140. /** The time that this mouse-event occurred. */
  141. const Time eventTime;
  142. /** The time that the corresponding mouse-down event occurred. */
  143. const Time mouseDownTime;
  144. /** The source device that generated this event. */
  145. MouseInputSource source;
  146. //==============================================================================
  147. /** Returns the x coordinate of the last place that a mouse was pressed.
  148. The coordinate is relative to the component specified in MouseEvent::component.
  149. @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
  150. */
  151. int getMouseDownX() const noexcept;
  152. /** Returns the y coordinate of the last place that a mouse was pressed.
  153. The coordinate is relative to the component specified in MouseEvent::component.
  154. @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
  155. */
  156. int getMouseDownY() const noexcept;
  157. /** Returns the coordinates of the last place that a mouse was pressed.
  158. The coordinates are relative to the component specified in MouseEvent::component.
  159. For a floating point version of this value, see mouseDownPosition.
  160. @see mouseDownPosition, getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
  161. */
  162. Point<int> getMouseDownPosition() const noexcept;
  163. /** Returns the straight-line distance between where the mouse is now and where it
  164. was the last time the button was pressed.
  165. This is quite handy for things like deciding whether the user has moved far enough
  166. for it to be considered a drag operation.
  167. @see getDistanceFromDragStartX
  168. */
  169. int getDistanceFromDragStart() const noexcept;
  170. /** Returns the difference between the mouse's current x position and where it was
  171. when the button was last pressed.
  172. @see getDistanceFromDragStart
  173. */
  174. int getDistanceFromDragStartX() const noexcept;
  175. /** Returns the difference between the mouse's current y position and where it was
  176. when the button was last pressed.
  177. @see getDistanceFromDragStart
  178. */
  179. int getDistanceFromDragStartY() const noexcept;
  180. /** Returns the difference between the mouse's current position and where it was
  181. when the button was last pressed.
  182. @see getDistanceFromDragStart
  183. */
  184. Point<int> getOffsetFromDragStart() const noexcept;
  185. /** Returns true if the user seems to be performing a drag gesture.
  186. This is only meaningful if called in either a mouseUp() or mouseDrag() method.
  187. It will return true if the user has dragged the mouse more than a few pixels from the place
  188. where the mouse-down occurred or the mouse has been held down for a significant amount of time.
  189. Once they have dragged it far enough for this method to return true, it will continue
  190. to return true until the mouse-up, even if they move the mouse back to the same
  191. location at which the mouse-down happened. This means that it's very handy for
  192. objects that can either be clicked on or dragged, as you can use it in the mouseDrag()
  193. callback to ignore small movements they might make while trying to click.
  194. */
  195. bool mouseWasDraggedSinceMouseDown() const noexcept;
  196. /** Returns true if the mouse event is part of a click gesture rather than a drag.
  197. This is effectively the opposite of mouseWasDraggedSinceMouseDown()
  198. */
  199. bool mouseWasClicked() const noexcept;
  200. /** For a click event, the number of times the mouse was clicked in succession.
  201. So for example a double-click event will return 2, a triple-click 3, etc.
  202. */
  203. int getNumberOfClicks() const noexcept { return numberOfClicks; }
  204. /** Returns the time that the mouse button has been held down for.
  205. If called from a mouseDrag or mouseUp callback, this will return the
  206. number of milliseconds since the corresponding mouseDown event occurred.
  207. If called in other contexts, e.g. a mouseMove, then the returned value
  208. may be 0 or an undefined value.
  209. */
  210. int getLengthOfMousePress() const noexcept;
  211. /** Returns true if the pressure value for this event is meaningful. */
  212. bool isPressureValid() const noexcept;
  213. /** Returns true if the orientation value for this event is meaningful. */
  214. bool isOrientationValid() const noexcept;
  215. /** Returns true if the rotation value for this event is meaningful. */
  216. bool isRotationValid() const noexcept;
  217. /** Returns true if the current tilt value (either x- or y-axis) is meaningful. */
  218. bool isTiltValid (bool tiltX) const noexcept;
  219. //==============================================================================
  220. /** The position of the mouse when the event occurred.
  221. This position is relative to the top-left of the component to which the
  222. event applies (as indicated by the MouseEvent::eventComponent field).
  223. For a floating-point position, see MouseEvent::position
  224. */
  225. Point<int> getPosition() const noexcept;
  226. /** Returns the mouse x position of this event, in global screen coordinates.
  227. The coordinates are relative to the top-left of the main monitor.
  228. @see getScreenPosition
  229. */
  230. int getScreenX() const;
  231. /** Returns the mouse y position of this event, in global screen coordinates.
  232. The coordinates are relative to the top-left of the main monitor.
  233. @see getScreenPosition
  234. */
  235. int getScreenY() const;
  236. /** Returns the mouse position of this event, in global screen coordinates.
  237. The coordinates are relative to the top-left of the main monitor.
  238. @see getMouseDownScreenPosition
  239. */
  240. Point<int> getScreenPosition() const;
  241. /** Returns the x coordinate at which the mouse button was last pressed.
  242. The coordinates are relative to the top-left of the main monitor.
  243. @see getMouseDownScreenPosition
  244. */
  245. int getMouseDownScreenX() const;
  246. /** Returns the y coordinate at which the mouse button was last pressed.
  247. The coordinates are relative to the top-left of the main monitor.
  248. @see getMouseDownScreenPosition
  249. */
  250. int getMouseDownScreenY() const;
  251. /** Returns the coordinates at which the mouse button was last pressed.
  252. The coordinates are relative to the top-left of the main monitor.
  253. @see getScreenPosition
  254. */
  255. Point<int> getMouseDownScreenPosition() const;
  256. //==============================================================================
  257. /** Creates a version of this event that is relative to a different component.
  258. The x and y positions of the event that is returned will have been
  259. adjusted to be relative to the new component.
  260. The component pointer that is passed-in must not be null.
  261. */
  262. MouseEvent getEventRelativeTo (Component* newComponent) const noexcept;
  263. /** Creates a copy of this event with a different position.
  264. All other members of the event object are the same, but the x and y are
  265. replaced with these new values.
  266. */
  267. MouseEvent withNewPosition (Point<float> newPosition) const noexcept;
  268. /** Creates a copy of this event with a different position.
  269. All other members of the event object are the same, but the x and y are
  270. replaced with these new values.
  271. */
  272. MouseEvent withNewPosition (Point<int> newPosition) const noexcept;
  273. //==============================================================================
  274. /** Changes the application-wide setting for the double-click time limit.
  275. This is the maximum length of time between mouse-clicks for it to be
  276. considered a double-click. It's used by the Component class.
  277. @see getDoubleClickTimeout, MouseListener::mouseDoubleClick
  278. */
  279. static void setDoubleClickTimeout (int timeOutMilliseconds) noexcept;
  280. /** Returns the application-wide setting for the double-click time limit.
  281. This is the maximum length of time between mouse-clicks for it to be
  282. considered a double-click. It's used by the Component class.
  283. @see setDoubleClickTimeout, MouseListener::mouseDoubleClick
  284. */
  285. static int getDoubleClickTimeout() noexcept;
  286. private:
  287. //==============================================================================
  288. const uint8 numberOfClicks, wasMovedSinceMouseDown;
  289. MouseEvent& operator= (const MouseEvent&);
  290. };
  291. //==============================================================================
  292. /**
  293. Contains status information about a mouse wheel event.
  294. @see MouseListener, MouseEvent
  295. @tags{GUI}
  296. */
  297. struct MouseWheelDetails final
  298. {
  299. //==============================================================================
  300. /** The amount that the wheel has been moved in the X axis.
  301. If isReversed is true, then a negative deltaX means that the wheel has been
  302. pushed physically to the left.
  303. If isReversed is false, then a negative deltaX means that the wheel has been
  304. pushed physically to the right.
  305. */
  306. float deltaX;
  307. /** The amount that the wheel has been moved in the Y axis.
  308. If isReversed is true, then a negative deltaY means that the wheel has been
  309. pushed physically upwards.
  310. If isReversed is false, then a negative deltaY means that the wheel has been
  311. pushed physically downwards.
  312. */
  313. float deltaY;
  314. /** Indicates whether the user has reversed the direction of the wheel.
  315. See deltaX and deltaY for an explanation of the effects of this value.
  316. */
  317. bool isReversed;
  318. /** If true, then the wheel has continuous, un-stepped motion. */
  319. bool isSmooth;
  320. /** If true, then this event is part of the inertial momentum phase that follows
  321. the wheel being released. */
  322. bool isInertial;
  323. };
  324. //==============================================================================
  325. /**
  326. Contains status information about a pen event.
  327. @see MouseListener, MouseEvent
  328. @tags{GUI}
  329. */
  330. struct PenDetails final
  331. {
  332. /**
  333. The rotation of the pen device in radians. Indicates the clockwise rotation, or twist,
  334. of the pen. The default is 0.
  335. */
  336. float rotation;
  337. /**
  338. Indicates the angle of tilt of the pointer in a range of -1.0 to 1.0 along the x-axis where
  339. a positive value indicates a tilt to the right. The default is 0.
  340. */
  341. float tiltX;
  342. /**
  343. Indicates the angle of tilt of the pointer in a range of -1.0 to 1.0 along the y-axis where
  344. a positive value indicates a tilt toward the user. The default is 0.
  345. */
  346. float tiltY;
  347. };
  348. } // namespace juce