| 12552 | } |
| 12553 | |
| 12554 | const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags) |
| 12555 | { |
| 12556 | ImGuiContext& g = *GImGui; |
| 12557 | ImGuiWindow* window = g.CurrentWindow; |
| 12558 | ImGuiPayload& payload = g.DragDropPayload; |
| 12559 | IM_ASSERT(g.DragDropActive); // Not called between BeginDragDropTarget() and EndDragDropTarget() ? |
| 12560 | IM_ASSERT(payload.DataFrameCount != -1); // Forgot to call EndDragDropTarget() ? |
| 12561 | if (type != NULL && !payload.IsDataType(type)) |
| 12562 | return NULL; |
| 12563 | |
| 12564 | // Accept smallest drag target bounding box, this allows us to nest drag targets conveniently without ordering constraints. |
| 12565 | // NB: We currently accept NULL id as target. However, overlapping targets requires a unique ID to function! |
| 12566 | const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId); |
| 12567 | ImRect r = g.DragDropTargetRect; |
| 12568 | float r_surface = r.GetWidth() * r.GetHeight(); |
| 12569 | if (r_surface > g.DragDropAcceptIdCurrRectSurface) |
| 12570 | return NULL; |
| 12571 | |
| 12572 | g.DragDropAcceptFlags = flags; |
| 12573 | g.DragDropAcceptIdCurr = g.DragDropTargetId; |
| 12574 | g.DragDropAcceptIdCurrRectSurface = r_surface; |
| 12575 | //IMGUI_DEBUG_LOG("AcceptDragDropPayload(): %08X: accept\n", g.DragDropTargetId); |
| 12576 | |
| 12577 | // Render default drop visuals |
| 12578 | payload.Preview = was_accepted_previously; |
| 12579 | flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that live for 1 frame) |
| 12580 | if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview) |
| 12581 | 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); |
| 12582 | |
| 12583 | g.DragDropAcceptFrameCount = g.FrameCount; |
| 12584 | 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() |
| 12585 | if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery)) |
| 12586 | return NULL; |
| 12587 | |
| 12588 | //IMGUI_DEBUG_LOG("AcceptDragDropPayload(): %08X: return payload\n", g.DragDropTargetId); |
| 12589 | return &payload; |
| 12590 | } |
| 12591 | |
| 12592 | // FIXME-DRAGDROP: Settle on a proper default visuals for drop target. |
| 12593 | void ImGui::RenderDragDropTargetRect(const ImRect& bb) |
nothing calls this directly
no test coverage detected