mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 05:01:05 +01:00 
			
		
		
		
	Viewport: Removed unnecessary fields (now that the coordinate system is consistent accross viewports): MouseRefPrevViewport, MouseClickedPosViewportId. (#1542)
This commit is contained in:
		
							
								
								
									
										3
									
								
								TODO.txt
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								TODO.txt
									
									
									
									
									
								
							| @@ -258,8 +258,7 @@ 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) | ||||
|  | ||||
|  - viewport: popup/tooltip glitches when appearing near the monitor limits (e.g. opening a menu). | ||||
|  - viewport: platform: introduce getfocus/setfocus api, so e.g. focus flags can be honored, imgui-side ctrl-tab can focus os window, OS alt-tab can focus imgui window etc. | ||||
|  - 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.  | ||||
|  - viewport: need to clarify how to use GetMousePos() from a user point of view. | ||||
|   | ||||
| @@ -117,9 +117,9 @@ static bool ImGui_ImplWin32_UpdateMouseCursor() | ||||
| } | ||||
|  | ||||
| // This code supports multiple OS Windows mapped into different ImGui viewports,  | ||||
| // So it is a little more complicated than your typical binding code (which only needs to set io.MousePos in your WM_MOUSEMOVE handler) | ||||
| // So it is a little more complicated than your typical single-viewport binding code (which only needs to set io.MousePos from the WM_MOUSEMOVE handler) | ||||
| // This is what imgui needs from the back-end to support multiple windows: | ||||
| // - io.MousePos               = mouse position (e.g. io.MousePos == viewport->Pos when we are on the upper-left of our viewport) | ||||
| // - io.MousePos               = mouse position in absolute coordinate (e.g. io.MousePos == ImVec2(0,0) when it is on the upper-left of the primary monitor) | ||||
| // - io.MousePosViewport       = viewport which mouse position is based from (generally the focused/active/capturing viewport) | ||||
| // - io.MouseHoveredWindow     = viewport which mouse is hovering, **regardless of it being the active/focused window**, **regardless of another window holding mouse captured**. [Optional] | ||||
| // This function overwrite the value of io.MousePos normally updated by the WM_MOUSEMOVE handler.  | ||||
|   | ||||
							
								
								
									
										18
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								imgui.cpp
									
									
									
									
									
								
							| @@ -3452,7 +3452,6 @@ static void ImGui::UpdateViewports() | ||||
|     IM_ASSERT(g.PlatformIO.Viewports.Size <= g.Viewports.Size); | ||||
|  | ||||
|     // Update mouse reference viewport | ||||
|     g.MouseRefPrevViewport = g.MouseRefViewport; | ||||
|     g.MouseRefViewport = g.IO.MousePosViewport ? FindViewportByID(g.IO.MousePosViewport) : g.Viewports[0]; | ||||
|  | ||||
|     // Update main viewport with current platform position and size | ||||
| @@ -3480,8 +3479,7 @@ static void ImGui::UpdateViewports() | ||||
|  | ||||
|             // Destroy | ||||
|             if (viewport == g.MouseRefViewport)         g.MouseRefViewport = main_viewport; | ||||
|             if (viewport == g.MouseRefPrevViewport)     g.MouseRefPrevViewport = main_viewport; | ||||
|             if (viewport == g.MouseHoveredLastViewport) g.MouseHoveredLastViewport = NULL; | ||||
|             if (viewport == g.MouseLastHoveredViewport) g.MouseLastHoveredViewport = NULL; | ||||
|             IM_ASSERT(viewport->RendererUserData == NULL && viewport->PlatformUserData == NULL && viewport->PlatformHandle == NULL); | ||||
|             IM_ASSERT(g.PlatformIO.Viewports.contains(viewport) == false); | ||||
|             IM_DELETE(viewport); | ||||
| @@ -3531,7 +3529,7 @@ static void ImGui::UpdateViewports() | ||||
|  | ||||
|     if (!(g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)) | ||||
|     { | ||||
|         g.MouseRefViewport = g.MouseRefPrevViewport = main_viewport; | ||||
|         g.MouseRefViewport = main_viewport; | ||||
|         return; | ||||
|     } | ||||
|  | ||||
| @@ -3555,7 +3553,7 @@ static void ImGui::UpdateViewports() | ||||
|         viewport_hovered = FindViewportHoveredFromPlatformWindowStack(g.IO.MousePos); | ||||
|     } | ||||
|     if (viewport_hovered != NULL) | ||||
|         g.MouseHoveredLastViewport = viewport_hovered; | ||||
|         g.MouseLastHoveredViewport = viewport_hovered; | ||||
|  | ||||
|     // When dragging something, always refer to the last hovered viewport.  | ||||
|     // (So when we are between viewports, our dragged preview will tend to show in the last viewport even if we don't have tooltips in viewports) | ||||
| @@ -3564,7 +3562,7 @@ static void ImGui::UpdateViewports() | ||||
|     if (is_mouse_dragging_with_an_expected_destination || g.ActiveId == 0 || !ImGui::IsAnyMouseDown()) | ||||
|     { | ||||
|         if (is_mouse_dragging_with_an_expected_destination && viewport_hovered == NULL) | ||||
|             viewport_hovered = g.MouseHoveredLastViewport; | ||||
|             viewport_hovered = g.MouseLastHoveredViewport; | ||||
|         if (viewport_hovered != NULL && viewport_hovered != g.MouseRefViewport && !(viewport_hovered->Flags & ImGuiViewportFlags_NoInputs)) | ||||
|             g.MouseRefViewport = viewport_hovered; | ||||
|     } | ||||
| @@ -3722,7 +3720,7 @@ static void ImGui::UpdateMouseInputs() | ||||
|     ImGuiContext& g = *GImGui; | ||||
|  | ||||
|     // If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta | ||||
|     if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev) && g.MouseRefViewport == g.MouseRefPrevViewport) | ||||
|     if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev)) | ||||
|         g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev; | ||||
|     else | ||||
|         g.IO.MouseDelta = ImVec2(0.0f, 0.0f); | ||||
| @@ -3752,7 +3750,6 @@ static void ImGui::UpdateMouseInputs() | ||||
|             g.IO.MouseClickedPos[i] = g.IO.MousePos; | ||||
|             g.IO.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f); | ||||
|             g.IO.MouseDragMaxDistanceSqr[i] = 0.0f; | ||||
|             g.MouseClickedPosViewportId[i] = g.MouseRefViewport->ID; | ||||
|         } | ||||
|         else if (g.IO.MouseDown[i]) | ||||
|         { | ||||
| @@ -4198,7 +4195,7 @@ void ImGui::Shutdown(ImGuiContext* context) | ||||
|     g.FontStack.clear(); | ||||
|     g.OpenPopupStack.clear(); | ||||
|     g.CurrentPopupStack.clear(); | ||||
|     g.CurrentViewport = g.MouseRefViewport = g.MouseRefPrevViewport = g.MouseHoveredLastViewport = NULL; | ||||
|     g.CurrentViewport = g.MouseRefViewport = g.MouseLastHoveredViewport = NULL; | ||||
|     for (int i = 0; i < g.Viewports.Size; i++) | ||||
|         IM_DELETE(g.Viewports[i]); | ||||
|     g.Viewports.clear(); | ||||
| @@ -5297,8 +5294,7 @@ ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold) | ||||
|         lock_threshold = g.IO.MouseDragThreshold; | ||||
|     if (g.IO.MouseDown[button]) | ||||
|         if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold) | ||||
|             if (g.MouseRefViewport->ID == g.MouseClickedPosViewportId[button]) | ||||
|                 return g.IO.MousePos - g.IO.MouseClickedPos[button];     // Assume we can only get active with left-mouse button (at the moment). | ||||
|             return g.IO.MousePos - g.IO.MouseClickedPos[button];     // Assume we can only get active with left-mouse button (at the moment). | ||||
|     return ImVec2(0.0f, 0.0f); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -642,9 +642,7 @@ struct ImGuiContext | ||||
|     ImVector<ImGuiViewportP*> Viewports;                        // Active viewports (always 1+, and generally 1 unless multi-viewports are enabled). Each viewports hold their copy of ImDrawData.  | ||||
|     ImGuiViewportP*         CurrentViewport;                    // We track changes of viewport (happening in Begin) so we can call Platform_OnChangedViewport() | ||||
|     ImGuiViewportP*         MouseRefViewport; | ||||
|     ImGuiViewportP*         MouseRefPrevViewport; | ||||
|     ImGuiViewportP*         MouseHoveredLastViewport;           // Last viewport that was hovered by mouse (even if we are not hovering any viewport any more) | ||||
|     ImGuiID                 MouseClickedPosViewportId[5];       // For rarely used fields we only compare to, store viewport ID only so we don't have to clean dangling pointers | ||||
|     ImGuiViewportP*         MouseLastHoveredViewport;           // Last known viewport that was hovered by mouse (even if we are not hovering any viewport any more) | ||||
|     ImGuiID                 PlatformLastFocusedViewport;        // Record of last focused platform window/viewport, when this changes we stamp the viewport as front-most | ||||
|  | ||||
|     // Navigation data (for gamepad/keyboard) | ||||
| @@ -776,9 +774,7 @@ struct ImGuiContext | ||||
|         NextTreeNodeOpenCond = 0; | ||||
|  | ||||
|         CurrentViewport = NULL; | ||||
|         MouseRefViewport = NULL; | ||||
|         MouseRefPrevViewport = MouseHoveredLastViewport = NULL; | ||||
|         memset(MouseClickedPosViewportId, 0, sizeof(MouseClickedPosViewportId)); | ||||
|         MouseRefViewport = MouseLastHoveredViewport = NULL; | ||||
|         PlatformLastFocusedViewport = 0; | ||||
|  | ||||
|         NavWindow = NULL; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user