mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 06:06:35 +00:00
Nav: DragBehavior: Tweaks (to take the noise out of the next commit).
This commit is contained in:
parent
e5e3cc617e
commit
4932303e62
132
imgui.cpp
132
imgui.cpp
@ -8852,73 +8852,73 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
|
||||
// Process clicking on the drag
|
||||
if (g.ActiveId == id)
|
||||
{
|
||||
if (g.IO.MouseDown[0] || g.NavActivateDownId == id)
|
||||
{
|
||||
if (g.ActiveIdIsJustActivated)
|
||||
{
|
||||
// Lock current value on click
|
||||
g.DragCurrentValue = *v;
|
||||
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);
|
||||
float adjust_delta = 0.0f;
|
||||
if (g.ActiveIdSource == ImGuiInputSource_Mouse && IsMousePosValid())
|
||||
{
|
||||
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;
|
||||
g.DragLastMouseDelta.x = mouse_drag_delta.x;
|
||||
}
|
||||
if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
||||
{
|
||||
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x;
|
||||
if (v_min < v_max && ((v_cur >= v_max && adjust_delta > 0.0f) || (v_cur <= v_min && adjust_delta < 0.0f))) // This is to avoid applying the saturation when already past the limits
|
||||
adjust_delta = 0.0f;
|
||||
v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
|
||||
}
|
||||
adjust_delta *= v_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) + (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 += adjust_delta;
|
||||
}
|
||||
|
||||
// Clamp
|
||||
if (v_min < v_max)
|
||||
v_cur = ImClamp(v_cur, v_min, v_max);
|
||||
g.DragCurrentValue = v_cur;
|
||||
}
|
||||
|
||||
// Round to user desired precision, then apply
|
||||
v_cur = RoundScalar(v_cur, decimal_precision);
|
||||
if (*v != v_cur)
|
||||
{
|
||||
*v = v_cur;
|
||||
value_changed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g.ActiveIdSource == ImGuiInputSource_Mouse && !g.IO.MouseDown[0])
|
||||
ClearActiveID();
|
||||
else if (g.ActiveIdSource == ImGuiInputSource_Nav && g.NavActivateDownId != id)
|
||||
ClearActiveID();
|
||||
}
|
||||
if (g.ActiveId == id)
|
||||
{
|
||||
if (g.ActiveIdIsJustActivated)
|
||||
{
|
||||
// Lock current value on click
|
||||
g.DragCurrentValue = *v;
|
||||
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);
|
||||
float adjust_delta = 0.0f;
|
||||
if (g.ActiveIdSource == ImGuiInputSource_Mouse && IsMousePosValid())
|
||||
{
|
||||
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;
|
||||
g.DragLastMouseDelta.x = mouse_drag_delta.x;
|
||||
}
|
||||
if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
||||
{
|
||||
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x;
|
||||
if (v_min < v_max && ((v_cur >= v_max && adjust_delta > 0.0f) || (v_cur <= v_min && adjust_delta < 0.0f))) // This is to avoid applying the saturation when already past the limits
|
||||
adjust_delta = 0.0f;
|
||||
v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
|
||||
}
|
||||
adjust_delta *= v_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) + (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 += adjust_delta;
|
||||
}
|
||||
|
||||
// Clamp
|
||||
if (v_min < v_max)
|
||||
v_cur = ImClamp(v_cur, v_min, v_max);
|
||||
g.DragCurrentValue = v_cur;
|
||||
}
|
||||
|
||||
// Round to user desired precision, then apply
|
||||
v_cur = RoundScalar(v_cur, decimal_precision);
|
||||
if (*v != v_cur)
|
||||
{
|
||||
*v = v_cur;
|
||||
value_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user