mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-24 13:42:03 +08:00
Internals: removed HoveredRootWindow, tweak IsWindowHovered().
This commit is contained in:
parent
f5bc5e8630
commit
fdebb2e093
27
imgui.cpp
27
imgui.cpp
@ -3557,7 +3557,7 @@ void ImGui::UpdateMouseMovingWindowEndFrame()
|
|||||||
{
|
{
|
||||||
// Handle the edge case of a popup being closed while clicking in its empty space.
|
// Handle the edge case of a popup being closed while clicking in its empty space.
|
||||||
// If we try to focus it, FocusWindow() > ClosePopupsOverWindow() will accidentally close any parent popups because they are not linked together any more.
|
// If we try to focus it, FocusWindow() > ClosePopupsOverWindow() will accidentally close any parent popups because they are not linked together any more.
|
||||||
ImGuiWindow* root_window = g.HoveredRootWindow;
|
ImGuiWindow* root_window = g.HoveredWindow ? g.HoveredWindow->RootWindow : NULL;
|
||||||
const bool is_closed_popup = root_window && (root_window->Flags & ImGuiWindowFlags_Popup) && !IsPopupOpen(root_window->PopupId, ImGuiPopupFlags_AnyPopupLevel);
|
const bool is_closed_popup = root_window && (root_window->Flags & ImGuiWindowFlags_Popup) && !IsPopupOpen(root_window->PopupId, ImGuiPopupFlags_AnyPopupLevel);
|
||||||
|
|
||||||
if (root_window != NULL && !is_closed_popup)
|
if (root_window != NULL && !is_closed_popup)
|
||||||
@ -3794,7 +3794,7 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags()
|
|||||||
|
|
||||||
// Modal windows prevents mouse from hovering behind them.
|
// Modal windows prevents mouse from hovering behind them.
|
||||||
ImGuiWindow* modal_window = GetTopMostPopupModal();
|
ImGuiWindow* modal_window = GetTopMostPopupModal();
|
||||||
if (modal_window && g.HoveredRootWindow && !IsWindowChildOf(g.HoveredRootWindow, modal_window))
|
if (modal_window && g.HoveredWindow && !IsWindowChildOf(g.HoveredWindow->RootWindow, modal_window))
|
||||||
clear_hovered_windows = true;
|
clear_hovered_windows = true;
|
||||||
|
|
||||||
// Disabled mouse?
|
// Disabled mouse?
|
||||||
@ -3822,7 +3822,7 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags()
|
|||||||
clear_hovered_windows = true;
|
clear_hovered_windows = true;
|
||||||
|
|
||||||
if (clear_hovered_windows)
|
if (clear_hovered_windows)
|
||||||
g.HoveredWindow = g.HoveredRootWindow = g.HoveredWindowUnderMovingWindow = NULL;
|
g.HoveredWindow = g.HoveredWindowUnderMovingWindow = NULL;
|
||||||
|
|
||||||
// Update io.WantCaptureMouse for the user application (true = dispatch mouse info to imgui, false = dispatch mouse info to Dear ImGui + app)
|
// Update io.WantCaptureMouse for the user application (true = dispatch mouse info to imgui, false = dispatch mouse info to Dear ImGui + app)
|
||||||
if (g.WantCaptureMouseNextFrame != -1)
|
if (g.WantCaptureMouseNextFrame != -1)
|
||||||
@ -4146,7 +4146,7 @@ void ImGui::Shutdown(ImGuiContext* context)
|
|||||||
g.CurrentWindowStack.clear();
|
g.CurrentWindowStack.clear();
|
||||||
g.WindowsById.Clear();
|
g.WindowsById.Clear();
|
||||||
g.NavWindow = NULL;
|
g.NavWindow = NULL;
|
||||||
g.HoveredWindow = g.HoveredRootWindow = g.HoveredWindowUnderMovingWindow = NULL;
|
g.HoveredWindow = g.HoveredWindowUnderMovingWindow = NULL;
|
||||||
g.ActiveIdWindow = g.ActiveIdPreviousFrameWindow = NULL;
|
g.ActiveIdWindow = g.ActiveIdPreviousFrameWindow = NULL;
|
||||||
g.MovingWindow = NULL;
|
g.MovingWindow = NULL;
|
||||||
g.ColorStack.clear();
|
g.ColorStack.clear();
|
||||||
@ -4550,7 +4550,6 @@ static void FindHoveredWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
g.HoveredWindow = hovered_window;
|
g.HoveredWindow = hovered_window;
|
||||||
g.HoveredRootWindow = g.HoveredWindow ? g.HoveredWindow->RootWindow : NULL;
|
|
||||||
g.HoveredWindowUnderMovingWindow = hovered_window_ignoring_moving_window;
|
g.HoveredWindowUnderMovingWindow = hovered_window_ignoring_moving_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6560,30 +6559,28 @@ bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags)
|
|||||||
{
|
{
|
||||||
IM_ASSERT((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0); // Flags not supported by this function
|
IM_ASSERT((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0); // Flags not supported by this function
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
|
||||||
if (flags & ImGuiHoveredFlags_AnyWindow)
|
|
||||||
{
|
|
||||||
if (g.HoveredWindow == NULL)
|
if (g.HoveredWindow == NULL)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
else
|
if ((flags & ImGuiHoveredFlags_AnyWindow) == 0)
|
||||||
{
|
{
|
||||||
|
ImGuiWindow* window = g.CurrentWindow;
|
||||||
switch (flags & (ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows))
|
switch (flags & (ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows))
|
||||||
{
|
{
|
||||||
case ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows:
|
case ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows:
|
||||||
if (g.HoveredRootWindow != g.CurrentWindow->RootWindow)
|
if (g.HoveredWindow->RootWindow != window->RootWindow)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case ImGuiHoveredFlags_RootWindow:
|
case ImGuiHoveredFlags_RootWindow:
|
||||||
if (g.HoveredWindow != g.CurrentWindow->RootWindow)
|
if (g.HoveredWindow != window->RootWindow)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case ImGuiHoveredFlags_ChildWindows:
|
case ImGuiHoveredFlags_ChildWindows:
|
||||||
if (g.HoveredWindow == NULL || !IsWindowChildOf(g.HoveredWindow, g.CurrentWindow))
|
if (!IsWindowChildOf(g.HoveredWindow, window))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (g.HoveredWindow != g.CurrentWindow)
|
if (g.HoveredWindow != window)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -11047,7 +11044,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
Text("WINDOWING");
|
Text("WINDOWING");
|
||||||
Indent();
|
Indent();
|
||||||
Text("HoveredWindow: '%s'", g.HoveredWindow ? g.HoveredWindow->Name : "NULL");
|
Text("HoveredWindow: '%s'", g.HoveredWindow ? g.HoveredWindow->Name : "NULL");
|
||||||
Text("HoveredRootWindow: '%s'", g.HoveredRootWindow ? g.HoveredRootWindow->Name : "NULL");
|
Text("HoveredWindow->Root: '%s'", g.HoveredWindow ? g.HoveredWindow->RootWindow->Name : "NULL");
|
||||||
Text("HoveredWindowUnderMovingWindow: '%s'", g.HoveredWindowUnderMovingWindow ? g.HoveredWindowUnderMovingWindow->Name : "NULL");
|
Text("HoveredWindowUnderMovingWindow: '%s'", g.HoveredWindowUnderMovingWindow ? g.HoveredWindowUnderMovingWindow->Name : "NULL");
|
||||||
Text("MovingWindow: '%s'", g.MovingWindow ? g.MovingWindow->Name : "NULL");
|
Text("MovingWindow: '%s'", g.MovingWindow ? g.MovingWindow->Name : "NULL");
|
||||||
Unindent();
|
Unindent();
|
||||||
|
@ -1312,7 +1312,6 @@ struct ImGuiContext
|
|||||||
int WindowsActiveCount; // Number of unique windows submitted by frame
|
int WindowsActiveCount; // Number of unique windows submitted by frame
|
||||||
ImGuiWindow* CurrentWindow; // Window being drawn into
|
ImGuiWindow* CurrentWindow; // Window being drawn into
|
||||||
ImGuiWindow* HoveredWindow; // Window the mouse is hovering. Will typically catch mouse inputs.
|
ImGuiWindow* HoveredWindow; // Window the mouse is hovering. Will typically catch mouse inputs.
|
||||||
ImGuiWindow* HoveredRootWindow; // == HoveredWindow ? HoveredWindow->RootWindow : NULL, merely a shortcut to avoid null test in some situation.
|
|
||||||
ImGuiWindow* HoveredWindowUnderMovingWindow; // Hovered window ignoring MovingWindow. Only set if MovingWindow is set.
|
ImGuiWindow* HoveredWindowUnderMovingWindow; // Hovered window ignoring MovingWindow. Only set if MovingWindow is set.
|
||||||
ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actual window that is moved is generally MovingWindow->RootWindow.
|
ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actual window that is moved is generally MovingWindow->RootWindow.
|
||||||
ImGuiWindow* WheelingWindow; // Track the window we started mouse-wheeling on. Until a timer elapse or mouse has moved, generally keep scrolling the same window even if during the course of scrolling the mouse ends up hovering a child window.
|
ImGuiWindow* WheelingWindow; // Track the window we started mouse-wheeling on. Until a timer elapse or mouse has moved, generally keep scrolling the same window even if during the course of scrolling the mouse ends up hovering a child window.
|
||||||
@ -1543,7 +1542,6 @@ struct ImGuiContext
|
|||||||
WindowsActiveCount = 0;
|
WindowsActiveCount = 0;
|
||||||
CurrentWindow = NULL;
|
CurrentWindow = NULL;
|
||||||
HoveredWindow = NULL;
|
HoveredWindow = NULL;
|
||||||
HoveredRootWindow = NULL;
|
|
||||||
HoveredWindowUnderMovingWindow = NULL;
|
HoveredWindowUnderMovingWindow = NULL;
|
||||||
MovingWindow = NULL;
|
MovingWindow = NULL;
|
||||||
WheelingWindow = NULL;
|
WheelingWindow = NULL;
|
||||||
|
@ -500,7 +500,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
|
|||||||
flags |= ImGuiButtonFlags_PressedOnDefault_;
|
flags |= ImGuiButtonFlags_PressedOnDefault_;
|
||||||
|
|
||||||
ImGuiWindow* backup_hovered_window = g.HoveredWindow;
|
ImGuiWindow* backup_hovered_window = g.HoveredWindow;
|
||||||
const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredRootWindow == window;
|
const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredWindow && g.HoveredWindow->RootWindow == window;
|
||||||
if (flatten_hovered_children)
|
if (flatten_hovered_children)
|
||||||
g.HoveredWindow = window;
|
g.HoveredWindow = window;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user