Skip to content

Commit a63fbbc

Browse files
committed
Added ImGuiHoveredFlags_AnyWindow, ImGuiFocusedFlags_AnyWindow. Obsoleted IsAnyWindowHovered()/IsAnyWindowFocused() in favor of IsWindowHovered(ImGuiHoveredFlags_AnyWindow)/IsWindowFocused(ImGuiFocusedFlags_AnyWindow). Added to demo. (#1382)
1 parent 1eee107 commit a63fbbc

File tree

3 files changed

+54
-46
lines changed

3 files changed

+54
-46
lines changed

imgui.cpp

+34-32
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@
213213
Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
214214
Also read releases logs https://github.com/ocornut/imgui/releases for more details.
215215

216+
- 2018/01/11 (1.54) - obsoleted IsAnyWindowHovered() in favor of IsWindowHovered(ImGuiHoveredFlags_AnyWindow). Kept redirection function (will obsolete).
217+
- 2018/01/11 (1.54) - obsoleted IsAnyWindowFocused() in favor of IsWindowFocused(ImGuiFocusedFlags_AnyWindow). Kept redirection function (will obsolete).
216218
- 2018/01/03 (1.54) - renamed ImGuiSizeConstraintCallback to ImGuiSizeCallback, ImGuiSizeConstraintCallbackData to ImGuiSizeCallbackData.
217219
- 2017/12/29 (1.54) - removed CalcItemRectClosestPoint() which was weird and not really used by anyone except demo code. If you need it it's easy to replicate on your side.
218220
- 2017/12/24 (1.53) - renamed the emblematic ShowTestWindow() function to ShowDemoWindow(). Kept redirection function (will obsolete).
@@ -3417,18 +3419,6 @@ bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool c
34173419
return rect_for_touch.Contains(g.IO.MousePos);
34183420
}
34193421

3420-
bool ImGui::IsAnyWindowHovered()
3421-
{
3422-
ImGuiContext& g = *GImGui;
3423-
return g.HoveredWindow != NULL;
3424-
}
3425-
3426-
bool ImGui::IsAnyWindowFocused()
3427-
{
3428-
ImGuiContext& g = *GImGui;
3429-
return g.NavWindow != NULL;
3430-
}
3431-
34323422
static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
34333423
{
34343424
const int key_index = GImGui->IO.KeyMap[key];
@@ -3959,7 +3949,7 @@ bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button)
39593949
if (!str_id)
39603950
str_id = "void_context";
39613951
ImGuiID id = GImGui->CurrentWindow->GetID(str_id);
3962-
if (IsMouseReleased(mouse_button) && !IsAnyWindowHovered())
3952+
if (IsMouseReleased(mouse_button) && !IsWindowHovered(ImGuiHoveredFlags_AnyWindow))
39633953
OpenPopupEx(id);
39643954
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
39653955
}
@@ -5522,24 +5512,33 @@ bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags)
55225512
{
55235513
IM_ASSERT((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0); // Flags not supported by this function
55245514
ImGuiContext& g = *GImGui;
5525-
switch (flags & (ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows))
5515+
5516+
if (flags & ImGuiHoveredFlags_AnyWindow)
55265517
{
5527-
case ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows:
5528-
if (g.HoveredRootWindow != g.CurrentWindow->RootWindow)
5529-
return false;
5530-
break;
5531-
case ImGuiHoveredFlags_RootWindow:
5532-
if (g.HoveredWindow != g.CurrentWindow->RootWindow)
5533-
return false;
5534-
break;
5535-
case ImGuiHoveredFlags_ChildWindows:
5536-
if (g.HoveredWindow == NULL || !IsWindowChildOf(g.HoveredWindow, g.CurrentWindow))
5537-
return false;
5538-
break;
5539-
default:
5540-
if (g.HoveredWindow != g.CurrentWindow)
5518+
if (g.HoveredWindow == NULL)
55415519
return false;
5542-
break;
5520+
}
5521+
else
5522+
{
5523+
switch (flags & (ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows))
5524+
{
5525+
case ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows:
5526+
if (g.HoveredRootWindow != g.CurrentWindow->RootWindow)
5527+
return false;
5528+
break;
5529+
case ImGuiHoveredFlags_RootWindow:
5530+
if (g.HoveredWindow != g.CurrentWindow->RootWindow)
5531+
return false;
5532+
break;
5533+
case ImGuiHoveredFlags_ChildWindows:
5534+
if (g.HoveredWindow == NULL || !IsWindowChildOf(g.HoveredWindow, g.CurrentWindow))
5535+
return false;
5536+
break;
5537+
default:
5538+
if (g.HoveredWindow != g.CurrentWindow)
5539+
return false;
5540+
break;
5541+
}
55435542
}
55445543

55455544
if (!IsWindowContentHoverable(g.HoveredRootWindow, flags))
@@ -5555,16 +5554,19 @@ bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags)
55555554
ImGuiContext& g = *GImGui;
55565555
IM_ASSERT(g.CurrentWindow); // Not inside a Begin()/End()
55575556

5557+
if (flags & ImGuiFocusedFlags_AnyWindow)
5558+
return g.NavWindow != NULL;
5559+
55585560
switch (flags & (ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows))
55595561
{
55605562
case ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows:
5561-
return g.NavWindow && g.CurrentWindow->RootWindow == g.NavWindow->RootWindow;
5563+
return g.NavWindow && g.NavWindow->RootWindow == g.CurrentWindow->RootWindow;
55625564
case ImGuiFocusedFlags_RootWindow:
5563-
return g.CurrentWindow->RootWindow == g.NavWindow;
5565+
return g.NavWindow == g.CurrentWindow->RootWindow;
55645566
case ImGuiFocusedFlags_ChildWindows:
55655567
return g.NavWindow && IsWindowChildOf(g.NavWindow, g.CurrentWindow);
55665568
default:
5567-
return g.CurrentWindow == g.NavWindow;
5569+
return g.NavWindow == g.CurrentWindow;
55685570
}
55695571
}
55705572

imgui.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,6 @@ namespace ImGui
463463
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.
464464
IMGUI_API bool IsWindowFocused(ImGuiFocusedFlags flags = 0); // is current window focused? or its root/child, depending on flags. see flags for options.
465465
IMGUI_API bool IsWindowHovered(ImGuiHoveredFlags flags = 0); // is current window hovered (and typically: not blocked by a popup/modal)? see flags for options.
466-
IMGUI_API bool IsAnyWindowFocused();
467-
IMGUI_API bool IsAnyWindowHovered(); // is mouse hovering any visible window
468466
IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle (of given size, starting from cursor position) is visible / not clipped.
469467
IMGUI_API bool IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max); // test if rectangle (in screen space) is visible / not clipped. to perform coarse clipping on user's side.
470468
IMGUI_API float GetTime();
@@ -623,6 +621,7 @@ enum ImGuiFocusedFlags_
623621
{
624622
ImGuiFocusedFlags_ChildWindows = 1 << 0, // IsWindowFocused(): Return true if any children of the window is focused
625623
ImGuiFocusedFlags_RootWindow = 1 << 1, // IsWindowFocused(): Test from root window (top most parent of the current hierarchy)
624+
ImGuiFocusedFlags_AnyWindow = 1 << 2, // IsWindowFocused(): Return true if any window is focused
626625
ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows
627626
};
628627

@@ -632,10 +631,11 @@ enum ImGuiHoveredFlags_
632631
ImGuiHoveredFlags_Default = 0, // Return true if directly over the item/window, not obstructed by another window, not obstructed by an active popup or modal blocking inputs under them.
633632
ImGuiHoveredFlags_ChildWindows = 1 << 0, // IsWindowHovered() only: Return true if any children of the window is hovered
634633
ImGuiHoveredFlags_RootWindow = 1 << 1, // IsWindowHovered() only: Test from root window (top most parent of the current hierarchy)
635-
ImGuiHoveredFlags_AllowWhenBlockedByPopup = 1 << 2, // Return true even if a popup window is normally blocking access to this item/window
636-
//ImGuiHoveredFlags_AllowWhenBlockedByModal = 1 << 3, // Return true even if a modal popup window is normally blocking access to this item/window. FIXME-TODO: Unavailable yet.
637-
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 4, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
638-
ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 5, // Return true even if the position is overlapped by another window
634+
ImGuiHoveredFlags_AnyWindow = 1 << 2, // IsWindowHovered() only: Return true if any window is hovered
635+
ImGuiHoveredFlags_AllowWhenBlockedByPopup = 1 << 3, // Return true even if a popup window is normally blocking access to this item/window
636+
//ImGuiHoveredFlags_AllowWhenBlockedByModal = 1 << 4, // Return true even if a modal popup window is normally blocking access to this item/window. FIXME-TODO: Unavailable yet.
637+
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 5, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
638+
ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 6, // Return true even if the position is overlapped by another window
639639
ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped,
640640
ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows
641641
};
@@ -988,6 +988,8 @@ struct ImGuiIO
988988
namespace ImGui
989989
{
990990
// OBSOLETED in 1.54 (from Dec 2017)
991+
static bool IsAnyWindowFocused() { return IsWindowFocused(ImGuiFocusedFlags_AnyWindow); }
992+
static bool IsAnyWindowHovered() { return IsWindowHovered(ImGuiHoveredFlags_AnyWindow); }
991993
static inline ImVec2 CalcItemRectClosestPoint(const ImVec2& pos, bool on_edge = false, float outward = 0.f) { (void)on_edge; (void)outward; IM_ASSERT(0); return pos; }
992994
// OBSOLETED in 1.53 (between Oct 2017 and Dec 2017)
993995
static inline void ShowTestWindow() { return ShowDemoWindow(); }
@@ -996,13 +998,13 @@ namespace ImGui
996998
static inline void SetNextWindowContentWidth(float w) { SetNextWindowContentSize(ImVec2(w, 0.0f)); }
997999
// OBSOLETED in 1.52 (between Aug 2017 and Oct 2017)
9981000
bool Begin(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha_override = -1.0f, ImGuiWindowFlags flags = 0); // Use SetNextWindowSize() instead if you want to set a window size.
999-
static inline bool IsRootWindowOrAnyChildHovered() { return IsItemHovered(ImGuiHoveredFlags_RootAndChildWindows); } // Use flags directly!
1001+
static inline bool IsRootWindowOrAnyChildHovered() { return IsItemHovered(ImGuiHoveredFlags_RootAndChildWindows); }
10001002
static inline void AlignFirstTextHeightToWidgets() { AlignTextToFramePadding(); }
10011003
static inline void SetNextWindowPosCenter(ImGuiCond c=0) { ImGuiIO& io = GetIO(); SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), c, ImVec2(0.5f, 0.5f)); }
10021004
// OBSOLETED in 1.51 (between Jun 2017 and Aug 2017)
10031005
static inline bool IsItemHoveredRect() { return IsItemHovered(ImGuiHoveredFlags_RectOnly); }
10041006
static inline bool IsPosHoveringAnyWindow(const ImVec2&) { IM_ASSERT(0); return false; } // This was misleading and partly broken. You probably want to use the ImGui::GetIO().WantCaptureMouse flag instead.
1005-
static inline bool IsMouseHoveringAnyWindow() { return IsAnyWindowHovered(); }
1007+
static inline bool IsMouseHoveringAnyWindow() { return IsWindowHovered(ImGuiHoveredFlags_AnyWindow); }
10061008
static inline bool IsMouseHoveringWindow() { return IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); }
10071009
// OBSOLETED IN 1.49 (between Apr 2016 and May 2016)
10081010
static inline bool CollapsingHeader(const char* label, const char* str_id, bool framed = true, bool default_open = false) { (void)str_id; (void)framed; ImGuiTreeNodeFlags default_open_flags = 1 << 5; return CollapsingHeader(label, (default_open ? default_open_flags : 0)); }

imgui_demo.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -1871,11 +1871,13 @@ void ImGui::ShowDemoWindow(bool* p_open)
18711871
"IsWindowFocused() = %d\n"
18721872
"IsWindowFocused(_ChildWindows) = %d\n"
18731873
"IsWindowFocused(_ChildWindows|_RootWindow) = %d\n"
1874-
"IsWindowFocused(_RootWindow) = %d\n",
1874+
"IsWindowFocused(_RootWindow) = %d\n"
1875+
"IsWindowFocused(_AnyWindow) = %d\n",
18751876
ImGui::IsWindowFocused(),
1876-
ImGui::IsWindowFocused(ImGuiHoveredFlags_ChildWindows),
1877-
ImGui::IsWindowFocused(ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_RootWindow),
1878-
ImGui::IsWindowFocused(ImGuiHoveredFlags_RootWindow));
1877+
ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows),
1878+
ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_RootWindow),
1879+
ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow),
1880+
ImGui::IsWindowFocused(ImGuiFocusedFlags_AnyWindow));
18791881

18801882
// Testing IsWindowHovered() function with its various flags (note that the flags can be combined)
18811883
ImGui::BulletText(
@@ -1884,13 +1886,15 @@ void ImGui::ShowDemoWindow(bool* p_open)
18841886
"IsWindowHovered(_AllowWhenBlockedByActiveItem) = %d\n"
18851887
"IsWindowHovered(_ChildWindows) = %d\n"
18861888
"IsWindowHovered(_ChildWindows|_RootWindow) = %d\n"
1887-
"IsWindowHovered(_RootWindow) = %d\n",
1889+
"IsWindowHovered(_RootWindow) = %d\n"
1890+
"IsWindowHovered(_AnyWindow) = %d\n",
18881891
ImGui::IsWindowHovered(),
18891892
ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup),
18901893
ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem),
18911894
ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows),
18921895
ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_RootWindow),
1893-
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow));
1896+
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow),
1897+
ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow));
18941898

18951899
// Testing IsItemHovered() function (because BulletText is an item itself and that would affect the output of IsItemHovered, we pass all lines in a single items to shorten the code)
18961900
ImGui::Button("ITEM");

0 commit comments

Comments
 (0)