Skip to content

Commit bd01072

Browse files
author
alcomposer
committed
Allow quick canvas to connect to parent viewports mouse listener on pan-drag
1 parent 74643cb commit bd01072

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

Source/Canvas.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,12 @@ bool Canvas::setPanDragMode(bool shouldPan)
27132713
v->enableMousePanning(shouldPan);
27142714
return true;
27152715
}
2716+
if (isQuickCanvas) {
2717+
if (auto v = dynamic_cast<CanvasViewport*>(dynamic_cast<Canvas*>(getParentComponent())->viewport.get())) {
2718+
v->enableMousePanning(shouldPan, this);
2719+
return true;
2720+
}
2721+
}
27162722
return false;
27172723
}
27182724

Source/CanvasViewport.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,24 @@ class CanvasViewport : public Viewport
3535
{
3636
}
3737

38-
void enablePanning(bool enabled)
38+
void enablePanning(bool enabled, Canvas* canvas = nullptr)
3939
{
40-
if (auto* viewedComponent = viewport->getViewedComponent()) {
41-
if (enabled) {
42-
viewedComponent->addMouseListener(this, false);
43-
} else {
44-
viewedComponent->removeMouseListener(this);
40+
auto attachMouseListnerToCanvas = [this, enabled](Component* component) -> bool {
41+
if (component) {
42+
if (enabled) {
43+
component->addMouseListener(this, false);
44+
} else {
45+
component->removeMouseListener(this);
46+
}
47+
return true;
4548
}
46-
}
49+
return false;
50+
};
51+
52+
if (attachMouseListnerToCanvas(canvas))
53+
return;
54+
55+
attachMouseListnerToCanvas(viewport->getViewedComponent());
4756
}
4857

4958
// warning: this only works because Canvas::mouseDown gets called before the listener's mouse down
@@ -429,9 +438,9 @@ class CanvasViewport : public Viewport
429438
vbar.repaint();
430439
}
431440

432-
void enableMousePanning(bool enablePanning)
441+
void enableMousePanning(bool enablePanning, Canvas* canvas = nullptr)
433442
{
434-
panner.enablePanning(enablePanning);
443+
panner.enablePanning(enablePanning, canvas);
435444
}
436445

437446
bool hitTest(int x, int y) override

0 commit comments

Comments
 (0)