From 002e513b82be5cc55e9f76bf7fc4e95df446b45f Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 23 May 2018 18:23:58 +0200 Subject: [PATCH] Added float GetWindowDpiScale(). (#1542, #1676) --- TODO.txt | 2 ++ imgui.cpp | 13 ++++++++++--- imgui.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/TODO.txt b/TODO.txt index f3984e2b..dcef7d35 100644 --- a/TODO.txt +++ b/TODO.txt @@ -264,6 +264,8 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - focus: SetKeyboardFocusHere() on with >= 0 offset could be done on same frame (else latch and modulate on beginning of next frame) - focus: unable to use SetKeyboardFocusHere() on clipped widgets. (#787) + - examples: move ImGui::NewFrame() out of the backend _NewFrame() ? + - viewport: make it possible to have no main/hosting viewport - viewport: use getfocus/setfocus api to synchronize imgui<>platform focus better (e.g imgui-side ctrl-tab can focus os window, OS initial setup and alt-tab can focus imgui window etc.) - viewport: store per-viewport/monitor DPI in .ini file so an application reload or main window changing DPI on reload can be properly patched for. - viewport: vulkan renderer implementation. diff --git a/imgui.cpp b/imgui.cpp index 5b53041f..5f53bdf5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8192,11 +8192,18 @@ ImDrawList* ImGui::GetWindowDrawList() return window->DrawList; } +float ImGui::GetWindowDpiScale() +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(g.CurrentViewport != NULL); + return g.CurrentViewport->DpiScale; +} + ImGuiViewport* ImGui::GetWindowViewport() { - ImGuiWindow* window = GetCurrentWindowRead(); - IM_ASSERT(window->Viewport != NULL); - return window->Viewport; + ImGuiContext& g = *GImGui; + IM_ASSERT(g.CurrentViewport != NULL && g.CurrentViewport == g.CurrentWindow->Viewport); + return g.CurrentViewport; } ImFont* ImGui::GetFont() diff --git a/imgui.h b/imgui.h index 05ea570f..070031fb 100644 --- a/imgui.h +++ b/imgui.h @@ -197,6 +197,7 @@ namespace ImGui IMGUI_API bool IsWindowFocused(ImGuiFocusedFlags flags=0); // is current window focused? or its root/child, depending on flags. see flags for options. IMGUI_API bool IsWindowHovered(ImGuiHoveredFlags flags=0); // is current window hovered (and typically: not blocked by a popup/modal)? see flags for options. NB: If you are trying to check whether your mouse should be dispatched to imgui or to your app, you should use the 'io.WantCaptureMouse' boolean for that! Please read the FAQ! IMGUI_API ImDrawList* GetWindowDrawList(); // get draw list associated to the current window, to append your own drawing primitives + IMGUI_API float GetWindowDpiScale(); // get DPI scale currently associated to the current window's viewport. IMGUI_API ImGuiViewport*GetWindowViewport(); // get viewport currently associated to the current window. IMGUI_API ImVec2 GetWindowPos(); // get current window position in screen space (useful if you want to do your own drawing via the DrawList API) IMGUI_API ImVec2 GetWindowSize(); // get current window size