preliminary implementation of multiple selection using EditorSelections

This commit is contained in:
Michael Becker 2020-05-24 19:11:55 -04:00
parent 6f5d7150d9
commit 5ad6fb3927
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
3 changed files with 92 additions and 1 deletions

View File

@ -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);
}

View File

@ -0,0 +1,44 @@
//
// WaveformAudioEditorSelection.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
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()
{
}
}
}

View File

@ -55,6 +55,7 @@
<Compile Include="Editors\Multimedia\Audio\Waveform\Controls\WaveformAudioEditorTrack.cs" />
<Compile Include="Editors\Multimedia\Audio\Waveform\Controls\WaveformAudioEditorTrackWaveform.cs" />
<Compile Include="Editors\Multimedia\Audio\Synthesized\Views\MIDIEvents\MIDIEventsView.cs" />
<Compile Include="Editors\Multimedia\Audio\Waveform\WaveformAudioEditorSelection.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Editors\" />