diff --git a/external/ImGui/include/imgui_imhex_extensions.h b/external/ImGui/include/imgui_imhex_extensions.h index 056c5bee5..63473c128 100644 --- a/external/ImGui/include/imgui_imhex_extensions.h +++ b/external/ImGui/include/imgui_imhex_extensions.h @@ -17,6 +17,10 @@ namespace ImGui { void Header(const char *label, bool firstEntry = false); + inline bool HasSecondPassed() { + return static_cast(ImGui::GetTime() * 100) % 100 <= static_cast(ImGui::GetIO().DeltaTime * 100); + } + std::tuple LoadImageFromPath(const char *path); void UnloadImage(ImTextureID texture); diff --git a/plugins/builtin/CMakeLists.txt b/plugins/builtin/CMakeLists.txt index c521a3e3f..39f57a115 100644 --- a/plugins/builtin/CMakeLists.txt +++ b/plugins/builtin/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(${PROJECT_NAME} SHARED source/content/settings_entries.cpp source/content/tools_entries.cpp source/content/data_processor_nodes.cpp + source/content/footer_items.cpp source/math_evaluator.cpp diff --git a/plugins/builtin/source/content/footer_items.cpp b/plugins/builtin/source/content/footer_items.cpp new file mode 100644 index 000000000..3eb53208c --- /dev/null +++ b/plugins/builtin/source/content/footer_items.cpp @@ -0,0 +1,21 @@ +#include + +#include +#include + +namespace hex::plugin::builtin { + + void addFooterItems() { + + ContentRegistry::Interface::addFooterItem([] { + static float framerate = 0; + if (ImGui::HasSecondPassed()) { + framerate = ImGui::GetIO().Framerate; + } + + ImGui::TextUnformatted(hex::format("FPS {0:.2f}", framerate).c_str()); + }); + + } + +} \ No newline at end of file diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp index 271094347..58fae7bdc 100644 --- a/plugins/builtin/source/plugin_builtin.cpp +++ b/plugins/builtin/source/plugin_builtin.cpp @@ -9,6 +9,8 @@ namespace hex::plugin::builtin { void registerSettings(); void registerDataProcessorNodes(); + void addFooterItems(); + void registerLanguageEnUS(); void registerLanguageDeDE(); void registerLanguageItIT(); @@ -26,6 +28,8 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") { registerSettings(); registerDataProcessorNodes(); + addFooterItems(); + registerLanguageEnUS(); registerLanguageDeDE(); registerLanguageItIT(); diff --git a/plugins/windows/source/content/footer_items.cpp b/plugins/windows/source/content/footer_items.cpp index 36f0444da..27fe7f76b 100644 --- a/plugins/windows/source/content/footer_items.cpp +++ b/plugins/windows/source/content/footer_items.cpp @@ -22,7 +22,7 @@ namespace hex::plugin::windows { ContentRegistry::Interface::addFooterItem([] { static float cpuUsage = 0.0F; - if (ImGui::GetFrameCount() % 60 == 0) { + if (ImGui::HasSecondPassed()) { static ULARGE_INTEGER lastCPU, lastSysCPU, lastUserCPU; static u32 numProcessors; static HANDLE self = GetCurrentProcess(); @@ -62,14 +62,14 @@ namespace hex::plugin::windows { } } - ImGui::TextUnformatted(hex::format(ICON_FA_TACHOMETER_ALT " {0:.3}%", cpuUsage * 100).c_str()); + ImGui::TextUnformatted(hex::format(ICON_FA_TACHOMETER_ALT " {0:.2f}%", cpuUsage * 100).c_str()); }); ContentRegistry::Interface::addFooterItem([] { static MEMORYSTATUSEX memInfo; static PROCESS_MEMORY_COUNTERS_EX pmc; - if (ImGui::GetFrameCount() % 60 == 0) { + if (ImGui::HasSecondPassed()) { memInfo.dwLength = sizeof(MEMORYSTATUSEX); GlobalMemoryStatusEx(&memInfo); GetProcessMemoryInfo(GetCurrentProcess(), reinterpret_cast(&pmc), sizeof(pmc)); diff --git a/source/window.cpp b/source/window.cpp index 210d4228a..fefb34219 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -339,26 +339,18 @@ namespace hex { } if (ImGui::BeginMenu("hex.menu.view"_lang)) { - ImGui::Separator(); - ImGui::MenuItem("hex.menu.view.fps"_lang, "", &this->m_fpsVisible); - #ifdef DEBUG + #if defined(DEBUG) + ImGui::Separator(); ImGui::MenuItem("hex.menu.view.demo"_lang, "", &this->m_demoWindowOpen); #endif ImGui::EndMenu(); } - if (this->m_fpsVisible) { - std::string fps = hex::format("{:.1f} FPS ", ImGui::GetIO().Framerate); + #if defined(DEBUG) ImGui::SameLine(); - ImGui::SetCursorPosX(ImGui::GetWindowWidth() - fps.length() * ImGui::GetFontSize()); - ImGui::TextUnformatted(fps.c_str()); - } else { - #if defined(DEBUG) - ImGui::SameLine(); - ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 2 * ImGui::GetFontSize()); - ImGui::TextUnformatted(ICON_FA_BUG); - #endif - } + ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 2 * ImGui::GetFontSize()); + ImGui::TextUnformatted(ICON_FA_BUG); + #endif ImGui::EndMenuBar(); }