Migrate RAM Search to PAVLV

This commit is contained in:
YoshiRulz 2019-10-25 22:04:56 +10:00
parent 0f687ff84e
commit b5d188ad5e
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
7 changed files with 127 additions and 56 deletions

View File

@ -163,6 +163,16 @@ namespace BizHawk.Client.EmuHawk
} }
} }
/// <summary>
/// Compatibility method from VirtualListView
/// </summary>
/// <param name="index"></param>
public void ensureVisible()
{
if (_selectedItems.Count != 0)
MakeIndexVisible(_selectedItems.Last().RowIndex.Value);
}
public void ClearSelectedRows() public void ClearSelectedRows()
{ {
_selectedItems.Clear(); _selectedItems.Clear();

View File

@ -75,13 +75,17 @@ namespace BizHawk.Client.EmuHawk
if (BorderSize > 0) if (BorderSize > 0)
{ {
// paint parent border // apparently mono can sometimes call OnPaint before attached to the parent??
using (var gParent = this.Parent.CreateGraphics()) if (this.Parent != null)
{ {
Pen borderPen = new Pen(BorderColor); // paint parent border
for (int b = 1, c = 1; b <= BorderSize; b++, c += 2) using (var gParent = this.Parent.CreateGraphics())
{ {
gParent.DrawRectangle(borderPen, this.Left - b, this.Top - b, this.Width + c, this.Height + c); Pen borderPen = new Pen(BorderColor);
for (int b = 1, c = 1; b <= BorderSize; b++, c += 2)
{
gParent.DrawRectangle(borderPen, this.Left - b, this.Top - b, this.Width + c, this.Height + c);
}
} }
} }
} }
@ -99,7 +103,8 @@ namespace BizHawk.Client.EmuHawk
QueryItemTextAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, out text, ref offsetX, ref offsetY); QueryItemTextAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, out text, ref offsetX, ref offsetY);
Color bgColor = ColumnHeaderBackgroundColor; Color bgColor = ColumnHeaderBackgroundColor;
QueryItemBkColor?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, ref bgColor); QueryItemBkColor?.Invoke(_draggingCell.RowIndex.Value, _columns.IndexOf(_draggingCell.Column), ref bgColor);
QueryItemBkColorAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, ref bgColor);
int x1 = _currentX.Value - (_draggingCell.Column.Width.Value / 2); int x1 = _currentX.Value - (_draggingCell.Column.Width.Value / 2);
int y1 = _currentY.Value - (CellHeight / 2); int y1 = _currentY.Value - (CellHeight / 2);
@ -124,7 +129,8 @@ namespace BizHawk.Client.EmuHawk
QueryItemTextAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, out text, ref offsetX, ref offsetY); QueryItemTextAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, out text, ref offsetX, ref offsetY);
Color bgColor = CellBackgroundColor; Color bgColor = CellBackgroundColor;
QueryItemBkColor?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, ref bgColor); QueryItemBkColor?.Invoke(_draggingCell.RowIndex.Value, _columns.IndexOf(_draggingCell.Column), ref bgColor);
QueryItemBkColorAdvanced?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, ref bgColor);
int x1 = _currentX.Value - (_draggingCell.Column.Width.Value / 2); int x1 = _currentX.Value - (_draggingCell.Column.Width.Value / 2);
int y1 = _currentY.Value - (CellHeight / 2); int y1 = _currentY.Value - (CellHeight / 2);
@ -144,7 +150,7 @@ namespace BizHawk.Client.EmuHawk
foreach (var column in visibleColumns) foreach (var column in visibleColumns)
{ {
var point = new Point(column.Left.Value + 2 * CellWidthPadding - _hBar.Value, CellHeightPadding); // TODO: fix this CellPadding issue (2 * CellPadding vs just CellPadding) var point = new Point(column.Left.Value + CellWidthPadding - _hBar.Value, CellHeightPadding);
string t = column.Text; string t = column.Text;
ResizeTextToFit(ref t, column.Width.Value, ColumnHeaderFont); ResizeTextToFit(ref t, column.Width.Value, ColumnHeaderFont);
@ -448,7 +454,8 @@ namespace BizHawk.Client.EmuHawk
} }
Color cellColor = rowColor; Color cellColor = rowColor;
QueryItemBkColor?.Invoke(cell.RowIndex.Value, cell.Column, ref cellColor); QueryItemBkColor?.Invoke(cell.RowIndex.Value, _columns.IndexOf(cell.Column), ref cellColor);
QueryItemBkColorAdvanced?.Invoke(cell.RowIndex.Value, cell.Column, ref cellColor);
// Alpha layering for cell before selection // Alpha layering for cell before selection
float alpha = (float)cellColor.A / 255; float alpha = (float)cellColor.A / 255;
@ -494,7 +501,8 @@ namespace BizHawk.Client.EmuHawk
for (int j = FirstVisibleColumn; j <= lastVisible; j++) // Horizontal for (int j = FirstVisibleColumn; j <= lastVisible; j++) // Horizontal
{ {
Color itemColor = CellBackgroundColor; Color itemColor = CellBackgroundColor;
QueryItemBkColor(f + startIndex, visibleColumns[j], ref itemColor); QueryItemBkColor?.Invoke(f + startIndex, _columns.IndexOf(visibleColumns[j]), ref itemColor);
QueryItemBkColorAdvanced?.Invoke(f + startIndex, visibleColumns[j], ref itemColor);
if (itemColor == CellBackgroundColor) if (itemColor == CellBackgroundColor)
{ {
itemColor = rowColor; itemColor = rowColor;

View File

@ -36,6 +36,12 @@ namespace BizHawk.Client.EmuHawk
[Category("Virtual")] [Category("Virtual")]
public event QueryItemBkColorHandler QueryItemBkColor; public event QueryItemBkColorHandler QueryItemBkColor;
/// <summary>
/// Fire the <see cref="QueryItemBkColorAdvanced"/> event which requests the background color for the passed cell
/// </summary>
[Category("Virtual")]
public event QueryItemBkColorHandlerAdvanced QueryItemBkColorAdvanced;
[Category("Virtual")] [Category("Virtual")]
public event QueryRowBkColorHandler QueryRowBkColor; public event QueryRowBkColorHandler QueryRowBkColor;
@ -110,7 +116,8 @@ namespace BizHawk.Client.EmuHawk
/// <summary> /// <summary>
/// Retrieve the background color for a cell /// Retrieve the background color for a cell
/// </summary> /// </summary>
public delegate void QueryItemBkColorHandler(int index, ListColumn column, ref Color color); public delegate void QueryItemBkColorHandlerAdvanced(int index, ListColumn column, ref Color color);
public delegate void QueryItemBkColorHandler(int index, int column, ref Color color);
public delegate void QueryRowBkColorHandler(int index, ref Color color); public delegate void QueryRowBkColorHandler(int index, ref Color color);
/// <summary> /// <summary>

View File

@ -34,13 +34,13 @@ namespace BizHawk.Client.EmuHawk
public PlatformAgnosticVirtualListView() public PlatformAgnosticVirtualListView()
{ {
ColumnHeaderFont = new Font("Arial", 8, FontStyle.Bold); ColumnHeaderFont = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Bold, GraphicsUnit.Point);
ColumnHeaderFontColor = Color.Black; ColumnHeaderFontColor = Color.Black;
ColumnHeaderBackgroundColor = Color.LightGray; ColumnHeaderBackgroundColor = Color.LightGray;
ColumnHeaderBackgroundHighlightColor = SystemColors.HighlightText; ColumnHeaderBackgroundHighlightColor = SystemColors.HighlightText;
ColumnHeaderOutlineColor = Color.Black; ColumnHeaderOutlineColor = Color.Black;
CellFont = new Font("Arial", 8, FontStyle.Regular); CellFont = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point);
CellFontColor = Color.Black; CellFontColor = Color.Black;
CellBackgroundColor = Color.White; CellBackgroundColor = Color.White;
CellBackgroundHighlightColor = Color.Blue; CellBackgroundHighlightColor = Color.Blue;

View File

@ -119,6 +119,21 @@ namespace BizHawk.Client.EmuHawk
} }
} }
protected void LoadColumnInfo(PlatformAgnosticVirtualListView listView, ToolDialogSettings.ColumnList columns)
{
listView.AllColumns.Clear();
var cl = columns
.Where(c => c.Visible)
.OrderBy(c => c.Index);
foreach (var column in cl)
{
string colText = column.Name.Replace("Column", "");
listView.AddColumn(column.Name, colText, column.Width, PlatformAgnosticVirtualListView.ListColumn.InputType.Text);
}
}
protected void SaveColumnInfo(VirtualListView listview, ToolDialogSettings.ColumnList columns) protected void SaveColumnInfo(VirtualListView listview, ToolDialogSettings.ColumnList columns)
{ {
foreach (ColumnHeader column in listview.Columns) foreach (ColumnHeader column in listview.Columns)
@ -128,6 +143,15 @@ namespace BizHawk.Client.EmuHawk
} }
} }
protected void SaveColumnInfo(PlatformAgnosticVirtualListView listview, ToolDialogSettings.ColumnList columns)
{
foreach (var column in listview.AllColumns)
{
columns[column.Name].Index = listview.AllColumns.IndexOf(column);
columns[column.Name].Width = column.Width.Value;
}
}
protected void RefreshFloatingWindowControl(bool floatingWindow) protected void RefreshFloatingWindowControl(bool floatingWindow)
{ {
Owner = floatingWindow ? null : GlobalWin.MainForm; Owner = floatingWindow ? null : GlobalWin.MainForm;

View File

@ -32,7 +32,7 @@
System.Windows.Forms.ToolStripMenuItem SearchMenuItem; System.Windows.Forms.ToolStripMenuItem SearchMenuItem;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RamSearch)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RamSearch));
this.TotalSearchLabel = new System.Windows.Forms.Label(); this.TotalSearchLabel = new System.Windows.Forms.Label();
this.WatchListView = new BizHawk.Client.EmuHawk.VirtualListView(); this.WatchListView = new BizHawk.Client.EmuHawk.PlatformAgnosticVirtualListView();
this.AddressColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.AddressColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ValueColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ValueColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.PreviousColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.PreviousColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@ -211,13 +211,10 @@
this.WatchListView.UseCustomBackground = true; this.WatchListView.UseCustomBackground = true;
this.WatchListView.View = System.Windows.Forms.View.Details; this.WatchListView.View = System.Windows.Forms.View.Details;
this.WatchListView.VirtualMode = true; this.WatchListView.VirtualMode = true;
this.WatchListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.WatchListView_ColumnClick);
this.WatchListView.SelectedIndexChanged += new System.EventHandler(this.WatchListView_SelectedIndexChanged); this.WatchListView.SelectedIndexChanged += new System.EventHandler(this.WatchListView_SelectedIndexChanged);
this.WatchListView.VirtualItemsSelectionRangeChanged += new System.Windows.Forms.ListViewVirtualItemsSelectionRangeChangedEventHandler(this.WatchListView_VirtualItemsSelectionRangeChanged);
this.WatchListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.NewRamSearch_DragDrop); this.WatchListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.NewRamSearch_DragDrop);
this.WatchListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.DragEnterWrapper); this.WatchListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.DragEnterWrapper);
this.WatchListView.Enter += new System.EventHandler(this.WatchListView_Enter); this.WatchListView.Enter += new System.EventHandler(this.WatchListView_Enter);
this.WatchListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.WatchListView_KeyDown);
this.WatchListView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.WatchListView_MouseDoubleClick); this.WatchListView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.WatchListView_MouseDoubleClick);
// //
// AddressColumn // AddressColumn
@ -1422,7 +1419,7 @@
#endregion #endregion
private System.Windows.Forms.Label TotalSearchLabel; private System.Windows.Forms.Label TotalSearchLabel;
VirtualListView WatchListView; BizHawk.Client.EmuHawk.PlatformAgnosticVirtualListView WatchListView;
private System.Windows.Forms.ColumnHeader AddressColumn; private System.Windows.Forms.ColumnHeader AddressColumn;
private System.Windows.Forms.ColumnHeader ValueColumn; private System.Windows.Forms.ColumnHeader ValueColumn;
private System.Windows.Forms.ColumnHeader PreviousColumn; private System.Windows.Forms.ColumnHeader PreviousColumn;

View File

@ -51,9 +51,9 @@ namespace BizHawk.Client.EmuHawk
SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
InitializeComponent(); InitializeComponent();
WatchListView.QueryItemText += ListView_QueryItemText;
WatchListView.QueryItemBkColor += ListView_QueryItemBkColor; SetupListViewSettings();
WatchListView.VirtualMode = true;
Closing += (o, e) => SaveConfigSettings(); Closing += (o, e) => SaveConfigSettings();
_sortedColumn = ""; _sortedColumn = "";
@ -62,6 +62,32 @@ namespace BizHawk.Client.EmuHawk
Settings = new RamSearchSettings(); Settings = new RamSearchSettings();
} }
private void SetupListViewSettings()
{
WatchListView.BorderColor = System.Drawing.Color.Black;
WatchListView.BorderSize = 1;
WatchListView.MultiSelect = true;
WatchListView.CellWidthPadding = 2;
WatchListView.CellHeightPadding = 1;
WatchListView.ScrollSpeed = 3;
WatchListView.AllowColumnResize = true;
WatchListView.AllowColumnReorder = true;
WatchListView.ColumnHeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 7.7F);
WatchListView.ColumnHeaderFontColor = System.Drawing.Color.Black;
WatchListView.ColumnHeaderBackgroundColor = System.Drawing.Color.White;
WatchListView.ColumnHeaderBackgroundHighlightColor = System.Drawing.Color.LightSteelBlue;
WatchListView.ColumnHeaderOutlineColor = System.Drawing.Color.LightGray;
WatchListView.CellFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point);
WatchListView.CellFontColor = System.Drawing.Color.Black;
WatchListView.CellBackgroundColor = System.Drawing.Color.White;
WatchListView.QueryItemText += ListView_QueryItemText;
WatchListView.QueryItemBkColor += ListView_QueryItemBkColor;
WatchListView.ColumnClick += WatchListView_ColumnClick;
WatchListView.KeyDown += WatchListView_KeyDown;
WatchListView.VirtualMode = true;
}
[RequiredService] [RequiredService]
public IMemoryDomains MemoryDomains { get; set; } public IMemoryDomains MemoryDomains { get; set; }
@ -163,33 +189,30 @@ namespace BizHawk.Client.EmuHawk
private void ListView_QueryItemBkColor(int index, int column, ref Color color) private void ListView_QueryItemBkColor(int index, int column, ref Color color)
{ {
if (column == 0) if (_searches.Count > 0)
{ {
if (_searches.Count > 0 && column == 0) var nextColor = Color.White;
var isCheat = Global.CheatList.IsActive(_settings.Domain, _searches[index].Address);
var isWeeded = Settings.PreviewMode && !_forcePreviewClear && _searches.Preview(_searches[index].Address);
if (_searches[index].Address >= _searches[index].Domain.Size)
{ {
var nextColor = Color.White; nextColor = Color.PeachPuff;
var isCheat = Global.CheatList.IsActive(_settings.Domain, _searches[index].Address);
var isWeeded = Settings.PreviewMode && !_forcePreviewClear && _searches.Preview(_searches[index].Address);
if (_searches[index].Address >= _searches[index].Domain.Size)
{
nextColor = Color.PeachPuff;
}
else if (isCheat)
{
nextColor = isWeeded ? Color.Lavender : Color.LightCyan;
}
else
{
if (isWeeded)
{
nextColor = Color.Pink;
}
}
color = nextColor;
} }
else if (isCheat)
{
nextColor = isWeeded ? Color.Lavender : Color.LightCyan;
}
else
{
if (isWeeded)
{
nextColor = Color.Pink;
}
}
color = nextColor;
} }
} }
@ -202,7 +225,7 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
var columnName = WatchListView.Columns[column].Name; var columnName = WatchListView.AllColumns[column].Name;
switch (columnName) switch (columnName)
{ {
case WatchList.ADDRESS: case WatchList.ADDRESS:
@ -551,7 +574,7 @@ namespace BizHawk.Client.EmuHawk
_forcePreviewClear = true; _forcePreviewClear = true;
} }
private IEnumerable<int> SelectedIndices => WatchListView.SelectedIndices.Cast<int>(); private IEnumerable<int> SelectedIndices => WatchListView.SelectedRows;
private IEnumerable<Watch> SelectedItems private IEnumerable<Watch> SelectedItems
{ {
@ -771,7 +794,7 @@ namespace BizHawk.Client.EmuHawk
DifferenceRadio.Enabled = true; DifferenceRadio.Enabled = true;
DifferentByBox.Enabled = true; DifferentByBox.Enabled = true;
ClearChangeCountsToolBarItem.Enabled = true; ClearChangeCountsToolBarItem.Enabled = true;
WatchListView.Columns[WatchList.CHANGES].Width = Settings.Columns[WatchList.CHANGES].Width; WatchListView.AllColumns[WatchList.CHANGES].Width = Settings.Columns[WatchList.CHANGES].Width;
SetReboot(true); SetReboot(true);
} }
@ -794,8 +817,8 @@ namespace BizHawk.Client.EmuHawk
PreviousValueRadio.Checked = true; PreviousValueRadio.Checked = true;
} }
Settings.Columns[WatchList.CHANGES].Width = WatchListView.Columns[WatchList.CHANGES].Width; Settings.Columns[WatchList.CHANGES].Width = WatchListView.AllColumns[WatchList.CHANGES].Width.Value;
WatchListView.Columns[WatchList.CHANGES].Width = 0; WatchListView.AllColumns[WatchList.CHANGES].Width = 0;
SetReboot(true); SetReboot(true);
} }
@ -808,7 +831,7 @@ namespace BizHawk.Client.EmuHawk
_searches.RemoveRange(indices); _searches.RemoveRange(indices);
UpdateList(); UpdateList();
WatchListView.SelectedIndices.Clear(); WatchListView.ClearSelectedRows();
ToggleSearchDependentToolBarItems(); ToggleSearchDependentToolBarItems();
} }
} }
@ -899,7 +922,7 @@ namespace BizHawk.Client.EmuHawk
private void GoToSpecifiedAddress() private void GoToSpecifiedAddress()
{ {
WatchListView.SelectedIndices.Clear(); WatchListView.ClearSelectedRows();
var prompt = new InputPrompt var prompt = new InputPrompt
{ {
Text = "Go to Address", Text = "Go to Address",
@ -1708,8 +1731,10 @@ namespace BizHawk.Client.EmuHawk
} }
else if (e.KeyCode == Keys.Escape && !e.Control && !e.Alt && !e.Shift) else if (e.KeyCode == Keys.Escape && !e.Control && !e.Alt && !e.Shift)
{ {
WatchListView.SelectedIndices.Clear(); WatchListView.ClearSelectedRows();
} }
base.OnKeyDown(e);
} }
private void WatchListView_SelectedIndexChanged(object sender, EventArgs e) private void WatchListView_SelectedIndexChanged(object sender, EventArgs e)
@ -1739,9 +1764,9 @@ namespace BizHawk.Client.EmuHawk
WatchListView.Refresh(); WatchListView.Refresh();
} }
private void WatchListView_ColumnClick(object sender, ColumnClickEventArgs e) private void WatchListView_ColumnClick(object sender, PlatformAgnosticVirtualListView.ColumnClickEventArgs e)
{ {
var column = WatchListView.Columns[e.Column]; var column = WatchListView.AllColumns[WatchListView.AllColumns.IndexOf(e.Column)];
if (column.Name != _sortedColumn) if (column.Name != _sortedColumn)
{ {
_sortReverse = false; _sortReverse = false;