From 0e04dfbad7208e453290d27f2ef704fdac050a4b Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 2 Jun 2015 20:57:29 +0100 Subject: [PATCH] Added IsWindowHovered() helper. --- imgui.cpp | 19 +++++++++++++------ imgui.h | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3ff73f010..3a895f695 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4310,36 +4310,43 @@ const char* ImGui::GetStyleColName(ImGuiCol idx) return "Unknown"; } +bool ImGui::IsWindowHovered() +{ + ImGuiState& g = *GImGui; + return g.HoveredWindow == g.CurrentWindow; +} + bool ImGui::IsWindowFocused() { ImGuiState& g = *GImGui; - ImGuiWindow* window = GetCurrentWindow(); - return g.FocusedWindow == window; + return g.FocusedWindow == g.CurrentWindow; } bool ImGui::IsRootWindowFocused() { ImGuiState& g = *GImGui; - ImGuiWindow* root_window = GetCurrentWindow()->RootWindow; + ImGuiWindow* root_window = g.CurrentWindow->RootWindow; return g.FocusedWindow == root_window; } bool ImGui::IsRootWindowOrAnyChildFocused() { ImGuiState& g = *GImGui; - ImGuiWindow* root_window = GetCurrentWindow()->RootWindow; + ImGuiWindow* root_window = g.CurrentWindow->RootWindow; return g.FocusedWindow && g.FocusedWindow->RootWindow == root_window; } float ImGui::GetWindowWidth() { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; return window->Size.x; } ImVec2 ImGui::GetWindowPos() { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; return window->Pos; } diff --git a/imgui.h b/imgui.h index 859bfc613..93cf7937e 100644 --- a/imgui.h +++ b/imgui.h @@ -344,6 +344,7 @@ namespace ImGui IMGUI_API ImVec2 GetItemRectMin(); // get bounding rect of last item in screen space IMGUI_API ImVec2 GetItemRectMax(); // " IMGUI_API ImVec2 GetItemRectSize(); // " + IMGUI_API bool IsWindowHovered(); IMGUI_API bool IsWindowFocused(); // is current window focused (differentiate child windows from each others) IMGUI_API bool IsRootWindowFocused(); // is current root window focused (top parent window in case of child windows) IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused