From 43e1c2e28ee0074a661514e83d3a2b59a942248b Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 8 Nov 2021 09:53:52 -0500 Subject: [PATCH] Draw Braids font on layer 1. --- src/Braids.cpp | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Braids.cpp b/src/Braids.cpp index 1d2fbc8..2139217 100644 --- a/src/Braids.cpp +++ b/src/Braids.cpp @@ -253,15 +253,8 @@ static const std::vector SHAPE_INFOS = { struct BraidsDisplay : TransparentWidget { Braids* module; - std::shared_ptr font; - - BraidsDisplay() { - font = APP->window->loadFont(asset::plugin(pluginInstance, "res/hdad-segment14-1.002/Segment14.ttf")); - } void draw(const DrawArgs& args) override { - int shape = module ? module->settings.shape : 0; - // Background NVGcolor backgroundColor = nvgRGB(0x38, 0x38, 0x38); NVGcolor borderColor = nvgRGB(0x10, 0x10, 0x10); @@ -273,19 +266,29 @@ struct BraidsDisplay : TransparentWidget { nvgStrokeColor(args.vg, borderColor); nvgStroke(args.vg); - // Text - nvgGlobalTint(args.vg, color::WHITE); - nvgFontSize(args.vg, 38); - nvgFontFaceId(args.vg, font->handle); - nvgTextLetterSpacing(args.vg, 2.5); - - Vec textPos = Vec(9, 48); - NVGcolor textColor = nvgRGB(0xaf, 0xd2, 0x2c); - nvgFillColor(args.vg, nvgTransRGBA(textColor, 16)); - // Background of all segments - nvgText(args.vg, textPos.x, textPos.y, "~~~~", NULL); - nvgFillColor(args.vg, textColor); - nvgText(args.vg, textPos.x, textPos.y, SHAPE_INFOS[shape].code.c_str(), NULL); + Widget::draw(args); + } + + void drawLayer(const DrawArgs& args, int layer) override { + if (layer == 1) { + // Text + int shape = module ? module->settings.shape : 0; + std::shared_ptr font = APP->window->loadFont(asset::plugin(pluginInstance, "res/hdad-segment14-1.002/Segment14.ttf")); + if (font) { + nvgFontSize(args.vg, 38); + nvgFontFaceId(args.vg, font->handle); + nvgTextLetterSpacing(args.vg, 2.5); + + Vec textPos = Vec(9, 48); + NVGcolor textColor = nvgRGB(0xaf, 0xd2, 0x2c); + nvgFillColor(args.vg, nvgTransRGBA(textColor, 16)); + // Background of all segments + nvgText(args.vg, textPos.x, textPos.y, "~~~~", NULL); + nvgFillColor(args.vg, textColor); + nvgText(args.vg, textPos.x, textPos.y, SHAPE_INFOS[shape].code.c_str(), NULL); + } + } + Widget::drawLayer(args, layer); } };