Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the animation bezier editor #48572

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions editor/animation_bezier_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
}

if (lines.size() >= 2) {
draw_multiline(lines, p_color);
draw_multiline(lines, p_color, Math::round(EDSCALE));
}
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ void AnimationBezierTrackEdit::_draw_line_clipped(const Vector2 &p_from, const V
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) {
Expand Down Expand Up @@ -244,7 +244,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
if (has_focus()) {
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
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"));
Expand All @@ -255,11 +255,11 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
Color linecolor = color;
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();

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"));

Expand Down Expand Up @@ -387,7 +387,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
if (!first && iv != prev_iv) {
Color lc = linecolor;
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;
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);
Expand Down Expand Up @@ -461,7 +461,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
ep.point_rect.size = bezier_icon->get_size();
if (selection.has(i)) {
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);
} else {
draw_texture(bezier_icon, ep.point_rect.position);
Expand All @@ -485,8 +485,6 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
}

if (box_selecting) {
Color bs = accent;
bs.a *= 0.5;
Vector2 bs_from = box_selection_from;
Vector2 bs_to = box_selection_to;
if (bs_from.x > bs_to.x) {
Expand All @@ -495,7 +493,14 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
if (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));
}
}
}
Expand Down Expand Up @@ -618,9 +623,9 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {

Ref<InputEventMouseButton> mb = p_event;
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()) {
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 {
if (v_zoom < 100000) {
v_zoom *= 1.2;
Expand All @@ -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) {
float v_zoom_orig = v_zoom;
const float v_zoom_orig = v_zoom;
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 {
if (v_zoom > 0.000001) {
v_zoom /= 1.2;
Expand Down Expand Up @@ -974,7 +979,7 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {

if (moving_handle != 0 && mm.is_valid()) {
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));

Expand Down
5 changes: 5 additions & 0 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5642,6 +5642,11 @@ float AnimationTrackEditor::snap_time(float p_value, bool p_relative) {
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) {
double rel = Math::fmod(timeline->get_value(), snap_increment);
p_value = Math::snapped(p_value + rel, snap_increment) - rel;
Expand Down