dashboard/src/panel/weather.cpp

94 lines
2.8 KiB
C++
Raw Normal View History

///////////////////////////////////////////////////////////////////////////////
// Tyler Perkins
// 19-9-21
// weather panel
//
#include "weather.hpp"
2021-09-19 22:23:02 +00:00
#include "weather_config.hpp"
using namespace dashboard::panel;
///////////////////////////////////////////////////////////////////////////////
// Constructors ///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
weather::weather(){
2021-10-02 18:14:58 +00:00
std::cerr << "WEATHER CONSTRUCTOR\n";
_time_on_screen = WEATHER_DEFAULT_ON_SCREEN_TIME;
_update_interval = std::chrono::milliseconds{UPDATE_INTERVAL};
_last_update = std::chrono::high_resolution_clock::now();
2021-09-19 22:23:02 +00:00
_rss = rss_utils::rss(WEATHER_URL_SOURCE);
2021-10-02 18:14:58 +00:00
_texture = SDL_CreateTexture(board::getRenderer(),
SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET,
SCREEN_WIDTH, SCREEN_HEIGHT);
2021-09-19 22:23:02 +00:00
update();
}
weather::~weather(){
2021-10-02 18:14:58 +00:00
std::cerr << "WEATHER DECONSTRUCTOR\n";
}
///////////////////////////////////////////////////////////////////////////////
// Draw function //////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void weather::draw(){
//check if its time to update
2021-09-19 22:23:02 +00:00
if((std::chrono::high_resolution_clock::now() - _last_update)
> _update_interval){
//TODO multithread this
update();
2021-09-19 22:23:02 +00:00
2021-10-02 18:14:58 +00:00
update_texture();
}
2021-09-19 22:23:02 +00:00
2021-10-02 18:14:58 +00:00
static SDL_Rect tgt = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };
2021-09-19 22:23:02 +00:00
2021-10-02 18:14:58 +00:00
//SDL_RenderCopy(board::getRenderer(), _texture, NULL,
//&tgt);
2021-09-19 22:23:02 +00:00
2021-10-02 18:14:58 +00:00
//TODO add this all to one texture
2021-09-19 22:23:02 +00:00
}
///////////////////////////////////////////////////////////////////////////////
// Helper functions ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
2021-10-02 18:14:58 +00:00
///////////////////////////////////////
// Update the information of the obj
// This DOES NOT update the display
void weather::update() {
std::cerr << "WEATHER::UPDATE\n";
_last_update = std::chrono::high_resolution_clock::now();
//fetch updates
2021-09-19 22:23:02 +00:00
_rss.update();
}
2021-10-02 18:14:58 +00:00
///////////////////////////////////////
// Update the texture that is being
// displayed, based on data in
// _rss
void weather::update_texture(){
//SDL_SetRenderTarget(board::getRenderer(), _texture);
SDL_Rect tgt;
tgt.x = 50;
tgt.y = 50;
TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 24 }),
_rss.getTitle().c_str(),
&tgt.w, &tgt.h);
SDL_RenderCopy(board::getRenderer(),
board::getString(_rss.getTitle(),
{ "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), NULL, &tgt );
//SDL_SetRenderTarget(board::getRenderer(), NULL);
}