From 8a0d2b428e8fd535e8535e03ccf6cfe9c90ef0bd Mon Sep 17 00:00:00 2001 From: blankie Date: Thu, 5 Jan 2023 20:53:34 +0700 Subject: [PATCH] Add "Add log entry every second" --- event_loop.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/event_loop.cpp b/event_loop.cpp index 3b082a0..e8ab06a 100644 --- a/event_loop.cpp +++ b/event_loop.cpp @@ -71,6 +71,8 @@ static inline void main_window(Config& active_config, bool* show_settings_window static inline void debug_window() { static bool show_demo_window = false; static size_t add_log_entry_presses = 1; + static bool log_entry_every_second = false; + static float log_entry_every_second_delta; if (show_demo_window) { ImGui::ShowDemoWindow(&show_demo_window); @@ -79,13 +81,29 @@ static inline void debug_window() { ImGui::End(); return; } + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::Checkbox("Show Dear ImGui Demo Window", &show_demo_window); + ImGui::Separator(); if (ImGui::Button("Add Log Entry")) { std::exception e; - log(std::string("Add log entry button pressed ") + std::to_string(add_log_entry_presses++) + " time(s)", e); + log(std::string("Debug log entry #") + std::to_string(add_log_entry_presses++) + " (activated via manual button press)", e); } + ImGui::SameLine(); + // returns true when it's pressed + if (ImGui::Checkbox("Add log entry every second", &log_entry_every_second)) { + log_entry_every_second_delta = 0.0f; + } + if (log_entry_every_second) { + log_entry_every_second_delta += ImGui::GetIO().DeltaTime; + if (log_entry_every_second_delta >= 1.0f) { + std::exception e; + log_entry_every_second_delta = 0.0f; + log(std::string("Debug log entry #") + std::to_string(add_log_entry_presses++) + " (activated by add log entry every second)", e); + } + } + ImGui::End(); }