draw axis numbers rotated in horizontal tastudio

see https://github.com/TASEmulators/BizHawk/issues/3708#issuecomment-2501398001
This commit is contained in:
Morilli 2025-03-02 00:34:42 +01:00
parent 5b7e7b4642
commit c476dbbf79
4 changed files with 40 additions and 86 deletions

View File

@ -24,9 +24,8 @@ namespace BizHawk.Client.EmuHawk
if (HorizontalOrientation)
{
CalculateHorizontalColumnPositions(VisibleColumns.ToList());
visibleColumns = VisibleColumns
.Take(_horizontalColumnTops.Count(c => c < e.ClipRectangle.Height))
.Where(c => c.Right > _vBar.Value && c.Left - _vBar.Value < e.ClipRectangle.Height)
.ToList();
}
else
@ -56,8 +55,8 @@ namespace BizHawk.Client.EmuHawk
// Foreground
DrawData(visibleColumns, firstVisibleRow, lastVisibleRow);
DrawColumnDrag(visibleColumns);
DrawCellDrag(visibleColumns);
DrawColumnDrag();
DrawCellDrag();
}
}
@ -74,34 +73,7 @@ namespace BizHawk.Client.EmuHawk
// Do nothing, and this should never be called
}
private void CalculateHorizontalColumnPositions(List<RollColumn> visibleColumns)
{
if (_horizontalColumnTops == null || _horizontalColumnTops.Length != visibleColumns.Count + 1)
{
_horizontalColumnTops = new int[visibleColumns.Count + 1];
}
int top = 0;
int startRow = FirstVisibleRow;
for (int j = 0; j < visibleColumns.Count; j++)
{
RollColumn col = visibleColumns[j];
int height = CellHeight;
if (col.Rotatable)
{
int strOffsetX = 0;
int strOffsetY = 0;
QueryItemText(startRow, col, out var text, ref strOffsetX, ref strOffsetY);
int textWidth = (int)_renderer.MeasureString(text, Font).Width;
height = Math.Max(height, textWidth + (CellWidthPadding * 2));
}
_horizontalColumnTops[j] = top;
top += height;
}
_horizontalColumnTops[visibleColumns.Count] = top;
}
private void DrawColumnDrag(List<RollColumn> visibleColumns)
private void DrawColumnDrag()
{
if (_columnDown is not { Width: > 0 }
|| !_columnDownMoved
@ -116,9 +88,8 @@ namespace BizHawk.Client.EmuHawk
int columnHeight = CellHeight;
if (HorizontalOrientation)
{
int columnIndex = visibleColumns.IndexOf(_columnDown);
columnWidth = MaxColumnWidth;
columnHeight = GetHColHeight(columnIndex);
columnHeight = _columnDown.Width;
}
int x1 = _currentX.Value - (columnWidth / 2);
@ -136,7 +107,7 @@ namespace BizHawk.Client.EmuHawk
_renderer.DrawString(_columnDown.Text, new Rectangle(x1 + CellWidthPadding, y1 + textOffsetY, columnWidth, columnHeight));
}
private void DrawCellDrag(List<RollColumn> visibleColumns)
private void DrawCellDrag()
{
if (_draggingCell is { RowIndex: int targetRow, Column: { Width: > 0 } targetCol }
&& _currentX.HasValue
@ -153,8 +124,7 @@ namespace BizHawk.Client.EmuHawk
int columnHeight = CellHeight;
if (HorizontalOrientation)
{
var columnIndex = visibleColumns.IndexOf(targetCol);
columnHeight = GetHColHeight(columnIndex);
columnHeight = targetCol.Width;
}
var x1 = _currentX.Value - targetCol.Width / 2;
int y1 = _currentY.Value - (columnHeight / 2);
@ -183,7 +153,7 @@ namespace BizHawk.Client.EmuHawk
if (HorizontalOrientation)
{
var columnHeight = GetHColHeight(j);
var columnHeight = column.Width;
var textSize = _renderer.MeasureString(column.Text, Font);
x = MaxColumnWidth - CellWidthPadding - (int)textSize.Width;
y = yOffset + ((columnHeight - (int)textSize.Height) / 2);
@ -225,14 +195,14 @@ namespace BizHawk.Client.EmuHawk
for (int j = 0; j < visibleColumns.Count; j++)
{
RollColumn col = visibleColumns[j];
int colHeight = GetHColHeight(j);
int colHeight = col.Width;
for (int i = 0, f = 0; f < range; i++, f++)
{
f += _lagFrames[i];
int baseX = RowsToPixels(i) + (col.Rotatable ? CellWidth : 0);
int baseY = GetHColTop(j) - _vBar.Value;
int baseY = col.Left - _vBar.Value;
if (!col.Rotatable)
{
@ -268,8 +238,8 @@ namespace BizHawk.Client.EmuHawk
else
{
// Center Text
int textX = Math.Max(((CellWidth - textWidth) / 2), CellWidthPadding) + strOffsetX;
int textY = CellHeightPadding + strOffsetY;
int textX = Math.Max(((CellWidth - textWidth) / 2), CellHeightPadding) + strOffsetX;
int textY = CellWidthPadding + strOffsetY;
DrawString(text, new Rectangle(baseX + textX, baseY + textY, MaxColumnWidth, CellHeight));
}
@ -335,7 +305,7 @@ namespace BizHawk.Client.EmuHawk
for (int j = 0; j < visibleColumns.Count; j++)
{
_renderer.Line(1, y, MaxColumnWidth, y);
y += GetHColHeight(j);
y += visibleColumns[j].Width;
}
if (visibleColumns.Count is not 0)
@ -379,8 +349,7 @@ namespace BizHawk.Client.EmuHawk
_renderer.SetBrush(SystemColors.ActiveBorder);
if (HorizontalOrientation)
{
int columnIndex = visibleColumns.IndexOf(column);
_renderer.FillRectangle(new Rectangle(1, GetHColTop(columnIndex) + 1, MaxColumnWidth - 1, GetHColHeight(columnIndex) - 1));
_renderer.FillRectangle(new Rectangle(1, column.Left + 1, MaxColumnWidth - 1, column.Width - 1));
}
else
{
@ -400,8 +369,8 @@ namespace BizHawk.Client.EmuHawk
continue;
}
int top = GetHColTop(i) - _vBar.Value;
int height = GetHColHeight(i);
int top = visibleColumns[i].Left - _vBar.Value;
int height = visibleColumns[i].Width;
_renderer.SetBrush(CurrentCell.Column!.Emphasis
? SystemColors.Highlight.Add(0x00222222)
@ -443,7 +412,7 @@ namespace BizHawk.Client.EmuHawk
{
if (QueryItemBkColor is not null || QueryRowBkColor is not null)
{
DoBackGroundCallback(visibleColumns, rect, firstVisibleRow, lastVisibleRow);
DoBackGroundCallback(visibleColumns, firstVisibleRow, lastVisibleRow);
}
if (GridLines)
@ -459,11 +428,12 @@ namespace BizHawk.Client.EmuHawk
}
// Rows
for (int i = 0; i < visibleColumns.Count + 1; i++)
_renderer.Line(RowsToPixels(0) + 1, 0, rect.Width + MaxColumnWidth, 0);
for (int i = 0; i < visibleColumns.Count; i++)
{
// TODO: MaxColumnWidth shouldn't be necessary
// This also makes too many assumptions, the parameters need to drive what is being drawn
int y = GetHColTop(i) - _vBar.Value;
int y = visibleColumns[i].Right - _vBar.Value;
int x = RowsToPixels(0) + 1;
_renderer.Line(x, y, rect.Width + MaxColumnWidth, y);
}
@ -492,10 +462,10 @@ namespace BizHawk.Client.EmuHawk
}
}
if (_selectedItems.Count is not 0) DoSelectionBG(visibleColumns, rect);
if (_selectedItems.Count is not 0) DoSelectionBG();
}
private void DoSelectionBG(List<RollColumn> visibleColumns, Rectangle rect)
private void DoSelectionBG()
{
var visibleRows = FirstVisibleRow.RangeTo(LastVisibleRow);
int lastRow = -1;
@ -537,12 +507,12 @@ namespace BizHawk.Client.EmuHawk
cellColor = Color.FromArgb(cellColor.R - (int)((cellColor.R - SystemColors.Highlight.R) * alpha),
cellColor.G - (int)((cellColor.G - SystemColors.Highlight.G) * alpha),
cellColor.B - (int)((cellColor.B - SystemColors.Highlight.B) * alpha));
DrawCellBG(cellColor, relativeCell, visibleColumns, rect);
DrawCellBG(cellColor, relativeCell);
}
}
// Given a cell with RowIndex in between 0 and VisibleRows, it draws the background color specified. Do not call with absolute row indices.
private void DrawCellBG(Color color, Cell cell, List<RollColumn> visibleColumns, Rectangle rect)
private void DrawCellBG(Color color, Cell cell)
{
int x, y, w, h;
@ -554,10 +524,9 @@ namespace BizHawk.Client.EmuHawk
return;
}
var columnIndex = visibleColumns.IndexOf(cell.Column!);
w = CellWidth - 1;
y = GetHColTop(columnIndex) - _vBar.Value + 1;
h = GetHColHeight(columnIndex) - 1;
y = cell.Column!.Left - _vBar.Value + 1;
h = cell.Column.Width - 1;
}
else
{
@ -577,7 +546,7 @@ namespace BizHawk.Client.EmuHawk
}
// Calls QueryItemBkColor callback for all visible cells and fills in the background of those cells.
private void DoBackGroundCallback(List<RollColumn> visibleColumns, Rectangle rect, int firstVisibleRow, int lastVisibleRow)
private void DoBackGroundCallback(List<RollColumn> visibleColumns, int firstVisibleRow, int lastVisibleRow)
{
if (visibleColumns.Count is 0) return;
@ -606,7 +575,7 @@ namespace BizHawk.Client.EmuHawk
{
currentCell.Column = column;
currentCell.RowIndex = i;
DrawCellBG(itemColor, currentCell, visibleColumns, rect);
DrawCellBG(itemColor, currentCell);
}
}
}

View File

@ -54,8 +54,6 @@ namespace BizHawk.Client.EmuHawk
private int _rowCount;
private SizeF _charSize;
private int[] _horizontalColumnTops; // Updated on paint, contains one extra item to allow inference of last column height
private RollColumn/*?*/ _columnDown;
private RollColumn/*?*/ _columnResizing;
@ -299,9 +297,7 @@ namespace BizHawk.Client.EmuHawk
int x = MaxColumnWidth;
int y = 0;
int w = Width - x;
int h = VisibleColumns.Any()
? GetHColBottom(VisibleColumns.Count() - 1)
: 0;
int h = TotalColWidth;
h = Math.Min(h, _drawHeight);
Invalidate(new Rectangle(x, y, w, h));
@ -1664,11 +1660,11 @@ namespace BizHawk.Client.EmuHawk
}
}
private void CalculateScrollbarsNeeded(int lastVisibleColumn)
private void CalculateScrollbarsNeeded()
{
if (HorizontalOrientation)
{
NeedsVScrollbar = GetHColBottom(lastVisibleColumn) > _drawHeight;
NeedsVScrollbar = TotalColWidth > _drawHeight;
NeedsHScrollbar = RowCount > 1;
}
else
@ -1682,7 +1678,7 @@ namespace BizHawk.Client.EmuHawk
// if either NeedsVScrollbar or NeedsHScrollbar changed we need to recalculate, so just run this again
if (HorizontalOrientation)
{
NeedsVScrollbar = GetHColBottom(lastVisibleColumn) > _drawHeight;
NeedsVScrollbar = TotalColWidth > _drawHeight;
NeedsHScrollbar = RowCount > 1;
}
else
@ -1698,8 +1694,7 @@ namespace BizHawk.Client.EmuHawk
// See MSDN Page for more information on the dumb ScrollBar.Maximum Property
private void RecalculateScrollBars()
{
int lastVisibleColumn = _columns.VisibleColumns.Count() - 1;
CalculateScrollbarsNeeded(lastVisibleColumn);
CalculateScrollbarsNeeded();
if (VisibleRows > 0)
{
@ -1724,7 +1719,7 @@ namespace BizHawk.Client.EmuHawk
{
if (HorizontalOrientation)
{
_vBar.Maximum = GetHColBottom(lastVisibleColumn) - _drawHeight + _vBar.LargeChange;
_vBar.Maximum = TotalColWidth - _drawHeight + _vBar.LargeChange;
if (_vBar.Maximum < 0)
{
_vBar.Maximum = 0;
@ -1902,7 +1897,7 @@ namespace BizHawk.Client.EmuHawk
if (_horizontalOrientation)
{
return _columns.VisibleColumns.Select(static (n, i) => (Column: n, Index: i))
.FirstOrNull(item => pixel >= GetHColTop(item.Index) - _vBar.Value && pixel <= GetHColBottom(item.Index) - _vBar.Value)
.FirstOrNull(item => pixel >= item.Column.Left - _vBar.Value && pixel <= item.Column.Right - _vBar.Value)
?.Column;
}
return _columns.VisibleColumns.FirstOrDefault(column => pixel >= column.Left - _hBar.Value && pixel <= column.Right - _hBar.Value);
@ -1938,19 +1933,6 @@ namespace BizHawk.Client.EmuHawk
return (int)Math.Floor((float)(pixels - ColumnHeight) / CellHeight);
}
private int GetHColTop(int index) =>
_horizontalColumnTops != null && 0.RangeToExclusive(_horizontalColumnTops.Length).Contains(index)
? _horizontalColumnTops[index]
: index * CellHeight;
private int GetHColHeight(int index) =>
_horizontalColumnTops != null && 0.RangeToExclusive(_horizontalColumnTops.Length - 1).Contains(index)
? _horizontalColumnTops[index + 1] - _horizontalColumnTops[index]
: CellHeight;
private int GetHColBottom(int index) =>
GetHColTop(index + 1);
// The width of the largest column cell in Horizontal Orientation
private int MaxColumnWidth { get; set; }

View File

@ -24,7 +24,7 @@ namespace BizHawk.Client.EmuHawk
public bool Emphasis { get; set; }
/// <summary>
/// Column header text will be drawn rotated, if true
/// Column text will be drawn rotated if true
/// </summary>
public bool Rotatable { get; set; }

View File

@ -360,7 +360,10 @@ namespace BizHawk.Client.EmuHawk
name: name,
widthUnscaled: (maxLength * 6) + 14, // magic numbers reused in EditBranchTextPopUp() --feos // not since eb63fa5a9 (before 2.3.3) --yoshi
type: type,
text: mnemonic));
text: mnemonic)
{
Rotatable = type is ColumnType.Axis
});
}
var columnsToHide = TasView.AllColumns