Browse Source

Draw LightWidget light and halo with drawLayer(args, 1) instead of resetting nvgGlobalTint().

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
aace0a075b
4 changed files with 15 additions and 9 deletions
  1. +1
    -0
      include/app/LightWidget.hpp
  2. +2
    -2
      include/widget/Widget.hpp
  3. +11
    -7
      src/app/LightWidget.cpp
  4. +1
    -0
      src/app/RackWidget.cpp

+ 1
- 0
include/app/LightWidget.hpp View File

@@ -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);


+ 2
- 2
include/widget/Widget.hpp View File

@@ -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);




+ 11
- 7
src/app/LightWidget.cpp View File

@@ -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);
} }






+ 1
- 0
src/app/RackWidget.cpp View File

@@ -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);
} }
}; };


Loading…
Cancel
Save