summaryrefslogtreecommitdiff
path: root/editor/animation_bezier_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/animation_bezier_editor.cpp')
-rw-r--r--editor/animation_bezier_editor.cpp67
1 files changed, 28 insertions, 39 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp
index 9c8fec26a7..ab9afda803 100644
--- a/editor/animation_bezier_editor.cpp
+++ b/editor/animation_bezier_editor.cpp
@@ -44,17 +44,6 @@ float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) {
return h;
}
-static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, const Vector2 &start, const Vector2 &control_1, const Vector2 &control_2, const Vector2 &end) {
- /* Formula from Wikipedia article on Bezier curves. */
- real_t omt = (1.0 - t);
- real_t omt2 = omt * omt;
- real_t omt3 = omt2 * omt;
- real_t t2 = t * t;
- real_t t3 = t2 * t;
-
- return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3;
-}
-
void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
float scale = timeline->get_zoom_scale();
@@ -62,7 +51,7 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
int right_limit = get_size().width;
//selection may have altered the order of keys
- Map<float, int> key_order;
+ RBMap<float, int> key_order;
for (int i = 0; i < animation->track_get_key_count(p_track); i++) {
float ofs = animation->track_get_key_time(p_track, i);
@@ -73,7 +62,7 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
key_order[ofs] = i;
}
- for (Map<float, int>::Element *E = key_order.front(); E; E = E->next()) {
+ for (RBMap<float, int>::Element *E = key_order.front(); E; E = E->next()) {
int i = E->get();
if (!E->next()) {
@@ -151,7 +140,7 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
for (int k = 0; k < iterations; k++) {
float middle = (low + high) / 2;
- Vector2 interp = _bezier_interp(middle, start, out_handle, in_handle, end);
+ Vector2 interp = start.bezier_interpolate(out_handle, in_handle, end, middle);
if (interp.x < t) {
low = middle;
@@ -161,8 +150,8 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
}
//interpolate the result:
- Vector2 low_pos = _bezier_interp(low, start, out_handle, in_handle, end);
- Vector2 high_pos = _bezier_interp(high, start, out_handle, in_handle, end);
+ Vector2 low_pos = start.bezier_interpolate(out_handle, in_handle, end, low);
+ Vector2 high_pos = start.bezier_interpolate(out_handle, in_handle, end, high);
float c = (t - low_pos.x) / (high_pos.x - low_pos.x);
@@ -262,12 +251,12 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
int vofs = vsep;
int margin = 0;
- Map<int, Color> subtrack_colors;
+ RBMap<int, Color> subtrack_colors;
Color selected_track_color;
subtracks.clear();
subtrack_icons.clear();
- Map<String, Vector<int>> track_indices;
+ RBMap<String, Vector<int>> track_indices;
int track_count = animation->get_track_count();
for (int i = 0; i < track_count; ++i) {
if (animation->track_get_type(i) != Animation::TrackType::TYPE_BEZIER) {
@@ -432,7 +421,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
Rect2 solo_rect = Rect2(solo_hpos, icon_start_height - solo->get_height() / 2, solo->get_width(), solo->get_height());
draw_texture(solo, solo_rect.position);
- Map<int, Rect2> track_icons;
+ RBMap<int, Rect2> track_icons;
track_icons[REMOVE_ICON] = remove_rect;
track_icons[LOCK_ICON] = lock_rect;
track_icons[VISIBILITY_ICON] = visible_rect;
@@ -665,9 +654,9 @@ void AnimationBezierTrackEdit::set_timeline(AnimationTimelineEdit *p_timeline) {
void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) {
editor = p_editor;
- connect("clear_selection", Callable(editor, "_clear_selection"), varray(false));
- connect("select_key", Callable(editor, "_key_selected"), varray(), CONNECT_DEFERRED);
- connect("deselect_key", Callable(editor, "_key_deselected"), varray(), CONNECT_DEFERRED);
+ connect("clear_selection", Callable(editor, "_clear_selection").bind(false));
+ connect("select_key", Callable(editor, "_key_selected"), CONNECT_DEFERRED);
+ connect("deselect_key", Callable(editor, "_key_deselected"), CONNECT_DEFERRED);
}
void AnimationBezierTrackEdit::_play_position_draw() {
@@ -747,8 +736,8 @@ void AnimationBezierTrackEdit::_update_locked_tracks_after(int p_track) {
}
Vector<int> updated_locked_tracks;
- for (Set<int>::Element *E = locked_tracks.front(); E; E = E->next()) {
- updated_locked_tracks.push_back(E->get());
+ for (const int &E : locked_tracks) {
+ updated_locked_tracks.push_back(E);
}
locked_tracks.clear();
for (int i = 0; i < updated_locked_tracks.size(); ++i) {
@@ -766,8 +755,8 @@ void AnimationBezierTrackEdit::_update_hidden_tracks_after(int p_track) {
}
Vector<int> updated_hidden_tracks;
- for (Set<int>::Element *E = hidden_tracks.front(); E; E = E->next()) {
- updated_hidden_tracks.push_back(E->get());
+ for (const int &E : hidden_tracks) {
+ updated_hidden_tracks.push_back(E);
}
hidden_tracks.clear();
for (int i = 0; i < updated_hidden_tracks.size(); ++i) {
@@ -792,8 +781,8 @@ void AnimationBezierTrackEdit::_clear_selection() {
void AnimationBezierTrackEdit::_change_selected_keys_handle_mode(Animation::HandleMode p_mode) {
undo_redo->create_action(TTR("Update Selected Key Handles"));
double ratio = timeline->get_zoom_scale() * v_zoom;
- for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
- const IntPair track_key_pair = E->get();
+ for (const IntPair &E : selection) {
+ const IntPair track_key_pair = E;
undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_handle_mode", track_key_pair.first, track_key_pair.second, animation->bezier_track_get_key_handle_mode(track_key_pair.first, track_key_pair.second), ratio);
undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_handle_mode", track_key_pair.first, track_key_pair.second, p_mode, ratio);
}
@@ -851,14 +840,14 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
focused_keys.insert(key_pair);
}
} else {
- for (SelectionSet::Element *E = selection.front(); E; E = E->next()) {
- focused_keys.insert(E->get());
- if (E->get().second > 0) {
- IntPair previous_key = IntPair(E->get().first, E->get().second - 1);
+ for (const IntPair &E : selection) {
+ focused_keys.insert(E);
+ if (E.second > 0) {
+ IntPair previous_key = IntPair(E.first, E.second - 1);
focused_keys.insert(previous_key);
}
- if (E->get().second < animation->track_get_key_count(E->get().first) - 1) {
- IntPair next_key = IntPair(E->get().first, E->get().second + 1);
+ if (E.second < animation->track_get_key_count(E.first) - 1) {
+ IntPair next_key = IntPair(E.first, E.second + 1);
focused_keys.insert(next_key);
}
}
@@ -873,8 +862,8 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
float minimum_value = INFINITY;
float maximum_value = -INFINITY;
- for (SelectionSet::Element *E = focused_keys.front(); E; E = E->next()) {
- IntPair key_pair = E->get();
+ for (const IntPair &E : selection) {
+ IntPair key_pair = E;
float time = animation->track_get_key_time(key_pair.first, key_pair.second);
float value = animation->bezier_track_get_key_value(key_pair.first, key_pair.second);
@@ -963,9 +952,9 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
}
}
- for (const KeyValue<int, Map<int, Rect2>> &E : subtrack_icons) {
+ for (const KeyValue<int, RBMap<int, Rect2>> &E : subtrack_icons) {
int track = E.key;
- Map<int, Rect2> track_icons = E.value;
+ RBMap<int, Rect2> track_icons = E.value;
for (const KeyValue<int, Rect2> &I : track_icons) {
if (I.value.has_point(mb->get_position())) {
if (I.key == REMOVE_ICON) {
@@ -1604,7 +1593,7 @@ AnimationBezierTrackEdit::AnimationBezierTrackEdit() {
play_position = memnew(Control);
play_position->set_mouse_filter(MOUSE_FILTER_PASS);
add_child(play_position);
- play_position->set_anchors_and_offsets_preset(PRESET_WIDE);
+ play_position->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
play_position->connect("draw", callable_mp(this, &AnimationBezierTrackEdit::_play_position_draw));
set_focus_mode(FOCUS_CLICK);