mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
DragBehavior: Moving code around, in what should be a no-op, to simplify upcoming Nav diff (#323, #180)
This commit is contained in:
parent
c816e6c742
commit
eb405ab375
25
imgui.cpp
25
imgui.cpp
@ -6769,32 +6769,33 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
|
||||
g.DragLastMouseDelta = ImVec2(0.f, 0.f);
|
||||
}
|
||||
|
||||
if (v_speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX)
|
||||
v_speed = (v_max - v_min) * g.DragSpeedDefaultRatio;
|
||||
|
||||
float v_cur = g.DragCurrentValue;
|
||||
const ImVec2 mouse_drag_delta = GetMouseDragDelta(0, 1.0f);
|
||||
if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f)
|
||||
{
|
||||
float speed = v_speed;
|
||||
if (speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX)
|
||||
speed = (v_max - v_min) * g.DragSpeedDefaultRatio;
|
||||
if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f)
|
||||
speed = speed * g.DragSpeedScaleFast;
|
||||
if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
|
||||
speed = speed * g.DragSpeedScaleSlow;
|
||||
float adjust_delta = mouse_drag_delta.x - g.DragLastMouseDelta.x;
|
||||
if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f)
|
||||
adjust_delta *= g.DragSpeedScaleFast;
|
||||
if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
|
||||
adjust_delta *= g.DragSpeedScaleSlow;
|
||||
adjust_delta *= v_speed;
|
||||
|
||||
float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed;
|
||||
if (fabsf(adjust_delta) > 0.0f)
|
||||
{
|
||||
if (fabsf(power - 1.0f) > 0.001f)
|
||||
{
|
||||
// Logarithmic curve on both side of 0.0
|
||||
float v0_abs = v_cur >= 0.0f ? v_cur : -v_cur;
|
||||
float v0_sign = v_cur >= 0.0f ? 1.0f : -1.0f;
|
||||
float v1 = powf(v0_abs, 1.0f / power) + (delta * v0_sign);
|
||||
float v1 = powf(v0_abs, 1.0f / power) + (adjust_delta * v0_sign);
|
||||
float v1_abs = v1 >= 0.0f ? v1 : -v1;
|
||||
float v1_sign = v1 >= 0.0f ? 1.0f : -1.0f; // Crossed sign line
|
||||
v_cur = powf(v1_abs, power) * v0_sign * v1_sign; // Reapply sign
|
||||
}
|
||||
else
|
||||
{
|
||||
v_cur += delta;
|
||||
v_cur += adjust_delta;
|
||||
}
|
||||
g.DragLastMouseDelta.x = mouse_drag_delta.x;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user