From befe02559ac3de15d1ba3a41d0939696cf6330a0 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 1 May 2016 12:14:07 +0200 Subject: [PATCH] Added IsRootWindowOrAnyChildHovered() helper (#615) --- imgui.cpp | 12 ++++++++---- imgui.h | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c6c4f04a..d15f3b01 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4579,15 +4579,19 @@ bool ImGui::IsWindowFocused() bool ImGui::IsRootWindowFocused() { ImGuiState& g = *GImGui; - ImGuiWindow* root_window = g.CurrentWindow->RootWindow; - return g.FocusedWindow == root_window; + return g.FocusedWindow == g.CurrentWindow->RootWindow; } bool ImGui::IsRootWindowOrAnyChildFocused() { ImGuiState& g = *GImGui; - ImGuiWindow* root_window = g.CurrentWindow->RootWindow; - return g.FocusedWindow && g.FocusedWindow->RootWindow == root_window; + return g.FocusedWindow && g.FocusedWindow->RootWindow == g.CurrentWindow->RootWindow; +} + +bool ImGui::IsRootWindowOrAnyChildHovered() +{ + ImGuiState& g = *GImGui; + return g.HoveredRootWindow && (g.HoveredRootWindow == g.CurrentWindow->RootWindow) && IsWindowContentHoverable(g.HoveredRootWindow); } float ImGui::GetWindowWidth() diff --git a/imgui.h b/imgui.h index e093116e..a451cea7 100644 --- a/imgui.h +++ b/imgui.h @@ -385,8 +385,9 @@ namespace ImGui IMGUI_API void SetItemAllowOverlap(); // allow last item to be overlapped by a subsequent item. sometimes useful with invisible buttons, selectables, etc. to catch unused area. IMGUI_API bool IsWindowHovered(); // is current window hovered and hoverable (not blocked by a popup) (differentiate child windows from each others) IMGUI_API bool IsWindowFocused(); // is current window focused - IMGUI_API bool IsRootWindowFocused(); // is current root window focused (top parent window in case of child windows) + IMGUI_API bool IsRootWindowFocused(); // is current root window focused (root = top-most parent of a child, otherwise self) IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused + IMGUI_API bool IsRootWindowOrAnyChildHovered(); // is current root window or any of its child (including current window) hovered and hoverable (not blocked by a popup) IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle of given size starting from cursor pos is visible (not clipped). to perform coarse clipping on user's side (as an optimization) IMGUI_API bool IsPosHoveringAnyWindow(const ImVec2& pos); // is given position hovering any active imgui window IMGUI_API float GetTime();