MCPcopy Create free account
hub / github.com/clementgallet/libTAS / ShowExampleAppSimpleOverlay

Function ShowExampleAppSimpleOverlay

src/external/imgui/imgui_demo.cpp:7775–7823  ·  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

7773// Demonstrate creating a simple static window with no decoration
7774// + a context-menu to choose which corner of the screen to use.
7775static void ShowExampleAppSimpleOverlay(bool* p_open)
7776{
7777 static int location = 0;
7778 ImGuiIO& io = ImGui::GetIO();
7779 ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
7780 if (location >= 0)
7781 {
7782 const float PAD = 10.0f;
7783 const ImGuiViewport* viewport = ImGui::GetMainViewport();
7784 ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
7785 ImVec2 work_size = viewport->WorkSize;
7786 ImVec2 window_pos, window_pos_pivot;
7787 window_pos.x = (location & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD);
7788 window_pos.y = (location & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD);
7789 window_pos_pivot.x = (location & 1) ? 1.0f : 0.0f;
7790 window_pos_pivot.y = (location & 2) ? 1.0f : 0.0f;
7791 ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
7792 window_flags |= ImGuiWindowFlags_NoMove;
7793 }
7794 else if (location == -2)
7795 {
7796 // Center window
7797 ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
7798 window_flags |= ImGuiWindowFlags_NoMove;
7799 }
7800 ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
7801 if (ImGui::Begin("Example: Simple overlay", p_open, window_flags))
7802 {
7803 IMGUI_DEMO_MARKER("Examples/Simple Overlay");
7804 ImGui::Text("Simple overlay\n" "(right-click to change position)");
7805 ImGui::Separator();
7806 if (ImGui::IsMousePosValid())
7807 ImGui::Text("Mouse Position: (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
7808 else
7809 ImGui::Text("Mouse Position: <invalid>");
7810 if (ImGui::BeginPopupContextWindow())
7811 {
7812 if (ImGui::MenuItem("Custom", NULL, location == -1)) location = -1;
7813 if (ImGui::MenuItem("Center", NULL, location == -2)) location = -2;
7814 if (ImGui::MenuItem("Top-left", NULL, location == 0)) location = 0;
7815 if (ImGui::MenuItem("Top-right", NULL, location == 1)) location = 1;
7816 if (ImGui::MenuItem("Bottom-left", NULL, location == 2)) location = 2;
7817 if (ImGui::MenuItem("Bottom-right", NULL, location == 3)) location = 3;
7818 if (p_open && ImGui::MenuItem("Close")) *p_open = false;
7819 ImGui::EndPopup();
7820 }
7821 }
7822 ImGui::End();
7823}
7824
7825//-----------------------------------------------------------------------------
7826// [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen()

Callers 1

ShowDemoWindowMethod · 0.85

Calls 2

ImVec2Function · 0.85
GetCenterMethod · 0.80

Tested by

no test coverage detected