diff --git a/SequenceEditor/Form1.cs b/SequenceEditor/Form1.cs index 089ba7893b..4c6c9573fe 100644 --- a/SequenceEditor/Form1.cs +++ b/SequenceEditor/Form1.cs @@ -20,7 +20,7 @@ namespace SequenceEditor void toolStripButton1_Click(object sender, EventArgs e) { - var shp = GetTextForm.GetString( "Add SHP..." ); + var shp = GetTextForm.GetString( "Add SHP...", "" ); if (shp == null) return; Program.Shps.Add(shp, Program.LoadAndResolve(shp)); } diff --git a/SequenceEditor/GetTextForm.cs b/SequenceEditor/GetTextForm.cs index ba79aa3df8..976c4594c1 100644 --- a/SequenceEditor/GetTextForm.cs +++ b/SequenceEditor/GetTextForm.cs @@ -16,10 +16,11 @@ namespace SequenceEditor InitializeComponent(); } - public static string GetString(string title) + public static string GetString(string title, string defaultValue) { using (var f = new GetTextForm()) { + f.textBox1.Text = defaultValue; f.Text = title; if (DialogResult.OK != f.ShowDialog()) return null; diff --git a/SequenceEditor/Program.cs b/SequenceEditor/Program.cs index f79f693a95..91bbcedff9 100644 --- a/SequenceEditor/Program.cs +++ b/SequenceEditor/Program.cs @@ -84,5 +84,7 @@ namespace SequenceEditor ? Program.Shps[shp].Length - start : ((a == "") ? 1 : int.Parse(a)); } + + public Sequence() { } } } diff --git a/SequenceEditor/Surface.cs b/SequenceEditor/Surface.cs index e90709231c..b8bf4b54aa 100644 --- a/SequenceEditor/Surface.cs +++ b/SequenceEditor/Surface.cs @@ -28,6 +28,10 @@ namespace SequenceEditor { base.OnMouseMove(e); mousePos = e.Location; + + if (e.Button == MouseButtons.Left) + isDragging = true; + Invalidate(); } @@ -37,7 +41,7 @@ namespace SequenceEditor { foreach (var shp in items) { - var sel = shp.Value.FirstOrDefault(a => a.Value.Contains(mousePos)); + var sel = shp.Value.FirstOrDefault(a => a.Value.Contains(p)); if (!sel.Value.IsEmpty) return Pair.New(shp.Key, sel.Key); } @@ -46,8 +50,46 @@ namespace SequenceEditor return null; } + string lastName = ""; + + protected override void OnMouseUp(MouseEventArgs e) + { + base.OnMouseUp(e); + + if (isDragging && e.Button == MouseButtons.Left) + { + isDragging = false; + + /* create a new sequence! */ + var start = FindFrameAt(clickPos); + var end = FindFrameAt(mousePos); + + if (start != null && end != null + && start.Value.First == end.Value.First) + { + var s = new Sequence() + { + start = start.Value.Second, + length = end.Value.Second - start.Value.Second + 1, + shp = start.Value.First + }; + + var name = GetTextForm.GetString("Name of new sequence", lastName); + if (name == null) return; + + Program.Sequences.Add(name, s); + lastName = name; + } + } + } + protected override void OnMouseDown(MouseEventArgs e) { + base.OnMouseDown(e); + + if (e.Button == MouseButtons.Left) + clickPos = e.Location; + if (e.Button == MouseButtons.Right) { var frameAtPoint = FindFrameAt(e.Location); @@ -63,6 +105,8 @@ namespace SequenceEditor } } + Sequence tempSequence; + protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); @@ -82,6 +126,21 @@ namespace SequenceEditor toolText = frameAtPoint.Value.Second.ToString(); } + tempSequence = null; + if (isDragging) + { + /* create a new sequence! */ + var start = FindFrameAt(clickPos); + var end = FindFrameAt(mousePos); + + if (start != null && end != null + && start.Value.First == end.Value.First) + tempSequence = new Sequence() { + start = start.Value.Second, + length = end.Value.Second - start.Value.Second + 1, + shp = start.Value.First }; + } + items.Clear(); foreach (var shp in Program.Shps) @@ -117,7 +176,11 @@ namespace SequenceEditor var brushes = new[] { Brushes.Green, Brushes.Red, Brushes.Blue, Brushes.Magenta, Brushes.DarkOrange, Brushes.Navy }; var seqid = 0; - foreach (var seq in Program.Sequences) + var seqs = Program.Sequences.Select(a => a); /* shorter than teh typename!! */ + if (tempSequence != null) + seqs = seqs.Concat(new[] { new KeyValuePair("New sequence...", tempSequence) }); + + foreach (var seq in seqs) { var firstFrame = seq.Value.start; var r = items[seq.Value.shp][firstFrame];