From e953ec9216f7d8c5fc36592e91406dce557d4268 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Mon, 23 May 2022 23:41:39 +0200 Subject: [PATCH 1/3] Cleanup arduino useless bullshit --- src/widgets/vumeter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/widgets/vumeter.cpp b/src/widgets/vumeter.cpp index 5400eea..d4f6937 100644 --- a/src/widgets/vumeter.cpp +++ b/src/widgets/vumeter.cpp @@ -1,5 +1,12 @@ #include "vumeter.h" +// system includes +#include + +// 3rdparty lib includes +#include +#include + // local includes #include "tftinstance.h" @@ -104,7 +111,7 @@ void VuMeter::redraw(float value) if (value < -3) value = -3; // Limit value to emulate needle end stops if (value > 33) value = 33; - float sdeg = map(value, -3, 33, -150, -30); // Map value to angle + float sdeg = cpputils::mapValue(value, -3, 33, -150, -30); // Map value to angle // Calcualte tip of needle coords float sx = cos(sdeg * 0.0174532925); float sy = sin(sdeg * 0.0174532925); -- 2.50.1 From 529c771ea3935c89bf3fe9c64fb56b94e328555f Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Tue, 24 May 2022 11:54:44 +0200 Subject: [PATCH 2/3] Fix assert when Menu is empty --- src/menudisplay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/menudisplay.cpp b/src/menudisplay.cpp index 7a44e63..bfdcb68 100644 --- a/src/menudisplay.cpp +++ b/src/menudisplay.cpp @@ -69,7 +69,7 @@ void MenuDisplay::update() item.update(); }); - if (getMenuItem(m_selectedIndex).skipScroll()) + if (m_selectedIndex >= 0 && getMenuItem(m_selectedIndex).skipScroll()) { if (offset > 0) { -- 2.50.1 From 6bd5afa6fc0d694b6dedf74d176295f8feb93a9a Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Tue, 24 May 2022 16:12:08 +0200 Subject: [PATCH 3/3] Added slider --- CMakeLists.txt | 2 ++ src/widgets/slider.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ src/widgets/slider.h | 31 +++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/widgets/slider.cpp create mode 100644 src/widgets/slider.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e3c00e..237bfd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ set(headers src/widgets/label.h src/widgets/progressbar.h src/widgets/reverseprogressbar.h + src/widgets/slider.h src/widgets/verticalmeter.h src/widgets/vumeter.h ) @@ -79,6 +80,7 @@ set(sources src/widgets/label.cpp src/widgets/progressbar.cpp src/widgets/reverseprogressbar.cpp + src/widgets/slider.cpp src/widgets/verticalmeter.cpp src/widgets/vumeter.cpp ) diff --git a/src/widgets/slider.cpp b/src/widgets/slider.cpp new file mode 100644 index 0000000..ef76a1c --- /dev/null +++ b/src/widgets/slider.cpp @@ -0,0 +1,44 @@ +#include "slider.h" + +// 3rdparty lib includes +#include + +// local includes +#include "tftinstance.h" + +namespace espgui { +Slider::Slider(int x, int y, int width, int height, int min, int max, uint32_t leftColor, uint32_t rightColor, uint32_t lineColor) : + m_x{x}, + m_y{y}, + m_width{width}, + m_height{height}, + m_min{min}, + m_max{max}, + m_leftColor{leftColor}, + m_rightColor{rightColor}, + m_lineColor{lineColor} +{} + +void Slider::start() +{ + m_lastValue = m_x+1; + tft.drawRect(m_x, m_y, m_width, m_height, TFT_WHITE); + tft.fillRect(m_x+1, m_y+1, m_width-2, m_height-2, m_rightColor); +} + +void Slider::redraw(int value) +{ + // slider with 1 pixel white line at position of value (mapped). Left side of line is leftColor, right side is rightColor + value = cpputils::mapValueClamped(value, m_min, m_max, m_x+1, m_x+m_width-1); + + if (value < m_lastValue) + tft.fillRect(value, m_y+1, m_lastValue-value+1, m_height-2, m_rightColor); + else if (value > m_lastValue) + tft.fillRect(m_lastValue, m_y+1, value-m_lastValue, m_height-2, m_leftColor); + + m_lastValue = value; + + // draw slider line + tft.drawFastVLine(std::min(value, m_x+m_width-2), m_y+1, m_height-2, m_lineColor); +} +} // namespace espgui diff --git a/src/widgets/slider.h b/src/widgets/slider.h new file mode 100644 index 0000000..d64d93b --- /dev/null +++ b/src/widgets/slider.h @@ -0,0 +1,31 @@ +#pragma once + +// system includes +#include + +// 3rdparty lib includes +#include + +namespace espgui { +class Slider +{ +public: + Slider(int x, int y, int width, int height, int min, int max, uint32_t leftColor = color565(180, 180, 0), uint32_t rightColor = TFT_YELLOW, uint32_t lineColor = TFT_BLACK); + + void start(); + void redraw(int value); + +private: + const int m_x; + const int m_y; + const int m_width; + const int m_height; + const int m_min; + const int m_max; + const uint32_t m_leftColor; + const uint32_t m_rightColor; + const uint32_t m_lineColor; + + int m_lastValue{}; +}; +} // namespace espgui -- 2.50.1