Skip to content

Commit f965130

Browse files
author
Kevin J Walters
committed
Removing background from text on Audioscope.
Gadgetoid#14
1 parent cedf5ca commit f965130

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

effect/effect.hpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class EffectText {
107107
int32_t text_pos_x = 0,
108108
int32_t text_pos_y = 0 ,
109109
char justification = 'l',
110+
bool background = true,
110111
uint8_t textbg_r = 0,
111112
uint8_t textbg_g = 0,
112113
uint8_t textbg_b = 0) :
@@ -118,6 +119,7 @@ class EffectText {
118119
text_g(text_g),
119120
text_b(text_b),
120121
justification(justification),
122+
background(background),
121123
textbg_r(textbg_r),
122124
textbg_g(textbg_g),
123125
textbg_b(textbg_b) { };
@@ -134,22 +136,24 @@ class EffectText {
134136
// PicoGraphics_PenRGB888::text(msg, text_origin, -1, 1.0f);
135137
size_t string_len = fixed_len > 0 ? fixed_len : text.length();
136138
int32_t space_pixels = string_len > 1 ? (string_len - 1) * 1 : 0;
137-
int32_t bg_max_width_px = bitmap_font.max_width * string_len + space_pixels;
138-
int32_t tx = text_pos_x, bx = text_pos_x, ty = text_pos_y, by = text_pos_y;
139+
int32_t tx = text_pos_x, y = text_pos_y;
139140
if (justification == 'r') {
140-
// Set x positions for right justified text
141+
// Set x position for right justified text
141142
tx = text_pos_x - measure_text(&bitmap_font, text, SCALE, 1, false);
142-
bx = text_pos_x - bg_max_width_px;
143143
}
144-
rectangle(bx, by,
145-
bg_max_width_px, bitmap_font.height,
146-
textbg_r, textbg_g, textbg_b);
144+
if (background) {
145+
int32_t bg_max_width_px = bitmap_font.max_width * string_len + space_pixels;
146+
int32_t bx = (justification == 'r') ? text_pos_x - bg_max_width_px : text_pos_x;
147+
rectangle(bx, y,
148+
bg_max_width_px, bitmap_font.height,
149+
textbg_r, textbg_g, textbg_b);
150+
}
147151
bitmap::text(&bitmap_font,
148152
[this](int32_t x, int32_t y, int32_t w, int32_t h) { rectangle(x, y,
149153
w, h,
150154
text_r, text_g, text_b); },
151155
text,
152-
tx, ty,
156+
tx, y,
153157
-1, SCALE, 1, false, 0);
154158
};
155159

@@ -161,6 +165,7 @@ class EffectText {
161165
int32_t text_pos_x, text_pos_y;
162166
uint8_t text_r, text_g, text_b;
163167
char justification;
168+
bool background;
164169
uint8_t textbg_r, textbg_g, textbg_b;
165170
};
166171

@@ -196,7 +201,7 @@ class EffectAudioscopeTuner : public EffectTuner {
196201
64, 64, 64,
197202
Display::WIDTH,
198203
Display::HEIGHT - font6.height,
199-
'r'),
204+
'r', false),
200205
// traces initialised in start()
201206
trace_intensity({8, 20, 51, 128}),
202207
trace_idx(0) { };

effect/effect_audioscope_tuner.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ void EffectAudioscopeTuner::updateDisplay(void) {
8484
display.clear();
8585
int32_t waveform_idx = 0;
8686
if (frequency != 0.0f) {
87-
// TODO consder a fixed 5 char of text at 5x5 + 4*5 position
88-
if (frequency < 99'999.49f) {
89-
freq_text.text(std::to_string(int32_t(roundf(tuner.frequency))),
90-
5);
91-
}
9287
int32_t zc_idx = tuner.findCross();
9388
if (zc_idx >= 0) {
9489
waveform_idx = zc_idx;
@@ -104,6 +99,13 @@ void EffectAudioscopeTuner::updateDisplay(void) {
10499
}
105100
trace_idx = (trace_idx + 1) % traces.size();
106101
drawTraces();
102+
103+
// Draw frequency counter value over scope traces
104+
// TODO consder a fixed 5 char of text at 5x5 + 4*5 position
105+
if (frequency > 0.0f && frequency < 99'999.49f) {
106+
freq_text.text(std::to_string(int32_t(roundf(tuner.frequency))),
107+
5);
108+
}
107109
}
108110

109111
void EffectAudioscopeTuner::drawTraces(void) {

0 commit comments

Comments
 (0)