Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Debug Stats window as an overlay with right click options #494

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/window/gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ void Gui::DrawMenu() {

if (GetMenuBar()) {
GetMenuBar()->Draw();

if (GetMenuBar()->IsVisible()) {
GetMenuBar()->MenuBarHeight = ImGui::GetFrameHeight();
} else {
GetMenuBar()->MenuBarHeight = 0.0f;
}
}

ImGui::End();
Expand Down
1 change: 1 addition & 0 deletions src/window/gui/GuiMenuBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace LUS {
class GuiMenuBar : public GuiElement {
public:
using GuiElement::GuiElement;
float MenuBarHeight;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to store this on the class. Can you remove this part and just hard code it where you currently use this?

};
} // namespace LUS
78 changes: 68 additions & 10 deletions src/window/gui/StatsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "ImGui/imgui.h"
#include "public/bridge/consolevariablebridge.h"
#include "spdlog/spdlog.h"
#include "Gui.h"
#include <Context.h>

namespace LUS {
StatsWindow::~StatsWindow() {
Expand All @@ -17,25 +19,81 @@ void StatsWindow::InitElement() {
void StatsWindow::DrawElement() {
const float framerate = ImGui::GetIO().Framerate;
const float deltatime = ImGui::GetIO().DeltaTime;
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
ImGui::Begin("Debug Stats", &mIsVisible, ImGuiWindowFlags_NoFocusOnAppearing);

static int location = 0;

ImGuiIO& io = ImGui::GetIO();
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
if (location >= 0) {
const std::shared_ptr<Gui> gui = LUS::Context::GetInstance()->GetWindow()->GetGui();
const ImGuiViewport* viewport = ImGui::GetMainViewport();

const float PAD = 10.0f;
const float MENU_BAR_HEIGHT = gui->GetMenuBar()->MenuBarHeight;

ImVec2 work_pos = viewport->WorkPos;
work_pos.y += MENU_BAR_HEIGHT;
ImVec2 work_size = viewport->WorkSize;
work_size.y -= MENU_BAR_HEIGHT;
ImVec2 window_pos, window_pos_pivot;
window_pos.x = (location & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD);
window_pos.y = (location & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD);
window_pos_pivot.x = (location & 1) ? 1.0f : 0.0f;
window_pos_pivot.y = (location & 2) ? 1.0f : 0.0f;
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
ImGui::SetNextWindowViewport(viewport->ID);
window_flags |= ImGuiWindowFlags_NoMove;
} else if (location == -2) {
// Center window
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
window_flags |= ImGuiWindowFlags_NoMove;
}

const ImVec2 window_size = ImVec2{ 275, 80 };
ImGui::SetNextWindowSize(window_size, ImGuiCond_Always);

ImGui::SetNextWindowBgAlpha(0.7f); // Transparent background

if (ImGui::Begin("Example: Simple overlay", &mIsVisible, window_flags)) {

ImGui::Text("Debug Stats\n"
"(right-click to change position)");

#if defined(_WIN32)
ImGui::Text("Platform: Windows");
ImGui::Text("Platform: Windows");
#elif defined(__APPLE__)
ImGui::Text("Platform: macOS");
ImGui::Text("Platform: macOS");
#elif defined(__SWITCH__)
ImGui::Text("Platform: Nintendo Switch");
ImGui::Text("Platform: Nintendo Switch");
#elif defined(__WIIU__)
ImGui::Text("Platform: Nintendo Wii U");
ImGui::Text("Platform: Nintendo Wii U");
#elif defined(__linux__)
ImGui::Text("Platform: Linux");
ImGui::Text("Platform: Linux");
#else
ImGui::Text("Platform: Unknown");
ImGui::Text("Platform: Unknown");
#endif
ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", deltatime * 1000.0f, framerate);
ImGui::Text("Status: %.3f ms/frame (%.1f FPS)", deltatime * 1000.0f, framerate);

if (ImGui::BeginPopupContextWindow()) {
if (ImGui::MenuItem("Custom", NULL, location == -1))
location = -1;
if (ImGui::MenuItem("Center", NULL, location == -2))
location = -2;
if (ImGui::MenuItem("Top-left", NULL, location == 0))
location = 0;
if (ImGui::MenuItem("Top-right", NULL, location == 1))
location = 1;
if (ImGui::MenuItem("Bottom-left", NULL, location == 2))
location = 2;
if (ImGui::MenuItem("Bottom-right", NULL, location == 3))
location = 3;
ImGui::EndPopup();
}
}

ImGui::End();
ImGui::PopStyleColor();
}

void StatsWindow::UpdateElement() {
Expand Down
Loading