From 543c5544567a3bb3dd797a6ec8e51f7913514abf Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Tue, 21 Dec 2021 16:47:35 -0500 Subject: [PATCH] Make date string configurable --- src/panel/def_overlay.cpp | 12 ++++++------ src/panel/def_overlay.hpp | 2 +- src/panel/def_overlay_config.hpp | 8 ++++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/panel/def_overlay.cpp b/src/panel/def_overlay.cpp index e8cf190..ba65608 100644 --- a/src/panel/def_overlay.cpp +++ b/src/panel/def_overlay.cpp @@ -65,9 +65,9 @@ void def_overlay::update() { _last_update = std::chrono::high_resolution_clock::now(); //get current date and time - std::time_t curr_time = std::chrono::system_clock::to_time_t( - std::chrono::system_clock::now()); - date_time = std::ctime(&curr_time); + std::time_t curr_time = std::time(nullptr); + std::strftime(date_time, sizeof(date_time), + DEF_OVERLAY_DATE_STRING, std::localtime(&curr_time)); } /////////////////////////////////////// @@ -114,12 +114,12 @@ void def_overlay::update_texture() { //show the date and time TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), - date_time.c_str(), + date_time, &tgt.w, &tgt.h); - tgt.x = SCREEN_WIDTH - tgt.w + 25; + tgt.x = SCREEN_WIDTH - tgt.w - 5; tgt.y = -5; SDL_RenderCopy(board::getRenderer(), - board::getString(date_time.c_str(), + board::getString(std::string(date_time), { "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt); diff --git a/src/panel/def_overlay.hpp b/src/panel/def_overlay.hpp index 6cbe7f4..ed0bdea 100644 --- a/src/panel/def_overlay.hpp +++ b/src/panel/def_overlay.hpp @@ -30,7 +30,7 @@ namespace dashboard::panel { void update_texture(); void initTexture(); - std::string date_time; + char date_time [100]; std::chrono::time_point _last_update; std::chrono::milliseconds _update_interval; diff --git a/src/panel/def_overlay_config.hpp b/src/panel/def_overlay_config.hpp index 3a49f83..b8f49d1 100644 --- a/src/panel/def_overlay_config.hpp +++ b/src/panel/def_overlay_config.hpp @@ -10,8 +10,8 @@ namespace dashboard::panel { //How long should we wait between updates? in ms - //Default 10 s - constexpr size_t DEF_OVERLAY_UPDATE_INTERVAL = 500; + //Default 1s + constexpr size_t DEF_OVERLAY_UPDATE_INTERVAL = 1000; //Height of the bar on the top and bottom, in pixels constexpr size_t DEF_OVERLAY_BAR_HEIGHT = 60; @@ -26,4 +26,8 @@ namespace dashboard::panel { constexpr uint8_t DEF_OVERLAY_BAR_GREEN = 0xD3; constexpr uint8_t DEF_OVERLAY_BAR_BLUE = 0xD3; constexpr uint8_t DEF_OVERLAY_BAR_ALPHA = 0x7F; + + //for more on how this string format works, refer to + //https://en.cppreference.com/w/cpp/chrono/c/strftime + constexpr char DEF_OVERLAY_DATE_STRING[] = "%a %R %p"; }