diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/animation_track_editor_plugins.cpp | 54 | ||||
-rw-r--r-- | editor/editor_resource_picker.cpp | 15 | ||||
-rw-r--r-- | editor/import/audio_stream_import_settings.cpp | 21 | ||||
-rw-r--r-- | editor/plugins/audio_stream_editor_plugin.cpp | 18 |
4 files changed, 53 insertions, 55 deletions
diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp index be4a070213..6824bc7960 100644 --- a/editor/animation_track_editor_plugins.cpp +++ b/editor/animation_track_editor_plugins.cpp @@ -309,8 +309,8 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x, Rect2 rect = Rect2(from_x, (get_size().height - fh) / 2, to_x - from_x, fh); draw_rect(rect, Color(0.25, 0.25, 0.25)); - Vector<Vector2> lines; - lines.resize((to_x - from_x + 1) * 2); + Vector<Vector2> points; + points.resize((to_x - from_x) * 2); preview_len = preview->get_length(); for (int i = from_x; i < to_x; i++) { @@ -320,14 +320,13 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x, float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5; int idx = i - from_x; - lines.write[idx * 2 + 0] = Vector2(i, rect.position.y + min * rect.size.y); - lines.write[idx * 2 + 1] = Vector2(i, rect.position.y + max * rect.size.y); + points.write[idx * 2 + 0] = Vector2(i, rect.position.y + min * rect.size.y); + points.write[idx * 2 + 1] = Vector2(i, rect.position.y + max * rect.size.y); } - Vector<Color> color; - color.push_back(Color(0.75, 0.75, 0.75)); + Vector<Color> colors = { Color(0.75, 0.75, 0.75) }; - RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, color); + RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), points, colors); if (p_selected) { Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); @@ -667,8 +666,8 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_ bg.b = 1 - color.b; draw_rect(rect, bg); - Vector<Vector2> lines; - Vector<Color> colorv; + Vector<Vector2> points; + Vector<Color> colors = { color }; { Ref<Animation> ap_anim = ap->get_animation(anim); @@ -685,16 +684,14 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_ continue; } - lines.push_back(Point2(x, y)); - lines.push_back(Point2(x + 1, y)); + points.push_back(Point2(x, y)); + points.push_back(Point2(x + 1, y)); } } - - colorv.push_back(color); } - if (lines.size() > 2) { - RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, colorv); + if (points.size() > 2) { + RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), points, colors); } int limit = to_x - from_x - 4; @@ -919,8 +916,8 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int Rect2 rect = Rect2(from_x, (h - fh) / 2, to_x - from_x, fh); draw_rect(rect, Color(0.25, 0.25, 0.25)); - Vector<Vector2> lines; - lines.resize((to_x - from_x + 1) * 2); + Vector<Vector2> points; + points.resize((to_x - from_x) * 2); preview_len = preview->get_length(); for (int i = from_x; i < to_x; i++) { @@ -933,14 +930,13 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5; int idx = i - from_x; - lines.write[idx * 2 + 0] = Vector2(i, rect.position.y + min * rect.size.y); - lines.write[idx * 2 + 1] = Vector2(i, rect.position.y + max * rect.size.y); + points.write[idx * 2 + 0] = Vector2(i, rect.position.y + min * rect.size.y); + points.write[idx * 2 + 1] = Vector2(i, rect.position.y + max * rect.size.y); } - Vector<Color> color; - color.push_back(Color(0.75, 0.75, 0.75)); + Vector<Color> colors = { Color(0.75, 0.75, 0.75) }; - RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, color); + RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), points, colors); Color cut_color = get_theme_color(SNAME("accent_color"), SNAME("Editor")); cut_color.a = 0.7; @@ -1279,8 +1275,8 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec, bg.b = 1 - color.b; draw_rect(rect, bg); - Vector<Vector2> lines; - Vector<Color> colorv; + Vector<Vector2> points; + Vector<Color> colors = { color }; { Ref<Animation> ap_anim = ap->get_animation(anim); @@ -1297,16 +1293,14 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec, continue; } - lines.push_back(Point2(x, y)); - lines.push_back(Point2(x + 1, y)); + points.push_back(Point2(x, y)); + points.push_back(Point2(x + 1, y)); } } - - colorv.push_back(color); } - if (lines.size() > 2) { - RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, colorv); + if (points.size() > 2) { + RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), points, colors); } int limit = to_x - from_x - 4; diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 2d6feac007..e364e994cb 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -1145,7 +1145,7 @@ void EditorAudioStreamPicker::_preview_draw() { Rect2 rect(Point2(), size); - if (audio_stream->get_length() > 0) { + if (audio_stream->get_length() > 0 && size.width > 0) { rect.size.height *= 0.5; stream_preview_rect->draw_rect(rect, Color(0, 0, 0, 1)); @@ -1153,8 +1153,8 @@ void EditorAudioStreamPicker::_preview_draw() { Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(audio_stream); float preview_len = preview->get_length(); - Vector<Vector2> lines; - lines.resize(size.width * 2); + Vector<Vector2> points; + points.resize(size.width * 2); for (int i = 0; i < size.width; i++) { float ofs = i * preview_len / size.width; @@ -1163,14 +1163,13 @@ void EditorAudioStreamPicker::_preview_draw() { float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5; int idx = i; - lines.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y); - lines.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y); + points.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y); + points.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y); } - Vector<Color> color; - color.push_back(get_theme_color(SNAME("contrast_color_2"), SNAME("Editor"))); + Vector<Color> colors = { get_theme_color(SNAME("contrast_color_2"), SNAME("Editor")) }; - RS::get_singleton()->canvas_item_add_multiline(stream_preview_rect->get_canvas_item(), lines, color); + RS::get_singleton()->canvas_item_add_multiline(stream_preview_rect->get_canvas_item(), points, colors); if (tagged_frame_offset_count) { Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); diff --git a/editor/import/audio_stream_import_settings.cpp b/editor/import/audio_stream_import_settings.cpp index 41a2f7a643..c32218bbfc 100644 --- a/editor/import/audio_stream_import_settings.cpp +++ b/editor/import/audio_stream_import_settings.cpp @@ -85,13 +85,13 @@ void AudioStreamImportSettings::_draw_preview() { Ref<Font> beat_font = get_theme_font(SNAME("main"), SNAME("EditorFonts")); int main_size = get_theme_font_size(SNAME("main_size"), SNAME("EditorFonts")); - Vector<Vector2> lines; - lines.resize(rect_size.width * 2); + Vector<Vector2> points; + points.resize((int)rect_size.width * 2); Color color_active = get_theme_color(SNAME("contrast_color_2"), SNAME("Editor")); Color color_inactive = color_active; color_inactive.a *= 0.5; - Vector<Color> color; - color.resize(lines.size()); + Vector<Color> colors; + colors.resize((int)rect_size.width); float inactive_from = 1e20; float beat_size = 0; @@ -115,16 +115,15 @@ void AudioStreamImportSettings::_draw_preview() { float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5; int idx = i; - lines.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y); - lines.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y); + points.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y); + points.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y); - Color c = ofs > inactive_from ? color_inactive : color_active; - - color.write[idx * 2 + 0] = c; - color.write[idx * 2 + 1] = c; + colors.write[idx] = ofs > inactive_from ? color_inactive : color_active; } - RS::get_singleton()->canvas_item_add_multiline(_preview->get_canvas_item(), lines, color); + if (!points.is_empty()) { + RS::get_singleton()->canvas_item_add_multiline(_preview->get_canvas_item(), points, colors); + } if (beat_size) { Color beat_color = Color(1, 1, 1, 1); diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp index 61f70f6b1e..e8fc4e76bb 100644 --- a/editor/plugins/audio_stream_editor_plugin.cpp +++ b/editor/plugins/audio_stream_editor_plugin.cpp @@ -74,14 +74,18 @@ void AudioStreamEditor::_notification(int p_what) { } void AudioStreamEditor::_draw_preview() { - Rect2 rect = _preview->get_rect(); Size2 size = get_size(); + if ((int)size.width <= 0) { + return; // No points to draw. + } + + Rect2 rect = _preview->get_rect(); Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); float preview_len = preview->get_length(); - Vector<Vector2> lines; - lines.resize(size.width * 2); + Vector<Vector2> points; + points.resize((int)size.width * 2); for (int i = 0; i < size.width; i++) { float ofs = i * preview_len / size.width; @@ -90,11 +94,13 @@ void AudioStreamEditor::_draw_preview() { float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5; int idx = i; - lines.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y); - lines.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y); + points.write[idx * 2 + 0] = Vector2(i + 1, rect.position.y + min * rect.size.y); + points.write[idx * 2 + 1] = Vector2(i + 1, rect.position.y + max * rect.size.y); } - RS::get_singleton()->canvas_item_add_multiline(_preview->get_canvas_item(), lines, { get_theme_color(SNAME("contrast_color_2"), SNAME("Editor")) }); + Vector<Color> colors = { get_theme_color(SNAME("contrast_color_2"), SNAME("Editor")) }; + + RS::get_singleton()->canvas_item_add_multiline(_preview->get_canvas_item(), points, colors); } void AudioStreamEditor::_preview_changed(ObjectID p_which) { |