Change IControlRenderer.MeasureString to return a SizeF instead of Size, for more accurate reporting, it was Size because that's what the GDI renderer did, but if we ever needed that again, we can easily convert to SizeF

This commit is contained in:
adelikat 2019-12-02 18:38:24 -06:00
parent 79d06bcb4a
commit c6c92c51c7
4 changed files with 15 additions and 14 deletions

View File

@ -80,10 +80,9 @@ namespace BizHawk.Client.EmuHawk.CustomControls
return new GdiPlusGraphicsLock();
}
public Size MeasureString(string str, Font font)
public SizeF MeasureString(string str, Font font)
{
var size = _graphics.MeasureString(str, font);
return new Size((int)(size.Width + 0.5), (int)(size.Height + 0.5));
return _graphics.MeasureString(str, font);
}
public void PrepDrawString(Font font, Color color, bool rotate = false)

View File

@ -14,7 +14,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls
/// Measure the width and height of string <paramref name="str"/> when drawn
/// using the given font <paramref name="font"/>
/// </summary>
Size MeasureString(string str, Font font);
SizeF MeasureString(string str, Font font);
void SetBrush(Color color);
void SetSolidPen(Color color);

View File

@ -51,7 +51,7 @@ namespace BizHawk.Client.EmuHawk
if (width.HasValue)
{
var max = (width.Value - CellWidthPadding) / _charSize.Width;
var max = (int)((width.Value - CellWidthPadding) / _charSize.Width + 0.5);
if (text.Length >= max)
{
text = text.Substring(0, max);
@ -94,7 +94,7 @@ namespace BizHawk.Client.EmuHawk
int strOffsetX = 0;
int strOffsetY = 0;
QueryItemText(startRow, col, out text, ref strOffsetX, ref strOffsetY);
int textWidth = _renderer.MeasureString(text, Font).Width;
int textWidth = (int)_renderer.MeasureString(text, Font).Width;
height = Math.Max(height, textWidth + (CellWidthPadding * 2));
}
_horizontalColumnHeights[j] = height;
@ -122,7 +122,7 @@ namespace BizHawk.Client.EmuHawk
int textOffsetY = CellHeightPadding;
if (HorizontalOrientation)
{
int textHeight = _renderer.MeasureString(_columnDown.Text, Font).Height;
int textHeight = (int)_renderer.MeasureString(_columnDown.Text, Font).Height;
textOffsetY = (columnHeight - textHeight) / 2;
}
@ -176,7 +176,7 @@ namespace BizHawk.Client.EmuHawk
{
var column = visibleColumns[j];
var columnHeight = GetHColHeight(j);
var textHeight = _renderer.MeasureString(column.Text, Font).Height;
var textHeight = (int)_renderer.MeasureString(column.Text, Font).Height;
var point = new Point(CellWidthPadding, y + ((columnHeight - textHeight) / 2));
if (IsHoveringOnColumnCell && column == CurrentCell.Column)
@ -264,7 +264,7 @@ namespace BizHawk.Client.EmuHawk
int strOffsetY = 0;
QueryItemText(f + startRow, col, out var text, ref strOffsetX, ref strOffsetY);
int textWidth = _renderer.MeasureString(text, Font).Width;
int textWidth = (int)_renderer.MeasureString(text, Font).Width;
if (col.Rotatable)
{
// Center Text

View File

@ -34,7 +34,7 @@ namespace BizHawk.Client.EmuHawk
private int _maxCharactersInHorizontal = 1;
private int _rowCount;
private Size _charSize;
private SizeF _charSize;
// Updated on paint
private int[] _horizontalColumnHeights;
@ -151,7 +151,7 @@ namespace BizHawk.Client.EmuHawk
}
var newWidth = (maxLength * _charSize.Width) + (CellWidthPadding * 2);
CurrentCell.Column.Width = newWidth;
CurrentCell.Column.Width = (int)newWidth;
_columns.ColumnsChanged();
Refresh();
}
@ -1936,11 +1936,13 @@ namespace BizHawk.Client.EmuHawk
// Measure width change to ignore extra padding at start/end
var size1 = _renderer.MeasureString("A", Font);
var size2 = _renderer.MeasureString("AA", Font);
_charSize = new Size(size2.Width - size1.Width, size1.Height); // TODO make this a property so changing it updates other values.
_charSize = new SizeF(size2.Width - size1.Width, size1.Height); // TODO make this a property so changing it updates other values.
}
CellHeight = _charSize.Height + (CellHeightPadding * 2);
CellWidth = (_charSize.Width * MaxCharactersInHorizontal) + (CellWidthPadding * 4); // Double the padding for horizontal because it looks better
// TODO: Should we round instead of truncate?
CellHeight = (int)_charSize.Height + (CellHeightPadding * 2);
CellWidth = (int)(_charSize.Width * MaxCharactersInHorizontal) + (CellWidthPadding * 4); // Double the padding for horizontal because it looks better
ColumnWidth = CellWidth;
ColumnHeight = CellHeight + 2;
}