Browse Source

Move SVG_DPI and mm2px() to svg.hpp.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
6ffea7d25d
4 changed files with 41 additions and 41 deletions
  1. +1
    -24
      include/app/common.hpp
  2. +14
    -14
      include/componentlibrary.hpp
  3. +24
    -0
      include/svg.hpp
  4. +2
    -3
      src/svg.cpp

+ 1
- 24
include/app/common.hpp View File

@@ -2,8 +2,8 @@
#include <jansson.h>

#include <common.hpp>
#include <math.hpp>
#include <ui/common.hpp>
#include <svg.hpp> // for mm2px(), etc


namespace rack {
@@ -14,29 +14,6 @@ namespace rack {
namespace app {


static const float SVG_DPI = 75.f;
static const float MM_PER_IN = 25.4f;


/** Converts inch measurements to pixels */
inline float in2px(float in) {
return in * SVG_DPI;
}

inline math::Vec in2px(math::Vec in) {
return in.mult(SVG_DPI);
}

/** Converts millimeter measurements to pixels */
inline float mm2px(float mm) {
return mm * (SVG_DPI / MM_PER_IN);
}

inline math::Vec mm2px(math::Vec mm) {
return mm.mult(SVG_DPI / MM_PER_IN);
}


// A 1HPx3U module should be 15x380 pixels. Thus the width of a module should be a factor of 15.
static const float RACK_GRID_WIDTH = 15;
static const float RACK_GRID_HEIGHT = 380;


+ 14
- 14
include/componentlibrary.hpp View File

@@ -133,7 +133,7 @@ typedef TRedGreenBlueLight<> RedGreenBlueLight;
template <typename TBase>
struct LargeLight : TBase {
LargeLight() {
this->box.size = app::mm2px(math::Vec(5.179, 5.179));
this->box.size = mm2px(math::Vec(5.179, 5.179));
}
};

@@ -141,7 +141,7 @@ struct LargeLight : TBase {
template <typename TBase>
struct MediumLight : TBase {
MediumLight() {
this->box.size = app::mm2px(math::Vec(3.176, 3.176));
this->box.size = mm2px(math::Vec(3.176, 3.176));
}
};

@@ -149,7 +149,7 @@ struct MediumLight : TBase {
template <typename TBase>
struct SmallLight : TBase {
SmallLight() {
this->box.size = app::mm2px(math::Vec(2.176, 2.176));
this->box.size = mm2px(math::Vec(2.176, 2.176));
}
};

@@ -157,7 +157,7 @@ struct SmallLight : TBase {
template <typename TBase>
struct TinyLight : TBase {
TinyLight() {
this->box.size = app::mm2px(math::Vec(1.088, 1.088));
this->box.size = mm2px(math::Vec(1.088, 1.088));
}
};

@@ -193,18 +193,18 @@ template <typename TBase>
struct LEDBezelLight : TBase {
LEDBezelLight() {
this->bgColor = color::BLACK_TRANSPARENT;
this->box.size = app::mm2px(math::Vec(6.0, 6.0));
this->box.size = mm2px(math::Vec(6.0, 6.0));
}
};

/** A light to displayed over PB61303. Must add a color by subclassing or templating.
Don't add this as a child of the PB61303 itself. Instead, just place it over it as a sibling in the scene graph, offset by app::mm2px(math::Vec(0.5, 0.5)).
Don't add this as a child of the PB61303 itself. Instead, just place it over it as a sibling in the scene graph, offset by mm2px(math::Vec(0.5, 0.5)).
*/
template <typename TBase>
struct PB61303Light : TBase {
PB61303Light() {
this->bgColor = color::BLACK_TRANSPARENT;
this->box.size = app::mm2px(math::Vec(9.0, 9.0));
this->box.size = mm2px(math::Vec(9.0, 9.0));
}
};

@@ -529,8 +529,8 @@ struct BefacoSlidePot : app::SvgSlider {

struct LEDSlider : app::SvgSlider {
LEDSlider() {
maxHandlePos = app::mm2px(math::Vec(0.738, 0.738).plus(math::Vec(2, 0)));
minHandlePos = app::mm2px(math::Vec(0.738, 22.078).plus(math::Vec(2, 0)));
maxHandlePos = mm2px(math::Vec(0.738, 0.738).plus(math::Vec(2, 0)));
minHandlePos = mm2px(math::Vec(0.738, 22.078).plus(math::Vec(2, 0)));
setBackgroundSvg(Svg::load(asset::system("res/ComponentLibrary/LEDSlider.svg")));
}
};
@@ -569,8 +569,8 @@ struct LEDSliderWhite : LEDSlider {
struct LEDSliderHorizontal : app::SvgSlider {
LEDSliderHorizontal() {
horizontal = true;
maxHandlePos = app::mm2px(math::Vec(22.078, 0.738).plus(math::Vec(0, 2)));
minHandlePos = app::mm2px(math::Vec(0.738, 0.738).plus(math::Vec(0, 2)));
maxHandlePos = mm2px(math::Vec(22.078, 0.738).plus(math::Vec(0, 2)));
minHandlePos = mm2px(math::Vec(0.738, 0.738).plus(math::Vec(0, 2)));
setBackgroundSvg(Svg::load(asset::system("res/ComponentLibrary/LEDSliderHorizontal.svg")));
}
};
@@ -602,7 +602,7 @@ template <typename TLightBase = RedLight>
struct LEDLightSlider : LightSlider<LEDSlider, TLightBase> {
LEDLightSlider() {
this->setHandleSvg(Svg::load(asset::system("res/ComponentLibrary/LEDSliderHandle.svg")));
this->light->box.size = app::mm2px(math::Vec(1.524, 3.276));
this->light->box.size = mm2px(math::Vec(1.524, 3.276));
}
};

@@ -610,7 +610,7 @@ template <typename TLightBase = RedLight>
struct LEDLightSliderHorizontal : LightSlider<LEDSliderHorizontal, TLightBase> {
LEDLightSliderHorizontal() {
this->setHandleSvg(Svg::load(asset::system("res/ComponentLibrary/LEDSliderHorizontalHandle.svg")));
this->light->box.size = app::mm2px(math::Vec(3.276, 1.524));
this->light->box.size = mm2px(math::Vec(3.276, 1.524));
}
};

@@ -768,7 +768,7 @@ struct ScrewBlack : app::SvgScrew {
struct SegmentDisplay : widget::Widget {
int lightsLen = 0;
bool vertical = false;
float margin = app::mm2px(0.5);
float margin = mm2px(0.5);

void draw(const DrawArgs& args) override {
// Background


+ 24
- 0
include/svg.hpp View File

@@ -5,11 +5,35 @@
#include <nanosvg.h>

#include <common.hpp>
#include <math.hpp>


namespace rack {


static const float SVG_DPI = 75.f;
static const float MM_PER_IN = 25.4f;


/** Converts inch measurements to pixels */
inline float in2px(float in) {
return in * SVG_DPI;
}

inline math::Vec in2px(math::Vec in) {
return in.mult(SVG_DPI);
}

/** Converts millimeter measurements to pixels */
inline float mm2px(float mm) {
return mm * (SVG_DPI / MM_PER_IN);
}

inline math::Vec mm2px(math::Vec mm) {
return mm.mult(SVG_DPI / MM_PER_IN);
}


struct Svg {
NSVGimage* handle = NULL;



+ 2
- 3
src/svg.cpp View File

@@ -1,7 +1,6 @@
#include <svg.hpp>
#include <map>
#include <math.hpp>
#include <app/common.hpp> // for app::SVG_DPI


// #define DEBUG_ONLY(x) x
@@ -18,7 +17,7 @@ Svg::~Svg() {


void Svg::loadFile(const std::string& filename) {
handle = nsvgParseFromFile(filename.c_str(), "px", app::SVG_DPI);
handle = nsvgParseFromFile(filename.c_str(), "px", SVG_DPI);
if (handle) {
INFO("Loaded SVG %s", filename.c_str());
}
@@ -31,7 +30,7 @@ void Svg::loadFile(const std::string& filename) {
void Svg::loadString(const std::string& str) {
// nsvgParse modifies the input string
std::string strCopy = str;
handle = nsvgParse(&strCopy[0], "px", app::SVG_DPI);
handle = nsvgParse(&strCopy[0], "px", SVG_DPI);
if (handle) {
INFO("Loaded SVG");
}


Loading…
Cancel
Save