diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1aaaf52 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build-* diff --git a/CMakeLists.txt b/CMakeLists.txt index aa79e03..9971d28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,9 @@ set(headers src/splitgraphdisplay.h src/textinterface.h src/textwithvaluehelper.h - src/tftinstance.h + src/tftcolors.h + src/tftespiimpl.h + src/tftinterface.h src/visibleinterface.h src/widgets/graph.h src/widgets/label.h @@ -75,7 +77,6 @@ set(sources src/splitgraphdisplay.cpp src/popupdisplay.cpp src/richtextrenderer.cpp - src/tftinstance.cpp src/icons/back.cpp src/icons/checked.cpp src/icons/unchecked.cpp diff --git a/converticons.sh b/converticons.sh new file mode 100755 index 0000000..771283e --- /dev/null +++ b/converticons.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +for i in icons/* +do + build-iconconvert-Desktop_Qt_6_4_0-Debug/iconconvert $i src/icons/ icon_templ.h.tmpl icon_templ.cpp.tmpl +done diff --git a/icon_templ.cpp.tmpl b/icon_templ.cpp.tmpl new file mode 100644 index 0000000..dc8bceb --- /dev/null +++ b/icon_templ.cpp.tmpl @@ -0,0 +1,9 @@ +#include "${name}.h" + +namespace espgui { +namespace icons { +const Icon<${width}, ${height}> ${name} {{ +${bytes} +}}; +} // namespace icons +} // namespace espgui diff --git a/icon_templ.h.tmpl b/icon_templ.h.tmpl new file mode 100644 index 0000000..26c94c8 --- /dev/null +++ b/icon_templ.h.tmpl @@ -0,0 +1,10 @@ +#pragma once + +// local +#include "icon.h" + +namespace espgui { +namespace icons { +extern const Icon<${width}, ${height}> ${name}; +} // namespace icons +} // namespace espgui diff --git a/iconconvert/.gitignore b/iconconvert/.gitignore new file mode 100644 index 0000000..ce7ad77 --- /dev/null +++ b/iconconvert/.gitignore @@ -0,0 +1 @@ +/*.pro.user* diff --git a/iconconvert/iconconvert.pro b/iconconvert/iconconvert.pro new file mode 100644 index 0000000..447fd0a --- /dev/null +++ b/iconconvert/iconconvert.pro @@ -0,0 +1,8 @@ +QT = core gui + +CONFIG += c++latest + +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 + +SOURCES += \ + main.cpp diff --git a/iconconvert/main.cpp b/iconconvert/main.cpp new file mode 100644 index 0000000..4c01648 --- /dev/null +++ b/iconconvert/main.cpp @@ -0,0 +1,190 @@ +#include +#include +#include +#include +#include +#include +#include + +namespace { +constexpr uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) noexcept +{ + return __builtin_bswap16(((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3)); +} +uint16_t color565(const QColor &color) noexcept +{ + return color565(color.red(), color.green(), color.blue()); +} +} // namespace + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + QCoreApplication::setApplicationName("iconconvert"); + QCoreApplication::setApplicationVersion("1.0"); + + QCommandLineParser parser; + parser.setApplicationDescription("Converts icons to .h/.cpp sources"); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("icon", QCoreApplication::translate("main", "Icon file.")); + parser.addPositionalArgument("destination", QCoreApplication::translate("main", "Destination directory.")); + parser.addPositionalArgument("header-templ", QCoreApplication::translate("main", "Header template")); + parser.addPositionalArgument("footer-templ", QCoreApplication::translate("main", "Footer template")); + + parser.process(app); + + const QStringList args = parser.positionalArguments(); + if (args.size() < 1) + { + qCritical("icon missing!"); + parser.showHelp(); + return -1; + } + + if (args.size() < 2) + { + qCritical("destination missing!"); + parser.showHelp(); + return -2; + } + + if (args.size() < 3) + { + qCritical("header-templ missing!"); + parser.showHelp(); + return -3; + } + + if (args.size() < 4) + { + qCritical("footer-templ missing!"); + parser.showHelp(); + return -4; + } + + QFileInfo fileInfo{args.at(0)}; + if (!fileInfo.exists()) + { + qCritical("icon not found!"); + return -5; + } + + QImage image; + if (!image.load(args.at(0)) || image.size().isEmpty()) + { + qCritical("could not load icon!"); + return -6; + } + + QString bytes; + { + std::size_t i{}; + + for (int y = 0; y < image.height(); y++) + for (int x = 0; x < image.width(); x++) + { + if (i == 0) + { + bytes += " "; + } + else + bytes += ", "; + + bytes += QStringLiteral("0x%0").arg(color565(image.pixel(x, y)), 4, 16, QLatin1Char('0')); + + if (++i == 16) + { + i = 0; + bytes += ",\n"; + } + } + } + + QDir dir{args.at(1)}; + if (!dir.exists()) + { + if (!dir.mkpath(dir.absolutePath())) + { + qCritical("could not create target directory"); + return -7; + } + } + + { + QString templ; + + { + QFile file{args.at(2)}; + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + qCritical("could not open header template (for reading) %s", qPrintable(file.errorString())); + return -8; + } + + templ = file.readAll(); + } + + { + QFile file{dir.absoluteFilePath(QStringLiteral("%0.h").arg(fileInfo.baseName()))}; + if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) + { + qCritical("could not open .h file for writing %s", qPrintable(file.errorString())); + return -9; + } + + const auto content = templ + .replace("${name}", fileInfo.baseName()) + .replace("${width}", QString::number(image.width())) + .replace("${height}", QString::number(image.height())) + .toUtf8(); + const std::size_t contentSize = content.size(); + if (const std::size_t written = file.write(content); written != contentSize) + { + qCritical("error while writing %zd != %zd %s", written, contentSize, qPrintable(file.errorString())); + return -10; + } + } + } + + { + QString templ; + + { + QFile file{args.at(3)}; + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + qCritical("could not open source template (for reading) %s", qPrintable(file.errorString())); + return -8; + } + + templ = file.readAll(); + } + + { + QFile file{dir.absoluteFilePath(QStringLiteral("%0.cpp").arg(fileInfo.baseName()))}; + if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) + { + qCritical("could not open .cpp file for writing %s", qPrintable(file.errorString())); + return -8; + } + + const auto content = templ + .replace("${name}", fileInfo.baseName()) + .replace("${width}", QString::number(image.width())) + .replace("${height}", QString::number(image.height())) + .replace("${bytes}", bytes) + .toUtf8(); + const std::size_t contentSize = content.size(); + if (const std::size_t written = file.write(content); written != contentSize) + { + qCritical("error while writing %zd != %zd %s", written, contentSize, qPrintable(file.errorString())); + return -10; + } + } + } + + qDebug() << fileInfo.baseName() << image.width() << image.height(); + + return 0; +} diff --git a/src/changevaluedisplay.cpp b/src/changevaluedisplay.cpp index bd07f64..ec11195 100644 --- a/src/changevaluedisplay.cpp +++ b/src/changevaluedisplay.cpp @@ -3,38 +3,38 @@ // 3rdparty lib includes #include +// local includes +#include "tftinterface.h" +#include "tftcolors.h" + namespace espgui { -void ChangeValueDisplayInterface::initScreen() +void ChangeValueDisplayInterface::initScreen(TftInterface &tft) { - Base::initScreen(); + Base::initScreen(tft); tft.drawRoundRect(35, 65, 190, 65, 8, TFT_WHITE); - m_valueLabel.start(); + m_valueLabel.start(tft); - tft.setTextFont(4); - tft.setTextColor(TFT_WHITE); - if (espgui::isLandscape()) + if (espgui::isLandscape(tft)) { - tft.drawString("Change value and press", 10, 152); - tft.drawString("button to confirm and", 10, 177); - tft.drawString("go back", 10, 202); + tft.drawString("Change value and press", 10, 152, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("button to confirm and", 10, 177, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("go back", 10, 202, TFT_WHITE, TFT_BLACK, 4); } else { - tft.drawString("Change value and", 10, 160); - tft.drawString("press button to", 10, 185); - tft.drawString("confirm and go", 10, 210); - tft.drawString("back.", 10, 235); + tft.drawString("Change value and", 10, 160, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("press button to", 10, 185, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("confirm and go", 10, 210, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("back.", 10, 235, TFT_WHITE, TFT_BLACK, 4); } } template<> -void ChangeValueDisplay::redraw() +void ChangeValueDisplay::redraw(TftInterface &tft) { - Base::redraw(); + Base::redraw(tft); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setTextFont(7); - m_valueLabel.redraw(fmt::format("{:.02f}", m_value)); + m_valueLabel.redraw(tft, fmt::format("{:.02f}", m_value), TFT_WHITE, TFT_BLACK, 7); } } // namespace espgui diff --git a/src/changevaluedisplay.h b/src/changevaluedisplay.h index e4315cd..2cf99f0 100644 --- a/src/changevaluedisplay.h +++ b/src/changevaluedisplay.h @@ -8,6 +8,8 @@ #include // local includes +#include "tftinterface.h" +#include "tftcolors.h" #include "displaywithtitle.h" #include "textinterface.h" #include "confirminterface.h" @@ -15,7 +17,6 @@ #include "errorhandlerinterface.h" #include "accessorinterface.h" #include "widgets/label.h" -#include "tftinstance.h" namespace espgui { @@ -28,7 +29,7 @@ class ChangeValueDisplayInterface : using Base = DisplayWithTitle; public: - void initScreen() override; + void initScreen(TftInterface &tft) override; ChangeValueDisplayInterface *asChangeValueDisplayInterface() override { return this; } const ChangeValueDisplayInterface *asChangeValueDisplayInterface() const override { return this; } @@ -67,7 +68,7 @@ class ChangeValueDisplay : public: void start() override; void update() override; - void redraw() override; + void redraw(TftInterface &tft) override; void buttonPressed(Button button) override; void buttonReleased(Button button) override; @@ -144,17 +145,15 @@ void ChangeValueDisplay::update() } template -void ChangeValueDisplay::redraw() +void ChangeValueDisplay::redraw(TftInterface &tft) { - Base::redraw(); + Base::redraw(tft); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setTextFont(7); - m_valueLabel.redraw(std::to_string(m_value)); + m_valueLabel.redraw(tft, std::to_string(m_value), TFT_WHITE, TFT_BLACK, 7); } template<> -void ChangeValueDisplay::redraw(); +void ChangeValueDisplay::redraw(TftInterface &tft); template void ChangeValueDisplay::buttonPressed(Button button) diff --git a/src/changevaluedisplay_chrono.h b/src/changevaluedisplay_chrono.h index 993f77b..002cd81 100644 --- a/src/changevaluedisplay_chrono.h +++ b/src/changevaluedisplay_chrono.h @@ -8,6 +8,8 @@ // local includes #include "changevaluedisplay.h" +#include "tftinterface.h" +#include "tftcolors.h" #include "displaywithtitle.h" #include "confirminterface.h" #include "backinterface.h" @@ -29,9 +31,9 @@ class ChangeValueDisplayChrono : public: void start() override; - void initScreen() override; + void initScreen(TftInterface &tft) override; void update() override; - void redraw() override; + void redraw(TftInterface &tft) override; void buttonPressed(Button button) override; void buttonReleased(Button button) override; @@ -54,27 +56,25 @@ void ChangeValueDisplayChrono::start() } template -void ChangeValueDisplayChrono::initScreen() +void ChangeValueDisplayChrono::initScreen(TftInterface &tft) { - Base::initScreen(); + Base::initScreen(tft); tft.drawRoundRect(32, 65, 190, 34, 8, TFT_WHITE); - m_valueLabel.start(); + m_valueLabel.start(tft); - tft.setTextFont(4); - tft.setTextColor(TFT_WHITE); - if (espgui::isLandscape()) + if (espgui::isLandscape(tft)) { - tft.drawString("Change value and press", 10, 152); - tft.drawString("button to confirm and", 10, 177); - tft.drawString("go back", 10, 202); + tft.drawString("Change value and press", 10, 152, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("button to confirm and", 10, 177, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("go back", 10, 202, TFT_WHITE, TFT_BLACK, 4); } else { - tft.drawString("Change value and", 10, 160); - tft.drawString("press button to", 10, 185); - tft.drawString("confirm and go", 10, 210); - tft.drawString("back.", 10, 235); + tft.drawString("Change value and", 10, 160, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("press button to", 10, 185, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("confirm and go", 10, 210, TFT_WHITE, TFT_BLACK, 4); + tft.drawString("back.", 10, 235, TFT_WHITE, TFT_BLACK, 4); } } @@ -94,13 +94,11 @@ void ChangeValueDisplayChrono::update() } template -void ChangeValueDisplayChrono::redraw() +void ChangeValueDisplayChrono::redraw(TftInterface &tft) { - Base::redraw(); + Base::redraw(tft); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setTextFont(4); - m_valueLabel.redraw(espchrono::toString(m_value)); + m_valueLabel.redraw(tft, espchrono::toString(m_value), TFT_WHITE, TFT_BLACK, 4); } template diff --git a/src/changevaluedisplay_ip_address_t.cpp b/src/changevaluedisplay_ip_address_t.cpp index 78ab66a..28cf173 100644 --- a/src/changevaluedisplay_ip_address_t.cpp +++ b/src/changevaluedisplay_ip_address_t.cpp @@ -1,7 +1,8 @@ #include "changevaluedisplay_ip_address_t.h" // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" namespace espgui { @@ -14,28 +15,27 @@ void ChangeValueDisplay::start() m_currentIndex = 0; } -void ChangeValueDisplay::initScreen() +void ChangeValueDisplay::initScreen(TftInterface &tft) { - Base::initScreen(); + Base::initScreen(tft); - tft.setTextColor(TFT_WHITE); - tft.drawString("Change IP Address", 0, 50); + tft.drawString("Change IP Address", 0, 50, TFT_WHITE, TFT_BLACK, 4); for(int i = 0; i <= 3; i++) { - drawRect(i, 3, TFT_WHITE); - drawRect(i, 4, TFT_WHITE); + drawRect(tft, i, 3, TFT_WHITE); + drawRect(tft, i, 4, TFT_WHITE); } for (auto &label : m_labels) - label.start(); + label.start(tft); - tft.drawString(".", spacing+boxWidth+spacing/4, y); - tft.drawString(".", spacing*2+boxWidth*2+spacing/4, y); - tft.drawString(".", spacing*3+boxWidth*3+spacing/4, y); + tft.drawString(".", spacing+boxWidth+spacing/4, y, TFT_WHITE, TFT_BLACK, 4); + tft.drawString(".", spacing*2+boxWidth*2+spacing/4, y, TFT_WHITE, TFT_BLACK, 4); + tft.drawString(".", spacing*3+boxWidth*3+spacing/4, y, TFT_WHITE, TFT_BLACK, 4); - drawRect(m_currentIndex, 1, TFT_YELLOW); - drawRect(m_currentIndex, 2, TFT_YELLOW); + drawRect(tft, m_currentIndex, 1, TFT_YELLOW); + drawRect(tft, m_currentIndex, 2, TFT_YELLOW); m_lastIndex = m_currentIndex; } @@ -47,27 +47,23 @@ void ChangeValueDisplay::update() // TODO auto scroll } -void ChangeValueDisplay::redraw() +void ChangeValueDisplay::redraw(TftInterface &tft) { - Base::redraw(); - - tft.setTextColor(TFT_WHITE, TFT_BLACK); + Base::redraw(tft); if (m_lastIndex != m_currentIndex) { - drawRect(m_lastIndex, 1, TFT_BLACK); - drawRect(m_lastIndex, 2, TFT_BLACK); + drawRect(tft, m_lastIndex, 1, TFT_BLACK); + drawRect(tft, m_lastIndex, 2, TFT_BLACK); - drawRect(m_currentIndex, 1, TFT_YELLOW); - drawRect(m_currentIndex, 2, TFT_YELLOW); + drawRect(tft, m_currentIndex, 1, TFT_YELLOW); + drawRect(tft, m_currentIndex, 2, TFT_YELLOW); m_lastIndex = m_currentIndex; } - tft.setTextFont(4); - for (auto i = 0; i < 4; i++) - m_labels[i].redraw(std::to_string(m_value.bytes()[i])); + m_labels[i].redraw(tft, std::to_string(m_value.bytes()[i]), TFT_WHITE, TFT_BLACK, 4); } void ChangeValueDisplay::buttonPressed(Button button) @@ -110,7 +106,7 @@ void ChangeValueDisplay::buttonReleased(Button button) // TODO stop auto scroll } -void ChangeValueDisplay::drawRect(int index, int offset, uint32_t color) const +void ChangeValueDisplay::drawRect(TftInterface &tft, int index, int offset, uint32_t color) const { tft.drawRoundRect(m_labels[index].x()-offset, m_labels[index].y()-offset, boxWidth+(offset*2), boxHeight+(offset*2), 3, color); } diff --git a/src/changevaluedisplay_ip_address_t.h b/src/changevaluedisplay_ip_address_t.h index 4191e5d..fe87309 100644 --- a/src/changevaluedisplay_ip_address_t.h +++ b/src/changevaluedisplay_ip_address_t.h @@ -34,9 +34,9 @@ public: const ChangeValueDisplay *asChangeValueDisplayIpAddress() const override { return this; } void start() override; - void initScreen() override; + void initScreen(TftInterface &tft) override; void update() override; - void redraw() override; + void redraw(TftInterface &tft) override; void buttonPressed(Button button) override; void buttonReleased(Button button) override; @@ -45,7 +45,7 @@ public: void setShownValue(wifi_stack::ip_address_t value) { m_value = value; } private: - void drawRect(int index, int offset, uint32_t color) const; + void drawRect(TftInterface &tft, int index, int offset, uint32_t color) const; wifi_stack::ip_address_t m_value; diff --git a/src/changevaluedisplay_string.cpp b/src/changevaluedisplay_string.cpp index f06fd5d..d372b6e 100644 --- a/src/changevaluedisplay_string.cpp +++ b/src/changevaluedisplay_string.cpp @@ -4,7 +4,8 @@ #include // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" void espgui::ChangeValueDisplay::start() { @@ -13,31 +14,40 @@ void espgui::ChangeValueDisplay::start() m_value = this->getValue(); } -void espgui::ChangeValueDisplay::initScreen() +void espgui::ChangeValueDisplay::initScreen(TftInterface &tft) { - Base::initScreen(); + Base::initScreen(tft); tft.drawRoundRect(10, 50, tft.width() - 20, 34, 5, TFT_WHITE); - m_valueLabel.start(); + m_valueLabel.start(tft); - m_keyboard.start(); + m_keyboard.start(tft); + + m_needsClear = std::nullopt; } -void espgui::ChangeValueDisplay::redraw() +void espgui::ChangeValueDisplay::redraw(TftInterface &tft) { const auto now = espchrono::millis_clock::now().time_since_epoch().count() / 1000; - Base::redraw(); + Base::redraw(tft); - tft.setTextColor(TFT_WHITE, TFT_BLACK); - tft.setTextFont(4); - m_valueLabel.redraw(m_value); + if (m_needsClear) + { + tft.drawRect(m_valueLabel.x() + tft.textWidth(*m_needsClear, 4) + 3, m_valueLabel.y(), 2, tft.fontHeight(4), TFT_BLACK); - tft.drawRect(m_valueLabel.x() + tft.textWidth(m_value) + 3, m_valueLabel.y(), 2, tft.fontHeight(), (now % 1000 < 500) ? TFT_WHITE : TFT_BLACK); + m_needsClear = std::nullopt; + } + + m_valueLabel.redraw(tft, m_value, TFT_WHITE, TFT_BLACK, 4); + + tft.drawRect(m_valueLabel.x() + tft.textWidth(m_value, 4) + 3, m_valueLabel.y(), 2, tft.fontHeight(4), (now % 1000 < 500) ? TFT_WHITE : TFT_BLACK); + + m_keyboard.redraw(tft); } void espgui::ChangeValueDisplay::setShownValue(std::string &&value) { - tft.drawRect(m_valueLabel.x() + tft.textWidth(m_value) + 3, m_valueLabel.y(), 2, tft.fontHeight(), TFT_BLACK); + m_needsClear = std::move(m_value); m_value = std::move(value); } diff --git a/src/changevaluedisplay_string.h b/src/changevaluedisplay_string.h index f968fa6..c2cc7ba 100644 --- a/src/changevaluedisplay_string.h +++ b/src/changevaluedisplay_string.h @@ -2,6 +2,7 @@ // system includes #include +#include // local includes #include "backinterface.h" @@ -29,8 +30,8 @@ public: const ChangeValueDisplay *asChangeValueDisplayString() const override { return this; } void start() override; - void initScreen() override; - void redraw() override; + void initScreen(TftInterface &tft) override; + void redraw(TftInterface &tft) override; void buttonPressed(Button button) override; void buttonReleased(Button button) override; @@ -48,6 +49,8 @@ private: Label m_valueLabel{12, 55}; // 188, 53 Keyboard> m_keyboard{*this}; + + std::optional m_needsClear; }; } // namespace espgui diff --git a/src/colorinterface.h b/src/colorinterface.h index 0defede..10abb4b 100644 --- a/src/colorinterface.h +++ b/src/colorinterface.h @@ -3,6 +3,9 @@ // 3rdparty lib includes #include +// local includes +#include "tftcolors.h" + namespace espgui { class ColorInterface { public: diff --git a/src/display.cpp b/src/display.cpp index b0a63fb..f30d354 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1,11 +1,15 @@ #include "display.h" +// 3rdparty lib includes +#include "TFT_eSPI.h" + // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" namespace espgui { -void Display::initScreen() +void Display::initScreen(TftInterface &tft) { tft.fillScreen(TFT_BLACK); } diff --git a/src/display.h b/src/display.h index 8fd1aae..403e2b7 100644 --- a/src/display.h +++ b/src/display.h @@ -9,6 +9,7 @@ // forward declares namespace espgui { +class TftInterface; class TextInterface; class MenuDisplay; class ChangeValueDisplayInterface; @@ -68,13 +69,13 @@ public: virtual void start() {} //! Display needs to fully initialize screen - virtual void initScreen(); + virtual void initScreen(TftInterface &tft); //! Display can do work needed to update correctly virtual void update() {} //! Display can update screen incrementally - virtual void redraw() {} + virtual void redraw(TftInterface &tft) {} //! Display goes out of existance, is not shown anymore virtual void stop() {} diff --git a/src/displaywithtitle.cpp b/src/displaywithtitle.cpp index e162b40..5b23a49 100644 --- a/src/displaywithtitle.cpp +++ b/src/displaywithtitle.cpp @@ -1,25 +1,24 @@ #include "displaywithtitle.h" // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" namespace espgui { -void DisplayWithTitle::initScreen() +void DisplayWithTitle::initScreen(TftInterface &tft) { - Base::initScreen(); + Base::initScreen(tft); - m_titleLabel.start(); + m_titleLabel.start(tft); tft.fillRect(0, 33, tft.width(), 3, TFT_WHITE); } -void DisplayWithTitle::redraw() +void DisplayWithTitle::redraw(TftInterface &tft) { - Base::redraw(); + Base::redraw(tft); - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW, TFT_BLACK); - m_titleLabel.redraw(text()); + m_titleLabel.redraw(tft, text(), TFT_YELLOW, TFT_BLACK, 4); } } // namespace espgui diff --git a/src/displaywithtitle.h b/src/displaywithtitle.h index bba9c06..3ea4a49 100644 --- a/src/displaywithtitle.h +++ b/src/displaywithtitle.h @@ -17,8 +17,8 @@ public: TextInterface *asTextInterface() override { return this; } const TextInterface *asTextInterface() const override { return this; } - void initScreen() override; - void redraw() override; + void initScreen(TftInterface &tft) override; + void redraw(TftInterface &tft) override; private: Label m_titleLabel{5, 5}; // 230, 25 diff --git a/src/graphdisplay.h b/src/graphdisplay.h index 97ad483..c5c5301 100644 --- a/src/graphdisplay.h +++ b/src/graphdisplay.h @@ -8,7 +8,6 @@ #include "textinterface.h" #include "widgets/label.h" #include "widgets/graph.h" -#include "tftinstance.h" #include "confirminterface.h" #include "backinterface.h" @@ -51,8 +50,8 @@ class GraphDisplay : using Base = DisplayWithTitle; public: - void initScreen() override; - void redraw() override; + void initScreen(TftInterface &tft) override; + void redraw(TftInterface &tft) override; void buttonPressed(Button button) override; @@ -64,17 +63,17 @@ private: }; template -void GraphDisplay::initScreen() +void GraphDisplay::initScreen(TftInterface &tft) { - Base::initScreen(); + Base::initScreen(tft); m_graph.start(static_cast &>(*this).getBuffers()); } template -void GraphDisplay::redraw() +void GraphDisplay::redraw(TftInterface &tft) { - Base::redraw(); + Base::redraw(tft); m_graph.redraw(static_cast &>(*this).getBuffers()); } diff --git a/src/icons/back.cpp b/src/icons/back.cpp index 3a8ad02..9b2e810 100644 --- a/src/icons/back.cpp +++ b/src/icons/back.cpp @@ -2,43 +2,44 @@ namespace espgui { namespace icons { -const Icon<24, 24> back{{ - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x016C, 0x014B, 0x010B, 0x01AC, 0x018C, 0x018C, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x014B, 0x0009, 0x0000, // 0x0020 (32) pixels - 0x2AD0, 0x3331, 0x00CB, 0x09CD, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x012B, 0x0007, 0x0000, 0x1A6F, 0x5CD7, 0x5C96, 0x0003, 0x09ED, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0040 (64) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x010B, 0x0006, 0xFFFF, 0x022F, 0x6518, // 0x0050 (80) pixels - 0x75FB, 0x5C96, 0x0000, 0x1AB0, 0x2312, 0x22F1, 0x1AB0, 0x1A6F, 0x0A0E, 0x016C, 0x0048, 0x00EA, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0060 (96) pixels - 0x0000, 0x0000, 0x010A, 0x0029, 0x0000, 0x022F, 0x6538, 0x761B, 0x761B, 0x5CD7, 0x024F, 0x22D0, 0x22D0, 0x1AB0, 0x1A6F, 0x124F, // 0x0070 (112) pixels - 0x01CD, 0x002A, 0x0000, 0x018C, 0x0007, 0x014B, 0x0000, 0x0000, 0x0002, 0x0003, 0x0A2E, 0x0000, 0x1A90, 0x6518, 0x7E3C, 0x761C, // 0x0080 (128) pixels - 0x761C, 0x6E1C, 0x65BB, 0x5D9A, 0x5D7A, 0x5539, 0x54F8, 0x4CB7, 0x4C76, 0x3BD4, 0x2B11, 0x1A6F, 0x016C, 0x43F5, 0x012B, 0x00A6, // 0x0090 (144) pixels - 0x0006, 0x024F, 0x0000, 0x22F1, 0x6518, 0x7E3C, 0x7E5C, 0x765C, 0x765C, 0x6E3C, 0x661C, 0x65FC, 0x5DBB, 0x559A, 0x4D5A, 0x44F9, // 0x00A0 (160) pixels - 0x44D8, 0x3C97, 0x4456, 0x3BD4, 0x2AF1, 0x09CD, 0x5D7C, 0x00AA, 0x022F, 0x0000, 0x2AF1, 0x6518, 0x863C, 0x7E3C, 0x6E3C, 0x663C, // 0x00B0 (176) pixels - 0x663D, 0x5E3D, 0x5E1C, 0x5DFC, 0x55DB, 0x559B, 0x4D5A, 0x4519, 0x3CB8, 0x3477, 0x3436, 0x33F5, 0x3BD4, 0x2AF1, 0x018C, 0x0000, // 0x00C0 (192) pixels - 0x014B, 0x22B0, 0x54B7, 0x5D9A, 0x4D7A, 0x3D7B, 0x357B, 0x2D9C, 0x2DDC, 0x2DDC, 0x2DBC, 0x2D7B, 0x355A, 0x3D5A, 0x453A, 0x4519, // 0x00D0 (208) pixels - 0x3CD8, 0x3477, 0x3436, 0x2BD5, 0x2BB5, 0x3394, 0x1A6F, 0x014C, 0x016B, 0x1A90, 0x3436, 0x24D9, 0x14D9, 0x1D1A, 0x1D5B, 0x1D9C, // 0x00E0 (224) pixels - 0x25DD, 0x25DD, 0x1D9C, 0x1D5B, 0x1D1A, 0x1CD9, 0x1CB8, 0x2CB8, 0x3CB8, 0x3477, 0x2C36, 0x2BD5, 0x2394, 0x33D5, 0x22F1, 0x11CC, // 0x00F0 (240) pixels - 0x022F, 0x0004, 0x1AD0, 0x2C57, 0x24F9, 0x1D1A, 0x1D5B, 0x1D7C, 0x1DBC, 0x25BC, 0x1D9C, 0x1D5B, 0x1D1A, 0x1CD9, 0x1C98, 0x1457, // 0x0100 (256) pixels - 0x1C37, 0x2C36, 0x2C16, 0x23D5, 0x2394, 0x23B5, 0x2B32, 0x11CD, 0x0000, 0x0A0E, 0x0000, 0x22F1, 0x2C77, 0x251A, 0x1D3A, 0x1D5B, // 0x0110 (272) pixels - 0x1D7B, 0x1D7B, 0x1D5B, 0x1D3A, 0x1CFA, 0x1CB9, 0x1C78, 0x1457, 0x1416, 0x13D5, 0x23D5, 0x23B5, 0x1B94, 0x1B94, 0x2B52, 0x11ED, // 0x0120 (288) pixels - 0x0023, 0x0000, 0x0A4F, 0x0000, 0x22F1, 0x3497, 0x251A, 0x1D1A, 0x1D3A, 0x2D5B, 0x2D3A, 0x2D1A, 0x24F9, 0x24D9, 0x1478, 0x1437, // 0x0130 (304) pixels - 0x13F6, 0x13B5, 0x1394, 0x1B74, 0x1B74, 0x1B94, 0x2B52, 0x11ED, 0x0000, 0x0087, 0x0000, 0x124F, 0x0000, 0x1AB0, 0x3497, 0x1D1A, // 0x0140 (320) pixels - 0x1CFA, 0x3497, 0x1B32, 0x2373, 0x2393, 0x2BD4, 0x3415, 0x2C57, 0x13F6, 0x1395, 0x1374, 0x1353, 0x1354, 0x2394, 0x2B32, 0x11ED, // 0x0150 (336) pixels - 0x0000, 0x0000, 0x0000, 0x00EA, 0x00EA, 0x0000, 0x126F, 0x3497, 0x24D9, 0x3435, 0x0000, 0x1270, 0x0000, 0x0029, 0x01AC, 0x22F1, // 0x0160 (352) pixels - 0x33F5, 0x1395, 0x1354, 0x1333, 0x0B33, 0x2394, 0x22F1, 0x22B0, 0x0000, 0x0000, 0x0000, 0x0000, 0x010B, 0x0008, 0x0000, 0x1A6F, // 0x0170 (368) pixels - 0x3477, 0x3435, 0x0006, 0x09ED, 0x0027, 0x00EA, 0x01AC, 0x0000, 0x22B0, 0x2BB4, 0x0B33, 0x1333, 0x0B34, 0x2B73, 0x22B0, 0x09AD, // 0x0180 (384) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x012B, 0x0009, 0x0000, 0x1A90, 0x3352, 0x004A, 0x09CD, 0x0000, 0x0000, 0x010A, 0x012B, // 0x0190 (400) pixels - 0x09CD, 0x2B53, 0x1354, 0x0B33, 0x1B54, 0x2B32, 0x228F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x014B, 0x010B, // 0x01A0 (416) pixels - 0x0007, 0x018D, 0x01AC, 0x01AC, 0x0000, 0x0000, 0x0000, 0x014B, 0x09CD, 0x2B32, 0x1374, 0x0B33, 0x2353, 0x2AF1, 0x08EA, 0x1A0D, // 0x01B0 (432) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x01AD, 0x09ED, 0x00CA, 0x018C, 0x018C, 0x0000, 0x0000, 0x0000, 0x018C, // 0x01C0 (448) pixels - 0x09ED, 0x2B53, 0x1354, 0x1B53, 0x2B32, 0x224E, 0x2B11, 0x0800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01D0 (464) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00A8, 0x09ED, 0x122E, 0x2B73, 0x1B54, 0x2B53, 0x32D0, 0x43D4, 0x0004, 0x0000, // 0x01E0 (480) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0049, 0x451B, // 0x01F0 (496) pixels - 0x1AB0, 0x2BB4, 0x2B53, 0x32F0, 0x5D3A, 0x0008, 0x00C9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0200 (512) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x018C, 0x010B, 0x3332, 0x3393, 0x2AD0, 0x873F, 0x012B, 0x11ED, 0x0000, 0x0000, // 0x0210 (528) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0109, 0x01AD, 0x018C, // 0x0220 (544) pixels - 0x22B0, 0x32F0, 0x761E, 0x016C, 0x1A2E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x014B, 0x018C, 0x018C, 0x09CD, 0x4C77, 0x012B, 0x1A0E, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -},"back"}; +const Icon<24, 24> back {{ + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6c01, 0x4b01, 0x0b01, 0xac01, 0x8c01, 0x8c01, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4b01, 0x0900, 0x0000, + 0xd02a, 0x3133, 0xcb00, 0xcd09, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x2b01, 0x0700, 0x0000, 0x6f1a, 0xd75c, 0x965c, 0x0300, 0xed09, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0b01, 0x0600, 0xffff, 0x2f02, 0x1865, + 0xfb75, 0x965c, 0x0000, 0xb01a, 0x1223, 0xf122, 0xb01a, 0x6f1a, 0x0e0a, 0x6c01, 0x4800, 0xea00, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0a01, 0x2900, 0x0000, 0x2f02, 0x3865, 0x1b76, 0x1b76, 0xd75c, 0x4f02, 0xd022, 0xd022, 0xb01a, 0x6f1a, 0x4f12, + 0xcd01, 0x2a00, 0x0000, 0x8c01, 0x0700, 0x4b01, 0x0000, 0x0000, 0x0200, 0x0300, 0x2e0a, 0x0000, 0x901a, 0x1865, 0x3c7e, 0x1c76, + 0x1c76, 0x1c6e, 0xbb65, 0x9a5d, 0x7a5d, 0x3955, 0xf854, 0xb74c, 0x764c, 0xd43b, 0x112b, 0x6f1a, 0x6c01, 0xf543, 0x2b01, 0xa600, + 0x0600, 0x4f02, 0x0000, 0xf122, 0x1865, 0x3c7e, 0x5c7e, 0x5c76, 0x5c76, 0x3c6e, 0x1c66, 0xfc65, 0xbb5d, 0x9a55, 0x5a4d, 0xf944, + 0xd844, 0x973c, 0x5644, 0xd43b, 0xf12a, 0xcd09, 0x7c5d, 0xaa00, 0x2f02, 0x0000, 0xf12a, 0x1865, 0x3c86, 0x3c7e, 0x3c6e, 0x3c66, + 0x3d66, 0x3d5e, 0x1c5e, 0xfc5d, 0xdb55, 0x9b55, 0x5a4d, 0x1945, 0xb83c, 0x7734, 0x3634, 0xf533, 0xd43b, 0xf12a, 0x8c01, 0x0000, + 0x4b01, 0xb022, 0xb754, 0x9a5d, 0x7a4d, 0x7b3d, 0x7b35, 0x9c2d, 0xdc2d, 0xdc2d, 0xbc2d, 0x7b2d, 0x5a35, 0x5a3d, 0x3a45, 0x1945, + 0xd83c, 0x7734, 0x3634, 0xd52b, 0xb52b, 0x9433, 0x6f1a, 0x4c01, 0x6b01, 0x901a, 0x3634, 0xd924, 0xd914, 0x1a1d, 0x5b1d, 0x9c1d, + 0xdd25, 0xdd25, 0x9c1d, 0x5b1d, 0x1a1d, 0xd91c, 0xb81c, 0xb82c, 0xb83c, 0x7734, 0x362c, 0xd52b, 0x9423, 0xd533, 0xf122, 0xcc11, + 0x2f02, 0x0400, 0xd01a, 0x572c, 0xf924, 0x1a1d, 0x5b1d, 0x7c1d, 0xbc1d, 0xbc25, 0x9c1d, 0x5b1d, 0x1a1d, 0xd91c, 0x981c, 0x5714, + 0x371c, 0x362c, 0x162c, 0xd523, 0x9423, 0xb523, 0x322b, 0xcd11, 0x0000, 0x0e0a, 0x0000, 0xf122, 0x772c, 0x1a25, 0x3a1d, 0x5b1d, + 0x7b1d, 0x7b1d, 0x5b1d, 0x3a1d, 0xfa1c, 0xb91c, 0x781c, 0x5714, 0x1614, 0xd513, 0xd523, 0xb523, 0x941b, 0x941b, 0x522b, 0xed11, + 0x2300, 0x0000, 0x4f0a, 0x0000, 0xf122, 0x9734, 0x1a25, 0x1a1d, 0x3a1d, 0x5b2d, 0x3a2d, 0x1a2d, 0xf924, 0xd924, 0x7814, 0x3714, + 0xf613, 0xb513, 0x9413, 0x741b, 0x741b, 0x941b, 0x522b, 0xed11, 0x0000, 0x8700, 0x0000, 0x4f12, 0x0000, 0xb01a, 0x9734, 0x1a1d, + 0xfa1c, 0x9734, 0x321b, 0x7323, 0x9323, 0xd42b, 0x1534, 0x572c, 0xf613, 0x9513, 0x7413, 0x5313, 0x5413, 0x9423, 0x322b, 0xed11, + 0x0000, 0x0000, 0x0000, 0xea00, 0xea00, 0x0000, 0x6f12, 0x9734, 0xd924, 0x3534, 0x0000, 0x7012, 0x0000, 0x2900, 0xac01, 0xf122, + 0xf533, 0x9513, 0x5413, 0x3313, 0x330b, 0x9423, 0xf122, 0xb022, 0x0000, 0x0000, 0x0000, 0x0000, 0x0b01, 0x0800, 0x0000, 0x6f1a, + 0x7734, 0x3534, 0x0600, 0xed09, 0x2700, 0xea00, 0xac01, 0x0000, 0xb022, 0xb42b, 0x330b, 0x3313, 0x340b, 0x732b, 0xb022, 0xad09, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2b01, 0x0900, 0x0000, 0x901a, 0x5233, 0x4a00, 0xcd09, 0x0000, 0x0000, 0x0a01, 0x2b01, + 0xcd09, 0x532b, 0x5413, 0x330b, 0x541b, 0x322b, 0x8f22, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4b01, 0x0b01, + 0x0700, 0x8d01, 0xac01, 0xac01, 0x0000, 0x0000, 0x0000, 0x4b01, 0xcd09, 0x322b, 0x7413, 0x330b, 0x5323, 0xf12a, 0xea08, 0x0d1a, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xad01, 0xed09, 0xca00, 0x8c01, 0x8c01, 0x0000, 0x0000, 0x0000, 0x8c01, + 0xed09, 0x532b, 0x5413, 0x531b, 0x322b, 0x4e22, 0x112b, 0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xa800, 0xed09, 0x2e12, 0x732b, 0x541b, 0x532b, 0xd032, 0xd443, 0x0400, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4900, 0x1b45, + 0xb01a, 0xb42b, 0x532b, 0xf032, 0x3a5d, 0x0800, 0xc900, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8c01, 0x0b01, 0x3233, 0x9333, 0xd02a, 0x3f87, 0x2b01, 0xed11, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0901, 0xad01, 0x8c01, + 0xb022, 0xf032, 0x1e76, 0x6c01, 0x2e1a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4b01, 0x8c01, 0x8c01, 0xcd09, 0x774c, 0x2b01, 0x0e1a, 0x0000, 0x0000, 0x0000, 0x0000, + +}}; } // namespace icons } // namespace espgui diff --git a/src/icons/back.h b/src/icons/back.h index 9af49d4..5429016 100644 --- a/src/icons/back.h +++ b/src/icons/back.h @@ -1,6 +1,6 @@ #pragma once -// local includes +// local #include "icon.h" namespace espgui { diff --git a/src/icons/checked.cpp b/src/icons/checked.cpp index 77406f5..26441fa 100644 --- a/src/icons/checked.cpp +++ b/src/icons/checked.cpp @@ -2,7 +2,7 @@ namespace espgui { namespace icons { -const espgui::Icon<24, 24> checked {{ +const Icon<24, 24> checked {{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -12,24 +12,24 @@ const espgui::Icon<24, 24> checked {{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0395, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0000, 0x0000, 0x0000, 0x0000, 0x0396, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x4499, 0xbedd, 0xefbf, 0xffff, 0xbedd, 0x5d3a, 0x0376, 0x0356, 0x0000, - 0x0000, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x7dbb, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x7dbb, 0x0376, 0x0395, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x653a, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x4499, 0x0376, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0xbedd, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbedd, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xefbf, 0x0376, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0xefbf, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0xbedd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbedd, 0x0377, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x4499, 0xffff, 0xffff, - 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5d3a, 0x0376, 0x0395, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x85bb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x85bb, 0x0376, 0x0000, - 0x0000, 0x0396, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x653a, - 0xbedd, 0xffff, 0xefbf, 0xbedd, 0x4499, 0x0376, 0x0356, 0x0000, 0x0000, 0x0000, 0x0000, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, - 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0376, 0x0395, 0x0000, 0x0000, + 0x0000, 0x0000, 0x9503, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x0000, 0x0000, 0x0000, 0x0000, 0x9603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x9944, 0xddbe, 0xbfef, 0xffff, 0xddbe, 0x3a5d, 0x7603, 0x5603, 0x0000, + 0x0000, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0xbb7d, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbb7d, 0x7603, 0x9503, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x3a65, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x9944, 0x7603, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0xddbe, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xddbe, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbfef, 0x7603, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0xbfef, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0xddbe, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xddbe, 0x7703, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x9944, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3a5d, 0x7603, 0x9503, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0xbb85, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbb85, 0x7603, 0x0000, + 0x0000, 0x9603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x3a65, + 0xddbe, 0xffff, 0xbfef, 0xddbe, 0x9944, 0x7603, 0x5603, 0x0000, 0x0000, 0x0000, 0x0000, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, + 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x7603, 0x9503, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, diff --git a/src/icons/checked.h b/src/icons/checked.h index 6314dcd..6065d70 100644 --- a/src/icons/checked.h +++ b/src/icons/checked.h @@ -1,10 +1,10 @@ #pragma once -// local includes +// local #include "icon.h" namespace espgui { namespace icons { -extern const espgui::Icon<24, 24> checked; +extern const Icon<24, 24> checked; } // namespace icons } // namespace espgui diff --git a/src/icons/unchecked.cpp b/src/icons/unchecked.cpp index 1e06bfe..b61badb 100644 --- a/src/icons/unchecked.cpp +++ b/src/icons/unchecked.cpp @@ -2,7 +2,7 @@ namespace espgui { namespace icons { -const espgui::Icon<24, 24> unchecked {{ +const Icon<24, 24> unchecked {{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -12,24 +12,24 @@ const espgui::Icon<24, 24> unchecked {{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x7410, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, - 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x7410, 0x73f0, 0x73f0, 0x73d0, 0x7410, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x73d0, 0x73f0, 0x73f0, 0x7410, 0x0000, - 0x0000, 0x73f0, 0x73f0, 0x7410, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x7410, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x73f0, 0x73f0, 0x7390, 0x73f0, 0x73f0, 0x7410, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, - 0x73f0, 0x7410, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x73f0, 0x73f0, - 0x73f0, 0x7410, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x73d0, 0x73f0, 0x73f0, 0x0000, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, - 0x73f0, 0x73f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7410, 0x73f0, - 0x73f0, 0x7390, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x73f0, 0x73f0, 0x7410, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, - 0x73f0, 0x73f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x73d0, 0x73f0, - 0x73f0, 0x73f0, 0x7410, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x7410, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x73f0, 0x73f0, 0x7410, 0x73f0, 0x73f0, 0x7410, 0x73f0, 0x73f0, 0x73f0, 0x73f0, - 0x7410, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x73f0, 0x73f0, 0x0000, - 0x0000, 0x7410, 0x73f0, 0x73f0, 0x7410, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x7410, 0x7410, 0x73f0, 0x73f0, 0x7410, 0x0000, 0x0000, 0x0000, 0x0000, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, - 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x73f0, 0x7410, 0x0000, 0x0000, + 0x0000, 0x0000, 0x1074, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, + 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0x0000, 0x0000, 0x0000, 0x0000, 0x1074, 0xf073, 0xf073, 0xd073, 0x1074, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xd073, 0xf073, 0xf073, 0x1074, 0x0000, + 0x0000, 0xf073, 0xf073, 0x1074, 0xf073, 0xf073, 0xf073, 0xf073, 0x1074, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf073, 0xf073, 0x9073, 0xf073, 0xf073, 0x1074, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, + 0xf073, 0x1074, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf073, 0xf073, + 0xf073, 0x1074, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xd073, 0xf073, 0xf073, 0x0000, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, + 0xf073, 0xf073, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1074, 0xf073, + 0xf073, 0x9073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf073, 0xf073, 0x1074, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, + 0xf073, 0xf073, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xd073, 0xf073, + 0xf073, 0xf073, 0x1074, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0x1074, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf073, 0xf073, 0x1074, 0xf073, 0xf073, 0x1074, 0xf073, 0xf073, 0xf073, 0xf073, + 0x1074, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf073, 0xf073, 0x0000, + 0x0000, 0x1074, 0xf073, 0xf073, 0x1074, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x1074, 0x1074, 0xf073, 0xf073, 0x1074, 0x0000, 0x0000, 0x0000, 0x0000, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, + 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0xf073, 0x1074, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, diff --git a/src/icons/unchecked.h b/src/icons/unchecked.h index 1ed7f3b..899d515 100644 --- a/src/icons/unchecked.h +++ b/src/icons/unchecked.h @@ -1,10 +1,10 @@ #pragma once -// local includes +// local #include "icon.h" namespace espgui { namespace icons { -extern const espgui::Icon<24, 24> unchecked; +extern const Icon<24, 24> unchecked; } // namespace icons } // namespace espgui diff --git a/src/keyboardhelper.h b/src/keyboardhelper.h index 05e5951..1f2f89d 100644 --- a/src/keyboardhelper.h +++ b/src/keyboardhelper.h @@ -8,9 +8,10 @@ #include // local includes +#include "tftinterface.h" +#include "tftcolors.h" #include "display.h" #include "screenmanager.h" -#include "tftinstance.h" namespace espgui { namespace { @@ -31,7 +32,9 @@ class Keyboard public: explicit Keyboard(TDisplay &display) : m_display(display) {} - void start(); + void start(TftInterface &tft); + + void redraw(TftInterface &tft); void buttonPressed(Button button); void buttonReleased(Button button); @@ -44,7 +47,7 @@ public: private: void updateCharLength(); - void drawKeyboard(bool dont_draw_string = false); + void drawKeyboard(TftInterface &tft, bool dont_draw_string = false); void nextScreen(); @@ -65,6 +68,9 @@ private: SCREEN_MAX }; Screen m_current_screen{Screen::SCREEN_2}; + + bool m_needsStart{}; + bool m_needsRedraw{}; }; template @@ -94,11 +100,11 @@ void Keyboard::nextScreen() if (m_current_screen >= Screen::SCREEN_MAX) m_current_screen = Screen::SCREEN_1; updateCharLength(); - start(); + m_needsStart = true; } template -void Keyboard::drawKeyboard(bool dont_draw_string) +void Keyboard::drawKeyboard(TftInterface &tft, bool dont_draw_string) { size_t char_index{0}; std::string keyboard_screen{m_keyboard}; @@ -114,12 +120,13 @@ void Keyboard::drawKeyboard(bool dont_draw_string) keyboard_lines.push_back(line); } +#if 0 + const auto datum = tft.getTextDatum(); tft.setTextDatum(MC_DATUM); for (size_t i = 0; i < keyboard_lines.size(); i++) - { tft.setTextColor(TFT_WHITE); - + { tft.setTextColor(TFT_GREY); const int32_t y = m_keyboard_start_y + (i * tft.fontHeight() + 9); @@ -160,7 +167,7 @@ void Keyboard::drawKeyboard(bool dont_draw_string) // draw 3 extra buttons, back, space and enter (x=10, x=tft.width()/2, x=tft.width()-10) const int32_t y = m_keyboard_start_y + (keyboard_lines.size() * tft.fontHeight()); - if (isLandscape()) + if (isLandscape(tft)) { // align left (SHIFT, SPACE) tft.drawRoundRect(15 - 2, y - 1, tft.textWidth(SHIFT) + 4, tft.fontHeight() + 2, 3, TFT_DARKGREY); @@ -244,6 +251,7 @@ void Keyboard::drawKeyboard(bool dont_draw_string) tft.drawString(ENTER, tft.width() - 15 - tft.textWidth(ENTER), y); } } +#endif } template @@ -296,16 +304,32 @@ void Keyboard::moveSelectorLeft() } template -void Keyboard::start() +void Keyboard::start(TftInterface &tft) { - const auto isLandscape = espgui::isLandscape(); + const auto isLandscape = espgui::isLandscape(tft); m_keyboard_start_y = isLandscape ? 98 : 120; tft.fillRect(1, m_keyboard_start_y - 10, tft.width()-1, tft.height() - m_keyboard_start_y - (isLandscape ? 0 : 30), TFT_BLACK); tft.drawSunkenRect(1, m_keyboard_start_y - 10, tft.width()-1, tft.height() - m_keyboard_start_y - (isLandscape ? 0 : 30), TFT_WHITE, TFT_GREY, TFT_BLACK); updateCharLength(); - drawKeyboard(); + drawKeyboard(tft); +} + +template +void Keyboard::redraw(TftInterface &tft) +{ + if (m_needsStart) + { + m_needsStart = false; + drawKeyboard(tft, true); + } + + if (m_needsRedraw) + { + m_needsRedraw = false; + drawKeyboard(tft, true); + } } template @@ -340,11 +364,11 @@ void Keyboard::buttonPressed(Button button) return; case Up: moveSelectorLeft(); - drawKeyboard(true); + m_needsRedraw = true; break; case Down: moveSelectorRight(); - drawKeyboard(true); + m_needsRedraw = true; break; default:; } diff --git a/src/menudisplay.cpp b/src/menudisplay.cpp index bed1a6b..f831c28 100644 --- a/src/menudisplay.cpp +++ b/src/menudisplay.cpp @@ -1,7 +1,8 @@ #include "menudisplay.h" // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" using namespace std::chrono_literals; @@ -20,12 +21,12 @@ void MenuDisplay::start() m_downHeld = std::nullopt; } -void MenuDisplay::initScreen() +void MenuDisplay::initScreen(TftInterface &tft) { - Base::initScreen(); + Base::initScreen(tft); for (auto &label : m_labels) - label.start(); + label.start(tft); runForEveryMenuItem([](MenuItem &item){ item.start(); @@ -108,12 +109,9 @@ void MenuDisplay::update() } } -void MenuDisplay::redraw() +void MenuDisplay::redraw(TftInterface &tft) { - Base::redraw(); - - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW, TFT_BLACK); + Base::redraw(tft); int i{0}; @@ -123,7 +121,7 @@ void MenuDisplay::redraw() int newHighlightedIndex{-1}; - const auto drawItemRect = [](const auto &label, const auto color){ + const auto drawItemRect = [&tft](const auto &label, const auto color){ tft.fillRect(5, label.y()-1, tft.width() - 10, @@ -160,36 +158,26 @@ void MenuDisplay::redraw() { drawItemRect(*labelsIter, TFT_GREY); *iconsIter = nullptr; - labelsIter->start(); + labelsIter->start(tft); if (auto icon = item.selectedIcon()) - { - tft.setSwapBytes(true); tft.pushImage(tft.width() - 6 - icon->WIDTH, labelsIter->y() + 1, icon->WIDTH, icon->HEIGHT, icon->buffer); - tft.setSwapBytes(false); - } } } else if (relativeIndex == m_highlightedIndex) { drawItemRect(*labelsIter, TFT_BLACK); *iconsIter = nullptr; - labelsIter->start(); - } + labelsIter->start(tft); + } - tft.setTextFont(item.font()); - tft.setTextColor(item.color(), selected ? TFT_GREY : TFT_BLACK); - labelsIter->redraw(item.text()); + labelsIter->redraw(tft, item.text(), item.color(), selected ? TFT_GREY : TFT_BLACK, item.font()); if (item.icon() != *iconsIter) { auto icon = item.icon(); if (icon) - { - tft.setSwapBytes(true); tft.pushImage(6, labelsIter->y() + 1, icon->WIDTH, icon->HEIGHT, icon->buffer); - tft.setSwapBytes(false); - } else if (*iconsIter) tft.fillRect(6, labelsIter->y() + 1, 24, 24, selected ? TFT_GREY : TFT_BLACK); *iconsIter = icon; @@ -211,7 +199,7 @@ void MenuDisplay::redraw() if (relativeIndex == m_highlightedIndex) drawItemRect(*labelsIter, TFT_BLACK); - labelsIter->clear(); + labelsIter->clear(tft, TFT_BLACK); if (*iconsIter) { diff --git a/src/menudisplay.h b/src/menudisplay.h index 4559a12..aeca150 100644 --- a/src/menudisplay.h +++ b/src/menudisplay.h @@ -29,9 +29,9 @@ class MenuDisplay : public: void start() override; - void initScreen() override; + void initScreen(TftInterface &tft) override; void update() override; - void redraw() override; + void redraw(TftInterface &tft) override; void stop() override; void buttonPressed(Button button) override; diff --git a/src/messagepopupdisplay.cpp b/src/messagepopupdisplay.cpp index 522de29..555faf7 100644 --- a/src/messagepopupdisplay.cpp +++ b/src/messagepopupdisplay.cpp @@ -4,10 +4,13 @@ #include // 3rdparty lib includes -#include #include #include +// local includes +#include "tftinterface.h" +#include "tftcolors.h" + namespace espgui { MessagePopupDisplay::MessagePopupDisplay(std::string &&message, std::unique_ptr &&lastDisplay) : @@ -31,7 +34,7 @@ void MessagePopupDisplay::buttonPressed(Button button) } } -void MessagePopupDisplay::initOverlay() +void MessagePopupDisplay::initOverlay(TftInterface &tft) { const auto leftMargin = 20; const auto rightMargin = leftMargin; @@ -45,15 +48,11 @@ void MessagePopupDisplay::initOverlay() CPP_UNUSED(right) - tft.setTextFont(4); - tft.drawSunkenRect(leftMargin, topMargin, width, height, color565(240, 240, 240), color565(100, 100, 100), color565(30, 30, 30)); - tft.setTextColor(TFT_WHITE, color565(30, 30, 30)); - int x = leftMargin + 5; int y = topMargin + 5; @@ -67,7 +66,7 @@ void MessagePopupDisplay::initOverlay() if (c != '\n') { - const auto addedWidth = tft.drawString(std::string_view{&c, 1}, x, y); + const auto addedWidth = tft.drawString(std::string_view{&c, 1}, x, y, TFT_WHITE, color565(30, 30, 30), 4); x += addedWidth; } @@ -75,8 +74,6 @@ void MessagePopupDisplay::initOverlay() break; } - tft.setTextColor(TFT_BLACK, color565(170, 170, 170)); - if constexpr (false) { tft.drawSunkenRect(leftMargin + 15, bottom - 40, @@ -86,7 +83,7 @@ void MessagePopupDisplay::initOverlay() color565(100, 100, 100), color565(170, 170, 170)); - tft.drawString("Retry", leftMargin + 18, bottom - 37); + tft.drawString("Retry", leftMargin + 18, bottom - 37, TFT_BLACK, color565(170, 170, 170), 4); } tft.drawSunkenRect(leftMargin + 15 + ((width - 15 - 30 - 15) / 2) + 15, bottom - 40, @@ -96,7 +93,7 @@ void MessagePopupDisplay::initOverlay() color565(100, 100, 100), color565(170, 170, 170)); - tft.drawString("Ok", leftMargin + 18 + ((width - 15 - 30 - 15) / 2) + 15 + 1, bottom - 37); + tft.drawString("Ok", leftMargin + 18 + ((width - 15 - 30 - 15) / 2) + 15 + 1, bottom - 37, TFT_BLACK, color565(170, 170, 170), 4); } } // namespace espgui diff --git a/src/messagepopupdisplay.h b/src/messagepopupdisplay.h index 0ab46ba..749839e 100644 --- a/src/messagepopupdisplay.h +++ b/src/messagepopupdisplay.h @@ -14,7 +14,7 @@ public: void buttonPressed(Button button) override; - void initOverlay() override; + void initOverlay(TftInterface &tft) override; private: std::string m_message; diff --git a/src/popupdisplay.cpp b/src/popupdisplay.cpp index cb1cd71..3513bc3 100644 --- a/src/popupdisplay.cpp +++ b/src/popupdisplay.cpp @@ -1,7 +1,6 @@ #include "popupdisplay.h" // 3rdparty lib includes -#include #include namespace espgui { @@ -11,20 +10,33 @@ PopupDisplay::PopupDisplay(std::unique_ptr &&lastDisplay) : { } -void PopupDisplay::initScreen() +void PopupDisplay::initScreen(TftInterface &tft) { - Base::initScreen(); + Base::initScreen(tft); - m_lastDisplay->initScreen(); + m_lastDisplay->initScreen(tft); - initOverlay(); + initOverlay(tft); +} + +void PopupDisplay::redraw(TftInterface &tft) +{ + if (m_wantsClose) + closeOverlay(tft); + else + Base::redraw(tft); } void PopupDisplay::closeOverlay() +{ + m_wantsClose = true; +} + +void PopupDisplay::closeOverlay(TftInterface &tft) { auto guard = std::move(espgui::currentDisplay); espgui::currentDisplay = std::move(m_lastDisplay); - espgui::currentDisplay->initScreen(); + espgui::currentDisplay->initScreen(tft); } } // namespace espgui diff --git a/src/popupdisplay.h b/src/popupdisplay.h index 173ab29..d2b37a2 100644 --- a/src/popupdisplay.h +++ b/src/popupdisplay.h @@ -15,13 +15,18 @@ class PopupDisplay : public Display public: PopupDisplay(std::unique_ptr &&lastDisplay); - void initScreen() override; + void initScreen(TftInterface &tft) override; - virtual void initOverlay() = 0; + void redraw(TftInterface &tft) override; + + virtual void initOverlay(TftInterface &tft) = 0; void closeOverlay(); + void closeOverlay(TftInterface &tft); private: std::unique_ptr m_lastDisplay; + + bool m_wantsClose{}; }; } // namespace espgui diff --git a/src/richtextrenderer.cpp b/src/richtextrenderer.cpp index b5ceb60..95466b8 100644 --- a/src/richtextrenderer.cpp +++ b/src/richtextrenderer.cpp @@ -6,6 +6,10 @@ // 3rdparty lib includes #include +// local includes +#include "tftinterface.h" +#include "tftcolors.h" + namespace espgui { void richTextEscape(std::string &subject) @@ -18,25 +22,20 @@ std::string richTextEscape(std::string_view subject) return cpputils::stringReplaceAll('&', "&&", subject); } -int16_t renderRichText(std::string_view str, int32_t poX, int32_t poY) -{ - return renderRichText(str, poX, poY, tft.textfont); -} - -int16_t renderRichText(std::string_view str, int32_t poX, int32_t poY, uint8_t font) +int16_t renderRichText(TftInterface &tft, std::string_view str, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font) { if (str.empty()) return 0; const int16_t fontHeight = tft.fontHeight(font); + const uint16_t oldColor = color; const uint8_t oldFont = font; - const uint16_t oldColor = tft.textcolor; int16_t width{}; - const auto drawString = [&poX, &poY, &font, &width, &fontHeight, &oldFont](std::string_view str) { - const auto addedWith = tft.drawString(str, poX, poY, font); + const auto drawString = [&tft, &poX, &poY, &color, &bgcolor, &font, &width, &fontHeight, &oldFont](std::string_view str) { + const auto addedWith = tft.drawString(str, poX, poY, color, bgcolor, font); if (font != oldFont) { @@ -44,7 +43,7 @@ int16_t renderRichText(std::string_view str, int32_t poX, int32_t poY, uint8_t f { tft.fillRect(poX, poY + newFontHeight, addedWith, fontHeight - newFontHeight, - tft.textbgcolor); + bgcolor); } } @@ -77,7 +76,7 @@ again: case '8': case '9': { - const auto color = [&controlChar,&oldColor](){ + color = [&controlChar,&oldColor](){ switch (controlChar) { case 'c': return oldColor; @@ -94,8 +93,6 @@ again: __builtin_unreachable(); }(); - tft.setTextColor(color, tft.textbgcolor); - auto newNewIter = newIter + 1; if (newNewIter != std::end(str)) { @@ -152,8 +149,6 @@ again: drawString(str); } - tft.setTextColor(oldColor, tft.textbgcolor); - return width; } diff --git a/src/richtextrenderer.h b/src/richtextrenderer.h index 5d36b36..bcfeed5 100644 --- a/src/richtextrenderer.h +++ b/src/richtextrenderer.h @@ -4,15 +4,14 @@ #include #include -// local includes -#include "tftinstance.h" +// forward declares +namespace espgui { class TftInterface; } namespace espgui { void richTextEscape(std::string &subject); std::string richTextEscape(std::string_view subject); -int16_t renderRichText(std::string_view str, int32_t poX, int32_t poY); -int16_t renderRichText(std::string_view str, int32_t poX, int32_t poY, uint8_t font); +int16_t renderRichText(TftInterface &tft, std::string_view str, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font); } // namespace espgui diff --git a/src/screenmanager.cpp b/src/screenmanager.cpp index 47577d9..aca6032 100644 --- a/src/screenmanager.cpp +++ b/src/screenmanager.cpp @@ -7,7 +7,7 @@ namespace espgui { std::unique_ptr currentDisplay; std::stack> displayStack; -std::function changeScreenCallback; +std::function changeScreenCallback; void deconstructScreen() { @@ -28,7 +28,7 @@ void pushScreenInternal() } } -void popScreen() +void popScreenImpl(TftInterface &tft) { deconstructScreen(); @@ -38,9 +38,14 @@ void popScreen() currentDisplay = std::move(displayStack.top()); displayStack.pop(); currentDisplay->start(); - currentDisplay->initScreen(); + currentDisplay->initScreen(tft); currentDisplay->update(); - currentDisplay->redraw(); + currentDisplay->redraw(tft); +} + +void popScreen() +{ + changeScreenCallback = [](TftInterface &tft){ popScreenImpl(tft); }; } } // namespace espgui diff --git a/src/screenmanager.h b/src/screenmanager.h index 3994af9..c636ba0 100644 --- a/src/screenmanager.h +++ b/src/screenmanager.h @@ -9,102 +9,78 @@ // local includes #include "display.h" +// forward declares +namespace espgui { class TftInterface; } + namespace espgui { extern std::unique_ptr currentDisplay; extern std::stack> displayStack; -extern std::function changeScreenCallback; +extern std::function changeScreenCallback; void deconstructScreen(); void pushScreenInternal(); +void popScreenImpl(TftInterface &tft); void popScreen(); -template -void switchScreenImpl(Args... args) -{ - deconstructScreen(); - - currentDisplay = std::make_unique(args...); - currentDisplay->start(); - currentDisplay->initScreen(); - currentDisplay->update(); - currentDisplay->redraw(); -} - -template -void switchScreenRefImpl(Args&&... args) -{ - deconstructScreen(); - - currentDisplay = std::make_unique(std::forward(args)...); - currentDisplay->start(); - currentDisplay->initScreen(); - currentDisplay->update(); - currentDisplay->redraw(); -} - template void switchScreen(Args... args) { - if (currentDisplay) - changeScreenCallback = [args...](){ switchScreenImpl(args...); }; - else - switchScreenImpl(args...); + changeScreenCallback = [args...](TftInterface &tft){ + deconstructScreen(); + + currentDisplay = std::make_unique(args...); + currentDisplay->start(); + currentDisplay->initScreen(tft); + currentDisplay->update(); + currentDisplay->redraw(tft); + }; } template void switchScreenRef(Args&&... args) { - if (currentDisplay) - changeScreenCallback = [args...](){ switchScreenRefImpl(std::forward(args)...); }; - else - switchScreenRefImpl(std::forward(args)...); -} + changeScreenCallback = [args...](TftInterface &tft){ + deconstructScreen(); -template -void pushScreenImpl(Args... args) -{ - pushScreenInternal(); - - currentDisplay = std::make_unique(args...); - currentDisplay->start(); - currentDisplay->initScreen(); - currentDisplay->update(); - currentDisplay->redraw(); -} - -template -void pushScreenRefImpl(Args&&... args) -{ - pushScreenInternal(); - - currentDisplay = std::make_unique(std::forward(args)...); - currentDisplay->start(); - currentDisplay->initScreen(); - currentDisplay->update(); - currentDisplay->redraw(); + currentDisplay = std::make_unique(std::forward(args)...); + currentDisplay->start(); + currentDisplay->initScreen(tft); + currentDisplay->update(); + currentDisplay->redraw(tft); + }; } template void pushScreen(Args... args) { - if (currentDisplay) - changeScreenCallback = [args...](){ pushScreenImpl(args...); }; - else - pushScreenImpl(args...); + changeScreenCallback = [args...](TftInterface &tft){ + pushScreenInternal(); + + currentDisplay = std::make_unique(args...); + currentDisplay->start(); + currentDisplay->initScreen(tft); + currentDisplay->update(); + currentDisplay->redraw(tft); + }; } template void pushScreenRef(Args&&... args) { - if (currentDisplay) - changeScreenCallback = [args...](){ pushScreenRefImpl(std::forward(args)...); }; - else - pushScreenRefImpl(std::forward(args)...); + changeScreenCallback = [args...](TftInterface &tft){ + pushScreenInternal(); + + currentDisplay = std::make_unique(std::forward(args)...); + currentDisplay->start(); + currentDisplay->initScreen(tft); + currentDisplay->update(); + currentDisplay->redraw(tft); + }; } } // namespace espgui diff --git a/src/splitgraphdisplay.h b/src/splitgraphdisplay.h index 68fb71f..ca3c734 100644 --- a/src/splitgraphdisplay.h +++ b/src/splitgraphdisplay.h @@ -2,6 +2,8 @@ // local includes #include "display.h" +#include "tftinterface.h" +#include "tftcolors.h" #include "textinterface.h" #include "widgets/label.h" #include "widgets/graph.h" @@ -53,9 +55,11 @@ class SplitGraphDisplay : public virtual ConfirmInterface, public virtual BackInterface { + using Base = Display; + public: - void initScreen() override; - void redraw() override; + void initScreen(TftInterface &tft) override; + void redraw(TftInterface &tft) override; void buttonPressed(Button button) override; @@ -67,9 +71,9 @@ private: }; template -void SplitGraphDisplay::initScreen() +void SplitGraphDisplay::initScreen(TftInterface &tft) { - tft.fillScreen(TFT_BLACK); + Base::initScreen(tft); m_titleLabel.start(); tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); @@ -79,7 +83,7 @@ void SplitGraphDisplay::initScreen() } template -void SplitGraphDisplay::redraw() +void SplitGraphDisplay::redraw(TftInterface &tft) { tft.setTextFont(4); tft.setTextColor(TFT_YELLOW, TFT_BLACK); diff --git a/src/tftcolors.h b/src/tftcolors.h new file mode 100644 index 0000000..5c52f95 --- /dev/null +++ b/src/tftcolors.h @@ -0,0 +1,46 @@ +#pragma once + +// system includes +#include + +namespace espgui { + +// Colour conversion +// Convert 8 bit red, green and blue to 16 bits +constexpr uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) noexcept +{ + return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3); +} + +/*************************************************************************************** +** Section 6: Colour enumeration +***************************************************************************************/ +// Default color definitions +constexpr uint16_t TFT_BLACK = color565( 0, 0, 0); +constexpr uint16_t TFT_NAVY = color565( 0, 0, 128); +constexpr uint16_t TFT_DARKGREEN = color565( 0, 128, 0); +constexpr uint16_t TFT_DARKCYAN = color565( 0, 128, 128); +constexpr uint16_t TFT_MAROON = color565(128, 0, 0); +constexpr uint16_t TFT_PURPLE = color565(128, 0, 128); +constexpr uint16_t TFT_OLIVE = color565(128, 128, 0); +constexpr uint16_t TFT_LIGHTGREY = color565(211, 211, 211); +constexpr uint16_t TFT_DARKGREY = color565(128, 128, 128); +constexpr uint16_t TFT_BLUE = color565( 0, 0, 255); +constexpr uint16_t TFT_GREEN = color565( 0, 255, 0); +constexpr uint16_t TFT_CYAN = color565( 0, 255, 255); +constexpr uint16_t TFT_RED = color565(255, 0, 0); +constexpr uint16_t TFT_MAGENTA = color565(255, 0, 255); +constexpr uint16_t TFT_YELLOW = color565(255, 255, 0); +constexpr uint16_t TFT_WHITE = color565(255, 255, 255); +constexpr uint16_t TFT_GREY = 0x5AEB; +constexpr uint16_t TFT_ORANGE = color565(255, 180, 0); +constexpr uint16_t TFT_GREENYELLOW = color565(180, 255, 0); +constexpr uint16_t TFT_PINK = color565(255, 192, 203); //Lighter pink, was 0xFC9F +constexpr uint16_t TFT_BROWN = color565(150, 75, 0); +constexpr uint16_t TFT_GOLD = color565(255, 215, 0); +constexpr uint16_t TFT_SILVER = color565(192, 192, 192); +constexpr uint16_t TFT_SKYBLUE = color565(135, 206, 235); +constexpr uint16_t TFT_VIOLET = color565(180, 46, 226); +constexpr uint16_t TFT_NICEBLUE = color565(59, 163, 255); + +} // namespace espgui diff --git a/src/tftespiimpl.h b/src/tftespiimpl.h new file mode 100644 index 0000000..2290f36 --- /dev/null +++ b/src/tftespiimpl.h @@ -0,0 +1,78 @@ +#pragma once + +// 3rdparty lib includes +#include "TFT_eSPI.h" + +// local includes +#include "tftinterface.h" + +namespace espgui { + +class TftESpiImpl : public TftInterface +{ +public: + void init() { m_tft.init(); } + + void drawPixel(int32_t x, int32_t y, uint16_t color) override { m_tft.drawPixel(x, y, color); } + void drawChar(int32_t x, int32_t y, uint16_t c, uint16_t color, uint16_t bg, uint8_t size) override { m_tft.drawChar(x, y, c, color, bg, size); } + void drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint16_t color) override { m_tft.drawLine(xs, ys, xe, ye, color); } + void drawFastVLine(int32_t x, int32_t y, int32_t h, uint16_t color) override { m_tft.drawFastVLine(x, y, h, color); } + void drawFastHLine(int32_t x, int32_t y, int32_t w, uint16_t color) override { m_tft.drawFastHLine(x, y, w, color); } + void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t color) override { m_tft.fillRect(x, y, w, h, color); } + + int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font) override { return m_tft.drawChar(uniCode, x, y, color, bgcolor, font); } + int16_t height() const override { return m_tft.height(); } + int16_t width() const override { return m_tft.width(); } + + void setRotation(uint8_t r) override { m_tft.setRotation(r); } + uint8_t getRotation(void) const { return m_tft.getRotation(); } + + // Graphics drawing + void fillScreen(uint32_t color) override { m_tft.fillScreen(color); } + void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) override { m_tft.drawRect(x, y, w, h, color); } + void drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color) override { m_tft.drawRoundRect(x, y, w, h, radius, color); } + void fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color) override { m_tft.fillRoundRect(x, y, w, h, radius, color); } + + void fillRectVGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2) override { m_tft.fillRectVGradient(x, y, w, h, color1, color2); } + void fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2) override { m_tft.fillRectHGradient(x, y, w, h, color1, color2); } + + uint16_t drawPixel(int32_t x, int32_t y, uint32_t color, uint8_t alpha, uint32_t bg_color = 0x00FFFFFF) override { return m_tft.drawPixel(x, y, color, alpha, bg_color); } + + void drawSpot(float ax, float ay, float r, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF) override { m_tft.drawSpot(ax, ay, r, fg_color, bg_color); } + + void fillSmoothCircle(int32_t x, int32_t y, int32_t r, uint32_t color, uint32_t bg_color = 0x00FFFFFF) override { m_tft.fillSmoothCircle(x, y, r, color, bg_color); } + + void fillSmoothRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color, uint32_t bg_color = 0x00FFFFFF) override { m_tft.fillSmoothRoundRect(x, y, w, h, radius, color, bg_color); } + + void drawWideLine(float ax, float ay, float bx, float by, float wd, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF) override { m_tft.drawWideLine(ax, ay, bx, by, wd, fg_color, bg_color); } + + void drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF) override { m_tft.drawWedgeLine(ax, ay, bx, by, aw, bw, fg_color, bg_color); } + + void drawSunkenRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color0, uint32_t color1, uint32_t color2) override { m_tft.drawSunkenRect(x, y, w, h, color0, color1, color2); } + + void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color) override { m_tft.drawCircle(x, y, r, color); } + void drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, uint32_t color) override { m_tft.drawCircleHelper(x, y, r, cornername, color); } + void fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color) override { m_tft.fillCircle(x, y, r, color); } + void fillCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, int32_t delta, uint32_t color) override { m_tft.fillCircleHelper(x, y, r, cornername, delta, color); } + + void drawEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) override { m_tft.drawEllipse(x, y, rx, ry, color); } + void fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) override { m_tft.fillEllipse(x, y, rx, ry, color); } + + void drawTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color) override { m_tft.drawTriangle(x1, y1, x2, y2, x3, y3, color); } + void fillTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color) override { m_tft.fillTriangle(x1, y1, x2, y2, x3, y3, color); } + + int16_t textWidth(std::string_view string, uint8_t font) override { return m_tft.textWidth(string, font); } + int16_t fontHeight(int16_t font) override { return m_tft.fontHeight(font); } + + int16_t drawString(std::string_view string, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font) override { return m_tft.drawString(string, x, y, color, bgcolor, font); } + int16_t drawCentreString(std::string_view string, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font) override { return m_tft.drawCentreString(string, x, y, color, bgcolor, font); } + int16_t drawRightString(std::string_view string, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font) override { return m_tft.drawRightString(string, x, y, color, bgcolor, font); } + + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data) { m_tft.pushImage(x, y, w, h, data); } + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent) { m_tft.pushImage(x, y, w, h, data, transparent); } + +private: + TFT_eSPI m_tft; +}; + +} // namespace espgui diff --git a/src/tftinstance.cpp b/src/tftinstance.cpp deleted file mode 100644 index 9cb17f5..0000000 --- a/src/tftinstance.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "tftinstance.h" - -namespace espgui { -TFT_eSPI tft; -} // namespace espgui diff --git a/src/tftinstance.h b/src/tftinstance.h deleted file mode 100644 index 07cc6a6..0000000 --- a/src/tftinstance.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -// 3rdparty lib includes -#include - -namespace espgui { -extern TFT_eSPI tft; -inline bool isLandscape() -{ - return (tft.getRotation() == 1 || tft.getRotation() == 3); -} -} diff --git a/src/tftinterface.h b/src/tftinterface.h new file mode 100644 index 0000000..54ede13 --- /dev/null +++ b/src/tftinterface.h @@ -0,0 +1,91 @@ +#pragma once + +// system includes +#include +#include + +namespace espgui { +class TftInterface +{ +public: + explicit TftInterface() = default; + virtual ~TftInterface() = default; + + virtual void drawPixel(int32_t x, int32_t y, uint16_t color) = 0; + virtual void drawChar(int32_t x, int32_t y, uint16_t c, uint16_t color, uint16_t bg, uint8_t size) = 0; + virtual void drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint16_t color) = 0; + virtual void drawFastVLine(int32_t x, int32_t y, int32_t h, uint16_t color) = 0; + virtual void drawFastHLine(int32_t x, int32_t y, int32_t w, uint16_t color) = 0; + virtual void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t color) = 0; + + virtual int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font) = 0; + virtual int16_t height(void) const = 0; + virtual int16_t width(void) const = 0; + + virtual void setRotation(uint8_t r) = 0; // Set the display image orientation to 0, 1, 2 or 3 + virtual uint8_t getRotation(void) const = 0; // Read the current rotation + + // Graphics drawing + virtual void fillScreen(uint32_t color) = 0; + virtual void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) = 0; + virtual void drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color) = 0; + virtual void fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color) = 0; + + virtual void fillRectVGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2) = 0; + virtual void fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2) = 0; + + // Draw a pixel blended with the pixel colour on the TFT or sprite, return blended colour + // If bg_color is not included the background pixel colour will be read from TFT or sprite + virtual uint16_t drawPixel(int32_t x, int32_t y, uint32_t color, uint8_t alpha, uint32_t bg_color = 0x00FFFFFF) = 0; + + // Draw a small anti-aliased filled circle at ax,ay with radius r (uses drawWideLine) + // If bg_color is not included the background pixel colour will be read from TFT or sprite + virtual void drawSpot(float ax, float ay, float r, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF) = 0; + + // Draw an anti-aliased filled circle at x, y with radius r + // If bg_color is not included the background pixel colour will be read from TFT or sprite + virtual void fillSmoothCircle(int32_t x, int32_t y, int32_t r, uint32_t color, uint32_t bg_color = 0x00FFFFFF) = 0; + + virtual void fillSmoothRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color, uint32_t bg_color = 0x00FFFFFF) = 0; + + // Draw an anti-aliased wide line from ax,ay to bx,by width wd with radiused ends (radius is wd/2) + // If bg_color is not included the background pixel colour will be read from TFT or sprite + virtual void drawWideLine(float ax, float ay, float bx, float by, float wd, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF) = 0; + + // Draw an anti-aliased wide line from ax,ay to bx,by with different width at each end aw, bw and with radiused ends + // If bg_color is not included the background pixel colour will be read from TFT or sprite + virtual void drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF) = 0; + + virtual void drawSunkenRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color0, uint32_t color1, uint32_t color2) = 0; + + virtual void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color) = 0; + virtual void drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, uint32_t color) = 0; + virtual void fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color) = 0; + virtual void fillCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, int32_t delta, uint32_t color) = 0; + + virtual void drawEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) = 0; + virtual void fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) = 0; + + // Corner 1 Corner 2 Corner 3 + virtual void drawTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color) = 0; + virtual void fillTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color) = 0; + + virtual int16_t textWidth(std::string_view string, uint8_t font); // Returns pixel width of string in specified font + virtual int16_t fontHeight(int16_t font); // Returns pixel height of string in specified font + + // Handle char arrays + // Use with setTextDatum() to position string on TFT, and setTextPadding() to blank old displayed strings + virtual int16_t drawString(std::string_view string, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font) = 0; // Draw string using specifed font number + virtual int16_t drawCentreString(std::string_view string, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font) = 0; // Deprecated, use setTextDatum() and drawString() + virtual int16_t drawRightString(std::string_view string, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font) = 0; // Deprecated, use setTextDatum() and drawString() + + // These are used to render images or sprites stored in RAM arrays (used by Sprite class for 16bpp Sprites) + virtual void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data) = 0; + virtual void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent) = 0; +}; + +inline bool isLandscape(const TftInterface &tft) +{ + return (tft.getRotation() == 1 || tft.getRotation() == 3); +} +} // namespace espgui diff --git a/src/widgets/graph.h b/src/widgets/graph.h index a67e45c..6432445 100644 --- a/src/widgets/graph.h +++ b/src/widgets/graph.h @@ -10,7 +10,8 @@ // local includes #include "label.h" -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" namespace espgui { template diff --git a/src/widgets/label.cpp b/src/widgets/label.cpp index cf0ed0f..7cc3ff1 100644 --- a/src/widgets/label.cpp +++ b/src/widgets/label.cpp @@ -1,7 +1,7 @@ #include "label.h" // local includes -#include "tftinstance.h" +#include "tftinterface.h" #include "richtextrenderer.h" namespace espgui { @@ -11,7 +11,7 @@ Label::Label(int x, int y) : { } -void Label::start() +void Label::start(TftInterface &tft) { m_lastStr.clear(); m_lastFont = -1; @@ -21,40 +21,40 @@ void Label::start() m_lastHeight = 0; } -void Label::redraw(std::string_view str, bool forceRedraw) +void Label::redraw(TftInterface &tft, std::string_view str, uint16_t color, uint16_t bgcolor, uint8_t font, bool forceRedraw) { if (m_lastStr == str && - m_lastFont == tft.textfont && - m_lastColor == tft.textcolor && + m_lastColor == color && + m_lastFont == font && !forceRedraw) return; - const auto renderedWidth = renderRichText(str, m_x, m_y); - const auto renderedHeight = tft.fontHeight(); + const auto renderedWidth = renderRichText(tft, str, m_x, m_y, color, bgcolor, font); + const auto renderedHeight = tft.fontHeight(font); if (renderedWidth < m_lastWidth) tft.fillRect(m_x + renderedWidth, m_y, m_lastWidth - renderedWidth, m_lastHeight, - tft.textbgcolor); + bgcolor); if (renderedHeight < m_lastHeight) tft.fillRect(m_x, m_y + renderedHeight, renderedWidth, m_lastHeight - renderedHeight, - tft.textbgcolor); + bgcolor); m_lastStr = str; - m_lastFont = tft.textfont; - m_lastColor = tft.textcolor; + m_lastColor = color; + m_lastFont = font; m_lastWidth = renderedWidth; m_lastHeight = renderedHeight; } -void Label::clear() +void Label::clear(TftInterface &tft, uint16_t bgcolor) { if (m_lastWidth || m_lastHeight) - tft.fillRect(m_x, m_y, m_lastWidth, m_lastHeight, tft.textbgcolor); + tft.fillRect(m_x, m_y, m_lastWidth, m_lastHeight, bgcolor); - start(); + start(tft); } } diff --git a/src/widgets/label.h b/src/widgets/label.h index 7ed13f5..149cdf1 100644 --- a/src/widgets/label.h +++ b/src/widgets/label.h @@ -3,26 +3,31 @@ // system includes #include +// forward declares +namespace espgui { +class TftInterface; +} // namespace espgui + namespace espgui { class Label { public: Label(int x, int y); - int x() const { return m_x; }; - int y() const { return m_y; }; + int x() const { return m_x; } + int y() const { return m_y; } - void start(); - void redraw(std::string_view str, bool forceRedraw = false); - void clear(); + void start(TftInterface &tft); + void redraw(TftInterface &tft, std::string_view str, uint16_t color, uint16_t bgcolor, uint8_t font, bool forceRedraw = false); + void clear(TftInterface &tft, uint16_t bgcolor); private: const int m_x; const int m_y; std::string m_lastStr; - int m_lastFont; - int m_lastColor; + uint16_t m_lastColor; + uint8_t m_lastFont; int m_lastWidth; int m_lastHeight; diff --git a/src/widgets/progressbar.cpp b/src/widgets/progressbar.cpp index 2bac405..2e34bfc 100644 --- a/src/widgets/progressbar.cpp +++ b/src/widgets/progressbar.cpp @@ -4,7 +4,8 @@ #include // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" namespace espgui { ProgressBar::ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color) : @@ -12,13 +13,13 @@ ProgressBar::ProgressBar(int x, int y, int width, int height, int min, int max, { } -void ProgressBar::start() +void ProgressBar::start(TftInterface &tft) { m_lastValue = m_x+1; tft.drawRect(m_x, m_y, m_width, m_height, TFT_WHITE); } -void ProgressBar::redraw(int value) +void ProgressBar::redraw(TftInterface &tft, int value) { value = cpputils::mapValueClamped(value, m_min, m_max, m_x+1, m_x+m_width-1); diff --git a/src/widgets/progressbar.h b/src/widgets/progressbar.h index 23b5180..fb2881a 100644 --- a/src/widgets/progressbar.h +++ b/src/widgets/progressbar.h @@ -6,14 +6,20 @@ // 3rdparty lib includes #include +// local includes +#include "tftcolors.h" + +// forward declares +namespace espgui { class TftInterface; } + namespace espgui { class ProgressBar { public: - ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color=TFT_YELLOW); + ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color = TFT_YELLOW); - void start(); - void redraw(int value); + void start(TftInterface &tft); + void redraw(TftInterface &tft, int value); private: const int m_x; diff --git a/src/widgets/reverseprogressbar.cpp b/src/widgets/reverseprogressbar.cpp index 714977d..dc11a2c 100644 --- a/src/widgets/reverseprogressbar.cpp +++ b/src/widgets/reverseprogressbar.cpp @@ -4,7 +4,8 @@ #include // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" namespace espgui { ReverseProgressBar::ReverseProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color) : @@ -12,13 +13,13 @@ ReverseProgressBar::ReverseProgressBar(int x, int y, int width, int height, int { } -void ReverseProgressBar::start() +void ReverseProgressBar::start(TftInterface &tft) { m_lastValue = m_x+m_width-1; tft.drawRect(m_x, m_y, m_width, m_height, TFT_WHITE); } -void ReverseProgressBar::redraw(int value) +void ReverseProgressBar::redraw(TftInterface &tft, int value) { value = cpputils::mapValueClamped(value, m_min, m_max, m_x+m_width-1, m_x+1); diff --git a/src/widgets/reverseprogressbar.h b/src/widgets/reverseprogressbar.h index 159bfe1..3d48eb1 100644 --- a/src/widgets/reverseprogressbar.h +++ b/src/widgets/reverseprogressbar.h @@ -6,14 +6,20 @@ // 3rdparty lib includes #include +// local includes +#include "tftcolors.h" + +// forward declares +namespace espgui { class TftInterface; } + namespace espgui { class ReverseProgressBar { public: ReverseProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color=TFT_YELLOW); - void start(); - void redraw(int value); + void start(TftInterface &tft); + void redraw(TftInterface &tft, int value); private: const int m_x; diff --git a/src/widgets/slider.cpp b/src/widgets/slider.cpp index ef76a1c..e20535a 100644 --- a/src/widgets/slider.cpp +++ b/src/widgets/slider.cpp @@ -4,7 +4,8 @@ #include // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.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) : @@ -19,14 +20,14 @@ Slider::Slider(int x, int y, int width, int height, int min, int max, uint32_t l m_lineColor{lineColor} {} -void Slider::start() +void Slider::start(TftInterface &tft) { 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) +void Slider::redraw(TftInterface &tft, 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); diff --git a/src/widgets/slider.h b/src/widgets/slider.h index d64d93b..51b8796 100644 --- a/src/widgets/slider.h +++ b/src/widgets/slider.h @@ -6,14 +6,20 @@ // 3rdparty lib includes #include +// local includes +#include "tftcolors.h" + +// forward declares +namespace espgui { class TftInterface; } + 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); + void start(TftInterface &tft); + void redraw(TftInterface &tft, int value); private: const int m_x; diff --git a/src/widgets/verticalmeter.cpp b/src/widgets/verticalmeter.cpp index 3a0df4a..08f7380 100644 --- a/src/widgets/verticalmeter.cpp +++ b/src/widgets/verticalmeter.cpp @@ -4,7 +4,8 @@ #include // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" namespace espgui { VerticalMeter::VerticalMeter(const char *text, const char *format, int x, int y) : @@ -12,13 +13,12 @@ VerticalMeter::VerticalMeter(const char *text, const char *format, int x, int y) { } -void VerticalMeter::start() +void VerticalMeter::start(TftInterface &tft) { int w = 36; tft.drawRect(m_x, m_y, w, 155, TFT_GREY); tft.fillRect(m_x + 2, m_y + 19, w - 3, 155 - 38, TFT_WHITE); - tft.setTextColor(TFT_CYAN, TFT_BLACK); - tft.drawCentreString(m_text, m_x + w / 2, m_y + 2, 2); + tft.drawCentreString(m_text, m_x + w / 2, m_y + 2, TFT_CYAN, TFT_BLACK, 2); for (int i = 0; i < 110; i += 10) tft.drawFastHLine(m_x + 20, m_y + 27 + i, 6, TFT_BLACK); @@ -29,16 +29,14 @@ void VerticalMeter::start() tft.fillTriangle(m_x + 3, m_y + 127, m_x + 3 + 16, m_y + 127, m_x + 3, m_y + 127 - 5, TFT_RED); tft.fillTriangle(m_x + 3, m_y + 127, m_x + 3 + 16, m_y + 127, m_x + 3, m_y + 127 + 5, TFT_RED); - tft.drawCentreString("---", m_x + w / 2, m_y + 155 - 18, 2); + tft.drawCentreString("---", m_x + w / 2, m_y + 155 - 18, TFT_CYAN, TFT_BLACK, 2); } -void VerticalMeter::redraw(float value, float min, float max) +void VerticalMeter::redraw(TftInterface &tft, float value, float min, float max) { - tft.setTextColor(TFT_GREEN, TFT_BLACK); - char buf[16]; snprintf(&buf[0], 16, m_format, value); - tft.drawRightString(buf, m_x + 36 - 5, 187 - 27 + 155 - 18, 2); + tft.drawRightString(buf, m_x + 36 - 5, 187 - 27 + 155 - 18, TFT_GREEN, TFT_BLACK, 2); const int dx = 3 + m_x; value = cpputils::mapValueClamped(value, min, max, 0.f, 100.f); diff --git a/src/widgets/verticalmeter.h b/src/widgets/verticalmeter.h index 2c5922c..930faa5 100644 --- a/src/widgets/verticalmeter.h +++ b/src/widgets/verticalmeter.h @@ -3,14 +3,17 @@ // system includes #include +// forward declares +namespace espgui { class TftInterface; } + namespace espgui { class VerticalMeter { public: VerticalMeter(const char *text, const char *format, int x, int y); - void start(); - void redraw(float value, float min, float max); + void start(TftInterface &tft); + void redraw(TftInterface &tft, float value, float min, float max); private: const char * const m_text; diff --git a/src/widgets/vumeter.cpp b/src/widgets/vumeter.cpp index d4f6937..b771362 100644 --- a/src/widgets/vumeter.cpp +++ b/src/widgets/vumeter.cpp @@ -8,10 +8,11 @@ #include // local includes -#include "tftinstance.h" +#include "tftinterface.h" +#include "tftcolors.h" namespace espgui { -void VuMeter::start() +void VuMeter::start(TftInterface &tft) { ltx = 0; osx = 120; @@ -21,8 +22,6 @@ void VuMeter::start() tft.fillRect(0, 0, 239, 126, TFT_GREY); tft.fillRect(5, 3, 230, 119, TFT_WHITE); - tft.setTextColor(TFT_BLACK); // Text colour - // Draw ticks every 5 degrees from -50 to +50 degrees (100 deg. FSD swing) for (int i = -50; i < 51; i += 5) { // Long scale tick length @@ -80,11 +79,11 @@ void VuMeter::start() x0 = sx * (100 + tl + 10) + 120; y0 = sy * (100 + tl + 10) + 140; switch (i / 25) { - case -2: tft.drawCentreString("0", x0, y0 - 12, 2); break; - case -1: tft.drawCentreString("7.5", x0, y0 - 9, 2); break; - case 0: tft.drawCentreString("15", x0, y0 - 6, 2); break; - case 1: tft.drawCentreString("22.5", x0, y0 - 9, 2); break; - case 2: tft.drawCentreString("30", x0, y0 - 12, 2); break; + case -2: tft.drawCentreString("0", x0, y0 - 12, TFT_BLACK, TFT_BLACK, 2); break; + case -1: tft.drawCentreString("7.5", x0, y0 - 9, TFT_BLACK, TFT_BLACK, 2); break; + case 0: tft.drawCentreString("15", x0, y0 - 6, TFT_BLACK, TFT_BLACK, 2); break; + case 1: tft.drawCentreString("22.5", x0, y0 - 9, TFT_BLACK, TFT_BLACK, 2); break; + case 2: tft.drawCentreString("30", x0, y0 - 12, TFT_BLACK, TFT_BLACK, 2); break; } } @@ -97,16 +96,15 @@ void VuMeter::start() if (i < 50) tft.drawLine(x0, y0, x1, y1, TFT_BLACK); } - tft.drawString("KM/h", 5 + 230 - 40, 119 - 20, 2); // Units at bottom right - tft.drawCentreString("KM/h", 120, 70, 4); // Comment out to avoid font 4 + tft.drawString("KM/h", 5 + 230 - 40, 119 - 20, TFT_BLACK, TFT_BLACK, 2); // Units at bottom right + tft.drawCentreString("KM/h", 120, 70, TFT_BLACK, TFT_BLACK, 4); // Comment out to avoid font 4 tft.drawRect(5, 3, 230, 119, TFT_BLACK); // Draw bezel line } -void VuMeter::redraw(float value) +void VuMeter::redraw(TftInterface &tft, float value) { - tft.setTextColor(TFT_BLACK, TFT_WHITE); char buf[8]; dtostrf(value, 4, 0, buf); - tft.drawRightString(buf, 50, 119 - 25, 4); + tft.drawRightString(buf, 50, 119 - 25, TFT_BLACK, TFT_WHITE, 4); if (value < -3) value = -3; // Limit value to emulate needle end stops if (value > 33) value = 33; @@ -125,8 +123,7 @@ void VuMeter::redraw(float value) tft.drawLine(120 + 20 * ltx + 1, 140 - 20, osx + 1, osy, TFT_WHITE); // Re-plot text under needle - tft.setTextColor(TFT_BLACK); - tft.drawCentreString("KM/h", 120, 70, 4); // // Comment out to avoid font 4 + tft.drawCentreString("KM/h", 120, 70, TFT_BLACK, TFT_BLACK, 4); // // Comment out to avoid font 4 // Store new needle end coords for next erase ltx = tx; diff --git a/src/widgets/vumeter.h b/src/widgets/vumeter.h index f903dc1..60d2f36 100644 --- a/src/widgets/vumeter.h +++ b/src/widgets/vumeter.h @@ -3,12 +3,15 @@ // system includes #include +// forward declares +namespace espgui { class TftInterface; } + namespace espgui { class VuMeter { public: - void start(); - void redraw(float value); + void start(TftInterface &tft); + void redraw(TftInterface &tft, float value); private: float ltx; // Saved x coord of bottom of needle