mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-19 06:26:35 +00:00
Viewport: Avoid unnecessary reapplying platform pos/size every frame. (#2205) + Fix GLFW ImGui_ImplGlfw_CreateWindow() from not applying position immediately. Clear LastNameHash properly (bug already fixed in Docking branch)
This commit is contained in:
parent
cae4d020dc
commit
862781b195
@ -409,6 +409,7 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
|
||||
data->Window = glfwCreateWindow((int)viewport->Size.x, (int)viewport->Size.y, "No Title Yet", NULL, share_window);
|
||||
data->WindowOwned = true;
|
||||
viewport->PlatformHandle = (void*)data->Window;
|
||||
glfwSetWindowPos(data->Window, (int)viewport->Pos.x, (int)viewport->Pos.y);
|
||||
|
||||
// Install callbacks for secondary viewports
|
||||
glfwSetMouseButtonCallback(data->Window, ImGui_ImplGlfw_MouseButtonCallback);
|
||||
|
17
imgui.cpp
17
imgui.cpp
@ -7280,9 +7280,9 @@ static void ImGui::UpdateViewports()
|
||||
// Apply Position and Size (from Platform Window to ImGui) if requested.
|
||||
// We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities.
|
||||
if (viewport->PlatformRequestMove)
|
||||
viewport->Pos = g.PlatformIO.Platform_GetWindowPos(viewport);
|
||||
viewport->Pos = viewport->LastPlatformPos = g.PlatformIO.Platform_GetWindowPos(viewport);
|
||||
if (viewport->PlatformRequestResize)
|
||||
viewport->Size = g.PlatformIO.Platform_GetWindowSize(viewport);
|
||||
viewport->Size = viewport->LastPlatformSize = g.PlatformIO.Platform_GetWindowSize(viewport);
|
||||
|
||||
// Translate imgui windows when a Host Viewport has been moved
|
||||
ImVec2 delta = viewport->Pos - viewport->LastPos;
|
||||
@ -7576,18 +7576,21 @@ void ImGui::UpdatePlatformWindows()
|
||||
g.PlatformIO.Platform_CreateWindow(viewport);
|
||||
if (g.PlatformIO.Renderer_CreateWindow != NULL)
|
||||
g.PlatformIO.Renderer_CreateWindow(viewport);
|
||||
viewport->RendererLastSize = viewport->Size;
|
||||
viewport->LastNameHash = 0;
|
||||
viewport->LastPlatformPos = viewport->LastPlatformSize = ImVec2(FLT_MAX, FLT_MAX); // By clearing those we'll enforce a call to Platform_SetWindowPos/Platform_SetWindowSize before Platform_ShowWindow
|
||||
viewport->LastRendererSize = viewport->Size;
|
||||
viewport->CreatedPlatformWindow = true;
|
||||
}
|
||||
|
||||
// Apply Position and Size (from ImGui to Platform/Renderer back-ends)
|
||||
if (!viewport->PlatformRequestMove)
|
||||
if ((viewport->LastPlatformPos.x != viewport->Pos.x || viewport->LastPlatformPos.y != viewport->Pos.y) && !viewport->PlatformRequestMove)
|
||||
g.PlatformIO.Platform_SetWindowPos(viewport, viewport->Pos);
|
||||
if (!viewport->PlatformRequestResize)
|
||||
if ((viewport->LastPlatformSize.x != viewport->Size.x || viewport->LastPlatformSize.y != viewport->Size.y) && !viewport->PlatformRequestResize)
|
||||
g.PlatformIO.Platform_SetWindowSize(viewport, viewport->Size);
|
||||
if (g.PlatformIO.Renderer_SetWindowSize && (viewport->RendererLastSize.x != viewport->Size.x || viewport->RendererLastSize.y != viewport->Size.y))
|
||||
if ((viewport->LastRendererSize.x != viewport->Size.x || viewport->LastRendererSize.y != viewport->Size.y) && g.PlatformIO.Renderer_SetWindowSize)
|
||||
g.PlatformIO.Renderer_SetWindowSize(viewport, viewport->Size);
|
||||
viewport->RendererLastSize = viewport->Size;
|
||||
viewport->LastPlatformPos = viewport->Pos;
|
||||
viewport->LastPlatformSize = viewport->LastRendererSize = viewport->Size;
|
||||
|
||||
// Update title bar (if it changed)
|
||||
if (ImGuiWindow* window_for_title = viewport->Window)
|
||||
|
@ -611,9 +611,11 @@ struct ImGuiViewportP : public ImGuiViewport
|
||||
ImDrawList* OverlayDrawList; // For convenience, a draw list we can render to that's always rendered last (we use it to draw software mouse cursor when io.MouseDrawCursor is set)
|
||||
ImDrawData DrawDataP;
|
||||
ImDrawDataBuilder DrawDataBuilder;
|
||||
ImVec2 RendererLastSize;
|
||||
ImVec2 LastPlatformPos;
|
||||
ImVec2 LastPlatformSize;
|
||||
ImVec2 LastRendererSize;
|
||||
|
||||
ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameOverlayDrawList = LastFrontMostStampCount = -1; LastNameHash = 0; CreatedPlatformWindow = false; Alpha = LastAlpha = 1.0f; PlatformMonitor = INT_MIN; Window = NULL; OverlayDrawList = NULL; RendererLastSize = ImVec2(-1.0f,-1.0f); }
|
||||
ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameOverlayDrawList = LastFrontMostStampCount = -1; LastNameHash = 0; CreatedPlatformWindow = false; Alpha = LastAlpha = 1.0f; PlatformMonitor = INT_MIN; Window = NULL; OverlayDrawList = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); }
|
||||
~ImGuiViewportP() { if (OverlayDrawList) IM_DELETE(OverlayDrawList); }
|
||||
ImRect GetRect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); }
|
||||
ImVec2 GetCenter() const{ return ImVec2(Pos.x + Size.x * 0.5f, Pos.y + Size.y * 0.5f); }
|
||||
|
Loading…
Reference in New Issue
Block a user