summaryrefslogtreecommitdiff
path: root/my_imgui_internal_widgets.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'my_imgui_internal_widgets.cpp')
-rw-r--r--my_imgui_internal_widgets.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/my_imgui_internal_widgets.cpp b/my_imgui_internal_widgets.cpp
index d398ca1..1c16b65 100644
--- a/my_imgui_internal_widgets.cpp
+++ b/my_imgui_internal_widgets.cpp
@@ -1,13 +1,41 @@
#include "my_imgui_internal_widgets.h"
-
#include "imgui.h"
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include "imgui_internal.h"
+// In the regular call (GetMouseDragDelta) after the threshold is passed for
+// the first time, it returns true on every delta change even if you call
+// ResetMouseDragDelta, which makes routines like changing the frame number
+// every time the mouse is dragged past a certain distance not work how you'd
+// expect. This function uses the actual mouse delta instead of the stored
+// "max" value.
+ImVec2 ImGui::GetLocalMouseDragDelta(ImGuiMouseButton button, float lock_threshold)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[button]) : ImVec2(0.0f, 0.0f);
+ if (lock_threshold < 0.0f)
+ lock_threshold = g.IO.MouseDragThreshold;
+ if (g.IO.MouseDown[button] || g.IO.MouseReleased[button])
+ if (ImLengthSqr(delta_from_click_pos) >= lock_threshold * lock_threshold)
+ if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MouseClickedPos[button]))
+ return g.IO.MousePos - g.IO.MouseClickedPos[button];
+ return ImVec2(0.0f, 0.0f);
+}
+
+// To make the above scenario work we also have to be able to subtract from the
+// delta; simply resetting it will cause misalignment from the mouse.
+void ImGui::SetLocalMouseDragDelta(ImGuiMouseButton button, ImVec2 DeltaOffset)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ g.IO.MouseClickedPos[button] += DeltaOffset;
+}
+
// A modded version of ScalarSlider allowing for the minimum and maximum parts
// of the slider to be draggable by two other buttons. p_mid is from range -1
// to 1, and s_min and max are from 0-1.