Skip to content

Commit

Permalink
draw fps
Browse files Browse the repository at this point in the history
  • Loading branch information
Xcedf committed Dec 31, 2024
1 parent a669e0d commit 867a4a7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ display:
show_menubar:
type: bool
default: true
show_fps:
type: bool
default: false
show_notifications:
type: bool
default: true
Expand Down
42 changes: 42 additions & 0 deletions ui/xui/main-menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,46 @@ void MainMenuInputView::Draw()
"Capture even if window is unfocused (requires restart)");
}

void DrawFPS()
{
const float DISTANCE = 10.0f;
static int corner = 0;
ImGuiIO &io = ImGui::GetIO();
if (corner != -1) {
ImVec2 window_pos =
ImVec2((corner & 1) ? io.DisplaySize.x - DISTANCE : DISTANCE,
(corner & 2) ? io.DisplaySize.y - DISTANCE : DISTANCE);
window_pos.y = g_main_menu_height + DISTANCE;
ImVec2 window_pos_pivot =
ImVec2((corner & 1) ? 1.0f : 0.0f, (corner & 2) ? 1.0f : 0.0f);
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
}

float fade = 1.0;

ImVec4 color = ImGui::GetStyle().Colors[ImGuiCol_ButtonActive];
color.w *= fade;
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1);
ImGui::PushStyleColor(ImGuiCol_PopupBg, ImVec4(0, 0, 0, fade * 0.9f));
ImGui::PushStyleColor(ImGuiCol_Border, color);
ImGui::PushStyleColor(ImGuiCol_Text, color);
ImGui::SetNextWindowBgAlpha(0.90f * fade);
if (ImGui::Begin("FPSOverlay", NULL,
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs)) {
ImGui::Text("FPS %d", g_nv2a_stats.increment_fps);
}
ImGui::PopStyleColor();
ImGui::PopStyleColor();
ImGui::PopStyleColor();
ImGui::PopStyleVar();
ImGui::End();
}

void MainMenuDisplayView::Draw()
{
SectionTitle("Renderer");
Expand Down Expand Up @@ -501,6 +541,8 @@ void MainMenuDisplayView::Draw()
SectionTitle("Interface");
Toggle("Show main menu bar", &g_config.display.ui.show_menubar,
"Show main menu bar when mouse is activated");
Toggle("Show framerate", &g_config.display.ui.show_fps,
"Enable / Disable the basic FPS monitor");
Toggle("Show notifications", &g_config.display.ui.show_notifications,
"Display notifications in upper-right corner");
Toggle("Hide mouse cursor", &g_config.display.ui.hide_cursor,
Expand Down
2 changes: 2 additions & 0 deletions ui/xui/main-menu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public:
void Draw() override;
};

void DrawFPS();

class MainMenuDisplayView : public virtual MainMenuTabView
{
public:
Expand Down
4 changes: 4 additions & 0 deletions ui/xui/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ void xemu_hud_render(void)
}
#endif

if (g_config.display.ui.show_fps) {
DrawFPS();
}

if (g_config.display.ui.show_menubar && !first_boot_window.is_open) {
// Auto-hide main menu after 5s of inactivity
static uint32_t last_check = 0;
Expand Down

0 comments on commit 867a4a7

Please sign in to comment.