1
0
mirror of synced 2025-01-18 17:14:13 +01:00

ui: Moved FPS counter to footer

This commit is contained in:
WerWolv 2021-06-07 18:13:54 +02:00
parent 7007fb53e7
commit e0112472d6
6 changed files with 39 additions and 17 deletions

View File

@ -17,6 +17,10 @@ namespace ImGui {
void Header(const char *label, bool firstEntry = false);
inline bool HasSecondPassed() {
return static_cast<ImU32>(ImGui::GetTime() * 100) % 100 <= static_cast<ImU32>(ImGui::GetIO().DeltaTime * 100);
}
std::tuple<ImTextureID, int, int> LoadImageFromPath(const char *path);
void UnloadImage(ImTextureID texture);

View File

@ -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

View File

@ -0,0 +1,21 @@
#include <hex/plugin.hpp>
#include <windows.h>
#include <psapi.h>
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());
});
}
}

View File

@ -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();

View File

@ -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<PROCESS_MEMORY_COUNTERS*>(&pmc), sizeof(pmc));

View File

@ -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();
}