From e1a103b251f219d567c60f8cffda100a057523c1 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 22 Dec 2017 13:41:41 +0100 Subject: [PATCH] Drag and Drop: Disable tracking mouse button ownership when an external drag source is active, to make it easier to achieve drag and drop over multiple OS windows. (#143) --- imgui.cpp | 5 +++-- imgui_demo.cpp | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 943b63ec..81a37d7a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2456,8 +2456,9 @@ void ImGui::NewFrame() g.OsImePosRequest = ImVec2(1.0f, 1.0f); // OS Input Method Editor showing on top-left of our window by default // If mouse was first clicked outside of ImGui bounds we also cancel out hovering. - // FIXME: For patterns of drag and drop between "application" and "imgui" we may need to rework/remove this test (first committed 311c0ca9 on 2015/02) - if (!mouse_avail_to_imgui) + // FIXME: For patterns of drag and drop across OS windows, we may need to rework/remove this test (first committed 311c0ca9 on 2015/02) + bool mouse_dragging_extern_payload = g.DragDropActive && (g.DragDropSourceFlags & ImGuiDragDropFlags_SourceExtern) != 0; + if (!mouse_avail_to_imgui && !mouse_dragging_extern_payload) g.HoveredWindow = g.HoveredRootWindow = NULL; // Scale & Scrolling diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 4f2705db..fb0cff59 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1734,7 +1734,10 @@ void ImGui::ShowTestWindow(bool* p_open) if (ImGui::TreeNode("Keyboard & Mouse State")) { - ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); + if (ImGui::IsMousePosValid()) + ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); + else + ImGui::Text("Mouse pos: "); ImGui::Text("Mouse down:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (io.MouseDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("b%d (%.02f secs)", i, io.MouseDownDuration[i]); } ImGui::Text("Mouse clicked:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseClicked(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); } ImGui::Text("Mouse dbl-clicked:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseDoubleClicked(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); }