InputRoll horizontal!
This commit is contained in:
parent
28c0586c8b
commit
4d2f6e902e
|
@ -9,8 +9,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public partial class InputRoll
|
||||
{
|
||||
private int[] _horizontalColumnHeights;
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
using (_renderer.LockGraphics(e.Graphics, Width, Height))
|
||||
|
@ -25,7 +23,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
var visibleColumns = _columns.VisibleColumns.ToList();
|
||||
|
||||
CalculateHorizontalColumnHeights(visibleColumns);
|
||||
CalculateHorizontalColumnPositions(visibleColumns);
|
||||
|
||||
if (visibleColumns.Any())
|
||||
{
|
||||
|
@ -39,8 +37,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
// Foreground
|
||||
DrawData(visibleColumns);
|
||||
|
||||
DrawColumnDrag();
|
||||
DrawCellDrag();
|
||||
DrawColumnDrag(visibleColumns);
|
||||
DrawCellDrag(visibleColumns);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,16 +66,19 @@ namespace BizHawk.Client.EmuHawk
|
|||
// Do nothing, and this should never be called
|
||||
}
|
||||
|
||||
private void CalculateHorizontalColumnHeights(List<RollColumn> visibleColumns)
|
||||
private void CalculateHorizontalColumnPositions(List<RollColumn> visibleColumns)
|
||||
{
|
||||
if (!HorizontalOrientation)
|
||||
{
|
||||
_horizontalColumnHeights = null;
|
||||
_horizontalColumnTops = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_horizontalColumnHeights = new int[visibleColumns.Count];
|
||||
_horizontalColumnTops = new int[visibleColumns.Count];
|
||||
|
||||
int top = 0;
|
||||
int startRow = FirstVisibleRow;
|
||||
for (int j = 0; j < visibleColumns.Count; j++)
|
||||
{
|
||||
|
@ -97,27 +98,25 @@ namespace BizHawk.Client.EmuHawk
|
|||
height = Math.Max(height, textWidth + (CellWidthPadding * 2));
|
||||
}
|
||||
_horizontalColumnHeights[j] = height;
|
||||
_horizontalColumnTops[j] = top;
|
||||
top += height;
|
||||
}
|
||||
}
|
||||
|
||||
private int HorizontalColumnsToPixels(int index)
|
||||
{
|
||||
int height = 0;
|
||||
for (int j = 0; j < index; j++)
|
||||
{
|
||||
height += _horizontalColumnHeights[j];
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
private void DrawColumnDrag()
|
||||
private void DrawColumnDrag(List<RollColumn> visibleColumns)
|
||||
{
|
||||
if (_columnDown?.Width != null && _columnDownMoved && _currentX.HasValue && _currentY.HasValue && IsHoveringOnColumnCell)
|
||||
{
|
||||
int columnHeight = CellHeight;
|
||||
if (HorizontalOrientation)
|
||||
{
|
||||
int columnIndex = visibleColumns.IndexOf(_columnDown);
|
||||
columnHeight = GetHColHeight(columnIndex);
|
||||
}
|
||||
int x1 = _currentX.Value - (_columnDown.Width.Value / 2);
|
||||
int y1 = _currentY.Value - (CellHeight / 2);
|
||||
int y1 = _currentY.Value - (columnHeight / 2);
|
||||
int x2 = x1 + _columnDown.Width.Value;
|
||||
int y2 = y1 + CellHeight;
|
||||
int y2 = y1 + columnHeight;
|
||||
|
||||
_renderer.SetSolidPen(_backColor);
|
||||
_renderer.DrawRectangle(x1, y1, x2, y2);
|
||||
|
@ -126,7 +125,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private void DrawCellDrag()
|
||||
private void DrawCellDrag(List<RollColumn> visibleColumns)
|
||||
{
|
||||
if (_draggingCell != null && _draggingCell.RowIndex.HasValue && _draggingCell.Column.Width.HasValue
|
||||
&& _currentX.HasValue && _currentY.HasValue)
|
||||
|
@ -139,10 +138,16 @@ namespace BizHawk.Client.EmuHawk
|
|||
Color bgColor = _backColor;
|
||||
QueryItemBkColor?.Invoke(_draggingCell.RowIndex.Value, _draggingCell.Column, ref bgColor);
|
||||
|
||||
int columnHeight = CellHeight;
|
||||
if (HorizontalOrientation)
|
||||
{
|
||||
int columnIndex = visibleColumns.IndexOf(_draggingCell.Column);
|
||||
columnHeight = GetHColHeight(columnIndex);
|
||||
}
|
||||
int x1 = _currentX.Value - (_draggingCell.Column.Width.Value / 2);
|
||||
int y1 = _currentY.Value - (CellHeight / 2);
|
||||
int y1 = _currentY.Value - (columnHeight / 2);
|
||||
int x2 = x1 + _draggingCell.Column.Width.Value;
|
||||
int y2 = y1 + CellHeight;
|
||||
int y2 = y1 + columnHeight;
|
||||
|
||||
_renderer.SetBrush(bgColor);
|
||||
_renderer.FillRectangle(x1, y1, x2 - x1, y2 - y1);
|
||||
|
@ -162,7 +167,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
for(int j = 0; j < visibleColumns.Count; j++)
|
||||
{
|
||||
var column = visibleColumns[j];
|
||||
var columnHeight = _horizontalColumnHeights[j];
|
||||
var columnHeight = GetHColHeight(j);
|
||||
var textHeight = _renderer.MeasureString(column.Text, _font).Height;
|
||||
var point = new Point(CellWidthPadding, y + ((columnHeight - textHeight) / 2));
|
||||
|
||||
|
@ -222,14 +227,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
for (int j = FirstVisibleColumn; j <= lastVisible; j++)
|
||||
{
|
||||
RollColumn col = visibleColumns[j];
|
||||
int colHeight = _horizontalColumnHeights[j];
|
||||
int colHeight = GetHColHeight(j);
|
||||
|
||||
for (int i = 0, f = 0; f < range; i++, f++)
|
||||
{
|
||||
f += _lagFrames[i];
|
||||
|
||||
int baseX = RowsToPixels(i) + (col.Rotatable ? CellWidth : 0);
|
||||
int baseY = HorizontalColumnsToPixels(j) - _vBar.Value;
|
||||
int baseY = GetHColTop(j) - _vBar.Value;
|
||||
|
||||
if (!col.Rotatable)
|
||||
{
|
||||
|
@ -341,7 +346,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
for (int j = 0; j < visibleColumns.Count; j++)
|
||||
{
|
||||
_renderer.Line(1, y, ColumnWidth, y);
|
||||
y += _horizontalColumnHeights[j];
|
||||
y += GetHColHeight(j);
|
||||
}
|
||||
|
||||
if (visibleColumns.Any())
|
||||
|
@ -383,7 +388,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (HorizontalOrientation)
|
||||
{
|
||||
int columnIndex = visibleColumns.IndexOf(column);
|
||||
_renderer.FillRectangle(1, HorizontalColumnsToPixels(columnIndex) + 1, ColumnWidth - 1, _horizontalColumnHeights[columnIndex] - 1);
|
||||
_renderer.FillRectangle(1, GetHColTop(columnIndex) + 1, ColumnWidth - 1, GetHColHeight(columnIndex) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -403,11 +408,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
continue;
|
||||
}
|
||||
|
||||
int top = GetHColTop(i) - _vBar.Value;
|
||||
int height = GetHColHeight(i);
|
||||
|
||||
_renderer.SetBrush(CurrentCell.Column.Emphasis
|
||||
? SystemColors.Highlight.Add(0x00222222)
|
||||
: SystemColors.Highlight);
|
||||
|
||||
_renderer.FillRectangle(1, HorizontalColumnsToPixels(i) + 1, ColumnWidth - 1, _horizontalColumnHeights[i] - 1);
|
||||
_renderer.FillRectangle(1, top + 1, ColumnWidth - 1, height - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -463,7 +471,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
// Rows
|
||||
for (int i = 0; i < visibleColumns.Count + 1; i++)
|
||||
{
|
||||
int y = HorizontalColumnsToPixels(i) - _vBar.Value;
|
||||
int y = GetHColTop(i) - _vBar.Value;
|
||||
_renderer.Line(RowsToPixels(0) + 1, y, DrawWidth, y);
|
||||
}
|
||||
}
|
||||
|
@ -560,8 +568,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
int columnIndex = visibleColumns.IndexOf(cell.Column);
|
||||
w = CellWidth - 1;
|
||||
y = HorizontalColumnsToPixels(columnIndex) - _vBar.Value + 1; // We can't draw without row and column, so assume they exist and fail catastrophically if they don't
|
||||
h = _horizontalColumnHeights[columnIndex] - 1;
|
||||
y = GetHColTop(columnIndex) - _vBar.Value + 1; // We can't draw without row and column, so assume they exist and fail catastrophically if they don't
|
||||
h = GetHColHeight(columnIndex) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -35,7 +35,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
private int _maxCharactersInHorizontal = 1;
|
||||
|
||||
private int _rowCount;
|
||||
private Size _charSize;
|
||||
private Size _charSize;
|
||||
|
||||
// Updated on paint
|
||||
private int[] _horizontalColumnHeights;
|
||||
private int[] _horizontalColumnTops;
|
||||
|
||||
private RollColumn _columnDown;
|
||||
private RollColumn _columnResizing;
|
||||
|
@ -148,7 +152,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
else
|
||||
{
|
||||
var maxLength = CurrentCell.Column.Text?.Length ?? 0;
|
||||
|
||||
|
||||
for (int i = 0; i < RowCount; i++)
|
||||
{
|
||||
|
@ -829,12 +832,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
get
|
||||
{
|
||||
var columnList = VisibleColumns.ToList();
|
||||
|
||||
if (HorizontalOrientation)
|
||||
{
|
||||
return _vBar.Value / CellHeight;
|
||||
return Enumerable.Range(0, columnList.Count).First(i => GetHColBottom(i) > _vBar.Value);
|
||||
}
|
||||
|
||||
var columnList = VisibleColumns.ToList();
|
||||
return columnList.FindIndex(c => c.Right > _hBar.Value);
|
||||
}
|
||||
}
|
||||
|
@ -846,21 +850,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
get
|
||||
{
|
||||
List<RollColumn> columnList = VisibleColumns.ToList();
|
||||
int ret;
|
||||
|
||||
if (HorizontalOrientation)
|
||||
{
|
||||
ret = (_vBar.Value + DrawHeight) / CellHeight;
|
||||
if (ret >= columnList.Count)
|
||||
{
|
||||
ret = columnList.Count - 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = columnList.FindLastIndex(c => c.Left <= DrawWidth + _hBar.Value);
|
||||
int count = columnList.Count;
|
||||
return Enumerable.Range(0, count).Select(i => count - 1 - i).First(i => GetHColTop(i) <= DrawWidth + _hBar.Value);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return columnList.FindLastIndex(c => c.Left <= DrawWidth + _hBar.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1279,11 +1276,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
ColumnClickEvent(ColumnAtX(e.X));
|
||||
ColumnClickEvent(ColumnAtPixel(e.X));
|
||||
}
|
||||
else if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
ColumnRightClickEvent(ColumnAtX(e.X));
|
||||
ColumnRightClickEvent(ColumnAtPixel(e.X));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1634,11 +1631,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
UpdateDrawSize();
|
||||
|
||||
var columns = _columns.VisibleColumns.ToList();
|
||||
var columns = _columns.VisibleColumns.ToList();
|
||||
int iLastColumn = columns.Count - 1;
|
||||
|
||||
if (HorizontalOrientation)
|
||||
{
|
||||
NeedsVScrollbar = columns.Count > DrawHeight / CellHeight;
|
||||
NeedsVScrollbar = GetHColBottom(iLastColumn) > DrawHeight;
|
||||
NeedsHScrollbar = RowCount > 1;
|
||||
}
|
||||
else
|
||||
|
@ -1652,9 +1650,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (HorizontalOrientation)
|
||||
{
|
||||
_vBar.LargeChange = DrawHeight / 2;
|
||||
_hBar.Maximum = Math.Max((VisibleRows - 1) * CellHeight, _hBar.Maximum);
|
||||
_hBar.LargeChange = (VisibleRows - 1) * CellHeight;
|
||||
_hBar.Maximum = Math.Max((VisibleRows - 1) * CellWidth, _hBar.Maximum);
|
||||
_hBar.LargeChange = (VisibleRows - 1) * CellWidth;
|
||||
_vBar.LargeChange = Math.Max(0, DrawHeight / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1671,7 +1669,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (HorizontalOrientation)
|
||||
{
|
||||
_vBar.Maximum = ((columns.Count() * CellHeight) - DrawHeight) + _vBar.LargeChange;
|
||||
_vBar.Maximum = GetHColBottom(iLastColumn) - DrawHeight + _vBar.LargeChange;
|
||||
if (_vBar.Maximum < 0)
|
||||
{
|
||||
_vBar.Maximum = 0;
|
||||
|
@ -1680,7 +1678,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
else
|
||||
{
|
||||
_vBar.Maximum = RowsToPixels(RowCount + 1) - (CellHeight * 3) + _vBar.LargeChange - 1;
|
||||
|
||||
if (_vBar.Maximum < 0)
|
||||
{
|
||||
_vBar.Maximum = 0;
|
||||
|
@ -1841,17 +1838,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (HorizontalOrientation)
|
||||
{
|
||||
newCell.RowIndex = PixelsToRows(x);
|
||||
|
||||
int colIndex = (y + _vBar.Value) / CellHeight;
|
||||
if (colIndex >= 0 && colIndex < columns.Count)
|
||||
{
|
||||
newCell.Column = columns[colIndex];
|
||||
}
|
||||
newCell.Column = ColumnAtPixel(y);
|
||||
}
|
||||
else
|
||||
{
|
||||
newCell.RowIndex = PixelsToRows(y);
|
||||
newCell.Column = ColumnAtX(x);
|
||||
newCell.Column = ColumnAtPixel(x);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1887,20 +1879,32 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the RollColumn object at the specified visible x coordinate. Coordinate should be between 0 and Width of the InputRoll Control.
|
||||
/// Returns the RollColumn object at the specified visible pixel coordinate.
|
||||
/// </summary>
|
||||
/// <param name="x">The x coordinate.</param>
|
||||
/// <returns>RollColumn object that contains the x coordinate or null if none exists.</returns>
|
||||
private RollColumn ColumnAtX(int x)
|
||||
/// <param name="pixels">The pixel coordinate.</param>
|
||||
/// <returns>RollColumn object that contains the pixel coordinate or null if none exists.</returns>
|
||||
private RollColumn ColumnAtPixel(int pixel)
|
||||
{
|
||||
foreach (RollColumn column in _columns.VisibleColumns)
|
||||
if (_horizontalOrientation)
|
||||
{
|
||||
if (column.Left.Value - _hBar.Value <= x && column.Right.Value - _hBar.Value >= x)
|
||||
foreach (var item in _columns.VisibleColumns.Select((n, i) => new { Column = n, Index = i }))
|
||||
{
|
||||
return column;
|
||||
if (GetHColTop(item.Index) - _vBar.Value <= pixel && GetHColBottom(item.Index) - _vBar.Value >= pixel)
|
||||
{
|
||||
return item.Column;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (RollColumn column in _columns.VisibleColumns)
|
||||
{
|
||||
if (column.Left.Value - _hBar.Value <= pixel && column.Right.Value - _hBar.Value >= pixel)
|
||||
{
|
||||
return column;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1933,7 +1937,16 @@ namespace BizHawk.Client.EmuHawk
|
|||
return (int)Math.Floor((float)(pixels - ColumnHeight) / CellHeight);
|
||||
}
|
||||
|
||||
// The width of the largest column cell in Horizontal Orientation
|
||||
private int GetHColHeight(int index) =>
|
||||
_horizontalColumnHeights != null && index < _horizontalColumnHeights.Length ? _horizontalColumnHeights[index] : CellHeight;
|
||||
|
||||
private int GetHColTop(int index) =>
|
||||
_horizontalColumnTops != null && index < _horizontalColumnTops.Length ? _horizontalColumnTops[index] : (index * CellHeight);
|
||||
|
||||
private int GetHColBottom(int index) =>
|
||||
GetHColTop(index) + GetHColHeight(index);
|
||||
|
||||
// The width of the largest column cell in Horizontal Orientation
|
||||
private int ColumnWidth { get; set; }
|
||||
|
||||
// The height of a column cell in Vertical Orientation.
|
||||
|
|
Loading…
Reference in New Issue