From c8023192414a4398c70e669fc2c2e4f6bc781f86 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 23 Aug 2021 18:40:03 +0100 Subject: [PATCH] Viewport: Stop touches on other components from interrupting scrolling Previously, a touch on a component outside the Viewport would interrupt and cancel a scroll gesture inside the Viewport. Now, the Viewport will respond to all drag events from the input source that started the drag, allowing the Viewport to be scrolled with one input source while adjusting other controls with another input source. The FontsDemo is useful for testing this behaviour, as it has two Viewports on a single screen, along with some other controls. --- modules/juce_gui_basics/layout/juce_Viewport.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/juce_gui_basics/layout/juce_Viewport.cpp b/modules/juce_gui_basics/layout/juce_Viewport.cpp index e37dd362f3..dfccd68ac9 100644 --- a/modules/juce_gui_basics/layout/juce_Viewport.cpp +++ b/modules/juce_gui_basics/layout/juce_Viewport.cpp @@ -222,7 +222,7 @@ struct Viewport::DragToScrollListener : private MouseListener, (int) offsetY.getPosition())); } - void mouseDown (const MouseEvent&) override + void mouseDown (const MouseEvent& e) override { if (! isGlobalMouseListener) { @@ -235,12 +235,15 @@ struct Viewport::DragToScrollListener : private MouseListener, Desktop::getInstance().addGlobalMouseListener (this); isGlobalMouseListener = true; + + scrollSource = e.source; } } void mouseDrag (const MouseEvent& e) override { - if (Desktop::getInstance().getNumDraggingMouseSources() == 1 && ! doesMouseEventComponentBlockViewportDrag (e.eventComponent)) + if (e.source == scrollSource + && ! doesMouseEventComponentBlockViewportDrag (e.eventComponent)) { auto totalOffset = e.getOffsetFromDragStart().toFloat(); @@ -263,9 +266,9 @@ struct Viewport::DragToScrollListener : private MouseListener, } } - void mouseUp (const MouseEvent&) override + void mouseUp (const MouseEvent& e) override { - if (isGlobalMouseListener && Desktop::getInstance().getNumDraggingMouseSources() == 0) + if (isGlobalMouseListener && e.source == scrollSource) endDragAndClearGlobalMouseListener(); } @@ -293,6 +296,7 @@ struct Viewport::DragToScrollListener : private MouseListener, Viewport& viewport; ViewportDragPosition offsetX, offsetY; Point originalViewPos; + MouseInputSource scrollSource = Desktop::getInstance().getMainMouseSource(); bool isDragging = false; bool isGlobalMouseListener = false;