mirror of
https://github.com/xemu-project/imgui.git
synced 2024-11-30 05:30:34 +00:00
Internals: Extracted code out of EndFrame() into UpdateMouseMovingWindowEndFrame()
This commit is contained in:
parent
b3469fa94b
commit
237109caa5
99
imgui.cpp
99
imgui.cpp
@ -2969,7 +2969,7 @@ void ImGui::StartMouseMovingWindow(ImGuiWindow* window)
|
|||||||
|
|
||||||
// Handle mouse moving window
|
// Handle mouse moving window
|
||||||
// Note: moving window with the navigation keys (Square + d-pad / CTRL+TAB + Arrows) are processed in NavUpdateWindowing()
|
// Note: moving window with the navigation keys (Square + d-pad / CTRL+TAB + Arrows) are processed in NavUpdateWindowing()
|
||||||
void ImGui::UpdateMouseMovingWindow()
|
void ImGui::UpdateMouseMovingWindowNewFrame()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
if (g.MovingWindow != NULL)
|
if (g.MovingWindow != NULL)
|
||||||
@ -3007,6 +3007,56 @@ void ImGui::UpdateMouseMovingWindow()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initiate moving window, handle left-click and right-click focus
|
||||||
|
void ImGui::UpdateMouseMovingWindowEndFrame()
|
||||||
|
{
|
||||||
|
// Initiate moving window
|
||||||
|
ImGuiContext& g = *GImGui;
|
||||||
|
if (g.ActiveId != 0 || g.HoveredId != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Unless we just made a window/popup appear
|
||||||
|
if (g.NavWindow && g.NavWindow->Appearing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Click to focus window and start moving (after we're done with all our widgets)
|
||||||
|
if (g.IO.MouseClicked[0])
|
||||||
|
{
|
||||||
|
if (g.HoveredRootWindow != NULL)
|
||||||
|
{
|
||||||
|
StartMouseMovingWindow(g.HoveredWindow);
|
||||||
|
if (g.IO.ConfigWindowsMoveFromTitleBarOnly && !(g.HoveredRootWindow->Flags & ImGuiWindowFlags_NoTitleBar))
|
||||||
|
if (!g.HoveredRootWindow->TitleBarRect().Contains(g.IO.MouseClickedPos[0]))
|
||||||
|
g.MovingWindow = NULL;
|
||||||
|
}
|
||||||
|
else if (g.NavWindow != NULL && GetFrontMostPopupModal() == NULL)
|
||||||
|
{
|
||||||
|
FocusWindow(NULL); // Clicking on void disable focus
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// With right mouse button we close popups without changing focus
|
||||||
|
// (The left mouse button path calls FocusWindow which will lead NewFrame->ClosePopupsOverWindow to trigger)
|
||||||
|
if (g.IO.MouseClicked[1])
|
||||||
|
{
|
||||||
|
// Find the top-most window between HoveredWindow and the front most Modal Window.
|
||||||
|
// This is where we can trim the popup stack.
|
||||||
|
ImGuiWindow* modal = GetFrontMostPopupModal();
|
||||||
|
bool hovered_window_above_modal = false;
|
||||||
|
if (modal == NULL)
|
||||||
|
hovered_window_above_modal = true;
|
||||||
|
for (int i = g.Windows.Size - 1; i >= 0 && hovered_window_above_modal == false; i--)
|
||||||
|
{
|
||||||
|
ImGuiWindow* window = g.Windows[i];
|
||||||
|
if (window == modal)
|
||||||
|
break;
|
||||||
|
if (window == g.HoveredWindow)
|
||||||
|
hovered_window_above_modal = true;
|
||||||
|
}
|
||||||
|
ClosePopupsOverWindow(hovered_window_above_modal ? g.HoveredWindow : modal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool IsWindowActiveAndVisible(ImGuiWindow* window)
|
static bool IsWindowActiveAndVisible(ImGuiWindow* window)
|
||||||
{
|
{
|
||||||
return (window->Active) && (!window->Hidden);
|
return (window->Active) && (!window->Hidden);
|
||||||
@ -3298,7 +3348,7 @@ void ImGui::NewFrame()
|
|||||||
g.IO.Framerate = (g.FramerateSecPerFrameAccum > 0.0f) ? (1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame))) : FLT_MAX;
|
g.IO.Framerate = (g.FramerateSecPerFrameAccum > 0.0f) ? (1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame))) : FLT_MAX;
|
||||||
|
|
||||||
// Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering)
|
// Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering)
|
||||||
UpdateMouseMovingWindow();
|
UpdateMouseMovingWindowNewFrame();
|
||||||
UpdateHoveredWindowAndCaptureFlags();
|
UpdateHoveredWindowAndCaptureFlags();
|
||||||
|
|
||||||
// Background darkening/whitening
|
// Background darkening/whitening
|
||||||
@ -3635,49 +3685,8 @@ void ImGui::EndFrame()
|
|||||||
g.FrameScopeActive = false;
|
g.FrameScopeActive = false;
|
||||||
g.FrameCountEnded = g.FrameCount;
|
g.FrameCountEnded = g.FrameCount;
|
||||||
|
|
||||||
// Initiate moving window
|
// Initiate moving window + handle left-click and right-click focus
|
||||||
if (g.ActiveId == 0 && g.HoveredId == 0)
|
UpdateMouseMovingWindowEndFrame();
|
||||||
{
|
|
||||||
if (!g.NavWindow || !g.NavWindow->Appearing) // Unless we just made a window/popup appear
|
|
||||||
{
|
|
||||||
// Click to focus window and start moving (after we're done with all our widgets)
|
|
||||||
if (g.IO.MouseClicked[0])
|
|
||||||
{
|
|
||||||
if (g.HoveredRootWindow != NULL)
|
|
||||||
{
|
|
||||||
StartMouseMovingWindow(g.HoveredWindow);
|
|
||||||
if (g.IO.ConfigWindowsMoveFromTitleBarOnly && !(g.HoveredRootWindow->Flags & ImGuiWindowFlags_NoTitleBar))
|
|
||||||
if (!g.HoveredRootWindow->TitleBarRect().Contains(g.IO.MouseClickedPos[0]))
|
|
||||||
g.MovingWindow = NULL;
|
|
||||||
}
|
|
||||||
else if (g.NavWindow != NULL && GetFrontMostPopupModal() == NULL)
|
|
||||||
{
|
|
||||||
FocusWindow(NULL); // Clicking on void disable focus
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// With right mouse button we close popups without changing focus
|
|
||||||
// (The left mouse button path calls FocusWindow which will lead NewFrame->ClosePopupsOverWindow to trigger)
|
|
||||||
if (g.IO.MouseClicked[1])
|
|
||||||
{
|
|
||||||
// Find the top-most window between HoveredWindow and the front most Modal Window.
|
|
||||||
// This is where we can trim the popup stack.
|
|
||||||
ImGuiWindow* modal = GetFrontMostPopupModal();
|
|
||||||
bool hovered_window_above_modal = false;
|
|
||||||
if (modal == NULL)
|
|
||||||
hovered_window_above_modal = true;
|
|
||||||
for (int i = g.Windows.Size - 1; i >= 0 && hovered_window_above_modal == false; i--)
|
|
||||||
{
|
|
||||||
ImGuiWindow* window = g.Windows[i];
|
|
||||||
if (window == modal)
|
|
||||||
break;
|
|
||||||
if (window == g.HoveredWindow)
|
|
||||||
hovered_window_above_modal = true;
|
|
||||||
}
|
|
||||||
ClosePopupsOverWindow(hovered_window_above_modal ? g.HoveredWindow : modal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort the window list so that all child windows are after their parent
|
// Sort the window list so that all child windows are after their parent
|
||||||
// We cannot do that on FocusWindow() because childs may not exist yet
|
// We cannot do that on FocusWindow() because childs may not exist yet
|
||||||
|
@ -1261,7 +1261,8 @@ namespace ImGui
|
|||||||
// NewFrame
|
// NewFrame
|
||||||
IMGUI_API void UpdateHoveredWindowAndCaptureFlags();
|
IMGUI_API void UpdateHoveredWindowAndCaptureFlags();
|
||||||
IMGUI_API void StartMouseMovingWindow(ImGuiWindow* window);
|
IMGUI_API void StartMouseMovingWindow(ImGuiWindow* window);
|
||||||
IMGUI_API void UpdateMouseMovingWindow();
|
IMGUI_API void UpdateMouseMovingWindowNewFrame();
|
||||||
|
IMGUI_API void UpdateMouseMovingWindowEndFrame();
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
IMGUI_API void MarkIniSettingsDirty();
|
IMGUI_API void MarkIniSettingsDirty();
|
||||||
|
Loading…
Reference in New Issue
Block a user