Rename GDITextRenderer to GDIRenderer, Input Roll - implement the Background color callback

This commit is contained in:
adelikat 2014-08-11 00:08:16 +00:00
parent 84e1f057fb
commit 3e9d5533e1
4 changed files with 142 additions and 87 deletions

View File

@ -443,7 +443,7 @@
<Compile Include="CustomControls\FolderBrowserDialogEx.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CustomControls\GDITextRenderer.cs" />
<Compile Include="CustomControls\GDIRenderer.cs" />
<Compile Include="CustomControls\HexTextBox.cs">
<SubType>Component</SubType>
</Compile>

View File

@ -165,7 +165,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls
public void FillRectangle(int x, int y, int w, int h)
{
var r = new GDIRect(new Rectangle(x, y, x + w, y + h));
var r = new GDIRect(new Rectangle(x, y, w, h));
FillRect(_hdc, ref r, _currentBrush);
}

View File

@ -252,20 +252,20 @@ namespace BizHawk.Client.EmuHawk
if (HorizontalOrientation)
{
Gdi.DrawRectangle(0, 0, _horizontalOrientedColumnWidth, Height);
Gdi.FillRectangle(1, 1, _horizontalOrientedColumnWidth - 3, Height - 3);
Gdi.DrawRectangle(0, 0, _horizontalOrientedColumnWidth + 1, Height);
Gdi.FillRectangle(1, 1, _horizontalOrientedColumnWidth, Height - 3);
int start = 0;
foreach (var column in Columns)
{
start += CellHeight;
Gdi.Line(1, start, _horizontalOrientedColumnWidth - 1, start);
Gdi.Line(1, start, _horizontalOrientedColumnWidth, start);
}
}
else
{
Gdi.DrawRectangle(0, 0, Width, CellHeight);
Gdi.FillRectangle(1, 1, Width - 3, CellHeight - 3);
Gdi.FillRectangle(1, 1, Width - 2, CellHeight);
int start = 0;
foreach (var column in Columns)
@ -291,21 +291,21 @@ namespace BizHawk.Client.EmuHawk
// Columns
for (int i = 1; i < Width / CellWidth; i++)
{
var x = _horizontalOrientedColumnWidth + (i * CellWidth);
var x = _horizontalOrientedColumnWidth + 1 + (i * CellWidth);
Gdi.Line(x, 1, x, Columns.Count * CellHeight);
}
// Rows
for (int i = 1; i < Columns.Count + 1; i++)
{
Gdi.Line(_horizontalOrientedColumnWidth, i * CellHeight, Width - 2, i * CellHeight);
Gdi.Line(_horizontalOrientedColumnWidth + 1, i * CellHeight, Width - 2, i * CellHeight);
}
}
else
{
// Columns
int x = 0;
int y = CellHeight;
int y = CellHeight + 1;
foreach (var column in Columns)
{
x += CalcWidth(column);
@ -318,6 +318,55 @@ namespace BizHawk.Client.EmuHawk
Gdi.Line(1, (i * CellHeight) + 1, Width - 2, (i * CellHeight) + 1);
}
}
// Do background callback
if (QueryItemBkColor != null)
{
if (HorizontalOrientation)
{
var visibleRows = (Width - _horizontalOrientedColumnWidth) / CellWidth;
for (int i = 0; i < visibleRows; i++)
{
for (int j = 0; j < Columns.Count; j++)
{
Color color = Color.White;
QueryItemBkColor(i, j, ref color);
if (color != Color.White) // An easy optimization, don't draw unless the user specified something other than the default
{
Gdi.SetBrush(color);
Gdi.FillRectangle(
_horizontalOrientedColumnWidth + (i * CellWidth) + 2,
(j * CellHeight) + 1,
CellWidth - 1,
CellHeight - 1);
}
}
}
}
else
{
var visibleRows = (Height / CellHeight) - 1;
for (int i = 1; i < visibleRows; i++)
{
int x = 1;
for (int j = 0; j < Columns.Count; j++)
{
Color color = Color.White;
QueryItemBkColor(i, j, ref color);
var width = CalcWidth(Columns[j]);
if (color != Color.White) // An easy optimization, don't draw unless the user specified something other than the default
{
Gdi.SetBrush(color);
Gdi.FillRectangle(x, (i * CellHeight) + 2, width - 1, CellHeight - 1);
}
x += width;
}
}
}
}
}
#endregion
@ -441,13 +490,13 @@ namespace BizHawk.Client.EmuHawk
{
if (HorizontalOrientation)
{
var x = _horizontalOrientedColumnWidth - 1;
var x = _horizontalOrientedColumnWidth;
var y = 0;
return new Point(x, y);
}
else
{
var y = CellHeight - 1;
var y = CellHeight;
return new Point(0, y);
}
}
@ -500,70 +549,74 @@ namespace BizHawk.Client.EmuHawk
}
#endregion
}
public class RollColumns : List<RollColumn>
{
public void Add(string name, string text, int width, RollColumn.InputType type = RollColumn.InputType.Text)
{
Add(new RollColumn
{
Name = name,
Text = text,
Width = width,
Type = type
});
}
#region Classes
public IEnumerable<string> Groups
public class RollColumns : List<RollColumn>
{
get
public void Add(string name, string text, int width, RollColumn.InputType type = RollColumn.InputType.Text)
{
return this
.Select(x => x.Group)
.Distinct();
Add(new RollColumn
{
Name = name,
Text = text,
Width = width,
Type = type
});
}
public IEnumerable<string> Groups
{
get
{
return this
.Select(x => x.Group)
.Distinct();
}
}
}
}
public class RollColumn
{
public enum InputType { Boolean, Float, Text, Image }
public string Group { get; set; }
public int? Width { get; set; }
public string Name { get; set; }
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)
public class RollColumn
{
Column = cell.Column;
RowIndex = cell.RowIndex;
public enum InputType { Boolean, Float, Text, Image }
public string Group { get; set; }
public int? Width { get; set; }
public string Name { get; set; }
public string Text { get; set; }
public InputType Type { get; set; }
}
public override bool Equals(object obj)
public class Cell
{
if (obj is Cell)
public RollColumn Column { get; set; }
public int? RowIndex { get; set; }
public Cell() { }
public Cell(Cell cell)
{
var cell = obj as Cell;
return this.Column == cell.Column && this.RowIndex == cell.RowIndex;
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();
}
return base.Equals(obj);
}
public override int GetHashCode()
{
return Column.GetHashCode() + RowIndex.GetHashCode();
}
#endregion
}
}

View File

@ -108,7 +108,10 @@ namespace BizHawk.Client.EmuHawk
private void TasView_QueryItemBkColor(int index, int column, ref Color color)
{
var test = r.NextDouble() > .5;
//var test = index == 2 && column == 2;
color = test ? Color.LightCyan : Color.White;
}
private void TasStudioExperiment_Load(object sender, EventArgs e)
@ -121,43 +124,43 @@ namespace BizHawk.Client.EmuHawk
InputView.AddColumns(new[]
{
new RollColumn
new InputRoll.RollColumn
{
Group = "",
Name = "Address",
Text = "Address"
},
new RollColumn
new InputRoll.RollColumn
{
Group = "",
Name = "Value",
Text = "Value"
},
new RollColumn
new InputRoll.RollColumn
{
Group = "",
Name = "Prev",
Text = "Prev"
},
new RollColumn
new InputRoll.RollColumn
{
Group = "",
Name = "Changes",
Text = "Changes"
},
new RollColumn
new InputRoll.RollColumn
{
Group = "",
Name = "Domain",
Text = "Domain"
},
new RollColumn
new InputRoll.RollColumn
{
Group = "",
Name = "Diff",
Text = "Diff"
},
new RollColumn
new InputRoll.RollColumn
{
Group = "",
Name = "Notes",
@ -166,78 +169,77 @@ namespace BizHawk.Client.EmuHawk
});
*/
InputView.AddColumns(new []
{
new RollColumn
new InputRoll.RollColumn
{
Group = "Core",
Name = "MarkerColumn",
Text = "",
Width = 23,
},
new RollColumn
new InputRoll.RollColumn
{
Group = "Core",
Name = "FrameColumn",
Text = "Frame",
Width = 50,
},
new RollColumn
new InputRoll.RollColumn
{
Group = "P1",
Name = "P1 Up",
Text = "U",
Type = RollColumn.InputType.Boolean
Type = InputRoll.RollColumn.InputType.Boolean
},
new RollColumn
new InputRoll.RollColumn
{
Group = "P1",
Name = "P1 Down",
Text = "D",
Type = RollColumn.InputType.Boolean
Type = InputRoll.RollColumn.InputType.Boolean
},
new RollColumn
new InputRoll.RollColumn
{
Group = "P1",
Name = "P1 Left",
Text = "L",
Type = RollColumn.InputType.Boolean
Type = InputRoll.RollColumn.InputType.Boolean
},
new RollColumn
new InputRoll.RollColumn
{
Group = "P1",
Name = "P1 Right",
Text = "R",
Type = RollColumn.InputType.Boolean
Type = InputRoll.RollColumn.InputType.Boolean
},
new RollColumn
new InputRoll.RollColumn
{
Group = "P1",
Name = "P1 Select",
Text = "s",
Type = RollColumn.InputType.Boolean
Type = InputRoll.RollColumn.InputType.Boolean
},
new RollColumn
new InputRoll.RollColumn
{
Group = "P1",
Name = "P1 Start",
Text = "S",
Type = RollColumn.InputType.Boolean
Type = InputRoll.RollColumn.InputType.Boolean
},
new RollColumn
new InputRoll.RollColumn
{
Group = "P1",
Name = "P1 B",
Text = "B",
Type = RollColumn.InputType.Boolean
Type = InputRoll.RollColumn.InputType.Boolean
},
new RollColumn
new InputRoll.RollColumn
{
Group = "P1",
Name = "P1 A",
Text = "A",
Type = RollColumn.InputType.Boolean
Type = InputRoll.RollColumn.InputType.Boolean
},
});
}