| 10686 | } |
| 10687 | |
| 10688 | const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags) |
| 10689 | { |
| 10690 | ImGuiContext& g = *GImGui; |
| 10691 | ImGuiWindow* window = g.CurrentWindow; |
| 10692 | ImGuiPayload& payload = g.DragDropPayload; |
| 10693 | IM_ASSERT(g.DragDropActive); // Not called between BeginDragDropTarget() and EndDragDropTarget() ? |
| 10694 | IM_ASSERT(payload.DataFrameCount != -1); // Forgot to call EndDragDropTarget() ? |
| 10695 | if (type != NULL && !payload.IsDataType(type)) |
| 10696 | return NULL; |
| 10697 | |
| 10698 | // Accept smallest drag target bounding box, this allows us to nest drag targets conveniently without ordering constraints. |
| 10699 | // NB: We currently accept NULL id as target. However, overlapping targets requires a unique ID to function! |
| 10700 | const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId); |
| 10701 | ImRect r = g.DragDropTargetRect; |
| 10702 | float r_surface = r.GetWidth() * r.GetHeight(); |
| 10703 | if (r_surface <= g.DragDropAcceptIdCurrRectSurface) |
| 10704 | { |
| 10705 | g.DragDropAcceptFlags = flags; |
| 10706 | g.DragDropAcceptIdCurr = g.DragDropTargetId; |
| 10707 | g.DragDropAcceptIdCurrRectSurface = r_surface; |
| 10708 | } |
| 10709 | |
| 10710 | // Render default drop visuals |
| 10711 | // FIXME-DRAGDROP: Settle on a proper default visuals for drop target. |
| 10712 | payload.Preview = was_accepted_previously; |
| 10713 | flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that lives for 1 frame) |
| 10714 | if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview) |
| 10715 | 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); |
| 10716 | |
| 10717 | g.DragDropAcceptFrameCount = g.FrameCount; |
| 10718 | 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() |
| 10719 | if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery)) |
| 10720 | return NULL; |
| 10721 | |
| 10722 | return &payload; |
| 10723 | } |
| 10724 | |
| 10725 | const ImGuiPayload* ImGui::GetDragDropPayload() |
| 10726 | { |
nothing calls this directly
no test coverage detected