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.

447 lines
18KB

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