From ed5f8446b442d3649248d9a63bf9672e61a01f27 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 25 Oct 2017 08:28:49 -0400 Subject: [PATCH] Avoid re-rendering rails when scrolling with a framebuffer margin --- src/app/RackWidget.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 8af91174..1b1b3b5e 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -16,6 +16,7 @@ namespace rack { RackWidget::RackWidget() { rails = new FramebufferWidget(); + rails->box.size = Vec(); { RackRail *rail = new RackRail(); rail->box.size = Vec(); @@ -342,17 +343,20 @@ void RackWidget::step() { // Adjust size and position of rails Widget *rail = rails->children.front(); Rect bound = getViewport(Rect(Vec(), box.size)); - // bound.pos = bound.pos.plus(Vec(100, 100)); - // bound.size = bound.size.minus(Vec(200, 200)); - rails->box = bound; - Vec grid = Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT); - Vec gridPos = bound.pos.div(grid).floor().mult(grid); - bound.pos = gridPos.minus(bound.pos); - bound.size = bound.size.minus(bound.pos); - if (!bound.isEqual(rail->box)) { + if (!rails->box.contains(bound)) { + // Add a margin around the otherwise tight bound, so that scrolling slightly will not require a re-render of rails. + Vec margin = Vec(100, 100); + bound.pos = bound.pos.minus(margin); + bound.size = bound.size.plus(margin.mult(2)); + rails->box = bound; + // Compute offset of rail within rails framebuffer + Vec grid = Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT); + Vec gridPos = bound.pos.div(grid).floor().mult(grid); + bound.pos = gridPos.minus(bound.pos); + bound.size = bound.size.minus(bound.pos); + rail->box = bound; rails->dirty = true; } - rail->box = bound; // Autosave every 15 seconds if (gGuiFrame % (60*15) == 0) {