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.

120 lines
5.3KB

  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. MouseEvent::MouseEvent (MouseInputSource inputSource,
  18. Point<float> pos,
  19. ModifierKeys modKeys,
  20. Component* const eventComp,
  21. Component* const originator,
  22. Time time,
  23. Point<float> downPos,
  24. Time downTime,
  25. const int numClicks,
  26. const bool mouseWasDragged) noexcept
  27. : position (pos),
  28. x (roundToInt (pos.x)),
  29. y (roundToInt (pos.y)),
  30. mods (modKeys),
  31. eventComponent (eventComp),
  32. originalComponent (originator),
  33. eventTime (time),
  34. mouseDownTime (downTime),
  35. source (inputSource),
  36. mouseDownPos (downPos),
  37. numberOfClicks ((uint8) numClicks),
  38. wasMovedSinceMouseDown ((uint8) (mouseWasDragged ? 1 : 0))
  39. {
  40. }
  41. MouseEvent::~MouseEvent() noexcept
  42. {
  43. }
  44. //==============================================================================
  45. MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const noexcept
  46. {
  47. jassert (otherComponent != nullptr);
  48. return MouseEvent (source, otherComponent->getLocalPoint (eventComponent, position),
  49. mods, otherComponent, originalComponent, eventTime,
  50. otherComponent->getLocalPoint (eventComponent, mouseDownPos),
  51. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown != 0);
  52. }
  53. MouseEvent MouseEvent::withNewPosition (Point<float> newPosition) const noexcept
  54. {
  55. return MouseEvent (source, newPosition, mods, eventComponent, originalComponent,
  56. eventTime, mouseDownPos, mouseDownTime,
  57. numberOfClicks, wasMovedSinceMouseDown != 0);
  58. }
  59. MouseEvent MouseEvent::withNewPosition (Point<int> newPosition) const noexcept
  60. {
  61. return MouseEvent (source, newPosition.toFloat(), mods, eventComponent, originalComponent,
  62. eventTime, mouseDownPos, mouseDownTime,
  63. numberOfClicks, wasMovedSinceMouseDown != 0);
  64. }
  65. //==============================================================================
  66. bool MouseEvent::mouseWasClicked() const noexcept
  67. {
  68. return wasMovedSinceMouseDown == 0;
  69. }
  70. int MouseEvent::getLengthOfMousePress() const noexcept
  71. {
  72. if (mouseDownTime.toMilliseconds() > 0)
  73. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  74. return 0;
  75. }
  76. //==============================================================================
  77. Point<int> MouseEvent::getPosition() const noexcept { return Point<int> (x, y); }
  78. Point<int> MouseEvent::getScreenPosition() const { return eventComponent->localPointToGlobal (getPosition()); }
  79. Point<int> MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos.roundToInt(); }
  80. Point<int> MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos).roundToInt(); }
  81. Point<int> MouseEvent::getOffsetFromDragStart() const noexcept { return (position - mouseDownPos).roundToInt(); }
  82. int MouseEvent::getDistanceFromDragStart() const noexcept { return roundToInt (mouseDownPos.getDistanceFrom (position)); }
  83. int MouseEvent::getMouseDownX() const noexcept { return roundToInt (mouseDownPos.x); }
  84. int MouseEvent::getMouseDownY() const noexcept { return roundToInt (mouseDownPos.y); }
  85. int MouseEvent::getDistanceFromDragStartX() const noexcept { return getOffsetFromDragStart().x; }
  86. int MouseEvent::getDistanceFromDragStartY() const noexcept { return getOffsetFromDragStart().y; }
  87. int MouseEvent::getScreenX() const { return getScreenPosition().x; }
  88. int MouseEvent::getScreenY() const { return getScreenPosition().y; }
  89. int MouseEvent::getMouseDownScreenX() const { return getMouseDownScreenPosition().x; }
  90. int MouseEvent::getMouseDownScreenY() const { return getMouseDownScreenPosition().y; }
  91. //==============================================================================
  92. static int doubleClickTimeOutMs = 400;
  93. int MouseEvent::getDoubleClickTimeout() noexcept { return doubleClickTimeOutMs; }
  94. void MouseEvent::setDoubleClickTimeout (const int newTime) noexcept { doubleClickTimeOutMs = newTime; }