From 499ceb024f88e3280efdac4973e2574c26ecbc07 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 15 Oct 2018 17:32:58 -0400 Subject: [PATCH] Remove math namespace --- include/WidgetState.hpp | 12 ++--- include/app/LedDisplay.hpp | 6 +-- include/app/ModuleWidget.hpp | 2 +- include/app/RackWidget.hpp | 6 +-- include/app/SVGPanel.hpp | 2 +- include/app/SVGSlider.hpp | 2 +- include/app/WireWidget.hpp | 4 +- include/app/common.hpp | 6 +-- include/color.hpp | 6 +-- include/dsp/minblep.hpp | 2 +- include/dsp/vumeter.hpp | 2 +- include/event.hpp | 10 ++-- include/helpers.hpp | 18 +++---- include/math.hpp | 14 +++-- include/rack.hpp | 11 ---- include/rack0.hpp | 2 +- include/string.hpp | 73 ++++---------------------- include/ui/IconButton.hpp | 2 +- include/ui/List.hpp | 2 +- include/ui/Menu.hpp | 6 +-- include/ui/MenuEntry.hpp | 2 +- include/ui/ProgressBar.hpp | 2 +- include/ui/ScrollWidget.hpp | 20 +++---- include/ui/Slider.hpp | 2 +- include/ui/TextField.hpp | 6 +-- include/widgets/QuantityWidget.hpp | 4 +- include/widgets/SVGWidget.hpp | 4 +- include/widgets/TransformWidget.hpp | 4 +- include/widgets/Widget.hpp | 19 +++---- include/widgets/ZoomWidget.hpp | 4 +- include/window.hpp | 10 ++-- src/Core/MIDICCToCVInterface.cpp | 4 +- src/Core/MIDIToCVInterface.cpp | 2 +- src/Core/MIDITriggerToCVInterface.cpp | 2 +- src/WidgetState.cpp | 12 ++--- src/app/AudioWidget.cpp | 12 ++--- src/app/CircularShadow.cpp | 2 +- src/app/Knob.cpp | 2 +- src/app/LedDisplay.cpp | 10 ++-- src/app/MidiWidget.cpp | 4 +- src/app/ModuleBrowser.cpp | 16 +++--- src/app/ModuleLightWidget.cpp | 2 +- src/app/ModuleWidget.cpp | 10 ++-- src/app/MultiLightWidget.cpp | 2 +- src/app/ParamWidget.cpp | 2 +- src/app/PluginManagerWidget.cpp | 6 +-- src/app/Port.cpp | 2 +- src/app/RackScene.cpp | 4 +- src/app/RackScrollWidget.cpp | 4 +- src/app/RackWidget.cpp | 40 +++++++------- src/app/SVGKnob.cpp | 12 ++--- src/app/SVGPort.cpp | 6 +-- src/app/SVGSlider.cpp | 2 +- src/app/SVGSwitch.cpp | 4 +- src/app/Toolbar.cpp | 8 +-- src/app/WireWidget.cpp | 22 ++++---- src/audio.cpp | 12 ++--- src/bridge.cpp | 2 +- src/gamepad.cpp | 6 +-- src/keyboard.cpp | 2 +- src/midi.cpp | 2 +- src/plugin.cpp | 4 +- src/settings.cpp | 10 ++-- src/string.cpp | 75 +++++++++++++++++++++++++++ src/svg.cpp | 22 ++++---- src/widgets/FramebufferWidget.cpp | 14 ++--- src/widgets/Widget.cpp | 10 ++-- src/window.cpp | 26 +++++----- 68 files changed, 323 insertions(+), 319 deletions(-) create mode 100644 src/string.cpp diff --git a/include/WidgetState.hpp b/include/WidgetState.hpp index 7b458b46..4be926d8 100644 --- a/include/WidgetState.hpp +++ b/include/WidgetState.hpp @@ -18,13 +18,13 @@ struct WidgetState { /** For middle-click dragging */ Widget *scrollWidget = NULL; - void handleButton(math::Vec pos, int button, int action, int mods); - void handleHover(math::Vec pos, math::Vec mouseDelta); + void handleButton(Vec pos, int button, int action, int mods); + void handleHover(Vec pos, Vec mouseDelta); void handleLeave(); - void handleScroll(math::Vec pos, math::Vec scrollDelta); - void handleText(math::Vec pos, int codepoint); - void handleKey(math::Vec pos, int key, int scancode, int action, int mods); - void handleDrop(math::Vec pos, std::vector paths); + void handleScroll(Vec pos, Vec scrollDelta); + void handleText(Vec pos, int codepoint); + void handleKey(Vec pos, int key, int scancode, int action, int mods); + void handleDrop(Vec pos, std::vector paths); void handleZoom(); /** Prepares a widget for deletion */ void finalizeWidget(Widget *w); diff --git a/include/app/LedDisplay.hpp b/include/app/LedDisplay.hpp index 71a6d85c..c4208b0a 100644 --- a/include/app/LedDisplay.hpp +++ b/include/app/LedDisplay.hpp @@ -17,7 +17,7 @@ struct LedDisplaySeparator : TransparentWidget { struct LedDisplayChoice : TransparentWidget { std::string text; std::shared_ptr font; - math::Vec textOffset; + Vec textOffset; NVGcolor color; LedDisplayChoice(); void draw(NVGcontext *vg) override; @@ -26,11 +26,11 @@ struct LedDisplayChoice : TransparentWidget { struct LedDisplayTextField : TextField { std::shared_ptr font; - math::Vec textOffset; + Vec textOffset; NVGcolor color; LedDisplayTextField(); void draw(NVGcontext *vg) override; - int getTextPosition(math::Vec mousePos) override; + int getTextPosition(Vec mousePos) override; }; diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index 80187274..d6986da0 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -64,7 +64,7 @@ struct ModuleWidget : OpaqueWidget { void draw(NVGcontext *vg) override; void drawShadow(NVGcontext *vg); - math::Vec dragPos; + Vec dragPos; void onHover(event::Hover &e) override; void onButton(event::Button &e) override; void onHoverKey(event::HoverKey &e) override; diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index c0faf7d0..cc6100ba 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -15,7 +15,7 @@ struct RackWidget : OpaqueWidget { // Only put WireWidgets in here WireContainer *wireContainer; std::string lastPath; - math::Vec lastMousePos; + Vec lastMousePos; bool lockModules = false; RackWidget(); @@ -45,9 +45,9 @@ struct RackWidget : OpaqueWidget { void deleteModule(ModuleWidget *m); void cloneModule(ModuleWidget *m); /** Sets a module's box if non-colliding. Returns true if set */ - bool requestModuleBox(ModuleWidget *m, math::Rect box); + bool requestModuleBox(ModuleWidget *m, Rect box); /** Moves a module to the closest non-colliding position */ - bool requestModuleBoxNearest(ModuleWidget *m, math::Rect box); + bool requestModuleBoxNearest(ModuleWidget *m, Rect box); void step() override; void draw(NVGcontext *vg) override; diff --git a/include/app/SVGPanel.hpp b/include/app/SVGPanel.hpp index 51d5e33b..624c94da 100644 --- a/include/app/SVGPanel.hpp +++ b/include/app/SVGPanel.hpp @@ -19,7 +19,7 @@ struct PanelBorder : TransparentWidget { struct SVGPanel : FramebufferWidget { void step() override { - if (math::isNear(gPixelRatio, 1.0)) { + if (isNear(gPixelRatio, 1.0)) { // Small details draw poorly at low DPI, so oversample when drawing to the framebuffer oversample = 2.0; } diff --git a/include/app/SVGSlider.hpp b/include/app/SVGSlider.hpp index 4de27504..714ea9e2 100644 --- a/include/app/SVGSlider.hpp +++ b/include/app/SVGSlider.hpp @@ -12,7 +12,7 @@ struct SVGSlider : Knob, FramebufferWidget { SVGWidget *background; SVGWidget *handle; /** Intermediate positions will be interpolated between these positions */ - math::Vec minHandlePos, maxHandlePos; + Vec minHandlePos, maxHandlePos; SVGSlider(); void setSVGs(std::shared_ptr backgroundSVG, std::shared_ptr handleSVG); diff --git a/include/app/WireWidget.hpp b/include/app/WireWidget.hpp index fa2649ab..8647dc6c 100644 --- a/include/app/WireWidget.hpp +++ b/include/app/WireWidget.hpp @@ -20,8 +20,8 @@ struct WireWidget : OpaqueWidget { ~WireWidget(); /** Synchronizes the plugged state of the widget to the owned wire */ void updateWire(); - math::Vec getOutputPos(); - math::Vec getInputPos(); + Vec getOutputPos(); + Vec getInputPos(); json_t *toJson(); void fromJson(json_t *rootJ); void draw(NVGcontext *vg) override; diff --git a/include/app/common.hpp b/include/app/common.hpp index fe8233b2..096afd0b 100644 --- a/include/app/common.hpp +++ b/include/app/common.hpp @@ -15,7 +15,7 @@ inline float in2px(float in) { return in * SVG_DPI; } -inline math::Vec in2px(math::Vec in) { +inline Vec in2px(Vec in) { return in.mult(SVG_DPI); } @@ -24,7 +24,7 @@ inline float mm2px(float mm) { return mm * (SVG_DPI / MM_PER_IN); } -inline math::Vec mm2px(math::Vec mm) { +inline Vec mm2px(Vec mm) { return mm.mult(SVG_DPI / MM_PER_IN); } @@ -32,7 +32,7 @@ inline math::Vec mm2px(math::Vec mm) { // 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; -static const math::Vec RACK_GRID_SIZE = math::Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT); +static const Vec RACK_GRID_SIZE = Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT); static const std::string PRESET_FILTERS = "VCV Rack module preset (.vcvm):vcvm"; static const std::string PATCH_FILTERS = "VCV Rack patch (.vcv):vcv"; diff --git a/include/color.hpp b/include/color.hpp index 47f19b56..5203d29c 100644 --- a/include/color.hpp +++ b/include/color.hpp @@ -23,7 +23,7 @@ static const NVGcolor CYAN = nvgRGB(0x00, 0xff, 0xff); inline NVGcolor clip(NVGcolor a) { for (int i = 0; i < 4; i++) - a.rgba[i] = math::clamp(a.rgba[i], 0.f, 1.f); + a.rgba[i] = clamp(a.rgba[i], 0.f, 1.f); return a; } @@ -87,9 +87,9 @@ inline std::string toHexString(NVGcolor c) { uint8_t b = std::round(c.b * 255); uint8_t a = std::round(c.a * 255); if (a == 255) - return string::stringf("#%02x%02x%02x", r, g, b); + return string::f("#%02x%02x%02x", r, g, b); else - return string::stringf("#%02x%02x%02x%02x", r, g, b, a); + return string::f("#%02x%02x%02x%02x", r, g, b, a); } diff --git a/include/dsp/minblep.hpp b/include/dsp/minblep.hpp index b56114c9..9c489ad9 100644 --- a/include/dsp/minblep.hpp +++ b/include/dsp/minblep.hpp @@ -23,7 +23,7 @@ struct MinBLEP { for (int j = 0; j < 2*ZERO_CROSSINGS; j++) { float minblepIndex = ((float)j - p) * oversample; int index = (pos + j) % (2*ZERO_CROSSINGS); - buf[index] += dx * (-1.0 + math::interpolateLinear(minblep, minblepIndex)); + buf[index] += dx * (-1.0 + interpolateLinear(minblep, minblepIndex)); } } float shift() { diff --git a/include/dsp/vumeter.hpp b/include/dsp/vumeter.hpp index a66bd82b..fcdfc0dc 100644 --- a/include/dsp/vumeter.hpp +++ b/include/dsp/vumeter.hpp @@ -23,7 +23,7 @@ struct VUMeter { return (dBScaled >= 0.0) ? 1.0 : 0.0; } else { - return math::clamp(dBScaled + i, 0.0, 1.0); + return clamp(dBScaled + i, 0.0, 1.0); } } }; diff --git a/include/event.hpp b/include/event.hpp index f1337873..7922ba4e 100644 --- a/include/event.hpp +++ b/include/event.hpp @@ -24,7 +24,7 @@ struct Event { struct Position { /** The pixel coordinate where the event occurred, relative to the Widget it is called on. */ - math::Vec pos; + Vec pos; }; @@ -52,7 +52,7 @@ If `target` is set, other events may occur on that Widget. */ struct Hover : Event, Position { /** Change in mouse position since the last frame. Can be zero. */ - math::Vec mouseDelta; + Vec mouseDelta; }; @@ -89,7 +89,7 @@ Recurses until consumed. */ struct HoverScroll : Event, Position { /** Change of scroll wheel position. */ - math::Vec scrollDelta; + Vec scrollDelta; }; @@ -147,7 +147,7 @@ struct DragEnd : Event { `mouseDelta` may be zero. */ struct DragMove : Event { - math::Vec mouseDelta; + Vec mouseDelta; }; @@ -156,7 +156,7 @@ Must consume to allow DragEnter, DragLeave, and DragDrop to occur. */ struct DragHover : Event, Position { /** Change in mouse position since the last frame. Can be zero. */ - math::Vec mouseDelta; + Vec mouseDelta; }; /** Occurs when the mouse enters a Widget while dragging. diff --git a/include/helpers.hpp b/include/helpers.hpp index a5fd7968..ed291af1 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -36,14 +36,14 @@ Model *createModel(std::string author, std::string slug, std::string name, Tags. } template -TWidget *createWidget(math::Vec pos) { +TWidget *createWidget(Vec pos) { TWidget *o = new TWidget; o->box.pos = pos; return o; } template -TParamWidget *createParam(math::Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { +TParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { TParamWidget *o = new TParamWidget; o->box.pos = pos; o->module = module; @@ -54,7 +54,7 @@ TParamWidget *createParam(math::Vec pos, Module *module, int paramId, float minV } template -TParamWidget *createParamCentered(math::Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { +TParamWidget *createParamCentered(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { TParamWidget *o = new TParamWidget; o->box.pos = pos.minus(o->box.size.div(2)); o->module = module; @@ -65,7 +65,7 @@ TParamWidget *createParamCentered(math::Vec pos, Module *module, int paramId, fl } template -TPort *createInput(math::Vec pos, Module *module, int inputId) { +TPort *createInput(Vec pos, Module *module, int inputId) { TPort *o = new TPort; o->box.pos = pos; o->module = module; @@ -75,7 +75,7 @@ TPort *createInput(math::Vec pos, Module *module, int inputId) { } template -TPort *createInputCentered(math::Vec pos, Module *module, int inputId) { +TPort *createInputCentered(Vec pos, Module *module, int inputId) { TPort *o = new TPort; o->box.pos = pos.minus(o->box.size.div(2)); o->module = module; @@ -85,7 +85,7 @@ TPort *createInputCentered(math::Vec pos, Module *module, int inputId) { } template -TPort *createOutput(math::Vec pos, Module *module, int outputId) { +TPort *createOutput(Vec pos, Module *module, int outputId) { TPort *o = new TPort; o->box.pos = pos; o->module = module; @@ -95,7 +95,7 @@ TPort *createOutput(math::Vec pos, Module *module, int outputId) { } template -TPort *createOutputCentered(math::Vec pos, Module *module, int outputId) { +TPort *createOutputCentered(Vec pos, Module *module, int outputId) { TPort *o = new TPort; o->box.pos = pos.minus(o->box.size.div(2)); o->module = module; @@ -105,7 +105,7 @@ TPort *createOutputCentered(math::Vec pos, Module *module, int outputId) { } template -TModuleLightWidget *createLight(math::Vec pos, Module *module, int firstLightId) { +TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) { TModuleLightWidget *o = new TModuleLightWidget; o->box.pos = pos; o->module = module; @@ -114,7 +114,7 @@ TModuleLightWidget *createLight(math::Vec pos, Module *module, int firstLightId) } template -TModuleLightWidget *createLightCentered(math::Vec pos, Module *module, int firstLightId) { +TModuleLightWidget *createLightCentered(Vec pos, Module *module, int firstLightId) { TModuleLightWidget *o = new TModuleLightWidget; o->box.pos = pos.minus(o->box.size.div(2)); o->module = module; diff --git a/include/math.hpp b/include/math.hpp index 52683a3a..ac43fe61 100644 --- a/include/math.hpp +++ b/include/math.hpp @@ -4,7 +4,6 @@ namespace rack { -namespace math { //////////////////// // basic integer functions @@ -265,8 +264,8 @@ struct Rect { Rect r; r.pos.x = clampBetween(pos.x, bound.pos.x, bound.pos.x + bound.size.x); r.pos.y = clampBetween(pos.y, bound.pos.y, bound.pos.y + bound.size.y); - r.size.x = rack::math::clamp(pos.x + size.x, bound.pos.x, bound.pos.x + bound.size.x) - r.pos.x; - r.size.y = rack::math::clamp(pos.y + size.y, bound.pos.y, bound.pos.y + bound.size.y) - r.pos.y; + r.size.x = rack::clamp(pos.x + size.x, bound.pos.x, bound.pos.x + bound.size.x) - r.pos.x; + r.size.y = rack::clamp(pos.y + size.y, bound.pos.y, bound.pos.y + bound.size.y) - r.pos.y; return r; } /** Nudges the position to fix inside a bounding box */ @@ -307,18 +306,17 @@ struct Rect { inline Vec Vec::clamp(Rect bound) const { return Vec( - rack::math::clamp(x, bound.pos.x, bound.pos.x + bound.size.x), - rack::math::clamp(y, bound.pos.y, bound.pos.y + bound.size.y)); + rack::clamp(x, bound.pos.x, bound.pos.x + bound.size.x), + rack::clamp(y, bound.pos.y, bound.pos.y + bound.size.y)); } inline Vec Vec::clampBetween(Rect bound) const { return Vec( - rack::math::clampBetween(x, bound.pos.x, bound.pos.x + bound.size.x), - rack::math::clampBetween(y, bound.pos.y, bound.pos.y + bound.size.y)); + rack::clampBetween(x, bound.pos.x, bound.pos.x + bound.size.x), + rack::clampBetween(y, bound.pos.y, bound.pos.y + bound.size.y)); } inline Vec Vec::clamp2(Rect bound) const {return clampBetween(bound);} -} // namespace math } // namespace rack diff --git a/include/rack.hpp b/include/rack.hpp index f7d759ab..397bf06e 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -16,14 +16,3 @@ #include "app.hpp" #include "ui.hpp" #include "helpers.hpp" - - -namespace rack { - - -// Adopt some sub-namespaces into the main namespace for convenience -using namespace math; -using string::stringf; - - -} // namespace rack diff --git a/include/rack0.hpp b/include/rack0.hpp index f91309c8..bf3754fd 100644 --- a/include/rack0.hpp +++ b/include/rack0.hpp @@ -110,7 +110,7 @@ DEPRECATED static const NVGcolor COLOR_DARK_PANEL = SCHEME_DARK_PANEL; //////////////////// template -DEPRECATED TScrew *createScrew(math::Vec pos) { +DEPRECATED TScrew *createScrew(Vec pos) { return createWidget(pos); } diff --git a/include/string.hpp b/include/string.hpp index 788b1ed5..4524775c 100644 --- a/include/string.hpp +++ b/include/string.hpp @@ -10,70 +10,19 @@ namespace string { /** Converts a printf format string and optional arguments into a std::string */ -inline std::string stringf(const char *format, ...) { - va_list args; - va_start(args, format); - // Compute size of required buffer - int size = vsnprintf(NULL, 0, format, args); - va_end(args); - if (size < 0) - return ""; - // Create buffer - std::string s; - s.resize(size); - va_start(args, format); - vsnprintf(&s[0], size + 1, format, args); - va_end(args); - return s; -} - -inline std::string lowercase(std::string s) { - std::transform(s.begin(), s.end(), s.begin(), ::tolower); - return s; -} - -inline std::string uppercase(std::string s) { - std::transform(s.begin(), s.end(), s.begin(), ::toupper); - return s; -} - +std::string f(const char *format, ...); +/** Replaces all characters to lowercase letters */ +std::string lowercase(std::string s); +/** Replaces all characters to uppercase letters */ +std::string uppercase(std::string s); /** Truncates and adds "..." to a string, not exceeding `len` characters */ -inline std::string ellipsize(std::string s, size_t len) { - if (s.size() <= len) - return s; - else - return s.substr(0, len - 3) + "..."; -} - -inline bool startsWith(std::string str, std::string prefix) { - return str.substr(0, prefix.size()) == prefix; -} - -inline bool endsWith(std::string str, std::string suffix) { - return str.substr(str.size() - suffix.size(), suffix.size()) == suffix; -} - +std::string ellipsize(std::string s, size_t len); +bool startsWith(std::string str, std::string prefix); +bool endsWith(std::string str, std::string suffix); /** Extracts portions of a path */ -inline std::string directory(std::string path) { - char *pathDup = strdup(path.c_str()); - std::string directory = dirname(pathDup); - free(pathDup); - return directory; -} - -inline std::string filename(std::string path) { - char *pathDup = strdup(path.c_str()); - std::string filename = basename(pathDup); - free(pathDup); - return filename; -} - -inline std::string extension(std::string path) { - const char *ext = strrchr(filename(path).c_str(), '.'); - if (!ext) - return ""; - return ext + 1; -} +std::string directory(std::string path); +std::string filename(std::string path); +std::string extension(std::string path); struct CaseInsensitiveCompare { bool operator()(const std::string &a, const std::string &b) const { diff --git a/include/ui/IconButton.hpp b/include/ui/IconButton.hpp index 360e65f5..f2f62fb6 100644 --- a/include/ui/IconButton.hpp +++ b/include/ui/IconButton.hpp @@ -17,7 +17,7 @@ struct IconButton : Button { addChild(fw); sw = new SVGWidget; - sw->box.pos = math::Vec(2, 2); + sw->box.pos = Vec(2, 2); fw->addChild(sw); } diff --git a/include/ui/List.hpp b/include/ui/List.hpp index 9516605c..74d79189 100644 --- a/include/ui/List.hpp +++ b/include/ui/List.hpp @@ -15,7 +15,7 @@ struct List : OpaqueWidget { if (!child->visible) continue; // Increment height, set position of child - child->box.pos = math::Vec(0.0, box.size.y); + child->box.pos = Vec(0.0, box.size.y); box.size.y += child->box.size.y; // Resize width of child child->box.size.x = box.size.x; diff --git a/include/ui/Menu.hpp b/include/ui/Menu.hpp index d0c1d583..6935d4d6 100644 --- a/include/ui/Menu.hpp +++ b/include/ui/Menu.hpp @@ -12,7 +12,7 @@ struct Menu : OpaqueWidget { MenuEntry *activeEntry = NULL; Menu() { - box.size = math::Vec(0, 0); + box.size = Vec(0, 0); } ~Menu() { @@ -42,12 +42,12 @@ struct Menu : OpaqueWidget { Widget::step(); // Set positions of children - box.size = math::Vec(0, 0); + box.size = Vec(0, 0); for (Widget *child : children) { if (!child->visible) continue; // Increment height, set position of child - child->box.pos = math::Vec(0, box.size.y); + child->box.pos = Vec(0, box.size.y); box.size.y += child->box.size.y; // Increase width based on maximum width of child if (child->box.size.x > box.size.x) { diff --git a/include/ui/MenuEntry.hpp b/include/ui/MenuEntry.hpp index 1636efda..0521eb51 100644 --- a/include/ui/MenuEntry.hpp +++ b/include/ui/MenuEntry.hpp @@ -7,7 +7,7 @@ namespace rack { struct MenuEntry : OpaqueWidget { MenuEntry() { - box.size = math::Vec(0, BND_WIDGET_HEIGHT); + box.size = Vec(0, BND_WIDGET_HEIGHT); } }; diff --git a/include/ui/ProgressBar.hpp b/include/ui/ProgressBar.hpp index c2382014..20e73fe6 100644 --- a/include/ui/ProgressBar.hpp +++ b/include/ui/ProgressBar.hpp @@ -11,7 +11,7 @@ struct ProgressBar : QuantityWidget { } void draw(NVGcontext *vg) override { - float progress = math::rescale(value, minValue, maxValue, 0.0, 1.0); + float progress = rescale(value, minValue, maxValue, 0.0, 1.0); bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL, BND_DEFAULT, progress, getText().c_str(), NULL); } }; diff --git a/include/ui/ScrollWidget.hpp b/include/ui/ScrollWidget.hpp index 3f63681c..4628dc5f 100644 --- a/include/ui/ScrollWidget.hpp +++ b/include/ui/ScrollWidget.hpp @@ -18,7 +18,7 @@ struct ScrollBar : OpaqueWidget { float size = 0.0; ScrollBar() { - box.size = math::Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); + box.size = Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); } void draw(NVGcontext *vg) override { @@ -44,7 +44,7 @@ struct ScrollWidget : OpaqueWidget { Widget *container; ScrollBar *horizontalScrollBar; ScrollBar *verticalScrollBar; - math::Vec offset; + Vec offset; ScrollWidget() { container = new Widget; @@ -61,8 +61,8 @@ struct ScrollWidget : OpaqueWidget { addChild(verticalScrollBar); } - void scrollTo(math::Rect r) { - math::Rect bound = math::Rect::fromMinMax(r.getBottomRight().minus(box.size), r.pos); + void scrollTo(Rect r) { + Rect bound = Rect::fromMinMax(r.getBottomRight().minus(box.size), r.pos); offset = offset.clampBetween(bound); } @@ -76,8 +76,8 @@ struct ScrollWidget : OpaqueWidget { Widget::step(); // Clamp scroll offset - math::Vec containerCorner = container->getChildrenBoundingBox().getBottomRight(); - math::Rect containerBox = math::Rect(math::Vec(0, 0), containerCorner.minus(box.size)); + Vec containerCorner = container->getChildrenBoundingBox().getBottomRight(); + Rect containerBox = Rect(Vec(0, 0), containerCorner.minus(box.size)); offset = offset.clamp(containerBox); // Lock offset to top/left if no scrollbar will display if (containerBox.size.x < 0.0) @@ -89,9 +89,9 @@ struct ScrollWidget : OpaqueWidget { container->box.pos = offset.neg().round(); // Update scrollbar offsets and sizes - math::Vec viewportSize = container->getChildrenBoundingBox().getBottomRight(); - math::Vec scrollbarOffset = offset.div(viewportSize.minus(box.size)); - math::Vec scrollbarSize = box.size.div(viewportSize); + Vec viewportSize = container->getChildrenBoundingBox().getBottomRight(); + Vec scrollbarOffset = offset.div(viewportSize.minus(box.size)); + Vec scrollbarSize = box.size.div(viewportSize); horizontalScrollBar->visible = (0.0 < scrollbarSize.x && scrollbarSize.x < 1.0); verticalScrollBar->visible = (0.0 < scrollbarSize.y && scrollbarSize.y < 1.0); @@ -101,7 +101,7 @@ struct ScrollWidget : OpaqueWidget { verticalScrollBar->size = scrollbarSize.y; // Resize scroll bars - math::Vec inner = math::Vec(box.size.x - verticalScrollBar->box.size.x, box.size.y - horizontalScrollBar->box.size.y); + Vec inner = Vec(box.size.x - verticalScrollBar->box.size.x, box.size.y - horizontalScrollBar->box.size.y); horizontalScrollBar->box.pos.y = inner.y; verticalScrollBar->box.pos.x = inner.x; horizontalScrollBar->box.size.x = verticalScrollBar->visible ? inner.x : box.size.x; diff --git a/include/ui/Slider.hpp b/include/ui/Slider.hpp index 08100c8b..533552e1 100644 --- a/include/ui/Slider.hpp +++ b/include/ui/Slider.hpp @@ -16,7 +16,7 @@ struct Slider : OpaqueWidget, QuantityWidget { } void draw(NVGcontext *vg) override { - float progress = math::rescale(value, minValue, maxValue, 0.0, 1.0); + float progress = rescale(value, minValue, maxValue, 0.0, 1.0); bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, getText().c_str(), NULL); } diff --git a/include/ui/TextField.hpp b/include/ui/TextField.hpp index 9661e9d7..2d4e0860 100644 --- a/include/ui/TextField.hpp +++ b/include/ui/TextField.hpp @@ -183,8 +183,8 @@ struct TextField : OpaqueWidget { } break; } - cursor = math::clamp(cursor, 0, (int) text.size()); - selection = math::clamp(selection, 0, (int) text.size()); + cursor = clamp(cursor, 0, (int) text.size()); + selection = clamp(selection, 0, (int) text.size()); e.target = this; } @@ -210,7 +210,7 @@ struct TextField : OpaqueWidget { onChange(eChange); } - virtual int getTextPosition(math::Vec mousePos) { + virtual int getTextPosition(Vec mousePos) { return bndTextFieldTextPosition(gVg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str(), mousePos.x, mousePos.y); } }; diff --git a/include/widgets/QuantityWidget.hpp b/include/widgets/QuantityWidget.hpp index 46f2b442..a72838d7 100644 --- a/include/widgets/QuantityWidget.hpp +++ b/include/widgets/QuantityWidget.hpp @@ -24,7 +24,7 @@ struct QuantityWidget : virtual Widget { } void setValue(float value) { - this->value = math::clampBetween(value, minValue, maxValue); + this->value = clampBetween(value, minValue, maxValue); event::Change e; onChange(e); } @@ -41,7 +41,7 @@ struct QuantityWidget : virtual Widget { /** Generates the display value */ std::string getText() { - return string::stringf("%s: %.*f%s", label.c_str(), precision, value, unit.c_str()); + return string::f("%s: %.*f%s", label.c_str(), precision, value, unit.c_str()); } }; diff --git a/include/widgets/SVGWidget.hpp b/include/widgets/SVGWidget.hpp index 418a8765..f1168201 100644 --- a/include/widgets/SVGWidget.hpp +++ b/include/widgets/SVGWidget.hpp @@ -12,10 +12,10 @@ struct SVGWidget : virtual Widget { /** Sets the box size to the svg image size */ void wrap() { if (svg && svg->handle) { - box.size = math::Vec(svg->handle->width, svg->handle->height); + box.size = Vec(svg->handle->width, svg->handle->height); } else { - box.size = math::Vec(); + box.size = Vec(); } } diff --git a/include/widgets/TransformWidget.hpp b/include/widgets/TransformWidget.hpp index 9c784935..fe7bc60f 100644 --- a/include/widgets/TransformWidget.hpp +++ b/include/widgets/TransformWidget.hpp @@ -18,7 +18,7 @@ struct TransformWidget : virtual Widget { nvgTransformIdentity(transform); } - void translate(math::Vec delta) { + void translate(Vec delta) { float t[6]; nvgTransformTranslate(t, delta.x, delta.y); nvgTransformPremultiply(transform, t); @@ -30,7 +30,7 @@ struct TransformWidget : virtual Widget { nvgTransformPremultiply(transform, t); } - void scale(math::Vec s) { + void scale(Vec s) { float t[6]; nvgTransformScale(t, s.x, s.y); nvgTransformPremultiply(transform, t); diff --git a/include/widgets/Widget.hpp b/include/widgets/Widget.hpp index 1c6f8918..388c8277 100644 --- a/include/widgets/Widget.hpp +++ b/include/widgets/Widget.hpp @@ -10,20 +10,13 @@ namespace rack { -namespace event { - -struct Event; - -} // namespace event - - /** A node in the 2D scene graph It is recommended to inherit virtually from Widget instead of directly. e.g. `struct MyWidget : virtual Widget {}` */ struct Widget { /** Stores position and size */ - math::Rect box = math::Rect(math::Vec(), math::Vec(INFINITY, INFINITY)); + Rect box = Rect(Vec(), Vec(INFINITY, INFINITY)); /** Automatically set when Widget is added as a child to another Widget */ Widget *parent = NULL; std::list children; @@ -34,15 +27,15 @@ struct Widget { virtual ~Widget(); - virtual math::Rect getChildrenBoundingBox(); + virtual Rect getChildrenBoundingBox(); /** Returns `v` transformed into the coordinate system of `relative` */ - virtual math::Vec getRelativeOffset(math::Vec v, Widget *relative); + virtual Vec getRelativeOffset(Vec v, Widget *relative); /** Returns `v` transformed into world coordinates */ - math::Vec getAbsoluteOffset(math::Vec v) { + Vec getAbsoluteOffset(Vec v) { return getRelativeOffset(v, NULL); } - /** Returns a subset of the given math::Rect bounded by the box of this widget and all ancestors */ - virtual math::Rect getViewport(math::Rect r); + /** Returns a subset of the given Rect bounded by the box of this widget and all ancestors */ + virtual Rect getViewport(Rect r); template T *getAncestorOfType() { diff --git a/include/widgets/ZoomWidget.hpp b/include/widgets/ZoomWidget.hpp index 8b9a8106..01373ebd 100644 --- a/include/widgets/ZoomWidget.hpp +++ b/include/widgets/ZoomWidget.hpp @@ -8,11 +8,11 @@ namespace rack { struct ZoomWidget : virtual Widget { float zoom = 1.f; - math::Vec getRelativeOffset(math::Vec v, Widget *relative) override { + Vec getRelativeOffset(Vec v, Widget *relative) override { return Widget::getRelativeOffset(v.mult(zoom), relative); } - math::Rect getViewport(math::Rect r) override { + Rect getViewport(Rect r) override { r.pos = r.pos.mult(zoom); r.size = r.size.mult(zoom); r = Widget::getViewport(r); diff --git a/include/window.hpp b/include/window.hpp index 5b862fe1..0af28d00 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -57,7 +57,7 @@ This is not equal to gPixelRatio in general. extern float gWindowRatio; extern bool gAllowCursorLock; extern int gGuiFrame; -extern math::Vec gMousePos; +extern Vec gMousePos; void windowInit(); @@ -68,10 +68,10 @@ void windowCursorLock(); void windowCursorUnlock(); bool windowIsModPressed(); bool windowIsShiftPressed(); -math::Vec windowGetWindowSize(); -void windowSetWindowSize(math::Vec size); -math::Vec windowGetWindowPos(); -void windowSetWindowPos(math::Vec pos); +Vec windowGetWindowSize(); +void windowSetWindowSize(Vec size); +Vec windowGetWindowPos(); +void windowSetWindowPos(Vec pos); bool windowIsMaximized(); void windowSetTheme(NVGcolor bg, NVGcolor fg); void windowSetFullScreen(bool fullScreen); diff --git a/src/Core/MIDICCToCVInterface.cpp b/src/Core/MIDICCToCVInterface.cpp index 59642278..7eb742b6 100644 --- a/src/Core/MIDICCToCVInterface.cpp +++ b/src/Core/MIDICCToCVInterface.cpp @@ -122,13 +122,13 @@ struct MidiCcChoice : GridChoice { void step() override { if (module->learningId == id) { if (0 <= focusCc) - text = string::stringf("%d", focusCc); + text = string::f("%d", focusCc); else text = "LRN"; color.a = 0.5; } else { - text = string::stringf("%d", module->learnedCcs[id]); + text = string::f("%d", module->learnedCcs[id]); color.a = 1.0; if (gWidgetState->selectedWidget == this) gWidgetState->selectedWidget = NULL; diff --git a/src/Core/MIDIToCVInterface.cpp b/src/Core/MIDIToCVInterface.cpp index 5a39bfcb..66e80b70 100644 --- a/src/Core/MIDIToCVInterface.cpp +++ b/src/Core/MIDIToCVInterface.cpp @@ -317,7 +317,7 @@ struct MIDIToCVInterfaceWidget : ModuleWidget { menu->addChild(construct()); for (int i = 0; i < 2; i++) { - ClockItem *item = createMenuItem(string::stringf("CLK %d rate", i + 1)); + ClockItem *item = createMenuItem(string::f("CLK %d rate", i + 1)); item->module = module; item->index = i; menu->addChild(item); diff --git a/src/Core/MIDITriggerToCVInterface.cpp b/src/Core/MIDITriggerToCVInterface.cpp index ad0cfb33..1a2fbc0a 100644 --- a/src/Core/MIDITriggerToCVInterface.cpp +++ b/src/Core/MIDITriggerToCVInterface.cpp @@ -169,7 +169,7 @@ struct MidiTrigChoice : GridChoice { }; int oct = note / 12 - 1; int semi = note % 12; - text = string::stringf("%s%d", noteNames[semi], oct); + text = string::f("%s%d", noteNames[semi], oct); color.a = 1.0; if (gWidgetState->selectedWidget == this) diff --git a/src/WidgetState.cpp b/src/WidgetState.cpp index 8252a747..f0127556 100644 --- a/src/WidgetState.cpp +++ b/src/WidgetState.cpp @@ -7,7 +7,7 @@ namespace rack { -void WidgetState::handleButton(math::Vec pos, int button, int action, int mods) { +void WidgetState::handleButton(Vec pos, int button, int action, int mods) { // event::Button event::Button eButton; eButton.pos = pos; @@ -74,7 +74,7 @@ void WidgetState::handleButton(math::Vec pos, int button, int action, int mods) } -void WidgetState::handleHover(math::Vec pos, math::Vec mouseDelta) { +void WidgetState::handleHover(Vec pos, Vec mouseDelta) { if (draggedWidget) { // event::DragMove event::DragMove eDragMove; @@ -148,7 +148,7 @@ void WidgetState::handleLeave() { hoveredWidget = NULL; } -void WidgetState::handleScroll(math::Vec pos, math::Vec scrollDelta) { +void WidgetState::handleScroll(Vec pos, Vec scrollDelta) { // event::HoverScroll event::HoverScroll eHoverScroll; eHoverScroll.pos = pos; @@ -156,7 +156,7 @@ void WidgetState::handleScroll(math::Vec pos, math::Vec scrollDelta) { rootWidget->onHoverScroll(eHoverScroll); } -void WidgetState::handleDrop(math::Vec pos, std::vector paths) { +void WidgetState::handleDrop(Vec pos, std::vector paths) { // event::PathDrop event::PathDrop ePathDrop; ePathDrop.pos = pos; @@ -164,7 +164,7 @@ void WidgetState::handleDrop(math::Vec pos, std::vector paths) { rootWidget->onPathDrop(ePathDrop); } -void WidgetState::handleText(math::Vec pos, int codepoint) { +void WidgetState::handleText(Vec pos, int codepoint) { if (selectedWidget) { // event::SelectText event::SelectText eSelectText; @@ -181,7 +181,7 @@ void WidgetState::handleText(math::Vec pos, int codepoint) { rootWidget->onHoverText(eHoverText); } -void WidgetState::handleKey(math::Vec pos, int key, int scancode, int action, int mods) { +void WidgetState::handleKey(Vec pos, int key, int scancode, int action, int mods) { if (selectedWidget) { // event::SelectKey event::SelectKey eSelectKey; diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index f788cef4..6e5082be 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -107,13 +107,13 @@ struct AudioSampleRateChoice : LedDisplayChoice { AudioSampleRateItem *item = new AudioSampleRateItem; item->audioIO = audioWidget->audioIO; item->sampleRate = sampleRate; - item->text = string::stringf("%d Hz", sampleRate); + item->text = string::f("%d Hz", sampleRate); item->rightText = CHECKMARK(item->sampleRate == audioWidget->audioIO->sampleRate); menu->addChild(item); } } void step() override { - text = string::stringf("%g kHz", audioWidget->audioIO->sampleRate / 1000.f); + text = string::f("%g kHz", audioWidget->audioIO->sampleRate / 1000.f); } }; @@ -140,21 +140,21 @@ struct AudioBlockSizeChoice : LedDisplayChoice { item->audioIO = audioWidget->audioIO; item->blockSize = blockSize; float latency = (float) blockSize / audioWidget->audioIO->sampleRate * 1000.0; - item->text = string::stringf("%d (%.1f ms)", blockSize, latency); + item->text = string::f("%d (%.1f ms)", blockSize, latency); item->rightText = CHECKMARK(item->blockSize == audioWidget->audioIO->blockSize); menu->addChild(item); } } void step() override { - text = string::stringf("%d", audioWidget->audioIO->blockSize); + text = string::f("%d", audioWidget->audioIO->blockSize); } }; AudioWidget::AudioWidget() { - box.size = mm2px(math::Vec(44, 28)); + box.size = mm2px(Vec(44, 28)); - math::Vec pos = math::Vec(); + Vec pos = Vec(); AudioDriverChoice *driverChoice = createWidget(pos); driverChoice->audioWidget = this; diff --git a/src/app/CircularShadow.cpp b/src/app/CircularShadow.cpp index d816ed26..80e24e1d 100644 --- a/src/app/CircularShadow.cpp +++ b/src/app/CircularShadow.cpp @@ -15,7 +15,7 @@ void CircularShadow::draw(NVGcontext *vg) { nvgBeginPath(vg); nvgRect(vg, -blurRadius, -blurRadius, box.size.x + 2*blurRadius, box.size.y + 2*blurRadius); - math::Vec center = box.size.div(2.0); + Vec center = box.size.div(2.0); float radius = center.x; NVGcolor icol = nvgRGBAf(0.0, 0.0, 0.0, opacity); NVGcolor ocol = nvgRGBAf(0.0, 0.0, 0.0, 0.0); diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index 0e67fe31..71c2f829 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -36,7 +36,7 @@ void Knob::onDragMove(event::DragMove &e) { if (windowIsModPressed()) delta /= 16.f; dragValue += delta; - dragValue = math::clampBetween(dragValue, minValue, maxValue); + dragValue = clampBetween(dragValue, minValue, maxValue); if (snap) setValue(std::round(dragValue)); else diff --git a/src/app/LedDisplay.cpp b/src/app/LedDisplay.cpp index 0c5efe74..9ab4a719 100644 --- a/src/app/LedDisplay.cpp +++ b/src/app/LedDisplay.cpp @@ -18,7 +18,7 @@ void LedDisplay::draw(NVGcontext *vg) { LedDisplaySeparator::LedDisplaySeparator() { - box.size = math::Vec(); + box.size = Vec(); } void LedDisplaySeparator::draw(NVGcontext *vg) { @@ -32,10 +32,10 @@ void LedDisplaySeparator::draw(NVGcontext *vg) { LedDisplayChoice::LedDisplayChoice() { - box.size = mm2px(math::Vec(0, 28.0 / 3)); + box.size = mm2px(Vec(0, 28.0 / 3)); font = Font::load(asset::global("res/fonts/ShareTechMono-Regular.ttf")); color = nvgRGB(0xff, 0xd7, 0x14); - textOffset = math::Vec(10, 18); + textOffset = Vec(10, 18); } void LedDisplayChoice::draw(NVGcontext *vg) { @@ -65,7 +65,7 @@ void LedDisplayChoice::onButton(event::Button &e) { LedDisplayTextField::LedDisplayTextField() { font = Font::load(asset::global("res/fonts/ShareTechMono-Regular.ttf")); color = nvgRGB(0xff, 0xd7, 0x14); - textOffset = math::Vec(5, 5); + textOffset = Vec(5, 5); } @@ -96,7 +96,7 @@ void LedDisplayTextField::draw(NVGcontext *vg) { nvgResetScissor(vg); } -int LedDisplayTextField::getTextPosition(math::Vec mousePos) { +int LedDisplayTextField::getTextPosition(Vec mousePos) { bndSetFont(font->handle); int textPos = bndIconLabelTextPosition(gVg, textOffset.x, textOffset.y, box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, diff --git a/src/app/MidiWidget.cpp b/src/app/MidiWidget.cpp index d6c2b945..66d8819f 100644 --- a/src/app/MidiWidget.cpp +++ b/src/app/MidiWidget.cpp @@ -111,9 +111,9 @@ struct MidiChannelChoice : LedDisplayChoice { MidiWidget::MidiWidget() { - box.size = mm2px(math::Vec(44, 28)); + box.size = mm2px(Vec(44, 28)); - math::Vec pos = math::Vec(); + Vec pos = Vec(); MidiDriverChoice *driverChoice = createWidget(pos); driverChoice->midiWidget = this; diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index 10a82fcb..9cecb728 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -58,7 +58,7 @@ struct SeparatorItem : OpaqueWidget { void setText(std::string text) { clearChildren(); - Label *label = createWidget