2014-08-06 01:32:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-08-07 14:55:55 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
2014-08-06 01:32:27 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-08-07 18:32:09 +00:00
|
|
|
|
using BizHawk.Client.EmuHawk.CustomControls;
|
|
|
|
|
|
2014-08-06 01:32:27 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
|
|
|
|
{
|
|
|
|
|
public class InputRoll : Control
|
|
|
|
|
{
|
2014-08-07 21:52:22 +00:00
|
|
|
|
private readonly RollColumns _columns = new RollColumns();
|
2014-08-06 01:32:27 +00:00
|
|
|
|
public InputRoll()
|
|
|
|
|
{
|
2014-08-07 18:32:09 +00:00
|
|
|
|
CellPadding = 3;
|
2014-08-07 21:52:22 +00:00
|
|
|
|
//SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
2014-08-06 01:32:27 +00:00
|
|
|
|
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
2014-08-07 21:52:22 +00:00
|
|
|
|
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
|
|
|
|
//SetStyle(ControlStyles.Opaque, true);
|
2014-08-07 18:32:09 +00:00
|
|
|
|
this.Font = new Font("Courier New", 8);
|
2014-08-07 21:52:22 +00:00
|
|
|
|
BackColor = Color.Transparent;
|
2014-08-06 01:32:27 +00:00
|
|
|
|
}
|
2014-08-07 14:55:55 +00:00
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
2014-08-07 18:32:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the amount of padding on the text inside a cell
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DefaultValue(3)]
|
|
|
|
|
public int CellPadding { get; set; }
|
|
|
|
|
|
2014-08-07 14:55:55 +00:00
|
|
|
|
// TODO: remove this, it is put here for more convenient replacing of a virtuallistview in tools with the need to refactor code
|
|
|
|
|
public bool VirtualMode { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets whether the control is horizontal or vertical
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Category("Behavior")]
|
|
|
|
|
public bool HorizontalOrientation { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the sets the virtual number of items to be displayed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Category("Behavior")]
|
|
|
|
|
public int ItemCount { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the sets the columns can be resized
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Category("Behavior")]
|
|
|
|
|
public bool AllowColumnResize { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the sets the columns can be reordered
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Category("Behavior")]
|
|
|
|
|
public bool AllowColumnReorder { get; set; }
|
|
|
|
|
|
2014-08-07 18:32:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Column data
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Category("Behavior")]
|
2014-08-07 21:52:22 +00:00
|
|
|
|
public RollColumns Columns
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _columns;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-07 14:55:55 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Event Handlers
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieve the background color for a Listview cell (item and subitem).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">Listview item (row).</param>
|
|
|
|
|
/// <param name="subItem">Listview subitem (column).</param>
|
|
|
|
|
/// <param name="color">Background color to use</param>
|
|
|
|
|
public delegate void QueryItemBkColorHandler(int item, int subItem, ref Color color);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieve the text for a Listview cell (item and subitem).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">Listview item (row).</param>
|
|
|
|
|
/// <param name="subItem">Listview subitem (column).</param>
|
|
|
|
|
/// <param name="text">Text to display.</param>
|
|
|
|
|
public delegate void QueryItemTextHandler(int item, int subItem, out string text);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fire the QueryItemBkColor event which requests the background color for the passed Listview cell
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Category("Virtual")] // TODO: can I make these up?
|
|
|
|
|
public event QueryItemBkColorHandler QueryItemBkColor;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fire the QueryItemText event which requests the text for the passed Listview cell.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Category("Virtual")]
|
|
|
|
|
public event QueryItemTextHandler QueryItemText;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Public Methods
|
|
|
|
|
|
|
|
|
|
public string UserSettingsSerialized()
|
|
|
|
|
{
|
|
|
|
|
return string.Empty; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Paint
|
|
|
|
|
|
2014-08-07 18:32:09 +00:00
|
|
|
|
private void DrawColumnBg(GDIRenderer ntr, PaintEventArgs e)
|
|
|
|
|
{
|
2014-08-08 02:09:59 +00:00
|
|
|
|
ntr.SetBrush(SystemColors.ControlLight);
|
|
|
|
|
|
2014-08-07 18:32:09 +00:00
|
|
|
|
if (HorizontalOrientation)
|
|
|
|
|
{
|
2014-08-08 02:09:59 +00:00
|
|
|
|
var colWidth = HorizontalOrientedColumnWidth;
|
|
|
|
|
ntr.DrawRectangle(0, 0, colWidth, Height - 2);
|
|
|
|
|
ntr.FillRectangle(1, 1, colWidth - 1, Height - 3);
|
|
|
|
|
|
|
|
|
|
int start = 0;
|
|
|
|
|
foreach (var column in Columns)
|
|
|
|
|
{
|
|
|
|
|
start += CellHeight;
|
|
|
|
|
ntr.Line(0, start, colWidth, start);
|
|
|
|
|
|
|
|
|
|
}
|
2014-08-07 18:32:09 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-08-08 02:09:59 +00:00
|
|
|
|
ntr.DrawRectangle(0, 0, Width - 2, CellHeight);
|
|
|
|
|
ntr.FillRectangle(1, 1, Width - 3, CellHeight - 1);
|
2014-08-07 18:32:09 +00:00
|
|
|
|
|
2014-08-08 02:09:59 +00:00
|
|
|
|
int start = 0;
|
|
|
|
|
foreach (var column in Columns)
|
|
|
|
|
{
|
|
|
|
|
start += column.Width;
|
|
|
|
|
ntr.Line(start, 0, start, CellHeight);
|
|
|
|
|
}
|
2014-08-07 18:32:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawBg(GDIRenderer ntr, PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var start = StartBg;
|
|
|
|
|
|
2014-08-07 23:52:19 +00:00
|
|
|
|
|
2014-08-08 02:09:59 +00:00
|
|
|
|
ntr.SetBrush(Color.White);
|
|
|
|
|
ntr.FillRectangle(StartBg.X, StartBg.Y, Width, Height);
|
2014-08-07 23:52:19 +00:00
|
|
|
|
|
|
|
|
|
//ntr.SetBrush(Color.Aqua);
|
2014-08-08 02:09:59 +00:00
|
|
|
|
ntr.DrawRectangle(StartBg.X, StartBg.Y, Width, Height);
|
2014-08-07 18:32:09 +00:00
|
|
|
|
|
|
|
|
|
if (HorizontalOrientation)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 14:55:55 +00:00
|
|
|
|
protected override void OnPaintBackground(PaintEventArgs pevent)
|
|
|
|
|
{
|
2014-08-07 18:32:09 +00:00
|
|
|
|
using (var ntr = new GDIRenderer(this))
|
|
|
|
|
{
|
|
|
|
|
if (NeedToUpdateColumn() && Columns.Any())
|
|
|
|
|
{
|
|
|
|
|
DrawColumnBg(ntr, pevent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NeedToUpdateBg())
|
|
|
|
|
{
|
|
|
|
|
DrawBg(ntr, pevent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//base.OnPaintBackground(pevent);
|
2014-08-07 14:55:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-08 02:09:59 +00:00
|
|
|
|
private void DrawColumnText(GDIRenderer ntr, PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (HorizontalOrientation)
|
|
|
|
|
{
|
|
|
|
|
int start = 0;
|
|
|
|
|
foreach (var column in Columns)
|
|
|
|
|
{
|
|
|
|
|
ntr.DrawString(column.Text, this.Font, Color.Black, new Point(CellPadding, start + CellPadding));
|
|
|
|
|
start += CellHeight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int start = 0;
|
|
|
|
|
foreach(var column in Columns)
|
|
|
|
|
{
|
|
|
|
|
ntr.DrawString(column.Text, this.Font, Color.Black, new Point(start + CellPadding, CellPadding));
|
|
|
|
|
start += column.Width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 14:55:55 +00:00
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
2014-08-08 02:09:59 +00:00
|
|
|
|
using (var ntr = new GDIRenderer(this))
|
|
|
|
|
{
|
|
|
|
|
if (NeedToUpdateColumn() && Columns.Any())
|
|
|
|
|
{
|
|
|
|
|
DrawColumnText(ntr, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//base.OnPaint(e);
|
2014-08-07 14:55:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Mouse and Key Events
|
|
|
|
|
|
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.R) // Ctrl + R
|
|
|
|
|
{
|
|
|
|
|
HorizontalOrientation ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Helpers
|
|
|
|
|
|
|
|
|
|
private bool NeedToUpdateColumn()
|
|
|
|
|
{
|
2014-08-07 18:32:09 +00:00
|
|
|
|
return true; // TODO
|
2014-08-07 14:55:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool NeedToUpdateText()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool NeedToUpdateBg()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool NeedToUpdateScrollbar()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 18:32:09 +00:00
|
|
|
|
private Point StartBg
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Columns.Any())
|
|
|
|
|
{
|
|
|
|
|
if (HorizontalOrientation)
|
|
|
|
|
{
|
2014-08-07 23:10:41 +00:00
|
|
|
|
var x = HorizontalOrientedColumnWidth;
|
2014-08-08 02:09:59 +00:00
|
|
|
|
var y = 0;
|
2014-08-07 18:32:09 +00:00
|
|
|
|
return new Point(x, y);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var x = 0;
|
2014-08-08 02:09:59 +00:00
|
|
|
|
var y = CellHeight;
|
2014-08-07 18:32:09 +00:00
|
|
|
|
return new Point(x, y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Point(0, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 23:10:41 +00:00
|
|
|
|
private int HorizontalOrientedColumnWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (Columns.Max(c => c.Text.Length) * TextWidth) + (CellPadding * 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-08 02:09:59 +00:00
|
|
|
|
private int CellHeight
|
2014-08-07 14:55:55 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-08-08 02:09:59 +00:00
|
|
|
|
return this.Font.Height + (CellPadding * 2);
|
2014-08-07 14:55:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int TextWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-08-07 18:32:09 +00:00
|
|
|
|
return 15;
|
2014-08-07 14:55:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool NeedsScrollbar
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (HorizontalOrientation)
|
|
|
|
|
{
|
|
|
|
|
return Width / TextWidth > ItemCount;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-08 02:09:59 +00:00
|
|
|
|
return Height / CellHeight > ItemCount;
|
2014-08-07 14:55:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RollColumns : List<RollColumn>
|
|
|
|
|
{
|
2014-08-07 23:10:41 +00:00
|
|
|
|
public void Add(string name, string text, int width, RollColumn.InputType type = RollColumn.InputType.Text)
|
2014-08-07 14:55:55 +00:00
|
|
|
|
{
|
|
|
|
|
Add(new RollColumn
|
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Text = text,
|
2014-08-07 18:32:09 +00:00
|
|
|
|
Width = width,
|
|
|
|
|
Type = type
|
2014-08-07 14:55:55 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 18:32:09 +00:00
|
|
|
|
|
|
|
|
|
|
2014-08-07 14:55:55 +00:00
|
|
|
|
public class RollColumn
|
|
|
|
|
{
|
2014-08-07 23:10:41 +00:00
|
|
|
|
public enum InputType { Boolean, Float, Text }
|
2014-08-07 18:32:09 +00:00
|
|
|
|
|
2014-08-07 14:55:55 +00:00
|
|
|
|
public int Width { get; set; }
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string Text { get; set; }
|
2014-08-07 18:32:09 +00:00
|
|
|
|
public InputType Type { get; set; }
|
2014-08-06 01:32:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|