2018-07-11 18:07:13 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class frmHistoryViewer : BaseForm
|
|
|
|
|
{
|
|
|
|
|
private Thread _emuThread;
|
|
|
|
|
private bool _paused = true;
|
|
|
|
|
|
|
|
|
|
public frmHistoryViewer()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2018-07-13 22:19:26 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnShown(e);
|
2018-07-11 18:07:13 -04:00
|
|
|
|
|
|
|
|
|
InteropEmu.InitializeHistoryViewer(this.Handle, ctrlRenderer.Handle);
|
|
|
|
|
trkPosition.Maximum = (int)(InteropEmu.GetHistoryViewerTotalFrameCount() / 60);
|
|
|
|
|
UpdatePositionLabel(0);
|
2018-07-13 22:19:26 -04:00
|
|
|
|
InteropEmu.Pause(InteropEmu.ConsoleId.HistoryViewer);
|
2018-07-11 18:07:13 -04:00
|
|
|
|
StartEmuThread();
|
|
|
|
|
tmrUpdatePosition.Start();
|
2018-07-13 22:19:26 -04:00
|
|
|
|
|
|
|
|
|
btnPausePlay.Focus();
|
2018-07-11 18:07:13 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
tmrUpdatePosition.Stop();
|
|
|
|
|
InteropEmu.ReleaseHistoryViewer();
|
|
|
|
|
base.OnClosing(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartEmuThread()
|
|
|
|
|
{
|
|
|
|
|
if(_emuThread == null) {
|
|
|
|
|
_emuThread = new Thread(() => {
|
|
|
|
|
try {
|
|
|
|
|
InteropEmu.RunHistoryViewer();
|
|
|
|
|
_emuThread = null;
|
|
|
|
|
} catch(Exception ex) {
|
|
|
|
|
MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString());
|
|
|
|
|
_emuThread = null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_emuThread.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnPausePlay_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(trkPosition.Value == trkPosition.Maximum) {
|
|
|
|
|
InteropEmu.SetHistoryViewerPosition(0);
|
|
|
|
|
}
|
2018-07-13 22:19:26 -04:00
|
|
|
|
if(_paused) {
|
|
|
|
|
InteropEmu.Resume(InteropEmu.ConsoleId.HistoryViewer);
|
|
|
|
|
} else {
|
|
|
|
|
InteropEmu.Pause(InteropEmu.ConsoleId.HistoryViewer);
|
|
|
|
|
}
|
2018-07-11 18:07:13 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void trkPosition_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.SetHistoryViewerPosition((UInt32)trkPosition.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tmrUpdatePosition_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-07-13 22:19:26 -04:00
|
|
|
|
_paused = InteropEmu.IsPaused(InteropEmu.ConsoleId.HistoryViewer);
|
2018-07-11 18:07:13 -04:00
|
|
|
|
if(_paused) {
|
|
|
|
|
btnPausePlay.Image = Properties.Resources.Play;
|
|
|
|
|
} else {
|
|
|
|
|
btnPausePlay.Image = Properties.Resources.Pause;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UInt32 positionInSeconds = InteropEmu.GetHistoryViewerPosition() / 2;
|
|
|
|
|
UpdatePositionLabel(positionInSeconds);
|
|
|
|
|
|
|
|
|
|
if(positionInSeconds <= trkPosition.Maximum) {
|
|
|
|
|
trkPosition.ValueChanged -= trkPosition_ValueChanged;
|
|
|
|
|
trkPosition.Value = (int)positionInSeconds;
|
|
|
|
|
trkPosition.ValueChanged += trkPosition_ValueChanged;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePositionLabel(uint positionInSeconds)
|
|
|
|
|
{
|
|
|
|
|
TimeSpan currentPosition = new TimeSpan(0, 0, (int)positionInSeconds);
|
|
|
|
|
TimeSpan totalLength = new TimeSpan(0, 0, trkPosition.Maximum);
|
|
|
|
|
lblPosition.Text = (
|
|
|
|
|
currentPosition.Minutes.ToString("00") + ":" + currentPosition.Seconds.ToString("00")
|
|
|
|
|
+ " / " +
|
|
|
|
|
totalLength.Minutes.ToString("00") + ":" + totalLength.Seconds.ToString("00")
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|