MCPcopy Create free account
hub / github.com/VictorGordan/opengl-tutorials / BeginDragDropTarget

Method BeginDragDropTarget

ImGUI GLFW Tutorial/imgui/imgui.cpp:9971–9996  ·  view source on GitHub ↗

We don't use BeginDragDropTargetCustom() and duplicate its code because: 1) we use LastItemRectHoveredRect which handles items that pushes a temporarily clip rectangle in their code. Calling BeginDragDropTargetCustom(LastItemRect) would not handle them. 2) and it's faster. as this code may be very frequently called, we want to early out as fast as we can. Also note how the HoveredWindow test is po

Source from the content-addressed store, hash-verified

9969// 2) and it's faster. as this code may be very frequently called, we want to early out as fast as we can.
9970// Also note how the HoveredWindow test is positioned differently in both functions (in both functions we optimize for the cheapest early out case)
9971bool ImGui::BeginDragDropTarget()
9972{
9973 ImGuiContext& g = *GImGui;
9974 if (!g.DragDropActive)
9975 return false;
9976
9977 ImGuiWindow* window = g.CurrentWindow;
9978 if (!(window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect))
9979 return false;
9980 ImGuiWindow* hovered_window = g.HoveredWindowUnderMovingWindow;
9981 if (hovered_window == NULL || window->RootWindow != hovered_window->RootWindow)
9982 return false;
9983
9984 const ImRect& display_rect = (window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? window->DC.LastItemDisplayRect : window->DC.LastItemRect;
9985 ImGuiID id = window->DC.LastItemId;
9986 if (id == 0)
9987 id = window->GetIDFromRectangle(display_rect);
9988 if (g.DragDropPayload.SourceId == id)
9989 return false;
9990
9991 IM_ASSERT(g.DragDropWithinTarget == false);
9992 g.DragDropTargetRect = display_rect;
9993 g.DragDropTargetId = id;
9994 g.DragDropWithinTarget = true;
9995 return true;
9996}
9997
9998bool ImGui::IsDragDropPayloadBeingAccepted()
9999{

Callers

nothing calls this directly

Calls 1

GetIDFromRectangleMethod · 0.45

Tested by

no test coverage detected