From e10d648a2808df340537c1f2127b7a723b39f118 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 18 Mar 2015 10:41:46 +0000 Subject: [PATCH] Added ImGui::GetItemActiveDragDelta() helpers for drag operations --- imgui.cpp | 11 +++++++++++ imgui.h | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index d8b71f39..cfd85bb7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2551,6 +2551,17 @@ bool ImGui::IsAnyItemActive() return g.ActiveId != 0; } +ImVec2 ImGui::GetItemActiveDragDelta() +{ + if (ImGui::IsItemActive()) + { + ImGuiState& g = *GImGui; + if (g.IO.MouseDown[0]) + return g.IO.MousePos - g.IO.MouseClickedPos[0]; // Assume we can only get active with left-mouse button (at the moment). + } + return ImVec2(0.0f, 0.0f); +} + ImVec2 ImGui::GetItemRectMin() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index 08a3a585..874858f2 100644 --- a/imgui.h +++ b/imgui.h @@ -354,12 +354,13 @@ namespace ImGui IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse? IMGUI_API bool IsItemActive(); // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false) IMGUI_API bool IsAnyItemActive(); // - IMGUI_API bool IsWindowFocused(); // is current window focused (differentiate child windows from each others) - IMGUI_API bool IsRootWindowFocused(); // is current root window focused - IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused + IMGUI_API ImVec2 GetItemActiveDragDelta(); // mouse delta from the time the item first got active IMGUI_API ImVec2 GetItemRectMin(); // get bounding rect of last item IMGUI_API ImVec2 GetItemRectMax(); // " IMGUI_API ImVec2 GetItemRectSize(); // " + IMGUI_API bool IsWindowFocused(); // is current window focused (differentiate child windows from each others) + IMGUI_API bool IsRootWindowFocused(); // is current root window focused + IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused IMGUI_API bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimization) IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry IMGUI_API bool IsMouseClicked(int button, bool repeat = false);