Add _title field to panel, display _title in overlay panel

This commit is contained in:
Tyler Perkins 2021-12-21 23:21:06 -05:00
parent fa32bcfad8
commit d4a94d87c4
9 changed files with 36 additions and 24 deletions

View File

@ -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

View File

@ -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]);

View File

@ -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);

View File

@ -25,6 +25,7 @@ namespace dashboard::panel {
void draw();
private:
void update();
void update_texture();

View File

@ -16,17 +16,19 @@
#include <SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <string>
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;

View File

@ -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(),

View File

@ -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;
}

View File

@ -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(),

View File

@ -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;