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.

178 lines
5.3KB

  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 (numberOfClicks_),
  40. wasMovedSinceMouseDown (mouseWasDragged)
  41. {
  42. }
  43. MouseEvent::~MouseEvent() noexcept
  44. {
  45. }
  46. //==============================================================================
  47. MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const noexcept
  48. {
  49. if (otherComponent == nullptr)
  50. {
  51. jassertfalse;
  52. return *this;
  53. }
  54. return MouseEvent (source, otherComponent->getLocalPoint (eventComponent, getPosition()),
  55. mods, otherComponent, originalComponent, eventTime,
  56. otherComponent->getLocalPoint (eventComponent, mouseDownPos),
  57. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  58. }
  59. MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const noexcept
  60. {
  61. return MouseEvent (source, newPosition, mods, eventComponent, originalComponent,
  62. eventTime, mouseDownPos, mouseDownTime,
  63. numberOfClicks, wasMovedSinceMouseDown);
  64. }
  65. //==============================================================================
  66. bool MouseEvent::mouseWasClicked() const noexcept
  67. {
  68. return ! wasMovedSinceMouseDown;
  69. }
  70. int MouseEvent::getMouseDownX() const noexcept
  71. {
  72. return mouseDownPos.getX();
  73. }
  74. int MouseEvent::getMouseDownY() const noexcept
  75. {
  76. return mouseDownPos.getY();
  77. }
  78. const Point<int> MouseEvent::getMouseDownPosition() const noexcept
  79. {
  80. return mouseDownPos;
  81. }
  82. int MouseEvent::getDistanceFromDragStartX() const noexcept
  83. {
  84. return x - mouseDownPos.getX();
  85. }
  86. int MouseEvent::getDistanceFromDragStartY() const noexcept
  87. {
  88. return y - mouseDownPos.getY();
  89. }
  90. int MouseEvent::getDistanceFromDragStart() const noexcept
  91. {
  92. return mouseDownPos.getDistanceFrom (getPosition());
  93. }
  94. const Point<int> MouseEvent::getOffsetFromDragStart() const noexcept
  95. {
  96. return getPosition() - mouseDownPos;
  97. }
  98. int MouseEvent::getLengthOfMousePress() const noexcept
  99. {
  100. if (mouseDownTime.toMilliseconds() > 0)
  101. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  102. return 0;
  103. }
  104. //==============================================================================
  105. const Point<int> MouseEvent::getPosition() const noexcept
  106. {
  107. return Point<int> (x, y);
  108. }
  109. int MouseEvent::getScreenX() const
  110. {
  111. return getScreenPosition().getX();
  112. }
  113. int MouseEvent::getScreenY() const
  114. {
  115. return getScreenPosition().getY();
  116. }
  117. const Point<int> MouseEvent::getScreenPosition() const
  118. {
  119. return eventComponent->localPointToGlobal (Point<int> (x, y));
  120. }
  121. int MouseEvent::getMouseDownScreenX() const
  122. {
  123. return getMouseDownScreenPosition().getX();
  124. }
  125. int MouseEvent::getMouseDownScreenY() const
  126. {
  127. return getMouseDownScreenPosition().getY();
  128. }
  129. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  130. {
  131. return eventComponent->localPointToGlobal (mouseDownPos);
  132. }
  133. //==============================================================================
  134. int MouseEvent::doubleClickTimeOutMs = 400;
  135. void MouseEvent::setDoubleClickTimeout (const int newTime) noexcept
  136. {
  137. doubleClickTimeOutMs = newTime;
  138. }
  139. int MouseEvent::getDoubleClickTimeout() noexcept
  140. {
  141. return doubleClickTimeOutMs;
  142. }
  143. END_JUCE_NAMESPACE