diff --git a/imgui.cpp b/imgui.cpp index 731bb0bd..7e07a2e1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7391,8 +7391,7 @@ ImDrawList* ImGui::GetWindowDrawList() float ImGui::GetWindowDpiScale() { ImGuiContext& g = *GImGui; - IM_ASSERT(g.CurrentViewport != NULL); - return g.CurrentViewport->DpiScale; + return g.CurrentDpiScale; } ImGuiViewport* ImGui::GetWindowViewport() @@ -10253,6 +10252,7 @@ void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* view viewport->LastFrameActive = g.FrameCount; if (g.CurrentViewport == viewport) return; + g.CurrentDpiScale = viewport->DpiScale; g.CurrentViewport = viewport; //IMGUI_DEBUG_LOG_VIEWPORT("SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0); @@ -10408,6 +10408,7 @@ static void ImGui::UpdateViewportsNewFrame() main_viewport_platform_pos = (main_viewport->Flags & ImGuiViewportFlags_Minimized) ? main_viewport->Pos : g.PlatformIO.Platform_GetWindowPos(main_viewport); AddUpdateViewport(NULL, IMGUI_VIEWPORT_DEFAULT_ID, main_viewport_platform_pos, main_viewport_platform_size, ImGuiViewportFlags_CanHostOtherWindows); + g.CurrentDpiScale = 0.0f; g.CurrentViewport = NULL; g.MouseViewport = NULL; for (int n = 0; n < g.Viewports.Size; n++) diff --git a/imgui_internal.h b/imgui_internal.h index 71d64469..b198612f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1079,6 +1079,7 @@ struct ImGuiContext // Viewports ImVector Viewports; // Active viewports (always 1+, and generally 1 unless multi-viewports are enabled). Each viewports hold their copy of ImDrawData. + float CurrentDpiScale; // == CurrentViewport->DpiScale ImGuiViewportP* CurrentViewport; // We track changes of viewport (happening in Begin) so we can call Platform_OnChangedViewport() ImGuiViewportP* MouseViewport; ImGuiViewportP* MouseLastHoveredViewport; // Last known viewport that was hovered by mouse (even if we are not hovering any viewport any more) + honoring the _NoInputs flag. @@ -1271,6 +1272,7 @@ struct ImGuiContext LastActiveId = 0; LastActiveIdTimer = 0.0f; + CurrentDpiScale = 0.0f; CurrentViewport = NULL; MouseViewport = MouseLastHoveredViewport = NULL; PlatformLastFocusedViewport = 0;