MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / AcceptDragDropPayload

Method AcceptDragDropPayload

plugins/Cardinal/src/DearImGui/imgui.cpp:10688–10723  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10686}
10687
10688const 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
10725const ImGuiPayload* ImGui::GetDragDropPayload()
10726{

Callers

nothing calls this directly

Calls 3

ImVec2Function · 0.85
IsDataTypeMethod · 0.80
AddRectMethod · 0.80

Tested by

no test coverage detected