@@ -13,6 +13,7 @@ struct LightWidget : widget::TransparentWidget { | |||||
NVGcolor borderColor = nvgRGBA(0, 0, 0, 0); | NVGcolor borderColor = nvgRGBA(0, 0, 0, 0); | ||||
void draw(const DrawArgs& args) override; | void draw(const DrawArgs& args) override; | ||||
void drawLayer(const DrawArgs& args, int layer) override; | |||||
virtual void drawBackground(const DrawArgs& args); | virtual void drawBackground(const DrawArgs& args); | ||||
virtual void drawLight(const DrawArgs& args); | virtual void drawLight(const DrawArgs& args); | ||||
virtual void drawHalo(const DrawArgs& args); | virtual void drawHalo(const DrawArgs& args); | ||||
@@ -130,7 +130,7 @@ struct Widget : WeakBase { | |||||
/** Draws the widget to the NanoVG context. | /** Draws the widget to the NanoVG context. | ||||
When overriding, call the superclass draw() to recurse to children. | |||||
When overriding, call the superclass's `draw(args)` to recurse to children. | |||||
*/ | */ | ||||
virtual void draw(const DrawArgs& args); | virtual void draw(const DrawArgs& args); | ||||
/** Override draw(const DrawArgs &args) instead */ | /** Override draw(const DrawArgs &args) instead */ | ||||
@@ -141,7 +141,7 @@ struct Widget : WeakBase { | |||||
Custom widgets may draw its children multiple times on different layers, passing an arbitrary layer number each time. | Custom widgets may draw its children multiple times on different layers, passing an arbitrary layer number each time. | ||||
Layer 0 calls children's draw(). | Layer 0 calls children's draw(). | ||||
When overriding, always wrap draw commands in `if (layer == ...) {}` to avoid drawing on all layers. | When overriding, always wrap draw commands in `if (layer == ...) {}` to avoid drawing on all layers. | ||||
When overriding, call the superclass drawLayer() to recurse to children. | |||||
When overriding, call the superclass's `drawLayer(args, layer)` to recurse to children. | |||||
*/ | */ | ||||
virtual void drawLayer(const DrawArgs& args, int layer); | virtual void drawLayer(const DrawArgs& args, int layer); | ||||
@@ -12,14 +12,18 @@ void LightWidget::draw(const DrawArgs& args) { | |||||
// Child widgets | // Child widgets | ||||
Widget::draw(args); | Widget::draw(args); | ||||
} | |||||
void LightWidget::drawLayer(const DrawArgs& args, int layer) { | |||||
if (layer == 1) { | |||||
// Use the formula `lightColor * (1 - dest) + dest` for blending | |||||
nvgGlobalCompositeBlendFunc(args.vg, NVG_ONE_MINUS_DST_COLOR, NVG_ONE); | |||||
drawLight(args); | |||||
drawHalo(args); | |||||
} | |||||
// Dynamic light and halo | |||||
// Override tint from rack brightness adjustment | |||||
nvgGlobalTint(args.vg, color::WHITE); | |||||
// Use the formula `lightColor * (1 - dest) + dest` for blending | |||||
nvgGlobalCompositeBlendFunc(args.vg, NVG_ONE_MINUS_DST_COLOR, NVG_ONE); | |||||
drawLight(args); | |||||
drawHalo(args); | |||||
Widget::drawLayer(args, layer); | |||||
} | } | ||||
@@ -46,6 +46,7 @@ struct ModuleContainer : widget::Widget { | |||||
Widget::draw(args); | Widget::draw(args); | ||||
// Draw lights and light halos | // Draw lights and light halos | ||||
nvgGlobalTint(args.vg, color::WHITE); | |||||
Widget::drawLayer(args, 1); | Widget::drawLayer(args, 1); | ||||
} | } | ||||
}; | }; | ||||