Skip to content

Commit b530459

Browse files
author
alcomposer
committed
Quick canvas doesn't need viewport? Maybe not?...
1 parent 5c1fb63 commit b530459

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

Source/Canvas.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class ObjectsResizer : public Component, NVGComponent, Value::Listener {
225225
std::function<void(Point<int>)> onMove;
226226
};
227227

228-
Canvas::Canvas(PluginEditor* parent, pd::Patch::Ptr p, Component* parentGraph)
228+
Canvas::Canvas(PluginEditor* parent, pd::Patch::Ptr p, Component* parentGraph, bool isQuickCanvas)
229229
: NVGComponent(this)
230230
, editor(parent)
231231
, pd(parent->pd)
@@ -235,6 +235,7 @@ Canvas::Canvas(PluginEditor* parent, pd::Patch::Ptr p, Component* parentGraph)
235235
, graphArea(nullptr)
236236
, pathUpdater(new ConnectionPathUpdater(this))
237237
, globalMouseListener(this)
238+
, isQuickCanvas(isQuickCanvas)
238239
{
239240
selectedComponents.addChangeListener(this);
240241

@@ -293,7 +294,7 @@ Canvas::Canvas(PluginEditor* parent, pd::Patch::Ptr p, Component* parentGraph)
293294
} else {
294295
isGraph = false;
295296
}
296-
if (!isGraph) {
297+
if (!isGraph && !isQuickCanvas) {
297298
auto* canvasViewport = new CanvasViewport(editor, this);
298299

299300
canvasViewport->setViewedComponent(this, false);
@@ -397,7 +398,17 @@ Canvas::~Canvas()
397398
}
398399

399400
saveViewportState();
401+
400402
zoomScale.removeListener(this);
403+
commandLocked.referTo(Value());
404+
commandLocked.removeListener(this);
405+
patchWidth.removeListener(this);
406+
patchHeight.removeListener(this);
407+
xRange.removeListener(this);
408+
yRange.removeListener(this);
409+
isGraphChild.removeListener(this);
410+
hideNameAndArgs.removeListener(this);
411+
401412
editor->removeModifierKeyListener(this);
402413
pd->unregisterMessageListener(this);
403414
patch.setVisible(false);
@@ -592,8 +603,7 @@ bool Canvas::updateFramebuffers(NVGcontext* nvg, Rectangle<int> invalidRegion)
592603
}
593604

594605
// Callback from canvasViewport to perform actual rendering
595-
void Canvas::performRender(NVGcontext* nvg, Rectangle<int> invalidRegion, bool isQuickCanvas)
596-
{
606+
void Canvas::performRender(NVGcontext* nvg, Rectangle<int> invalidRegion, bool isQuickCanvas) {
597607
auto const halfSize = infiniteCanvasSize / 2;
598608
auto const zoom = getValue<float>(zoomScale);
599609
bool isLocked = getValue<bool>(locked);
@@ -818,15 +828,11 @@ void Canvas::performRender(NVGcontext* nvg, Rectangle<int> invalidRegion, bool i
818828

819829
nvgRestore(nvg);
820830

821-
//if (quickCanvas) {
822-
// std::cout << "rendering quick canvas region: " << invalidRegion.toString() << std::endl;
823-
// quickCanvas->performRender(nvg, quickCanvas->getBounds(), true);
824-
//}
825-
826-
827831
// Draw scrollbars
828-
if (viewport && isQuickCanvas) {
832+
if (viewport && !quickCanvas) {
829833
reinterpret_cast<CanvasViewport*>(viewport.get())->render(nvg);
834+
} else if (isQuickCanvas) {
835+
reinterpret_cast<CanvasViewport*>(findParentComponentOfClass<Canvas>()->viewport.get())->render(nvg);
830836
}
831837
}
832838

Source/Canvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Canvas : public Component
6969
, public NVGComponent
7070
, public ChangeListener {
7171
public:
72-
Canvas(PluginEditor* parent, pd::Patch::Ptr patch, Component* parentGraph = nullptr);
72+
Canvas(PluginEditor* parent, pd::Patch::Ptr patch, Component* parentGraph = nullptr, bool isQuickCanvas = false);
7373

7474
~Canvas() override;
7575

Source/CanvasViewport.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ class CanvasViewport : public Viewport
383383
if (approximatelyEqual(0.0f, cnv->quickCanvas->quickCanvasAlpha)) {
384384
stopTimer(Timers::QuickCanvasAnimationTimer);
385385

386+
cnv->quickCanvas->zoomScale.referTo(Value());
387+
cnv->quickCanvas->locked.referTo(Value());
386388
cnv->quickCanvas.reset();
387389
}
388390
}
@@ -476,7 +478,7 @@ class CanvasViewport : public Viewport
476478
}
477479

478480
if (!cnv->quickCanvas) {
479-
cnv->quickCanvas = std::make_unique<Canvas>(editor, patch);
481+
cnv->quickCanvas = std::make_unique<Canvas>(editor, patch, nullptr, true);
480482
cnv->addAndMakeVisible(cnv->quickCanvas.get());
481483

482484
cnv->quickCanvas->zoomScale.referTo(cnv->zoomScale);
@@ -485,8 +487,8 @@ class CanvasViewport : public Viewport
485487
cnv->quickCanvas->locked.referTo(cnv->locked);
486488
cnv->quickCanvas->locked.setValue(cnv->locked);
487489

488-
cnv->quickCanvas->isQuickCanvas = true;
489490
cnv->quickCanvas->quickCanvasOffset = cnv->canvasOrigin - obj->getPosition().translated(Object::margin, Object::margin) + patch->getGraphBounds().getPosition();
491+
490492
cnv->resized();
491493
}
492494
return;

0 commit comments

Comments
 (0)