1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Provided a public field MouseEvent::mouseDownPosition, to provide a floating point version of the mouse-down pos

This commit is contained in:
jules 2018-05-30 14:49:29 +01:00
parent 8fd1740ad8
commit ea43a1f57d
2 changed files with 18 additions and 12 deletions

View file

@ -47,12 +47,12 @@ MouseEvent::MouseEvent (MouseInputSource inputSource,
pressure (force),
orientation (o), rotation (r),
tiltX (tX), tiltY (tY),
mouseDownPosition (downPos),
eventComponent (eventComp),
originalComponent (originator),
eventTime (time),
mouseDownTime (downTime),
source (inputSource),
mouseDownPos (downPos),
numberOfClicks ((uint8) numClicks),
wasMovedSinceMouseDown ((uint8) (mouseWasDragged ? 1 : 0))
{
@ -70,21 +70,21 @@ MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) cons
return MouseEvent (source, otherComponent->getLocalPoint (eventComponent, position),
mods, pressure, orientation, rotation, tiltX, tiltY,
otherComponent, originalComponent, eventTime,
otherComponent->getLocalPoint (eventComponent, mouseDownPos),
otherComponent->getLocalPoint (eventComponent, mouseDownPosition),
mouseDownTime, numberOfClicks, wasMovedSinceMouseDown != 0);
}
MouseEvent MouseEvent::withNewPosition (Point<float> newPosition) const noexcept
{
return MouseEvent (source, newPosition, mods, pressure, orientation, rotation, tiltX, tiltY,
eventComponent, originalComponent, eventTime, mouseDownPos, mouseDownTime,
eventComponent, originalComponent, eventTime, mouseDownPosition, mouseDownTime,
numberOfClicks, wasMovedSinceMouseDown != 0);
}
MouseEvent MouseEvent::withNewPosition (Point<int> newPosition) const noexcept
{
return MouseEvent (source, newPosition.toFloat(), mods, pressure, orientation, rotation,
tiltX, tiltY, eventComponent, originalComponent, eventTime, mouseDownPos,
tiltX, tiltY, eventComponent, originalComponent, eventTime, mouseDownPosition,
mouseDownTime, numberOfClicks, wasMovedSinceMouseDown != 0);
}
@ -111,14 +111,14 @@ int MouseEvent::getLengthOfMousePress() const noexcept
Point<int> MouseEvent::getPosition() const noexcept { return Point<int> (x, y); }
Point<int> MouseEvent::getScreenPosition() const { return eventComponent->localPointToGlobal (getPosition()); }
Point<int> MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos.roundToInt(); }
Point<int> MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos).roundToInt(); }
Point<int> MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPosition.roundToInt(); }
Point<int> MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPosition).roundToInt(); }
Point<int> MouseEvent::getOffsetFromDragStart() const noexcept { return (position - mouseDownPos).roundToInt(); }
int MouseEvent::getDistanceFromDragStart() const noexcept { return roundToInt (mouseDownPos.getDistanceFrom (position)); }
Point<int> MouseEvent::getOffsetFromDragStart() const noexcept { return (position - mouseDownPosition).roundToInt(); }
int MouseEvent::getDistanceFromDragStart() const noexcept { return roundToInt (mouseDownPosition.getDistanceFrom (position)); }
int MouseEvent::getMouseDownX() const noexcept { return roundToInt (mouseDownPos.x); }
int MouseEvent::getMouseDownY() const noexcept { return roundToInt (mouseDownPos.y); }
int MouseEvent::getMouseDownX() const noexcept { return roundToInt (mouseDownPosition.x); }
int MouseEvent::getMouseDownY() const noexcept { return roundToInt (mouseDownPosition.y); }
int MouseEvent::getDistanceFromDragStartX() const noexcept { return getOffsetFromDragStart().x; }
int MouseEvent::getDistanceFromDragStartY() const noexcept { return getOffsetFromDragStart().y; }

View file

@ -149,6 +149,12 @@ public:
*/
const float tiltY;
/** The coordinates of the last place that a mouse button was pressed.
The coordinates are relative to the component specified in MouseEvent::component.
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
*/
const Point<float> mouseDownPosition;
/** The component that this event applies to.
This is usually the component that the mouse was over at the time, but for mouse-drag
@ -197,7 +203,8 @@ public:
/** Returns the coordinates of the last place that a mouse was pressed.
The coordinates are relative to the component specified in MouseEvent::component.
@see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
For a floating point version of this value, see mouseDownPosition.
@see mouseDownPosition, getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown
*/
Point<int> getMouseDownPosition() const noexcept;
@ -367,7 +374,6 @@ public:
private:
//==============================================================================
const Point<float> mouseDownPos;
const uint8 numberOfClicks, wasMovedSinceMouseDown;
MouseEvent& operator= (const MouseEvent&);