| 15776 | } |
| 15777 | |
| 15778 | const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags) |
| 15779 | { |
| 15780 | ImGuiContext& g = *GImGui; |
| 15781 | ImGuiPayload& payload = g.DragDropPayload; |
| 15782 | IM_ASSERT(g.DragDropActive); // Not called between BeginDragDropTarget() and EndDragDropTarget() ? |
| 15783 | IM_ASSERT(payload.DataFrameCount != -1); // Forgot to call EndDragDropTarget() ? |
| 15784 | if (type != NULL && !payload.IsDataType(type)) |
| 15785 | return NULL; |
| 15786 | |
| 15787 | // Accept smallest drag target bounding box, this allows us to nest drag targets conveniently without ordering constraints. |
| 15788 | // NB: We currently accept NULL id as target. However, overlapping targets requires a unique ID to function! |
| 15789 | const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId); |
| 15790 | ImRect r = g.DragDropTargetRect; |
| 15791 | float r_surface = r.GetWidth() * r.GetHeight(); |
| 15792 | if (r_surface > g.DragDropAcceptIdCurrRectSurface) |
| 15793 | return NULL; |
| 15794 | |
| 15795 | g.DragDropAcceptFlagsCurr = flags; |
| 15796 | g.DragDropAcceptIdCurr = g.DragDropTargetId; |
| 15797 | g.DragDropAcceptIdCurrRectSurface = r_surface; |
| 15798 | //IMGUI_DEBUG_LOG("AcceptDragDropPayload(): %08X: accept\n", g.DragDropTargetId); |
| 15799 | |
| 15800 | // Render default drop visuals |
| 15801 | payload.Preview = was_accepted_previously; |
| 15802 | flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that live for 1 frame) |
| 15803 | const bool draw_target_rect = payload.Preview && !(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); |
| 15804 | if (draw_target_rect && g.DragDropTargetFullViewport != 0) |
| 15805 | { |
| 15806 | ImGuiViewport* viewport = FindViewportByID(g.DragDropTargetFullViewport); |
| 15807 | IM_ASSERT(viewport != NULL); |
| 15808 | ImRect bb = g.DragDropTargetRect; |
| 15809 | bb.Expand(-3.5f); |
| 15810 | RenderDragDropTargetRectEx(GetForegroundDrawList(viewport), bb); |
| 15811 | } |
| 15812 | else if (draw_target_rect) |
| 15813 | { |
| 15814 | RenderDragDropTargetRectForItem(r); |
| 15815 | } |
| 15816 | |
| 15817 | g.DragDropAcceptFrameCount = g.FrameCount; |
| 15818 | if ((g.DragDropSourceFlags & ImGuiDragDropFlags_SourceExtern) && g.DragDropMouseButton == -1) |
| 15819 | payload.Delivery = was_accepted_previously && (g.DragDropSourceFrameCount < g.FrameCount); |
| 15820 | else |
| 15821 | 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() |
| 15822 | if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery)) |
| 15823 | return NULL; |
| 15824 | |
| 15825 | if (payload.Delivery) |
| 15826 | IMGUI_DEBUG_LOG_ACTIVEID("[dragdrop] AcceptDragDropPayload(): 0x%08X: payload delivery\n", g.DragDropTargetId); |
| 15827 | return &payload; |
| 15828 | } |
| 15829 | |
| 15830 | // FIXME-STYLE FIXME-DRAGDROP: Settle on a proper default visuals for drop target. |
| 15831 | void ImGui::RenderDragDropTargetRectForItem(const ImRect& bb) |
nothing calls this directly
no test coverage detected