diff options
Diffstat (limited to 'editor/animation_bezier_editor.cpp')
-rw-r--r-- | editor/animation_bezier_editor.cpp | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index f880ece88b..5d2b825c4f 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,6 +31,8 @@ #include "animation_bezier_editor.h" #include "editor/editor_node.h" +#include "editor_scale.h" +#include "scene/resources/text_line.h" float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) { float h = p_h; @@ -246,6 +248,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { } Ref<Font> font = get_theme_font("font", "Label"); + int font_size = get_theme_font_size("font_size", "Label"); Color color = get_theme_color("font_color", "Label"); int hsep = get_theme_constant("hseparation", "ItemList"); int vsep = get_theme_constant("vseparation", "ItemList"); @@ -285,26 +288,27 @@ void AnimationBezierTrackEdit::_notification(int p_what) { String text; - int h = font->get_height(); - if (node) { int ofs = 0; Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(node, "Node"); - h = MAX(h, icon->get_height()); + text = node->get_name(); + ofs += hsep; + ofs += icon->get_width(); + + TextLine text_buf = TextLine(text, font, font_size); + text_buf.set_width(limit - ofs - hsep); + + int h = MAX(text_buf.get_size().y, icon->get_height()); draw_texture(icon, Point2(ofs, vofs + int(h - icon->get_height()) / 2)); margin = icon->get_width(); - text = node->get_name(); - ofs += hsep; - ofs += icon->get_width(); - - Vector2 string_pos = Point2(ofs, vofs + (h - font->get_height()) / 2 + font->get_ascent()); + Vector2 string_pos = Point2(ofs, vofs + (h - text_buf.get_size().y) / 2 + text_buf.get_line_ascent()); string_pos = string_pos.floor(); - draw_string(font, string_pos, text, color, limit - ofs - hsep); + text_buf.draw(get_canvas_item(), string_pos, color); vofs += h + vsep; } @@ -326,7 +330,10 @@ void AnimationBezierTrackEdit::_notification(int p_what) { path = path.replace_first(base_path, ""); Color cc = color; - Rect2 rect = Rect2(margin, vofs, limit - margin - hsep, font->get_height() + vsep); + TextLine text_buf = TextLine(path, font, font_size); + text_buf.set_width(limit - margin - hsep); + + Rect2 rect = Rect2(margin, vofs, limit - margin - hsep, text_buf.get_size().y + vsep); if (i != track) { cc.a *= 0.7; uint32_t hash = path.hash(); @@ -337,7 +344,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { Color subcolor; subcolor.set_hsv(h, 0.2, 0.8); subcolor.a = 0.5; - draw_rect(Rect2(0, vofs + font->get_height() * 0.1, margin - hsep, font->get_height() * 0.8), subcolor); + draw_rect(Rect2(0, vofs + text_buf.get_size().y * 0.1, margin - hsep, text_buf.get_size().y * 0.8), subcolor); subtrack_colors[i] = subcolor; subtracks[i] = rect; @@ -346,19 +353,21 @@ void AnimationBezierTrackEdit::_notification(int p_what) { ac.a = 0.5; draw_rect(rect, ac); } - draw_string(font, Point2(margin, vofs + font->get_ascent()), path, cc, limit - margin - hsep); - vofs += font->get_height() + vsep; + Vector2 string_pos = Point2(margin, vofs + text_buf.get_line_ascent()); + text_buf.draw(get_canvas_item(), string_pos, cc); + + vofs += text_buf.get_size().y + vsep; } Color accent = get_theme_color("accent_color", "Editor"); { //guides - float min_left_scale = font->get_height() + vsep; + float min_left_scale = font->get_height(font_size) + vsep; float scale = (min_left_scale * 2) * v_zoom; float step = Math::pow(10.0, Math::round(Math::log(scale / 5.0) / Math::log(10.0))) * 5.0; - scale = Math::stepify(scale, step); + scale = Math::snapped(scale, step); while (scale / v_zoom < min_left_scale * 2) { scale += step; @@ -366,7 +375,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { bool first = true; int prev_iv = 0; - for (int i = font->get_height(); i < get_size().height; i++) { + for (int i = font->get_height(font_size); i < get_size().height; i++) { float ofs = get_size().height / 2 - i; ofs *= v_zoom; ofs += v_scroll; @@ -381,7 +390,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { draw_line(Point2(limit, i), Point2(right_limit, i), lc); Color c = color; c.a *= 0.5; - draw_string(font, Point2(limit + 8, i - 2), rtos(Math::stepify((iv + 1) * scale, step)), 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); } first = false; @@ -452,8 +461,8 @@ 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() - 4), TTR("Time:") + " " + rtos(Math::stepify(offset, 0.001)), accent); - draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + rtos(Math::stepify(value, 0.001)), accent); + 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, -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); } @@ -498,14 +507,14 @@ Ref<Animation> AnimationBezierTrackEdit::get_animation() const { void AnimationBezierTrackEdit::set_animation_and_track(const Ref<Animation> &p_animation, int p_track) { animation = p_animation; track = p_track; - if (is_connected_compat("select_key", editor, "_key_selected")) { - disconnect_compat("select_key", editor, "_key_selected"); + if (is_connected("select_key", Callable(editor, "_key_selected"))) { + disconnect("select_key", Callable(editor, "_key_selected")); } - if (is_connected_compat("deselect_key", editor, "_key_deselected")) { - disconnect_compat("deselect_key", editor, "_key_deselected"); + if (is_connected("deselect_key", Callable(editor, "_key_deselected"))) { + disconnect("deselect_key", Callable(editor, "_key_deselected")); } - connect_compat("select_key", editor, "_key_selected", varray(p_track), CONNECT_DEFERRED); - connect_compat("deselect_key", editor, "_key_deselected", varray(p_track), CONNECT_DEFERRED); + connect("select_key", Callable(editor, "_key_selected"), varray(p_track), CONNECT_DEFERRED); + connect("deselect_key", Callable(editor, "_key_deselected"), varray(p_track), CONNECT_DEFERRED); update(); } @@ -524,7 +533,7 @@ void AnimationBezierTrackEdit::set_timeline(AnimationTimelineEdit *p_timeline) { void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) { editor = p_editor; - connect_compat("clear_selection", editor, "_clear_selection", varray(false)); + connect("clear_selection", Callable(editor, "_clear_selection"), varray(false)); } void AnimationBezierTrackEdit::_play_position_draw() { @@ -539,7 +548,7 @@ void AnimationBezierTrackEdit::_play_position_draw() { if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) { Color color = get_theme_color("accent_color", "Editor"); - play_position->draw_line(Point2(px, 0), Point2(px, h), color); + play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(2 * EDSCALE)); } } @@ -558,6 +567,7 @@ void AnimationBezierTrackEdit::set_root(Node *p_root) { void AnimationBezierTrackEdit::_zoom_changed() { update(); + play_position->update(); } String AnimationBezierTrackEdit::get_tooltip(const Point2 &p_pos) const { @@ -1154,7 +1164,7 @@ AnimationBezierTrackEdit::AnimationBezierTrackEdit() { play_position = memnew(Control); play_position->set_mouse_filter(MOUSE_FILTER_PASS); add_child(play_position); - play_position->set_anchors_and_margins_preset(PRESET_WIDE); + play_position->set_anchors_and_offsets_preset(PRESET_WIDE); play_position->connect("draw", callable_mp(this, &AnimationBezierTrackEdit::_play_position_draw)); set_focus_mode(FOCUS_CLICK); |