Improve the animation bezier editor
- Allow snapping bezier handles to the timeline. - Allow precise snapping when holding Shift for keyframes and handles. - Previously, it was only allowed for seeking the timeline. - This change also impacts the animation track editor, not just the bezier editor. - Invert the Ctrl + mouse wheel behavior to match the zoom direction in the animation track editor. - Increase the line spacing between the "Time:" and "Value:" texts to improve readability. - Tweak box selection styling to match the animation track editor. - Adjust line widths for hiDPI displays.
This commit is contained in:
parent
9f5c61315c
commit
4a4d977bea
2 changed files with 25 additions and 15 deletions
|
@ -178,7 +178,7 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lines.size() >= 2) {
|
if (lines.size() >= 2) {
|
||||||
draw_multiline(lines, p_color);
|
draw_multiline(lines, p_color, Math::round(EDSCALE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ void AnimationBezierTrackEdit::_draw_line_clipped(const Vector2 &p_from, const V
|
||||||
from = from.lerp(to, c);
|
from = from.lerp(to, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_line(from, to, p_color);
|
draw_line(from, to, p_color, Math::round(EDSCALE));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationBezierTrackEdit::_notification(int p_what) {
|
void AnimationBezierTrackEdit::_notification(int p_what) {
|
||||||
|
@ -244,7 +244,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
|
||||||
if (has_focus()) {
|
if (has_focus()) {
|
||||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||||
accent.a *= 0.7;
|
accent.a *= 0.7;
|
||||||
draw_rect(Rect2(Point2(), get_size()), accent, false);
|
draw_rect(Rect2(Point2(), get_size()), accent, false, Math::round(EDSCALE));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
|
||||||
|
@ -255,11 +255,11 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
|
||||||
Color linecolor = color;
|
Color linecolor = color;
|
||||||
linecolor.a = 0.2;
|
linecolor.a = 0.2;
|
||||||
|
|
||||||
draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor);
|
draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor, Math::round(EDSCALE));
|
||||||
|
|
||||||
int right_limit = get_size().width - timeline->get_buttons_width();
|
int right_limit = get_size().width - timeline->get_buttons_width();
|
||||||
|
|
||||||
draw_line(Point2(right_limit, 0), Point2(right_limit, get_size().height), linecolor);
|
draw_line(Point2(right_limit, 0), Point2(right_limit, get_size().height), linecolor, Math::round(EDSCALE));
|
||||||
|
|
||||||
Ref<Texture2D> close_icon = get_theme_icon(SNAME("Close"), SNAME("EditorIcons"));
|
Ref<Texture2D> close_icon = get_theme_icon(SNAME("Close"), SNAME("EditorIcons"));
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
|
||||||
if (!first && iv != prev_iv) {
|
if (!first && iv != prev_iv) {
|
||||||
Color lc = linecolor;
|
Color lc = linecolor;
|
||||||
lc.a *= 0.5;
|
lc.a *= 0.5;
|
||||||
draw_line(Point2(limit, i), Point2(right_limit, i), lc);
|
draw_line(Point2(limit, i), Point2(right_limit, i), lc, Math::round(EDSCALE));
|
||||||
Color c = color;
|
Color c = color;
|
||||||
c.a *= 0.5;
|
c.a *= 0.5;
|
||||||
draw_string(font, Point2(limit + 8, i - 2), TS->format_number(rtos(Math::snapped((iv + 1) * scale, step))), HALIGN_LEFT, -1, font_size, c);
|
draw_string(font, Point2(limit + 8, i - 2), TS->format_number(rtos(Math::snapped((iv + 1) * scale, step))), HALIGN_LEFT, -1, font_size, c);
|
||||||
|
@ -461,7 +461,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
|
||||||
ep.point_rect.size = bezier_icon->get_size();
|
ep.point_rect.size = bezier_icon->get_size();
|
||||||
if (selection.has(i)) {
|
if (selection.has(i)) {
|
||||||
draw_texture(selected_icon, ep.point_rect.position);
|
draw_texture(selected_icon, ep.point_rect.position);
|
||||||
draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 4), TTR("Time:") + " " + TS->format_number(rtos(Math::snapped(offset, 0.001))), HALIGN_LEFT, -1, font_size, accent);
|
draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 8), TTR("Time:") + " " + TS->format_number(rtos(Math::snapped(offset, 0.001))), HALIGN_LEFT, -1, font_size, accent);
|
||||||
draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::snapped(value, 0.001))), HALIGN_LEFT, -1, font_size, accent);
|
draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::snapped(value, 0.001))), HALIGN_LEFT, -1, font_size, accent);
|
||||||
} else {
|
} else {
|
||||||
draw_texture(bezier_icon, ep.point_rect.position);
|
draw_texture(bezier_icon, ep.point_rect.position);
|
||||||
|
@ -485,8 +485,6 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (box_selecting) {
|
if (box_selecting) {
|
||||||
Color bs = accent;
|
|
||||||
bs.a *= 0.5;
|
|
||||||
Vector2 bs_from = box_selection_from;
|
Vector2 bs_from = box_selection_from;
|
||||||
Vector2 bs_to = box_selection_to;
|
Vector2 bs_to = box_selection_to;
|
||||||
if (bs_from.x > bs_to.x) {
|
if (bs_from.x > bs_to.x) {
|
||||||
|
@ -495,7 +493,14 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
|
||||||
if (bs_from.y > bs_to.y) {
|
if (bs_from.y > bs_to.y) {
|
||||||
SWAP(bs_from.y, bs_to.y);
|
SWAP(bs_from.y, bs_to.y);
|
||||||
}
|
}
|
||||||
draw_rect(Rect2(bs_from, bs_to - bs_from), bs);
|
draw_rect(
|
||||||
|
Rect2(bs_from, bs_to - bs_from),
|
||||||
|
get_theme_color("box_selection_fill_color", "Editor"));
|
||||||
|
draw_rect(
|
||||||
|
Rect2(bs_from, bs_to - bs_from),
|
||||||
|
get_theme_color("box_selection_stroke_color", "Editor"),
|
||||||
|
false,
|
||||||
|
Math::round(EDSCALE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -618,9 +623,9 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
|
||||||
|
|
||||||
Ref<InputEventMouseButton> mb = p_event;
|
Ref<InputEventMouseButton> mb = p_event;
|
||||||
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) {
|
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) {
|
||||||
float v_zoom_orig = v_zoom;
|
const float v_zoom_orig = v_zoom;
|
||||||
if (mb->is_command_pressed()) {
|
if (mb->is_command_pressed()) {
|
||||||
timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() * 1.05);
|
timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() / 1.05);
|
||||||
} else {
|
} else {
|
||||||
if (v_zoom < 100000) {
|
if (v_zoom < 100000) {
|
||||||
v_zoom *= 1.2;
|
v_zoom *= 1.2;
|
||||||
|
@ -631,9 +636,9 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) {
|
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) {
|
||||||
float v_zoom_orig = v_zoom;
|
const float v_zoom_orig = v_zoom;
|
||||||
if (mb->is_command_pressed()) {
|
if (mb->is_command_pressed()) {
|
||||||
timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() / 1.05);
|
timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() * 1.05);
|
||||||
} else {
|
} else {
|
||||||
if (v_zoom > 0.000001) {
|
if (v_zoom > 0.000001) {
|
||||||
v_zoom /= 1.2;
|
v_zoom /= 1.2;
|
||||||
|
@ -974,7 +979,7 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
|
||||||
|
|
||||||
if (moving_handle != 0 && mm.is_valid()) {
|
if (moving_handle != 0 && mm.is_valid()) {
|
||||||
float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll;
|
float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll;
|
||||||
float x = ((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value();
|
float x = editor->snap_time((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value();
|
||||||
|
|
||||||
Vector2 key_pos = Vector2(animation->track_get_key_time(track, moving_handle_key), animation->bezier_track_get_key_value(track, moving_handle_key));
|
Vector2 key_pos = Vector2(animation->track_get_key_time(track, moving_handle_key), animation->bezier_track_get_key_value(track, moving_handle_key));
|
||||||
|
|
||||||
|
|
|
@ -5642,6 +5642,11 @@ float AnimationTrackEditor::snap_time(float p_value, bool p_relative) {
|
||||||
snap_increment = step->get_value();
|
snap_increment = step->get_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
|
||||||
|
// Use more precise snapping when holding Shift.
|
||||||
|
snap_increment *= 0.25;
|
||||||
|
}
|
||||||
|
|
||||||
if (p_relative) {
|
if (p_relative) {
|
||||||
double rel = Math::fmod(timeline->get_value(), snap_increment);
|
double rel = Math::fmod(timeline->get_value(), snap_increment);
|
||||||
p_value = Math::snapped(p_value + rel, snap_increment) - rel;
|
p_value = Math::snapped(p_value + rel, snap_increment) - rel;
|
||||||
|
|
Loading…
Reference in a new issue