From a4c1e537b0cb2540535357d880e46f63b38c134f Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Wed, 5 Oct 2022 23:49:41 -0400 Subject: graph edits; arch rework --- my_imgui_internal_widgets.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'my_imgui_internal_widgets.cpp') 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. -- cgit v1.2.3