GDIRenderer: add a method to create NormalFont using the LOGFONT features.

InputRoll: make the font match what fceux uses. padding still works oddly though.
This commit is contained in:
feos 2016-04-17 11:47:18 +03:00
parent 5a6ffe022a
commit a18648dc45
2 changed files with 16 additions and 7 deletions

View File

@ -142,6 +142,16 @@ namespace BizHawk.Client.EmuHawk.CustomControls
TextOut(CurrentHDC, point.X, point.Y, str, str.Length);
}
public static IntPtr CreateNormalHFont(Font font, int width)
{
LOGFONT logf = new LOGFONT();
font.ToLogFont(logf);
logf.lfWidth = width;
logf.lfOutPrecision = (byte)FontPrecision.OUT_TT_ONLY_PRECIS;
var ret = CreateFontIndirect(logf);
return ret;
}
//this returns an IntPtr HFONT because .net's Font class will erase the relevant properties when using its Font.FromLogFont()
//note that whether this is rotated clockwise or CCW might affect how you have to position the text (right-aligned sometimes?, up or down by the height of the font?)
public static IntPtr CreateRotatedHFont(Font font, bool CW)

View File

@ -47,13 +47,12 @@ namespace BizHawk.Client.EmuHawk
public bool letKeysModifySelection { get; set; }
private IntPtr RotatedFont;
private readonly Font NormalFont;
private readonly IntPtr NormalFont;
private Color _foreColor;
private Color _backColor;
public InputRoll()
{
UseCustomBackground = true;
GridLines = true;
CellWidthPadding = 3;
@ -61,11 +60,11 @@ namespace BizHawk.Client.EmuHawk
CurrentCell = null;
ScrollMethod = "near";
NormalFont = new Font("Courier New", 8); // Only support fixed width
Font 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(NormalFont, true);
RotatedFont = GDIRenderer.CreateRotatedHFont(CommonFont, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
@ -77,7 +76,7 @@ namespace BizHawk.Client.EmuHawk
using (var g = CreateGraphics())
using (var LCK = Gdi.LockGraphics(g))
{
_charSize = Gdi.MeasureString("A", NormalFont); // TODO make this a property so changing it updates other values.
_charSize = Gdi.MeasureString("A", CommonFont); // TODO make this a property so changing it updates other values.
}
UpdateCellSize();
@ -132,7 +131,7 @@ namespace BizHawk.Client.EmuHawk
{
Gdi.Dispose();
NormalFont.Dispose();
GDIRenderer.DestroyHFont(NormalFont);
GDIRenderer.DestroyHFont(RotatedFont);
base.Dispose(disposing);