Browse Source

Avoid re-rendering rails when scrolling with a framebuffer margin

tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
ed5f8446b4
1 changed files with 13 additions and 9 deletions
  1. +13
    -9
      src/app/RackWidget.cpp

+ 13
- 9
src/app/RackWidget.cpp View File

@@ -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) {


Loading…
Cancel
Save