From b0451e9f554b73b5fa40a8f39a5412d769eed1ab Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sun, 19 Dec 2021 19:59:53 -0500 Subject: [PATCH] Added text processing for weather elements --- src/panel/weather.cpp | 31 ++++++++++++++++++++++++++----- src/panel/weather.hpp | 5 +++++ src/panel/weather_config.hpp | 3 +-- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/panel/weather.cpp b/src/panel/weather.cpp index 5337093..f74f522 100644 --- a/src/panel/weather.cpp +++ b/src/panel/weather.cpp @@ -15,7 +15,6 @@ using namespace dashboard::panel; weather::weather(){ std::cerr << "WEATHER CONSTRUCTOR\n"; - //std::cerr << "Current Renderer : " << board::getRenderer() << "\n"; _time_on_screen = WEATHER_DEFAULT_ON_SCREEN_TIME; _update_interval = std::chrono::milliseconds{UPDATE_INTERVAL}; //let set to default, will make it so it updates the texture ASAP @@ -36,8 +35,11 @@ weather::~weather(){ void weather::draw(){ //create the texture if this is the first time running draw - if(_texture == nullptr) + if(_texture == nullptr){ initTexture(); + update(); + update_texture(); + } //check if its time to update if((std::chrono::high_resolution_clock::now() - _last_update) @@ -68,6 +70,16 @@ void weather::update() { //fetch updates _rss.update(); + + //update internal state + + current_desc = _rss.getItem(0).getDescription(); + current_desc = current_desc.substr(0,current_desc.find('<')); + std::cerr << "Current Description : (\" " << current_desc << "\")\n"; + + tommorow_desc = _rss.getItem(1).getDescription(); + tommorow_desc = tommorow_desc.substr(0,tommorow_desc.find('<')); + std::cerr << "Tommorow Description : (\" " << tommorow_desc << "\")\n"; } /////////////////////////////////////// @@ -87,19 +99,28 @@ void weather::update_texture(){ _rss.getTitle().c_str(), &tgt.w, &tgt.h); SDL_RenderCopy(board::getRenderer(), - board::getString(_rss.getTitle(), + board::getString(_rss.getTitle().c_str(), { "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), NULL, &tgt); //current weather TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), - _rss.getItem(0).getTitle().c_str(), + current_desc.c_str(), &tgt.w, &tgt.h); tgt.x = SCREEN_WIDTH / 2 - (tgt.w / 2); tgt.y = SCREEN_HEIGHT / 2 - (tgt.h / 2); SDL_RenderCopy(board::getRenderer(), - board::getString(_rss.getItem(0).getTitle().c_str(), + board::getString(current_desc.c_str(), { "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), NULL, &tgt); + //tommorow's weather + TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), + tommorow_desc.c_str(), + &tgt.w, &tgt.h); + tgt.x = SCREEN_WIDTH / 2 - (tgt.w / 2); + tgt.y = SCREEN_HEIGHT / 2 - (tgt.h / 2) + 30; + SDL_RenderCopy(board::getRenderer(), + board::getString(tommorow_desc.c_str(), + { "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), NULL, &tgt); SDL_SetRenderTarget(board::getRenderer(), NULL); } diff --git a/src/panel/weather.hpp b/src/panel/weather.hpp index 65f3ad2..b6db686 100644 --- a/src/panel/weather.hpp +++ b/src/panel/weather.hpp @@ -16,6 +16,7 @@ #include #include +#include namespace dashboard::panel { class weather : public panel { @@ -30,6 +31,10 @@ namespace dashboard::panel { void update_texture(); void initTexture(); + std::string current_desc; + std::string tommorow_desc; + + rss_utils::rss _rss; std::chrono::time_point _last_update; std::chrono::milliseconds _update_interval; diff --git a/src/panel/weather_config.hpp b/src/panel/weather_config.hpp index 0d46cea..35aa03b 100644 --- a/src/panel/weather_config.hpp +++ b/src/panel/weather_config.hpp @@ -16,6 +16,5 @@ namespace dashboard::panel { //How long should we wait between updates? in ms //Default 1 hour - //constexpr size_t UPDATE_INTERVAL = 3600000; - constexpr size_t UPDATE_INTERVAL = 5000; + constexpr size_t UPDATE_INTERVAL = 3600000; }