From f9651301130866f21ebbff90bd06ae8cac0a848b Mon Sep 17 00:00:00 2001 From: Kevin J Walters Date: Thu, 11 Jan 2024 16:11:28 +0000 Subject: [PATCH] Removing background from text on Audioscope. #14 --- effect/effect.hpp | 23 ++++++++++++++--------- effect/effect_audioscope_tuner.cpp | 12 +++++++----- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/effect/effect.hpp b/effect/effect.hpp index 6ed8160..c52ef29 100644 --- a/effect/effect.hpp +++ b/effect/effect.hpp @@ -107,6 +107,7 @@ class EffectText { int32_t text_pos_x = 0, int32_t text_pos_y = 0 , char justification = 'l', + bool background = true, uint8_t textbg_r = 0, uint8_t textbg_g = 0, uint8_t textbg_b = 0) : @@ -118,6 +119,7 @@ class EffectText { text_g(text_g), text_b(text_b), justification(justification), + background(background), textbg_r(textbg_r), textbg_g(textbg_g), textbg_b(textbg_b) { }; @@ -134,22 +136,24 @@ class EffectText { // PicoGraphics_PenRGB888::text(msg, text_origin, -1, 1.0f); size_t string_len = fixed_len > 0 ? fixed_len : text.length(); int32_t space_pixels = string_len > 1 ? (string_len - 1) * 1 : 0; - int32_t bg_max_width_px = bitmap_font.max_width * string_len + space_pixels; - int32_t tx = text_pos_x, bx = text_pos_x, ty = text_pos_y, by = text_pos_y; + int32_t tx = text_pos_x, y = text_pos_y; if (justification == 'r') { - // Set x positions for right justified text + // Set x position for right justified text tx = text_pos_x - measure_text(&bitmap_font, text, SCALE, 1, false); - bx = text_pos_x - bg_max_width_px; } - rectangle(bx, by, - bg_max_width_px, bitmap_font.height, - textbg_r, textbg_g, textbg_b); + if (background) { + int32_t bg_max_width_px = bitmap_font.max_width * string_len + space_pixels; + int32_t bx = (justification == 'r') ? text_pos_x - bg_max_width_px : text_pos_x; + rectangle(bx, y, + bg_max_width_px, bitmap_font.height, + textbg_r, textbg_g, textbg_b); + } bitmap::text(&bitmap_font, [this](int32_t x, int32_t y, int32_t w, int32_t h) { rectangle(x, y, w, h, text_r, text_g, text_b); }, text, - tx, ty, + tx, y, -1, SCALE, 1, false, 0); }; @@ -161,6 +165,7 @@ class EffectText { int32_t text_pos_x, text_pos_y; uint8_t text_r, text_g, text_b; char justification; + bool background; uint8_t textbg_r, textbg_g, textbg_b; }; @@ -196,7 +201,7 @@ class EffectAudioscopeTuner : public EffectTuner { 64, 64, 64, Display::WIDTH, Display::HEIGHT - font6.height, - 'r'), + 'r', false), // traces initialised in start() trace_intensity({8, 20, 51, 128}), trace_idx(0) { }; diff --git a/effect/effect_audioscope_tuner.cpp b/effect/effect_audioscope_tuner.cpp index d5ad473..7528872 100644 --- a/effect/effect_audioscope_tuner.cpp +++ b/effect/effect_audioscope_tuner.cpp @@ -84,11 +84,6 @@ void EffectAudioscopeTuner::updateDisplay(void) { display.clear(); int32_t waveform_idx = 0; if (frequency != 0.0f) { - // TODO consder a fixed 5 char of text at 5x5 + 4*5 position - if (frequency < 99'999.49f) { - freq_text.text(std::to_string(int32_t(roundf(tuner.frequency))), - 5); - } int32_t zc_idx = tuner.findCross(); if (zc_idx >= 0) { waveform_idx = zc_idx; @@ -104,6 +99,13 @@ void EffectAudioscopeTuner::updateDisplay(void) { } trace_idx = (trace_idx + 1) % traces.size(); drawTraces(); + + // Draw frequency counter value over scope traces + // TODO consder a fixed 5 char of text at 5x5 + 4*5 position + if (frequency > 0.0f && frequency < 99'999.49f) { + freq_text.text(std::to_string(int32_t(roundf(tuner.frequency))), + 5); + } } void EffectAudioscopeTuner::drawTraces(void) {