From 479658080d796a48b8993912cf2ed0fc534c3631 Mon Sep 17 00:00:00 2001 From: djpeterso23662 Date: Sat, 11 Mar 2023 16:06:09 -0500 Subject: [PATCH] Remove font references stored across frames --- src/SEQEuclid.cpp | 97 +++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/src/SEQEuclid.cpp b/src/SEQEuclid.cpp index 9b71ac3..757ed5d 100644 --- a/src/SEQEuclid.cpp +++ b/src/SEQEuclid.cpp @@ -391,62 +391,77 @@ struct SEQEuclid : Module { struct SEQEuclidDisplayWidget : TransparentWidget { SEQEuclid *module; // make sure we can see module-level variables, including contrast, from draw() int *value = NULL; - std::shared_ptr font; SEQEuclidDisplayWidget() { - font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Segment7Standard.ttf")); + //Don't store Font and Image references across multiple frames } - void draw(const DrawArgs &args) override { + void draw(const DrawArgs& args) override { if (!value) { return; // don't blow up the Plugin Manager // https://github.com/AScustomWorks/AS/blob/master/src/DelayPlusStereo.cpp } - // Background - NVGcolor backgroundColor = nvgRGB(0x74, 0x44, 0x44); - NVGcolor borderColor = nvgRGB(0x10, 0x10, 0x10); - if (module->contrast == 1) { - backgroundColor = nvgRGB(0xc0, 0xc0, 0xc0); // high contrast light background color - borderColor = nvgRGB(0x17, 0x17, 0x17); // high contrast dark border color + // LED Background + int contrast = module ? module->contrast : 0; + if (!contrast) { + NVGcolor backgroundColor = nvgRGB(0x74, 0x44, 0x44); + NVGcolor borderColor = nvgRGB(0x10, 0x10, 0x10); + nvgBeginPath(args.vg); + nvgRoundedRect(args.vg, 0.0, 0.0, box.size.x, box.size.y, 5.0); + nvgFillColor(args.vg, backgroundColor); + nvgFill(args.vg); + nvgStrokeWidth(args.vg, 1.0); + nvgStrokeColor(args.vg, borderColor); + nvgStroke(args.vg); } - nvgBeginPath(args.vg); - nvgRoundedRect(args.vg, 0.0, 0.0, box.size.x, box.size.y, 5.0); - nvgFillColor(args.vg, backgroundColor); - nvgFill(args.vg); - nvgStrokeWidth(args.vg, 1.0); - if (module->contrast == 1) { - nvgStrokeWidth(args.vg, 3.0); // high contrast thicker border - } - nvgStrokeColor(args.vg, borderColor); - nvgStroke(args.vg); + } + + void drawLayer(const DrawArgs& args, int layer) override { + if (!value) { + return; // don't blow up the Plugin Manager + } + if (layer == 1) { + int contrast = module ? module->contrast : 0; + + //LCD backlight + if (contrast) { + NVGcolor backgroundColor = nvgRGB(0xc0, 0xc0, 0xc0); // high contrast light background color + NVGcolor borderColor = nvgRGB(0x17, 0x17, 0x17); // high contrast dark border color + + nvgBeginPath(args.vg); + nvgRoundedRect(args.vg, 0.0, 0.0, box.size.x, box.size.y, 5.0); + nvgFillColor(args.vg, backgroundColor); + nvgFill(args.vg); + nvgStrokeWidth(args.vg, 3.0); // high contrast thicker border + nvgStrokeColor(args.vg, borderColor); + nvgStroke(args.vg); + } - nvgFontSize(args.vg, 36); - nvgFontFaceId(args.vg, font->handle); - nvgTextLetterSpacing(args.vg, 2.5); + // Text + std::shared_ptr font = APP->window->loadFont(asset::plugin(pluginInstance, "res/Segment7Standard.ttf")); + if (font) { + + nvgFontSize(args.vg, 36); + nvgFontFaceId(args.vg, font->handle); + nvgTextLetterSpacing(args.vg, 2.5); - std::string to_display = std::to_string(*value); - Vec textPos = Vec(7.0f, 35.0f); + std::string to_display = std::to_string(*value); + Vec textPos = Vec(7.0f, 35.0f); - NVGcolor textColor = nvgRGB(0xdf, 0xd2, 0x2c); - if (module->contrast == 1) { - textColor = nvgRGB(0xc0, 0xc0, 0xc0); // high contrast light text color - } - nvgFillColor(args.vg, nvgTransRGBA(textColor, 16)); - nvgText(args.vg, textPos.x, textPos.y, "~~~", NULL); + NVGcolor textColor = contrast ? nvgRGB(0xc0, 0xc0, 0xc0) : nvgRGB(0xdf, 0xd2, 0x2c); + nvgFillColor(args.vg, nvgTransRGBA(textColor, 16)); + nvgText(args.vg, textPos.x, textPos.y, "~~~", NULL); - textColor = nvgRGB(0xda, 0xe9, 0x29); - if (module->contrast == 1) { - textColor = nvgRGB(0xc0, 0xc0, 0xc0); // high contrast light text color - } - nvgFillColor(args.vg, nvgTransRGBA(textColor, 16)); - nvgText(args.vg, textPos.x, textPos.y, "\\\\\\", NULL); + textColor = contrast ? nvgRGB(0xc0, 0xc0, 0xc0) : nvgRGB(0xda, 0xe9, 0x29); + nvgFillColor(args.vg, nvgTransRGBA(textColor, 16)); + nvgText(args.vg, textPos.x, textPos.y, "\\\\\\", NULL); - textColor = nvgRGB(0xf0, 0x00, 0x00); - if (module->contrast == 1) { - textColor = nvgRGB(0x00, 0x00, 0x00); // high contrast dark text color + textColor = contrast ? nvgRGB(0x00, 0x00, 0x00) : nvgRGB(0xf0, 0x00, 0x00); + nvgFillColor(args.vg, textColor); + nvgText(args.vg, textPos.x, textPos.y, to_display.c_str(), NULL); + } } - nvgFillColor(args.vg, textColor); - nvgText(args.vg, textPos.x, textPos.y, to_display.c_str(), NULL); + Widget::drawLayer(args, layer); } };