Browse Source

ModuleWidget serializes pos in rack grid coordinates instead of pixel

coordinates
tags/v0.6.0
Andrew Belt 7 years ago
parent
commit
d55d460c1f
4 changed files with 22 additions and 17 deletions
  1. +12
    -2
      include/app.hpp
  2. +0
    -13
      include/widgets.hpp
  3. +9
    -2
      src/app/ModuleWidget.cpp
  4. +1
    -0
      src/gui.cpp

+ 12
- 2
include/app.hpp View File

@@ -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;


+ 0
- 13
include/widgets.hpp View File

@@ -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
////////////////////


+ 9
- 2
src/app/ModuleWidget.cpp View File

@@ -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");


+ 1
- 0
src/gui.cpp View File

@@ -27,6 +27,7 @@
#include <ApplicationServices/ApplicationServices.h>
#endif


namespace rack {

GLFWwindow *gWindow = NULL;


Loading…
Cancel
Save