From 7dac51859cfc1651b32b67a568ef74aa9d8e3e9f Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 31 Jul 2014 11:18:38 +0100 Subject: [PATCH] Fixes for unbounded mouse behaviour on scaled displays --- .../mouse/juce_MouseInputSource.cpp | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp index 3607ff5678..8bed5afa86 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp @@ -274,7 +274,7 @@ public: sendMouseDrag (*current, newScreenPos + unboundedMouseOffset, time); if (isUnboundedMouseModeOn) - handleUnboundedDrag (current); + handleUnboundedDrag (*current); } else { @@ -399,7 +399,8 @@ public: { // when released, return the mouse to within the component's bounds if (Component* current = getComponentUnderMouse()) - setScreenPosition (current->getScreenBounds().toFloat().getConstrainedPoint (lastScreenPos)); + setScreenPosition (current->getScreenBounds().toFloat() + .getConstrainedPoint (ScalingHelpers::unscaledScreenPosToScaled (lastScreenPos))); } isUnboundedMouseModeOn = enable; @@ -409,21 +410,22 @@ public: } } - void handleUnboundedDrag (Component* current) + void handleUnboundedDrag (Component& current) { - const Rectangle screenArea (current->getParentMonitorArea().expanded (-2, -2).toFloat()); + const Rectangle componentScreenBounds + = ScalingHelpers::scaledScreenPosToUnscaled (current.getParentMonitorArea().reduced (2, 2).toFloat()); - if (! screenArea.contains (lastScreenPos)) + if (! componentScreenBounds.contains (lastScreenPos)) { - const Point componentCentre (current->getScreenBounds().toFloat().getCentre()); - unboundedMouseOffset += (lastScreenPos - componentCentre); + const Point componentCentre (current.getScreenBounds().toFloat().getCentre()); + unboundedMouseOffset += (lastScreenPos - ScalingHelpers::scaledScreenPosToUnscaled (componentCentre)); setScreenPosition (componentCentre); } else if (isCursorVisibleUntilOffscreen && (! unboundedMouseOffset.isOrigin()) - && screenArea.contains (lastScreenPos + unboundedMouseOffset)) + && componentScreenBounds.contains (lastScreenPos + unboundedMouseOffset)) { - setScreenPosition (lastScreenPos + unboundedMouseOffset); + MouseInputSource::setRawMousePosition (lastScreenPos + unboundedMouseOffset); unboundedMouseOffset = Point(); } } @@ -462,10 +464,9 @@ public: //============================================================================== const int index; const bool isMouseDevice; - Point lastScreenPos; + Point lastScreenPos, unboundedMouseOffset; // NB: these are unscaled coords ModifierKeys buttonState; - Point unboundedMouseOffset; bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen; private: