summaryrefslogtreecommitdiffstats
path: root/editor/plugins/audio_stream_editor_plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/audio_stream_editor_plugin.cpp')
-rw-r--r--editor/plugins/audio_stream_editor_plugin.cpp18
1 files changed, 12 insertions, 6 deletions
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) {