Compare commits
1 Commits
main
...
color-sele
Author | SHA1 | Date | |
---|---|---|---|
503187af0b |
@ -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
|
||||
|
91
src/changevaluedisplay_colorhelper.cpp
Normal file
91
src/changevaluedisplay_colorhelper.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
#include "changevaluedisplay_colorhelper.h"
|
||||
|
||||
// esp-idf includes
|
||||
#include <esp_log.h>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <tftutils.h>
|
||||
|
||||
// local includes
|
||||
#include "tftcolors.h"
|
||||
|
||||
namespace espgui {
|
||||
namespace {
|
||||
constexpr const auto INNER_CIRCLE_RADIUS = 10;
|
||||
} // namespace
|
||||
|
||||
void ChangeValueDisplay<cpputils::ColorHelper>::start()
|
||||
{
|
||||
Base::start();
|
||||
|
||||
m_value = this->getValue();
|
||||
}
|
||||
|
||||
void ChangeValueDisplay<cpputils::ColorHelper>::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<cpputils::ColorHelper>::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<cpputils::ColorHelper>::redraw(TftInterface &tft)
|
||||
{
|
||||
Base::redraw(tft);
|
||||
}
|
||||
|
||||
void ChangeValueDisplay<cpputils::ColorHelper>::buttonPressed(Button button)
|
||||
{
|
||||
//Base::buttonPressed(button);
|
||||
switch (button)
|
||||
{
|
||||
case Button::Left:
|
||||
back();
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeValueDisplay<cpputils::ColorHelper>::buttonReleased(Button button)
|
||||
{
|
||||
//Base::buttonReleased(button);
|
||||
}
|
||||
|
||||
void ChangeValueDisplay<cpputils::ColorHelper>::confirmValue()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ChangeValueDisplay<cpputils::ColorHelper>::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
|
42
src/changevaluedisplay_colorhelper.h
Normal file
42
src/changevaluedisplay_colorhelper.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <optional>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <color_utils.h>
|
||||
|
||||
// local includes
|
||||
#include "backinterface.h"
|
||||
#include "changevaluedisplay.h"
|
||||
#include "confirminterface.h"
|
||||
#include "displaywithtitle.h"
|
||||
#include "errorhandlerinterface.h"
|
||||
|
||||
namespace espgui {
|
||||
|
||||
template<>
|
||||
class ChangeValueDisplay<cpputils::ColorHelper> :
|
||||
public DisplayWithTitle,
|
||||
public virtual AccessorInterface<cpputils::ColorHelper>,
|
||||
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
|
11
src/tftutils.cpp
Normal file
11
src/tftutils.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "tftutils.h"
|
||||
|
||||
// system includes
|
||||
#include <cmath>
|
||||
|
||||
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
|
8
src/tftutils.h
Normal file
8
src/tftutils.h
Normal file
@ -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
|
Reference in New Issue
Block a user