From 6bcbf82b7cba3e32c14c4de3843cef439395efca Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 28 Jul 2015 20:03:03 -0400 Subject: [PATCH] Tastudio - ability to move markers by shift+click dragging them --- .../tools/TAStudio/InputRoll.cs | 67 +++++++++++++++++++ .../tools/TAStudio/TAStudio.Designer.cs | 19 +++--- .../tools/TAStudio/TAStudio.ListView.cs | 13 +++- .../tools/TAStudio/TAStudio.cs | 14 ++++ 4 files changed, 102 insertions(+), 11 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs index 32cd69a270..8bde0646ba 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs @@ -359,6 +359,10 @@ namespace BizHawk.Client.EmuHawk [Description("Occurs when the scroll value of the columns (in vertical orientation this is the horizontal scroll bar change, and in horizontal it is the vertical scroll bar)")] public event ColumnScrollEvent ColumnScroll; + [Category("Action")] + [Description("Occurs when a cell is dragged and then dropped into a new cell, old cell is the cell that was being dragged, new cell is its new destination")] + public event CellDroppedEvent CellDropped; + /// /// Retrieve the text for a cell /// @@ -394,6 +398,8 @@ namespace BizHawk.Client.EmuHawk public delegate void ColumnScrollEvent(object sender, EventArgs e); + public delegate void CellDroppedEvent(object sender, CellEventArgs e); + public class CellEventArgs { public CellEventArgs(Cell oldCell, Cell newCell) @@ -780,6 +786,30 @@ namespace BizHawk.Client.EmuHawk } } + private Cell DraggingCell = null; + + public void DragCurrentCell() + { + DraggingCell = CurrentCell; + } + + public void ReleaseCurrentCell() + { + if (DraggingCell != null) + { + var draggedCell = DraggingCell; + DraggingCell = null; + + if (CurrentCell != draggedCell) + { + if (CellDropped != null) + { + CellDropped(this, new CellEventArgs(draggedCell, CurrentCell)); + } + } + } + } + /// /// Scrolls to the given index, according to the scroll settings. /// @@ -916,6 +946,7 @@ namespace BizHawk.Client.EmuHawk DrawData(e); DrawColumnDrag(e); + DrawCellDrag(e); Gdi.CopyToScreen(); Gdi.EndOffScreenBitmap(); @@ -943,6 +974,42 @@ namespace BizHawk.Client.EmuHawk } } + private void DrawCellDrag(PaintEventArgs e) + { + if (DraggingCell != null) + { + try + { + var text = ""; + if (QueryItemText != null) + { + QueryItemText(DraggingCell.RowIndex.Value, DraggingCell.Column, out text); + } + + Color bgColor = this.BackColor; + if (QueryItemBkColor != null) + { + QueryItemBkColor(DraggingCell.RowIndex.Value, DraggingCell.Column, ref bgColor); + } + + int x1 = _currentX.Value - (DraggingCell.Column.Width.Value / 2); + int y1 = _currentY.Value - (CellHeight / 2); + int x2 = x1 + DraggingCell.Column.Width.Value; + int y2 = y1 + CellHeight; + + + Gdi.SetBrush(bgColor); + Gdi.FillRectangle(x1, y1, x2 - x1, y2 - y1); + Gdi.PrepDrawString(this.NormalFont, this.ForeColor); + Gdi.DrawString(text, new Point(x1 + CellWidthPadding, y1 + CellHeightPadding)); + } + catch (Exception ex) + { + int zzz = 0; + } + } + } + private void DrawColumnText(PaintEventArgs e) { var columns = _columns.VisibleColumns.ToList(); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs index 9a10a5a08b..d6df2e388e 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs @@ -172,11 +172,11 @@ namespace BizHawk.Client.EmuHawk this.BranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.StartFromNowSeparator = new System.Windows.Forms.ToolStripSeparator(); this.StartNewProjectFromNowMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.StartANewProjectFromSaveRamMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.BookMarkControl = new BizHawk.Client.EmuHawk.BookmarksBranchesBox(); this.BranchesMarkersSplit = new System.Windows.Forms.SplitContainer(); this.MainVertialSplit = new System.Windows.Forms.SplitContainer(); - this.StartANewProjectFromSaveRamMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.TASMenu.SuspendLayout(); this.TasStatusStrip.SuspendLayout(); this.MarkerContextMenu.SuspendLayout(); @@ -1057,6 +1057,7 @@ namespace BizHawk.Client.EmuHawk this.TasView.SelectedIndexChanged += new System.EventHandler(this.TasView_SelectedIndexChanged); this.TasView.RightMouseScrolled += new BizHawk.Client.EmuHawk.InputRoll.RightMouseScrollEventHandler(this.TasView_MouseWheel); this.TasView.ColumnReordered += new BizHawk.Client.EmuHawk.InputRoll.ColumnReorderedEventHandler(this.TasView_ColumnReordered); + this.TasView.CellDropped += new BizHawk.Client.EmuHawk.InputRoll.CellDroppedEvent(this.TasView_CellDropped); this.TasView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TasView_KeyDown); this.TasView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.TasView_MouseDoubleClick); this.TasView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TasView_MouseDown); @@ -1194,7 +1195,7 @@ namespace BizHawk.Client.EmuHawk this.StartNewProjectFromNowMenuItem, this.StartANewProjectFromSaveRamMenuItem}); this.RightClickMenu.Name = "RightClickMenu"; - this.RightClickMenu.Size = new System.Drawing.Size(273, 480); + this.RightClickMenu.Size = new System.Drawing.Size(273, 458); this.RightClickMenu.Opened += new System.EventHandler(this.RightClickMenu_Opened); // // SetMarkersContextMenuItem @@ -1365,6 +1366,13 @@ namespace BizHawk.Client.EmuHawk this.StartNewProjectFromNowMenuItem.Text = "Start a new project from Here"; this.StartNewProjectFromNowMenuItem.Click += new System.EventHandler(this.StartNewProjectFromNowMenuItem_Click); // + // StartANewProjectFromSaveRamMenuItem + // + this.StartANewProjectFromSaveRamMenuItem.Name = "StartANewProjectFromSaveRamMenuItem"; + this.StartANewProjectFromSaveRamMenuItem.Size = new System.Drawing.Size(272, 22); + this.StartANewProjectFromSaveRamMenuItem.Text = "Start a new project from SaveRam"; + this.StartANewProjectFromSaveRamMenuItem.Click += new System.EventHandler(this.StartANewProjectFromSaveRamMenuItem_Click); + // // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -1432,13 +1440,6 @@ namespace BizHawk.Client.EmuHawk this.MainVertialSplit.TabIndex = 10; this.MainVertialSplit.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.MainVertialSplit_SplitterMoved); // - // StartANewProjectFromSaveRamMenuItem - // - this.StartANewProjectFromSaveRamMenuItem.Name = "StartANewProjectFromSaveRamMenuItem"; - this.StartANewProjectFromSaveRamMenuItem.Size = new System.Drawing.Size(272, 22); - this.StartANewProjectFromSaveRamMenuItem.Text = "Start a new project from SaveRam"; - this.StartANewProjectFromSaveRamMenuItem.Click += new System.EventHandler(this.StartANewProjectFromSaveRamMenuItem_Click); - // // TAStudio // this.AllowDrop = true; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index cb3ec18c5c..a4061f5fee 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -354,8 +354,16 @@ namespace BizHawk.Client.EmuHawk } else if (TasView.CurrentCell.Column.Name == FrameColumnName) { - _startFrameDrag = true; - _frameDragState = TasView.SelectedRows.Contains(frame); + if (Control.ModifierKeys == Keys.Shift && CurrentTasMovie.Markers.IsMarker(frame)) + { + // TODO + TasView.DragCurrentCell(); + } + else + { + _startFrameDrag = true; + _frameDragState = TasView.SelectedRows.Contains(frame); + } } else // User changed input { @@ -477,6 +485,7 @@ namespace BizHawk.Client.EmuHawk _startFrameDrag = false; _startBoolDrawColumn = string.Empty; _startFloatDrawColumn = string.Empty; + TasView.ReleaseCurrentCell(); // Exit float editing if value was changed with cursor if (_floatEditRow != -1 && _floatPaintState != CurrentTasMovie.GetFloatState(_floatEditRow, _floatEditColumn)) { diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index b4f3437725..c0db9604ef 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -902,5 +902,19 @@ namespace BizHawk.Client.EmuHawk } } } + + private void TasView_CellDropped(object sender, InputRoll.CellEventArgs e) + { + if (e.NewCell != null && e.NewCell.RowIndex.HasValue && + !CurrentTasMovie.Markers.IsMarker(e.NewCell.RowIndex.Value)) + { + var currentMarker = CurrentTasMovie.Markers.Single(m => m.Frame == e.OldCell.RowIndex.Value); + int newFrame = e.NewCell.RowIndex.Value; + var newMarker = new TasMovieMarker(newFrame, currentMarker.Message); + CurrentTasMovie.Markers.Remove(currentMarker); + CurrentTasMovie.Markers.Add(newMarker); + RefreshDialog(); + } + } } }