mirror of
https://github.com/Clortox/dashboard.git
synced 2026-03-04 00:58:00 +00:00
Add _title field to panel, display _title in overlay panel
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace dashboard::panel {
|
||||
|
||||
void draw();
|
||||
|
||||
|
||||
private:
|
||||
void update();
|
||||
void update_texture();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user