Skip to content

Commit 0f614cd

Browse files
committed
Show marker lines/sections in the animation bezier editor
1 parent 4fcd855 commit 0f614cd

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

editor/animation/animation_bezier_editor.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,60 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
321321
subtracks.clear();
322322
subtrack_icons.clear();
323323

324+
// Marker sections.
325+
{
326+
float scale = timeline->get_zoom_scale();
327+
int limit_end = get_size().width - timeline->get_buttons_width();
328+
329+
PackedStringArray section = editor->get_selected_section();
330+
if (section.size() == 2) {
331+
StringName start_marker = section[0];
332+
StringName end_marker = section[1];
333+
double start_time = animation->get_marker_time(start_marker);
334+
double end_time = animation->get_marker_time(end_marker);
335+
336+
// When AnimationPlayer is playing, don't move the preview rect, so it still indicates the playback section.
337+
AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player();
338+
if (editor->is_marker_moving_selection() && !(player && player->is_playing())) {
339+
start_time += editor->get_marker_moving_selection_offset();
340+
end_time += editor->get_marker_moving_selection_offset();
341+
}
342+
343+
if (start_time < animation->get_length() && end_time >= 0) {
344+
float start_ofs = MAX(0, start_time) - timeline->get_value();
345+
float end_ofs = MIN(animation->get_length(), end_time) - timeline->get_value();
346+
start_ofs = start_ofs * scale + limit;
347+
end_ofs = end_ofs * scale + limit;
348+
start_ofs = MAX(start_ofs, limit);
349+
end_ofs = MIN(end_ofs, limit_end);
350+
Rect2 rect;
351+
rect.set_position(Vector2(start_ofs, 0));
352+
rect.set_size(Vector2(end_ofs - start_ofs, get_size().height));
353+
354+
draw_rect(rect, Color(1, 0.1, 0.1, 0.2));
355+
}
356+
}
357+
}
358+
359+
// Marker overlays.
360+
{
361+
float scale = timeline->get_zoom_scale();
362+
PackedStringArray markers = animation->get_marker_names();
363+
for (const StringName marker : markers) {
364+
double time = animation->get_marker_time(marker);
365+
if (editor->is_marker_selected(marker) && editor->is_marker_moving_selection()) {
366+
time += editor->get_marker_moving_selection_offset();
367+
}
368+
if (time >= 0) {
369+
float offset = time - timeline->get_value();
370+
offset = offset * scale + limit;
371+
Color marker_color = animation->get_marker_color(marker);
372+
marker_color.a = 0.2;
373+
draw_line(Point2(offset, 0), Point2(offset, get_size().height), marker_color, Math::round(EDSCALE));
374+
}
375+
}
376+
}
377+
324378
RBMap<String, Vector<int>> track_indices;
325379
int track_count = animation->get_track_count();
326380
for (int i = 0; i < track_count; ++i) {

editor/animation/animation_track_editor.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7778,6 +7778,14 @@ AnimationTrackEditor::AnimationTrackEditor() {
77787778
box_selection_container->set_clip_contents(true);
77797779
timeline_vbox->add_child(box_selection_container);
77807780

7781+
bezier_edit = memnew(AnimationBezierTrackEdit);
7782+
timeline_vbox->add_child(bezier_edit);
7783+
bezier_edit->set_editor(this);
7784+
bezier_edit->set_timeline(timeline);
7785+
bezier_edit->hide();
7786+
bezier_edit->set_v_size_flags(SIZE_EXPAND_FILL);
7787+
bezier_edit->connect("timeline_changed", callable_mp(this, &AnimationTrackEditor::_timeline_changed));
7788+
77817789
marker_edit = memnew(AnimationMarkerEdit);
77827790
timeline->get_child(0)->add_child(marker_edit);
77837791
marker_edit->set_editor(this);
@@ -7786,6 +7794,7 @@ AnimationTrackEditor::AnimationTrackEditor() {
77867794
marker_edit->set_anchors_and_offsets_preset(Control::LayoutPreset::PRESET_FULL_RECT);
77877795
marker_edit->connect(SceneStringName(draw), callable_mp(this, &AnimationTrackEditor::_redraw_groups));
77887796
marker_edit->connect(SceneStringName(draw), callable_mp(this, &AnimationTrackEditor::_redraw_tracks));
7797+
marker_edit->connect(SceneStringName(draw), callable_mp((CanvasItem *)bezier_edit, &CanvasItem::queue_redraw));
77897798

77907799
scroll = memnew(ScrollContainer);
77917800
box_selection_container->add_child(scroll);
@@ -7801,14 +7810,6 @@ AnimationTrackEditor::AnimationTrackEditor() {
78017810
scroll->get_v_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(this, &AnimationTrackEditor::_v_scroll_changed));
78027811
scroll->get_h_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(this, &AnimationTrackEditor::_h_scroll_changed));
78037812

7804-
bezier_edit = memnew(AnimationBezierTrackEdit);
7805-
timeline_vbox->add_child(bezier_edit);
7806-
bezier_edit->set_editor(this);
7807-
bezier_edit->set_timeline(timeline);
7808-
bezier_edit->hide();
7809-
bezier_edit->set_v_size_flags(SIZE_EXPAND_FILL);
7810-
bezier_edit->connect("timeline_changed", callable_mp(this, &AnimationTrackEditor::_timeline_changed));
7811-
78127813
timeline_vbox->set_custom_minimum_size(Size2(0, 150) * EDSCALE);
78137814

78147815
hscroll = memnew(HScrollBar);

0 commit comments

Comments
 (0)