From d4a94d87c4e5edd899b3e1d6e4ae65a75af1c167 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Tue, 21 Dec 2021 23:21:06 -0500 Subject: [PATCH] Add _title field to panel, display _title in overlay panel --- src/board.cpp | 2 ++ src/config.cpp | 2 +- src/panel/def_overlay.cpp | 14 ++++++++++++-- src/panel/def_overlay.hpp | 1 + src/panel/panel.hpp | 4 +++- src/panel/weather.cpp | 11 +---------- src/panel/weather_config.hpp | 5 +++++ src/panel/wifi.cpp | 17 +++++++---------- src/panel/wifi_config.hpp | 4 ++++ 9 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/board.cpp b/src/board.cpp index ccc7527..26ba2a4 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -348,6 +348,7 @@ void board::start(){ //time since last panel auto last_panel = start; + OVERLAY->_title = PANELS[0]->_title; SDL_Log("Starting main loop...\n"); for(;;){ @@ -359,6 +360,7 @@ void board::start(){ start - last_panel).count() >= PANELS[i]->_time_on_screen){ i++; last_panel = start; + OVERLAY->_title = PANELS[i]->_title; } //check if we can loop back over diff --git a/src/config.cpp b/src/config.cpp index 9d59802..505abd5 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -48,6 +48,6 @@ size_t FONT_LOCATIONS_LENGTH = sizeof(FONT_LOCATIONS)/sizeof(FONT_LOCATIONS[0]); //}; const FONT_SIZE_STRING CONST_STRINGS[] = { //Weather strings - { "Today's Weather", { "Roboto_Mono/RobotoMono-Medium.ttf", 50 } }, + { "Weather", { "Roboto_Mono/RobotoMono-Medium.ttf", 50 } }, }; size_t CONST_STRINGS_LENGTH = sizeof(CONST_STRINGS)/sizeof(CONST_STRINGS[0]); diff --git a/src/panel/def_overlay.cpp b/src/panel/def_overlay.cpp index ba65608..739657c 100644 --- a/src/panel/def_overlay.cpp +++ b/src/panel/def_overlay.cpp @@ -19,8 +19,7 @@ def_overlay::def_overlay(){ _time_on_screen = 0; _update_interval = std::chrono::milliseconds{DEF_OVERLAY_UPDATE_INTERVAL}; _texture = nullptr; - //let set to default, will make it so it updates the texture ASAP - //_last_update; + _title = ""; } def_overlay::~def_overlay(){ @@ -122,6 +121,17 @@ void def_overlay::update_texture() { board::getString(std::string(date_time), { "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt); + //show the current panel title (stored in _title) + TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), + _title.c_str(), + &tgt.w, &tgt.h); + tgt.x = 5; tgt.y = -5; + SDL_RenderCopy(board::getRenderer(), + board::getString(_title, + { "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt); + + + SDL_SetRenderTarget(board::getRenderer(), NULL); diff --git a/src/panel/def_overlay.hpp b/src/panel/def_overlay.hpp index ed0bdea..eb544f4 100644 --- a/src/panel/def_overlay.hpp +++ b/src/panel/def_overlay.hpp @@ -25,6 +25,7 @@ namespace dashboard::panel { void draw(); + private: void update(); void update_texture(); diff --git a/src/panel/panel.hpp b/src/panel/panel.hpp index 0e6e57f..fa2a345 100644 --- a/src/panel/panel.hpp +++ b/src/panel/panel.hpp @@ -16,17 +16,19 @@ #include #include #include +#include namespace dashboard::panel { class panel { public: panel() = default; - ~panel() = default; + virtual ~panel() = default; virtual void draw() = 0; //in milliseconds size_t _time_on_screen = 0; + std::string _title; protected: SDL_Texture* _texture; diff --git a/src/panel/weather.cpp b/src/panel/weather.cpp index af2d30c..7e0fb81 100644 --- a/src/panel/weather.cpp +++ b/src/panel/weather.cpp @@ -18,6 +18,7 @@ weather::weather(){ _time_on_screen = WEATHER_DEFAULT_ON_SCREEN_TIME; _update_interval = std::chrono::milliseconds{WEATHER_UPDATE_INTERVAL}; _texture = nullptr; + _title = WEATHER_TITLE; //let set to default, will make it so it updates the texture ASAP //_last_update; _rss = rss_utils::rss(WEATHER_URL_SOURCE); @@ -93,16 +94,6 @@ void weather::update_texture(){ SDL_RenderCopy(board::getRenderer(), board::getImage("sky.png"), NULL, NULL); - //title - tgt.x = 50; - tgt.y = 50; - TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), - "Today's Weather", - &tgt.w, &tgt.h); - SDL_RenderCopy(board::getRenderer(), - board::getString("Today's Weather", - { "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt); - //current weather TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), current_desc.c_str(), diff --git a/src/panel/weather_config.hpp b/src/panel/weather_config.hpp index ff8ea34..c28088c 100644 --- a/src/panel/weather_config.hpp +++ b/src/panel/weather_config.hpp @@ -7,6 +7,10 @@ #pragma once namespace dashboard::panel { + //This will be displayed at the top left on the status bar. Set to a blank + //string to not show anything + constexpr char WEATHER_TITLE[] = "Weather"; + //New York RSS feed static const char* WEATHER_URL_SOURCE = "http://rss.accuweather.com/rss/liveweather_rss.asp?locCode=10007"; @@ -17,4 +21,5 @@ namespace dashboard::panel { //How long should we wait between updates? in ms //Default 1 hour constexpr size_t WEATHER_UPDATE_INTERVAL = 3600000; + } diff --git a/src/panel/wifi.cpp b/src/panel/wifi.cpp index 7d0c613..6f64a27 100644 --- a/src/panel/wifi.cpp +++ b/src/panel/wifi.cpp @@ -7,6 +7,8 @@ #include "wifi.hpp" #include "wifi_config.hpp" +#include "def_overlay_config.hpp" + using namespace dashboard::panel; /////////////////////////////////////////////////////////////////////////////// @@ -17,6 +19,7 @@ wifi::wifi(){ std::cerr << "WIFI CONSTRUCTOR\n"; _texture = nullptr; _time_on_screen = WIFI_DEFAULT_TIME_ON_SCREEN; + _title = WIFI_TITLE; } wifi::~wifi(){ @@ -69,16 +72,10 @@ void wifi::update_texture(){ SDL_RenderCopy(board::getRenderer(), board::getImage("wifi_background.jpg"), NULL, NULL); - //place the title - tgt.x = 50; - tgt.y = 50; - TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), - "Wireless", - &tgt.w, &tgt.h); - //Note about the string "Wireless" + //Note about the strings here //Because this is only called once, it makes more sense to not have - //"Wireless" as a static string, and instead generate it dynamically once, - //copy it into this _texture, and then delete if once it goes out of the + //any of these as static strings and instead generate them dynamically once, + //copy it into this _texture, and then delete it once it goes out of the //LRU. This way, we dont waste memory holding a string we only copy once SDL_RenderCopy(board::getRenderer(), board::getString("Wireless", @@ -86,7 +83,7 @@ void wifi::update_texture(){ //show the QRCode tgt.x = -25; - tgt.y = tgt.h - 6; + tgt.y = DEF_OVERLAY_BAR_HEIGHT; tgt.w = (SCREEN_WIDTH / 2) ; tgt.h = tgt.w; SDL_RenderCopy(board::getRenderer(), diff --git a/src/panel/wifi_config.hpp b/src/panel/wifi_config.hpp index c127e3d..c6ffd3a 100644 --- a/src/panel/wifi_config.hpp +++ b/src/panel/wifi_config.hpp @@ -7,6 +7,10 @@ #pragma once namespace dashboard::panel { + //This will be displayed at the top left on the status bar. Set to a blank + //string to not show anything + constexpr char WIFI_TITLE[] = "Wirless"; + //Default time the slid is shown on the screen, in ms //Default 15s constexpr size_t WIFI_DEFAULT_TIME_ON_SCREEN = 15000;