Skip to content

Commit

Permalink
Remove font references stored across frames
Browse files Browse the repository at this point in the history
  • Loading branch information
djpeterso23662 committed Mar 11, 2023
1 parent fd8b20a commit 4796580
Showing 1 changed file with 56 additions and 41 deletions.
97 changes: 56 additions & 41 deletions src/SEQEuclid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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> 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);
}
};

Expand Down

0 comments on commit 4796580

Please sign in to comment.