| @@ -20,7 +20,7 @@ struct LedDisplaySeparator : TransparentWidget { | |||
| struct LedDisplayChoice : TransparentWidget { | |||
| std::string text; | |||
| std::shared_ptr<Font> font; | |||
| Vec textOffset; | |||
| math::Vec textOffset; | |||
| NVGcolor color; | |||
| LedDisplayChoice(); | |||
| void draw(NVGcontext *vg) override; | |||
| @@ -29,11 +29,11 @@ struct LedDisplayChoice : TransparentWidget { | |||
| struct LedDisplayTextField : TextField { | |||
| std::shared_ptr<Font> font; | |||
| Vec textOffset; | |||
| math::Vec textOffset; | |||
| NVGcolor color; | |||
| LedDisplayTextField(); | |||
| void draw(NVGcontext *vg) override; | |||
| int getTextPosition(Vec mousePos) override; | |||
| int getTextPosition(math::Vec mousePos) override; | |||
| }; | |||
| @@ -70,7 +70,7 @@ struct ModuleWidget : OpaqueWidget { | |||
| void draw(NVGcontext *vg) override; | |||
| void drawShadow(NVGcontext *vg); | |||
| Vec dragPos; | |||
| math::Vec dragPos; | |||
| void onHover(event::Hover &e) override; | |||
| void onButton(event::Button &e) override; | |||
| void onHoverKey(event::HoverKey &e) override; | |||
| @@ -16,7 +16,7 @@ struct RackWidget : OpaqueWidget { | |||
| // Only put WireWidgets in here | |||
| WireContainer *wireContainer; | |||
| std::string lastPath; | |||
| Vec lastMousePos; | |||
| math::Vec lastMousePos; | |||
| bool lockModules = false; | |||
| RackWidget(); | |||
| @@ -46,9 +46,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, Rect box); | |||
| bool requestModuleBox(ModuleWidget *m, math::Rect box); | |||
| /** Moves a module to the closest non-colliding position */ | |||
| bool requestModuleBoxNearest(ModuleWidget *m, Rect box); | |||
| bool requestModuleBoxNearest(ModuleWidget *m, math::Rect box); | |||
| void step() override; | |||
| void draw(NVGcontext *vg) override; | |||
| @@ -23,7 +23,7 @@ struct PanelBorder : TransparentWidget { | |||
| struct SVGPanel : FramebufferWidget { | |||
| void step() override { | |||
| if (isNear(context()->window->pixelRatio, 1.0)) { | |||
| if (math::isNear(context()->window->pixelRatio, 1.0)) { | |||
| // Small details draw poorly at low DPI, so oversample when drawing to the framebuffer | |||
| oversample = 2.0; | |||
| } | |||
| @@ -15,7 +15,7 @@ struct SVGSlider : Knob, FramebufferWidget { | |||
| SVGWidget *background; | |||
| SVGWidget *handle; | |||
| /** Intermediate positions will be interpolated between these positions */ | |||
| Vec minHandlePos, maxHandlePos; | |||
| math::Vec minHandlePos, maxHandlePos; | |||
| SVGSlider(); | |||
| void setSVGs(std::shared_ptr<SVG> backgroundSVG, std::shared_ptr<SVG> handleSVG); | |||
| @@ -23,8 +23,8 @@ struct WireWidget : OpaqueWidget { | |||
| ~WireWidget(); | |||
| /** Synchronizes the plugged state of the widget to the owned wire */ | |||
| void updateWire(); | |||
| Vec getOutputPos(); | |||
| Vec getInputPos(); | |||
| math::Vec getOutputPos(); | |||
| math::Vec getInputPos(); | |||
| json_t *toJson(); | |||
| void fromJson(json_t *rootJ); | |||
| void draw(NVGcontext *vg) override; | |||
| @@ -20,7 +20,7 @@ inline float in2px(float in) { | |||
| return in * SVG_DPI; | |||
| } | |||
| inline Vec in2px(Vec in) { | |||
| inline math::Vec in2px(math::Vec in) { | |||
| return in.mult(SVG_DPI); | |||
| } | |||
| @@ -29,7 +29,7 @@ inline float mm2px(float mm) { | |||
| return mm * (SVG_DPI / MM_PER_IN); | |||
| } | |||
| inline Vec mm2px(Vec mm) { | |||
| inline math::Vec mm2px(math::Vec mm) { | |||
| return mm.mult(SVG_DPI / MM_PER_IN); | |||
| } | |||
| @@ -37,7 +37,7 @@ inline Vec mm2px(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 Vec RACK_GRID_SIZE = Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT); | |||
| static const math::Vec RACK_GRID_SIZE = math::Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT); | |||
| extern const std::string PRESET_FILTERS; | |||
| extern const std::string PATCH_FILTERS; | |||
| @@ -325,9 +325,9 @@ struct BefacoTinyKnob : SVGKnob { | |||
| struct BefacoSlidePot : SVGSlider { | |||
| BefacoSlidePot() { | |||
| Vec margin = Vec(3.5, 3.5); | |||
| maxHandlePos = Vec(-1, -2).plus(margin); | |||
| minHandlePos = Vec(-1, 87).plus(margin); | |||
| math::Vec margin = math::Vec(3.5, 3.5); | |||
| maxHandlePos = math::Vec(-1, -2).plus(margin); | |||
| minHandlePos = math::Vec(-1, 87).plus(margin); | |||
| setSVGs(SVG::load(asset::system("res/ComponentLibrary/BefacoSlidePot.svg")), SVG::load(asset::system("res/ComponentLibrary/BefacoSlidePotHandle.svg"))); | |||
| background->box.pos = margin; | |||
| box.size = background->box.size.plus(margin.mult(2)); | |||
| @@ -336,8 +336,8 @@ struct BefacoSlidePot : SVGSlider { | |||
| struct LEDSlider : SVGSlider { | |||
| LEDSlider() { | |||
| maxHandlePos = mm2px(Vec(0.738, 0.738).plus(Vec(2, 0))); | |||
| minHandlePos = mm2px(Vec(0.738, 22.078).plus(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))); | |||
| setSVGs(SVG::load(asset::system("res/ComponentLibrary/LEDSlider.svg")), NULL); | |||
| } | |||
| }; | |||
| @@ -459,7 +459,7 @@ struct RGBLight : ModuleLightWidget { | |||
| template <typename BASE> | |||
| struct LargeLight : BASE { | |||
| LargeLight() { | |||
| this->box.size = mm2px(Vec(5.179, 5.179)); | |||
| this->box.size = mm2px(math::Vec(5.179, 5.179)); | |||
| } | |||
| }; | |||
| @@ -467,7 +467,7 @@ struct LargeLight : BASE { | |||
| template <typename BASE> | |||
| struct MediumLight : BASE { | |||
| MediumLight() { | |||
| this->box.size = mm2px(Vec(3.176, 3.176)); | |||
| this->box.size = mm2px(math::Vec(3.176, 3.176)); | |||
| } | |||
| }; | |||
| @@ -475,7 +475,7 @@ struct MediumLight : BASE { | |||
| template <typename BASE> | |||
| struct SmallLight : BASE { | |||
| SmallLight() { | |||
| this->box.size = mm2px(Vec(2.176, 2.176)); | |||
| this->box.size = mm2px(math::Vec(2.176, 2.176)); | |||
| } | |||
| }; | |||
| @@ -483,7 +483,7 @@ struct SmallLight : BASE { | |||
| template <typename BASE> | |||
| struct TinyLight : BASE { | |||
| TinyLight() { | |||
| this->box.size = mm2px(Vec(1.088, 1.088)); | |||
| this->box.size = mm2px(math::Vec(1.088, 1.088)); | |||
| } | |||
| }; | |||
| @@ -492,18 +492,18 @@ template <typename BASE> | |||
| struct LEDBezelLight : BASE { | |||
| LEDBezelLight() { | |||
| this->bgColor = color::BLACK_TRANSPARENT; | |||
| this->box.size = mm2px(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 mm2px(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 BASE> | |||
| struct PB61303Light : BASE { | |||
| PB61303Light() { | |||
| this->bgColor = color::BLACK_TRANSPARENT; | |||
| this->box.size = mm2px(Vec(9.0, 9.0)); | |||
| this->box.size = mm2px(math::Vec(9.0, 9.0)); | |||
| } | |||
| }; | |||
| @@ -23,7 +23,7 @@ struct SchmittTrigger { | |||
| /** Updates the state of the Schmitt Trigger given a value. | |||
| Returns true if triggered, i.e. the value increases from 0 to 1. | |||
| If different trigger thresholds are needed, use | |||
| process(rescale(in, low, high, 0.f, 1.f)) | |||
| process(math::rescale(in, low, high, 0.f, 1.f)) | |||
| for example. | |||
| */ | |||
| bool process(float in) { | |||
| @@ -56,7 +56,7 @@ struct SlewLimiter { | |||
| this->fall = fall; | |||
| } | |||
| float process(float in) { | |||
| out = clamp(in, out - fall, out + rise); | |||
| out = math::clamp(in, out - fall, out + rise); | |||
| return out; | |||
| } | |||
| }; | |||
| @@ -22,7 +22,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 + interpolateLinear(minblep, minblepIndex)); | |||
| buf[index] += dx * (-1.0 + math::interpolateLinear(minblep, minblepIndex)); | |||
| } | |||
| } | |||
| float shift() { | |||
| @@ -22,7 +22,7 @@ struct VUMeter { | |||
| return (dBScaled >= 0.0) ? 1.0 : 0.0; | |||
| } | |||
| else { | |||
| return clamp(dBScaled + i, 0.0, 1.0); | |||
| return math::clamp(dBScaled + i, 0.0, 1.0); | |||
| } | |||
| } | |||
| }; | |||
| @@ -25,7 +25,7 @@ struct Event { | |||
| struct Position { | |||
| /** The pixel coordinate where the event occurred, relative to the Widget it is called on. */ | |||
| Vec pos; | |||
| math::Vec pos; | |||
| }; | |||
| @@ -53,7 +53,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. */ | |||
| Vec mouseDelta; | |||
| math::Vec mouseDelta; | |||
| }; | |||
| @@ -90,7 +90,7 @@ Recurses until consumed. | |||
| */ | |||
| struct HoverScroll : Event, Position { | |||
| /** Change of scroll wheel position. */ | |||
| Vec scrollDelta; | |||
| math::Vec scrollDelta; | |||
| }; | |||
| @@ -148,7 +148,7 @@ struct DragEnd : Event { | |||
| `mouseDelta` may be zero. | |||
| */ | |||
| struct DragMove : Event { | |||
| Vec mouseDelta; | |||
| math::Vec mouseDelta; | |||
| }; | |||
| @@ -157,7 +157,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. */ | |||
| Vec mouseDelta; | |||
| math::Vec mouseDelta; | |||
| }; | |||
| /** Occurs when the mouse enters a Widget while dragging. | |||
| @@ -217,13 +217,13 @@ struct Context { | |||
| /** For middle-click dragging */ | |||
| Widget *scrollWidget = NULL; | |||
| void handleButton(Vec pos, int button, int action, int mods); | |||
| void handleHover(Vec pos, Vec mouseDelta); | |||
| void handleButton(math::Vec pos, int button, int action, int mods); | |||
| void handleHover(math::Vec pos, math::Vec mouseDelta); | |||
| void handleLeave(); | |||
| 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<std::string> paths); | |||
| 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<std::string> paths); | |||
| void handleZoom(); | |||
| /** Prepares a widget for deletion */ | |||
| void finalizeWidget(Widget *w); | |||
| @@ -40,14 +40,14 @@ Model *createModel(std::string author, std::string slug, std::string name, Tags. | |||
| } | |||
| template <class TWidget> | |||
| TWidget *createWidget(Vec pos) { | |||
| TWidget *createWidget(math::Vec pos) { | |||
| TWidget *o = new TWidget; | |||
| o->box.pos = pos; | |||
| return o; | |||
| } | |||
| template <class TParamWidget> | |||
| TParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { | |||
| TParamWidget *createParam(math::Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { | |||
| TParamWidget *o = new TParamWidget; | |||
| o->box.pos = pos; | |||
| o->quantity->module = module; | |||
| @@ -58,7 +58,7 @@ TParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, | |||
| } | |||
| template <class TParamWidget> | |||
| TParamWidget *createParamCentered(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { | |||
| TParamWidget *createParamCentered(math::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->quantity->module = module; | |||
| @@ -69,7 +69,7 @@ TParamWidget *createParamCentered(Vec pos, Module *module, int paramId, float mi | |||
| } | |||
| template <class TPort> | |||
| TPort *createInput(Vec pos, Module *module, int inputId) { | |||
| TPort *createInput(math::Vec pos, Module *module, int inputId) { | |||
| TPort *o = new TPort; | |||
| o->box.pos = pos; | |||
| o->module = module; | |||
| @@ -79,7 +79,7 @@ TPort *createInput(Vec pos, Module *module, int inputId) { | |||
| } | |||
| template <class TPort> | |||
| TPort *createInputCentered(Vec pos, Module *module, int inputId) { | |||
| TPort *createInputCentered(math::Vec pos, Module *module, int inputId) { | |||
| TPort *o = new TPort; | |||
| o->box.pos = pos.minus(o->box.size.div(2)); | |||
| o->module = module; | |||
| @@ -89,7 +89,7 @@ TPort *createInputCentered(Vec pos, Module *module, int inputId) { | |||
| } | |||
| template <class TPort> | |||
| TPort *createOutput(Vec pos, Module *module, int outputId) { | |||
| TPort *createOutput(math::Vec pos, Module *module, int outputId) { | |||
| TPort *o = new TPort; | |||
| o->box.pos = pos; | |||
| o->module = module; | |||
| @@ -99,7 +99,7 @@ TPort *createOutput(Vec pos, Module *module, int outputId) { | |||
| } | |||
| template <class TPort> | |||
| TPort *createOutputCentered(Vec pos, Module *module, int outputId) { | |||
| TPort *createOutputCentered(math::Vec pos, Module *module, int outputId) { | |||
| TPort *o = new TPort; | |||
| o->box.pos = pos.minus(o->box.size.div(2)); | |||
| o->module = module; | |||
| @@ -109,7 +109,7 @@ TPort *createOutputCentered(Vec pos, Module *module, int outputId) { | |||
| } | |||
| template <class TModuleLightWidget> | |||
| TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) { | |||
| TModuleLightWidget *createLight(math::Vec pos, Module *module, int firstLightId) { | |||
| TModuleLightWidget *o = new TModuleLightWidget; | |||
| o->box.pos = pos; | |||
| o->module = module; | |||
| @@ -118,7 +118,7 @@ TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) { | |||
| } | |||
| template <class TModuleLightWidget> | |||
| TModuleLightWidget *createLightCentered(Vec pos, Module *module, int firstLightId) { | |||
| TModuleLightWidget *createLightCentered(math::Vec pos, Module *module, int firstLightId) { | |||
| TModuleLightWidget *o = new TModuleLightWidget; | |||
| o->box.pos = pos.minus(o->box.size.div(2)); | |||
| o->module = module; | |||
| @@ -4,6 +4,7 @@ | |||
| namespace rack { | |||
| namespace math { | |||
| //////////////////// | |||
| // basic integer functions | |||
| @@ -270,8 +271,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::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; | |||
| r.size.x = math::clamp(pos.x + size.x, bound.pos.x, bound.pos.x + bound.size.x) - r.pos.x; | |||
| r.size.y = math::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 */ | |||
| @@ -312,17 +313,18 @@ struct Rect { | |||
| inline Vec Vec::clamp(Rect bound) const { | |||
| return Vec( | |||
| rack::clamp(x, bound.pos.x, bound.pos.x + bound.size.x), | |||
| rack::clamp(y, bound.pos.y, bound.pos.y + bound.size.y)); | |||
| math::clamp(x, bound.pos.x, bound.pos.x + bound.size.x), | |||
| math::clamp(y, bound.pos.y, bound.pos.y + bound.size.y)); | |||
| } | |||
| inline Vec Vec::clampBetween(Rect bound) const { | |||
| return Vec( | |||
| rack::clampBetween(x, bound.pos.x, bound.pos.x + bound.size.x), | |||
| rack::clampBetween(y, bound.pos.y, bound.pos.y + bound.size.y)); | |||
| math::clampBetween(x, bound.pos.x, bound.pos.x + bound.size.x), | |||
| math::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 | |||
| @@ -81,3 +81,11 @@ | |||
| #include "plugin/Plugin.hpp" | |||
| #include "plugin/Model.hpp" | |||
| #include "plugin/callbacks.hpp" | |||
| namespace rack { | |||
| // Import namespace for convenience | |||
| using namespace math; | |||
| } // namespace rack | |||
| @@ -28,7 +28,7 @@ DEPRECATED inline float clamp2(float x, float a, float b) {return clampBetween(x | |||
| DEPRECATED inline int mini(int a, int b) {return std::min(a, b);} | |||
| DEPRECATED inline int maxi(int a, int b) {return std::max(a, b);} | |||
| DEPRECATED inline int clampi(int x, int min, int max) {return clamp(x, min, max);} | |||
| DEPRECATED inline int clampi(int x, int min, int max) {return math::clamp(x, min, max);} | |||
| DEPRECATED inline int absi(int a) {return std::abs(a);} | |||
| DEPRECATED inline int eucmodi(int a, int base) {return eucMod(a, base);} | |||
| DEPRECATED inline int log2i(int n) {return log2(n);} | |||
| @@ -36,11 +36,11 @@ DEPRECATED inline bool ispow2i(int n) {return isPow2(n);} | |||
| DEPRECATED inline float absf(float x) {return std::abs(x);} | |||
| DEPRECATED inline float sgnf(float x) {return sgn(x);} | |||
| DEPRECATED inline float eucmodf(float a, float base) {return eucMod(a, base);} | |||
| DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {return isNear(a, b, epsilon);} | |||
| DEPRECATED inline float clampf(float x, float min, float max) {return clamp(x, min, max);} | |||
| DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {return math::isNear(a, b, epsilon);} | |||
| DEPRECATED inline float clampf(float x, float min, float max) {return math::clamp(x, min, max);} | |||
| DEPRECATED inline float clamp2f(float x, float min, float max) {return clampBetween(x, min, max);} | |||
| DEPRECATED inline float chopf(float x, float eps) {return chop(x, eps);} | |||
| DEPRECATED inline float rescalef(float x, float a, float b, float yMin, float yMax) {return rescale(x, a, b, yMin, yMax);} | |||
| DEPRECATED inline float rescalef(float x, float a, float b, float yMin, float yMax) {return math::rescale(x, a, b, yMin, yMax);} | |||
| DEPRECATED inline float crossf(float a, float b, float frac) {return crossfade(a, b, frac);} | |||
| DEPRECATED inline float interpf(const float *p, float x) {return interpolateLinear(p, x);} | |||
| DEPRECATED inline void cmultf(float *cr, float *ci, float ar, float ai, float br, float bi) {return cmult(cr, ci, ar, ai, br, bi);} | |||
| @@ -109,7 +109,7 @@ DEPRECATED static const NVGcolor COLOR_DARK_PANEL = SCHEME_DARK_PANEL; | |||
| //////////////////// | |||
| template <class TScrew> | |||
| DEPRECATED TScrew *createScrew(Vec pos) { | |||
| DEPRECATED TScrew *createScrew(math::Vec pos) { | |||
| return createWidget<TScrew>(pos); | |||
| } | |||
| @@ -20,7 +20,7 @@ struct IconButton : Button { | |||
| addChild(fw); | |||
| sw = new SVGWidget; | |||
| sw->box.pos = Vec(2, 2); | |||
| sw->box.pos = math::Vec(2, 2); | |||
| fw->addChild(sw); | |||
| } | |||
| @@ -16,7 +16,7 @@ struct List : OpaqueWidget { | |||
| if (!child->visible) | |||
| continue; | |||
| // Increment height, set position of child | |||
| child->box.pos = Vec(0.0, box.size.y); | |||
| child->box.pos = math::Vec(0.0, box.size.y); | |||
| box.size.y += child->box.size.y; | |||
| // Resize width of child | |||
| child->box.size.x = box.size.x; | |||
| @@ -14,7 +14,7 @@ struct Menu : OpaqueWidget { | |||
| MenuEntry *activeEntry = NULL; | |||
| Menu() { | |||
| box.size = Vec(0, 0); | |||
| box.size = math::Vec(0, 0); | |||
| } | |||
| ~Menu() { | |||
| @@ -44,12 +44,12 @@ struct Menu : OpaqueWidget { | |||
| Widget::step(); | |||
| // Set positions of children | |||
| box.size = Vec(0, 0); | |||
| box.size = math::Vec(0, 0); | |||
| for (Widget *child : children) { | |||
| if (!child->visible) | |||
| continue; | |||
| // Increment height, set position of child | |||
| child->box.pos = Vec(0, box.size.y); | |||
| child->box.pos = math::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) { | |||
| @@ -8,7 +8,7 @@ namespace rack { | |||
| struct MenuEntry : OpaqueWidget { | |||
| MenuEntry() { | |||
| box.size = Vec(0, BND_WIDGET_HEIGHT); | |||
| box.size = math::Vec(0, BND_WIDGET_HEIGHT); | |||
| } | |||
| }; | |||
| @@ -95,12 +95,12 @@ struct Quantity { | |||
| /** Sets value from the range 0 to 1 */ | |||
| void setScaledValue(float scaledValue) { | |||
| setValue(rescale(scaledValue, 0.f, 1.f, getMinValue(), getMaxValue())); | |||
| setValue(math::rescale(scaledValue, 0.f, 1.f, getMinValue(), getMaxValue())); | |||
| } | |||
| /** Returns the value rescaled to the range 0 to 1 */ | |||
| float getScaledValue() { | |||
| return rescale(getValue(), getMinValue(), getMaxValue(), 0.f, 1.f); | |||
| return math::rescale(getValue(), getMinValue(), getMaxValue(), 0.f, 1.f); | |||
| } | |||
| /** The difference between the max and min values */ | |||
| @@ -20,7 +20,7 @@ struct ScrollBar : OpaqueWidget { | |||
| float size = 0.0; | |||
| ScrollBar() { | |||
| box.size = Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); | |||
| box.size = math::Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); | |||
| } | |||
| void draw(NVGcontext *vg) override { | |||
| @@ -46,7 +46,7 @@ struct ScrollWidget : OpaqueWidget { | |||
| Widget *container; | |||
| ScrollBar *horizontalScrollBar; | |||
| ScrollBar *verticalScrollBar; | |||
| Vec offset; | |||
| math::Vec offset; | |||
| ScrollWidget() { | |||
| container = new Widget; | |||
| @@ -63,8 +63,8 @@ struct ScrollWidget : OpaqueWidget { | |||
| addChild(verticalScrollBar); | |||
| } | |||
| void scrollTo(Rect r) { | |||
| Rect bound = Rect::fromMinMax(r.getBottomRight().minus(box.size), r.pos); | |||
| void scrollTo(math::Rect r) { | |||
| math::Rect bound = math::Rect::fromMinMax(r.getBottomRight().minus(box.size), r.pos); | |||
| offset = offset.clampBetween(bound); | |||
| } | |||
| @@ -78,8 +78,8 @@ struct ScrollWidget : OpaqueWidget { | |||
| Widget::step(); | |||
| // Clamp scroll offset | |||
| Vec containerCorner = container->getChildrenBoundingBox().getBottomRight(); | |||
| Rect containerBox = Rect(Vec(0, 0), containerCorner.minus(box.size)); | |||
| math::Vec containerCorner = container->getChildrenBoundingBox().getBottomRight(); | |||
| math::Rect containerBox = math::Rect(math::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) | |||
| @@ -91,9 +91,9 @@ struct ScrollWidget : OpaqueWidget { | |||
| container->box.pos = offset.neg().round(); | |||
| // Update scrollbar offsets and sizes | |||
| Vec viewportSize = container->getChildrenBoundingBox().getBottomRight(); | |||
| Vec scrollbarOffset = offset.div(viewportSize.minus(box.size)); | |||
| Vec scrollbarSize = box.size.div(viewportSize); | |||
| math::Vec viewportSize = container->getChildrenBoundingBox().getBottomRight(); | |||
| math::Vec scrollbarOffset = offset.div(viewportSize.minus(box.size)); | |||
| math::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); | |||
| @@ -103,7 +103,7 @@ struct ScrollWidget : OpaqueWidget { | |||
| verticalScrollBar->size = scrollbarSize.y; | |||
| // Resize scroll bars | |||
| Vec inner = Vec(box.size.x - verticalScrollBar->box.size.x, box.size.y - horizontalScrollBar->box.size.y); | |||
| math::Vec inner = math::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; | |||
| @@ -185,8 +185,8 @@ struct TextField : OpaqueWidget { | |||
| } break; | |||
| } | |||
| cursor = clamp(cursor, 0, (int) text.size()); | |||
| selection = clamp(selection, 0, (int) text.size()); | |||
| cursor = math::clamp(cursor, 0, (int) text.size()); | |||
| selection = math::clamp(selection, 0, (int) text.size()); | |||
| e.target = this; | |||
| } | |||
| @@ -212,7 +212,7 @@ struct TextField : OpaqueWidget { | |||
| onChange(eChange); | |||
| } | |||
| virtual int getTextPosition(Vec mousePos) { | |||
| virtual int getTextPosition(math::Vec mousePos) { | |||
| return bndTextFieldTextPosition(context()->window->vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str(), mousePos.x, mousePos.y); | |||
| } | |||
| }; | |||
| @@ -13,10 +13,10 @@ struct SVGWidget : VirtualWidget { | |||
| /** Sets the box size to the svg image size */ | |||
| void wrap() { | |||
| if (svg && svg->handle) { | |||
| box.size = Vec(svg->handle->width, svg->handle->height); | |||
| box.size = math::Vec(svg->handle->width, svg->handle->height); | |||
| } | |||
| else { | |||
| box.size = Vec(); | |||
| box.size = math::Vec(); | |||
| } | |||
| } | |||
| @@ -18,7 +18,7 @@ struct TransformWidget : VirtualWidget { | |||
| nvgTransformIdentity(transform); | |||
| } | |||
| void translate(Vec delta) { | |||
| void translate(math::Vec delta) { | |||
| float t[6]; | |||
| nvgTransformTranslate(t, delta.x, delta.y); | |||
| nvgTransformPremultiply(transform, t); | |||
| @@ -30,7 +30,7 @@ struct TransformWidget : VirtualWidget { | |||
| nvgTransformPremultiply(transform, t); | |||
| } | |||
| void scale(Vec s) { | |||
| void scale(math::Vec s) { | |||
| float t[6]; | |||
| nvgTransformScale(t, s.x, s.y); | |||
| nvgTransformPremultiply(transform, t); | |||
| @@ -16,7 +16,7 @@ e.g. `struct MyWidget : VirtualWidget {}` | |||
| */ | |||
| struct Widget { | |||
| /** Stores position and size */ | |||
| Rect box = Rect(Vec(), Vec(INFINITY, INFINITY)); | |||
| math::Rect box = math::Rect(math::Vec(), math::Vec(INFINITY, INFINITY)); | |||
| /** Automatically set when Widget is added as a child to another Widget */ | |||
| Widget *parent = NULL; | |||
| std::list<Widget*> children; | |||
| @@ -27,15 +27,15 @@ struct Widget { | |||
| virtual ~Widget(); | |||
| virtual Rect getChildrenBoundingBox(); | |||
| virtual math::Rect getChildrenBoundingBox(); | |||
| /** Returns `v` transformed into the coordinate system of `relative` */ | |||
| virtual Vec getRelativeOffset(Vec v, Widget *relative); | |||
| virtual math::Vec getRelativeOffset(math::Vec v, Widget *relative); | |||
| /** Returns `v` transformed into world coordinates */ | |||
| Vec getAbsoluteOffset(Vec v) { | |||
| math::Vec getAbsoluteOffset(math::Vec v) { | |||
| return getRelativeOffset(v, NULL); | |||
| } | |||
| /** Returns a subset of the given Rect bounded by the box of this widget and all ancestors */ | |||
| virtual Rect getViewport(Rect r); | |||
| /** 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); | |||
| template <class T> | |||
| T *getAncestorOfType() { | |||
| @@ -8,11 +8,11 @@ namespace rack { | |||
| struct ZoomWidget : VirtualWidget { | |||
| float zoom = 1.f; | |||
| Vec getRelativeOffset(Vec v, Widget *relative) override { | |||
| math::Vec getRelativeOffset(math::Vec v, Widget *relative) override { | |||
| return Widget::getRelativeOffset(v.mult(zoom), relative); | |||
| } | |||
| Rect getViewport(Rect r) override { | |||
| math::Rect getViewport(math::Rect r) override { | |||
| r.pos = r.pos.mult(zoom); | |||
| r.size = r.size.mult(zoom); | |||
| r = Widget::getViewport(r); | |||
| @@ -56,7 +56,7 @@ struct Window { | |||
| bool allowCursorLock = true; | |||
| int frame = 0; | |||
| /** The last known absolute mouse position in the window */ | |||
| Vec mousePos; | |||
| math::Vec mousePos; | |||
| std::shared_ptr<Font> uiFont; | |||
| struct Internal; | |||
| @@ -70,10 +70,10 @@ struct Window { | |||
| void cursorUnlock(); | |||
| bool isModPressed(); | |||
| bool isShiftPressed(); | |||
| Vec getWindowSize(); | |||
| void setWindowSize(Vec size); | |||
| Vec getWindowPos(); | |||
| void setWindowPos(Vec pos); | |||
| math::Vec getWindowSize(); | |||
| void setWindowSize(math::Vec size); | |||
| math::Vec getWindowPos(); | |||
| void setWindowPos(math::Vec pos); | |||
| bool isMaximized(); | |||
| void setFullScreen(bool fullScreen); | |||
| bool isFullScreen(); | |||
| @@ -152,9 +152,9 @@ struct AudioBlockSizeChoice : LedDisplayChoice { | |||
| AudioWidget::AudioWidget() { | |||
| box.size = mm2px(Vec(44, 28)); | |||
| box.size = mm2px(math::Vec(44, 28)); | |||
| Vec pos = Vec(); | |||
| math::Vec pos = math::Vec(); | |||
| AudioDriverChoice *driverChoice = createWidget<AudioDriverChoice>(pos); | |||
| driverChoice->audioWidget = this; | |||
| @@ -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); | |||
| Vec center = box.size.div(2.0); | |||
| math::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); | |||
| @@ -19,7 +19,7 @@ void LedDisplay::draw(NVGcontext *vg) { | |||
| LedDisplaySeparator::LedDisplaySeparator() { | |||
| box.size = Vec(); | |||
| box.size = math::Vec(); | |||
| } | |||
| void LedDisplaySeparator::draw(NVGcontext *vg) { | |||
| @@ -33,10 +33,10 @@ void LedDisplaySeparator::draw(NVGcontext *vg) { | |||
| LedDisplayChoice::LedDisplayChoice() { | |||
| box.size = mm2px(Vec(0, 28.0 / 3)); | |||
| box.size = mm2px(math::Vec(0, 28.0 / 3)); | |||
| font = Font::load(asset::system("res/fonts/ShareTechMono-Regular.ttf")); | |||
| color = nvgRGB(0xff, 0xd7, 0x14); | |||
| textOffset = Vec(10, 18); | |||
| textOffset = math::Vec(10, 18); | |||
| } | |||
| void LedDisplayChoice::draw(NVGcontext *vg) { | |||
| @@ -66,7 +66,7 @@ void LedDisplayChoice::onButton(event::Button &e) { | |||
| LedDisplayTextField::LedDisplayTextField() { | |||
| font = Font::load(asset::system("res/fonts/ShareTechMono-Regular.ttf")); | |||
| color = nvgRGB(0xff, 0xd7, 0x14); | |||
| textOffset = Vec(5, 5); | |||
| textOffset = math::Vec(5, 5); | |||
| } | |||
| @@ -97,7 +97,7 @@ void LedDisplayTextField::draw(NVGcontext *vg) { | |||
| nvgResetScissor(vg); | |||
| } | |||
| int LedDisplayTextField::getTextPosition(Vec mousePos) { | |||
| int LedDisplayTextField::getTextPosition(math::Vec mousePos) { | |||
| bndSetFont(font->handle); | |||
| int textPos = bndIconLabelTextPosition(context()->window->vg, textOffset.x, textOffset.y, | |||
| box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, | |||
| @@ -111,9 +111,9 @@ struct MidiChannelChoice : LedDisplayChoice { | |||
| MidiWidget::MidiWidget() { | |||
| box.size = mm2px(Vec(44, 28)); | |||
| box.size = mm2px(math::Vec(44, 28)); | |||
| Vec pos = Vec(); | |||
| math::Vec pos = math::Vec(); | |||
| MidiDriverChoice *driverChoice = createWidget<MidiDriverChoice>(pos); | |||
| driverChoice->midiWidget = this; | |||
| @@ -76,7 +76,7 @@ struct SeparatorItem : OpaqueWidget { | |||
| void setText(std::string text) { | |||
| clearChildren(); | |||
| Label *label = createWidget<Label>(Vec(0, 12 + itemMargin)); | |||
| Label *label = createWidget<Label>(math::Vec(0, 12 + itemMargin)); | |||
| label->text = text; | |||
| label->fontSize = 20; | |||
| label->color.a *= 0.5; | |||
| @@ -127,7 +127,7 @@ struct ModelItem : BrowserListItem { | |||
| assert(model); | |||
| this->model = model; | |||
| FavoriteRadioButton *favoriteButton = createWidget<FavoriteRadioButton>(Vec(8, itemMargin)); | |||
| FavoriteRadioButton *favoriteButton = createWidget<FavoriteRadioButton>(math::Vec(8, itemMargin)); | |||
| favoriteButton->box.size.x = 20; | |||
| addChild(favoriteButton); | |||
| @@ -141,7 +141,7 @@ struct ModelItem : BrowserListItem { | |||
| nameLabel->text = model->name; | |||
| addChild(nameLabel); | |||
| pluginLabel = createWidget<Label>(Vec(0, itemMargin)); | |||
| pluginLabel = createWidget<Label>(math::Vec(0, itemMargin)); | |||
| pluginLabel->alignment = Label::RIGHT_ALIGNMENT; | |||
| pluginLabel->text = model->plugin->slug + " " + model->plugin->version; | |||
| pluginLabel->color.a = 0.5; | |||
| @@ -172,7 +172,7 @@ struct AuthorItem : BrowserListItem { | |||
| void setAuthor(std::string author) { | |||
| clearChildren(); | |||
| this->author = author; | |||
| Label *authorLabel = createWidget<Label>(Vec(0, 0 + itemMargin)); | |||
| Label *authorLabel = createWidget<Label>(math::Vec(0, 0 + itemMargin)); | |||
| if (author.empty()) | |||
| authorLabel->text = "Show all modules"; | |||
| else | |||
| @@ -190,7 +190,7 @@ struct TagItem : BrowserListItem { | |||
| void setTag(ModelTag tag) { | |||
| clearChildren(); | |||
| this->tag = tag; | |||
| Label *tagLabel = createWidget<Label>(Vec(0, 0 + itemMargin)); | |||
| Label *tagLabel = createWidget<Label>(math::Vec(0, 0 + itemMargin)); | |||
| if (tag == NO_TAG) | |||
| tagLabel->text = "Show all tags"; | |||
| else | |||
| @@ -204,7 +204,7 @@ struct TagItem : BrowserListItem { | |||
| struct ClearFilterItem : BrowserListItem { | |||
| ClearFilterItem() { | |||
| Label *label = createWidget<Label>(Vec(0, 0 + itemMargin)); | |||
| Label *label = createWidget<Label>(math::Vec(0, 0 + itemMargin)); | |||
| label->text = "Back"; | |||
| addChild(label); | |||
| } | |||
| @@ -232,7 +232,7 @@ struct BrowserList : List { | |||
| void incrementSelection(int delta) { | |||
| selected += delta; | |||
| selected = clamp(selected, 0, countItems() - 1); | |||
| selected = math::clamp(selected, 0, countItems() - 1); | |||
| } | |||
| int countItems() { | |||
| @@ -313,7 +313,7 @@ struct ModuleBrowser : OpaqueWidget { | |||
| addChild(searchField); | |||
| moduleList = new BrowserList; | |||
| moduleList->box.size = Vec(box.size.x, 0.0); | |||
| moduleList->box.size = math::Vec(box.size.x, 0.0); | |||
| // Module Scroll | |||
| moduleScroll = new ScrollWidget; | |||
| @@ -11,7 +11,7 @@ void ModuleLightWidget::step() { | |||
| for (size_t i = 0; i < baseColors.size(); i++) { | |||
| float value = module->lights[firstLightId + i].getBrightness(); | |||
| value = clamp(value, 0.f, 1.f); | |||
| value = math::clamp(value, 0.f, 1.f); | |||
| values[i] = value; | |||
| } | |||
| setValues(values); | |||
| @@ -270,7 +270,7 @@ void ModuleWidget::draw(NVGcontext *vg) { | |||
| nvgFillColor(vg, nvgRGBf(1, 1, 1)); | |||
| nvgText(vg, 10.0, box.size.y - 6.0, cpuText.c_str(), NULL); | |||
| float p = clamp(module->cpuTime, 0.f, 1.f); | |||
| float p = math::clamp(module->cpuTime, 0.f, 1.f); | |||
| nvgBeginPath(vg); | |||
| nvgRect(vg, | |||
| 0, (1.f - p) * box.size.y, | |||
| @@ -286,7 +286,7 @@ void ModuleWidget::drawShadow(NVGcontext *vg) { | |||
| nvgBeginPath(vg); | |||
| float r = 20; // Blur radius | |||
| float c = 20; // Corner radius | |||
| Vec b = Vec(-10, 30); // Offset from each corner | |||
| math::Vec b = math::Vec(-10, 30); // Offset from each corner | |||
| nvgRect(vg, b.x - r, b.y - r, box.size.x - 2*b.x + 2*r, box.size.y - 2*b.y + 2*r); | |||
| NVGcolor shadowColor = nvgRGBAf(0, 0, 0, 0.2); | |||
| NVGcolor transparentColor = nvgRGBAf(0, 0, 0, 0); | |||
| @@ -375,7 +375,7 @@ void ModuleWidget::onDragEnd(event::DragEnd &e) { | |||
| void ModuleWidget::onDragMove(event::DragMove &e) { | |||
| if (!context()->scene->rackWidget->lockModules) { | |||
| Rect newBox = box; | |||
| math::Rect newBox = box; | |||
| newBox.pos = context()->scene->rackWidget->lastMousePos.minus(dragPos); | |||
| context()->scene->rackWidget->requestModuleBoxNearest(this, newBox); | |||
| } | |||
| @@ -14,7 +14,7 @@ void MultiLightWidget::setValues(const std::vector<float> &values) { | |||
| color = nvgRGBAf(0, 0, 0, 0); | |||
| for (size_t i = 0; i < baseColors.size(); i++) { | |||
| NVGcolor c = baseColors[i]; | |||
| c.a *= clamp(values[i], 0.f, 1.f); | |||
| c.a *= math::clamp(values[i], 0.f, 1.f); | |||
| color = color::screen(color, c); | |||
| } | |||
| color = color::clip(color); | |||
| @@ -149,7 +149,7 @@ PluginManagerWidget::PluginManagerWidget() { | |||
| box.size.y = BND_WIDGET_HEIGHT; | |||
| { | |||
| SequentialLayout *layout = createWidget<SequentialLayout>(Vec(0, 0)); | |||
| SequentialLayout *layout = createWidget<SequentialLayout>(math::Vec(0, 0)); | |||
| layout->spacing = 5; | |||
| loginWidget = layout; | |||
| @@ -182,7 +182,7 @@ PluginManagerWidget::PluginManagerWidget() { | |||
| } | |||
| { | |||
| SequentialLayout *layout = createWidget<SequentialLayout>(Vec(0, 0)); | |||
| SequentialLayout *layout = createWidget<SequentialLayout>(math::Vec(0, 0)); | |||
| layout->spacing = 5; | |||
| manageWidget = layout; | |||
| @@ -205,7 +205,7 @@ PluginManagerWidget::PluginManagerWidget() { | |||
| } | |||
| { | |||
| SequentialLayout *layout = createWidget<SequentialLayout>(Vec(0, 0)); | |||
| SequentialLayout *layout = createWidget<SequentialLayout>(math::Vec(0, 0)); | |||
| layout->spacing = 5; | |||
| downloadWidget = layout; | |||
| @@ -12,7 +12,7 @@ struct PlugLight : MultiLightWidget { | |||
| PlugLight() { | |||
| addBaseColor(color::GREEN); | |||
| addBaseColor(color::RED); | |||
| box.size = Vec(8, 8); | |||
| box.size = math::Vec(8, 8); | |||
| bgColor = color::BLACK_TRANSPARENT; | |||
| } | |||
| }; | |||
| @@ -8,8 +8,8 @@ namespace rack { | |||
| void RackScrollWidget::step() { | |||
| Vec pos = context()->window->mousePos; | |||
| Rect viewport = getViewport(box.zeroPos()); | |||
| math::Vec pos = context()->window->mousePos; | |||
| math::Rect viewport = getViewport(box.zeroPos()); | |||
| // Scroll rack if dragging cable near the edge of the screen | |||
| if (context()->scene->rackWidget->wireContainer->activeWire) { | |||
| float margin = 20.0; | |||
| @@ -36,11 +36,11 @@ struct ModuleContainer : Widget { | |||
| RackWidget::RackWidget() { | |||
| rails = new FramebufferWidget; | |||
| rails->box.size = Vec(); | |||
| rails->box.size = math::Vec(); | |||
| rails->oversample = 1.0; | |||
| { | |||
| RackRail *rail = new RackRail; | |||
| rail->box.size = Vec(); | |||
| rail->box.size = math::Vec(); | |||
| rails->addChild(rail); | |||
| } | |||
| addChild(rails); | |||
| @@ -60,7 +60,7 @@ void RackWidget::clear() { | |||
| wireContainer->clearChildren(); | |||
| moduleContainer->clearChildren(); | |||
| context()->scene->scrollWidget->offset = Vec(0, 0); | |||
| context()->scene->scrollWidget->offset = math::Vec(0, 0); | |||
| } | |||
| void RackWidget::reset() { | |||
| @@ -206,7 +206,7 @@ json_t *RackWidget::toJson() { | |||
| json_t *moduleJ = moduleWidget->toJson(); | |||
| { | |||
| // pos | |||
| Vec pos = moduleWidget->box.pos.div(RACK_GRID_SIZE).round(); | |||
| math::Vec pos = moduleWidget->box.pos.div(RACK_GRID_SIZE).round(); | |||
| json_t *posJ = json_pack("[i, i]", (int) pos.x, (int) pos.y); | |||
| json_object_set_new(moduleJ, "pos", posJ); | |||
| } | |||
| @@ -289,7 +289,7 @@ void RackWidget::fromJson(json_t *rootJ) { | |||
| json_t *posJ = json_object_get(moduleJ, "pos"); | |||
| double x, y; | |||
| json_unpack(posJ, "[F, F]", &x, &y); | |||
| Vec pos = Vec(x, y); | |||
| math::Vec pos = math::Vec(x, y); | |||
| if (legacy && legacy <= 1) { | |||
| moduleWidget->box.pos = pos; | |||
| } | |||
| @@ -403,7 +403,7 @@ void RackWidget::pastePresetClipboard() { | |||
| if (moduleJ) { | |||
| ModuleWidget *moduleWidget = moduleFromJson(moduleJ); | |||
| // Set moduleWidget position | |||
| Rect newBox = moduleWidget->box; | |||
| math::Rect newBox = moduleWidget->box; | |||
| newBox.pos = lastMousePos.minus(newBox.size.div(2)); | |||
| requestModuleBoxNearest(moduleWidget, newBox); | |||
| @@ -429,12 +429,12 @@ void RackWidget::cloneModule(ModuleWidget *m) { | |||
| json_t *moduleJ = m->toJson(); | |||
| ModuleWidget *clonedModuleWidget = moduleFromJson(moduleJ); | |||
| json_decref(moduleJ); | |||
| Rect clonedBox = clonedModuleWidget->box; | |||
| math::Rect clonedBox = clonedModuleWidget->box; | |||
| clonedBox.pos = m->box.pos; | |||
| requestModuleBoxNearest(clonedModuleWidget, clonedBox); | |||
| } | |||
| bool RackWidget::requestModuleBox(ModuleWidget *m, Rect box) { | |||
| bool RackWidget::requestModuleBox(ModuleWidget *m, math::Rect box) { | |||
| if (box.pos.x < 0 || box.pos.y < 0) | |||
| return false; | |||
| @@ -448,25 +448,25 @@ bool RackWidget::requestModuleBox(ModuleWidget *m, Rect box) { | |||
| return true; | |||
| } | |||
| bool RackWidget::requestModuleBoxNearest(ModuleWidget *m, Rect box) { | |||
| bool RackWidget::requestModuleBoxNearest(ModuleWidget *m, math::Rect box) { | |||
| // Create possible positions | |||
| int x0 = roundf(box.pos.x / RACK_GRID_WIDTH); | |||
| int y0 = roundf(box.pos.y / RACK_GRID_HEIGHT); | |||
| std::vector<Vec> positions; | |||
| std::vector<math::Vec> positions; | |||
| for (int y = std::max(0, y0 - 8); y < y0 + 8; y++) { | |||
| for (int x = std::max(0, x0 - 400); x < x0 + 400; x++) { | |||
| positions.push_back(Vec(x * RACK_GRID_WIDTH, y * RACK_GRID_HEIGHT)); | |||
| positions.push_back(math::Vec(x * RACK_GRID_WIDTH, y * RACK_GRID_HEIGHT)); | |||
| } | |||
| } | |||
| // Sort possible positions by distance to the requested position | |||
| std::sort(positions.begin(), positions.end(), [box](Vec a, Vec b) { | |||
| std::sort(positions.begin(), positions.end(), [box](math::Vec a, math::Vec b) { | |||
| return a.minus(box.pos).norm() < b.minus(box.pos).norm(); | |||
| }); | |||
| // Find a position that does not collide | |||
| for (Vec position : positions) { | |||
| Rect newBox = box; | |||
| for (math::Vec position : positions) { | |||
| math::Rect newBox = box; | |||
| newBox.pos = position; | |||
| if (requestModuleBox(m, newBox)) | |||
| return true; | |||
| @@ -476,15 +476,15 @@ bool RackWidget::requestModuleBoxNearest(ModuleWidget *m, Rect box) { | |||
| void RackWidget::step() { | |||
| // Expand size to fit modules | |||
| Vec moduleSize = moduleContainer->getChildrenBoundingBox().getBottomRight(); | |||
| math::Vec moduleSize = moduleContainer->getChildrenBoundingBox().getBottomRight(); | |||
| // We assume that the size is reset by a parent before calling step(). Otherwise it will grow unbounded. | |||
| box.size = box.size.max(moduleSize); | |||
| // Adjust size and position of rails | |||
| Widget *rail = rails->children.front(); | |||
| Rect bound = getViewport(Rect(Vec(), box.size)); | |||
| math::Rect bound = getViewport(math::Rect(math::Vec(), box.size)); | |||
| if (!rails->box.contains(bound)) { | |||
| Vec cellMargin = Vec(20, 1); | |||
| math::Vec cellMargin = math::Vec(20, 1); | |||
| rails->box.pos = bound.pos.div(RACK_GRID_SIZE).floor().minus(cellMargin).mult(RACK_GRID_SIZE); | |||
| rails->box.size = bound.size.plus(cellMargin.mult(RACK_GRID_SIZE).mult(2)); | |||
| rails->dirty = true; | |||
| @@ -520,7 +520,7 @@ void RackWidget::onButton(event::Button &e) { | |||
| } | |||
| void RackWidget::onZoom(event::Zoom &e) { | |||
| rails->box.size = Vec(); | |||
| rails->box.size = math::Vec(); | |||
| OpaqueWidget::onZoom(e); | |||
| } | |||
| @@ -7,7 +7,7 @@ namespace rack { | |||
| SVGKnob::SVGKnob() { | |||
| shadow = new CircularShadow; | |||
| addChild(shadow); | |||
| shadow->box.size = Vec(); | |||
| shadow->box.size = math::Vec(); | |||
| tw = new TransformWidget; | |||
| addChild(tw); | |||
| @@ -21,8 +21,8 @@ void SVGKnob::setSVG(std::shared_ptr<SVG> svg) { | |||
| tw->box.size = sw->box.size; | |||
| box.size = sw->box.size; | |||
| shadow->box.size = sw->box.size; | |||
| shadow->box.pos = Vec(0, sw->box.size.y * 0.1); | |||
| // shadow->box = shadow->box.grow(Vec(2, 2)); | |||
| shadow->box.pos = math::Vec(0, sw->box.size.y * 0.1); | |||
| // shadow->box = shadow->box.grow(math::Vec(2, 2)); | |||
| } | |||
| void SVGKnob::step() { | |||
| @@ -30,15 +30,15 @@ void SVGKnob::step() { | |||
| if (dirty && quantity) { | |||
| float angle; | |||
| if (quantity->isBounded()) { | |||
| angle = rescale(quantity->getValue(), -1.f, 1.f, minAngle, maxAngle); | |||
| angle = math::rescale(quantity->getValue(), -1.f, 1.f, minAngle, maxAngle); | |||
| angle = std::fmod(angle, 2*M_PI); | |||
| } | |||
| else { | |||
| angle = rescale(quantity->getScaledValue(), 0.f, 1.f, minAngle, maxAngle); | |||
| angle = math::rescale(quantity->getScaledValue(), 0.f, 1.f, minAngle, maxAngle); | |||
| } | |||
| tw->identity(); | |||
| // Rotate SVG | |||
| Vec center = sw->box.getCenter(); | |||
| math::Vec center = sw->box.getCenter(); | |||
| tw->translate(center); | |||
| tw->rotate(angle); | |||
| tw->translate(center.neg()); | |||
| @@ -9,7 +9,7 @@ SVGPort::SVGPort() { | |||
| addChild(shadow); | |||
| // Avoid breakage if plugins fail to call setSVG() | |||
| // In that case, just disable the shadow. | |||
| shadow->box.size = Vec(); | |||
| shadow->box.size = math::Vec(); | |||
| background = new SVGWidget; | |||
| addChild(background); | |||
| @@ -19,8 +19,8 @@ void SVGPort::setSVG(std::shared_ptr<SVG> svg) { | |||
| background->setSVG(svg); | |||
| box.size = background->box.size; | |||
| shadow->box.size = background->box.size; | |||
| shadow->box.pos = Vec(0, background->box.size.y * 0.1); | |||
| // shadow->box = shadow->box.grow(Vec(2, 2)); | |||
| shadow->box.pos = math::Vec(0, background->box.size.y * 0.1); | |||
| // shadow->box = shadow->box.grow(math::Vec(2, 2)); | |||
| } | |||
| void SVGPort::draw(NVGcontext *vg) { | |||
| @@ -26,9 +26,9 @@ void SVGSlider::step() { | |||
| if (dirty && quantity) { | |||
| // Interpolate handle position | |||
| float v = quantity->getScaledValue(); | |||
| handle->box.pos = Vec( | |||
| rescale(v, 0.f, 1.f, minHandlePos.x, maxHandlePos.x), | |||
| rescale(v, 0.f, 1.f, minHandlePos.y, maxHandlePos.y)); | |||
| handle->box.pos = math::Vec( | |||
| math::rescale(v, 0.f, 1.f, minHandlePos.x, maxHandlePos.x), | |||
| math::rescale(v, 0.f, 1.f, minHandlePos.y, maxHandlePos.y)); | |||
| } | |||
| FramebufferWidget::step(); | |||
| } | |||
| @@ -22,7 +22,7 @@ void SVGSwitch::onChange(event::Change &e) { | |||
| assert(frames.size() > 0); | |||
| if (quantity) { | |||
| int index = quantity->getScaledValue() * (frames.size() - 1); | |||
| index = clamp(index, 0, (int) frames.size() - 1); | |||
| index = math::clamp(index, 0, (int) frames.size() - 1); | |||
| sw->setSVG(frames[index]); | |||
| dirty = true; | |||
| } | |||
| @@ -36,7 +36,7 @@ void Scene::step() { | |||
| // Resize to be a bit larger than the ScrollWidget viewport | |||
| rackWidget->box.size = scrollWidget->box.size | |||
| .minus(scrollWidget->container->box.pos) | |||
| .plus(Vec(500, 500)) | |||
| .plus(math::Vec(500, 500)) | |||
| .div(zoomWidget->zoom); | |||
| OpaqueWidget::step(); | |||
| @@ -20,7 +20,7 @@ struct TooltipIconButton : IconButton { | |||
| void onEnter(event::Enter &e) override { | |||
| if (!tooltip) { | |||
| tooltip = new Tooltip; | |||
| tooltip->box.pos = getAbsoluteOffset(Vec(0, BND_WIDGET_HEIGHT)); | |||
| tooltip->box.pos = getAbsoluteOffset(math::Vec(0, BND_WIDGET_HEIGHT)); | |||
| tooltip->text = getTooltipText(); | |||
| context()->scene->addChild(tooltip); | |||
| } | |||
| @@ -128,7 +128,7 @@ struct SampleRateButton : TooltipIconButton { | |||
| std::string getTooltipText() override {return "Engine sample rate";} | |||
| void onAction(event::Action &e) override { | |||
| Menu *menu = createMenu(); | |||
| menu->box.pos = getAbsoluteOffset(Vec(0, box.size.y)); | |||
| menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); | |||
| menu->box.size.x = box.size.x; | |||
| menu->addChild(createMenuLabel("Engine sample rate")); | |||
| @@ -204,7 +204,7 @@ Toolbar::Toolbar() { | |||
| box.size.y = BND_WIDGET_HEIGHT + 2*5; | |||
| SequentialLayout *layout = new SequentialLayout; | |||
| layout->box.pos = Vec(5, 5); | |||
| layout->box.pos = math::Vec(5, 5); | |||
| layout->spacing = 5; | |||
| addChild(layout); | |||
| @@ -9,7 +9,7 @@ | |||
| namespace rack { | |||
| static void drawPlug(NVGcontext *vg, Vec pos, NVGcolor color) { | |||
| static void drawPlug(NVGcontext *vg, math::Vec pos, NVGcolor color) { | |||
| NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5); | |||
| // Plug solid | |||
| @@ -30,7 +30,7 @@ static void drawPlug(NVGcontext *vg, Vec pos, NVGcolor color) { | |||
| nvgFill(vg); | |||
| } | |||
| static void drawWire(NVGcontext *vg, Vec pos1, Vec pos2, NVGcolor color, float tension, float opacity) { | |||
| static void drawWire(NVGcontext *vg, math::Vec pos1, math::Vec pos2, NVGcolor color, float tension, float opacity) { | |||
| NVGcolor colorShadow = nvgRGBAf(0, 0, 0, 0.10); | |||
| NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5); | |||
| @@ -40,14 +40,14 @@ static void drawWire(NVGcontext *vg, Vec pos1, Vec pos2, NVGcolor color, float t | |||
| nvgGlobalAlpha(vg, powf(opacity, 1.5)); | |||
| float dist = pos1.minus(pos2).norm(); | |||
| Vec slump; | |||
| math::Vec slump; | |||
| slump.y = (1.0 - tension) * (150.0 + 1.0*dist); | |||
| Vec pos3 = pos1.plus(pos2).div(2).plus(slump); | |||
| math::Vec pos3 = pos1.plus(pos2).div(2).plus(slump); | |||
| nvgLineJoin(vg, NVG_ROUND); | |||
| // Shadow | |||
| Vec pos4 = pos3.plus(slump.mult(0.08)); | |||
| math::Vec pos4 = pos3.plus(slump.mult(0.08)); | |||
| nvgBeginPath(vg); | |||
| nvgMoveTo(vg, pos1.x, pos1.y); | |||
| nvgQuadTo(vg, pos4.x, pos4.y, pos2.x, pos2.y); | |||
| @@ -121,7 +121,7 @@ void WireWidget::updateWire() { | |||
| } | |||
| } | |||
| Vec WireWidget::getOutputPos() { | |||
| math::Vec WireWidget::getOutputPos() { | |||
| if (outputPort) { | |||
| return outputPort->getRelativeOffset(outputPort->box.zeroPos().getCenter(), context()->scene->rackWidget); | |||
| } | |||
| @@ -133,7 +133,7 @@ Vec WireWidget::getOutputPos() { | |||
| } | |||
| } | |||
| Vec WireWidget::getInputPos() { | |||
| math::Vec WireWidget::getInputPos() { | |||
| if (inputPort) { | |||
| return inputPort->getRelativeOffset(inputPort->box.zeroPos().getCenter(), context()->scene->rackWidget); | |||
| } | |||
| @@ -179,15 +179,15 @@ void WireWidget::draw(NVGcontext *vg) { | |||
| opacity = 1.0; | |||
| } | |||
| Vec outputPos = getOutputPos(); | |||
| Vec inputPos = getInputPos(); | |||
| math::Vec outputPos = getOutputPos(); | |||
| math::Vec inputPos = getInputPos(); | |||
| drawWire(vg, outputPos, inputPos, color, tension, opacity); | |||
| } | |||
| void WireWidget::drawPlugs(NVGcontext *vg) { | |||
| // TODO Figure out a way to draw plugs first and wires last, and cut the plug portion of the wire off. | |||
| Vec outputPos = getOutputPos(); | |||
| Vec inputPos = getInputPos(); | |||
| math::Vec outputPos = getOutputPos(); | |||
| math::Vec inputPos = getInputPos(); | |||
| drawPlug(vg, outputPos, color); | |||
| drawPlug(vg, inputPos, color); | |||
| @@ -228,7 +228,7 @@ void AudioIO::openStream() { | |||
| if (rtAudio->isStreamOpen()) | |||
| return; | |||
| setChannels(clamp((int) deviceInfo.outputChannels - offset, 0, maxChannels), clamp((int) deviceInfo.inputChannels - offset, 0, maxChannels)); | |||
| setChannels(math::clamp((int) deviceInfo.outputChannels - offset, 0, maxChannels), math::clamp((int) deviceInfo.inputChannels - offset, 0, maxChannels)); | |||
| if (numOutputs == 0 && numInputs == 0) { | |||
| WARN("RtAudio device %d has 0 inputs and 0 outputs", device); | |||
| @@ -8,7 +8,7 @@ namespace color { | |||
| NVGcolor clip(NVGcolor a) { | |||
| for (int i = 0; i < 4; i++) | |||
| a.rgba[i] = clamp(a.rgba[i], 0.f, 1.f); | |||
| a.rgba[i] = math::clamp(a.rgba[i], 0.f, 1.f); | |||
| return a; | |||
| } | |||
| @@ -7,7 +7,7 @@ namespace rack { | |||
| namespace event { | |||
| void Context::handleButton(Vec pos, int button, int action, int mods) { | |||
| void Context::handleButton(math::Vec pos, int button, int action, int mods) { | |||
| // event::Button | |||
| event::Button eButton; | |||
| eButton.pos = pos; | |||
| @@ -74,7 +74,7 @@ void Context::handleButton(Vec pos, int button, int action, int mods) { | |||
| } | |||
| void Context::handleHover(Vec pos, Vec mouseDelta) { | |||
| void Context::handleHover(math::Vec pos, math::Vec mouseDelta) { | |||
| if (draggedWidget) { | |||
| // event::DragMove | |||
| event::DragMove eDragMove; | |||
| @@ -148,7 +148,7 @@ void Context::handleLeave() { | |||
| hoveredWidget = NULL; | |||
| } | |||
| void Context::handleScroll(Vec pos, Vec scrollDelta) { | |||
| void Context::handleScroll(math::Vec pos, math::Vec scrollDelta) { | |||
| // event::HoverScroll | |||
| event::HoverScroll eHoverScroll; | |||
| eHoverScroll.pos = pos; | |||
| @@ -156,7 +156,7 @@ void Context::handleScroll(Vec pos, Vec scrollDelta) { | |||
| rootWidget->onHoverScroll(eHoverScroll); | |||
| } | |||
| void Context::handleDrop(Vec pos, std::vector<std::string> paths) { | |||
| void Context::handleDrop(math::Vec pos, std::vector<std::string> paths) { | |||
| // event::PathDrop | |||
| event::PathDrop ePathDrop; | |||
| ePathDrop.pos = pos; | |||
| @@ -164,7 +164,7 @@ void Context::handleDrop(Vec pos, std::vector<std::string> paths) { | |||
| rootWidget->onPathDrop(ePathDrop); | |||
| } | |||
| void Context::handleText(Vec pos, int codepoint) { | |||
| void Context::handleText(math::Vec pos, int codepoint) { | |||
| if (selectedWidget) { | |||
| // event::SelectText | |||
| event::SelectText eSelectText; | |||
| @@ -181,7 +181,7 @@ void Context::handleText(Vec pos, int codepoint) { | |||
| rootWidget->onHoverText(eHoverText); | |||
| } | |||
| void Context::handleKey(Vec pos, int key, int scancode, int action, int mods) { | |||
| void Context::handleKey(math::Vec pos, int key, int scancode, int action, int mods) { | |||
| if (selectedWidget) { | |||
| // event::SelectKey | |||
| event::SelectKey eSelectKey; | |||
| @@ -24,7 +24,7 @@ void InputDevice::step() { | |||
| ccs.resize(numAxes); | |||
| for (int i = 0; i < numAxes; i++) { | |||
| // Allow CC value to go negative, but clamp at -127 instead of -128 for symmetry | |||
| int8_t cc = clamp((int) std::round(axes[i] * 127), -127, 127); | |||
| int8_t cc = math::clamp((int) std::round(axes[i] * 127), -127, 127); | |||
| if (cc != ccs[i]) { | |||
| ccs[i] = cc; | |||
| @@ -61,7 +61,7 @@ void InputDevice::onKeyPress(int key) { | |||
| default: break; | |||
| } | |||
| octave = clamp(octave, 0, 9); | |||
| octave = math::clamp(octave, 0, 9); | |||
| if (note < 0) | |||
| return; | |||
| @@ -23,12 +23,12 @@ static json_t *settingsToJson() { | |||
| if (!context()->window->isMaximized()) { | |||
| // windowSize | |||
| Vec windowSize = context()->window->getWindowSize(); | |||
| math::Vec windowSize = context()->window->getWindowSize(); | |||
| json_t *windowSizeJ = json_pack("[f, f]", windowSize.x, windowSize.y); | |||
| json_object_set_new(rootJ, "windowSize", windowSizeJ); | |||
| // windowPos | |||
| Vec windowPos = context()->window->getWindowPos(); | |||
| math::Vec windowPos = context()->window->getWindowPos(); | |||
| json_t *windowPosJ = json_pack("[f, f]", windowPos.x, windowPos.y); | |||
| json_object_set_new(rootJ, "windowPos", windowPosJ); | |||
| } | |||
| @@ -88,7 +88,7 @@ static void settingsFromJson(json_t *rootJ) { | |||
| if (windowSizeJ) { | |||
| double width, height; | |||
| json_unpack(windowSizeJ, "[F, F]", &width, &height); | |||
| context()->window->setWindowSize(Vec(width, height)); | |||
| context()->window->setWindowSize(math::Vec(width, height)); | |||
| } | |||
| // windowPos | |||
| @@ -96,7 +96,7 @@ static void settingsFromJson(json_t *rootJ) { | |||
| if (windowPosJ) { | |||
| double x, y; | |||
| json_unpack(windowPosJ, "[F, F]", &x, &y); | |||
| context()->window->setWindowPos(Vec(x, y)); | |||
| context()->window->setWindowPos(math::Vec(x, y)); | |||
| } | |||
| // opacity | |||
| @@ -112,7 +112,7 @@ static void settingsFromJson(json_t *rootJ) { | |||
| // zoom | |||
| json_t *zoomJ = json_object_get(rootJ, "zoom"); | |||
| if (zoomJ) { | |||
| context()->scene->zoomWidget->setZoom(clamp((float) json_number_value(zoomJ), 0.25f, 4.0f)); | |||
| context()->scene->zoomWidget->setZoom(math::clamp((float) json_number_value(zoomJ), 0.25f, 4.0f)); | |||
| } | |||
| // allowCursorLock | |||
| @@ -26,7 +26,7 @@ static NVGpaint getPaint(NVGcontext *vg, NSVGpaint *p) { | |||
| float inverse[6]; | |||
| nvgTransformInverse(inverse, g->xform); | |||
| DEBUG_ONLY(printf(" inverse: %f %f %f %f %f %f\n", inverse[0], inverse[1], inverse[2], inverse[3], inverse[4], inverse[5]);) | |||
| Vec s, e; | |||
| math::Vec s, e; | |||
| DEBUG_ONLY(printf(" sx: %f sy: %f ex: %f ey: %f\n", s.x, s.y, e.x, e.y);) | |||
| // Is it always the case that the gradient should be transformed from (0, 0) to (0, 1)? | |||
| nvgTransformPoint(&s.x, &s.y, inverse, 0, 0); | |||
| @@ -42,10 +42,10 @@ static NVGpaint getPaint(NVGcontext *vg, NSVGpaint *p) { | |||
| } | |||
| /** Returns the parameterized value of the line p2--p3 where it intersects with p0--p1 */ | |||
| static float getLineCrossing(Vec p0, Vec p1, Vec p2, Vec p3) { | |||
| Vec b = p2.minus(p0); | |||
| Vec d = p1.minus(p0); | |||
| Vec e = p3.minus(p2); | |||
| static float getLineCrossing(math::Vec p0, math::Vec p1, math::Vec p2, math::Vec p3) { | |||
| math::Vec b = p2.minus(p0); | |||
| math::Vec d = p1.minus(p0); | |||
| math::Vec e = p3.minus(p2); | |||
| float m = d.x * e.y - d.y * e.x; | |||
| // Check if lines are parallel, or if either pair of points are equal | |||
| if (std::abs(m) < 1e-6) | |||
| @@ -94,8 +94,8 @@ void svgDraw(NVGcontext *vg, NSVGimage *svg) { | |||
| // Also assume that the topology is the same if we use straight lines rather than Beziers (not always the case but usually true). | |||
| // Using the even-odd fill rule, if we draw a line from a point on the path to a point outside the boundary (e.g. top left) and count the number of times it crosses another path, the parity of this count determines whether the path is a hole (odd) or solid (even). | |||
| int crossings = 0; | |||
| Vec p0 = Vec(path->pts[0], path->pts[1]); | |||
| Vec p1 = Vec(path->bounds[0] - 1.0, path->bounds[1] - 1.0); | |||
| math::Vec p0 = math::Vec(path->pts[0], path->pts[1]); | |||
| math::Vec p1 = math::Vec(path->bounds[0] - 1.0, path->bounds[1] - 1.0); | |||
| // Iterate all other paths | |||
| for (NSVGpath *path2 = shape->paths; path2; path2 = path2->next) { | |||
| if (path2 == path) | |||
| @@ -107,9 +107,9 @@ void svgDraw(NVGcontext *vg, NSVGimage *svg) { | |||
| for (int i = 1; i < path2->npts + 3; i += 3) { | |||
| float *p = &path2->pts[2*i]; | |||
| // The previous point | |||
| Vec p2 = Vec(p[-2], p[-1]); | |||
| math::Vec p2 = math::Vec(p[-2], p[-1]); | |||
| // The current point | |||
| Vec p3 = (i < path2->npts) ? Vec(p[4], p[5]) : Vec(path2->pts[0], path2->pts[1]); | |||
| math::Vec p3 = (i < path2->npts) ? math::Vec(p[4], p[5]) : math::Vec(path2->pts[0], path2->pts[1]); | |||
| float crossing = getLineCrossing(p0, p1, p2, p3); | |||
| float crossing2 = getLineCrossing(p2, p3, p0, p1); | |||
| if (0.0 <= crossing && crossing < 1.0 && 0.0 <= crossing2) { | |||
| @@ -126,10 +126,10 @@ void svgDraw(NVGcontext *vg, NSVGimage *svg) { | |||
| /* | |||
| // Shoelace algorithm for computing the area, and thus the winding direction | |||
| float area = 0.0; | |||
| Vec p0 = Vec(path->pts[0], path->pts[1]); | |||
| math::Vec p0 = math::Vec(path->pts[0], path->pts[1]); | |||
| for (int i = 1; i < path->npts; i += 3) { | |||
| float *p = &path->pts[2*i]; | |||
| Vec p1 = (i < path->npts) ? Vec(p[4], p[5]) : Vec(path->pts[0], path->pts[1]); | |||
| math::Vec p1 = (i < path->npts) ? math::Vec(p[4], p[5]) : math::Vec(path->pts[0], path->pts[1]); | |||
| area += 0.5 * (p1.x - p0.x) * (p1.y + p0.y); | |||
| printf("%f %f, %f %f\n", p0.x, p0.y, p1.x, p1.y); | |||
| p0 = p1; | |||
| @@ -9,7 +9,7 @@ namespace rack { | |||
| struct FramebufferWidget::Internal { | |||
| NVGLUframebuffer *fb = NULL; | |||
| Rect box; | |||
| math::Rect box; | |||
| ~Internal() { | |||
| setFramebuffer(NULL); | |||
| @@ -42,10 +42,10 @@ void FramebufferWidget::draw(NVGcontext *vg) { | |||
| // Skew and rotate is not supported | |||
| assert(std::abs(xform[1]) < 1e-6); | |||
| assert(std::abs(xform[2]) < 1e-6); | |||
| Vec s = Vec(xform[0], xform[3]); | |||
| Vec b = Vec(xform[4], xform[5]); | |||
| Vec bi = b.floor(); | |||
| Vec bf = b.minus(bi); | |||
| math::Vec s = math::Vec(xform[0], xform[3]); | |||
| math::Vec b = math::Vec(xform[4], xform[5]); | |||
| math::Vec bi = b.floor(); | |||
| math::Vec bf = b.minus(bi); | |||
| // Render to framebuffer | |||
| if (dirty) { | |||
| @@ -53,9 +53,9 @@ void FramebufferWidget::draw(NVGcontext *vg) { | |||
| internal->box = getChildrenBoundingBox(); | |||
| internal->box.pos = internal->box.pos.mult(s).floor(); | |||
| internal->box.size = internal->box.size.mult(s).ceil().plus(Vec(1, 1)); | |||
| internal->box.size = internal->box.size.mult(s).ceil().plus(math::Vec(1, 1)); | |||
| Vec fbSize = internal->box.size.mult(context()->window->pixelRatio * oversample); | |||
| math::Vec fbSize = internal->box.size.mult(context()->window->pixelRatio * oversample); | |||
| if (!fbSize.isFinite()) | |||
| return; | |||
| @@ -13,8 +13,8 @@ Widget::~Widget() { | |||
| clearChildren(); | |||
| } | |||
| Rect Widget::getChildrenBoundingBox() { | |||
| Rect bound; | |||
| math::Rect Widget::getChildrenBoundingBox() { | |||
| math::Rect bound; | |||
| for (Widget *child : children) { | |||
| if (child == children.front()) { | |||
| bound = child->box; | |||
| @@ -26,7 +26,7 @@ Rect Widget::getChildrenBoundingBox() { | |||
| return bound; | |||
| } | |||
| Vec Widget::getRelativeOffset(Vec v, Widget *relative) { | |||
| math::Vec Widget::getRelativeOffset(math::Vec v, Widget *relative) { | |||
| if (this == relative) { | |||
| return v; | |||
| } | |||
| @@ -37,8 +37,8 @@ Vec Widget::getRelativeOffset(Vec v, Widget *relative) { | |||
| return v; | |||
| } | |||
| Rect Widget::getViewport(Rect r) { | |||
| Rect bound; | |||
| math::Rect Widget::getViewport(math::Rect r) { | |||
| math::Rect bound; | |||
| if (parent) { | |||
| bound = parent->getViewport(box); | |||
| } | |||
| @@ -91,8 +91,8 @@ static void mouseButtonStickyCallback(GLFWwindow *win, int button, int action, i | |||
| static void cursorPosCallback(GLFWwindow *win, double xpos, double ypos) { | |||
| Window *window = (Window*) glfwGetWindowUserPointer(win); | |||
| Vec mousePos = Vec(xpos, ypos).div(window->pixelRatio / window->windowRatio).round(); | |||
| Vec mouseDelta = mousePos.minus(window->mousePos); | |||
| math::Vec mousePos = math::Vec(xpos, ypos).div(window->pixelRatio / window->windowRatio).round(); | |||
| math::Vec mouseDelta = mousePos.minus(window->mousePos); | |||
| int cursorMode = glfwGetInputMode(win, GLFW_CURSOR); | |||
| (void) cursorMode; | |||
| @@ -123,10 +123,10 @@ static void cursorEnterCallback(GLFWwindow *win, int entered) { | |||
| static void scrollCallback(GLFWwindow *win, double x, double y) { | |||
| Window *window = (Window*) glfwGetWindowUserPointer(win); | |||
| Vec scrollDelta = Vec(x, y); | |||
| math::Vec scrollDelta = math::Vec(x, y); | |||
| #if ARCH_LIN || ARCH_WIN | |||
| if (window->isShiftPressed()) | |||
| scrollDelta = Vec(y, x); | |||
| scrollDelta = math::Vec(y, x); | |||
| #endif | |||
| scrollDelta = scrollDelta.mult(50.0); | |||
| @@ -338,7 +338,7 @@ void Window::run() { | |||
| glfwGetWindowSize(win, &windowWidth, &windowHeight); | |||
| windowRatio = (float)width / windowWidth; | |||
| context()->event->rootWidget->box.size = Vec(width, height).div(pixelRatio); | |||
| context()->event->rootWidget->box.size = math::Vec(width, height).div(pixelRatio); | |||
| // Step scene | |||
| context()->event->rootWidget->step(); | |||
| @@ -393,25 +393,25 @@ bool Window::isShiftPressed() { | |||
| return glfwGetKey(win, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(win, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; | |||
| } | |||
| Vec Window::getWindowSize() { | |||
| math::Vec Window::getWindowSize() { | |||
| int width, height; | |||
| glfwGetWindowSize(win, &width, &height); | |||
| return Vec(width, height); | |||
| return math::Vec(width, height); | |||
| } | |||
| void Window::setWindowSize(Vec size) { | |||
| void Window::setWindowSize(math::Vec size) { | |||
| int width = size.x; | |||
| int height = size.y; | |||
| glfwSetWindowSize(win, width, height); | |||
| } | |||
| Vec Window::getWindowPos() { | |||
| math::Vec Window::getWindowPos() { | |||
| int x, y; | |||
| glfwGetWindowPos(win, &x, &y); | |||
| return Vec(x, y); | |||
| return math::Vec(x, y); | |||
| } | |||
| void Window::setWindowPos(Vec pos) { | |||
| void Window::setWindowPos(math::Vec pos) { | |||
| int x = pos.x; | |||
| int y = pos.y; | |||
| glfwSetWindowPos(win, x, y); | |||