#include "screen.h" #include #include "fonts.h" namespace roro { bool Screen::begin() { canvas_.setColorDepth(8); // RGB332: saves 32 KB of RAM (M1 Q46); theme colours are converted canvas_.setPsram(false); return canvas_.createSprite(theme::kWidth, theme::kHeight) != nullptr; } void Screen::render(AppManager& apps, const StatusInfo& status, const Toast* toast, const Question* question) { const auto& area = theme::kContent; App& app = apps.foreground(); // An App that keeps what it drew: only the Status Bar is cleared, unless the App has changed // or a Toast or the help panel, drawn over it, has just gone. bool overlay = apps.help().isOpen() || toast || question, retains = app.retainsContent(); if (overlayWas_ && !overlay) lost_ = true; if (retains && &app == lastApp_ && !lost_) { canvas_.fillRect(0, 0, theme::kWidth, area.y, theme::kBackground); } else { canvas_.fillSprite(theme::kBackground); if (retains) app.contentLost(); } lastApp_ = &app; lost_ = false; overlayWas_ = overlay && retains; canvas_.setClipRect(area.x, area.y, area.w, area.h); app.draw(canvas_); if (apps.help().isOpen()) widgets::help(canvas_, apps.help()); // over the App, under the Status Bar if (question) widgets::dialog(canvas_, question->title, question->message, *question->dialog); canvas_.clearClipRect(); widgets::statusBar(canvas_, status); if (toast) widgets::toast(canvas_, *toast); canvas_.pushSprite(&M5Cardputer.Display, 0, 0); } void Screen::renderUpdate(const std::string& title, const std::string& detail, int percent) { lost_ = true; canvas_.fillSprite(theme::kBackground); canvas_.setTextDatum(top_center); canvas_.setFont(&fonts::bold); canvas_.setTextColor(theme::kAccent); canvas_.drawString(title.c_str(), theme::kWidth / 2, 34); canvas_.setFont(&fonts::body); canvas_.setTextColor(theme::kText); canvas_.drawString(detail.c_str(), theme::kWidth / 2, 56); if (percent >= 0) { const int x = 20, y = 82, w = theme::kWidth - 40, h = 12; canvas_.drawRect(x, y, w, h, theme::kMuted); canvas_.fillRect(x + 1, y + 1, (w - 2) * percent / 100, h - 2, theme::kAccent); canvas_.drawString((std::to_string(percent) + "%").c_str(), theme::kWidth / 2, y + 18); } canvas_.setTextDatum(top_left); canvas_.pushSprite(&M5Cardputer.Display, 0, 0); } } // namespace roro