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.

184 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #include "../../../core/juce_StandardHeader.h"
  19. BEGIN_JUCE_NAMESPACE
  20. #include "juce_MouseEvent.h"
  21. #include "../juce_Component.h"
  22. //==============================================================================
  23. MouseEvent::MouseEvent (MouseInputSource& source_,
  24. const Point<int>& position,
  25. const ModifierKeys& mods_,
  26. Component* const eventComponent_,
  27. Component* const originator,
  28. const Time& eventTime_,
  29. const Point<int> mouseDownPos_,
  30. const Time& mouseDownTime_,
  31. const int numberOfClicks_,
  32. const bool mouseWasDragged) throw()
  33. : x (position.getX()),
  34. y (position.getY()),
  35. mods (mods_),
  36. eventComponent (eventComponent_),
  37. originalComponent (originator),
  38. eventTime (eventTime_),
  39. source (source_),
  40. mouseDownPos (mouseDownPos_),
  41. mouseDownTime (mouseDownTime_),
  42. numberOfClicks (numberOfClicks_),
  43. wasMovedSinceMouseDown (mouseWasDragged)
  44. {
  45. }
  46. MouseEvent::~MouseEvent() throw()
  47. {
  48. }
  49. //==============================================================================
  50. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  51. {
  52. if (otherComponent == 0)
  53. {
  54. jassertfalse;
  55. return *this;
  56. }
  57. return MouseEvent (source, otherComponent->getLocalPoint (eventComponent, getPosition()),
  58. mods, otherComponent, originalComponent, eventTime,
  59. otherComponent->getLocalPoint (eventComponent, mouseDownPos),
  60. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  61. }
  62. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  63. {
  64. return MouseEvent (source, newPosition, mods, eventComponent, originalComponent,
  65. eventTime, mouseDownPos, mouseDownTime,
  66. numberOfClicks, wasMovedSinceMouseDown);
  67. }
  68. //==============================================================================
  69. bool MouseEvent::mouseWasClicked() const throw()
  70. {
  71. return ! wasMovedSinceMouseDown;
  72. }
  73. int MouseEvent::getMouseDownX() const throw()
  74. {
  75. return mouseDownPos.getX();
  76. }
  77. int MouseEvent::getMouseDownY() const throw()
  78. {
  79. return mouseDownPos.getY();
  80. }
  81. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  82. {
  83. return mouseDownPos;
  84. }
  85. int MouseEvent::getDistanceFromDragStartX() const throw()
  86. {
  87. return x - mouseDownPos.getX();
  88. }
  89. int MouseEvent::getDistanceFromDragStartY() const throw()
  90. {
  91. return y - mouseDownPos.getY();
  92. }
  93. int MouseEvent::getDistanceFromDragStart() const throw()
  94. {
  95. return mouseDownPos.getDistanceFrom (getPosition());
  96. }
  97. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  98. {
  99. return getPosition() - mouseDownPos;
  100. }
  101. int MouseEvent::getLengthOfMousePress() const throw()
  102. {
  103. if (mouseDownTime.toMilliseconds() > 0)
  104. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  105. return 0;
  106. }
  107. //==============================================================================
  108. const Point<int> MouseEvent::getPosition() const throw()
  109. {
  110. return Point<int> (x, y);
  111. }
  112. int MouseEvent::getScreenX() const
  113. {
  114. return getScreenPosition().getX();
  115. }
  116. int MouseEvent::getScreenY() const
  117. {
  118. return getScreenPosition().getY();
  119. }
  120. const Point<int> MouseEvent::getScreenPosition() const
  121. {
  122. return eventComponent->localPointToGlobal (Point<int> (x, y));
  123. }
  124. int MouseEvent::getMouseDownScreenX() const
  125. {
  126. return getMouseDownScreenPosition().getX();
  127. }
  128. int MouseEvent::getMouseDownScreenY() const
  129. {
  130. return getMouseDownScreenPosition().getY();
  131. }
  132. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  133. {
  134. return eventComponent->localPointToGlobal (mouseDownPos);
  135. }
  136. //==============================================================================
  137. int MouseEvent::doubleClickTimeOutMs = 400;
  138. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  139. {
  140. doubleClickTimeOutMs = newTime;
  141. }
  142. int MouseEvent::getDoubleClickTimeout() throw()
  143. {
  144. return doubleClickTimeOutMs;
  145. }
  146. END_JUCE_NAMESPACE