-TAStudio automatically set Read-Only

-TAStudio no longer refreshes every frame if playback cursor isn't visible; slight performance boost
-Editing while in playback won't mess up the LagLog (states still do)
-Fixes to rotated display and HBar scrolling
This commit is contained in:
SuuperW 2015-03-19 19:55:38 +00:00
parent 91dc780103
commit 9328dd2f3a
7 changed files with 107 additions and 118 deletions

View File

@ -136,6 +136,9 @@ namespace BizHawk.Client.Common
{
var input = Movie.GetInputState(Global.Emulator.Frame);
if (Global.Emulator.Frame == 0) // Hacky
HandleMovieAfterFrameLoop(); // Frame 0 needs to be handled.
MovieControllerAdapter.LatchFromSource(input);
if (MultiTrack.IsActive)
{

View File

@ -46,6 +46,12 @@ namespace BizHawk.Client.Common
return; // Nothing to do
}
if (frame > LagLog.Count)
{
System.Diagnostics.Debug.Print("Lag Log error. f" + frame + ", log: " + LagLog.Count);
return; // Can this break anything?
}
if (frame >= LagLog.Count)
{
LagLog.Add(value.Value);

View File

@ -79,7 +79,9 @@ namespace BizHawk.Client.Common
States = new SortedList<int, byte[]>(limit);
if (Directory.Exists(statePath))
{
Directory.Delete(statePath, true); // To delete old files that may still exist.
}
Directory.CreateDirectory(statePath);
accessed = new List<int>();
}

View File

@ -89,7 +89,7 @@ namespace BizHawk.Client.EmuHawk
{
// Location gets calculated later (e.g. on resize)
Visible = false,
SmallChange = 1,
SmallChange = CellWidth,
LargeChange = 20
};
@ -247,6 +247,8 @@ namespace BizHawk.Client.EmuHawk
/// </summary>
[Category("Virtual")]
public event QueryItemBkColorHandler QueryItemBkColor;
[Category("Virtual")]
public event QueryRowBkColorHandler QueryRowBkColor;
/// <summary>
/// Fire the QueryItemIconHandler event which requests an icon for a given cell
@ -303,6 +305,7 @@ namespace BizHawk.Client.EmuHawk
/// Retrieve the background color for a cell
/// </summary>
public delegate void QueryItemBkColorHandler(int index, RollColumn column, ref Color color);
public delegate void QueryRowBkColorHandler(int index, ref Color color);
/// <summary>
/// Retrive the image for a given cell
@ -643,6 +646,8 @@ namespace BizHawk.Client.EmuHawk
{
return (index >= FirstVisibleRow) && (index <= LastFullyVisibleRow);
}
public bool IsPartiallyVisible(int index)
{ return (index >= FirstVisibleRow) && (index <= LastVisibleRow); }
/// <summary>
/// Gets the number of rows currently visible including partially visible rows.
@ -675,7 +680,7 @@ namespace BizHawk.Client.EmuHawk
if (HorizontalOrientation)
return VBar.Value / CellHeight;
else
return columnList.FindIndex(c => c.Right > 0);
return columnList.FindIndex(c => c.Right > HBar.Value);
}
}
@ -844,7 +849,7 @@ namespace BizHawk.Client.EmuHawk
if (HorizontalOrientation)
{
int start = 0;
int start = -VBar.Value;
Gdi.PrepDrawString(this.RotatedFont, this.ForeColor);
@ -916,15 +921,12 @@ namespace BizHawk.Client.EmuHawk
int y = 0;
if (QueryItemIcon != null)
{
x = RowsToPixels(i) + CellWidthPadding;
y = (j * CellHeight) + (CellHeightPadding * 2);
QueryItemIcon(f + startRow, columns[j], ref image);
}
if (image != null)
{
x = RowsToPixels(i) + CellWidthPadding;
y = (j * CellHeight) + (CellHeightPadding * 2);
Gdi.DrawBitmap(image, new Point(x, y), true);
}
else
@ -934,7 +936,7 @@ namespace BizHawk.Client.EmuHawk
// Center Text
x = RowsToPixels(i) + (CellWidth - text.Length * _charSize.Width) / 2;
y = (j * CellHeight) + CellHeightPadding;
y = (j * CellHeight) + CellHeightPadding - VBar.Value;
var point = new Point(x, y);
var rePrep = false;
@ -971,14 +973,10 @@ namespace BizHawk.Client.EmuHawk
int LastVisible = LastVisibleColumnIndex;
for (int j = FirstVisibleColumn; j <= LastVisible; j++) // Horizontal
{
var col = columns[j];
if (col.Left.Value < 0 || col.Left.Value > DrawWidth)
{
continue;
}
RollColumn col = columns[j];
string text;
var point = new Point(col.Left.Value + xPadding, RowsToPixels(i) + CellHeightPadding);
Point point = new Point(col.Left.Value + xPadding, RowsToPixels(i) + CellHeightPadding);
Bitmap image = null;
if (QueryItemIcon != null)
@ -988,7 +986,7 @@ namespace BizHawk.Client.EmuHawk
if (image != null)
{
Gdi.DrawBitmap(image, new Point(col.Left.Value, point.Y + CellHeightPadding), true);
Gdi.DrawBitmap(image, new Point(point.X, point.Y + CellHeightPadding), true);
}
else
{
@ -1030,7 +1028,7 @@ namespace BizHawk.Client.EmuHawk
Gdi.Line(0, 0, 0, columns.Count * CellHeight + 1);
Gdi.Line(ColumnWidth, 0, ColumnWidth, columns.Count * CellHeight + 1);
int start = 0;
int start = -VBar.Value;
foreach (var column in columns)
{
Gdi.Line(1, start, ColumnWidth, start);
@ -1149,10 +1147,8 @@ namespace BizHawk.Client.EmuHawk
/// <param name="e"></param>
private void DrawBg(PaintEventArgs e)
{
if (QueryItemBkColor != null && UseCustomBackground)
{
if (UseCustomBackground && QueryItemBkColor != null)
DoBackGroundCallback(e);
}
if (GridLines)
{
@ -1164,14 +1160,14 @@ namespace BizHawk.Client.EmuHawk
// Columns
for (int i = 1; i < VisibleRows + 1; i++)
{
var x = RowsToPixels(i);
int x = RowsToPixels(i);
Gdi.Line(x, 1, x, DrawHeight);
}
// Rows
for (int i = 0; i < columns.Count + 1; i++)
{
Gdi.Line(RowsToPixels(0) + 1, i * CellHeight, DrawWidth, i * CellHeight);
Gdi.Line(RowsToPixels(0) + 1, i * CellHeight - VBar.Value, DrawWidth, i * CellHeight - VBar.Value);
}
}
else
@ -1242,7 +1238,7 @@ namespace BizHawk.Client.EmuHawk
{
x = RowsToPixels(cell.RowIndex.Value) + 1;
w = CellWidth - 1;
y = (CellHeight * columns.IndexOf(cell.Column)) + 1; // We can't draw without row and column, so assume they exist and fail catastrophically if they don't
y = (CellHeight * columns.IndexOf(cell.Column)) + 1 - VBar.Value; // We can't draw without row and column, so assume they exist and fail catastrophically if they don't
h = CellHeight - 1;
if (x < ColumnWidth) { return; }
}
@ -1284,19 +1280,24 @@ namespace BizHawk.Client.EmuHawk
{
f += lagFrames[i];
int LastVisible = LastVisibleColumnIndex;
Color rowColor = Color.White;
if (QueryRowBkColor != null)
QueryRowBkColor(f + startIndex, ref rowColor);
for (int j = FirstVisibleColumn; j <= LastVisible; j++) // TODO: Don't query all columns
{
var color = Color.White;
QueryItemBkColor(f + startIndex, columns[j], ref color);
Color itemColor = Color.White;
QueryItemBkColor(f + startIndex, columns[j], ref itemColor);
if (itemColor == Color.White)
itemColor = rowColor;
if (color != Color.White) // An easy optimization, don't draw unless the user specified something other than the default
if (itemColor != Color.White) // An easy optimization, don't draw unless the user specified something other than the default
{
var cell = new Cell()
{
Column = columns[j],
RowIndex = i
};
DrawCellBG(color, cell);
DrawCellBG(itemColor, cell);
}
}
}
@ -1310,18 +1311,24 @@ namespace BizHawk.Client.EmuHawk
{
f += lagFrames[i];
int LastVisible = LastVisibleColumnIndex;
Color rowColor = Color.White;
if (QueryRowBkColor != null)
QueryRowBkColor(f + startRow, ref rowColor);
for (int j = FirstVisibleColumn; j <= LastVisible; j++) // Horizontal
{
var color = Color.White;
QueryItemBkColor(f + startRow, columns[j], ref color);
if (color != Color.White) // An easy optimization, don't draw unless the user specified something other than the default
Color itemColor = Color.White;
QueryItemBkColor(f + startRow, columns[j], ref itemColor);
if (itemColor == Color.White)
itemColor = rowColor;
if (itemColor != Color.White) // An easy optimization, don't draw unless the user specified something other than the default
{
var cell = new Cell
{
Column = columns[j],
RowIndex = i
};
DrawCellBG(color, cell);
DrawCellBG(itemColor, cell);
}
}
}
@ -1696,21 +1703,6 @@ namespace BizHawk.Client.EmuHawk
// TODO scroll to correct positions
if (HorizontalOrientation)
{
VBar.SmallChange = CellHeight;
HBar.SmallChange = CellWidth;
VBar.LargeChange = 10;
HBar.LargeChange = CellWidth * 20;
}
else
{
VBar.SmallChange = CellHeight;
HBar.SmallChange = 1;
VBar.LargeChange = CellHeight * 20;
HBar.LargeChange = 20;
}
ColumnChangedCallback();
RecalculateScrollBars();
@ -1802,7 +1794,7 @@ namespace BizHawk.Client.EmuHawk
{
if (HorizontalOrientation)
{
VBar.LargeChange = 10;
VBar.LargeChange = DrawHeight / 2;
HBar.Maximum = Math.Max((VisibleRows - 1) * CellHeight, HBar.Maximum);
HBar.LargeChange = (VisibleRows - 1) * CellHeight;
}
@ -1810,7 +1802,7 @@ namespace BizHawk.Client.EmuHawk
{
VBar.Maximum = Math.Max((VisibleRows - 1) * CellHeight, VBar.Maximum); // ScrollBar.Maximum is dumb
VBar.LargeChange = (VisibleRows - 1) * CellHeight;
HBar.LargeChange = 10;
HBar.LargeChange = DrawWidth / 2;
}
}
@ -1819,7 +1811,7 @@ namespace BizHawk.Client.EmuHawk
{
if (HorizontalOrientation)
{
VBar.Maximum = (((columns.Count() * CellHeight) - DrawHeight) / CellHeight) + VBar.LargeChange;
VBar.Maximum = ((columns.Count() * CellHeight) - DrawHeight) + VBar.LargeChange;
}
else
{
@ -2013,7 +2005,7 @@ namespace BizHawk.Client.EmuHawk
newCell.RowIndex = PixelsToRows(x);
}
int colIndex = (y / CellHeight);
int colIndex = (y + VBar.Value) / CellHeight;
if (colIndex >= 0 && colIndex < columns.Count)
{
newCell.Column = columns[colIndex];
@ -2077,7 +2069,7 @@ namespace BizHawk.Client.EmuHawk
/// <returns>RollColumn object that contains the x coordinate or null if none exists.</returns>
private RollColumn ColumnAtX(int x)
{
foreach (var column in _columns.VisibleColumns)
foreach (RollColumn column in _columns.VisibleColumns)
{
if (column.Left.Value - HBar.Value <= x && column.Right.Value - HBar.Value >= x)
{

View File

@ -30,15 +30,20 @@ namespace BizHawk.Client.EmuHawk
return;
}
bool refreshNeeded = false;
if (AutoadjustInputMenuItem.Checked)
AutoAdjustInput();
refreshNeeded = AutoAdjustInput();
if (TasPlaybackBox.FollowCursor)
{
SetVisibleIndex();
}
RefreshDialog();
if (TasView.IsPartiallyVisible(Global.Emulator.Frame) || TasView.IsPartiallyVisible(Global.Emulator.Frame - 1))
refreshNeeded = true;
if (refreshNeeded)
RefreshDialog();
else if (TasView.RowCount != CurrentTasMovie.InputLogLength + 1) // Perhaps not the best place to put this.
TasView.RowCount = CurrentTasMovie.InputLogLength + 1;
}
public void FastUpdate()

View File

@ -2,7 +2,9 @@
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.Collections.Generic;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
@ -41,7 +43,7 @@ namespace BizHawk.Client.EmuHawk
private bool _triggerAutoRestore; // If true, autorestore will be called on mouse up
private int? _triggerAutoRestoreFromFrame; // If set and _triggerAutoRestore is true, will call GoToFrameIfNecessary() with this value
public static Color CurrentFrame_FrameCol = Color.FromArgb(0xCFEDFC);
// public static Color CurrentFrame_FrameCol = Color.FromArgb(0xCFEDFC); Why?
public static Color CurrentFrame_InputLog = Color.FromArgb(0xB5E7F7);
public static Color GreenZone_FrameCol = Color.FromArgb(0xDDFFDD);
@ -94,77 +96,50 @@ namespace BizHawk.Client.EmuHawk
private void TasView_QueryItemBkColor(int index, InputRoll.RollColumn column, ref Color color)
{
var columnName = column.Name;
var record = CurrentTasMovie[index];
string columnName = column.Name;
if (columnName == MarkerColumnName)
{
if (VersionInfo.DeveloperBuild) // For debugging purposes, let's visually show the state frames
{
color = (record.HasState ? color = Color.FromArgb(0xEEEEEE) : Color.White);
}
{ // For debugging purposes, let's visually show the state frames
if (VersionInfo.DeveloperBuild && CurrentTasMovie.TasStateManager.HasState(index))
color = Color.FromArgb(0xEEEEEE);
else
color = Color.FromArgb(0xFEFFFF);
return;
}
if (columnName == FrameColumnName)
{
if (Emulator.Frame == index)
{
color = CurrentFrame_FrameCol;
}
else if (CurrentTasMovie.Markers.IsMarker(index))
{
if (Emulator.Frame != index && CurrentTasMovie.Markers.IsMarker(index))
color = Marker_FrameCol;
}
else if (record.Lagged.HasValue)
{
color = record.Lagged.Value ?
LagZone_FrameCol :
GreenZone_FrameCol;
}
else if (record.WasLagged.HasValue)
{
color = record.WasLagged.Value ?
LagZone_Invalidated_FrameCol :
GreenZone_Invalidated_FrameCol;
}
else
{
color = Color.White;
}
}
else if (index == _floatEditRow && columnName == _floatEditColumn)
{ // SuuperW: Analog editing is indicated by a color change.
color = AnalogEdit_Col;
}
}
private void TasView_QueryRowBkColor(int index, ref Color color)
{
TasMovieRecord record = CurrentTasMovie[index];
if (Emulator.Frame == index)
{
color = CurrentFrame_InputLog;
}
else if (record.Lagged.HasValue)
{
color = record.Lagged.Value ?
LagZone_InputLog :
GreenZone_InputLog;
}
else if (record.WasLagged.HasValue)
{
color = record.WasLagged.Value ?
LagZone_Invalidated_InputLog :
GreenZone_Invalidated_FrameCol;
}
else
{
// SuuperW: Analog editing is indicated by a color change.
if (index == _floatEditRow && columnName == _floatEditColumn)
{
color = AnalogEdit_Col;
return;
}
if (Emulator.Frame == index)
{
color = CurrentFrame_InputLog;
}
else
{
if (record.Lagged.HasValue)
{
color = record.Lagged.Value ?
LagZone_InputLog :
GreenZone_InputLog;
}
else if (record.WasLagged.HasValue)
{
color = record.WasLagged.Value ?
LagZone_Invalidated_InputLog :
GreenZone_Invalidated_FrameCol;
}
else
{
color = Color.FromArgb(0xFFFEEE);
}
}
color = Color.FromArgb(0xFFFEEE);
}
}

View File

@ -82,6 +82,7 @@ namespace BizHawk.Client.EmuHawk
MarkerControl.Emulator = this.Emulator;
TasView.QueryItemText += TasView_QueryItemText;
TasView.QueryItemBkColor += TasView_QueryItemBkColor;
TasView.QueryRowBkColor += TasView_QueryRowBkColor;
TasView.QueryItemIcon += TasView_QueryItemIcon;
TasView.QueryFrameLag += TasView_QueryFrameLag;
TasView.InputPaintingMode = Settings.DrawInput;
@ -296,6 +297,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.MainForm.ClearRewindData();
Global.Config.MovieEndAction = MovieEndAction.Record;
GlobalWin.MainForm.SetMainformMovieInfo();
Global.MovieSession.ReadOnly = true;
}
#endregion
@ -522,7 +524,7 @@ namespace BizHawk.Client.EmuHawk
if (MarkerControl != null)
MarkerControl.UpdateValues();
if (undoForm != null)
if (undoForm != null && !undoForm.IsDisposed)
undoForm.UpdateValues();
}
@ -776,7 +778,7 @@ namespace BizHawk.Client.EmuHawk
}
#endregion
private void AutoAdjustInput()
private bool AutoAdjustInput()
{
TasMovieRecord lagLog = CurrentTasMovie[Emulator.Frame - 1]; // Minus one because get frame is +1;
bool isLag = Emulator.AsInputPollable().IsLagFrame;
@ -788,13 +790,17 @@ namespace BizHawk.Client.EmuHawk
CurrentTasMovie.RemoveFrame(Global.Emulator.Frame - 1);
CurrentTasMovie.RemoveLagHistory(Global.Emulator.Frame); // Set frame is not +1. [should change?]
GoToFrame(Emulator.Frame - 1);
return true;
}
else if (!lagLog.WasLagged.Value && isLag)
{ // (it shouldn't need to rewind, since the inserted input wasn't polled)
CurrentTasMovie.InsertInput(Global.Emulator.Frame - 1, CurrentTasMovie.GetInputLogEntry(Emulator.Frame - 2));
CurrentTasMovie.InsertLagHistory(Global.Emulator.Frame - 1, true);
return true;
}
}
return false;
}
private void TAStudio_KeyDown(object sender, KeyEventArgs e)