From 5ad6fb39273127acf3f98432d8bc2bcd4feb1c1f Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sun, 24 May 2020 19:11:55 -0400 Subject: [PATCH] preliminary implementation of multiple selection using EditorSelections --- .../WaveformAudioEditorTrackWaveform.cs | 48 ++++++++++++++++++- .../Waveform/WaveformAudioEditorSelection.cs | 44 +++++++++++++++++ ...or.Plugins.Multimedia.UserInterface.csproj | 1 + 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/WaveformAudioEditorSelection.cs diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/Controls/WaveformAudioEditorTrackWaveform.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/Controls/WaveformAudioEditorTrackWaveform.cs index 1c58e96c..a0a80930 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/Controls/WaveformAudioEditorTrackWaveform.cs +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/Controls/WaveformAudioEditorTrackWaveform.cs @@ -48,10 +48,20 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Au public double ScaleFactorY { get; set; } = 0.5;// 1.0; private int origStart = 0; + private bool appendSelection = false; protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); + if ((e.ModifierKeys & MBS.Framework.UserInterface.Input.Keyboard.KeyboardModifierKey.Control) == MBS.Framework.UserInterface.Input.Keyboard.KeyboardModifierKey.Control) + { + appendSelection = true; + } + else + { + (Parent.Parent as WaveformAudioEditor).Selections.Clear(); + } + origStart = (int)e.X; _SelectionStart = (int)e.X; _SelectionLength = 0; @@ -76,6 +86,17 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Au Refresh(); } } + protected override void OnMouseUp(MouseEventArgs e) + { + base.OnMouseUp(e); + + WaveformAudioEditorSelection sel = new WaveformAudioEditorSelection((Parent.Parent as WaveformAudioEditor), SelectionStart, SelectionLength); + if (!appendSelection) + { + (Parent.Parent as WaveformAudioEditor).Selections.Clear(); + } + (Parent.Parent as WaveformAudioEditor).Selections.Add(sel); + } private const int WAVEFORM_MIDPOINT = 128; @@ -92,12 +113,25 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Au Pen pen = new Pen(SystemColors.HighlightBackground); Pen pen2 = new Pen(SystemColors.HighlightForeground); + // draw the existing selections backgrounds + WaveformAudioEditor ed = (Parent.Parent as WaveformAudioEditor); + for (int i = 0; i < ed.Selections.Count; i++) + { + if ((ed.Selections[i] as WaveformAudioEditorSelection).SelectionLength > 0) + { + e.Graphics.FillRectangle(new SolidBrush(SystemColors.HighlightBackground), new Rectangle((ed.Selections[i] as WaveformAudioEditorSelection).SelectionStart, 0, (ed.Selections[i] as WaveformAudioEditorSelection).SelectionLength, Size.Height)); + } + } + + // draw the currently active selection background if (SelectionLength > 0) { e.Graphics.FillRectangle(new SolidBrush(SystemColors.HighlightBackground), new Rectangle(SelectionStart, 0, SelectionLength, Size.Height)); } + // draw the midpoint line e.Graphics.DrawLine(new Pen(Colors.Black), 0, WAVEFORM_MIDPOINT * ScaleFactorY, HorizontalAdjustment.Value + Size.Width, WAVEFORM_MIDPOINT * ScaleFactorY); + // draw the currently active selection start line e.Graphics.DrawLine(new Pen(Colors.White), SelectionStart, 0, SelectionStart, Size.Height); for (int i = 0; i < wave.RawSamples.Length; i++) @@ -111,7 +145,19 @@ namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Au } else { - e.Graphics.DrawLine(pen, lastPoint.X, lastPoint.Y, x, y); + bool drawn = false; + for (int j = 0; j < ed.Selections.Count; j++) + { + if (x >= (ed.Selections[j] as WaveformAudioEditorSelection).SelectionStart && x <= (((ed.Selections[j] as WaveformAudioEditorSelection).SelectionLength) + (ed.Selections[j] as WaveformAudioEditorSelection).SelectionLength)) + { + e.Graphics.DrawLine(pen2, lastPoint.X, lastPoint.Y, x, y); + drawn = true; + break; + } + } + + if (!drawn) + e.Graphics.DrawLine(pen, lastPoint.X, lastPoint.Y, x, y); } lastPoint = new Vector2D(x, y); } diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/WaveformAudioEditorSelection.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/WaveformAudioEditorSelection.cs new file mode 100644 index 00000000..32f38a81 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/Editors/Multimedia/Audio/Waveform/WaveformAudioEditorSelection.cs @@ -0,0 +1,44 @@ +// +// WaveformAudioEditorSelection.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using UniversalEditor.UserInterface; + +namespace UniversalEditor.Plugins.Multimedia.UserInterface.Editors.Multimedia.Audio.Waveform +{ + public class WaveformAudioEditorSelection : EditorSelection + { + public WaveformAudioEditorSelection(Editor editor, int selectionStart, int selectionLength) : base(editor) + { + SelectionStart = selectionStart; + SelectionLength = selectionLength; + } + + public int SelectionStart { get; set; } = 0; + public int SelectionLength { get; set; } = 0; + + private object _Content = null; + public override object Content { get => _Content; set => _Content = value; } + + protected override void DeleteInternal() + { + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface.csproj b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface.csproj index dfbe530e..205f6d44 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface.csproj +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface/UniversalEditor.Plugins.Multimedia.UserInterface.csproj @@ -55,6 +55,7 @@ +