From 282edfc7aaed01ad8390f9f982e369e82e28995e Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Mon, 20 Dec 2021 13:14:47 -0500 Subject: [PATCH] Add panel incrmementing --- DEVELOPMENT.md | 4 ++++ src/board.cpp | 12 +++++++++++- src/panel/panel.hpp | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 8d32a0e..1fd32d2 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -31,6 +31,10 @@ up to you to call this, to give you the option of lazy loading it. because SDL will not be setup when your constructor is called, and therefore will not be able to properly create the texture for the renderer. +The *_time_on_screen* value is in milliseconds, and will be the amount of time +the board will display the panel before transitioning. This value can be +modified at runtime if needed (ie displaying a dynamic length video). + The provided memory api stores textures (SDL_Texture), fonts (TTF_Font), and strings (SDL_Texture). Both static values can be added that will exist for the lifetime of the program, as well as dynamic versions that will be stored in a diff --git a/src/board.cpp b/src/board.cpp index 4a09466..80ad201 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -346,13 +346,23 @@ void board::start(){ //frame counter static unsigned long long int fcount = 0; + //time since last panel + auto last_panel = start; + SDL_Log("Starting main loop...\n"); for(;;){ start = std::chrono::high_resolution_clock::now(); fcount++; + //check if its time to increment the panel + if(std::chrono::duration_cast( + start - last_panel).count() >= PANELS[i]->_time_on_screen){ + i++; + last_panel = start; + } + //check if we can loop back over - if(i > PANELS_LENGTH) + if(i >= PANELS_LENGTH) i = 0; SDL_RenderClear(_renderer); diff --git a/src/panel/panel.hpp b/src/panel/panel.hpp index 1c7cdc7..7d0a70d 100644 --- a/src/panel/panel.hpp +++ b/src/panel/panel.hpp @@ -25,6 +25,7 @@ namespace dashboard::panel { virtual void draw() = 0; + //in milliseconds size_t _time_on_screen = 0; protected: