From d65c463a0f255c0b14558a10ee30447c35011c76 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Sun, 12 May 2024 10:52:10 +0200 Subject: [PATCH] fnShowResizeWidget: add invisible button (to disable window drag in this zone) --- src/immvision/internal/image.cpp | 14 ++++++++++++-- src_all_in_one/immvision/immvision.cpp | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/immvision/internal/image.cpp b/src/immvision/internal/image.cpp index 7b02404..6e17ac1 100644 --- a/src/immvision/internal/image.cpp +++ b/src/immvision/internal/image.cpp @@ -497,11 +497,21 @@ namespace ImmVision ImVec2 tl(br.x - size, br.y - size); ImRect zone(tl, br); - ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, ImGui::GetColorU32(ImGuiCol_ButtonHovered)); + + { + auto cursorPos = ImGui::GetCursorPos(); + ImGui::SetCursorPos(tl); + ImGui::InvisibleButton("##resize", zone.GetSize()); + ImGui::SetCursorPos(cursorPos); + } + + bool isMouseHoveringWidget = ImGui::IsMouseHoveringRect(zone.Min, zone.Max); + ImU32 color = isMouseHoveringWidget ? ImGui::GetColorU32(ImGuiCol_ButtonHovered) : ImGui::GetColorU32(ImGuiCol_Button); + ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, color); if (!cacheParams.IsResizing) { - if (ImGui::IsMouseHoveringRect(zone.Min, zone.Max) && ImGui::IsMouseDown(0)) + if (isMouseHoveringWidget && ImGui::IsMouseDown(0)) { ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNWSE); cacheParams.IsResizing = true; diff --git a/src_all_in_one/immvision/immvision.cpp b/src_all_in_one/immvision/immvision.cpp index 2206975..b4320b0 100644 --- a/src_all_in_one/immvision/immvision.cpp +++ b/src_all_in_one/immvision/immvision.cpp @@ -9955,11 +9955,21 @@ namespace ImmVision ImVec2 tl(br.x - size, br.y - size); ImRect zone(tl, br); - ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, ImGui::GetColorU32(ImGuiCol_ButtonHovered)); + + { + auto cursorPos = ImGui::GetCursorPos(); + ImGui::SetCursorPos(tl); + ImGui::InvisibleButton("##resize", zone.GetSize()); + ImGui::SetCursorPos(cursorPos); + } + + bool isMouseHoveringWidget = ImGui::IsMouseHoveringRect(zone.Min, zone.Max); + ImU32 color = isMouseHoveringWidget ? ImGui::GetColorU32(ImGuiCol_ButtonHovered) : ImGui::GetColorU32(ImGuiCol_Button); + ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, color); if (!cacheParams.IsResizing) { - if (ImGui::IsMouseHoveringRect(zone.Min, zone.Max) && ImGui::IsMouseDown(0)) + if (isMouseHoveringWidget && ImGui::IsMouseDown(0)) { ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNWSE); cacheParams.IsResizing = true;