Browse Source

Serialize gridOffset of RackScrollWidget in patch.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
1878e97e4c
2 changed files with 19 additions and 7 deletions
  1. +4
    -5
      src/app/RackScrollWidget.cpp
  2. +15
    -2
      src/patch.cpp

+ 4
- 5
src/app/RackScrollWidget.cpp View File

@@ -39,18 +39,17 @@ RackScrollWidget::~RackScrollWidget() {


void RackScrollWidget::reset() {
offset = RACK_OFFSET.mult(zoomWidget->zoom);
offset = offset.minus(math::Vec(30, 30));
offset = RACK_OFFSET * zoomWidget->getZoom() - math::Vec(30, 30);
}


math::Vec RackScrollWidget::getGridOffset() {
return offset.minus(RACK_OFFSET).div(RACK_GRID_SIZE);
return (offset / zoomWidget->getZoom() - RACK_OFFSET) / RACK_GRID_SIZE;
}


void RackScrollWidget::setGridOffset(math::Vec gridOffset) {
offset = gridOffset.mult(RACK_GRID_SIZE).plus(RACK_OFFSET);
offset = (gridOffset * RACK_GRID_SIZE + RACK_OFFSET) * zoomWidget->getZoom();
}


@@ -67,7 +66,7 @@ void RackScrollWidget::setZoom(float zoom) {
void RackScrollWidget::setZoom(float zoom, math::Vec pivot) {
zoom = math::clamp(zoom, std::pow(2.f, -2), std::pow(2.f, 2));

offset = offset.plus(pivot).mult(zoom / zoomWidget->getZoom()).minus(pivot);
offset = (offset + pivot) * (zoom / zoomWidget->getZoom()) - pivot;
zoomWidget->setZoom(zoom);
}



+ 15
- 2
src/patch.cpp View File

@@ -416,10 +416,15 @@ json_t* Manager::toJson() {
if (!APP->history->isSaved())
json_object_set_new(rootJ, "unsaved", json_boolean(true));

// zoom
if (APP->scene) {
// zoom
float zoom = APP->scene->rackScroll->getZoom();
json_object_set_new(rootJ, "zoom", json_real(zoom));

// gridOffset
math::Vec gridOffset = APP->scene->rackScroll->getGridOffset();
json_t* gridOffsetJ = json_pack("[f, f]", gridOffset.x, gridOffset.y);
json_object_set_new(rootJ, "gridOffset", gridOffsetJ);
}

// Merge with Engine JSON
@@ -460,11 +465,19 @@ void Manager::fromJson(json_t* rootJ) {
if (!unsavedJ)
APP->history->setSaved();

// zoom
if (APP->scene) {
// zoom
json_t* zoomJ = json_object_get(rootJ, "zoom");
if (zoomJ)
APP->scene->rackScroll->setZoom(json_number_value(zoomJ));

// gridOffset
json_t* gridOffsetJ = json_object_get(rootJ, "gridOffset");
if (gridOffsetJ) {
double x, y;
json_unpack(gridOffsetJ, "[F, F]", &x, &y);
APP->scene->rackScroll->setGridOffset(math::Vec(x, y));
}
}

// Pass JSON to Engine and RackWidget


Loading…
Cancel
Save