Skip to content

Commit 9fc656d

Browse files
committed
Merge pull request #110676 from YeldhamDev/can_you_bezier_a_marker
Show marker lines/sections in the animation bezier editor
2 parents 62abe9e + 0f614cd commit 9fc656d

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
@@ -7852,6 +7852,14 @@ AnimationTrackEditor::AnimationTrackEditor() {
78527852
box_selection_container->set_clip_contents(true);
78537853
timeline_vbox->add_child(box_selection_container);
78547854

7855+
bezier_edit = memnew(AnimationBezierTrackEdit);
7856+
timeline_vbox->add_child(bezier_edit);
7857+
bezier_edit->set_editor(this);
7858+
bezier_edit->set_timeline(timeline);
7859+
bezier_edit->hide();
7860+
bezier_edit->set_v_size_flags(SIZE_EXPAND_FILL);
7861+
bezier_edit->connect("timeline_changed", callable_mp(this, &AnimationTrackEditor::_timeline_changed));
7862+
78557863
marker_edit = memnew(AnimationMarkerEdit);
78567864
timeline->get_child(0)->add_child(marker_edit);
78577865
marker_edit->set_editor(this);
@@ -7860,6 +7868,7 @@ AnimationTrackEditor::AnimationTrackEditor() {
78607868
marker_edit->set_anchors_and_offsets_preset(Control::LayoutPreset::PRESET_FULL_RECT);
78617869
marker_edit->connect(SceneStringName(draw), callable_mp(this, &AnimationTrackEditor::_redraw_groups));
78627870
marker_edit->connect(SceneStringName(draw), callable_mp(this, &AnimationTrackEditor::_redraw_tracks));
7871+
marker_edit->connect(SceneStringName(draw), callable_mp((CanvasItem *)bezier_edit, &CanvasItem::queue_redraw));
78637872

78647873
scroll = memnew(ScrollContainer);
78657874
box_selection_container->add_child(scroll);
@@ -7875,14 +7884,6 @@ AnimationTrackEditor::AnimationTrackEditor() {
78757884
scroll->get_v_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(this, &AnimationTrackEditor::_v_scroll_changed));
78767885
scroll->get_h_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(this, &AnimationTrackEditor::_h_scroll_changed));
78777886

7878-
bezier_edit = memnew(AnimationBezierTrackEdit);
7879-
timeline_vbox->add_child(bezier_edit);
7880-
bezier_edit->set_editor(this);
7881-
bezier_edit->set_timeline(timeline);
7882-
bezier_edit->hide();
7883-
bezier_edit->set_v_size_flags(SIZE_EXPAND_FILL);
7884-
bezier_edit->connect("timeline_changed", callable_mp(this, &AnimationTrackEditor::_timeline_changed));
7885-
78867887
timeline_vbox->set_custom_minimum_size(Size2(0, 150) * EDSCALE);
78877888

78887889
hscroll = memnew(HScrollBar);

0 commit comments

Comments
 (0)