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

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.
This commit is contained in:
reuk 2021-08-23 18:40:03 +01:00
parent 7b64bd7406
commit c802319241
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -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<int> originalViewPos;
MouseInputSource scrollSource = Desktop::getInstance().getMainMouseSource();
bool isDragging = false;
bool isGlobalMouseListener = false;