The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

113 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. MouseEvent::MouseEvent (MouseInputSource& source_,
  19. const Point<int>& position,
  20. const ModifierKeys& mods_,
  21. Component* const eventComponent_,
  22. Component* const originator,
  23. const Time& eventTime_,
  24. const Point<int> mouseDownPos_,
  25. const Time& mouseDownTime_,
  26. const int numberOfClicks_,
  27. const bool mouseWasDragged) noexcept
  28. : x (position.x),
  29. y (position.y),
  30. mods (mods_),
  31. eventComponent (eventComponent_),
  32. originalComponent (originator),
  33. eventTime (eventTime_),
  34. source (source_),
  35. mouseDownPos (mouseDownPos_),
  36. mouseDownTime (mouseDownTime_),
  37. numberOfClicks ((uint8) numberOfClicks_),
  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, getPosition()),
  49. mods, otherComponent, originalComponent, eventTime,
  50. otherComponent->getLocalPoint (eventComponent, mouseDownPos),
  51. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown != 0);
  52. }
  53. MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const noexcept
  54. {
  55. return MouseEvent (source, newPosition, mods, eventComponent, originalComponent,
  56. eventTime, mouseDownPos, mouseDownTime,
  57. numberOfClicks, wasMovedSinceMouseDown != 0);
  58. }
  59. //==============================================================================
  60. bool MouseEvent::mouseWasClicked() const noexcept
  61. {
  62. return wasMovedSinceMouseDown == 0;
  63. }
  64. int MouseEvent::getLengthOfMousePress() const noexcept
  65. {
  66. if (mouseDownTime.toMilliseconds() > 0)
  67. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  68. return 0;
  69. }
  70. //==============================================================================
  71. Point<int> MouseEvent::getPosition() const noexcept { return Point<int> (x, y); }
  72. Point<int> MouseEvent::getScreenPosition() const { return eventComponent->localPointToGlobal (getPosition()); }
  73. Point<int> MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos; }
  74. Point<int> MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos); }
  75. Point<int> MouseEvent::getOffsetFromDragStart() const noexcept { return getPosition() - mouseDownPos; }
  76. int MouseEvent::getDistanceFromDragStart() const noexcept { return mouseDownPos.getDistanceFrom (getPosition()); }
  77. int MouseEvent::getMouseDownX() const noexcept { return mouseDownPos.x; }
  78. int MouseEvent::getMouseDownY() const noexcept { return mouseDownPos.y; }
  79. int MouseEvent::getDistanceFromDragStartX() const noexcept { return x - mouseDownPos.x; }
  80. int MouseEvent::getDistanceFromDragStartY() const noexcept { return y - mouseDownPos.y; }
  81. int MouseEvent::getScreenX() const { return getScreenPosition().x; }
  82. int MouseEvent::getScreenY() const { return getScreenPosition().y; }
  83. int MouseEvent::getMouseDownScreenX() const { return getMouseDownScreenPosition().x; }
  84. int MouseEvent::getMouseDownScreenY() const { return getMouseDownScreenPosition().y; }
  85. //==============================================================================
  86. static int doubleClickTimeOutMs = 400;
  87. int MouseEvent::getDoubleClickTimeout() noexcept { return doubleClickTimeOutMs; }
  88. void MouseEvent::setDoubleClickTimeout (const int newTime) noexcept { doubleClickTimeOutMs = newTime; }