Input Roll - track current cell information, including a cell changed event handler

This commit is contained in:
adelikat 2014-08-10 15:57:59 +00:00
parent 85d0f29ed2
commit c16a4fefc6
3 changed files with 244 additions and 60 deletions

View File

@ -32,6 +32,7 @@ namespace BizHawk.Client.EmuHawk
Gdi = new GDIRenderer(this);
_charSize = Gdi.MeasureString("A", this.Font);
CurrentCell = null;
}
protected override void Dispose(bool disposing)
@ -107,10 +108,30 @@ namespace BizHawk.Client.EmuHawk
[Category("Virtual")]
public event QueryItemTextHandler QueryItemText;
public class CellEventArgs
{
public CellEventArgs(Cell oldCell, Cell newCell)
{
OldCell = oldCell;
NewCell = newCell;
}
public Cell OldCell { get; private set; }
public Cell NewCell { get; private set; }
}
public delegate void CellChangeEventHandler(object sender, CellEventArgs e);
[Category("Mouse")] // TODO: is this the correct name?
public event CellChangeEventHandler PointedCellChanged;
#endregion
#region Public Methods
// TODO: designer ignore
public Cell CurrentCell { get; set; }
public string UserSettingsSerialized()
{
return string.Empty; // TODO
@ -314,10 +335,101 @@ namespace BizHawk.Client.EmuHawk
base.OnKeyDown(e);
}
private void CalculatePointedCell(int x, int y)
{
var newCell = new Cell();
// If pointing to a column header
if (Columns.Any())
{
if (HorizontalOrientation)
{
if (x < _horizontalOrientedColumnWidth)
{
newCell.RowIndex = null;
}
else
{
newCell.RowIndex = (x - _horizontalOrientedColumnWidth) / CellWidth;
}
int colIndex = (y / CellHeight);
if (colIndex >= 0 && colIndex < Columns.Count)
{
newCell.Column = Columns[colIndex];
}
}
else
{
if (y < CellHeight)
{
newCell.RowIndex = null;
}
else
{
newCell.RowIndex = (y / CellHeight) - 1;
}
int start = 0;
//for (int i = 0; i < Columns.Count; i++)
foreach (var column in Columns)
{
if (x > start)
{
start += CalcWidth(column);
if (x <= start)
{
newCell.Column = column;
break;
}
}
}
}
}
if (newCell != CurrentCell)
{
CellChanged(CurrentCell, newCell);
CurrentCell = newCell;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
CalculatePointedCell(e.X, e.Y);
base.OnMouseMove(e);
}
protected override void OnMouseEnter(EventArgs e)
{
CurrentCell = new Cell
{
Column = null,
RowIndex = null
};
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
CurrentCell = null;
base.OnMouseLeave(e);
}
#endregion
#region Helpers
private void CellChanged(Cell oldCell, Cell newCell)
{
if (PointedCellChanged != null)
{
PointedCellChanged(this, new CellEventArgs(oldCell, newCell));
}
}
private bool NeedToUpdateScrollbar()
{
return true;
@ -422,4 +534,34 @@ namespace BizHawk.Client.EmuHawk
public string Text { get; set; }
public InputType Type { get; set; }
}
public class Cell
{
public RollColumn Column { get; set; }
public int? RowIndex { get; set; }
public Cell() { }
public Cell(Cell cell)
{
Column = cell.Column;
RowIndex = cell.RowIndex;
}
public override bool Equals(object obj)
{
if (obj is Cell)
{
var cell = obj as Cell;
return this.Column == cell.Column && this.RowIndex == cell.RowIndex;
}
return base.Equals(obj);
}
public override int GetHashCode()
{
return Column.GetHashCode() + RowIndex.GetHashCode();
}
}
}

View File

@ -28,70 +28,95 @@
/// </summary>
private void InitializeComponent()
{
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.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
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.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.settingsToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(404, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// settingsToolStripMenuItem
//
this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(404, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// settingsToolStripMenuItem
//
this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.autoloadToolStripMenuItem});
this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
this.settingsToolStripMenuItem.Text = "&Settings";
this.settingsToolStripMenuItem.DropDownOpened += new System.EventHandler(this.settingsToolStripMenuItem_DropDownOpened);
//
// autoloadToolStripMenuItem
//
this.autoloadToolStripMenuItem.Name = "autoloadToolStripMenuItem";
this.autoloadToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
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)
this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
this.settingsToolStripMenuItem.Text = "&Settings";
this.settingsToolStripMenuItem.DropDownOpened += new System.EventHandler(this.settingsToolStripMenuItem_DropDownOpened);
//
// autoloadToolStripMenuItem
//
this.autoloadToolStripMenuItem.Name = "autoloadToolStripMenuItem";
this.autoloadToolStripMenuItem.Size = new System.Drawing.Size(123, 22);
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.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;
//
// TasStudioExperiment
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(404, 418);
this.Controls.Add(this.InputView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "TasStudioExperiment";
this.Text = "TasStudioExperiment";
this.Load += new System.EventHandler(this.TasStudioExperiment_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
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;
this.label1.Location = new System.Drawing.Point(12, 87);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(67, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Current Cell: ";
//
// CurrentCellLabel
//
this.CurrentCellLabel.AutoSize = true;
this.CurrentCellLabel.Location = new System.Drawing.Point(85, 87);
this.CurrentCellLabel.Name = "CurrentCellLabel";
this.CurrentCellLabel.Size = new System.Drawing.Size(35, 13);
this.CurrentCellLabel.TabIndex = 3;
this.CurrentCellLabel.Text = "label2";
//
// TasStudioExperiment
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(404, 418);
this.Controls.Add(this.CurrentCellLabel);
this.Controls.Add(this.label1);
this.Controls.Add(this.InputView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "TasStudioExperiment";
this.Text = "TasStudioExperiment";
this.Load += new System.EventHandler(this.TasStudioExperiment_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
@ -101,5 +126,7 @@
private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem autoloadToolStripMenuItem;
private InputRoll InputView;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label CurrentCellLabel;
}
}

View File

@ -251,5 +251,20 @@ namespace BizHawk.Client.EmuHawk
{
}
private void InputView_PointedCellChanged(object sender, InputRoll.CellEventArgs e)
{
if (e.NewCell == null)
{
CurrentCellLabel.Text = "None";
}
else
{
string column = e.NewCell.Column != null ? e.NewCell.Column.Text : "None";
string row = e.NewCell.RowIndex.HasValue ? e.NewCell.RowIndex.Value.ToString() : "None";
CurrentCellLabel.Text = string.Format("Column: {0} RowIndex: {1}", column, row);
}
}
}
}