/* ============================================================================== This file is part of the JUCE library - "Jules' Utility Class Extensions" Copyright 2004-9 by Raw Material Software Ltd. ------------------------------------------------------------------------------ JUCE can be redistributed and/or modified under the terms of the GNU General Public License (Version 2), as published by the Free Software Foundation. A copy of the license is included in the JUCE distribution, or can be found online at www.gnu.org/licenses. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ------------------------------------------------------------------------------ To release a closed-source product which uses JUCE, commercial licenses are available: visit www.rawmaterialsoftware.com/juce for more information. ============================================================================== */ #include "../../../core/juce_StandardHeader.h" BEGIN_JUCE_NAMESPACE #include "juce_MouseEvent.h" #include "../juce_Component.h" //============================================================================== MouseEvent::MouseEvent (const Point& position, const ModifierKeys& mods_, Component* const originator, const Time& eventTime_, const Point mouseDownPos_, const Time& mouseDownTime_, const int numberOfClicks_, const bool mouseWasDragged) throw() : x (position.getX()), y (position.getY()), mods (mods_), eventComponent (originator), originalComponent (originator), eventTime (eventTime_), mouseDownPos (mouseDownPos_), mouseDownTime (mouseDownTime_), numberOfClicks (numberOfClicks_), wasMovedSinceMouseDown (mouseWasDragged) { } MouseEvent::~MouseEvent() throw() { } //============================================================================== bool MouseEvent::mouseWasClicked() const throw() { return ! wasMovedSinceMouseDown; } int MouseEvent::getMouseDownX() const throw() { return mouseDownPos.getX(); } int MouseEvent::getMouseDownY() const throw() { return mouseDownPos.getY(); } const Point MouseEvent::getMouseDownPosition() const throw() { return mouseDownPos; } int MouseEvent::getDistanceFromDragStartX() const throw() { return x - mouseDownPos.getX(); } int MouseEvent::getDistanceFromDragStartY() const throw() { return y - mouseDownPos.getY(); } int MouseEvent::getDistanceFromDragStart() const throw() { return roundToInt (juce_hypot (getDistanceFromDragStartX(), getDistanceFromDragStartY())); } int MouseEvent::getLengthOfMousePress() const throw() { if (mouseDownTime.toMilliseconds() > 0) return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds()); return 0; } //============================================================================== const Point MouseEvent::getPosition() const throw() { return Point (x, y); } int MouseEvent::getScreenX() const { return getScreenPosition().getX(); } int MouseEvent::getScreenY() const { return getScreenPosition().getY(); } const Point MouseEvent::getScreenPosition() const { return eventComponent->relativePositionToGlobal (Point (x, y)); } int MouseEvent::getMouseDownScreenX() const { return getMouseDownScreenPosition().getX(); } int MouseEvent::getMouseDownScreenY() const { return getMouseDownScreenPosition().getY(); } const Point MouseEvent::getMouseDownScreenPosition() const { return eventComponent->relativePositionToGlobal (mouseDownPos); } //============================================================================== const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw() { if (otherComponent == 0) { jassertfalse return *this; } return MouseEvent (eventComponent->relativePositionToOtherComponent (otherComponent, Point (x, y)), mods, originalComponent, eventTime, eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos), mouseDownTime, numberOfClicks, wasMovedSinceMouseDown); } //============================================================================== static int doubleClickTimeOutMs = 400; void MouseEvent::setDoubleClickTimeout (const int newTime) throw() { doubleClickTimeOutMs = newTime; } int MouseEvent::getDoubleClickTimeout() throw() { return doubleClickTimeOutMs; } END_JUCE_NAMESPACE