Input Roll - implement column click event

This commit is contained in:
adelikat 2014-08-11 01:49:45 +00:00
parent d12938bf33
commit 2c0052ee20
3 changed files with 79 additions and 23 deletions

View File

@ -14,7 +14,6 @@ namespace BizHawk.Client.EmuHawk
private readonly GDIRenderer Gdi;
private readonly RollColumns Columns = new RollColumns();
private bool NeedToReDrawColumn = false;
private int _horizontalOrientedColumnWidth = 0;
private Size _charSize;
@ -102,6 +101,9 @@ namespace BizHawk.Client.EmuHawk
[Category("Mouse")]
public event CellChangeEventHandler PointedCellChanged;
[Category("Action")]
public event ColumnClickEventHandler ColumnClick;
/// <summary>
/// Retrieve the text for a cell
/// </summary>
@ -114,6 +116,8 @@ namespace BizHawk.Client.EmuHawk
public delegate void CellChangeEventHandler(object sender, CellEventArgs e);
public delegate void ColumnClickEventHandler(object sender, ColumnClickEventArgs e);
public class CellEventArgs
{
public CellEventArgs(Cell oldCell, Cell newCell)
@ -155,6 +159,11 @@ namespace BizHawk.Client.EmuHawk
ColumnChanged();
}
public RollColumn GetColumn(int index)
{
return Columns[index];
}
#endregion
#region Paint
@ -470,6 +479,16 @@ namespace BizHawk.Client.EmuHawk
base.OnMouseLeave(e);
}
protected override void OnMouseClick(MouseEventArgs e)
{
if (IsHoveringOnColumnCell)
{
ColumnClickEvent(ColumnAtX(e.X));
}
base.OnMouseClick(e);
}
#endregion
#region Helpers
@ -558,6 +577,14 @@ namespace BizHawk.Client.EmuHawk
}
}
private void ColumnClickEvent(RollColumn column)
{
if (ColumnClick != null)
{
ColumnClick(this, new ColumnClickEventArgs(Columns.IndexOf(column)));
}
}
private bool NeedToUpdateScrollbar()
{
return true;
@ -617,7 +644,6 @@ namespace BizHawk.Client.EmuHawk
private void ColumnChanged()
{
NeedToReDrawColumn = true;
var text = Columns.Max(c => c.Text.Length);
_horizontalOrientedColumnWidth = (text * _charSize.Width) + (CellPadding * 2);
}
@ -628,6 +654,21 @@ namespace BizHawk.Client.EmuHawk
return col.Width ?? ((col.Text.Length * _charSize.Width) + (CellPadding * 4));
}
private RollColumn ColumnAtX(int x)
{
int start = 0;
foreach (var column in Columns)
{
start += CalcWidth(column);
if (start > x)
{
return column;
}
}
return null;
}
#endregion
#region Classes

View File

@ -31,9 +31,9 @@
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.autoloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.InputView = new BizHawk.Client.EmuHawk.InputRoll();
this.label1 = new System.Windows.Forms.Label();
this.CurrentCellLabel = new System.Windows.Forms.Label();
this.InputView = new BizHawk.Client.EmuHawk.InputRoll();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
@ -63,25 +63,6 @@
this.autoloadToolStripMenuItem.Text = "Autoload";
this.autoloadToolStripMenuItem.Click += new System.EventHandler(this.autoloadToolStripMenuItem_Click);
//
// InputView
//
this.InputView.AllowColumnReorder = false;
this.InputView.AllowColumnResize = false;
this.InputView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.InputView.CurrentCell = null;
this.InputView.Font = new System.Drawing.Font("Courier New", 8F);
this.InputView.HorizontalOrientation = false;
this.InputView.ItemCount = 0;
this.InputView.Location = new System.Drawing.Point(12, 103);
this.InputView.Name = "InputView";
this.InputView.Size = new System.Drawing.Size(380, 303);
this.InputView.TabIndex = 1;
this.InputView.Text = "inputRoll1";
this.InputView.VirtualMode = false;
this.InputView.PointedCellChanged += new BizHawk.Client.EmuHawk.InputRoll.CellChangeEventHandler(this.InputView_PointedCellChanged);
//
// label1
//
this.label1.AutoSize = true;
@ -100,6 +81,25 @@
this.CurrentCellLabel.TabIndex = 3;
this.CurrentCellLabel.Text = "label2";
//
// InputView
//
this.InputView.AllowColumnReorder = false;
this.InputView.AllowColumnResize = false;
this.InputView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.InputView.Font = new System.Drawing.Font("Courier New", 8F);
this.InputView.HorizontalOrientation = false;
this.InputView.ItemCount = 0;
this.InputView.Location = new System.Drawing.Point(12, 103);
this.InputView.Name = "InputView";
this.InputView.Size = new System.Drawing.Size(380, 303);
this.InputView.TabIndex = 1;
this.InputView.Text = "inputRoll1";
this.InputView.VirtualMode = false;
this.InputView.PointedCellChanged += new BizHawk.Client.EmuHawk.InputRoll.CellChangeEventHandler(this.InputView_PointedCellChanged);
this.InputView.ColumnClick += new BizHawk.Client.EmuHawk.InputRoll.ColumnClickEventHandler(this.InputView_ColumnClick);
//
// TasStudioExperiment
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -60,9 +60,17 @@ namespace BizHawk.Client.EmuHawk
r = new Random((int)DateTime.Now.Ticks);
}
private int? columnClicked = null;
private void TasView_QueryItemText(int index, int column, out string text)
{
if (columnClicked.HasValue && column == columnClicked)
{
text = "!";
return;
}
text = r.NextDouble() > .5 ? "_" : "";
/*
@ -268,5 +276,12 @@ namespace BizHawk.Client.EmuHawk
CurrentCellLabel.Text = string.Format("Column: {0} RowIndex: {1}", column, row);
}
}
private void InputView_ColumnClick(object sender, ColumnClickEventArgs e)
{
var column = InputView.GetColumn(e.Column);
columnClicked = e.Column;
InputView.Refresh();
}
}
}