mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 12:12:28 +00:00
Improve the inspector easing editor
- Make it possible to drag a negative easing or an easing of 0 back to a positive value. - Clamp the value between -1000000 and 1000000 to avoid issues related to infinity. - Display more decimals for numbers closer to 0, less for large numbers. - Display trailing zeroes in decimals to avoid flickering when dragging. This closes #18712 and closes #22079.
This commit is contained in:
parent
241e709462
commit
028de11db8
@ -946,14 +946,11 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float val = get_edited_object()->get(get_edited_property());
|
float val = get_edited_object()->get(get_edited_property());
|
||||||
if (val == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bool sg = val < 0;
|
bool sg = val < 0;
|
||||||
val = Math::absf(val);
|
val = Math::absf(val);
|
||||||
|
|
||||||
val = Math::log(val) / Math::log((float)2.0);
|
val = Math::log(val) / Math::log((float)2.0);
|
||||||
//logspace
|
// Logarithmic space.
|
||||||
val += rel * 0.05;
|
val += rel * 0.05;
|
||||||
|
|
||||||
val = Math::pow(2.0f, val);
|
val = Math::pow(2.0f, val);
|
||||||
@ -961,6 +958,16 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
|
|||||||
val = -val;
|
val = -val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 0 is a singularity, but both positive and negative values
|
||||||
|
// are otherwise allowed. Enforce 0+ as workaround.
|
||||||
|
if (Math::is_zero_approx(val)) {
|
||||||
|
val = 0.00001;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit to a reasonable value to prevent the curve going into infinity,
|
||||||
|
// which can cause crashes and other issues.
|
||||||
|
val = CLAMP(val, -1'000'000, 1'000'000);
|
||||||
|
|
||||||
emit_changed(get_edited_property(), val);
|
emit_changed(get_edited_property(), val);
|
||||||
easing_draw->update();
|
easing_draw->update();
|
||||||
}
|
}
|
||||||
@ -1003,7 +1010,18 @@ void EditorPropertyEasing::_draw_easing() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
easing_draw->draw_multiline(lines, line_color, 1.0);
|
easing_draw->draw_multiline(lines, line_color, 1.0);
|
||||||
f->draw(ci, Point2(10, 10 + f->get_ascent()), String::num(exp, 2), font_color);
|
// Draw more decimals for small numbers since higher precision is usually required for fine adjustments.
|
||||||
|
int decimals;
|
||||||
|
if (Math::abs(exp) < 0.1 - CMP_EPSILON) {
|
||||||
|
decimals = 4;
|
||||||
|
} else if (Math::abs(exp) < 1 - CMP_EPSILON) {
|
||||||
|
decimals = 3;
|
||||||
|
} else if (Math::abs(exp) < 10 - CMP_EPSILON) {
|
||||||
|
decimals = 2;
|
||||||
|
} else {
|
||||||
|
decimals = 1;
|
||||||
|
}
|
||||||
|
f->draw(ci, Point2(10, 10 + f->get_ascent()), rtos(exp).pad_decimals(decimals), font_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorPropertyEasing::update_property() {
|
void EditorPropertyEasing::update_property() {
|
||||||
@ -1035,6 +1053,11 @@ void EditorPropertyEasing::_spin_value_changed(double p_value) {
|
|||||||
if (Math::is_zero_approx(p_value)) {
|
if (Math::is_zero_approx(p_value)) {
|
||||||
p_value = 0.00001;
|
p_value = 0.00001;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Limit to a reasonable value to prevent the curve going into infinity,
|
||||||
|
// which can cause crashes and other issues.
|
||||||
|
p_value = CLAMP(p_value, -1'000'000, 1'000'000);
|
||||||
|
|
||||||
emit_changed(get_edited_property(), p_value);
|
emit_changed(get_edited_property(), p_value);
|
||||||
_spin_focus_exited();
|
_spin_focus_exited();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user