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_MouseEvent.cpp 4.9KB

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