Skip to content

Commit

Permalink
Internal: Added two missing ImVec2 operators for consistency. Split u…
Browse files Browse the repository at this point in the history
…p DragDropWithinSourceOrTarget

ImVec2 *= ImVec2 to match  ImVec2 * ImVec2, likewise with /
  • Loading branch information
ocornut committed Mar 12, 2020
1 parent b016f1a commit 1d5612a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
27 changes: 14 additions & 13 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3846,7 +3846,8 @@ void ImGui::NewFrame()
g.DragDropAcceptIdPrev = g.DragDropAcceptIdCurr;
g.DragDropAcceptIdCurr = 0;
g.DragDropAcceptIdCurrRectSurface = FLT_MAX;
g.DragDropWithinSourceOrTarget = false;
g.DragDropWithinSource = false;
g.DragDropWithinTarget = false;

// Update keyboard input state
memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration));
Expand Down Expand Up @@ -4237,9 +4238,9 @@ void ImGui::EndFrame()
// Drag and Drop: Fallback for source tooltip. This is not ideal but better than nothing.
if (g.DragDropActive && g.DragDropSourceFrameCount < g.FrameCount)
{
g.DragDropWithinSourceOrTarget = true;
g.DragDropWithinSource = true;
SetTooltip("...");
g.DragDropWithinSourceOrTarget = false;
g.DragDropWithinSource = false;
}

// End frame
Expand Down Expand Up @@ -7459,7 +7460,7 @@ void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags toolt
{
ImGuiContext& g = *GImGui;

if (g.DragDropWithinSourceOrTarget)
if (g.DragDropWithinSource || g.DragDropWithinTarget)
{
// The default tooltip position is a little offset to give space to see the context menu (it's also clamped within the current viewport/monitor)
// In the context of a dragging tooltip we try to reduce that offset and we enforce following the cursor.
Expand Down Expand Up @@ -9119,7 +9120,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
g.DragDropMouseButton = mouse_button;
}
g.DragDropSourceFrameCount = g.FrameCount;
g.DragDropWithinSourceOrTarget = true;
g.DragDropWithinSource = true;

if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
{
Expand All @@ -9146,15 +9147,15 @@ void ImGui::EndDragDropSource()
{
ImGuiContext& g = *GImGui;
IM_ASSERT(g.DragDropActive);
IM_ASSERT(g.DragDropWithinSourceOrTarget && "Not after a BeginDragDropSource()?");
IM_ASSERT(g.DragDropWithinSource && "Not after a BeginDragDropSource()?");

if (!(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
EndTooltip();

// Discard the drag if have not called SetDragDropPayload()
if (g.DragDropPayload.DataFrameCount == -1)
ClearDragDrop();
g.DragDropWithinSourceOrTarget = false;
g.DragDropWithinSource = false;
}

// Use 'cond' to choose to submit payload on drag start or every frame
Expand Down Expand Up @@ -9216,10 +9217,10 @@ bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id)
if (window->SkipItems)
return false;

IM_ASSERT(g.DragDropWithinSourceOrTarget == false);
IM_ASSERT(g.DragDropWithinTarget == false);
g.DragDropTargetRect = bb;
g.DragDropTargetId = id;
g.DragDropWithinSourceOrTarget = true;
g.DragDropWithinTarget = true;
return true;
}

Expand All @@ -9246,10 +9247,10 @@ bool ImGui::BeginDragDropTarget()
if (g.DragDropPayload.SourceId == id)
return false;

IM_ASSERT(g.DragDropWithinSourceOrTarget == false);
IM_ASSERT(g.DragDropWithinTarget == false);
g.DragDropTargetRect = display_rect;
g.DragDropTargetId = id;
g.DragDropWithinSourceOrTarget = true;
g.DragDropWithinTarget = true;
return true;
}

Expand Down Expand Up @@ -9313,8 +9314,8 @@ void ImGui::EndDragDropTarget()
{
ImGuiContext& g = *GImGui;
IM_ASSERT(g.DragDropActive);
IM_ASSERT(g.DragDropWithinSourceOrTarget);
g.DragDropWithinSourceOrTarget = false;
IM_ASSERT(g.DragDropWithinTarget);
g.DragDropWithinTarget = false;
}

//-----------------------------------------------------------------------------
Expand Down
11 changes: 7 additions & 4 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,12 @@ static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs)
static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
static inline ImVec2& operator*=(ImVec2& lhs, const ImVec2& rhs) { lhs.x *= rhs.x; lhs.y *= rhs.y; return lhs; }
static inline ImVec2& operator/=(ImVec2& lhs, const ImVec2& rhs) { lhs.x /= rhs.x; lhs.y /= rhs.y; return lhs; }
static inline ImVec4 operator+(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x+rhs.x, lhs.y+rhs.y, lhs.z+rhs.z, lhs.w+rhs.w); }
static inline ImVec4 operator-(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z, lhs.w-rhs.w); }
static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs) { return ImVec4(lhs.x*rhs.x, lhs.y*rhs.y, lhs.z*rhs.z, lhs.w*rhs.w); }
Expand Down Expand Up @@ -1128,7 +1130,8 @@ struct ImGuiContext

// Drag and Drop
bool DragDropActive;
bool DragDropWithinSourceOrTarget; // Set when within a BeginDragDropXXX/EndDragDropXXX block.
bool DragDropWithinSource; // Set when within a BeginDragDropXXX/EndDragDropXXX block for a drag source.
bool DragDropWithinTarget; // Set when within a BeginDragDropXXX/EndDragDropXXX block for a drag target.
ImGuiDragDropFlags DragDropSourceFlags;
int DragDropSourceFrameCount;
int DragDropMouseButton;
Expand Down Expand Up @@ -1284,7 +1287,7 @@ struct ImGuiContext
ForegroundDrawList._OwnerName = "##Foreground"; // Give it a name for debugging
MouseCursor = ImGuiMouseCursor_Arrow;

DragDropActive = DragDropWithinSourceOrTarget = false;
DragDropActive = DragDropWithinSource = DragDropWithinTarget = false;
DragDropSourceFlags = ImGuiDragDropFlags_None;
DragDropSourceFrameCount = -1;
DragDropMouseButton = -1;
Expand Down

0 comments on commit 1d5612a

Please sign in to comment.