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.

119 lines
5.4KB

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