MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / ShowExampleAppSimpleOverlay

Function ShowExampleAppSimpleOverlay

3rdparty/imgui/src/imgui_demo.cpp:10010–10058  ·  view source on GitHub ↗

Demonstrate creating a simple static window with no decoration + a context-menu to choose which corner of the screen to use.

Source from the content-addressed store, hash-verified

10008// Demonstrate creating a simple static window with no decoration
10009// + a context-menu to choose which corner of the screen to use.
10010static void ShowExampleAppSimpleOverlay(bool* p_open)
10011{
10012 static int location = 0;
10013 ImGuiIO& io = ImGui::GetIO();
10014 ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
10015 if (location >= 0)
10016 {
10017 const float PAD = 10.0f;
10018 const ImGuiViewport* viewport = ImGui::GetMainViewport();
10019 ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
10020 ImVec2 work_size = viewport->WorkSize;
10021 ImVec2 window_pos, window_pos_pivot;
10022 window_pos.x = (location & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD);
10023 window_pos.y = (location & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD);
10024 window_pos_pivot.x = (location & 1) ? 1.0f : 0.0f;
10025 window_pos_pivot.y = (location & 2) ? 1.0f : 0.0f;
10026 ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
10027 window_flags |= ImGuiWindowFlags_NoMove;
10028 }
10029 else if (location == -2)
10030 {
10031 // Center window
10032 ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
10033 window_flags |= ImGuiWindowFlags_NoMove;
10034 }
10035 ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
10036 if (ImGui::Begin("Example: Simple overlay", p_open, window_flags))
10037 {
10038 IMGUI_DEMO_MARKER("Examples/Simple overlay"); // Scroll up to the beginning of this function to see overlay flags
10039 ImGui::Text("Simple overlay\n" "(right-click to change position)");
10040 ImGui::Separator();
10041 if (ImGui::IsMousePosValid())
10042 ImGui::Text("Mouse Position: (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
10043 else
10044 ImGui::Text("Mouse Position: <invalid>");
10045 if (ImGui::BeginPopupContextWindow())
10046 {
10047 if (ImGui::MenuItem("Custom", NULL, location == -1)) location = -1;
10048 if (ImGui::MenuItem("Center", NULL, location == -2)) location = -2;
10049 if (ImGui::MenuItem("Top-left", NULL, location == 0)) location = 0;
10050 if (ImGui::MenuItem("Top-right", NULL, location == 1)) location = 1;
10051 if (ImGui::MenuItem("Bottom-left", NULL, location == 2)) location = 2;
10052 if (ImGui::MenuItem("Bottom-right", NULL, location == 3)) location = 3;
10053 if (p_open && ImGui::MenuItem("Close")) *p_open = false;
10054 ImGui::EndPopup();
10055 }
10056 }
10057 ImGui::End();
10058}
10059
10060//-----------------------------------------------------------------------------
10061// [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen()

Callers 1

ShowDemoWindowMethod · 0.85

Calls 4

BeginFunction · 0.85
EndFunction · 0.85
GetCenterMethod · 0.80
ImVec2Function · 0.50

Tested by

no test coverage detected