Browse Source

When cloning, pasting, or importing module selection, place modules nearest to center of rack viewport.

tags/v2.2.3
Andrew Belt 1 year ago
parent
commit
a5e377f2e6
3 changed files with 19 additions and 3 deletions
  1. +3
    -0
      include/ui/ScrollWidget.hpp
  2. +1
    -1
      include/widget/Widget.hpp
  3. +15
    -2
      src/app/RackWidget.cpp

+ 3
- 0
include/ui/ScrollWidget.hpp View File

@@ -23,6 +23,9 @@ struct ScrollWidget : widget::OpaqueWidget {

ScrollWidget();
~ScrollWidget();
math::Vec getScrollOffset() {
return offset;
}
void scrollTo(math::Rect r);
/** Returns the bound of allowed `offset` values in pixels. */
math::Rect getContainerOffsetBound();


+ 1
- 1
include/widget/Widget.hpp View File

@@ -85,7 +85,7 @@ struct Widget : WeakBase {
}
/** Returns a subset of the given Rect bounded by the box of this widget and all ancestors.
*/
virtual math::Rect getViewport(math::Rect r);
virtual math::Rect getViewport(math::Rect r = math::Rect::inf());

template <class T>
T* getAncestorOfType() {


+ 15
- 2
src/app/RackWidget.cpp View File

@@ -401,6 +401,8 @@ static PasteJsonResult RackWidget_pasteJson(RackWidget* that, json_t* rootJ, his
that->deselectAll();

std::map<int64_t, ModuleWidget*> newModules;
math::Vec posMin(INFINITY, INFINITY);
math::Vec posMax(-INFINITY, -INFINITY);

// modules
json_t* modulesJ = json_object_get(rootJ, "modules");
@@ -435,8 +437,9 @@ static PasteJsonResult RackWidget_pasteJson(RackWidget* that, json_t* rootJ, his
double x = 0.0, y = 0.0;
json_unpack(posJ, "[F, F]", &x, &y);
math::Vec pos = math::Vec(x, y);
pos = pos.mult(RACK_GRID_SIZE);
mw->box.pos = pos.plus(RACK_OFFSET);
mw->box.pos = pos * RACK_GRID_SIZE + RACK_OFFSET;
posMin = posMin.min(mw->box.getTopLeft());
posMax = posMax.max(mw->box.getBottomRight());

that->internal->moduleContainer->addChild(mw);
that->select(mw);
@@ -444,6 +447,16 @@ static PasteJsonResult RackWidget_pasteJson(RackWidget* that, json_t* rootJ, his
newModules[id] = mw;
}

// Adjust center of selection to appear at center of rack view
math::Vec posCenter = (posMin + posMax) / 2;
math::Vec rackCenter = APP->scene->rack->getViewport().getCenter();
math::Vec posDelta = ((rackCenter - posCenter) / RACK_GRID_SIZE).round() * RACK_GRID_SIZE;

for (auto pair : newModules) {
ModuleWidget* mw = pair.second;
mw->box.pos += posDelta;
}

// This calls updateExpanders()
that->setSelectionPosNearest(math::Vec(0, 0));



Loading…
Cancel
Save