2013-12-05 20:06:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2015-07-25 16:01:26 +00:00
|
|
|
|
using System.Windows.Media;
|
2015-07-19 02:20:38 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
using BizHawk.Client.Common;
|
2015-07-19 14:37:53 +00:00
|
|
|
|
using BizHawk.Common;
|
2015-07-19 02:20:38 +00:00
|
|
|
|
|
2013-12-05 20:06:06 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
|
|
|
|
{
|
|
|
|
|
public partial class BookmarksBranchesBox : UserControl
|
|
|
|
|
{
|
2015-07-22 21:26:25 +00:00
|
|
|
|
private const string BranchNumberColumnName = "BranchNumberColumn";
|
|
|
|
|
private const string FrameColumnName = "FrameColumn";
|
|
|
|
|
private const string TimeColumnName = "TimeColumn";
|
|
|
|
|
|
2015-07-19 14:50:14 +00:00
|
|
|
|
private readonly PlatformFrameRates FrameRates = new PlatformFrameRates();
|
2015-07-18 20:13:38 +00:00
|
|
|
|
public TAStudio Tastudio { get; set; }
|
|
|
|
|
|
2015-07-19 02:20:38 +00:00
|
|
|
|
public TasBranchCollection Branches
|
|
|
|
|
{
|
|
|
|
|
get { return Tastudio.CurrentTasMovie.TasBranches; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 20:06:06 +00:00
|
|
|
|
public BookmarksBranchesBox()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2015-07-22 21:26:25 +00:00
|
|
|
|
|
|
|
|
|
BranchView.AllColumns.AddRange(new InputRoll.RollColumn[]
|
|
|
|
|
{
|
|
|
|
|
new InputRoll.RollColumn
|
|
|
|
|
{
|
|
|
|
|
Name = BranchNumberColumnName,
|
|
|
|
|
Text = "#",
|
|
|
|
|
Width = 30
|
|
|
|
|
},
|
|
|
|
|
new InputRoll.RollColumn
|
|
|
|
|
{
|
|
|
|
|
Name = FrameColumnName,
|
|
|
|
|
Text = "Frame",
|
2015-07-25 20:28:51 +00:00
|
|
|
|
Width = 64
|
2015-07-22 21:26:25 +00:00
|
|
|
|
},
|
|
|
|
|
new InputRoll.RollColumn
|
|
|
|
|
{
|
|
|
|
|
Name = TimeColumnName,
|
|
|
|
|
Text = "Length",
|
2015-07-25 20:28:51 +00:00
|
|
|
|
Width = 90
|
2015-07-22 21:26:25 +00:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2015-07-18 20:10:56 +00:00
|
|
|
|
BranchView.QueryItemText += QueryItemText;
|
|
|
|
|
BranchView.QueryItemBkColor += QueryItemBkColor;
|
2013-12-05 20:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 02:20:38 +00:00
|
|
|
|
public TasBranch SelectedBranch
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2015-07-26 03:42:50 +00:00
|
|
|
|
if (BranchView.AnyRowsSelected)
|
2015-07-19 02:20:38 +00:00
|
|
|
|
{
|
2015-07-22 21:26:25 +00:00
|
|
|
|
return Branches[BranchView.SelectedRows.First()];
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 19:14:33 +00:00
|
|
|
|
private int CurrentBranch = -1;
|
|
|
|
|
|
2015-07-22 21:26:25 +00:00
|
|
|
|
private void QueryItemText(int index, InputRoll.RollColumn column, out string text)
|
2013-12-05 20:06:06 +00:00
|
|
|
|
{
|
2015-07-18 20:10:56 +00:00
|
|
|
|
text = string.Empty;
|
2015-07-19 02:20:38 +00:00
|
|
|
|
|
|
|
|
|
if (index >= Tastudio.CurrentTasMovie.TasBranches.Count)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 21:26:25 +00:00
|
|
|
|
switch (column.Name)
|
2015-07-19 02:20:38 +00:00
|
|
|
|
{
|
2015-07-22 21:26:25 +00:00
|
|
|
|
case BranchNumberColumnName:
|
2015-07-19 02:20:38 +00:00
|
|
|
|
text = index.ToString();
|
|
|
|
|
break;
|
2015-07-22 21:26:25 +00:00
|
|
|
|
case FrameColumnName:
|
2015-07-19 02:20:38 +00:00
|
|
|
|
text = Branches[index].Frame.ToString();
|
|
|
|
|
break;
|
2015-07-22 21:26:25 +00:00
|
|
|
|
case TimeColumnName:
|
2015-07-19 14:50:14 +00:00
|
|
|
|
text = MovieTime(Branches[index].Frame).ToString(@"hh\:mm\:ss\.fff");
|
2015-07-19 02:20:38 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2015-07-18 20:10:56 +00:00
|
|
|
|
}
|
2013-12-05 20:06:06 +00:00
|
|
|
|
|
2015-07-22 21:26:25 +00:00
|
|
|
|
private void QueryItemBkColor(int index, InputRoll.RollColumn column, ref Color color)
|
2015-07-18 20:10:56 +00:00
|
|
|
|
{
|
2015-07-22 19:14:33 +00:00
|
|
|
|
if (index == CurrentBranch)
|
|
|
|
|
color = SystemColors.HotTrack;
|
2015-07-25 16:01:26 +00:00
|
|
|
|
|
|
|
|
|
// Highlight the branch cell a little, if hovering over it
|
|
|
|
|
if (BranchView.CurrentCellIsDataCell &&
|
|
|
|
|
BranchView.CurrentCell.Column.Name == BranchNumberColumnName &&
|
|
|
|
|
column.Name == BranchNumberColumnName &&
|
|
|
|
|
index == BranchView.CurrentCell.RowIndex)
|
|
|
|
|
{
|
|
|
|
|
color = Color.FromArgb((byte)(color.A - 24), (byte)(color.R - 24), (byte)(color.G - 24), (byte)(color.B - 24));
|
|
|
|
|
}
|
2013-12-05 20:06:06 +00:00
|
|
|
|
}
|
2015-07-19 02:20:38 +00:00
|
|
|
|
|
|
|
|
|
private void AddContextMenu_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-07-25 19:42:28 +00:00
|
|
|
|
Branch();
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BranchView_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2015-07-22 19:14:33 +00:00
|
|
|
|
LoadSelectedBranch();
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
2015-07-22 21:26:25 +00:00
|
|
|
|
|
2015-07-19 14:37:53 +00:00
|
|
|
|
private void LoadBranchContextMenuItem_Click(object sender, EventArgs e)
|
2015-07-22 19:14:33 +00:00
|
|
|
|
{
|
|
|
|
|
LoadSelectedBranch();
|
|
|
|
|
}
|
2015-07-22 21:26:25 +00:00
|
|
|
|
|
2015-07-22 19:14:33 +00:00
|
|
|
|
private void LoadSelectedBranch()
|
2015-07-19 14:37:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (SelectedBranch != null)
|
|
|
|
|
{
|
2015-07-22 21:26:25 +00:00
|
|
|
|
CurrentBranch = BranchView.SelectedRows.First();
|
2015-07-22 19:14:33 +00:00
|
|
|
|
BranchView.Refresh();
|
2015-07-19 14:37:53 +00:00
|
|
|
|
LoadBranch(SelectedBranch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 02:20:38 +00:00
|
|
|
|
private void BranchesContextMenu_Opening(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
2015-07-26 01:56:24 +00:00
|
|
|
|
UpdateBranchContextMenuItem.Enabled =
|
2015-07-22 19:14:33 +00:00
|
|
|
|
RemoveBranchContextMenuItem.Enabled =
|
2015-07-19 14:37:53 +00:00
|
|
|
|
LoadBranchContextMenuItem.Enabled =
|
|
|
|
|
SelectedBranch != null;
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveBranchContextMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (SelectedBranch != null)
|
|
|
|
|
{
|
2015-07-26 00:55:23 +00:00
|
|
|
|
int index = Branches.IndexOf(SelectedBranch);
|
|
|
|
|
if (index == CurrentBranch)
|
2015-07-25 16:07:22 +00:00
|
|
|
|
{
|
|
|
|
|
CurrentBranch = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 02:20:38 +00:00
|
|
|
|
Branches.Remove(SelectedBranch);
|
2015-07-22 21:26:25 +00:00
|
|
|
|
BranchView.RowCount = Branches.Count;
|
2015-07-26 00:55:23 +00:00
|
|
|
|
|
|
|
|
|
if (index == BranchView.SelectedRows.FirstOrDefault())
|
|
|
|
|
{
|
|
|
|
|
BranchView.ClearSelectedRows();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 21:26:25 +00:00
|
|
|
|
BranchView.Refresh();
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadBranch(TasBranch branch)
|
|
|
|
|
{
|
2015-07-19 14:37:53 +00:00
|
|
|
|
Tastudio.CurrentTasMovie.LoadBranch(branch);
|
|
|
|
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
|
|
|
|
var stateInfo = new KeyValuePair<int, byte[]>(branch.Frame, branch.CoreData);
|
|
|
|
|
Tastudio.LoadState(stateInfo);
|
2015-07-22 00:31:51 +00:00
|
|
|
|
QuickBmpFile.Copy(new BitmapBufferVideoProvider(branch.OSDFrameBuffer), Global.Emulator.VideoProvider());
|
2015-07-19 14:37:53 +00:00
|
|
|
|
GlobalWin.MainForm.PauseEmulator();
|
|
|
|
|
GlobalWin.MainForm.PauseOnFrame = null;
|
|
|
|
|
Tastudio.RefreshDialog();
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
2015-07-19 14:50:14 +00:00
|
|
|
|
|
2015-07-25 19:42:28 +00:00
|
|
|
|
// TODO: copy pasted from PlatformFrameRates
|
2015-07-19 14:50:14 +00:00
|
|
|
|
|
|
|
|
|
private TimeSpan MovieTime(int frameCount)
|
|
|
|
|
{
|
|
|
|
|
var dblseconds = GetSeconds(frameCount);
|
|
|
|
|
var seconds = (int)(dblseconds % 60);
|
|
|
|
|
var days = seconds / 86400;
|
|
|
|
|
var hours = seconds / 3600;
|
|
|
|
|
var minutes = (seconds / 60) % 60;
|
|
|
|
|
var milliseconds = (int)((dblseconds - seconds) * 1000);
|
|
|
|
|
return new TimeSpan(days, hours, minutes, seconds, milliseconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double GetSeconds(int frameCount)
|
|
|
|
|
{
|
|
|
|
|
double frames = frameCount;
|
|
|
|
|
|
|
|
|
|
if (frames < 1)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return frames / Fps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double Fps()
|
|
|
|
|
{
|
2015-07-22 19:31:47 +00:00
|
|
|
|
TasMovie movie = Tastudio.CurrentTasMovie;
|
|
|
|
|
string system = movie.HeaderEntries[HeaderKeys.PLATFORM];
|
|
|
|
|
bool pal = movie.HeaderEntries.ContainsKey(HeaderKeys.PAL) &&
|
2015-07-19 14:50:14 +00:00
|
|
|
|
movie.HeaderEntries[HeaderKeys.PAL] == "1";
|
|
|
|
|
|
|
|
|
|
return FrameRates[system, pal];
|
|
|
|
|
}
|
|
|
|
|
// ***************************
|
2015-07-20 00:49:23 +00:00
|
|
|
|
|
|
|
|
|
public void UpdateValues()
|
|
|
|
|
{
|
2015-07-22 21:26:25 +00:00
|
|
|
|
BranchView.RowCount = Branches.Count;
|
2015-07-20 00:49:23 +00:00
|
|
|
|
}
|
2015-07-20 01:57:41 +00:00
|
|
|
|
|
|
|
|
|
public void Branch()
|
2015-07-26 01:56:24 +00:00
|
|
|
|
{
|
|
|
|
|
var branch = CreateBranch();
|
|
|
|
|
Branches.Add(branch);
|
|
|
|
|
BranchView.RowCount = Branches.Count;
|
|
|
|
|
BranchView.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TasBranch CreateBranch()
|
2015-07-20 01:57:41 +00:00
|
|
|
|
{
|
2015-07-25 19:42:28 +00:00
|
|
|
|
// TODO: don't use Global.Emulator
|
2015-07-26 01:56:24 +00:00
|
|
|
|
return new TasBranch
|
2015-07-25 19:42:28 +00:00
|
|
|
|
{
|
|
|
|
|
Frame = Global.Emulator.Frame,
|
|
|
|
|
CoreData = (byte[])((Global.Emulator as IStatable).SaveStateBinary().Clone()),
|
|
|
|
|
InputLog = Tastudio.CurrentTasMovie.InputLog.ToList(),
|
|
|
|
|
OSDFrameBuffer = GlobalWin.MainForm.CaptureOSD(),
|
|
|
|
|
LagLog = Tastudio.CurrentTasMovie.TasLagLog.Clone(),
|
|
|
|
|
ChangeLog = new TasMovieChangeLog(Tastudio.CurrentTasMovie)
|
|
|
|
|
};
|
2015-07-20 01:57:41 +00:00
|
|
|
|
}
|
2015-07-25 12:40:17 +00:00
|
|
|
|
|
|
|
|
|
private void BranchView_CellHovered(object sender, InputRoll.CellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.NewCell != null && e.NewCell.RowIndex.HasValue && e.NewCell.Column != null && e.NewCell.RowIndex < Branches.Count)
|
|
|
|
|
{
|
|
|
|
|
if (e.NewCell.Column.Name == BranchNumberColumnName)
|
|
|
|
|
{
|
|
|
|
|
ScreenShotPopUp(Branches[e.NewCell.RowIndex.Value], e.NewCell.RowIndex.Value);
|
|
|
|
|
}
|
2015-07-25 16:01:26 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CloseScreenShotPopUp();
|
|
|
|
|
}
|
2015-07-25 12:40:17 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CloseScreenShotPopUp();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BranchView_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (BranchView.CurrentCell == null || !BranchView.CurrentCell.RowIndex.HasValue || BranchView.CurrentCell.Column == null)
|
|
|
|
|
{
|
|
|
|
|
CloseScreenShotPopUp();
|
|
|
|
|
}
|
2015-07-25 16:01:26 +00:00
|
|
|
|
else if (BranchView.CurrentCell.Column.Name == BranchNumberColumnName)
|
|
|
|
|
{
|
|
|
|
|
BranchView.Refresh();
|
|
|
|
|
}
|
2015-07-25 12:40:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CloseScreenShotPopUp()
|
|
|
|
|
{
|
|
|
|
|
Tastudio.ScreenshotControl.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 16:01:26 +00:00
|
|
|
|
private void BranchView_MouseLeave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Tastudio.ScreenshotControl.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 12:40:17 +00:00
|
|
|
|
private void ScreenShotPopUp(TasBranch branch, int index)
|
|
|
|
|
{
|
2015-07-26 01:31:06 +00:00
|
|
|
|
Point locationOnForm = this.FindForm().PointToClient(
|
|
|
|
|
this.Parent.PointToScreen(this.Location));
|
|
|
|
|
|
|
|
|
|
int x = locationOnForm.X - Tastudio.ScreenshotControl.Width;
|
|
|
|
|
int y = locationOnForm.Y + (BranchView.RowHeight * index);
|
2015-07-25 15:08:23 +00:00
|
|
|
|
|
|
|
|
|
Tastudio.ScreenshotControl.Location = new Point(x, y);
|
|
|
|
|
|
2015-07-25 12:40:17 +00:00
|
|
|
|
Tastudio.ScreenshotControl.Visible = true;
|
|
|
|
|
Tastudio.ScreenshotControl.Branch = branch;
|
2015-07-25 15:08:23 +00:00
|
|
|
|
Tastudio.ScreenshotControl.Refresh();
|
2015-07-25 12:40:17 +00:00
|
|
|
|
}
|
2015-07-26 01:56:24 +00:00
|
|
|
|
|
|
|
|
|
private void UpdateBranchContextMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (SelectedBranch != null)
|
|
|
|
|
{
|
|
|
|
|
UpdateBranch(SelectedBranch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBranch(TasBranch branch)
|
|
|
|
|
{
|
|
|
|
|
var index = Branches.IndexOf(branch);
|
|
|
|
|
|
|
|
|
|
var newbranch = CreateBranch();
|
|
|
|
|
Branches.Insert(index, newbranch);
|
|
|
|
|
|
|
|
|
|
Branches.Remove(branch);
|
|
|
|
|
BranchView.Refresh();
|
|
|
|
|
}
|
2013-12-05 20:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|