From 4640c20c428a40092ee398fc7983e32c61be1083 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 2 Dec 2021 17:27:52 -0500 Subject: [PATCH] Draw digital display on layer 1. --- src/plugin.hpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/plugin.hpp b/src/plugin.hpp index 9d05b3c..fa5bd9c 100644 --- a/src/plugin.hpp +++ b/src/plugin.hpp @@ -45,13 +45,7 @@ struct DigitalDisplay : Widget { NVGcolor fgColor = SCHEME_YELLOW; Vec textPos; - void draw(const DrawArgs &args) override { - // Background - nvgBeginPath(args.vg); - nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, 2); - nvgFillColor(args.vg, nvgRGB(0x19, 0x19, 0x19)); - nvgFill(args.vg); - + void prepareFont(const DrawArgs& args) { // Get font std::shared_ptr font = APP->window->loadFont(fontPath); if (!font) @@ -60,14 +54,31 @@ struct DigitalDisplay : Widget { nvgFontSize(args.vg, fontSize); nvgTextLetterSpacing(args.vg, 0.0); nvgTextAlign(args.vg, NVG_ALIGN_RIGHT); + } + + void draw(const DrawArgs& args) override { + // Background + nvgBeginPath(args.vg); + nvgRoundedRect(args.vg, 0, 0, box.size.x, box.size.y, 2); + nvgFillColor(args.vg, nvgRGB(0x19, 0x19, 0x19)); + nvgFill(args.vg); + + prepareFont(args); // Background text nvgFillColor(args.vg, bgColor); nvgText(args.vg, textPos.x, textPos.y, bgText.c_str(), NULL); + } + + void drawLayer(const DrawArgs& args, int layer) override { + if (layer == 1) { + prepareFont(args); - // Foreground text - nvgFillColor(args.vg, fgColor); - nvgText(args.vg, textPos.x, textPos.y, text.c_str(), NULL); + // Foreground text + nvgFillColor(args.vg, fgColor); + nvgText(args.vg, textPos.x, textPos.y, text.c_str(), NULL); + } + Widget::drawLayer(args, layer); } };