| 11984 | } |
| 11985 | |
| 11986 | const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags) |
| 11987 | { |
| 11988 | ImGuiContext& g = *GImGui; |
| 11989 | ImGuiWindow* window = g.CurrentWindow; |
| 11990 | ImGuiPayload& payload = g.DragDropPayload; |
| 11991 | IM_ASSERT(g.DragDropActive); // Not called between BeginDragDropTarget() and EndDragDropTarget() ? |
| 11992 | IM_ASSERT(payload.DataFrameCount != -1); // Forgot to call EndDragDropTarget() ? |
| 11993 | if (type != NULL && !payload.IsDataType(type)) |
| 11994 | return NULL; |
| 11995 | |
| 11996 | // Accept smallest drag target bounding box, this allows us to nest drag targets conveniently without ordering constraints. |
| 11997 | // NB: We currently accept NULL id as target. However, overlapping targets requires a unique ID to function! |
| 11998 | const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId); |
| 11999 | ImRect r = g.DragDropTargetRect; |
| 12000 | float r_surface = r.GetWidth() * r.GetHeight(); |
| 12001 | if (r_surface <= g.DragDropAcceptIdCurrRectSurface) |
| 12002 | { |
| 12003 | g.DragDropAcceptFlags = flags; |
| 12004 | g.DragDropAcceptIdCurr = g.DragDropTargetId; |
| 12005 | g.DragDropAcceptIdCurrRectSurface = r_surface; |
| 12006 | } |
| 12007 | |
| 12008 | // Render default drop visuals |
| 12009 | payload.Preview = was_accepted_previously; |
| 12010 | flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that live for 1 frame) |
| 12011 | if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview) |
| 12012 | window->DrawList->AddRect(r.Min - ImVec2(3.5f,3.5f), r.Max + ImVec2(3.5f, 3.5f), GetColorU32(ImGuiCol_DragDropTarget), 0.0f, 0, 2.0f); |
| 12013 | |
| 12014 | g.DragDropAcceptFrameCount = g.FrameCount; |
| 12015 | payload.Delivery = was_accepted_previously && !IsMouseDown(g.DragDropMouseButton); // For extern drag sources affecting os window focus, it's easier to just test !IsMouseDown() instead of IsMouseReleased() |
| 12016 | if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery)) |
| 12017 | return NULL; |
| 12018 | |
| 12019 | return &payload; |
| 12020 | } |
| 12021 | |
| 12022 | // FIXME-DRAGDROP: Settle on a proper default visuals for drop target. |
| 12023 | void ImGui::RenderDragDropTargetRect(const ImRect& bb) |
nothing calls this directly
no test coverage detected