InputRoll - drawing - use e.ClipRectangle instead of width/height to draw
This commit is contained in:
parent
813e5820ae
commit
bb5267d042
|
@ -16,13 +16,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
// White Background
|
// White Background
|
||||||
_renderer.SetBrush(Color.White);
|
_renderer.SetBrush(Color.White);
|
||||||
_renderer.SetSolidPen(Color.White);
|
_renderer.SetSolidPen(Color.White);
|
||||||
_renderer.FillRectangle(new Rectangle(0, CellHeight, _drawWidth, _drawHeight));
|
_renderer.FillRectangle(e.ClipRectangle);
|
||||||
|
|
||||||
// Lag frame calculations
|
// Lag frame calculations
|
||||||
SetLagFramesArray();
|
SetLagFramesArray();
|
||||||
|
|
||||||
var visibleColumns = _columns.VisibleColumns.ToList();
|
var visibleColumns = _columns.VisibleColumns
|
||||||
|
.Where(c => c.Left < e.ClipRectangle.Width)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// TODO: FirstVisibleRow assumes there is a visible row
|
||||||
|
var firstVisibleRow = FirstVisibleRow;
|
||||||
|
var lastVisibleRow = firstVisibleRow + CalcVisibleRows(e.ClipRectangle);
|
||||||
CalculateHorizontalColumnPositions(visibleColumns);
|
CalculateHorizontalColumnPositions(visibleColumns);
|
||||||
|
|
||||||
if (visibleColumns.Any())
|
if (visibleColumns.Any())
|
||||||
|
@ -32,10 +37,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
DrawBg(visibleColumns);
|
DrawBg(visibleColumns, e.ClipRectangle);
|
||||||
|
|
||||||
// Foreground
|
// Foreground
|
||||||
DrawData(visibleColumns);
|
DrawData(visibleColumns, e.ClipRectangle, firstVisibleRow, lastVisibleRow);
|
||||||
|
|
||||||
DrawColumnDrag(visibleColumns);
|
DrawColumnDrag(visibleColumns);
|
||||||
DrawCellDrag(visibleColumns);
|
DrawCellDrag(visibleColumns);
|
||||||
|
@ -57,6 +62,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void CalculateHorizontalColumnPositions(List<RollColumn> visibleColumns)
|
private void CalculateHorizontalColumnPositions(List<RollColumn> visibleColumns)
|
||||||
{
|
{
|
||||||
|
int firstVisibleRow = FirstVisibleRow;
|
||||||
|
|
||||||
if (!HorizontalOrientation)
|
if (!HorizontalOrientation)
|
||||||
{
|
{
|
||||||
_horizontalColumnHeights = null;
|
_horizontalColumnHeights = null;
|
||||||
|
@ -68,7 +75,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_horizontalColumnTops = new int[visibleColumns.Count];
|
_horizontalColumnTops = new int[visibleColumns.Count];
|
||||||
|
|
||||||
int top = 0;
|
int top = 0;
|
||||||
int startRow = FirstVisibleRow;
|
int startRow = firstVisibleRow;
|
||||||
for (int j = 0; j < visibleColumns.Count; j++)
|
for (int j = 0; j < visibleColumns.Count; j++)
|
||||||
{
|
{
|
||||||
RollColumn col = visibleColumns[j];
|
RollColumn col = visibleColumns[j];
|
||||||
|
@ -200,8 +207,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawData(List<RollColumn> visibleColumns)
|
private void DrawData(List<RollColumn> visibleColumns, Rectangle rect, int firstVisibleRow, int lastVisibleRow)
|
||||||
{
|
{
|
||||||
|
int firstVisibleColumn = FirstVisibleColumn(visibleColumns);
|
||||||
|
var lastVisibleColumn = LastVisibleColumn(visibleColumns, rect.Width);
|
||||||
|
|
||||||
// Prevent exceptions with small TAStudio windows
|
// Prevent exceptions with small TAStudio windows
|
||||||
if (visibleColumns.Count == 0)
|
if (visibleColumns.Count == 0)
|
||||||
{
|
{
|
||||||
|
@ -213,14 +223,14 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int startRow = FirstVisibleRow;
|
int startRow = firstVisibleRow;
|
||||||
int range = Math.Min(LastVisibleRow, RowCount - 1) - startRow + 1;
|
int range = Math.Min(lastVisibleRow, RowCount - 1) - startRow + 1;
|
||||||
_renderer.PrepDrawString(Font, _foreColor);
|
_renderer.PrepDrawString(Font, _foreColor);
|
||||||
|
|
||||||
if (HorizontalOrientation)
|
if (HorizontalOrientation)
|
||||||
{
|
{
|
||||||
int lastVisible = LastVisibleColumn;
|
int lastVisible = lastVisibleRow;
|
||||||
for (int j = FirstVisibleColumn; j <= lastVisible; j++)
|
for (int j = firstVisibleRow; j <= lastVisible; j++)
|
||||||
{
|
{
|
||||||
RollColumn col = visibleColumns[j];
|
RollColumn col = visibleColumns[j];
|
||||||
int colHeight = GetHColHeight(j);
|
int colHeight = GetHColHeight(j);
|
||||||
|
@ -280,8 +290,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
for (int i = 0, f = 0; f < range; i++, f++) // Vertical
|
for (int i = 0, f = 0; f < range; i++, f++) // Vertical
|
||||||
{
|
{
|
||||||
f += _lagFrames[i];
|
f += _lagFrames[i];
|
||||||
int lastVisible = LastVisibleColumn;
|
int lastVisible = lastVisibleColumn;
|
||||||
for (int j = FirstVisibleColumn; j <= lastVisible; j++) // Horizontal
|
for (int j = firstVisibleColumn; j <= lastVisible; j++) // Horizontal
|
||||||
{
|
{
|
||||||
RollColumn col = visibleColumns[j];
|
RollColumn col = visibleColumns[j];
|
||||||
|
|
||||||
|
@ -434,11 +444,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
// TODO refactor this and DoBackGroundCallback functions.
|
// TODO refactor this and DoBackGroundCallback functions.
|
||||||
// Draw Gridlines and background colors using QueryItemBkColor.
|
// Draw Gridlines and background colors using QueryItemBkColor.
|
||||||
private void DrawBg(List<RollColumn> visibleColumns)
|
private void DrawBg(List<RollColumn> visibleColumns, Rectangle rect)
|
||||||
{
|
{
|
||||||
if (QueryItemBkColor != null)
|
if (QueryItemBkColor != null)
|
||||||
{
|
{
|
||||||
DoBackGroundCallback(visibleColumns);
|
DoBackGroundCallback(visibleColumns, rect.Width);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GridLines)
|
if (GridLines)
|
||||||
|
@ -579,12 +589,12 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calls QueryItemBkColor callback for all visible cells and fills in the background of those cells.
|
// Calls QueryItemBkColor callback for all visible cells and fills in the background of those cells.
|
||||||
private void DoBackGroundCallback(List<RollColumn> visibleColumns)
|
private void DoBackGroundCallback(List<RollColumn> visibleColumns, int width)
|
||||||
{
|
{
|
||||||
int startIndex = FirstVisibleRow;
|
int startIndex = FirstVisibleRow;
|
||||||
int range = Math.Min(LastVisibleRow, RowCount - 1) - startIndex + 1;
|
int range = Math.Min(LastVisibleRow, RowCount - 1) - startIndex + 1;
|
||||||
int lastVisibleColumn = LastVisibleColumn;
|
int lastVisibleColumn = LastVisibleColumn(visibleColumns, width);
|
||||||
int firstVisibleColumn = FirstVisibleColumn;
|
int firstVisibleColumn = FirstVisibleColumn(visibleColumns);
|
||||||
|
|
||||||
// Prevent exceptions with small TAStudio windows
|
// Prevent exceptions with small TAStudio windows
|
||||||
if (firstVisibleColumn < 0)
|
if (firstVisibleColumn < 0)
|
||||||
|
|
|
@ -778,12 +778,20 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int FirstVisibleColumn
|
// TODO: don't duplicate property logic
|
||||||
|
private int CalcVisibleRows(Rectangle rect)
|
||||||
{
|
{
|
||||||
get
|
if (HorizontalOrientation)
|
||||||
{
|
{
|
||||||
var columnList = VisibleColumns.ToList();
|
return (rect.Width - MaxColumnWidth) / CellWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (rect.Height - ColumnHeight - 3) / CellHeight; // Minus three makes it work
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: account for no visible columns
|
||||||
|
private int FirstVisibleColumn(List<RollColumn> columnList)
|
||||||
|
{
|
||||||
if (HorizontalOrientation)
|
if (HorizontalOrientation)
|
||||||
{
|
{
|
||||||
return Enumerable.Range(0, columnList.Count).First(i => GetHColBottom(i) > _vBar.Value);
|
return Enumerable.Range(0, columnList.Count).First(i => GetHColBottom(i) > _vBar.Value);
|
||||||
|
@ -791,22 +799,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
return columnList.FindIndex(c => c.Right > _hBar.Value);
|
return columnList.FindIndex(c => c.Right > _hBar.Value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private int LastVisibleColumn
|
private int LastVisibleColumn(List<RollColumn> columnList, int width)
|
||||||
{
|
{
|
||||||
get
|
|
||||||
{
|
|
||||||
var columnList = VisibleColumns.ToList();
|
|
||||||
|
|
||||||
if (HorizontalOrientation)
|
if (HorizontalOrientation)
|
||||||
{
|
{
|
||||||
int count = columnList.Count;
|
int count = columnList.Count;
|
||||||
return Enumerable.Range(0, count).Select(i => count - 1 - i).First(i => GetHColTop(i) <= _drawWidth + _hBar.Value);
|
return Enumerable.Range(0, count)
|
||||||
|
.Select(i => count - 1 - i)
|
||||||
|
.First(i => GetHColTop(i) <= _drawWidth + _hBar.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return columnList.FindLastIndex(c => c.Left <= _drawWidth + _hBar.Value);
|
return columnList.FindLastIndex(c => c.Left <= _drawWidth + _hBar.Value && c.Left < width);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cell _draggingCell;
|
private Cell _draggingCell;
|
||||||
|
|
Loading…
Reference in New Issue