Added text processing for weather elements
This commit is contained in:
parent
e5cbbea696
commit
b0451e9f55
@ -15,7 +15,6 @@ using namespace dashboard::panel;
|
|||||||
|
|
||||||
weather::weather(){
|
weather::weather(){
|
||||||
std::cerr << "WEATHER CONSTRUCTOR\n";
|
std::cerr << "WEATHER CONSTRUCTOR\n";
|
||||||
//std::cerr << "Current Renderer : " << board::getRenderer() << "\n";
|
|
||||||
_time_on_screen = WEATHER_DEFAULT_ON_SCREEN_TIME;
|
_time_on_screen = WEATHER_DEFAULT_ON_SCREEN_TIME;
|
||||||
_update_interval = std::chrono::milliseconds{UPDATE_INTERVAL};
|
_update_interval = std::chrono::milliseconds{UPDATE_INTERVAL};
|
||||||
//let set to default, will make it so it updates the texture ASAP
|
//let set to default, will make it so it updates the texture ASAP
|
||||||
@ -36,8 +35,11 @@ weather::~weather(){
|
|||||||
|
|
||||||
void weather::draw(){
|
void weather::draw(){
|
||||||
//create the texture if this is the first time running draw
|
//create the texture if this is the first time running draw
|
||||||
if(_texture == nullptr)
|
if(_texture == nullptr){
|
||||||
initTexture();
|
initTexture();
|
||||||
|
update();
|
||||||
|
update_texture();
|
||||||
|
}
|
||||||
|
|
||||||
//check if its time to update
|
//check if its time to update
|
||||||
if((std::chrono::high_resolution_clock::now() - _last_update)
|
if((std::chrono::high_resolution_clock::now() - _last_update)
|
||||||
@ -68,6 +70,16 @@ void weather::update() {
|
|||||||
|
|
||||||
//fetch updates
|
//fetch updates
|
||||||
_rss.update();
|
_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(),
|
_rss.getTitle().c_str(),
|
||||||
&tgt.w, &tgt.h);
|
&tgt.w, &tgt.h);
|
||||||
SDL_RenderCopy(board::getRenderer(),
|
SDL_RenderCopy(board::getRenderer(),
|
||||||
board::getString(_rss.getTitle(),
|
board::getString(_rss.getTitle().c_str(),
|
||||||
{ "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), NULL, &tgt);
|
{ "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), NULL, &tgt);
|
||||||
|
|
||||||
//current weather
|
//current weather
|
||||||
TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 24 }),
|
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.w, &tgt.h);
|
||||||
tgt.x = SCREEN_WIDTH / 2 - (tgt.w / 2);
|
tgt.x = SCREEN_WIDTH / 2 - (tgt.w / 2);
|
||||||
tgt.y = SCREEN_HEIGHT / 2 - (tgt.h / 2);
|
tgt.y = SCREEN_HEIGHT / 2 - (tgt.h / 2);
|
||||||
SDL_RenderCopy(board::getRenderer(),
|
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);
|
{ "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);
|
SDL_SetRenderTarget(board::getRenderer(), NULL);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace dashboard::panel {
|
namespace dashboard::panel {
|
||||||
class weather : public panel {
|
class weather : public panel {
|
||||||
@ -30,6 +31,10 @@ namespace dashboard::panel {
|
|||||||
void update_texture();
|
void update_texture();
|
||||||
void initTexture();
|
void initTexture();
|
||||||
|
|
||||||
|
std::string current_desc;
|
||||||
|
std::string tommorow_desc;
|
||||||
|
|
||||||
|
|
||||||
rss_utils::rss _rss;
|
rss_utils::rss _rss;
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;
|
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;
|
||||||
std::chrono::milliseconds _update_interval;
|
std::chrono::milliseconds _update_interval;
|
||||||
|
@ -16,6 +16,5 @@ namespace dashboard::panel {
|
|||||||
|
|
||||||
//How long should we wait between updates? in ms
|
//How long should we wait between updates? in ms
|
||||||
//Default 1 hour
|
//Default 1 hour
|
||||||
//constexpr size_t UPDATE_INTERVAL = 3600000;
|
constexpr size_t UPDATE_INTERVAL = 3600000;
|
||||||
constexpr size_t UPDATE_INTERVAL = 5000;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user