@@ -28,8 +28,8 @@ struct CableWidget : widget::OpaqueWidget { | |||||
math::Vec getInputPos(); | math::Vec getInputPos(); | ||||
json_t *toJson(); | json_t *toJson(); | ||||
void fromJson(json_t *rootJ); | 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); | |||||
}; | }; | ||||
@@ -11,7 +11,7 @@ struct CircularShadow : widget::TransparentWidget { | |||||
float blurRadius; | float blurRadius; | ||||
float opacity; | float opacity; | ||||
CircularShadow(); | CircularShadow(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -10,12 +10,12 @@ namespace app { | |||||
struct LedDisplay : widget::OpaqueWidget { | struct LedDisplay : widget::OpaqueWidget { | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
struct LedDisplaySeparator : widget::TransparentWidget { | struct LedDisplaySeparator : widget::TransparentWidget { | ||||
LedDisplaySeparator(); | LedDisplaySeparator(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
struct LedDisplayChoice : widget::TransparentWidget { | struct LedDisplayChoice : widget::TransparentWidget { | ||||
@@ -25,7 +25,7 @@ struct LedDisplayChoice : widget::TransparentWidget { | |||||
NVGcolor color; | NVGcolor color; | ||||
NVGcolor bgColor; | NVGcolor bgColor; | ||||
LedDisplayChoice(); | LedDisplayChoice(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onButton(const event::Button &e) override; | void onButton(const event::Button &e) override; | ||||
}; | }; | ||||
@@ -34,7 +34,7 @@ struct LedDisplayTextField : ui::TextField { | |||||
math::Vec textOffset; | math::Vec textOffset; | ||||
NVGcolor color; | NVGcolor color; | ||||
LedDisplayTextField(); | LedDisplayTextField(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
int getTextPosition(math::Vec mousePos) override; | int getTextPosition(math::Vec mousePos) override; | ||||
}; | }; | ||||
@@ -11,9 +11,9 @@ struct LightWidget : widget::TransparentWidget { | |||||
NVGcolor bgColor = nvgRGBA(0, 0, 0, 0); | NVGcolor bgColor = nvgRGBA(0, 0, 0, 0); | ||||
NVGcolor color = nvgRGBA(0, 0, 0, 0); | NVGcolor color = nvgRGBA(0, 0, 0, 0); | ||||
NVGcolor borderColor = 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); | |||||
}; | }; | ||||
@@ -32,8 +32,8 @@ struct ModuleWidget : widget::OpaqueWidget { | |||||
} | } | ||||
~ModuleWidget(); | ~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 onHover(const event::Hover &e) override; | ||||
void onButton(const event::Button &e) override; | void onButton(const event::Button &e) override; | ||||
@@ -18,7 +18,7 @@ struct ParamWidget : widget::OpaqueWidget { | |||||
~ParamWidget(); | ~ParamWidget(); | ||||
void step() override; | void step() override; | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onButton(const event::Button &e) override; | void onButton(const event::Button &e) override; | ||||
void onDoubleClick(const event::DoubleClick &e) override; | void onDoubleClick(const event::DoubleClick &e) override; | ||||
void onEnter(const event::Enter &e) override; | void onEnter(const event::Enter &e) override; | ||||
@@ -26,7 +26,7 @@ struct PortWidget : widget::OpaqueWidget { | |||||
~PortWidget(); | ~PortWidget(); | ||||
void step() override; | void step() override; | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onButton(const event::Button &e) override; | void onButton(const event::Button &e) override; | ||||
void onEnter(const event::Enter &e) override; | void onEnter(const event::Enter &e) override; | ||||
@@ -8,7 +8,7 @@ namespace app { | |||||
struct RackRail : widget::TransparentWidget { | struct RackRail : widget::TransparentWidget { | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -9,7 +9,7 @@ namespace app { | |||||
struct RackScrollWidget : ui::ScrollWidget { | struct RackScrollWidget : ui::ScrollWidget { | ||||
void step() override; | void step() override; | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -26,7 +26,7 @@ struct RackWidget : widget::OpaqueWidget { | |||||
~RackWidget(); | ~RackWidget(); | ||||
void step() override; | void step() override; | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onHover(const event::Hover &e) override; | void onHover(const event::Hover &e) override; | ||||
void onHoverKey(const event::HoverKey &e) override; | void onHoverKey(const event::HoverKey &e) override; | ||||
@@ -30,7 +30,7 @@ struct Scene : widget::OpaqueWidget { | |||||
Scene(); | Scene(); | ||||
~Scene(); | ~Scene(); | ||||
void step() override; | void step() override; | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onHoverKey(const event::HoverKey &e) override; | void onHoverKey(const event::HoverKey &e) override; | ||||
void onPathDrop(const event::PathDrop &e) override; | void onPathDrop(const event::PathDrop &e) override; | ||||
@@ -11,7 +11,7 @@ namespace app { | |||||
struct PanelBorder : widget::TransparentWidget { | struct PanelBorder : widget::TransparentWidget { | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -13,7 +13,7 @@ struct Toolbar : widget::OpaqueWidget { | |||||
float cableTension = 0.5; | float cableTension = 0.5; | ||||
Toolbar(); | Toolbar(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -38,7 +38,7 @@ struct Module { | |||||
void reset(); | void reset(); | ||||
void randomize(); | void randomize(); | ||||
struct ProcessContext { | |||||
struct ProcessArgs { | |||||
float sampleRate; | float sampleRate; | ||||
float sampleTime; | float sampleTime; | ||||
}; | }; | ||||
@@ -46,9 +46,14 @@ struct Module { | |||||
/** Advances the module by one audio sample. | /** Advances the module by one audio sample. | ||||
Override this method to read Inputs and Params and to write Outputs and Lights. | 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. */ | /** Called when the engine sample rate is changed. */ | ||||
virtual void onSampleRateChange() {} | virtual void onSampleRateChange() {} | ||||
@@ -16,7 +16,7 @@ struct Button : widget::OpaqueWidget { | |||||
Button(); | Button(); | ||||
~Button(); | ~Button(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onEnter(const event::Enter &e) override; | void onEnter(const event::Enter &e) override; | ||||
void onLeave(const event::Leave &e) override; | void onLeave(const event::Leave &e) override; | ||||
void onDragStart(const event::DragStart &e) override; | void onDragStart(const event::DragStart &e) override; | ||||
@@ -8,7 +8,7 @@ namespace ui { | |||||
struct ChoiceButton : Button { | struct ChoiceButton : Button { | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -20,7 +20,7 @@ struct Label : widget::Widget { | |||||
Alignment alignment = LEFT_ALIGNMENT; | Alignment alignment = LEFT_ALIGNMENT; | ||||
Label(); | Label(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -18,7 +18,7 @@ struct Menu : widget::OpaqueWidget { | |||||
~Menu(); | ~Menu(); | ||||
void setChildMenu(Menu *menu); | void setChildMenu(Menu *menu); | ||||
void step() override; | void step() override; | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onHoverScroll(const event::HoverScroll &e) override; | void onHoverScroll(const event::HoverScroll &e) override; | ||||
}; | }; | ||||
@@ -18,7 +18,7 @@ struct MenuItem : MenuEntry { | |||||
std::string rightText; | std::string rightText; | ||||
bool disabled = false; | bool disabled = false; | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void step() override; | void step() override; | ||||
void onEnter(const event::Enter &e) override; | void onEnter(const event::Enter &e) override; | ||||
void onDragStart(const event::DragStart &e) override; | void onDragStart(const event::DragStart &e) override; | ||||
@@ -10,7 +10,7 @@ namespace ui { | |||||
struct MenuLabel : MenuEntry { | struct MenuLabel : MenuEntry { | ||||
std::string text; | std::string text; | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void step() override; | void step() override; | ||||
}; | }; | ||||
@@ -9,7 +9,7 @@ namespace ui { | |||||
struct MenuSeparator : MenuEntry { | struct MenuSeparator : MenuEntry { | ||||
MenuSeparator(); | MenuSeparator(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -8,7 +8,7 @@ namespace ui { | |||||
struct PasswordField : TextField { | struct PasswordField : TextField { | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -13,7 +13,7 @@ struct ProgressBar : widget::Widget { | |||||
ProgressBar(); | ProgressBar(); | ||||
~ProgressBar(); | ~ProgressBar(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -14,7 +14,7 @@ struct RadioButton : widget::OpaqueWidget { | |||||
RadioButton(); | RadioButton(); | ||||
~RadioButton(); | ~RadioButton(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onEnter(const event::Enter &e) override; | void onEnter(const event::Enter &e) override; | ||||
void onLeave(const event::Leave &e) override; | void onLeave(const event::Leave &e) override; | ||||
void onDragDrop(const event::DragDrop &e) override; | void onDragDrop(const event::DragDrop &e) override; | ||||
@@ -19,7 +19,7 @@ struct ScrollBar : widget::OpaqueWidget { | |||||
float size = 0.0; | float size = 0.0; | ||||
ScrollBar(); | ScrollBar(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onDragStart(const event::DragStart &e) override; | void onDragStart(const event::DragStart &e) override; | ||||
void onDragMove(const event::DragMove &e) override; | void onDragMove(const event::DragMove &e) override; | ||||
void onDragEnd(const event::DragEnd &e) override; | void onDragEnd(const event::DragEnd &e) override; | ||||
@@ -17,7 +17,7 @@ struct ScrollWidget : widget::Widget { | |||||
ScrollWidget(); | ScrollWidget(); | ||||
void scrollTo(math::Rect r); | void scrollTo(math::Rect r); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void step() override; | void step() override; | ||||
void onHover(const event::Hover &e) override; | void onHover(const event::Hover &e) override; | ||||
void onHoverScroll(const event::HoverScroll &e) override; | void onHoverScroll(const event::HoverScroll &e) override; | ||||
@@ -15,7 +15,7 @@ struct Slider : widget::OpaqueWidget { | |||||
Slider(); | Slider(); | ||||
~Slider(); | ~Slider(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onDragStart(const event::DragStart &e) override; | void onDragStart(const event::DragStart &e) override; | ||||
void onDragMove(const event::DragMove &e) override; | void onDragMove(const event::DragMove &e) override; | ||||
void onDragEnd(const event::DragEnd &e) override; | void onDragEnd(const event::DragEnd &e) override; | ||||
@@ -21,7 +21,7 @@ struct TextField : widget::OpaqueWidget { | |||||
int selection = 0; | int selection = 0; | ||||
TextField(); | TextField(); | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onButton(const event::Button &e) override; | void onButton(const event::Button &e) override; | ||||
void onHover(const event::Hover &e) override; | void onHover(const event::Hover &e) override; | ||||
void onEnter(const event::Enter &e) override; | void onEnter(const event::Enter &e) override; | ||||
@@ -11,7 +11,7 @@ struct Tooltip : widget::Widget { | |||||
std::string text; | std::string text; | ||||
void step() override; | void step() override; | ||||
void draw(const widget::DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -28,7 +28,7 @@ struct FramebufferWidget : Widget { | |||||
FramebufferWidget(); | FramebufferWidget(); | ||||
~FramebufferWidget(); | ~FramebufferWidget(); | ||||
void draw(const DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
virtual void drawFramebuffer(); | virtual void drawFramebuffer(); | ||||
int getImageHandle(); | int getImageHandle(); | ||||
@@ -18,7 +18,7 @@ struct SvgWidget : Widget { | |||||
void setSvg(std::shared_ptr<Svg> svg); | void setSvg(std::shared_ptr<Svg> svg); | ||||
DEPRECATED void setSVG(std::shared_ptr<Svg> svg) {setSvg(svg);} | DEPRECATED void setSVG(std::shared_ptr<Svg> svg) {setSvg(svg);} | ||||
void draw(const DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
}; | }; | ||||
@@ -37,10 +37,10 @@ struct TransformWidget : Widget { | |||||
nvgTransformPremultiply(transform, t); | 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 | // 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); | |||||
} | } | ||||
}; | }; | ||||
@@ -15,12 +15,6 @@ namespace rack { | |||||
namespace widget { | 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). | /** 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 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. | 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 */ | /** Advances the module by one frame */ | ||||
virtual void step(); | virtual void step(); | ||||
struct DrawArgs { | |||||
NVGcontext *vg; | |||||
math::Rect clipBox; | |||||
}; | |||||
/** Draws the widget to the NanoVG context */ | /** 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) {} | DEPRECATED virtual void draw(NVGcontext *vg) {} | ||||
// Events | // Events | ||||
@@ -13,7 +13,7 @@ struct ZoomWidget : Widget { | |||||
math::Vec getRelativeOffset(math::Vec v, Widget *relative) override; | math::Vec getRelativeOffset(math::Vec v, Widget *relative) override; | ||||
math::Rect getViewport(math::Rect r) override; | math::Rect getViewport(math::Rect r) override; | ||||
void setZoom(float zoom); | void setZoom(float zoom); | ||||
void draw(const DrawContext &ctx) override; | |||||
void draw(const DrawArgs &args) override; | |||||
void onHover(const event::Hover &e) override { | void onHover(const event::Hover &e) override { | ||||
event::Hover e2 = e; | event::Hover e2 = e; | ||||
@@ -122,10 +122,10 @@ struct AudioInterface : Module { | |||||
onSampleRateChange(); | onSampleRateChange(); | ||||
} | } | ||||
void process(const ProcessContext &ctx) override { | |||||
void process(const ProcessArgs &args) override { | |||||
// Update SRC states | // 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); | inputSrc.setChannels(port.numInputs); | ||||
outputSrc.setChannels(port.numOutputs); | outputSrc.setChannels(port.numOutputs); | ||||
@@ -17,12 +17,12 @@ struct BlankPanel : Widget { | |||||
Widget::step(); | 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); | 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) { | for (float x = 5.0; x <= 10.0; x += 5.0) { | ||||
nvgBeginPath(ctx.vg); | |||||
nvgBeginPath(args.vg); | |||||
const float margin = 5.0; | 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); | |||||
} | } | ||||
} | } | ||||
}; | }; | ||||
@@ -62,9 +62,9 @@ struct CV_CC : Module { | |||||
midiOutput.midi::Output::reset(); | midiOutput.midi::Output::reset(); | ||||
} | } | ||||
void process(const ProcessContext &ctx) override { | |||||
void process(const ProcessArgs &args) override { | |||||
const float rateLimiterPeriod = 0.010f; | const float rateLimiterPeriod = 0.010f; | ||||
rateLimiterPhase += ctx.sampleTime / rateLimiterPeriod; | |||||
rateLimiterPhase += args.sampleTime / rateLimiterPeriod; | |||||
if (rateLimiterPhase >= 1.f) { | if (rateLimiterPhase >= 1.f) { | ||||
rateLimiterPhase -= 1.f; | rateLimiterPhase -= 1.f; | ||||
} | } | ||||
@@ -89,7 +89,7 @@ struct CV_Gate : Module { | |||||
midiOutput.midi::Output::reset(); | midiOutput.midi::Output::reset(); | ||||
} | } | ||||
void process(const ProcessContext &ctx) override { | |||||
void process(const ProcessArgs &args) override { | |||||
for (int i = 0; i < 16; i++) { | for (int i = 0; i < 16; i++) { | ||||
int note = learnedNotes[i]; | int note = learnedNotes[i]; | ||||
if (velocityMode) { | if (velocityMode) { | ||||
@@ -241,9 +241,9 @@ struct CV_MIDI : Module { | |||||
midiOutput.midi::Output::reset(); | midiOutput.midi::Output::reset(); | ||||
} | } | ||||
void process(const ProcessContext &ctx) override { | |||||
void process(const ProcessArgs &args) override { | |||||
const float rateLimiterPeriod = 0.005f; | const float rateLimiterPeriod = 0.005f; | ||||
rateLimiterPhase += ctx.sampleTime / rateLimiterPeriod; | |||||
rateLimiterPhase += args.sampleTime / rateLimiterPeriod; | |||||
if (rateLimiterPhase >= 1.f) { | if (rateLimiterPhase >= 1.f) { | ||||
rateLimiterPhase -= 1.f; | rateLimiterPhase -= 1.f; | ||||
} | } | ||||
@@ -42,7 +42,7 @@ struct MIDI_CC : Module { | |||||
midiInput.reset(); | midiInput.reset(); | ||||
} | } | ||||
void process(const ProcessContext &ctx) override { | |||||
void process(const ProcessArgs &args) override { | |||||
midi::Message msg; | midi::Message msg; | ||||
while (midiInput.shift(&msg)) { | while (midiInput.shift(&msg)) { | ||||
processMessage(msg); | processMessage(msg); | ||||
@@ -63,7 +63,7 @@ struct MIDI_CC : Module { | |||||
} | } | ||||
else { | else { | ||||
// Smooth value with filter | // Smooth value with filter | ||||
valueFilters[i].process(ctx.sampleTime, value); | |||||
valueFilters[i].process(args.sampleTime, value); | |||||
} | } | ||||
lastValues[i] = values[cc]; | lastValues[i] = values[cc]; | ||||
outputs[CC_OUTPUT + i].setVoltage(valueFilters[i].out); | outputs[CC_OUTPUT + i].setVoltage(valueFilters[i].out); | ||||
@@ -103,7 +103,7 @@ struct MIDI_CV : Module { | |||||
heldNotes.clear(); | heldNotes.clear(); | ||||
} | } | ||||
void process(const ProcessContext &ctx) override { | |||||
void process(const ProcessArgs &args) override { | |||||
midi::Message msg; | midi::Message msg; | ||||
while (midiInput.shift(&msg)) { | while (midiInput.shift(&msg)) { | ||||
processMessage(msg); | processMessage(msg); | ||||
@@ -119,29 +119,29 @@ struct MIDI_CV : Module { | |||||
outputs[GATE_OUTPUT].setVoltage(gates[c] ? 10.f : 0.f, c); | 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[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[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) { | if (polyMode == MPE_MODE) { | ||||
for (int c = 0; c < channels; c++) { | for (int c = 0; c < channels; c++) { | ||||
outputs[PITCH_OUTPUT].setChannels(channels); | outputs[PITCH_OUTPUT].setChannels(channels); | ||||
outputs[MOD_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 { | else { | ||||
outputs[PITCH_OUTPUT].setChannels(1); | outputs[PITCH_OUTPUT].setChannels(1); | ||||
outputs[MOD_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) { | void processMessage(midi::Message msg) { | ||||
@@ -46,7 +46,7 @@ struct MIDI_Gate : Module { | |||||
} | } | ||||
} | } | ||||
void process(const ProcessContext &ctx) override { | |||||
void process(const ProcessArgs &args) override { | |||||
midi::Message msg; | midi::Message msg; | ||||
while (midiInput.shift(&msg)) { | while (midiInput.shift(&msg)) { | ||||
processMessage(msg); | processMessage(msg); | ||||
@@ -58,7 +58,7 @@ struct MIDI_Gate : Module { | |||||
// If the gate is off, wait 1 ms before turning the pulse off. | // If the gate is off, wait 1 ms before turning the pulse off. | ||||
// This avoids drum controllers sending a pulse with 0 ms duration. | // This avoids drum controllers sending a pulse with 0 ms duration. | ||||
if (!gates[i]) { | if (!gates[i]) { | ||||
gateTimes[i] -= ctx.sampleTime; | |||||
gateTimes[i] -= args.sampleTime; | |||||
} | } | ||||
} | } | ||||
else { | else { | ||||
@@ -65,7 +65,7 @@ struct MIDI_Map : Module { | |||||
midiInput.reset(); | midiInput.reset(); | ||||
} | } | ||||
void process(const ProcessContext &ctx) override { | |||||
void process(const ProcessArgs &args) override { | |||||
midi::Message msg; | midi::Message msg; | ||||
while (midiInput.shift(&msg)) { | while (midiInput.shift(&msg)) { | ||||
processMessage(msg); | processMessage(msg); | ||||
@@ -90,7 +90,7 @@ struct MIDI_Map : Module { | |||||
continue; | continue; | ||||
// Set param | // Set param | ||||
float v = rescale(values[cc], 0, 127, 0.f, 1.f); | 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); | v = rescale(v, 0.f, 1.f, param->minValue, param->maxValue); | ||||
APP->engine->setParam(module, paramId, v); | APP->engine->setParam(module, paramId, v); | ||||
} | } | ||||
@@ -11,67 +11,67 @@ | |||||
namespace rack { | namespace rack { | ||||
namespace app { | 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); | NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5); | ||||
// Plug solid | // 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 | // Border | ||||
nvgStrokeWidth(ctx.vg, 1.0); | |||||
nvgStrokeColor(ctx.vg, colorOutline); | |||||
nvgStroke(ctx.vg); | |||||
nvgStrokeWidth(vg, 1.0); | |||||
nvgStrokeColor(vg, colorOutline); | |||||
nvgStroke(vg); | |||||
// Hole | // 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 colorShadow = nvgRGBAf(0, 0, 0, 0.10); | ||||
NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5); | NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5); | ||||
// Cable | // Cable | ||||
if (opacity > 0.0) { | if (opacity > 0.0) { | ||||
nvgSave(ctx.vg); | |||||
nvgSave(vg); | |||||
// This power scaling looks more linear than actual linear scaling | // 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(); | float dist = pos1.minus(pos2).norm(); | ||||
math::Vec slump; | math::Vec slump; | ||||
slump.y = (1.0 - tension) * (150.0 + 1.0*dist); | slump.y = (1.0 - tension) * (150.0 + 1.0*dist); | ||||
math::Vec pos3 = pos1.plus(pos2).div(2).plus(slump); | math::Vec pos3 = pos1.plus(pos2).div(2).plus(slump); | ||||
nvgLineJoin(ctx.vg, NVG_ROUND); | |||||
nvgLineJoin(vg, NVG_ROUND); | |||||
// Shadow | // Shadow | ||||
math::Vec pos4 = pos3.plus(slump.mult(0.08)); | 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 | // 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 | // 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 opacity = settings.cableOpacity; | ||||
float tension = settings.cableTension; | float tension = settings.cableTension; | ||||
float thickness = 5; | float thickness = 5; | ||||
@@ -241,33 +241,33 @@ void CableWidget::draw(const widget::DrawContext &ctx) { | |||||
math::Vec outputPos = getOutputPos(); | math::Vec outputPos = getOutputPos(); | ||||
math::Vec inputPos = getInputPos(); | 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. | // 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 outputPos = getOutputPos(); | ||||
math::Vec inputPos = getInputPos(); | math::Vec inputPos = getInputPos(); | ||||
// Draw plug if the cable is on top, or if the cable is incomplete | // Draw plug if the cable is on top, or if the cable is incomplete | ||||
if (!isComplete() || APP->scene->rackWidget->getTopCable(outputPort) == this) { | if (!isComplete() || APP->scene->rackWidget->getTopCable(outputPort) == this) { | ||||
drawPlug(ctx, outputPos, color); | |||||
drawPlug(args.vg, outputPos, color); | |||||
if (isComplete()) { | if (isComplete()) { | ||||
// Draw plug light | // 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) { | if (!isComplete() || APP->scene->rackWidget->getTopCable(inputPort) == this) { | ||||
drawPlug(ctx, inputPos, color); | |||||
drawPlug(args.vg, inputPos, color); | |||||
if (isComplete()) { | 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); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -10,19 +10,19 @@ CircularShadow::CircularShadow() { | |||||
opacity = 0.15; | opacity = 0.15; | ||||
} | } | ||||
void CircularShadow::draw(const widget::DrawContext &ctx) { | |||||
void CircularShadow::draw(const DrawArgs &args) { | |||||
if (opacity <= 0.0) | if (opacity <= 0.0) | ||||
return; | 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); | math::Vec center = box.size.div(2.0); | ||||
float radius = center.x; | float radius = center.x; | ||||
NVGcolor icol = nvgRGBAf(0.0, 0.0, 0.0, opacity); | NVGcolor icol = nvgRGBAf(0.0, 0.0, 0.0, opacity); | ||||
NVGcolor ocol = nvgRGBAf(0.0, 0.0, 0.0, 0.0); | 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); | |||||
} | } | ||||
@@ -9,16 +9,16 @@ namespace rack { | |||||
namespace app { | 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(); | 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); | textOffset = math::Vec(10, 18); | ||||
} | } | ||||
void LedDisplayChoice::draw(const widget::DrawContext &ctx) { | |||||
void LedDisplayChoice::draw(const DrawArgs &args) { | |||||
if (bgColor.a > 0.0) { | 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) { | 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 | // 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 | // Text | ||||
if (font->handle >= 0) { | if (font->handle >= 0) { | ||||
@@ -95,14 +95,14 @@ void LedDisplayTextField::draw(const widget::DrawContext &ctx) { | |||||
highlightColor.a = 0.5; | highlightColor.a = 0.5; | ||||
int begin = std::min(cursor, selection); | int begin = std::min(cursor, selection); | ||||
int end = (this == APP->event->selectedWidget) ? std::max(cursor, selection) : -1; | 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, | box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, | ||||
-1, color, 12, text.c_str(), highlightColor, begin, end); | -1, color, 12, text.c_str(), highlightColor, begin, end); | ||||
bndSetFont(APP->window->uiFont->handle); | bndSetFont(APP->window->uiFont->handle); | ||||
} | } | ||||
nvgResetScissor(ctx.vg); | |||||
nvgResetScissor(args.vg); | |||||
} | } | ||||
int LedDisplayTextField::getTextPosition(math::Vec mousePos) { | int LedDisplayTextField::getTextPosition(math::Vec mousePos) { | ||||
@@ -6,51 +6,51 @@ namespace rack { | |||||
namespace app { | 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; | 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 | // Background | ||||
if (bgColor.a > 0.0) { | if (bgColor.a > 0.0) { | ||||
nvgFillColor(ctx.vg, bgColor); | |||||
nvgFill(ctx.vg); | |||||
nvgFillColor(args.vg, bgColor); | |||||
nvgFill(args.vg); | |||||
} | } | ||||
// Foreground | // Foreground | ||||
if (color.a > 0.0) { | if (color.a > 0.0) { | ||||
nvgFillColor(ctx.vg, color); | |||||
nvgFill(ctx.vg); | |||||
nvgFillColor(args.vg, color); | |||||
nvgFill(args.vg); | |||||
} | } | ||||
// Border | // Border | ||||
if (borderColor.a > 0.0) { | 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 radius = box.size.x / 2.0; | ||||
float oradius = 4.0 * radius; | 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; | NVGpaint paint; | ||||
NVGcolor icol = color::mult(color, 0.07); | NVGcolor icol = color::mult(color, 0.07); | ||||
NVGcolor ocol = nvgRGB(0, 0, 0); | 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); | |||||
} | } | ||||
@@ -189,7 +189,7 @@ struct ModelBox : widget::OpaqueWidget { | |||||
} | } | ||||
} | } | ||||
void draw(const widget::DrawContext &ctx) override { | |||||
void draw(const DrawArgs &args) override { | |||||
visibleFrames = 0; | visibleFrames = 0; | ||||
// Lazily create preview when drawn | // Lazily create preview when drawn | ||||
@@ -197,16 +197,16 @@ struct ModelBox : widget::OpaqueWidget { | |||||
createPreview(); | 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 | // Translucent overlay when selected | ||||
if (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(); | 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) { | void setSearch(const std::string &search) { | ||||
@@ -141,59 +141,59 @@ ModuleWidget::~ModuleWidget() { | |||||
setModule(NULL); | 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) { | if (module && module->bypass) { | ||||
nvgGlobalAlpha(ctx.vg, 0.25); | |||||
nvgGlobalAlpha(args.vg, 0.25); | |||||
} | } | ||||
widget::Widget::draw(ctx); | |||||
widget::Widget::draw(args); | |||||
// Power meter | // Power meter | ||||
if (module && settings.cpuMeter) { | if (module && settings.cpuMeter) { | ||||
nvgBeginPath(ctx.vg); | |||||
nvgRect(ctx.vg, | |||||
nvgBeginPath(args.vg); | |||||
nvgRect(args.vg, | |||||
0, box.size.y - 20, | 0, box.size.y - 20, | ||||
105, 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); | 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); | 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, | 0, (1.f - p) * box.size.y, | ||||
5, 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) { | // 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); | // 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 r = 20; // Blur radius | ||||
float c = 20; // Corner radius | float c = 20; // Corner radius | ||||
math::Vec b = math::Vec(-10, 30); // Offset from each corner | 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 shadowColor = nvgRGBAf(0, 0, 0, 0.2); | ||||
NVGcolor transparentColor = nvgRGBAf(0, 0, 0, 0); | 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) { | void ModuleWidget::onHover(const event::Hover &e) { | ||||
@@ -141,32 +141,32 @@ void ParamWidget::step() { | |||||
widget::OpaqueWidget::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) { | // if (paramQuantity) { | ||||
// nvgBeginPath(ctx.vg); | |||||
// nvgRect(ctx.vg, | |||||
// nvgBeginPath(args.vg); | |||||
// nvgRect(args.vg, | |||||
// box.size.x - 12, box.size.y - 12, | // box.size.x - 12, box.size.y - 12, | ||||
// 12, 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); | // 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 | // Param map indicator | ||||
engine::ParamHandle *paramHandle = paramQuantity ? APP->engine->getParamHandle(paramQuantity->module, paramQuantity->paramId) : NULL; | engine::ParamHandle *paramHandle = paramQuantity ? APP->engine->getParamHandle(paramQuantity->module, paramQuantity->paramId) : NULL; | ||||
if (paramHandle) { | if (paramHandle) { | ||||
NVGcolor color = nvgRGB(0xff, 0x40, 0xff); | 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); | |||||
} | } | ||||
} | } | ||||
@@ -47,14 +47,14 @@ void PortWidget::step() { | |||||
plugLight->setBrightnesses(values); | plugLight->setBrightnesses(values); | ||||
} | } | ||||
void PortWidget::draw(const widget::DrawContext &ctx) { | |||||
void PortWidget::draw(const DrawArgs &args) { | |||||
CableWidget *cw = APP->scene->rackWidget->incompleteCable; | CableWidget *cw = APP->scene->rackWidget->incompleteCable; | ||||
if (cw) { | if (cw) { | ||||
// Dim the PortWidget if the active cable cannot plug into this PortWidget | // Dim the PortWidget if the active cable cannot plug into this PortWidget | ||||
if (type == OUTPUT ? cw->outputPort : cw->inputPort) | 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) { | void PortWidget::onButton(const event::Button &e) { | ||||
@@ -4,57 +4,57 @@ | |||||
namespace rack { | namespace rack { | ||||
namespace app { | namespace app { | ||||
void RackRail::draw(const widget::DrawContext &ctx) { | |||||
void RackRail::draw(const DrawArgs &args) { | |||||
const float railHeight = RACK_GRID_WIDTH; | const float railHeight = RACK_GRID_WIDTH; | ||||
// Background color | // 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 | // 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; | float holeRadius = 3.5; | ||||
for (float railY = 0; railY < box.size.y; railY += RACK_GRID_HEIGHT) { | for (float railY = 0; railY < box.size.y; railY += RACK_GRID_HEIGHT) { | ||||
// Top rail | // 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) { | 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 | // 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) { | 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 | // Useful for screenshots | ||||
if (0) { | 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); | |||||
} | } | ||||
} | } | ||||
@@ -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); | |||||
} | } | ||||
@@ -43,32 +43,32 @@ static ModuleWidget *moduleFromJson(json_t *moduleJ) { | |||||
struct ModuleContainer : widget::Widget { | 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. | // Draw shadows behind each ModuleWidget first, so the shadow doesn't overlap the front of other ModuleWidgets. | ||||
for (widget::Widget *child : children) { | for (widget::Widget *child : children) { | ||||
ModuleWidget *w = dynamic_cast<ModuleWidget*>(child); | ModuleWidget *w = dynamic_cast<ModuleWidget*>(child); | ||||
assert(w); | 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 { | 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 | // Draw cable plugs | ||||
for (widget::Widget *w : children) { | for (widget::Widget *w : children) { | ||||
CableWidget *cw = dynamic_cast<CableWidget*>(w); | CableWidget *cw = dynamic_cast<CableWidget*>(w); | ||||
assert(cw); | assert(cw); | ||||
cw->drawPlugs(ctx); | |||||
cw->drawPlugs(args); | |||||
} | } | ||||
} | } | ||||
}; | }; | ||||
@@ -117,8 +117,8 @@ void RackWidget::step() { | |||||
widget::Widget::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) { | void RackWidget::onHover(const event::Hover &e) { | ||||
@@ -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) { | void Scene::onHoverKey(const event::HoverKey &e) { | ||||
@@ -5,13 +5,13 @@ namespace rack { | |||||
namespace app { | 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); | 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); | |||||
} | } | ||||
@@ -27,8 +27,8 @@ struct MenuButton : ui::Button { | |||||
box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str()) + 1.0; | box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str()) + 1.0; | ||||
widget::Widget::step(); | 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) { | // if (1) { | ||||
// // Notification circle | // // 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); | 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); | |||||
} | } | ||||
@@ -192,7 +192,7 @@ static void Engine_stepModules(Engine *engine, int threadId) { | |||||
int modulesLen = internal->modules.size(); | int modulesLen = internal->modules.size(); | ||||
float sampleTime = internal->sampleTime; | float sampleTime = internal->sampleTime; | ||||
Module::ProcessContext processCtx; | |||||
Module::ProcessArgs processCtx; | |||||
processCtx.sampleRate = internal->sampleRate; | processCtx.sampleRate = internal->sampleRate; | ||||
processCtx.sampleTime = internal->sampleTime; | processCtx.sampleTime = internal->sampleTime; | ||||
@@ -211,7 +211,6 @@ static void Engine_stepModules(Engine *engine, int threadId) { | |||||
auto startTime = std::chrono::high_resolution_clock::now(); | auto startTime = std::chrono::high_resolution_clock::now(); | ||||
module->process(processCtx); | module->process(processCtx); | ||||
module->step(); | |||||
auto stopTime = std::chrono::high_resolution_clock::now(); | auto stopTime = std::chrono::high_resolution_clock::now(); | ||||
float cpuTime = std::chrono::duration<float>(stopTime - startTime).count(); | float cpuTime = std::chrono::duration<float>(stopTime - startTime).count(); | ||||
@@ -221,8 +220,6 @@ static void Engine_stepModules(Engine *engine, int threadId) { | |||||
} | } | ||||
else { | else { | ||||
module->process(processCtx); | module->process(processCtx); | ||||
// Call deprecated method | |||||
module->step(); | |||||
} | } | ||||
} | } | ||||
@@ -14,8 +14,8 @@ Button::~Button() { | |||||
delete quantity; | 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) { | void Button::onEnter(const event::Enter &e) { | ||||
@@ -5,8 +5,8 @@ namespace rack { | |||||
namespace ui { | 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()); | |||||
} | } | ||||
@@ -11,7 +11,7 @@ Label::Label() { | |||||
color = bndGetTheme()->regularTheme.textColor; | color = bndGetTheme()->regularTheme.textColor; | ||||
} | } | ||||
void Label::draw(const widget::DrawContext &ctx) { | |||||
void Label::draw(const DrawArgs &args) { | |||||
// TODO | // TODO | ||||
// Custom font sizes do not work with right or center alignment | // Custom font sizes do not work with right or center alignment | ||||
float x; | float x; | ||||
@@ -21,14 +21,14 @@ void Label::draw(const widget::DrawContext &ctx) { | |||||
x = 0.0; | x = 0.0; | ||||
} break; | } break; | ||||
case RIGHT_ALIGNMENT: { | 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; | } break; | ||||
case CENTER_ALIGNMENT: { | 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; | } 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); | |||||
} | } | ||||
@@ -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) { | void Menu::onHoverScroll(const event::HoverScroll &e) { | ||||
@@ -5,7 +5,7 @@ namespace rack { | |||||
namespace ui { | namespace ui { | ||||
void MenuItem::draw(const widget::DrawContext &ctx) { | |||||
void MenuItem::draw(const DrawArgs &args) { | |||||
BNDwidgetState state = BND_DEFAULT; | BNDwidgetState state = BND_DEFAULT; | ||||
if (APP->event->hoveredWidget == this) | if (APP->event->hoveredWidget == this) | ||||
@@ -18,14 +18,14 @@ void MenuItem::draw(const widget::DrawContext &ctx) { | |||||
// Main text and background | // Main text and background | ||||
if (!disabled) | 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 | 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 | // 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; | 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() { | void MenuItem::step() { | ||||
@@ -6,8 +6,8 @@ namespace rack { | |||||
namespace ui { | 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() { | void MenuLabel::step() { | ||||
@@ -9,14 +9,14 @@ MenuSeparator::MenuSeparator() { | |||||
box.size.y = BND_WIDGET_HEIGHT / 2; | 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; | 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); | |||||
} | } | ||||
@@ -5,10 +5,10 @@ namespace rack { | |||||
namespace ui { | namespace ui { | ||||
void PasswordField::draw(const widget::DrawContext &ctx) { | |||||
void PasswordField::draw(const DrawArgs &args) { | |||||
std::string textTmp = text; | std::string textTmp = text; | ||||
text = std::string(textTmp.size(), '*'); | text = std::string(textTmp.size(), '*'); | ||||
TextField::draw(ctx); | |||||
TextField::draw(args); | |||||
text = textTmp; | text = textTmp; | ||||
} | } | ||||
@@ -14,10 +14,10 @@ ProgressBar::~ProgressBar() { | |||||
delete quantity; | delete quantity; | ||||
} | } | ||||
void ProgressBar::draw(const widget::DrawContext &ctx) { | |||||
void ProgressBar::draw(const DrawArgs &args) { | |||||
float progress = quantity ? quantity->getScaledValue() : 0.f; | float progress = quantity ? quantity->getScaledValue() : 0.f; | ||||
std::string text = quantity ? quantity->getString() : ""; | 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); | |||||
} | } | ||||
@@ -14,11 +14,11 @@ RadioButton::~RadioButton() { | |||||
delete quantity; | delete quantity; | ||||
} | } | ||||
void RadioButton::draw(const widget::DrawContext &ctx) { | |||||
void RadioButton::draw(const DrawArgs &args) { | |||||
std::string label; | std::string label; | ||||
if (quantity) | if (quantity) | ||||
label = quantity->getLabel(); | 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) { | void RadioButton::onEnter(const event::Enter &e) { | ||||
@@ -12,8 +12,8 @@ ScrollBar::ScrollBar() { | |||||
box.size = math::Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); | 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) { | void ScrollBar::onDragStart(const event::DragStart &e) { | ||||
@@ -27,10 +27,10 @@ void ScrollWidget::scrollTo(math::Rect r) { | |||||
offset = offset.clampSafe(bound); | 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() { | void ScrollWidget::step() { | ||||
@@ -17,10 +17,10 @@ Slider::~Slider() { | |||||
delete quantity; | delete quantity; | ||||
} | } | ||||
void Slider::draw(const widget::DrawContext &ctx) { | |||||
void Slider::draw(const DrawArgs &args) { | |||||
float progress = quantity ? quantity->getScaledValue() : 0.f; | float progress = quantity ? quantity->getScaledValue() : 0.f; | ||||
std::string text = quantity ? quantity->getString() : ""; | 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) { | void Slider::onDragStart(const event::DragStart &e) { | ||||
@@ -8,8 +8,8 @@ TextField::TextField() { | |||||
box.size.y = BND_WIDGET_HEIGHT; | 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; | BNDwidgetState state; | ||||
if (this == APP->event->selectedWidget) | if (this == APP->event->selectedWidget) | ||||
@@ -21,13 +21,13 @@ void TextField::draw(const widget::DrawContext &ctx) { | |||||
int begin = std::min(cursor, selection); | int begin = std::min(cursor, selection); | ||||
int end = std::max(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 | // Draw placeholder text | ||||
if (text.empty() && state != BND_ACTIVE) { | 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) { | void TextField::onButton(const event::Button &e) { | ||||
@@ -14,10 +14,10 @@ void Tooltip::step() { | |||||
widget::Widget::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); | |||||
} | } | ||||
@@ -15,17 +15,17 @@ FramebufferWidget::~FramebufferWidget() { | |||||
nvgluDeleteFramebuffer(fb); | 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 | // Bypass framebuffer rendering if we're already drawing in a framebuffer | ||||
// In other words, disallow nested framebuffers. They look bad. | // 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; | return; | ||||
} | } | ||||
// Get world transform | // Get world transform | ||||
float xform[6]; | float xform[6]; | ||||
nvgCurrentTransform(ctx.vg, xform); | |||||
nvgCurrentTransform(args.vg, xform); | |||||
// Skew and rotate is not supported | // Skew and rotate is not supported | ||||
assert(math::isNear(xform[1], 0.f)); | assert(math::isNear(xform[1], 0.f)); | ||||
assert(math::isNear(xform[2], 0.f)); | assert(math::isNear(xform[2], 0.f)); | ||||
@@ -66,7 +66,7 @@ void FramebufferWidget::draw(const DrawContext &ctx) { | |||||
nvgluDeleteFramebuffer(fb); | nvgluDeleteFramebuffer(fb); | ||||
// Create a framebuffer from the main nanovg context. We will draw to this in the secondary nanovg context. | // Create a framebuffer from the main nanovg context. We will draw to this in the secondary nanovg context. | ||||
if (fbSize.isFinite() && !fbSize.isZero()) | 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) | if (!fb) | ||||
@@ -81,28 +81,28 @@ void FramebufferWidget::draw(const DrawContext &ctx) { | |||||
return; | return; | ||||
// Draw framebuffer image, using world coordinates | // 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.x + fbBox.pos.x, | ||||
offsetI.y + fbBox.pos.y, | offsetI.y + fbBox.pos.y, | ||||
fbBox.size.x, fbBox.size.y); | fbBox.size.x, fbBox.size.y); | ||||
NVGpaint paint = nvgImagePattern(ctx.vg, | |||||
NVGpaint paint = nvgImagePattern(args.vg, | |||||
offsetI.x + fbBox.pos.x, | offsetI.x + fbBox.pos.x, | ||||
offsetI.y + fbBox.pos.y, | offsetI.y + fbBox.pos.y, | ||||
fbBox.size.x, fbBox.size.y, | fbBox.size.x, fbBox.size.y, | ||||
0.0, fb->image, 1.0); | 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 | // 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() { | void FramebufferWidget::drawFramebuffer() { | ||||
@@ -116,9 +116,9 @@ void FramebufferWidget::drawFramebuffer() { | |||||
nvgTranslate(vg, fbOffset.x, fbOffset.y); | nvgTranslate(vg, fbOffset.x, fbOffset.y); | ||||
nvgScale(vg, fbScale.x, fbScale.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); | glViewport(0.0, 0.0, fbSize.x, fbSize.y); | ||||
glClearColor(0.0, 0.0, 0.0, 0.0); | glClearColor(0.0, 0.0, 0.0, 0.0); | ||||
@@ -20,9 +20,9 @@ void SvgWidget::setSvg(std::shared_ptr<Svg> svg) { | |||||
wrap(); | wrap(); | ||||
} | } | ||||
void SvgWidget::draw(const DrawContext &ctx) { | |||||
void SvgWidget::draw(const DrawArgs &args) { | |||||
if (svg && svg->handle) { | if (svg && svg->handle) { | ||||
svgDraw(ctx.vg, svg->handle); | |||||
svgDraw(args.vg, svg->handle); | |||||
} | } | ||||
} | } | ||||
@@ -144,33 +144,33 @@ void Widget::step() { | |||||
} | } | ||||
} | } | ||||
void Widget::draw(const DrawContext &ctx) { | |||||
void Widget::draw(const DrawArgs &args) { | |||||
// Iterate children | // Iterate children | ||||
for (Widget *child : children) { | for (Widget *child : children) { | ||||
// Don't draw if invisible | // Don't draw if invisible | ||||
if (!child->visible) | if (!child->visible) | ||||
continue; | continue; | ||||
// Don't draw if child is outside clip box | // Don't draw if child is outside clip box | ||||
if (!ctx.clipBox.isIntersecting(child->box)) | |||||
if (!args.clipBox.isIntersecting(child->box)) | |||||
continue; | continue; | ||||
DrawContext childCtx = ctx; | |||||
DrawArgs childCtx = args; | |||||
// Intersect child clip box with self | // Intersect child clip box with self | ||||
childCtx.clipBox = childCtx.clipBox.intersect(child->box); | childCtx.clipBox = childCtx.clipBox.intersect(child->box); | ||||
childCtx.clipBox.pos = childCtx.clipBox.pos.minus(child->box.pos); | 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 push | ||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | ||||
// Call deprecated draw function, which does nothing by default | // Call deprecated draw function, which does nothing by default | ||||
child->draw(ctx.vg); | |||||
child->draw(args.vg); | |||||
#pragma GCC diagnostic pop | #pragma GCC diagnostic pop | ||||
child->draw(childCtx); | |||||
nvgRestore(ctx.vg); | |||||
nvgRestore(args.vg); | |||||
} | } | ||||
} | } | ||||
@@ -29,12 +29,12 @@ void ZoomWidget::setZoom(float zoom) { | |||||
Widget::onZoom(eZoom); | 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.pos = zoomCtx.clipBox.pos.div(zoom); | ||||
zoomCtx.clipBox.size = zoomCtx.clipBox.size.div(zoom); | zoomCtx.clipBox.size = zoomCtx.clipBox.size.div(zoom); | ||||
// No need to save the state because that is done in the parent | // 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); | Widget::draw(zoomCtx); | ||||
} | } | ||||
@@ -385,9 +385,10 @@ void Window::run() { | |||||
nvgBeginFrame(vg, fbWidth, fbHeight, pixelRatio); | nvgBeginFrame(vg, fbWidth, fbHeight, pixelRatio); | ||||
nvgScale(vg, pixelRatio, 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); | glViewport(0, 0, fbWidth, fbHeight); | ||||
glClearColor(0.0, 0.0, 0.0, 1.0); | glClearColor(0.0, 0.0, 0.0, 1.0); | ||||