From aace0a075bb44e01fd67a454a3ad9145c0e79619 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 7 Oct 2021 22:34:24 -0400 Subject: [PATCH] Draw LightWidget light and halo with drawLayer(args, 1) instead of resetting nvgGlobalTint(). --- include/app/LightWidget.hpp | 1 + include/widget/Widget.hpp | 4 ++-- src/app/LightWidget.cpp | 18 +++++++++++------- src/app/RackWidget.cpp | 1 + 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/app/LightWidget.hpp b/include/app/LightWidget.hpp index 5c6bcac8..9aff23c8 100644 --- a/include/app/LightWidget.hpp +++ b/include/app/LightWidget.hpp @@ -13,6 +13,7 @@ struct LightWidget : widget::TransparentWidget { NVGcolor borderColor = nvgRGBA(0, 0, 0, 0); void draw(const DrawArgs& args) override; + void drawLayer(const DrawArgs& args, int layer) override; virtual void drawBackground(const DrawArgs& args); virtual void drawLight(const DrawArgs& args); virtual void drawHalo(const DrawArgs& args); diff --git a/include/widget/Widget.hpp b/include/widget/Widget.hpp index d2795829..0a8c7f90 100644 --- a/include/widget/Widget.hpp +++ b/include/widget/Widget.hpp @@ -130,7 +130,7 @@ struct Widget : WeakBase { /** 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); /** 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. Layer 0 calls children's draw(). 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); diff --git a/src/app/LightWidget.cpp b/src/app/LightWidget.cpp index a094ffaa..db36a7c9 100644 --- a/src/app/LightWidget.cpp +++ b/src/app/LightWidget.cpp @@ -12,14 +12,18 @@ void LightWidget::draw(const DrawArgs& args) { // Child widgets 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); } diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 8334a3f6..26915cc0 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -46,6 +46,7 @@ struct ModuleContainer : widget::Widget { Widget::draw(args); // Draw lights and light halos + nvgGlobalTint(args.vg, color::WHITE); Widget::drawLayer(args, 1); } };