move some font shenanigans into GDI Renderer instead of input roll
This commit is contained in:
parent
b4a38597a6
commit
b7f8f830e0
|
@ -17,6 +17,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls
|
|||
private class FontCacheEntry
|
||||
{
|
||||
public IntPtr HFont;
|
||||
public IntPtr RotatedHFont;
|
||||
}
|
||||
|
||||
// Cache of all the brushes used, rather than create them again and again
|
||||
|
@ -41,6 +42,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls
|
|||
foreach (var fc in _fontsCache)
|
||||
{
|
||||
DeleteObject(fc.Value.HFont);
|
||||
DeleteObject(fc.Value.RotatedHFont);
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.Assert(_hdc == IntPtr.Zero, "Disposed a GDIRenderer while it held an HDC");
|
||||
|
@ -123,10 +125,22 @@ namespace BizHawk.Client.EmuHawk.CustomControls
|
|||
DeleteObject(hFont);
|
||||
}
|
||||
|
||||
public void PrepDrawString(IntPtr hFont, Color color)
|
||||
public void PrepDrawString(Font font, Color color, bool rotate = false)
|
||||
{
|
||||
FontCacheEntry fontEntry;
|
||||
var result = _fontsCache.TryGetValue(font, out fontEntry);
|
||||
if (!result)
|
||||
{
|
||||
// Hack! The 6 is hardcoded to make tastudio look like taseditor, because taseditor is so perfect and wonderful
|
||||
_fontsCache.Add(font, new FontCacheEntry
|
||||
{
|
||||
HFont = CreateNormalHFont(font, 6),
|
||||
RotatedHFont = CreateRotatedHFont(font, true)
|
||||
});
|
||||
}
|
||||
|
||||
SetGraphicsMode(CurrentHdc, 2); // shouldn't be necessary.. cant hurt
|
||||
SelectObject(CurrentHdc, hFont);
|
||||
SelectObject(CurrentHdc, rotate ? fontEntry.RotatedHFont : fontEntry.HFont);
|
||||
SetTextColor(color);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls
|
|||
void SetBrush(Color color);
|
||||
void SetSolidPen(Color color);
|
||||
|
||||
// TODO: use the Font version
|
||||
void PrepDrawString(IntPtr hFont, Color color);
|
||||
void PrepDrawString(Font font, Color color, bool rotate = false);
|
||||
|
||||
/// <summary>
|
||||
/// Draw the given string using the given font and foreground color at given location
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
_renderer.SetSolidPen(_backColor);
|
||||
_renderer.DrawRectangle(x1, y1, x2, y2);
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
_renderer.DrawString(_columnDown.Text, new Point(x1 + CellWidthPadding, y1 + CellHeightPadding));
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
_renderer.SetBrush(bgColor);
|
||||
_renderer.FillRectangle(x1, y1, x2 - x1, y2 - y1);
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
_renderer.DrawString(text, new Point(x1 + CellWidthPadding + offsetX, y1 + CellHeightPadding + offsetY));
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
int start = -_vBar.Value;
|
||||
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
|
||||
foreach (var column in visibleColumns)
|
||||
{
|
||||
|
@ -118,9 +118,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (IsHoveringOnColumnCell && column == CurrentCell.Column)
|
||||
{
|
||||
_renderer.PrepDrawString(_normalFont, SystemColors.HighlightText);
|
||||
_renderer.PrepDrawString(_font, SystemColors.HighlightText);
|
||||
DrawString(column.Text, column.Width, point);
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -132,7 +132,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else
|
||||
{
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
|
||||
foreach (var column in visibleColumns)
|
||||
{
|
||||
|
@ -140,9 +140,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (IsHoveringOnColumnCell && column == CurrentCell.Column)
|
||||
{
|
||||
_renderer.PrepDrawString(_normalFont, SystemColors.HighlightText);
|
||||
_renderer.PrepDrawString(_font, SystemColors.HighlightText);
|
||||
DrawString(column.Text, column.Width, point);
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -166,7 +166,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
int startRow = FirstVisibleRow;
|
||||
int range = Math.Min(LastVisibleRow, RowCount - 1) - startRow + 1;
|
||||
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
for (int i = 0, f = 0; f < range; i++, f++)
|
||||
{
|
||||
f += _lagFrames[i];
|
||||
|
@ -202,21 +202,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (j == 1)
|
||||
if (_selectedItems.Contains(new Cell { Column = visibleColumns[j], RowIndex = i + startRow }))
|
||||
{
|
||||
_renderer.PrepDrawString(_rotatedFont, SystemColors.HighlightText);
|
||||
_renderer.PrepDrawString(_font, SystemColors.HighlightText, rotate: true);
|
||||
rePrep = true;
|
||||
}
|
||||
else if (j == 1)
|
||||
{
|
||||
// 1. not sure about this; 2. repreps may be excess, but if we render one column at a time, we do need to change back after rendering the header
|
||||
rePrep = true;
|
||||
_renderer.PrepDrawString(_rotatedFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor, rotate: true);
|
||||
}
|
||||
|
||||
DrawString(text, ColumnWidth, point);
|
||||
|
||||
if (rePrep)
|
||||
{
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
int startRow = FirstVisibleRow;
|
||||
int range = Math.Min(LastVisibleRow, RowCount - 1) - startRow + 1;
|
||||
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
int xPadding = CellWidthPadding + 1 - _hBar.Value;
|
||||
for (int i = 0, f = 0; f < range; i++, f++) // Vertical
|
||||
{
|
||||
|
@ -257,7 +257,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
bool rePrep = false;
|
||||
if (_selectedItems.Contains(new Cell { Column = visibleColumns[j], RowIndex = f + startRow }))
|
||||
{
|
||||
_renderer.PrepDrawString(_normalFont, SystemColors.HighlightText);
|
||||
_renderer.PrepDrawString(_font, SystemColors.HighlightText);
|
||||
rePrep = true;
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (rePrep)
|
||||
{
|
||||
_renderer.PrepDrawString(_normalFont, _foreColor);
|
||||
_renderer.PrepDrawString(_font, _foreColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
private readonly Timer _hoverTimer = new Timer();
|
||||
private readonly byte[] _lagFrames = new byte[256]; // Large enough value that it shouldn't ever need resizing. // apparently not large enough for 4K
|
||||
|
||||
private readonly IntPtr _rotatedFont;
|
||||
private readonly IntPtr _normalFont;
|
||||
private readonly Color _foreColor;
|
||||
private readonly Color _backColor;
|
||||
|
||||
|
@ -51,6 +49,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
public bool LetKeysModifySelection { get; set; }
|
||||
public bool SuspendHotkeys { get; set; }
|
||||
|
||||
private Font _font = new Font("Arial", 8, FontStyle.Bold);
|
||||
|
||||
public InputRoll()
|
||||
{
|
||||
UseCustomBackground = true;
|
||||
|
@ -60,13 +60,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
CurrentCell = null;
|
||||
ScrollMethod = "near";
|
||||
|
||||
var commonFont = new Font("Arial", 8, FontStyle.Bold);
|
||||
_normalFont = GdiRenderer.CreateNormalHFont(commonFont, 6);
|
||||
|
||||
// PrepDrawString doesn't actually set the font, so this is rather useless.
|
||||
// I'm leaving this stuff as-is so it will be a bit easier to fix up with another rendering method.
|
||||
_rotatedFont = GdiRenderer.CreateRotatedHFont(commonFont, true);
|
||||
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
SetStyle(ControlStyles.UserPaint, true);
|
||||
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
||||
|
@ -77,7 +70,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
using (var g = CreateGraphics())
|
||||
using (_renderer.LockGraphics(g, Width, Height))
|
||||
{
|
||||
_charSize = _renderer.MeasureString("A", commonFont); // TODO make this a property so changing it updates other values.
|
||||
_charSize = _renderer.MeasureString("A", _font); // TODO make this a property so changing it updates other values.
|
||||
}
|
||||
|
||||
UpdateCellSize();
|
||||
|
@ -127,10 +120,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_renderer.Dispose();
|
||||
|
||||
GdiRenderer.DestroyHFont(_normalFont);
|
||||
GdiRenderer.DestroyHFont(_rotatedFont);
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue