From 344d48be31e1fae98c9f7cb6d96b6d77d29abec0 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 27 Sep 2017 16:49:25 +0200 Subject: [PATCH] IsItemHovered(), ItemAdd(): Fixed seemingly unnecessary comparaison of root windows, makes IsItemHovered() more consistent with internal IsHovered(). Original test was added in 6e99688fa74b3de5694a8e021619cc1ade51ee03 should not have been using RootWindow in the first place. The difference between public-facing and internal versions would only be noticeable with overlapped child windows, which doesn't really happen anyway --- imgui.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 25d463fd..2bce31de 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1948,16 +1948,14 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id) //if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG] // Set up for public-facing IsItemHovered(). We store the result in DC.LastItemHoveredAndUsable. - // This is roughly matching the behavior of internal IsHovered() + // This is roughly matching the behavior of internal-facing IsHovered() // - we allow hovering to be true when ActiveId==window->MoveID, so that clicking on non-interactive items such as a Text() item still returns true with IsItemHovered()) // FIXME-OPT: Consider moving this code to IsItemHovered() so it's only evaluated if users needs it. - if (g.HoveredRootWindow == window->RootWindow) - { + if (g.HoveredWindow == window) if (IsMouseHoveringRect(bb.Min, bb.Max)) if (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdAllowOverlap || (g.ActiveId == window->MoveId)) if (IsWindowContentHoverable(window)) window->DC.LastItemHoveredAndUsable = true; - } return true; } @@ -1982,9 +1980,10 @@ bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs) { ImGuiWindow* window = GetCurrentWindowRead(); if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow)) - if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap) && IsMouseHoveringRect(bb.Min, bb.Max)) - if (IsWindowContentHoverable(g.HoveredRootWindow)) - return true; + if (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap) + if (IsMouseHoveringRect(bb.Min, bb.Max)) + if (IsWindowContentHoverable(g.HoveredRootWindow)) + return true; } return false; }