Skip to content

Commit da3a36e

Browse files
committed
Backport from docking branch: minor stuff.
Fixed software mouse cursor being rendered multiple times if Render() is called more than once.
1 parent 78c6435 commit da3a36e

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

docs/CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Other Changes:
7676
- Metrics: Added a node showing windows in submission order and showing the Begin() stack.
7777
- Misc: Added missing ImGuiMouseCursor_NotAllowed cursor for software rendering (when the
7878
io.MouseDrawCursor flag is enabled). (#4713) [@nobody-special666]
79+
- Misc: Fixed software mouse cursor being rendered multiple times if Render() is called more than once.
7980
- Misc: Fix MinGW DLL build issue (when IMGUI_API is defined). [@rokups]
8081
- CI: Add MinGW DLL build to test suite. [@rokups]
8182
- Backends: Vulkan: Call vkCmdSetScissor() at the end of render with a full-viewport to reduce

imgui.cpp

+19-10
Original file line numberDiff line numberDiff line change
@@ -3386,6 +3386,17 @@ bool ImGui::IsClippedEx(const ImRect& bb, ImGuiID id)
33863386
return false;
33873387
}
33883388

3389+
// This is also inlined in ItemAdd()
3390+
// Note: if ImGuiItemStatusFlags_HasDisplayRect is set, user needs to set window->DC.LastItemDisplayRect!
3391+
void ImGui::SetLastItemData(ImGuiID item_id, ImGuiItemFlags in_flags, ImGuiItemStatusFlags item_flags, const ImRect& item_rect)
3392+
{
3393+
ImGuiContext& g = *GImGui;
3394+
g.LastItemData.ID = item_id;
3395+
g.LastItemData.InFlags = in_flags;
3396+
g.LastItemData.StatusFlags = item_flags;
3397+
g.LastItemData.Rect = item_rect;
3398+
}
3399+
33893400
float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
33903401
{
33913402
if (wrap_pos_x < 0.0f)
@@ -4533,6 +4544,7 @@ void ImGui::Render()
45334544

45344545
if (g.FrameCountEnded != g.FrameCount)
45354546
EndFrame();
4547+
const bool first_render_of_frame = (g.FrameCountRendered != g.FrameCount);
45364548
g.FrameCountRendered = g.FrameCount;
45374549
g.IO.MetricsRenderWindows = 0;
45384550

@@ -4570,7 +4582,7 @@ void ImGui::Render()
45704582
viewport->DrawDataBuilder.FlattenIntoSingleLayer();
45714583

45724584
// Draw software mouse cursor if requested by io.MouseDrawCursor flag
4573-
if (g.IO.MouseDrawCursor)
4585+
if (g.IO.MouseDrawCursor && first_render_of_frame)
45744586
RenderMouseCursor(GetForegroundDrawList(viewport), g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48));
45754587

45764588
// Add foreground ImDrawList (for each active viewport)
@@ -5351,11 +5363,11 @@ ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window)
53515363
return size_final;
53525364
}
53535365

5354-
static ImGuiCol GetWindowBgColorIdxFromFlags(ImGuiWindowFlags flags)
5366+
static ImGuiCol GetWindowBgColorIdx(ImGuiWindow* window)
53555367
{
5356-
if (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup))
5368+
if (window->Flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup))
53575369
return ImGuiCol_PopupBg;
5358-
if (flags & ImGuiWindowFlags_ChildWindow)
5370+
if (window->Flags & ImGuiWindowFlags_ChildWindow)
53595371
return ImGuiCol_ChildBg;
53605372
return ImGuiCol_WindowBg;
53615373
}
@@ -5633,7 +5645,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar
56335645
// Window background
56345646
if (!(flags & ImGuiWindowFlags_NoBackground))
56355647
{
5636-
ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags));
5648+
ImU32 bg_col = GetColorU32(GetWindowBgColorIdx(window));
56375649
bool override_alpha = false;
56385650
float alpha = 1.0f;
56395651
if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasBgAlpha)
@@ -6386,10 +6398,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
63866398

63876399
// We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin().
63886400
// This is useful to allow creating context menus on title bar only, etc.
6389-
g.LastItemData.ID = window->MoveId;
6390-
g.LastItemData.InFlags = g.CurrentItemFlags;
6391-
g.LastItemData.StatusFlags = IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0;
6392-
g.LastItemData.Rect = title_bar_rect;
6401+
SetLastItemData(window->MoveId, g.CurrentItemFlags, IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0, title_bar_rect);
63936402

63946403
#ifdef IMGUI_ENABLE_TEST_ENGINE
63956404
if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
@@ -6837,8 +6846,8 @@ bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags)
68376846
return false;
68386847
if (flags & ImGuiFocusedFlags_AnyWindow)
68396848
return true;
6840-
IM_ASSERT(cur_window); // Not inside a Begin()/End()
68416849

6850+
IM_ASSERT(cur_window); // Not inside a Begin()/End()
68426851
const bool popup_hierarchy = (flags & ImGuiFocusedFlags_NoPopupHierarchy) == 0;
68436852
if (flags & ImGuiHoveredFlags_RootWindow)
68446853
cur_window = GetCombinedRootWindow(cur_window, popup_hierarchy);

imgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ enum ImGuiWindowFlags_
954954
ImGuiWindowFlags_NoMove = 1 << 2, // Disable user moving the window
955955
ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scrollbars (window can still scroll with mouse or programmatically)
956956
ImGuiWindowFlags_NoScrollWithMouse = 1 << 4, // Disable user vertically scrolling with mouse wheel. On child window, mouse wheel will be forwarded to the parent unless NoScrollbar is also set.
957-
ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it
957+
ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it. Also referred to as Window Menu Button (e.g. within a docking node).
958958
ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame
959959
ImGuiWindowFlags_NoBackground = 1 << 7, // Disable drawing background color (WindowBg, etc.) and outside border. Similar as using SetNextWindowBgAlpha(0.0f).
960960
ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file

imgui_internal.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,7 @@ struct ImGuiTabItem
21002100
};
21012101

21022102
// Storage for a tab bar (sizeof() 152 bytes)
2103-
struct ImGuiTabBar
2103+
struct IMGUI_API ImGuiTabBar
21042104
{
21052105
ImVector<ImGuiTabItem> Tabs;
21062106
ImGuiTabBarFlags Flags;
@@ -2499,6 +2499,7 @@ namespace ImGui
24992499
IMGUI_API bool ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb = NULL, ImGuiItemFlags extra_flags = 0);
25002500
IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id);
25012501
IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id);
2502+
IMGUI_API void SetLastItemData(ImGuiID item_id, ImGuiItemFlags in_flags, ImGuiItemStatusFlags status_flags, const ImRect& item_rect);
25022503
IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_w, float default_h);
25032504
IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
25042505
IMGUI_API void PushMultiItemsWidths(int components, float width_full);

0 commit comments

Comments
 (0)