From 503187af0b1441f844f2351da26c693769c7fc39 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Wed, 28 Dec 2022 22:24:20 +0100 Subject: [PATCH] WIP --- CMakeLists.txt | 4 ++ src/changevaluedisplay_colorhelper.cpp | 91 ++++++++++++++++++++++++++ src/changevaluedisplay_colorhelper.h | 42 ++++++++++++ src/tftutils.cpp | 11 ++++ src/tftutils.h | 8 +++ 5 files changed, 156 insertions(+) create mode 100644 src/changevaluedisplay_colorhelper.cpp create mode 100644 src/changevaluedisplay_colorhelper.h create mode 100644 src/tftutils.cpp create mode 100644 src/tftutils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9971d28..e655885 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ set(headers src/changevaluedisplay.h src/changevaluedisplay_bool.h src/changevaluedisplay_chrono.h + src/changevaluedisplay_colorhelper.h src/changevaluedisplay_daylightsavingmode.h src/changevaluedisplay_ip_address_t.h src/changevaluedisplay_sntp_sync_mode_t.h @@ -49,6 +50,7 @@ set(headers src/tftcolors.h src/tftespiimpl.h src/tftinterface.h + src/tftutils.h src/visibleinterface.h src/widgets/graph.h src/widgets/label.h @@ -62,6 +64,7 @@ set(headers set(sources src/changevaluedisplay.cpp src/changevaluedisplay_bool.cpp + src/changevaluedisplay_colorhelper.cpp src/changevaluedisplay_daylightsavingmode.cpp src/changevaluedisplay_ip_address_t.cpp src/changevaluedisplay_sntp_sync_mode_t.cpp @@ -75,6 +78,7 @@ set(sources src/messagepopupdisplay.cpp src/screenmanager.cpp src/splitgraphdisplay.cpp + src/tftutils.cpp src/popupdisplay.cpp src/richtextrenderer.cpp src/icons/back.cpp diff --git a/src/changevaluedisplay_colorhelper.cpp b/src/changevaluedisplay_colorhelper.cpp new file mode 100644 index 0000000..8b3bff1 --- /dev/null +++ b/src/changevaluedisplay_colorhelper.cpp @@ -0,0 +1,91 @@ +#include "changevaluedisplay_colorhelper.h" + +// esp-idf includes +#include + +// 3rdparty lib includes +#include + +// local includes +#include "tftcolors.h" + +namespace espgui { +namespace { +constexpr const auto INNER_CIRCLE_RADIUS = 10; +} // namespace + +void ChangeValueDisplay::start() +{ + Base::start(); + + m_value = this->getValue(); +} + +void ChangeValueDisplay::initScreen(TftInterface &tft) +{ + Base::initScreen(tft); + + const int16_t center_x = tft.width() / 2; + const int16_t center_y = (tft.height()+36) / 2; // 36 is the height of the title bar + + ESP_LOGI("ChangeValueDisplay::initScreen", "center_x: %d, center_y: %d, color: %s", center_x, center_y, toString(m_value).c_str()); + + drawHSVWheel(tft, center_x, center_y, center_y + INNER_CIRCLE_RADIUS*2); + + tft.fillCircle(center_x, center_y, INNER_CIRCLE_RADIUS, colorToNumber(m_value)); +} + +void ChangeValueDisplay::redraw(TftInterface &tft) +{ + Base::redraw(tft); +} + +void ChangeValueDisplay::buttonPressed(Button button) +{ + //Base::buttonPressed(button); + switch (button) + { + case Button::Left: + back(); + break; + default:; + } +} + +void ChangeValueDisplay::buttonReleased(Button button) +{ + //Base::buttonReleased(button); +} + +void ChangeValueDisplay::confirmValue() +{ + +} + +void ChangeValueDisplay::drawHSVWheel(TftInterface &tft, int16_t x, int16_t y, uint8_t d) const +{ + // use tft.fillCircleHelper() to draw the wheel + constexpr const auto circle_count = 4; + constexpr const auto section_count = 8; + const auto min_radius = INNER_CIRCLE_RADIUS; + const auto max_radius = d / 2; + + for (uint8_t i = 0; i < circle_count; i++) + { + tft.drawCircle(x, y, min_radius + i * (max_radius - min_radius) / circle_count, TFT_WHITE); + } + + auto hsv = cpputils::HsvColor{0, 255, 255}; + + // use fillArc(TftInterface &tft, int x, int y, int start_angle, int rx, int ry, int w, unsigned int color) + + for (uint8_t i = 0; i < section_count; i++) + { + const auto color = cpputils::colorToNumber(cpputils::HsvToRgb(hsv)); + const auto start_angle = i * 360 / section_count; + const auto end_angle = (i + 1) * 360 / section_count; + + hsv.h += 255 / section_count % 255; + } +} +} // namespace espgui diff --git a/src/changevaluedisplay_colorhelper.h b/src/changevaluedisplay_colorhelper.h new file mode 100644 index 0000000..15d8b81 --- /dev/null +++ b/src/changevaluedisplay_colorhelper.h @@ -0,0 +1,42 @@ +#pragma once + +// system includes +#include + +// 3rdparty lib includes +#include + +// local includes +#include "backinterface.h" +#include "changevaluedisplay.h" +#include "confirminterface.h" +#include "displaywithtitle.h" +#include "errorhandlerinterface.h" + +namespace espgui { + +template<> +class ChangeValueDisplay : + public DisplayWithTitle, + public virtual AccessorInterface, + public virtual ConfirmInterface, + public virtual BackInterface, + public virtual ErrorHandlerInterface +{ + using Base = DisplayWithTitle; + +public: + void start() override; + void initScreen(TftInterface &tft) override; + void redraw(TftInterface &tft) override; + + void buttonPressed(Button button) override; + void buttonReleased(Button button) override; + + void drawHSVWheel(TftInterface &tft, int16_t x, int16_t y, uint8_t d) const; + void confirmValue(); +private: + cpputils::ColorHelper m_value; +}; + +} // namespace espgui diff --git a/src/tftutils.cpp b/src/tftutils.cpp new file mode 100644 index 0000000..614baef --- /dev/null +++ b/src/tftutils.cpp @@ -0,0 +1,11 @@ +#include "tftutils.h" + +// system includes +#include + +namespace espgui { +void fillCircleSegment(TftInterface &tft, int x0, int y0, int r, int w, float start_angle, float end_angle, unsigned int color) +{ + +} +} // namespace espgui diff --git a/src/tftutils.h b/src/tftutils.h new file mode 100644 index 0000000..9a2aa68 --- /dev/null +++ b/src/tftutils.h @@ -0,0 +1,8 @@ +#pragma once + +// local includes +#include "tftinterface.h" + +namespace espgui { +void fillCircleSegment(TftInterface &tft, int x0, int y0, int r, int w, float start_angle, float end_angle, unsigned int color); +} // namespace espgui