Browse Source

Expand RackScrollWidget bounding box to current scroll position

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
f58fc44799
2 changed files with 17 additions and 8 deletions
  1. +1
    -0
      include/app/RackScrollWidget.hpp
  2. +16
    -8
      src/app/RackScrollWidget.cpp

+ 1
- 0
include/app/RackScrollWidget.hpp View File

@@ -14,6 +14,7 @@ struct RackScrollWidget : ui::ScrollWidget {
RackWidget *rackWidget;
/** The pivot point for zooming */
math::Vec zoomPos;
math::Vec oldOffset;

RackScrollWidget();
void step() override;


+ 16
- 8
src/app/RackScrollWidget.cpp View File

@@ -42,17 +42,24 @@ void RackScrollWidget::step() {
zoomWidget->box.size = moduleBox.size.mult(zoom);

// Expand to moduleBox
math::Rect viewportBox = moduleBox.grow(RACK_GRID_SIZE.mult(math::Vec(50, 2)));
viewportBox.pos = viewportBox.pos.mult(zoom);
viewportBox.size = viewportBox.size.mult(zoom);
math::Rect scrollBox = moduleBox.grow(RACK_GRID_SIZE.mult(math::Vec(50, 2)));
scrollBox.pos = scrollBox.pos.mult(zoom);
scrollBox.size = scrollBox.size.mult(zoom);

// Expand scrollBox to center the moduleBox
math::Vec s = box.size.minus(scrollBox.size).max(math::Vec());
scrollBox.pos = scrollBox.pos.minus(s.div(2));
scrollBox.size = scrollBox.size.plus(s);

// Expand to viewport size
math::Vec s = box.size.minus(viewportBox.size).max(math::Vec());
viewportBox.pos = viewportBox.pos.minus(s.div(2));
viewportBox.size = viewportBox.size.plus(s);
math::Rect viewportBox;
viewportBox.pos = oldOffset;
viewportBox.size = box.size;
scrollBox = scrollBox.expand(viewportBox);

// Reposition widgets
zoomWidget->box = viewportBox;
rackWidget->box.pos = zoomWidget->box.pos.div(zoom).neg();
zoomWidget->box = scrollBox;
rackWidget->box.pos = scrollBox.pos.div(zoom).neg();

// Scroll rack if dragging cable near the edge of the screen
math::Vec pos = APP->window->mousePos;
@@ -71,6 +78,7 @@ void RackScrollWidget::step() {
}

ScrollWidget::step();
oldOffset = offset;
}




Loading…
Cancel
Save