Skip to content

Commit

Permalink
Don't cache font.
Browse files Browse the repository at this point in the history
  • Loading branch information
zezic committed Dec 3, 2021
1 parent cb151af commit 3f12cb0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 39 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"slug": "ZZC",
"name": "ZZC",
"brand": "ZZC",
"version": "2.0.1",
"version": "2.0.2",
"license": "GPL-3.0-only",
"author": "Sergey Ukolov",
"authorEmail": "[email protected]",
Expand Down
6 changes: 3 additions & 3 deletions src/FN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ struct FN3TextDisplayWidget : TransparentWidget {
NVGcolor lcdColor = nvgRGB(0x12, 0x12, 0x12);
NVGcolor lcdTextColor = nvgRGB(0xff, 0xd4, 0x2a);

std::shared_ptr<Font> font;

FN3TextDisplayWidget() {
font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/Nunito/Nunito-Black.ttf"));
};

void drawLayer(const DrawArgs &args, int layer) override {
if (layer != 1) { return; }

std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/Nunito/Nunito-Black.ttf"));
if (!font) { return; }

char textString[10];

if (text && *text) {
Expand Down
8 changes: 3 additions & 5 deletions src/Phasor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ struct PhasorWidget : ModuleWidget {
struct VerticalRatioDisplayWidget : BaseDisplayWidget {
float *value = nullptr;
int *mode = nullptr;
std::shared_ptr<Font> font;
NVGcolor lcdGhostColor = nvgRGB(0x1e, 0x1f, 0x1d);
NVGcolor lcdTextColor = nvgRGB(0xff, 0xd4, 0x2a);
std::shared_ptr<RatioDisplayData> rddPtr;

VerticalRatioDisplayWidget() {
font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
};

void draw(const DrawArgs &args) override {
std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
if (!font) { return; }

drawBackground(args);

nvgFontSize(args.vg, 11);
Expand Down
8 changes: 3 additions & 5 deletions src/SRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ void writeMusicalNotation(char *output, size_t size, float voltage) {
struct VoltageDisplayWidget : BaseDisplayWidget {
float *value = nullptr;
int *mode = nullptr;
std::shared_ptr<Font> font;

VoltageDisplayWidget() {
font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
};

void drawLayer(const DrawArgs &args, int layer) override {
if (layer != 1) { return; }

std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
if (!font) { return; }

// Text (integer part)
nvgFontSize(args.vg, 11);
nvgFontFaceId(args.vg, font->handle);
Expand Down
10 changes: 5 additions & 5 deletions src/WavetablePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ struct WavetableWidget : TransparentWidget {
NVGcolor brightColor = nvgRGB(0xff, 0xd4, 0x2a);
NVGcolor graphColor = nvgRGBA(0xfe, 0xc3, 0x00, 0x40);
WaveformDimensions wd;
std::shared_ptr<Font> font;
std::string* filename = nullptr;

WavetableWidget() {
font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/SKODANext/SKODANext-Regular.ttf"));
}

void draw(const DrawArgs &args) override {

if (!this->wtPtr) { return; }

std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/SKODANext/SKODANext-Regular.ttf"));
if (!font) { return; }

Wavetable* wt = this->wtPtr.get();

nvgStrokeColor(args.vg, this->graphColor);
Expand Down
32 changes: 12 additions & 20 deletions src/widgets/displays.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ struct BaseDisplayWidget : TransparentWidget {
struct Display32Widget : BaseDisplayWidget {
float *value = nullptr;
bool *disabled = nullptr;
std::shared_ptr<Font> font;

Display32Widget() {
font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
};

void drawLayer(const DrawArgs &args, int layer) override {
if (layer != 1) { return; }

std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
if (!font) { return; }

float valueToDraw = std::abs(value ? *value : 120.0f);

// Text (integer part)
Expand Down Expand Up @@ -128,15 +126,13 @@ struct Display32Widget : BaseDisplayWidget {

struct DisplayIntpartWidget : BaseDisplayWidget {
float *value = nullptr;
std::shared_ptr<Font> font;

DisplayIntpartWidget() {
font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
};

void drawLayer(const DrawArgs &args, int layer) override {
if (layer != 1) { return; }

std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
if (!font) { return; }

// Text (integer part)
nvgFontSize(args.vg, 11);
nvgFontFaceId(args.vg, font->handle);
Expand Down Expand Up @@ -165,7 +161,6 @@ struct IntDisplayWidget : BaseDisplayWidget {
bool *blinking = nullptr;
int blinkingPhase = 0;
std::string textGhost = "88";
std::shared_ptr<Font> font;
NVGcolor lcdTextColorBlink = nvgRGB(0x8a, 0x72, 0x17);
NVGcolor negColor = nvgRGB(0xe7, 0x34, 0x2d);
NVGcolor negColorBlink = nvgRGB(0x8a, 0x1f, 0x1b);
Expand All @@ -174,13 +169,12 @@ struct IntDisplayWidget : BaseDisplayWidget {
NVGcolor polyColor = nvgRGB(0x76, 0xdc, 0xfa);
NVGcolor polyColorBlink = nvgRGB(0x43, 0x7e, 0x8f);

IntDisplayWidget() {
font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
};

void drawLayer(const DrawArgs &args, int layer) override {
if (layer != 1) { return; }

std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
if (!font) { return; }

nvgFontSize(args.vg, 11);
nvgFontFaceId(args.vg, font->handle);
nvgTextLetterSpacing(args.vg, 1.0);
Expand Down Expand Up @@ -230,15 +224,13 @@ struct IntDisplayWidget : BaseDisplayWidget {
struct RatioDisplayWidget : BaseDisplayWidget {
float *from = nullptr;
float *to = nullptr;
std::shared_ptr<Font> font;

RatioDisplayWidget() {
font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
};

void drawLayer(const DrawArgs &args, int layer) override {
if (layer != 1) { return; }

std::shared_ptr<Font> font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/DSEG/DSEG7ClassicMini-Italic.ttf"));
if (!font) { return; }

nvgFontSize(args.vg, 11);
nvgFontFaceId(args.vg, font->handle);
nvgTextLetterSpacing(args.vg, 1.0);
Expand Down

0 comments on commit 3f12cb0

Please sign in to comment.