From a509fab1c1475d428732d88c1c26acf168de0936 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 16 Feb 2019 19:01:28 -0500 Subject: [PATCH] Move and rename widget::DrawContext to widget::Widget::DrawArgs. Rename Module::ProcessContext to Module::ProcessArgs. --- include/app/CableWidget.hpp | 4 +- include/app/CircularShadow.hpp | 2 +- include/app/LedDisplay.hpp | 8 +-- include/app/LightWidget.hpp | 6 +- include/app/ModuleWidget.hpp | 4 +- include/app/ParamWidget.hpp | 2 +- include/app/PortWidget.hpp | 2 +- include/app/RackRail.hpp | 2 +- include/app/RackScrollWidget.hpp | 2 +- include/app/RackWidget.hpp | 2 +- include/app/Scene.hpp | 2 +- include/app/SvgPanel.hpp | 2 +- include/app/Toolbar.hpp | 2 +- include/engine/Module.hpp | 13 ++-- include/ui/Button.hpp | 2 +- include/ui/ChoiceButton.hpp | 2 +- include/ui/Label.hpp | 2 +- include/ui/Menu.hpp | 2 +- include/ui/MenuItem.hpp | 2 +- include/ui/MenuLabel.hpp | 2 +- include/ui/MenuSeparator.hpp | 2 +- include/ui/PasswordField.hpp | 2 +- include/ui/ProgressBar.hpp | 2 +- include/ui/RadioButton.hpp | 2 +- include/ui/ScrollBar.hpp | 2 +- include/ui/ScrollWidget.hpp | 2 +- include/ui/Slider.hpp | 2 +- include/ui/TextField.hpp | 2 +- include/ui/Tooltip.hpp | 2 +- include/widget/FramebufferWidget.hpp | 2 +- include/widget/SvgWidget.hpp | 2 +- include/widget/TransformWidget.hpp | 6 +- include/widget/Widget.hpp | 16 ++--- include/widget/ZoomWidget.hpp | 2 +- src/Core/AudioInterface.cpp | 6 +- src/Core/Blank.cpp | 26 ++++---- src/Core/CV_CC.cpp | 4 +- src/Core/CV_Gate.cpp | 2 +- src/Core/CV_MIDI.cpp | 4 +- src/Core/MIDI_CC.cpp | 4 +- src/Core/MIDI_CV.cpp | 22 +++---- src/Core/MIDI_Gate.cpp | 4 +- src/Core/MIDI_Map.cpp | 4 +- src/app/CableWidget.cpp | 90 ++++++++++++++-------------- src/app/CircularShadow.cpp | 12 ++-- src/app/LedDisplay.cpp | 66 ++++++++++---------- src/app/LightWidget.cpp | 40 ++++++------- src/app/ModuleBrowser.cpp | 22 +++---- src/app/ModuleWidget.cpp | 48 +++++++-------- src/app/ParamWidget.cpp | 28 ++++----- src/app/PortWidget.cpp | 6 +- src/app/RackRail.cpp | 60 +++++++++---------- src/app/RackScrollWidget.cpp | 4 +- src/app/RackWidget.cpp | 22 +++---- src/app/Scene.cpp | 4 +- src/app/SvgPanel.cpp | 12 ++-- src/app/Toolbar.cpp | 28 ++++----- src/engine/Engine.cpp | 5 +- src/ui/Button.cpp | 4 +- src/ui/ChoiceButton.cpp | 4 +- src/ui/Label.cpp | 8 +-- src/ui/Menu.cpp | 6 +- src/ui/MenuItem.cpp | 10 ++-- src/ui/MenuLabel.cpp | 4 +- src/ui/MenuSeparator.cpp | 14 ++--- src/ui/PasswordField.cpp | 4 +- src/ui/ProgressBar.cpp | 4 +- src/ui/RadioButton.cpp | 4 +- src/ui/ScrollBar.cpp | 4 +- src/ui/ScrollWidget.cpp | 8 +-- src/ui/Slider.cpp | 4 +- src/ui/TextField.cpp | 10 ++-- src/ui/Tooltip.cpp | 8 +-- src/widget/FramebufferWidget.cpp | 38 ++++++------ src/widget/SvgWidget.cpp | 4 +- src/widget/Widget.cpp | 18 +++--- src/widget/ZoomWidget.cpp | 6 +- src/window.cpp | 7 ++- 78 files changed, 403 insertions(+), 400 deletions(-) diff --git a/include/app/CableWidget.hpp b/include/app/CableWidget.hpp index fb54eead..83f2e5c7 100644 --- a/include/app/CableWidget.hpp +++ b/include/app/CableWidget.hpp @@ -28,8 +28,8 @@ struct CableWidget : widget::OpaqueWidget { math::Vec getInputPos(); json_t *toJson(); void fromJson(json_t *rootJ); - void draw(const widget::DrawContext &ctx) override; - void drawPlugs(const widget::DrawContext &ctx); + void draw(const DrawArgs &args) override; + void drawPlugs(const DrawArgs &args); }; diff --git a/include/app/CircularShadow.hpp b/include/app/CircularShadow.hpp index afed3cec..5041d74b 100644 --- a/include/app/CircularShadow.hpp +++ b/include/app/CircularShadow.hpp @@ -11,7 +11,7 @@ struct CircularShadow : widget::TransparentWidget { float blurRadius; float opacity; CircularShadow(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/app/LedDisplay.hpp b/include/app/LedDisplay.hpp index bdca68ba..eb069a8a 100644 --- a/include/app/LedDisplay.hpp +++ b/include/app/LedDisplay.hpp @@ -10,12 +10,12 @@ namespace app { struct LedDisplay : widget::OpaqueWidget { - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; struct LedDisplaySeparator : widget::TransparentWidget { LedDisplaySeparator(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; struct LedDisplayChoice : widget::TransparentWidget { @@ -25,7 +25,7 @@ struct LedDisplayChoice : widget::TransparentWidget { NVGcolor color; NVGcolor bgColor; LedDisplayChoice(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onButton(const event::Button &e) override; }; @@ -34,7 +34,7 @@ struct LedDisplayTextField : ui::TextField { math::Vec textOffset; NVGcolor color; LedDisplayTextField(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; int getTextPosition(math::Vec mousePos) override; }; diff --git a/include/app/LightWidget.hpp b/include/app/LightWidget.hpp index 7dfabc39..ff76e5d6 100644 --- a/include/app/LightWidget.hpp +++ b/include/app/LightWidget.hpp @@ -11,9 +11,9 @@ struct LightWidget : widget::TransparentWidget { NVGcolor bgColor = nvgRGBA(0, 0, 0, 0); NVGcolor color = nvgRGBA(0, 0, 0, 0); NVGcolor borderColor = nvgRGBA(0, 0, 0, 0); - void draw(const widget::DrawContext &ctx) override; - virtual void drawLight(const widget::DrawContext &ctx); - virtual void drawHalo(const widget::DrawContext &ctx); + void draw(const DrawArgs &args) override; + virtual void drawLight(const DrawArgs &args); + virtual void drawHalo(const DrawArgs &args); }; diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index 611cf636..cfecc3b5 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -32,8 +32,8 @@ struct ModuleWidget : widget::OpaqueWidget { } ~ModuleWidget(); - void draw(const widget::DrawContext &ctx) override; - void drawShadow(const widget::DrawContext &ctx); + void draw(const DrawArgs &args) override; + void drawShadow(const DrawArgs &args); void onHover(const event::Hover &e) override; void onButton(const event::Button &e) override; diff --git a/include/app/ParamWidget.hpp b/include/app/ParamWidget.hpp index 0a631018..0e134288 100644 --- a/include/app/ParamWidget.hpp +++ b/include/app/ParamWidget.hpp @@ -18,7 +18,7 @@ struct ParamWidget : widget::OpaqueWidget { ~ParamWidget(); void step() override; - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onButton(const event::Button &e) override; void onDoubleClick(const event::DoubleClick &e) override; void onEnter(const event::Enter &e) override; diff --git a/include/app/PortWidget.hpp b/include/app/PortWidget.hpp index 2c1dc426..821af288 100644 --- a/include/app/PortWidget.hpp +++ b/include/app/PortWidget.hpp @@ -26,7 +26,7 @@ struct PortWidget : widget::OpaqueWidget { ~PortWidget(); void step() override; - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onButton(const event::Button &e) override; void onEnter(const event::Enter &e) override; diff --git a/include/app/RackRail.hpp b/include/app/RackRail.hpp index 4ee5f068..6ff2863d 100644 --- a/include/app/RackRail.hpp +++ b/include/app/RackRail.hpp @@ -8,7 +8,7 @@ namespace app { struct RackRail : widget::TransparentWidget { - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/app/RackScrollWidget.hpp b/include/app/RackScrollWidget.hpp index 2f260efc..735ee94b 100644 --- a/include/app/RackScrollWidget.hpp +++ b/include/app/RackScrollWidget.hpp @@ -9,7 +9,7 @@ namespace app { struct RackScrollWidget : ui::ScrollWidget { void step() override; - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index 56acfc56..443ce44b 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -26,7 +26,7 @@ struct RackWidget : widget::OpaqueWidget { ~RackWidget(); void step() override; - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onHover(const event::Hover &e) override; void onHoverKey(const event::HoverKey &e) override; diff --git a/include/app/Scene.hpp b/include/app/Scene.hpp index 091d8a17..f14a93da 100644 --- a/include/app/Scene.hpp +++ b/include/app/Scene.hpp @@ -30,7 +30,7 @@ struct Scene : widget::OpaqueWidget { Scene(); ~Scene(); void step() override; - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onHoverKey(const event::HoverKey &e) override; void onPathDrop(const event::PathDrop &e) override; diff --git a/include/app/SvgPanel.hpp b/include/app/SvgPanel.hpp index c7d62032..e4fc6e66 100644 --- a/include/app/SvgPanel.hpp +++ b/include/app/SvgPanel.hpp @@ -11,7 +11,7 @@ namespace app { struct PanelBorder : widget::TransparentWidget { - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/app/Toolbar.hpp b/include/app/Toolbar.hpp index 0609b750..1ac06eda 100644 --- a/include/app/Toolbar.hpp +++ b/include/app/Toolbar.hpp @@ -13,7 +13,7 @@ struct Toolbar : widget::OpaqueWidget { float cableTension = 0.5; Toolbar(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/engine/Module.hpp b/include/engine/Module.hpp index 762048bb..134cd877 100644 --- a/include/engine/Module.hpp +++ b/include/engine/Module.hpp @@ -38,7 +38,7 @@ struct Module { void reset(); void randomize(); - struct ProcessContext { + struct ProcessArgs { float sampleRate; float sampleTime; }; @@ -46,9 +46,14 @@ struct Module { /** Advances the module by one audio sample. Override this method to read Inputs and Params and to write Outputs and Lights. */ - virtual void process(const ProcessContext &ctx) {} - /** Deprecated. Override process() instead. */ - virtual void step() {} + virtual void process(const ProcessArgs &args) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + step(); +#pragma GCC diagnostic pop + } + /** Override process(const ProcessArgs &args) instead. */ + DEPRECATED virtual void step() {} /** Called when the engine sample rate is changed. */ virtual void onSampleRateChange() {} diff --git a/include/ui/Button.hpp b/include/ui/Button.hpp index c7d25ac7..f6da9044 100644 --- a/include/ui/Button.hpp +++ b/include/ui/Button.hpp @@ -16,7 +16,7 @@ struct Button : widget::OpaqueWidget { Button(); ~Button(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onEnter(const event::Enter &e) override; void onLeave(const event::Leave &e) override; void onDragStart(const event::DragStart &e) override; diff --git a/include/ui/ChoiceButton.hpp b/include/ui/ChoiceButton.hpp index dd69b57a..4b9afd9c 100644 --- a/include/ui/ChoiceButton.hpp +++ b/include/ui/ChoiceButton.hpp @@ -8,7 +8,7 @@ namespace ui { struct ChoiceButton : Button { - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/ui/Label.hpp b/include/ui/Label.hpp index 15c54760..b072cfa7 100644 --- a/include/ui/Label.hpp +++ b/include/ui/Label.hpp @@ -20,7 +20,7 @@ struct Label : widget::Widget { Alignment alignment = LEFT_ALIGNMENT; Label(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/ui/Menu.hpp b/include/ui/Menu.hpp index bff50853..73677f57 100644 --- a/include/ui/Menu.hpp +++ b/include/ui/Menu.hpp @@ -18,7 +18,7 @@ struct Menu : widget::OpaqueWidget { ~Menu(); void setChildMenu(Menu *menu); void step() override; - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onHoverScroll(const event::HoverScroll &e) override; }; diff --git a/include/ui/MenuItem.hpp b/include/ui/MenuItem.hpp index ce494977..e720b477 100644 --- a/include/ui/MenuItem.hpp +++ b/include/ui/MenuItem.hpp @@ -18,7 +18,7 @@ struct MenuItem : MenuEntry { std::string rightText; bool disabled = false; - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void step() override; void onEnter(const event::Enter &e) override; void onDragStart(const event::DragStart &e) override; diff --git a/include/ui/MenuLabel.hpp b/include/ui/MenuLabel.hpp index d5f4eafd..7e7d7c36 100644 --- a/include/ui/MenuLabel.hpp +++ b/include/ui/MenuLabel.hpp @@ -10,7 +10,7 @@ namespace ui { struct MenuLabel : MenuEntry { std::string text; - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void step() override; }; diff --git a/include/ui/MenuSeparator.hpp b/include/ui/MenuSeparator.hpp index 9e143ee4..c2aff03a 100644 --- a/include/ui/MenuSeparator.hpp +++ b/include/ui/MenuSeparator.hpp @@ -9,7 +9,7 @@ namespace ui { struct MenuSeparator : MenuEntry { MenuSeparator(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/ui/PasswordField.hpp b/include/ui/PasswordField.hpp index 0250e00c..779e6b0a 100644 --- a/include/ui/PasswordField.hpp +++ b/include/ui/PasswordField.hpp @@ -8,7 +8,7 @@ namespace ui { struct PasswordField : TextField { - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/ui/ProgressBar.hpp b/include/ui/ProgressBar.hpp index a7b153f1..9bd396a6 100644 --- a/include/ui/ProgressBar.hpp +++ b/include/ui/ProgressBar.hpp @@ -13,7 +13,7 @@ struct ProgressBar : widget::Widget { ProgressBar(); ~ProgressBar(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/ui/RadioButton.hpp b/include/ui/RadioButton.hpp index 4f4ca66c..575e0716 100644 --- a/include/ui/RadioButton.hpp +++ b/include/ui/RadioButton.hpp @@ -14,7 +14,7 @@ struct RadioButton : widget::OpaqueWidget { RadioButton(); ~RadioButton(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onEnter(const event::Enter &e) override; void onLeave(const event::Leave &e) override; void onDragDrop(const event::DragDrop &e) override; diff --git a/include/ui/ScrollBar.hpp b/include/ui/ScrollBar.hpp index 7cbe8912..3c6d4908 100644 --- a/include/ui/ScrollBar.hpp +++ b/include/ui/ScrollBar.hpp @@ -19,7 +19,7 @@ struct ScrollBar : widget::OpaqueWidget { float size = 0.0; ScrollBar(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onDragStart(const event::DragStart &e) override; void onDragMove(const event::DragMove &e) override; void onDragEnd(const event::DragEnd &e) override; diff --git a/include/ui/ScrollWidget.hpp b/include/ui/ScrollWidget.hpp index 0af4230d..294a5c10 100644 --- a/include/ui/ScrollWidget.hpp +++ b/include/ui/ScrollWidget.hpp @@ -17,7 +17,7 @@ struct ScrollWidget : widget::Widget { ScrollWidget(); void scrollTo(math::Rect r); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void step() override; void onHover(const event::Hover &e) override; void onHoverScroll(const event::HoverScroll &e) override; diff --git a/include/ui/Slider.hpp b/include/ui/Slider.hpp index 98c0bbd2..bcf969f9 100644 --- a/include/ui/Slider.hpp +++ b/include/ui/Slider.hpp @@ -15,7 +15,7 @@ struct Slider : widget::OpaqueWidget { Slider(); ~Slider(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onDragStart(const event::DragStart &e) override; void onDragMove(const event::DragMove &e) override; void onDragEnd(const event::DragEnd &e) override; diff --git a/include/ui/TextField.hpp b/include/ui/TextField.hpp index bd4de4b7..8ab43b01 100644 --- a/include/ui/TextField.hpp +++ b/include/ui/TextField.hpp @@ -21,7 +21,7 @@ struct TextField : widget::OpaqueWidget { int selection = 0; TextField(); - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onButton(const event::Button &e) override; void onHover(const event::Hover &e) override; void onEnter(const event::Enter &e) override; diff --git a/include/ui/Tooltip.hpp b/include/ui/Tooltip.hpp index 1b3f8212..96446a78 100644 --- a/include/ui/Tooltip.hpp +++ b/include/ui/Tooltip.hpp @@ -11,7 +11,7 @@ struct Tooltip : widget::Widget { std::string text; void step() override; - void draw(const widget::DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/widget/FramebufferWidget.hpp b/include/widget/FramebufferWidget.hpp index a80c42d5..2070a2c7 100644 --- a/include/widget/FramebufferWidget.hpp +++ b/include/widget/FramebufferWidget.hpp @@ -28,7 +28,7 @@ struct FramebufferWidget : Widget { FramebufferWidget(); ~FramebufferWidget(); - void draw(const DrawContext &ctx) override; + void draw(const DrawArgs &args) override; virtual void drawFramebuffer(); int getImageHandle(); diff --git a/include/widget/SvgWidget.hpp b/include/widget/SvgWidget.hpp index 6419bae4..915714bf 100644 --- a/include/widget/SvgWidget.hpp +++ b/include/widget/SvgWidget.hpp @@ -18,7 +18,7 @@ struct SvgWidget : Widget { void setSvg(std::shared_ptr svg); DEPRECATED void setSVG(std::shared_ptr svg) {setSvg(svg);} - void draw(const DrawContext &ctx) override; + void draw(const DrawArgs &args) override; }; diff --git a/include/widget/TransformWidget.hpp b/include/widget/TransformWidget.hpp index e47685a1..dcddafb5 100644 --- a/include/widget/TransformWidget.hpp +++ b/include/widget/TransformWidget.hpp @@ -37,10 +37,10 @@ struct TransformWidget : Widget { nvgTransformPremultiply(transform, t); } - void draw(const DrawContext &ctx) override { + void draw(const DrawArgs &args) override { // No need to save the state because that is done in the parent - nvgTransform(ctx.vg, transform[0], transform[1], transform[2], transform[3], transform[4], transform[5]); - Widget::draw(ctx); + nvgTransform(args.vg, transform[0], transform[1], transform[2], transform[3], transform[4], transform[5]); + Widget::draw(args); } }; diff --git a/include/widget/Widget.hpp b/include/widget/Widget.hpp index fc5df681..46569314 100644 --- a/include/widget/Widget.hpp +++ b/include/widget/Widget.hpp @@ -15,12 +15,6 @@ namespace rack { namespace widget { -struct DrawContext { - NVGcontext *vg; - math::Rect clipBox = math::Rect(math::Vec(), math::Vec(INFINITY, INFINITY)); -}; - - /** A node in the 2D [scene graph](https://en.wikipedia.org/wiki/Scene_graph). The bounding box of a Widget is a rectangle specified by `box` relative to their parent. The appearance is defined by overriding `draw()`, and the behavior is defined by overriding `step()` and `on*()` event handlers. @@ -86,9 +80,15 @@ struct Widget { /** Advances the module by one frame */ virtual void step(); + + struct DrawArgs { + NVGcontext *vg; + math::Rect clipBox; + }; + /** Draws the widget to the NanoVG context */ - virtual void draw(const DrawContext &ctx); - /** Override `draw(const DrawContext &ctx)` instead */ + virtual void draw(const DrawArgs &args); + /** Override draw(const DrawArgs &args) instead */ DEPRECATED virtual void draw(NVGcontext *vg) {} // Events diff --git a/include/widget/ZoomWidget.hpp b/include/widget/ZoomWidget.hpp index a3979c6e..4ad649bd 100644 --- a/include/widget/ZoomWidget.hpp +++ b/include/widget/ZoomWidget.hpp @@ -13,7 +13,7 @@ struct ZoomWidget : Widget { math::Vec getRelativeOffset(math::Vec v, Widget *relative) override; math::Rect getViewport(math::Rect r) override; void setZoom(float zoom); - void draw(const DrawContext &ctx) override; + void draw(const DrawArgs &args) override; void onHover(const event::Hover &e) override { event::Hover e2 = e; diff --git a/src/Core/AudioInterface.cpp b/src/Core/AudioInterface.cpp index 28ab9f44..ec1b155a 100644 --- a/src/Core/AudioInterface.cpp +++ b/src/Core/AudioInterface.cpp @@ -122,10 +122,10 @@ struct AudioInterface : Module { onSampleRateChange(); } - void process(const ProcessContext &ctx) override { + void process(const ProcessArgs &args) override { // Update SRC states - inputSrc.setRates(port.sampleRate, ctx.sampleRate); - outputSrc.setRates(ctx.sampleRate, port.sampleRate); + inputSrc.setRates(port.sampleRate, args.sampleRate); + outputSrc.setRates(args.sampleRate, port.sampleRate); inputSrc.setChannels(port.numInputs); outputSrc.setChannels(port.numOutputs); diff --git a/src/Core/Blank.cpp b/src/Core/Blank.cpp index 6b9b403d..92b4b547 100644 --- a/src/Core/Blank.cpp +++ b/src/Core/Blank.cpp @@ -17,12 +17,12 @@ struct BlankPanel : Widget { Widget::step(); } - void draw(const DrawContext &ctx) override { - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, 0.0, 0.0, box.size.x, box.size.y); - nvgFillColor(ctx.vg, nvgRGB(0xe6, 0xe6, 0xe6)); - nvgFill(ctx.vg); - Widget::draw(ctx); + void draw(const DrawArgs &args) override { + nvgBeginPath(args.vg); + nvgRect(args.vg, 0.0, 0.0, box.size.x, box.size.y); + nvgFillColor(args.vg, nvgRGB(0xe6, 0xe6, 0xe6)); + nvgFill(args.vg); + Widget::draw(args); } }; @@ -71,15 +71,15 @@ struct ModuleResizeHandle : Widget { APP->scene->rackWidget->requestModuleBox(m, newBox); } - void draw(const DrawContext &ctx) override { + void draw(const DrawArgs &args) override { for (float x = 5.0; x <= 10.0; x += 5.0) { - nvgBeginPath(ctx.vg); + nvgBeginPath(args.vg); const float margin = 5.0; - nvgMoveTo(ctx.vg, x + 0.5, margin + 0.5); - nvgLineTo(ctx.vg, x + 0.5, box.size.y - margin + 0.5); - nvgStrokeWidth(ctx.vg, 1.0); - nvgStrokeColor(ctx.vg, nvgRGBAf(0.5, 0.5, 0.5, 0.5)); - nvgStroke(ctx.vg); + nvgMoveTo(args.vg, x + 0.5, margin + 0.5); + nvgLineTo(args.vg, x + 0.5, box.size.y - margin + 0.5); + nvgStrokeWidth(args.vg, 1.0); + nvgStrokeColor(args.vg, nvgRGBAf(0.5, 0.5, 0.5, 0.5)); + nvgStroke(args.vg); } } }; diff --git a/src/Core/CV_CC.cpp b/src/Core/CV_CC.cpp index 389a854c..6b9a7d5a 100644 --- a/src/Core/CV_CC.cpp +++ b/src/Core/CV_CC.cpp @@ -62,9 +62,9 @@ struct CV_CC : Module { midiOutput.midi::Output::reset(); } - void process(const ProcessContext &ctx) override { + void process(const ProcessArgs &args) override { const float rateLimiterPeriod = 0.010f; - rateLimiterPhase += ctx.sampleTime / rateLimiterPeriod; + rateLimiterPhase += args.sampleTime / rateLimiterPeriod; if (rateLimiterPhase >= 1.f) { rateLimiterPhase -= 1.f; } diff --git a/src/Core/CV_Gate.cpp b/src/Core/CV_Gate.cpp index baa00076..1c9d0337 100644 --- a/src/Core/CV_Gate.cpp +++ b/src/Core/CV_Gate.cpp @@ -89,7 +89,7 @@ struct CV_Gate : Module { midiOutput.midi::Output::reset(); } - void process(const ProcessContext &ctx) override { + void process(const ProcessArgs &args) override { for (int i = 0; i < 16; i++) { int note = learnedNotes[i]; if (velocityMode) { diff --git a/src/Core/CV_MIDI.cpp b/src/Core/CV_MIDI.cpp index eef4c58b..cac76095 100644 --- a/src/Core/CV_MIDI.cpp +++ b/src/Core/CV_MIDI.cpp @@ -241,9 +241,9 @@ struct CV_MIDI : Module { midiOutput.midi::Output::reset(); } - void process(const ProcessContext &ctx) override { + void process(const ProcessArgs &args) override { const float rateLimiterPeriod = 0.005f; - rateLimiterPhase += ctx.sampleTime / rateLimiterPeriod; + rateLimiterPhase += args.sampleTime / rateLimiterPeriod; if (rateLimiterPhase >= 1.f) { rateLimiterPhase -= 1.f; } diff --git a/src/Core/MIDI_CC.cpp b/src/Core/MIDI_CC.cpp index d41a2082..321d4396 100644 --- a/src/Core/MIDI_CC.cpp +++ b/src/Core/MIDI_CC.cpp @@ -42,7 +42,7 @@ struct MIDI_CC : Module { midiInput.reset(); } - void process(const ProcessContext &ctx) override { + void process(const ProcessArgs &args) override { midi::Message msg; while (midiInput.shift(&msg)) { processMessage(msg); @@ -63,7 +63,7 @@ struct MIDI_CC : Module { } else { // Smooth value with filter - valueFilters[i].process(ctx.sampleTime, value); + valueFilters[i].process(args.sampleTime, value); } lastValues[i] = values[cc]; outputs[CC_OUTPUT + i].setVoltage(valueFilters[i].out); diff --git a/src/Core/MIDI_CV.cpp b/src/Core/MIDI_CV.cpp index b93e942a..aa4ca7b0 100644 --- a/src/Core/MIDI_CV.cpp +++ b/src/Core/MIDI_CV.cpp @@ -103,7 +103,7 @@ struct MIDI_CV : Module { heldNotes.clear(); } - void process(const ProcessContext &ctx) override { + void process(const ProcessArgs &args) override { midi::Message msg; while (midiInput.shift(&msg)) { processMessage(msg); @@ -119,29 +119,29 @@ struct MIDI_CV : Module { outputs[GATE_OUTPUT].setVoltage(gates[c] ? 10.f : 0.f, c); outputs[VELOCITY_OUTPUT].setVoltage(rescale(velocities[c], 0, 127, 0.f, 10.f), c); outputs[AFTERTOUCH_OUTPUT].setVoltage(rescale(aftertouches[c], 0, 127, 0.f, 10.f), c); - outputs[RETRIGGER_OUTPUT].setVoltage(retriggerPulses[c].process(ctx.sampleTime) ? 10.f : 0.f, c); + outputs[RETRIGGER_OUTPUT].setVoltage(retriggerPulses[c].process(args.sampleTime) ? 10.f : 0.f, c); } if (polyMode == MPE_MODE) { for (int c = 0; c < channels; c++) { outputs[PITCH_OUTPUT].setChannels(channels); outputs[MOD_OUTPUT].setChannels(channels); - outputs[PITCH_OUTPUT].setVoltage(pitchFilters[c].process(ctx.sampleTime, rescale(pitches[c], 0, 1<<14, -5.f, 5.f)), c); - outputs[MOD_OUTPUT].setVoltage(modFilters[c].process(ctx.sampleTime, rescale(mods[c], 0, 127, 0.f, 10.f)), c); + outputs[PITCH_OUTPUT].setVoltage(pitchFilters[c].process(args.sampleTime, rescale(pitches[c], 0, 1<<14, -5.f, 5.f)), c); + outputs[MOD_OUTPUT].setVoltage(modFilters[c].process(args.sampleTime, rescale(mods[c], 0, 127, 0.f, 10.f)), c); } } else { outputs[PITCH_OUTPUT].setChannels(1); outputs[MOD_OUTPUT].setChannels(1); - outputs[PITCH_OUTPUT].setVoltage(pitchFilters[0].process(ctx.sampleTime, rescale(pitches[0], 0, 1<<14, -5.f, 5.f))); - outputs[MOD_OUTPUT].setVoltage(modFilters[0].process(ctx.sampleTime, rescale(mods[0], 0, 127, 0.f, 10.f))); + outputs[PITCH_OUTPUT].setVoltage(pitchFilters[0].process(args.sampleTime, rescale(pitches[0], 0, 1<<14, -5.f, 5.f))); + outputs[MOD_OUTPUT].setVoltage(modFilters[0].process(args.sampleTime, rescale(mods[0], 0, 127, 0.f, 10.f))); } - outputs[CLOCK_OUTPUT].setVoltage(clockPulse.process(ctx.sampleTime) ? 10.f : 0.f); - outputs[CLOCK_DIV_OUTPUT].setVoltage(clockDividerPulse.process(ctx.sampleTime) ? 10.f : 0.f); - outputs[START_OUTPUT].setVoltage(startPulse.process(ctx.sampleTime) ? 10.f : 0.f); - outputs[STOP_OUTPUT].setVoltage(stopPulse.process(ctx.sampleTime) ? 10.f : 0.f); - outputs[CONTINUE_OUTPUT].setVoltage(continuePulse.process(ctx.sampleTime) ? 10.f : 0.f); + outputs[CLOCK_OUTPUT].setVoltage(clockPulse.process(args.sampleTime) ? 10.f : 0.f); + outputs[CLOCK_DIV_OUTPUT].setVoltage(clockDividerPulse.process(args.sampleTime) ? 10.f : 0.f); + outputs[START_OUTPUT].setVoltage(startPulse.process(args.sampleTime) ? 10.f : 0.f); + outputs[STOP_OUTPUT].setVoltage(stopPulse.process(args.sampleTime) ? 10.f : 0.f); + outputs[CONTINUE_OUTPUT].setVoltage(continuePulse.process(args.sampleTime) ? 10.f : 0.f); } void processMessage(midi::Message msg) { diff --git a/src/Core/MIDI_Gate.cpp b/src/Core/MIDI_Gate.cpp index 8921a493..73f40df0 100644 --- a/src/Core/MIDI_Gate.cpp +++ b/src/Core/MIDI_Gate.cpp @@ -46,7 +46,7 @@ struct MIDI_Gate : Module { } } - void process(const ProcessContext &ctx) override { + void process(const ProcessArgs &args) override { midi::Message msg; while (midiInput.shift(&msg)) { processMessage(msg); @@ -58,7 +58,7 @@ struct MIDI_Gate : Module { // If the gate is off, wait 1 ms before turning the pulse off. // This avoids drum controllers sending a pulse with 0 ms duration. if (!gates[i]) { - gateTimes[i] -= ctx.sampleTime; + gateTimes[i] -= args.sampleTime; } } else { diff --git a/src/Core/MIDI_Map.cpp b/src/Core/MIDI_Map.cpp index 3892df4d..b1384dbd 100644 --- a/src/Core/MIDI_Map.cpp +++ b/src/Core/MIDI_Map.cpp @@ -65,7 +65,7 @@ struct MIDI_Map : Module { midiInput.reset(); } - void process(const ProcessContext &ctx) override { + void process(const ProcessArgs &args) override { midi::Message msg; while (midiInput.shift(&msg)) { processMessage(msg); @@ -90,7 +90,7 @@ struct MIDI_Map : Module { continue; // Set param float v = rescale(values[cc], 0, 127, 0.f, 1.f); - v = valueFilters[id].process(ctx.sampleTime, v); + v = valueFilters[id].process(args.sampleTime, v); v = rescale(v, 0.f, 1.f, param->minValue, param->maxValue); APP->engine->setParam(module, paramId, v); } diff --git a/src/app/CableWidget.cpp b/src/app/CableWidget.cpp index b053cf05..274c3cdb 100644 --- a/src/app/CableWidget.cpp +++ b/src/app/CableWidget.cpp @@ -11,67 +11,67 @@ namespace rack { namespace app { -static void drawPlug(const widget::DrawContext &ctx, math::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 - nvgBeginPath(ctx.vg); - nvgCircle(ctx.vg, pos.x, pos.y, 9); - nvgFillColor(ctx.vg, color); - nvgFill(ctx.vg); + nvgBeginPath(vg); + nvgCircle(vg, pos.x, pos.y, 9); + nvgFillColor(vg, color); + nvgFill(vg); // Border - nvgStrokeWidth(ctx.vg, 1.0); - nvgStrokeColor(ctx.vg, colorOutline); - nvgStroke(ctx.vg); + nvgStrokeWidth(vg, 1.0); + nvgStrokeColor(vg, colorOutline); + nvgStroke(vg); // Hole - nvgBeginPath(ctx.vg); - nvgCircle(ctx.vg, pos.x, pos.y, 5); - nvgFillColor(ctx.vg, nvgRGBf(0.0, 0.0, 0.0)); - nvgFill(ctx.vg); + nvgBeginPath(vg); + nvgCircle(vg, pos.x, pos.y, 5); + nvgFillColor(vg, nvgRGBf(0.0, 0.0, 0.0)); + nvgFill(vg); } -static void drawCable(const widget::DrawContext &ctx, math::Vec pos1, math::Vec pos2, NVGcolor color, float thickness, float tension, float opacity) { +static void drawCable(NVGcontext *vg, math::Vec pos1, math::Vec pos2, NVGcolor color, float thickness, 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); // Cable if (opacity > 0.0) { - nvgSave(ctx.vg); + nvgSave(vg); // This power scaling looks more linear than actual linear scaling - nvgGlobalAlpha(ctx.vg, std::pow(opacity, 1.5)); + nvgGlobalAlpha(vg, std::pow(opacity, 1.5)); float dist = pos1.minus(pos2).norm(); math::Vec slump; slump.y = (1.0 - tension) * (150.0 + 1.0*dist); math::Vec pos3 = pos1.plus(pos2).div(2).plus(slump); - nvgLineJoin(ctx.vg, NVG_ROUND); + nvgLineJoin(vg, NVG_ROUND); // Shadow math::Vec pos4 = pos3.plus(slump.mult(0.08)); - nvgBeginPath(ctx.vg); - nvgMoveTo(ctx.vg, pos1.x, pos1.y); - nvgQuadTo(ctx.vg, pos4.x, pos4.y, pos2.x, pos2.y); - nvgStrokeColor(ctx.vg, colorShadow); - nvgStrokeWidth(ctx.vg, thickness); - nvgStroke(ctx.vg); + nvgBeginPath(vg); + nvgMoveTo(vg, pos1.x, pos1.y); + nvgQuadTo(vg, pos4.x, pos4.y, pos2.x, pos2.y); + nvgStrokeColor(vg, colorShadow); + nvgStrokeWidth(vg, thickness); + nvgStroke(vg); // Cable outline - nvgBeginPath(ctx.vg); - nvgMoveTo(ctx.vg, pos1.x, pos1.y); - nvgQuadTo(ctx.vg, pos3.x, pos3.y, pos2.x, pos2.y); - nvgStrokeColor(ctx.vg, colorOutline); - nvgStrokeWidth(ctx.vg, thickness); - nvgStroke(ctx.vg); + nvgBeginPath(vg); + nvgMoveTo(vg, pos1.x, pos1.y); + nvgQuadTo(vg, pos3.x, pos3.y, pos2.x, pos2.y); + nvgStrokeColor(vg, colorOutline); + nvgStrokeWidth(vg, thickness); + nvgStroke(vg); // Cable solid - nvgStrokeColor(ctx.vg, color); - nvgStrokeWidth(ctx.vg, thickness - 2); - nvgStroke(ctx.vg); + nvgStrokeColor(vg, color); + nvgStrokeWidth(vg, thickness - 2); + nvgStroke(vg); - nvgRestore(ctx.vg); + nvgRestore(vg); } } @@ -213,7 +213,7 @@ void CableWidget::fromJson(json_t *rootJ) { } } -void CableWidget::draw(const widget::DrawContext &ctx) { +void CableWidget::draw(const DrawArgs &args) { float opacity = settings.cableOpacity; float tension = settings.cableTension; float thickness = 5; @@ -241,33 +241,33 @@ void CableWidget::draw(const widget::DrawContext &ctx) { math::Vec outputPos = getOutputPos(); math::Vec inputPos = getInputPos(); - drawCable(ctx, outputPos, inputPos, color, thickness, tension, opacity); + drawCable(args.vg, outputPos, inputPos, color, thickness, tension, opacity); } -void CableWidget::drawPlugs(const widget::DrawContext &ctx) { +void CableWidget::drawPlugs(const DrawArgs &args) { // TODO Figure out a way to draw plugs first and cables last, and cut the plug portion of the cable off. math::Vec outputPos = getOutputPos(); math::Vec inputPos = getInputPos(); // Draw plug if the cable is on top, or if the cable is incomplete if (!isComplete() || APP->scene->rackWidget->getTopCable(outputPort) == this) { - drawPlug(ctx, outputPos, color); + drawPlug(args.vg, outputPos, color); if (isComplete()) { // Draw plug light - nvgSave(ctx.vg); - nvgTranslate(ctx.vg, outputPos.x - 4, outputPos.y - 4); - outputPort->plugLight->draw(ctx); - nvgRestore(ctx.vg); + nvgSave(args.vg); + nvgTranslate(args.vg, outputPos.x - 4, outputPos.y - 4); + outputPort->plugLight->draw(args); + nvgRestore(args.vg); } } if (!isComplete() || APP->scene->rackWidget->getTopCable(inputPort) == this) { - drawPlug(ctx, inputPos, color); + drawPlug(args.vg, inputPos, color); if (isComplete()) { - nvgSave(ctx.vg); - nvgTranslate(ctx.vg, inputPos.x - 4, inputPos.y - 4); - inputPort->plugLight->draw(ctx); - nvgRestore(ctx.vg); + nvgSave(args.vg); + nvgTranslate(args.vg, inputPos.x - 4, inputPos.y - 4); + inputPort->plugLight->draw(args); + nvgRestore(args.vg); } } } diff --git a/src/app/CircularShadow.cpp b/src/app/CircularShadow.cpp index 6f9c1cf9..cf75a7fe 100644 --- a/src/app/CircularShadow.cpp +++ b/src/app/CircularShadow.cpp @@ -10,19 +10,19 @@ CircularShadow::CircularShadow() { opacity = 0.15; } -void CircularShadow::draw(const widget::DrawContext &ctx) { +void CircularShadow::draw(const DrawArgs &args) { if (opacity <= 0.0) return; - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, -blurRadius, -blurRadius, box.size.x + 2*blurRadius, box.size.y + 2*blurRadius); + nvgBeginPath(args.vg); + nvgRect(args.vg, -blurRadius, -blurRadius, box.size.x + 2*blurRadius, box.size.y + 2*blurRadius); 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); - NVGpaint paint = nvgRadialGradient(ctx.vg, center.x, center.y, radius - blurRadius, radius, icol, ocol); - nvgFillPaint(ctx.vg, paint); - nvgFill(ctx.vg); + NVGpaint paint = nvgRadialGradient(args.vg, center.x, center.y, radius - blurRadius, radius, icol, ocol); + nvgFillPaint(args.vg, paint); + nvgFill(args.vg); } diff --git a/src/app/LedDisplay.cpp b/src/app/LedDisplay.cpp index 20d98247..3de85acb 100644 --- a/src/app/LedDisplay.cpp +++ b/src/app/LedDisplay.cpp @@ -9,16 +9,16 @@ namespace rack { namespace app { -void LedDisplay::draw(const widget::DrawContext &ctx) { +void LedDisplay::draw(const DrawArgs &args) { - nvgBeginPath(ctx.vg); - nvgRoundedRect(ctx.vg, 0, 0, box.size.x, box.size.y, 5.0); - nvgFillColor(ctx.vg, nvgRGB(0x00, 0x00, 0x00)); - nvgFill(ctx.vg); + nvgBeginPath(args.vg); + nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, 5.0); + nvgFillColor(args.vg, nvgRGB(0x00, 0x00, 0x00)); + nvgFill(args.vg); - nvgScissor(ctx.vg, RECT_ARGS(ctx.clipBox)); - widget::Widget::draw(ctx); - nvgResetScissor(ctx.vg); + nvgScissor(args.vg, RECT_ARGS(args.clipBox)); + widget::Widget::draw(args); + nvgResetScissor(args.vg); } @@ -26,13 +26,13 @@ LedDisplaySeparator::LedDisplaySeparator() { box.size = math::Vec(); } -void LedDisplaySeparator::draw(const widget::DrawContext &ctx) { - nvgBeginPath(ctx.vg); - nvgMoveTo(ctx.vg, 0, 0); - nvgLineTo(ctx.vg, box.size.x, box.size.y); - nvgStrokeWidth(ctx.vg, 1.0); - nvgStrokeColor(ctx.vg, nvgRGB(0x33, 0x33, 0x33)); - nvgStroke(ctx.vg); +void LedDisplaySeparator::draw(const DrawArgs &args) { + nvgBeginPath(args.vg); + nvgMoveTo(args.vg, 0, 0); + nvgLineTo(args.vg, box.size.x, box.size.y); + nvgStrokeWidth(args.vg, 1.0); + nvgStrokeColor(args.vg, nvgRGB(0x33, 0x33, 0x33)); + nvgStroke(args.vg); } @@ -44,21 +44,21 @@ LedDisplayChoice::LedDisplayChoice() { textOffset = math::Vec(10, 18); } -void LedDisplayChoice::draw(const widget::DrawContext &ctx) { +void LedDisplayChoice::draw(const DrawArgs &args) { if (bgColor.a > 0.0) { - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, 0, 0, box.size.x, box.size.y); - nvgFillColor(ctx.vg, bgColor); - nvgFill(ctx.vg); + nvgBeginPath(args.vg); + nvgRect(args.vg, 0, 0, box.size.x, box.size.y); + nvgFillColor(args.vg, bgColor); + nvgFill(args.vg); } if (font->handle >= 0) { - nvgFillColor(ctx.vg, color); - nvgFontFaceId(ctx.vg, font->handle); - nvgTextLetterSpacing(ctx.vg, 0.0); + nvgFillColor(args.vg, color); + nvgFontFaceId(args.vg, font->handle); + nvgTextLetterSpacing(args.vg, 0.0); - nvgFontSize(ctx.vg, 12); - nvgText(ctx.vg, textOffset.x, textOffset.y, text.c_str(), NULL); + nvgFontSize(args.vg, 12); + nvgText(args.vg, textOffset.x, textOffset.y, text.c_str(), NULL); } } @@ -78,14 +78,14 @@ LedDisplayTextField::LedDisplayTextField() { } -void LedDisplayTextField::draw(const widget::DrawContext &ctx) { - nvgScissor(ctx.vg, RECT_ARGS(ctx.clipBox)); +void LedDisplayTextField::draw(const DrawArgs &args) { + nvgScissor(args.vg, RECT_ARGS(args.clipBox)); // Background - nvgBeginPath(ctx.vg); - nvgRoundedRect(ctx.vg, 0, 0, box.size.x, box.size.y, 5.0); - nvgFillColor(ctx.vg, nvgRGB(0x00, 0x00, 0x00)); - nvgFill(ctx.vg); + nvgBeginPath(args.vg); + nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, 5.0); + nvgFillColor(args.vg, nvgRGB(0x00, 0x00, 0x00)); + nvgFill(args.vg); // Text if (font->handle >= 0) { @@ -95,14 +95,14 @@ void LedDisplayTextField::draw(const widget::DrawContext &ctx) { highlightColor.a = 0.5; int begin = std::min(cursor, selection); int end = (this == APP->event->selectedWidget) ? std::max(cursor, selection) : -1; - bndIconLabelCaret(ctx.vg, textOffset.x, textOffset.y, + bndIconLabelCaret(args.vg, textOffset.x, textOffset.y, box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, -1, color, 12, text.c_str(), highlightColor, begin, end); bndSetFont(APP->window->uiFont->handle); } - nvgResetScissor(ctx.vg); + nvgResetScissor(args.vg); } int LedDisplayTextField::getTextPosition(math::Vec mousePos) { diff --git a/src/app/LightWidget.cpp b/src/app/LightWidget.cpp index 7acefd6f..a96e1f9b 100644 --- a/src/app/LightWidget.cpp +++ b/src/app/LightWidget.cpp @@ -6,51 +6,51 @@ namespace rack { namespace app { -void LightWidget::draw(const widget::DrawContext &ctx) { - drawLight(ctx); - drawHalo(ctx); +void LightWidget::draw(const DrawArgs &args) { + drawLight(args); + drawHalo(args); } -void LightWidget::drawLight(const widget::DrawContext &ctx) { +void LightWidget::drawLight(const DrawArgs &args) { float radius = box.size.x / 2.0; - nvgBeginPath(ctx.vg); - nvgCircle(ctx.vg, radius, radius, radius); + nvgBeginPath(args.vg); + nvgCircle(args.vg, radius, radius, radius); // Background if (bgColor.a > 0.0) { - nvgFillColor(ctx.vg, bgColor); - nvgFill(ctx.vg); + nvgFillColor(args.vg, bgColor); + nvgFill(args.vg); } // Foreground if (color.a > 0.0) { - nvgFillColor(ctx.vg, color); - nvgFill(ctx.vg); + nvgFillColor(args.vg, color); + nvgFill(args.vg); } // Border if (borderColor.a > 0.0) { - nvgStrokeWidth(ctx.vg, 0.5); - nvgStrokeColor(ctx.vg, borderColor); - nvgStroke(ctx.vg); + nvgStrokeWidth(args.vg, 0.5); + nvgStrokeColor(args.vg, borderColor); + nvgStroke(args.vg); } } -void LightWidget::drawHalo(const widget::DrawContext &ctx) { +void LightWidget::drawHalo(const DrawArgs &args) { float radius = box.size.x / 2.0; float oradius = 4.0 * radius; - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, radius - oradius, radius - oradius, 2*oradius, 2*oradius); + nvgBeginPath(args.vg); + nvgRect(args.vg, radius - oradius, radius - oradius, 2*oradius, 2*oradius); NVGpaint paint; NVGcolor icol = color::mult(color, 0.07); NVGcolor ocol = nvgRGB(0, 0, 0); - paint = nvgRadialGradient(ctx.vg, radius, radius, radius, oradius, icol, ocol); - nvgFillPaint(ctx.vg, paint); - nvgGlobalCompositeOperation(ctx.vg, NVG_LIGHTER); - nvgFill(ctx.vg); + paint = nvgRadialGradient(args.vg, radius, radius, radius, oradius, icol, ocol); + nvgFillPaint(args.vg, paint); + nvgGlobalCompositeOperation(args.vg, NVG_LIGHTER); + nvgFill(args.vg); } diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index 51d36275..ef61b878 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -189,7 +189,7 @@ struct ModelBox : widget::OpaqueWidget { } } - void draw(const widget::DrawContext &ctx) override { + void draw(const DrawArgs &args) override { visibleFrames = 0; // Lazily create preview when drawn @@ -197,16 +197,16 @@ struct ModelBox : widget::OpaqueWidget { createPreview(); } - nvgScissor(ctx.vg, RECT_ARGS(ctx.clipBox)); - widget::OpaqueWidget::draw(ctx); - nvgResetScissor(ctx.vg); + nvgScissor(args.vg, RECT_ARGS(args.clipBox)); + widget::OpaqueWidget::draw(args); + nvgResetScissor(args.vg); // Translucent overlay when selected if (selected) { - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, 0.0, 0.0, box.size.x, box.size.y); - nvgFillColor(ctx.vg, nvgRGBAf(1, 1, 1, 0.25)); - nvgFill(ctx.vg); + nvgBeginPath(args.vg); + nvgRect(args.vg, 0.0, 0.0, box.size.x, box.size.y); + nvgFillColor(args.vg, nvgRGBAf(1, 1, 1, 0.25)); + nvgFill(args.vg); } } @@ -350,9 +350,9 @@ struct ModuleBrowser : widget::OpaqueWidget { widget::OpaqueWidget::step(); } - void draw(const widget::DrawContext &ctx) override { - bndMenuBackground(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, 0); - widget::Widget::draw(ctx); + void draw(const DrawArgs &args) override { + bndMenuBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y, 0); + widget::Widget::draw(args); } void setSearch(const std::string &search) { diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 3f7e7064..a068b0fa 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -141,59 +141,59 @@ ModuleWidget::~ModuleWidget() { setModule(NULL); } -void ModuleWidget::draw(const widget::DrawContext &ctx) { - nvgScissor(ctx.vg, RECT_ARGS(ctx.clipBox)); +void ModuleWidget::draw(const DrawArgs &args) { + nvgScissor(args.vg, RECT_ARGS(args.clipBox)); if (module && module->bypass) { - nvgGlobalAlpha(ctx.vg, 0.25); + nvgGlobalAlpha(args.vg, 0.25); } - widget::Widget::draw(ctx); + widget::Widget::draw(args); // Power meter if (module && settings.cpuMeter) { - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, + nvgBeginPath(args.vg); + nvgRect(args.vg, 0, box.size.y - 20, 105, 20); - nvgFillColor(ctx.vg, nvgRGBAf(0, 0, 0, 0.75)); - nvgFill(ctx.vg); + nvgFillColor(args.vg, nvgRGBAf(0, 0, 0, 0.75)); + nvgFill(args.vg); std::string cpuText = string::f("%.2f μs %.1f%%", module->cpuTime * 1e6f, module->cpuTime * APP->engine->getSampleRate() * 100); - bndLabel(ctx.vg, 2.0, box.size.y - 20.0, INFINITY, INFINITY, -1, cpuText.c_str()); + bndLabel(args.vg, 2.0, box.size.y - 20.0, INFINITY, INFINITY, -1, cpuText.c_str()); float p = math::clamp(module->cpuTime / APP->engine->getSampleTime(), 0.f, 1.f); - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, + nvgBeginPath(args.vg); + nvgRect(args.vg, 0, (1.f - p) * box.size.y, 5, p * box.size.y); - nvgFillColor(ctx.vg, nvgRGBAf(1, 0, 0, 1.0)); - nvgFill(ctx.vg); + nvgFillColor(args.vg, nvgRGBAf(1, 0, 0, 1.0)); + nvgFill(args.vg); } // if (module) { - // nvgBeginPath(ctx.vg); - // nvgRect(ctx.vg, 0, 0, 20, 20); - // nvgFillColor(ctx.vg, nvgRGBAf(0, 0, 0, 0.75)); - // nvgFill(ctx.vg); + // nvgBeginPath(args.vg); + // nvgRect(args.vg, 0, 0, 20, 20); + // nvgFillColor(args.vg, nvgRGBAf(0, 0, 0, 0.75)); + // nvgFill(args.vg); // std::string debugText = string::f("%d", module->id); - // bndLabel(ctx.vg, 0, 0, INFINITY, INFINITY, -1, debugText.c_str()); + // bndLabel(args.vg, 0, 0, INFINITY, INFINITY, -1, debugText.c_str()); // } - nvgResetScissor(ctx.vg); + nvgResetScissor(args.vg); } -void ModuleWidget::drawShadow(const widget::DrawContext &ctx) { - nvgBeginPath(ctx.vg); +void ModuleWidget::drawShadow(const DrawArgs &args) { + nvgBeginPath(args.vg); float r = 20; // Blur radius float c = 20; // Corner radius math::Vec b = math::Vec(-10, 30); // Offset from each corner - nvgRect(ctx.vg, b.x - r, b.y - r, box.size.x - 2*b.x + 2*r, box.size.y - 2*b.y + 2*r); + nvgRect(args.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); - nvgFillPaint(ctx.vg, nvgBoxGradient(ctx.vg, b.x, b.y, box.size.x - 2*b.x, box.size.y - 2*b.y, c, r, shadowColor, transparentColor)); - nvgFill(ctx.vg); + nvgFillPaint(args.vg, nvgBoxGradient(args.vg, b.x, b.y, box.size.x - 2*b.x, box.size.y - 2*b.y, c, r, shadowColor, transparentColor)); + nvgFill(args.vg); } void ModuleWidget::onHover(const event::Hover &e) { diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index 14e8c79d..66f32927 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -141,32 +141,32 @@ void ParamWidget::step() { widget::OpaqueWidget::step(); } -void ParamWidget::draw(const widget::DrawContext &ctx) { - widget::Widget::draw(ctx); +void ParamWidget::draw(const DrawArgs &args) { + widget::Widget::draw(args); // if (paramQuantity) { - // nvgBeginPath(ctx.vg); - // nvgRect(ctx.vg, + // nvgBeginPath(args.vg); + // nvgRect(args.vg, // box.size.x - 12, box.size.y - 12, // 12, 12); - // nvgFillColor(ctx.vg, nvgRGBAf(1, 0, 1, 0.9)); - // nvgFill(ctx.vg); + // nvgFillColor(args.vg, nvgRGBAf(1, 0, 1, 0.9)); + // nvgFill(args.vg); // std::string mapText = string::f("%d", paramQuantity->paramId); - // bndLabel(ctx.vg, box.size.x - 17.0, box.size.y - 16.0, INFINITY, INFINITY, -1, mapText.c_str()); + // bndLabel(args.vg, box.size.x - 17.0, box.size.y - 16.0, INFINITY, INFINITY, -1, mapText.c_str()); // } // Param map indicator engine::ParamHandle *paramHandle = paramQuantity ? APP->engine->getParamHandle(paramQuantity->module, paramQuantity->paramId) : NULL; if (paramHandle) { NVGcolor color = nvgRGB(0xff, 0x40, 0xff); - nvgBeginPath(ctx.vg); - nvgCircle(ctx.vg, box.size.x - 3, box.size.y - 3, 3.0); - nvgFillColor(ctx.vg, color); - nvgFill(ctx.vg); - nvgStrokeColor(ctx.vg, color::mult(color, 0.5)); - nvgStrokeWidth(ctx.vg, 1.0); - nvgStroke(ctx.vg); + nvgBeginPath(args.vg); + nvgCircle(args.vg, box.size.x - 3, box.size.y - 3, 3.0); + nvgFillColor(args.vg, color); + nvgFill(args.vg); + nvgStrokeColor(args.vg, color::mult(color, 0.5)); + nvgStrokeWidth(args.vg, 1.0); + nvgStroke(args.vg); } } diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index d674ac6a..65d41997 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -47,14 +47,14 @@ void PortWidget::step() { plugLight->setBrightnesses(values); } -void PortWidget::draw(const widget::DrawContext &ctx) { +void PortWidget::draw(const DrawArgs &args) { CableWidget *cw = APP->scene->rackWidget->incompleteCable; if (cw) { // Dim the PortWidget if the active cable cannot plug into this PortWidget if (type == OUTPUT ? cw->outputPort : cw->inputPort) - nvgGlobalAlpha(ctx.vg, 0.5); + nvgGlobalAlpha(args.vg, 0.5); } - widget::Widget::draw(ctx); + widget::Widget::draw(args); } void PortWidget::onButton(const event::Button &e) { diff --git a/src/app/RackRail.cpp b/src/app/RackRail.cpp index b5de5d6a..13e251e1 100644 --- a/src/app/RackRail.cpp +++ b/src/app/RackRail.cpp @@ -4,57 +4,57 @@ namespace rack { namespace app { -void RackRail::draw(const widget::DrawContext &ctx) { +void RackRail::draw(const DrawArgs &args) { const float railHeight = RACK_GRID_WIDTH; // Background color - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, 0.0, 0.0, box.size.x, box.size.y); - nvgFillColor(ctx.vg, nvgRGBf(0.2, 0.2, 0.2)); - nvgFill(ctx.vg); + nvgBeginPath(args.vg); + nvgRect(args.vg, 0.0, 0.0, box.size.x, box.size.y); + nvgFillColor(args.vg, nvgRGBf(0.2, 0.2, 0.2)); + nvgFill(args.vg); // Rails - nvgFillColor(ctx.vg, nvgRGBf(0.85, 0.85, 0.85)); - nvgStrokeWidth(ctx.vg, 1.0); - nvgStrokeColor(ctx.vg, nvgRGBf(0.7, 0.7, 0.7)); + nvgFillColor(args.vg, nvgRGBf(0.85, 0.85, 0.85)); + nvgStrokeWidth(args.vg, 1.0); + nvgStrokeColor(args.vg, nvgRGBf(0.7, 0.7, 0.7)); float holeRadius = 3.5; for (float railY = 0; railY < box.size.y; railY += RACK_GRID_HEIGHT) { // Top rail - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, 0, railY, box.size.x, railHeight); + nvgBeginPath(args.vg); + nvgRect(args.vg, 0, railY, box.size.x, railHeight); for (float railX = 0; railX < box.size.x; railX += RACK_GRID_WIDTH) { - nvgCircle(ctx.vg, railX + RACK_GRID_WIDTH / 2, railY + railHeight / 2, holeRadius); - nvgPathWinding(ctx.vg, NVG_HOLE); + nvgCircle(args.vg, railX + RACK_GRID_WIDTH / 2, railY + railHeight / 2, holeRadius); + nvgPathWinding(args.vg, NVG_HOLE); } - nvgFill(ctx.vg); + nvgFill(args.vg); - nvgBeginPath(ctx.vg); - nvgMoveTo(ctx.vg, 0, railY + railHeight - 0.5); - nvgLineTo(ctx.vg, box.size.x, railY + railHeight - 0.5); - nvgStroke(ctx.vg); + nvgBeginPath(args.vg); + nvgMoveTo(args.vg, 0, railY + railHeight - 0.5); + nvgLineTo(args.vg, box.size.x, railY + railHeight - 0.5); + nvgStroke(args.vg); // Bottom rail - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, 0, railY + RACK_GRID_HEIGHT - railHeight, box.size.x, railHeight); + nvgBeginPath(args.vg); + nvgRect(args.vg, 0, railY + RACK_GRID_HEIGHT - railHeight, box.size.x, railHeight); for (float railX = 0; railX < box.size.x; railX += RACK_GRID_WIDTH) { - nvgCircle(ctx.vg, railX + RACK_GRID_WIDTH / 2, railY + RACK_GRID_HEIGHT - railHeight + railHeight / 2, holeRadius); - nvgPathWinding(ctx.vg, NVG_HOLE); + nvgCircle(args.vg, railX + RACK_GRID_WIDTH / 2, railY + RACK_GRID_HEIGHT - railHeight + railHeight / 2, holeRadius); + nvgPathWinding(args.vg, NVG_HOLE); } - nvgFill(ctx.vg); + nvgFill(args.vg); - nvgBeginPath(ctx.vg); - nvgMoveTo(ctx.vg, 0, railY + RACK_GRID_HEIGHT - 0.5); - nvgLineTo(ctx.vg, box.size.x, railY + RACK_GRID_HEIGHT - 0.5); - nvgStroke(ctx.vg); + nvgBeginPath(args.vg); + nvgMoveTo(args.vg, 0, railY + RACK_GRID_HEIGHT - 0.5); + nvgLineTo(args.vg, box.size.x, railY + RACK_GRID_HEIGHT - 0.5); + nvgStroke(args.vg); } // Useful for screenshots if (0) { - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, 0.0, 0.0, box.size.x, box.size.y); - nvgFillColor(ctx.vg, nvgRGBf(1.0, 1.0, 1.0)); - nvgFill(ctx.vg); + nvgBeginPath(args.vg); + nvgRect(args.vg, 0.0, 0.0, box.size.x, box.size.y); + nvgFillColor(args.vg, nvgRGBf(1.0, 1.0, 1.0)); + nvgFill(args.vg); } } diff --git a/src/app/RackScrollWidget.cpp b/src/app/RackScrollWidget.cpp index 93e8ffe5..1a0baa86 100644 --- a/src/app/RackScrollWidget.cpp +++ b/src/app/RackScrollWidget.cpp @@ -28,8 +28,8 @@ void RackScrollWidget::step() { } -void RackScrollWidget::draw(const widget::DrawContext &ctx) { - ui::ScrollWidget::draw(ctx); +void RackScrollWidget::draw(const DrawArgs &args) { + ui::ScrollWidget::draw(args); } diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 54ce2285..fb1ad1fe 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -43,32 +43,32 @@ static ModuleWidget *moduleFromJson(json_t *moduleJ) { struct ModuleContainer : widget::Widget { - void draw(const widget::DrawContext &ctx) override { + void draw(const DrawArgs &args) override { // Draw shadows behind each ModuleWidget first, so the shadow doesn't overlap the front of other ModuleWidgets. for (widget::Widget *child : children) { ModuleWidget *w = dynamic_cast(child); assert(w); - nvgSave(ctx.vg); - nvgTranslate(ctx.vg, child->box.pos.x, child->box.pos.y); - w->drawShadow(ctx); - nvgRestore(ctx.vg); + nvgSave(args.vg); + nvgTranslate(args.vg, child->box.pos.x, child->box.pos.y); + w->drawShadow(args); + nvgRestore(args.vg); } - widget::Widget::draw(ctx); + widget::Widget::draw(args); } }; struct CableContainer : widget::TransparentWidget { - void draw(const widget::DrawContext &ctx) override { - widget::Widget::draw(ctx); + void draw(const DrawArgs &args) override { + widget::Widget::draw(args); // Draw cable plugs for (widget::Widget *w : children) { CableWidget *cw = dynamic_cast(w); assert(cw); - cw->drawPlugs(ctx); + cw->drawPlugs(args); } } }; @@ -117,8 +117,8 @@ void RackWidget::step() { widget::Widget::step(); } -void RackWidget::draw(const widget::DrawContext &ctx) { - widget::Widget::draw(ctx); +void RackWidget::draw(const DrawArgs &args) { + widget::Widget::draw(args); } void RackWidget::onHover(const event::Hover &e) { diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 22eed9cf..e9a879bf 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -87,8 +87,8 @@ void Scene::step() { } } -void Scene::draw(const widget::DrawContext &ctx) { - widget::OpaqueWidget::draw(ctx); +void Scene::draw(const DrawArgs &args) { + widget::OpaqueWidget::draw(args); } void Scene::onHoverKey(const event::HoverKey &e) { diff --git a/src/app/SvgPanel.cpp b/src/app/SvgPanel.cpp index bf977dff..bc244269 100644 --- a/src/app/SvgPanel.cpp +++ b/src/app/SvgPanel.cpp @@ -5,13 +5,13 @@ namespace rack { namespace app { -void PanelBorder::draw(const widget::DrawContext &ctx) { +void PanelBorder::draw(const DrawArgs &args) { NVGcolor borderColor = nvgRGBAf(0.5, 0.5, 0.5, 0.5); - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0); - nvgStrokeColor(ctx.vg, borderColor); - nvgStrokeWidth(ctx.vg, 1.0); - nvgStroke(ctx.vg); + nvgBeginPath(args.vg); + nvgRect(args.vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0); + nvgStrokeColor(args.vg, borderColor); + nvgStrokeWidth(args.vg, 1.0); + nvgStroke(args.vg); } diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index bf0db5a5..6a4591b0 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -27,8 +27,8 @@ struct MenuButton : ui::Button { box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str()) + 1.0; widget::Widget::step(); } - void draw(const widget::DrawContext &ctx) override { - bndMenuItem(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str()); + void draw(const DrawArgs &args) override { + bndMenuItem(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str()); } }; @@ -582,16 +582,16 @@ struct PluginsButton : MenuButton { } } - void draw(const widget::DrawContext &ctx) override { - MenuButton::draw(ctx); + void draw(const DrawArgs &args) override { + MenuButton::draw(args); // if (1) { // // Notification circle - // nvgBeginPath(ctx.vg); - // nvgCircle(ctx.vg, box.size.x - 3, 3, 4.0); - // nvgFillColor(ctx.vg, nvgRGBf(1.0, 0.0, 0.0)); - // nvgFill(ctx.vg); - // nvgStrokeColor(ctx.vg, nvgRGBf(0.5, 0.0, 0.0)); - // nvgStroke(ctx.vg); + // nvgBeginPath(args.vg); + // nvgCircle(args.vg, box.size.x - 3, 3, 4.0); + // nvgFillColor(args.vg, nvgRGBf(1.0, 0.0, 0.0)); + // nvgFill(args.vg); + // nvgStrokeColor(args.vg, nvgRGBf(0.5, 0.0, 0.0)); + // nvgStroke(args.vg); // } } }; @@ -676,11 +676,11 @@ Toolbar::Toolbar() { layout->addChild(helpButton); } -void Toolbar::draw(const widget::DrawContext &ctx) { - bndMenuBackground(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL); - bndBevel(ctx.vg, 0.0, 0.0, box.size.x, box.size.y); +void Toolbar::draw(const DrawArgs &args) { + bndMenuBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL); + bndBevel(args.vg, 0.0, 0.0, box.size.x, box.size.y); - widget::Widget::draw(ctx); + widget::Widget::draw(args); } diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 7b61d8e2..f1f08a63 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -192,7 +192,7 @@ static void Engine_stepModules(Engine *engine, int threadId) { int modulesLen = internal->modules.size(); float sampleTime = internal->sampleTime; - Module::ProcessContext processCtx; + Module::ProcessArgs processCtx; processCtx.sampleRate = internal->sampleRate; processCtx.sampleTime = internal->sampleTime; @@ -211,7 +211,6 @@ static void Engine_stepModules(Engine *engine, int threadId) { auto startTime = std::chrono::high_resolution_clock::now(); module->process(processCtx); - module->step(); auto stopTime = std::chrono::high_resolution_clock::now(); float cpuTime = std::chrono::duration(stopTime - startTime).count(); @@ -221,8 +220,6 @@ static void Engine_stepModules(Engine *engine, int threadId) { } else { module->process(processCtx); - // Call deprecated method - module->step(); } } diff --git a/src/ui/Button.cpp b/src/ui/Button.cpp index 897a5c59..b49ece23 100644 --- a/src/ui/Button.cpp +++ b/src/ui/Button.cpp @@ -14,8 +14,8 @@ Button::~Button() { delete quantity; } -void Button::draw(const widget::DrawContext &ctx) { - bndToolButton(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); +void Button::draw(const DrawArgs &args) { + bndToolButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); } void Button::onEnter(const event::Enter &e) { diff --git a/src/ui/ChoiceButton.cpp b/src/ui/ChoiceButton.cpp index 53912220..9894dbbd 100644 --- a/src/ui/ChoiceButton.cpp +++ b/src/ui/ChoiceButton.cpp @@ -5,8 +5,8 @@ namespace rack { namespace ui { -void ChoiceButton::draw(const widget::DrawContext &ctx) { - bndChoiceButton(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); +void ChoiceButton::draw(const DrawArgs &args) { + bndChoiceButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); } diff --git a/src/ui/Label.cpp b/src/ui/Label.cpp index 492acb58..b940eff5 100644 --- a/src/ui/Label.cpp +++ b/src/ui/Label.cpp @@ -11,7 +11,7 @@ Label::Label() { color = bndGetTheme()->regularTheme.textColor; } -void Label::draw(const widget::DrawContext &ctx) { +void Label::draw(const DrawArgs &args) { // TODO // Custom font sizes do not work with right or center alignment float x; @@ -21,14 +21,14 @@ void Label::draw(const widget::DrawContext &ctx) { x = 0.0; } break; case RIGHT_ALIGNMENT: { - x = box.size.x - bndLabelWidth(ctx.vg, -1, text.c_str()); + x = box.size.x - bndLabelWidth(args.vg, -1, text.c_str()); } break; case CENTER_ALIGNMENT: { - x = (box.size.x - bndLabelWidth(ctx.vg, -1, text.c_str())) / 2.0; + x = (box.size.x - bndLabelWidth(args.vg, -1, text.c_str())) / 2.0; } break; } - bndIconLabelValue(ctx.vg, x, 0.0, box.size.x, box.size.y, -1, color, BND_LEFT, fontSize, text.c_str(), NULL); + bndIconLabelValue(args.vg, x, 0.0, box.size.x, box.size.y, -1, color, BND_LEFT, fontSize, text.c_str(), NULL); } diff --git a/src/ui/Menu.cpp b/src/ui/Menu.cpp index 1346bfec..004bd8d6 100644 --- a/src/ui/Menu.cpp +++ b/src/ui/Menu.cpp @@ -49,9 +49,9 @@ void Menu::step() { } } -void Menu::draw(const widget::DrawContext &ctx) { - bndMenuBackground(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE); - widget::Widget::draw(ctx); +void Menu::draw(const DrawArgs &args) { + bndMenuBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE); + widget::Widget::draw(args); } void Menu::onHoverScroll(const event::HoverScroll &e) { diff --git a/src/ui/MenuItem.cpp b/src/ui/MenuItem.cpp index 5e054bb9..b6e3027e 100644 --- a/src/ui/MenuItem.cpp +++ b/src/ui/MenuItem.cpp @@ -5,7 +5,7 @@ namespace rack { namespace ui { -void MenuItem::draw(const widget::DrawContext &ctx) { +void MenuItem::draw(const DrawArgs &args) { BNDwidgetState state = BND_DEFAULT; if (APP->event->hoveredWidget == this) @@ -18,14 +18,14 @@ void MenuItem::draw(const widget::DrawContext &ctx) { // Main text and background if (!disabled) - bndMenuItem(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str()); + bndMenuItem(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str()); else - bndMenuLabel(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); + bndMenuLabel(args.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); // Right text - float x = box.size.x - bndLabelWidth(ctx.vg, -1, rightText.c_str()); + float x = box.size.x - bndLabelWidth(args.vg, -1, rightText.c_str()); NVGcolor rightColor = (state == BND_DEFAULT && !disabled) ? bndGetTheme()->menuTheme.textColor : bndGetTheme()->menuTheme.textSelectedColor; - bndIconLabelValue(ctx.vg, x, 0.0, box.size.x, box.size.y, -1, rightColor, BND_LEFT, BND_LABEL_FONT_SIZE, rightText.c_str(), NULL); + bndIconLabelValue(args.vg, x, 0.0, box.size.x, box.size.y, -1, rightColor, BND_LEFT, BND_LABEL_FONT_SIZE, rightText.c_str(), NULL); } void MenuItem::step() { diff --git a/src/ui/MenuLabel.cpp b/src/ui/MenuLabel.cpp index 72c0ee60..38e83367 100644 --- a/src/ui/MenuLabel.cpp +++ b/src/ui/MenuLabel.cpp @@ -6,8 +6,8 @@ namespace rack { namespace ui { -void MenuLabel::draw(const widget::DrawContext &ctx) { - bndMenuLabel(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); +void MenuLabel::draw(const DrawArgs &args) { + bndMenuLabel(args.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); } void MenuLabel::step() { diff --git a/src/ui/MenuSeparator.cpp b/src/ui/MenuSeparator.cpp index 3c39c314..016f51eb 100644 --- a/src/ui/MenuSeparator.cpp +++ b/src/ui/MenuSeparator.cpp @@ -9,14 +9,14 @@ MenuSeparator::MenuSeparator() { box.size.y = BND_WIDGET_HEIGHT / 2; } -void MenuSeparator::draw(const widget::DrawContext &ctx) { - nvgBeginPath(ctx.vg); +void MenuSeparator::draw(const DrawArgs &args) { + nvgBeginPath(args.vg); const float margin = 8.0; - nvgMoveTo(ctx.vg, margin, box.size.y / 2.0); - nvgLineTo(ctx.vg, box.size.x - margin, box.size.y / 2.0); - nvgStrokeWidth(ctx.vg, 1.0); - nvgStrokeColor(ctx.vg, color::alpha(bndGetTheme()->menuTheme.textColor, 0.25)); - nvgStroke(ctx.vg); + nvgMoveTo(args.vg, margin, box.size.y / 2.0); + nvgLineTo(args.vg, box.size.x - margin, box.size.y / 2.0); + nvgStrokeWidth(args.vg, 1.0); + nvgStrokeColor(args.vg, color::alpha(bndGetTheme()->menuTheme.textColor, 0.25)); + nvgStroke(args.vg); } diff --git a/src/ui/PasswordField.cpp b/src/ui/PasswordField.cpp index 73c4b6da..ef73be12 100644 --- a/src/ui/PasswordField.cpp +++ b/src/ui/PasswordField.cpp @@ -5,10 +5,10 @@ namespace rack { namespace ui { -void PasswordField::draw(const widget::DrawContext &ctx) { +void PasswordField::draw(const DrawArgs &args) { std::string textTmp = text; text = std::string(textTmp.size(), '*'); - TextField::draw(ctx); + TextField::draw(args); text = textTmp; } diff --git a/src/ui/ProgressBar.cpp b/src/ui/ProgressBar.cpp index 352b47c4..f3abf13a 100644 --- a/src/ui/ProgressBar.cpp +++ b/src/ui/ProgressBar.cpp @@ -14,10 +14,10 @@ ProgressBar::~ProgressBar() { delete quantity; } -void ProgressBar::draw(const widget::DrawContext &ctx) { +void ProgressBar::draw(const DrawArgs &args) { float progress = quantity ? quantity->getScaledValue() : 0.f; std::string text = quantity ? quantity->getString() : ""; - bndSlider(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL, BND_DEFAULT, progress, text.c_str(), NULL); + bndSlider(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL, BND_DEFAULT, progress, text.c_str(), NULL); } diff --git a/src/ui/RadioButton.cpp b/src/ui/RadioButton.cpp index 5e4c5fd8..ac78dbba 100644 --- a/src/ui/RadioButton.cpp +++ b/src/ui/RadioButton.cpp @@ -14,11 +14,11 @@ RadioButton::~RadioButton() { delete quantity; } -void RadioButton::draw(const widget::DrawContext &ctx) { +void RadioButton::draw(const DrawArgs &args) { std::string label; if (quantity) label = quantity->getLabel(); - bndRadioButton(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, label.c_str()); + bndRadioButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, label.c_str()); } void RadioButton::onEnter(const event::Enter &e) { diff --git a/src/ui/ScrollBar.cpp b/src/ui/ScrollBar.cpp index 6dc697b9..c0d0da81 100644 --- a/src/ui/ScrollBar.cpp +++ b/src/ui/ScrollBar.cpp @@ -12,8 +12,8 @@ ScrollBar::ScrollBar() { box.size = math::Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); } -void ScrollBar::draw(const widget::DrawContext &ctx) { - bndScrollBar(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size); +void ScrollBar::draw(const DrawArgs &args) { + bndScrollBar(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size); } void ScrollBar::onDragStart(const event::DragStart &e) { diff --git a/src/ui/ScrollWidget.cpp b/src/ui/ScrollWidget.cpp index 7ea535ea..9e35cbf3 100644 --- a/src/ui/ScrollWidget.cpp +++ b/src/ui/ScrollWidget.cpp @@ -27,10 +27,10 @@ void ScrollWidget::scrollTo(math::Rect r) { offset = offset.clampSafe(bound); } -void ScrollWidget::draw(const widget::DrawContext &ctx) { - nvgScissor(ctx.vg, RECT_ARGS(ctx.clipBox)); - widget::Widget::draw(ctx); - nvgResetScissor(ctx.vg); +void ScrollWidget::draw(const DrawArgs &args) { + nvgScissor(args.vg, RECT_ARGS(args.clipBox)); + widget::Widget::draw(args); + nvgResetScissor(args.vg); } void ScrollWidget::step() { diff --git a/src/ui/Slider.cpp b/src/ui/Slider.cpp index ec35bf86..9a529bdf 100644 --- a/src/ui/Slider.cpp +++ b/src/ui/Slider.cpp @@ -17,10 +17,10 @@ Slider::~Slider() { delete quantity; } -void Slider::draw(const widget::DrawContext &ctx) { +void Slider::draw(const DrawArgs &args) { float progress = quantity ? quantity->getScaledValue() : 0.f; std::string text = quantity ? quantity->getString() : ""; - bndSlider(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL); + bndSlider(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL); } void Slider::onDragStart(const event::DragStart &e) { diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index e4935b2f..b8ae3348 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -8,8 +8,8 @@ TextField::TextField() { box.size.y = BND_WIDGET_HEIGHT; } -void TextField::draw(const widget::DrawContext &ctx) { - nvgScissor(ctx.vg, RECT_ARGS(ctx.clipBox)); +void TextField::draw(const DrawArgs &args) { + nvgScissor(args.vg, RECT_ARGS(args.clipBox)); BNDwidgetState state; if (this == APP->event->selectedWidget) @@ -21,13 +21,13 @@ void TextField::draw(const widget::DrawContext &ctx) { int begin = std::min(cursor, selection); int end = std::max(cursor, selection); - bndTextField(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str(), begin, end); + bndTextField(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str(), begin, end); // Draw placeholder text if (text.empty() && state != BND_ACTIVE) { - bndIconLabelCaret(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, -1, bndGetTheme()->textFieldTheme.itemColor, 13, placeholder.c_str(), bndGetTheme()->textFieldTheme.itemColor, 0, -1); + bndIconLabelCaret(args.vg, 0.0, 0.0, box.size.x, box.size.y, -1, bndGetTheme()->textFieldTheme.itemColor, 13, placeholder.c_str(), bndGetTheme()->textFieldTheme.itemColor, 0, -1); } - nvgResetScissor(ctx.vg); + nvgResetScissor(args.vg); } void TextField::onButton(const event::Button &e) { diff --git a/src/ui/Tooltip.cpp b/src/ui/Tooltip.cpp index e4f3ce5d..51862552 100644 --- a/src/ui/Tooltip.cpp +++ b/src/ui/Tooltip.cpp @@ -14,10 +14,10 @@ void Tooltip::step() { widget::Widget::step(); } -void Tooltip::draw(const widget::DrawContext &ctx) { - bndTooltipBackground(ctx.vg, 0.0, 0.0, box.size.x, box.size.y); - bndMenuLabel(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); - widget::Widget::draw(ctx); +void Tooltip::draw(const DrawArgs &args) { + bndTooltipBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y); + bndMenuLabel(args.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); + widget::Widget::draw(args); } diff --git a/src/widget/FramebufferWidget.cpp b/src/widget/FramebufferWidget.cpp index 11b61132..39a03b31 100644 --- a/src/widget/FramebufferWidget.cpp +++ b/src/widget/FramebufferWidget.cpp @@ -15,17 +15,17 @@ FramebufferWidget::~FramebufferWidget() { nvgluDeleteFramebuffer(fb); } -void FramebufferWidget::draw(const DrawContext &ctx) { +void FramebufferWidget::draw(const DrawArgs &args) { // Bypass framebuffer rendering if we're already drawing in a framebuffer // In other words, disallow nested framebuffers. They look bad. - if (ctx.vg == APP->window->fbVg) { - Widget::draw(ctx); + if (args.vg == APP->window->fbVg) { + Widget::draw(args); return; } // Get world transform float xform[6]; - nvgCurrentTransform(ctx.vg, xform); + nvgCurrentTransform(args.vg, xform); // Skew and rotate is not supported assert(math::isNear(xform[1], 0.f)); assert(math::isNear(xform[2], 0.f)); @@ -66,7 +66,7 @@ void FramebufferWidget::draw(const DrawContext &ctx) { nvgluDeleteFramebuffer(fb); // Create a framebuffer from the main nanovg context. We will draw to this in the secondary nanovg context. if (fbSize.isFinite() && !fbSize.isZero()) - fb = nvgluCreateFramebuffer(ctx.vg, fbSize.x, fbSize.y, 0); + fb = nvgluCreateFramebuffer(args.vg, fbSize.x, fbSize.y, 0); } if (!fb) @@ -81,28 +81,28 @@ void FramebufferWidget::draw(const DrawContext &ctx) { return; // Draw framebuffer image, using world coordinates - nvgSave(ctx.vg); - nvgResetTransform(ctx.vg); + nvgSave(args.vg); + nvgResetTransform(args.vg); - nvgBeginPath(ctx.vg); - nvgRect(ctx.vg, + nvgBeginPath(args.vg); + nvgRect(args.vg, offsetI.x + fbBox.pos.x, offsetI.y + fbBox.pos.y, fbBox.size.x, fbBox.size.y); - NVGpaint paint = nvgImagePattern(ctx.vg, + NVGpaint paint = nvgImagePattern(args.vg, offsetI.x + fbBox.pos.x, offsetI.y + fbBox.pos.y, fbBox.size.x, fbBox.size.y, 0.0, fb->image, 1.0); - nvgFillPaint(ctx.vg, paint); - nvgFill(ctx.vg); + nvgFillPaint(args.vg, paint); + nvgFill(args.vg); // For debugging the bounding box of the framebuffer - // nvgStrokeWidth(ctx.vg, 2.0); - // nvgStrokeColor(ctx.vg, nvgRGBAf(1, 1, 0, 0.5)); - // nvgStroke(ctx.vg); + // nvgStrokeWidth(args.vg, 2.0); + // nvgStrokeColor(args.vg, nvgRGBAf(1, 1, 0, 0.5)); + // nvgStroke(args.vg); - nvgRestore(ctx.vg); + nvgRestore(args.vg); } void FramebufferWidget::drawFramebuffer() { @@ -116,9 +116,9 @@ void FramebufferWidget::drawFramebuffer() { nvgTranslate(vg, fbOffset.x, fbOffset.y); nvgScale(vg, fbScale.x, fbScale.y); - DrawContext ctx; - ctx.vg = vg; - Widget::draw(ctx); + DrawArgs args; + args.vg = vg; + Widget::draw(args); glViewport(0.0, 0.0, fbSize.x, fbSize.y); glClearColor(0.0, 0.0, 0.0, 0.0); diff --git a/src/widget/SvgWidget.cpp b/src/widget/SvgWidget.cpp index f40f0032..9129e6cb 100644 --- a/src/widget/SvgWidget.cpp +++ b/src/widget/SvgWidget.cpp @@ -20,9 +20,9 @@ void SvgWidget::setSvg(std::shared_ptr svg) { wrap(); } -void SvgWidget::draw(const DrawContext &ctx) { +void SvgWidget::draw(const DrawArgs &args) { if (svg && svg->handle) { - svgDraw(ctx.vg, svg->handle); + svgDraw(args.vg, svg->handle); } } diff --git a/src/widget/Widget.cpp b/src/widget/Widget.cpp index dd9bc5df..fb3b1e0c 100644 --- a/src/widget/Widget.cpp +++ b/src/widget/Widget.cpp @@ -144,33 +144,33 @@ void Widget::step() { } } -void Widget::draw(const DrawContext &ctx) { +void Widget::draw(const DrawArgs &args) { // Iterate children for (Widget *child : children) { // Don't draw if invisible if (!child->visible) continue; // Don't draw if child is outside clip box - if (!ctx.clipBox.isIntersecting(child->box)) + if (!args.clipBox.isIntersecting(child->box)) continue; - DrawContext childCtx = ctx; + DrawArgs childCtx = args; // Intersect child clip box with self childCtx.clipBox = childCtx.clipBox.intersect(child->box); childCtx.clipBox.pos = childCtx.clipBox.pos.minus(child->box.pos); - nvgSave(ctx.vg); - nvgTranslate(ctx.vg, child->box.pos.x, child->box.pos.y); + nvgSave(args.vg); + nvgTranslate(args.vg, child->box.pos.x, child->box.pos.y); + + child->draw(childCtx); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // Call deprecated draw function, which does nothing by default - child->draw(ctx.vg); + child->draw(args.vg); #pragma GCC diagnostic pop - child->draw(childCtx); - - nvgRestore(ctx.vg); + nvgRestore(args.vg); } } diff --git a/src/widget/ZoomWidget.cpp b/src/widget/ZoomWidget.cpp index 7f0c0e6d..73986179 100644 --- a/src/widget/ZoomWidget.cpp +++ b/src/widget/ZoomWidget.cpp @@ -29,12 +29,12 @@ void ZoomWidget::setZoom(float zoom) { Widget::onZoom(eZoom); } -void ZoomWidget::draw(const DrawContext &ctx) { - DrawContext zoomCtx = ctx; +void ZoomWidget::draw(const DrawArgs &args) { + DrawArgs zoomCtx = args; zoomCtx.clipBox.pos = zoomCtx.clipBox.pos.div(zoom); zoomCtx.clipBox.size = zoomCtx.clipBox.size.div(zoom); // No need to save the state because that is done in the parent - nvgScale(ctx.vg, zoom, zoom); + nvgScale(args.vg, zoom, zoom); Widget::draw(zoomCtx); } diff --git a/src/window.cpp b/src/window.cpp index 2a6c3d09..43a8e7dd 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -385,9 +385,10 @@ void Window::run() { nvgBeginFrame(vg, fbWidth, fbHeight, pixelRatio); nvgScale(vg, pixelRatio, pixelRatio); - widget::DrawContext ctx; - ctx.vg = vg; - APP->event->rootWidget->draw(ctx); + widget::Widget::DrawArgs args; + args.vg = vg; + args.clipBox = APP->event->rootWidget->box.zeroPos(); + APP->event->rootWidget->draw(args); glViewport(0, 0, fbWidth, fbHeight); glClearColor(0.0, 0.0, 0.0, 1.0);