BizHawk/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs

305 lines
6.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
2014-08-07 18:32:09 +00:00
using BizHawk.Client.EmuHawk.CustomControls;
namespace BizHawk.Client.EmuHawk
{
public class InputRoll : Control
{
private readonly RollColumns _columns = new RollColumns();
public InputRoll()
{
2014-08-07 18:32:09 +00:00
CellPadding = 3;
//SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
//SetStyle(ControlStyles.Opaque, true);
2014-08-07 18:32:09 +00:00
this.Font = new Font("Courier New", 8);
BackColor = Color.Transparent;
}
#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; }
// 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")]
public RollColumns Columns
{
get
{
return _columns;
}
}
#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)
{
if (HorizontalOrientation)
{
2014-08-07 23:10:41 +00:00
//HorizontalOrientedColumnWidth
//ntr.DrawRectangle
2014-08-07 18:32:09 +00:00
}
else
{
}
}
private void DrawBg(GDIRenderer ntr, PaintEventArgs e)
{
var start = StartBg;
2014-08-07 23:10:41 +00:00
//ntr.SetBrush(Color.White);
ntr.SetBrush(Color.Aqua);
ntr.DrawRectangle(start.X, start.Y, Width, Height);
ntr.FillRectangle(start.X, start.Y, Width-50, Height-50);
2014-08-07 18:32:09 +00:00
if (HorizontalOrientation)
{
}
else
{
}
}
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);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
#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
}
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-07 18:32:09 +00:00
var y = TextHeight + CellPadding;
return new Point(x, y);
}
else
{
var x = 0;
2014-08-07 23:10:41 +00:00
var y = TextHeight + (CellPadding * 2);
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);
}
}
private int TextHeight
{
get
{
2014-08-07 18:32:09 +00:00
return this.Font.Height;
}
}
private int TextWidth
{
get
{
2014-08-07 18:32:09 +00:00
return 15;
}
}
private bool NeedsScrollbar
{
get
{
if (HorizontalOrientation)
{
return Width / TextWidth > ItemCount;
}
return Height / TextHeight > ItemCount;
}
}
#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)
{
Add(new RollColumn
{
Name = name,
Text = text,
2014-08-07 18:32:09 +00:00
Width = width,
Type = type
});
}
}
2014-08-07 18:32:09 +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
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; }
}
}