From d55d460c1f10c9f26d04b7f43de7138e0158ffb2 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 15 Jan 2018 09:13:59 -0500 Subject: [PATCH] ModuleWidget serializes pos in rack grid coordinates instead of pixel coordinates --- include/app.hpp | 14 ++++++++++++-- include/widgets.hpp | 13 ------------- src/app/ModuleWidget.cpp | 11 +++++++++-- src/gui.cpp | 1 + 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/include/app.hpp b/include/app.hpp index f122f2ff..dbcc6fe2 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -4,13 +4,23 @@ #include "widgets.hpp" -namespace rack { - +#define SVG_DPI 75.0 #define CHECKMARK_STRING "✔" #define CHECKMARK(_cond) ((_cond) ? CHECKMARK_STRING : "") +namespace rack { + +inline Vec in2px(Vec inches) { + return inches.mult(SVG_DPI); +} + +inline Vec mm2px(Vec millimeters) { + return millimeters.mult(SVG_DPI / 25.4); +} + + struct Model; struct Module; struct Wire; diff --git a/include/widgets.hpp b/include/widgets.hpp index 6c8fa9f3..6ebfaec6 100644 --- a/include/widgets.hpp +++ b/include/widgets.hpp @@ -11,21 +11,8 @@ #include "events.hpp" -#define SVG_DPI 75.0 - - namespace rack { - -inline Vec in2px(Vec inches) { - return inches.mult(SVG_DPI); -} - -inline Vec mm2px(Vec millimeters) { - return millimeters.mult(SVG_DPI / 25.4); -} - - //////////////////// // resources //////////////////// diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index cab832b7..393aee5b 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -68,7 +68,8 @@ json_t *ModuleWidget::toJson() { // model json_object_set_new(rootJ, "model", json_string(model->slug.c_str())); // pos - json_t *posJ = json_pack("[f, f]", (double) box.pos.x, (double) box.pos.y); + Vec pos = box.pos.div(RACK_GRID_SIZE).round(); + json_t *posJ = json_pack("[i, i]", (int) pos.x, (int) pos.y); json_object_set_new(rootJ, "pos", posJ); // params json_t *paramsJ = json_array(); @@ -99,7 +100,13 @@ void ModuleWidget::fromJson(json_t *rootJ) { json_t *posJ = json_object_get(rootJ, "pos"); double x, y; json_unpack(posJ, "[F, F]", &x, &y); - box.pos = Vec(x, y); + Vec pos = Vec(x, y); + if (legacy && legacy <= 1) { + box.pos = pos; + } + else { + box.pos = pos.mult(RACK_GRID_SIZE); + } // params json_t *paramsJ = json_object_get(rootJ, "params"); diff --git a/src/gui.cpp b/src/gui.cpp index 6a940374..e614a77f 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -27,6 +27,7 @@ #include #endif + namespace rack { GLFWwindow *gWindow = NULL;