diff --git a/include/app/common.hpp b/include/app/common.hpp index c722018f..5350cad9 100644 --- a/include/app/common.hpp +++ b/include/app/common.hpp @@ -2,8 +2,8 @@ #include #include -#include #include +#include // 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; diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index f675bf24..c6889830 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -133,7 +133,7 @@ typedef TRedGreenBlueLight<> RedGreenBlueLight; template 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 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 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 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 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 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 struct LEDLightSlider : LightSlider { 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 struct LEDLightSliderHorizontal : LightSlider { 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 diff --git a/include/svg.hpp b/include/svg.hpp index dd97032a..2a71a99d 100644 --- a/include/svg.hpp +++ b/include/svg.hpp @@ -5,11 +5,35 @@ #include #include +#include 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; diff --git a/src/svg.cpp b/src/svg.cpp index cccd01de..1d6fb9cc 100644 --- a/src/svg.cpp +++ b/src/svg.cpp @@ -1,7 +1,6 @@ #include #include #include -#include // 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"); }