Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ private void DrawData(List<RollColumn> visibleColumns, int firstVisibleRow, int
_renderer.PrepDrawString(Font, _foreColor);

Cell currentCell = new();
Cell mouseCell = null;
if (ShowColumnTextOnHover && _draggingCell == null && !IsPaintDown)
{
mouseCell = CurrentCell;
}
if (HorizontalOrientation)
{
for (int j = 0; j < visibleColumns.Count; j++)
Expand Down Expand Up @@ -223,20 +228,28 @@ private void DrawData(List<RollColumn> visibleColumns, int firstVisibleRow, int

bool rePrep = false;
Color foreColor = _foreColor;
Font font = Font;
currentCell.Column = col;
currentCell.RowIndex = f + startRow;
if (_selectedItems.Contains(currentCell))
{
foreColor = SystemColors.HighlightText;
rePrep = true;
}
if (text.Length == 0 && mouseCell == currentCell)
{
font = new Font(Font, FontStyle.Regular);
foreColor = SystemColors.GrayText;
text = col.Text;
rePrep = true;
}
if (col.Rotatable || rePrep)
{
_renderer.PrepDrawString(Font, foreColor, rotate: col.Rotatable);
_renderer.PrepDrawString(font, foreColor, rotate: col.Rotatable);
rePrep = true;
}

int textWidth = (int)_renderer.MeasureString(text, Font).Width;
int textWidth = (int)_renderer.MeasureString(text, font).Width;
if (col.Rotatable)
{
// Center Text
Expand Down Expand Up @@ -287,13 +300,26 @@ private void DrawData(List<RollColumn> visibleColumns, int firstVisibleRow, int
QueryItemText(this, f + startRow, column, out var text, ref strOffsetX, ref strOffsetY);

bool rePrep = false;
Color foreColor = _foreColor;
Font font = Font;
currentCell.Column = column;
currentCell.RowIndex = f + startRow;
if (_selectedItems.Contains(currentCell))
{
_renderer.PrepDrawString(Font, SystemColors.HighlightText);
foreColor = SystemColors.HighlightText;
rePrep = true;
}
if (text.Length == 0 && mouseCell == currentCell)
{
font = new Font(Font, FontStyle.Regular);
foreColor = SystemColors.GrayText;
text = column.Text;
rePrep = true;
}
if (rePrep)
{
_renderer.PrepDrawString(font, foreColor);
}

DrawString(text, new Rectangle(point.X + strOffsetX, point.Y + strOffsetY, column.Width, ColumnHeight));

Expand Down
100 changes: 39 additions & 61 deletions src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ protected override void OnDoubleClick(EventArgs e)
[DefaultValue(true)]
public bool GridLines { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether empty cells will display their column's text when the mouse cursor is placed over them
/// </summary>
[DefaultValue(false)]
[Category("Appearance")]
public bool ShowColumnTextOnHover { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the control is horizontal or vertical
/// </summary>
Expand Down Expand Up @@ -725,8 +732,6 @@ public int FirstVisibleRow
_programmaticallyUpdatingScrollBarValues = false;
}
}
_programmaticallyChangingRow = false;
PointMouseToNewCell();
}
}

Expand Down Expand Up @@ -799,8 +804,6 @@ private int LastVisibleRow
}
while ((lastVisible - value < 0 || _lagFrames[VisibleRows - halfRow] < lastVisible - value) && FirstVisibleRow != 0);
}
_programmaticallyChangingRow = false;
PointMouseToNewCell();
}
}

Expand Down Expand Up @@ -911,21 +914,15 @@ public void ScrollToIndex(int index)
}
}
}
_programmaticallyChangingRow = false;
PointMouseToNewCell();
}

public bool _programmaticallyChangingRow = false;

/// <summary>
/// Scrolls so that the given index is visible, if it isn't already; doesn't use scroll settings.
/// </summary>
public void MakeIndexVisible(int index)
{
if (!IsVisible(index))
{
_programmaticallyChangingRow = true;

if (FirstVisibleRow > index)
{
FirstVisibleRow = index;
Expand Down Expand Up @@ -983,32 +980,16 @@ public IEnumerable<ToolStripItem> GenerateContextMenuItems()
private bool _columnDownMoved;
private int _previousX; // TODO: move me

// It's necessary to call this anytime the control is programmatically scrolled
// Since the mouse may not be pointing to the same cell anymore
public void PointMouseToNewCell()
public bool SuppressCellChange;

private void PointMouseToNewCell()
{
if (SuppressCellChange) return;

if (_currentX.HasValue && _currentY.HasValue)
{
var newCell = CalculatePointedCell(_currentX.Value, _currentY.Value);
if (CurrentCell != newCell)
{
if (QueryFrameLag != null && newCell.RowIndex.HasValue)
{
newCell.RowIndex += CountLagFramesDisplay(newCell.RowIndex.Value);
}

newCell.RowIndex += FirstVisibleRow;
if (newCell.RowIndex < 0)
{
newCell.RowIndex = 0;
}

if (_programmaticallyChangingRow)
{
_programmaticallyChangingRow = false;
CellChanged(newCell);
}
}
CellChanged(newCell);
}
}

Expand Down Expand Up @@ -1039,33 +1020,12 @@ protected override void OnMouseMove(MouseEventArgs e)

Cell newCell = CalculatePointedCell(_currentX.Value, _currentY.Value);

// SuuperW: Hide lag frames
if (QueryFrameLag != null && newCell.RowIndex.HasValue)
bool changed = CellChanged(newCell);
if (changed && (ShowColumnTextOnHover || IsHoveringOnColumnCell || WasHoveringOnColumnCell))
{
newCell.RowIndex += CountLagFramesDisplay(newCell.RowIndex.Value);
}

newCell.RowIndex += FirstVisibleRow;
if (newCell.RowIndex < 0)
{
newCell.RowIndex = 0;
}

if (!newCell.Equals(CurrentCell))
{
CellChanged(newCell);

if (IsHoveringOnColumnCell
|| (WasHoveringOnColumnCell && !IsHoveringOnColumnCell))
{
Refresh();
}
else if (_columnDown != null)
{
Refresh();
}
Refresh();
}
else if (_columnDown != null) // Kind of silly feeling to have this check twice, but the only alternative I can think of has it refreshing twice when pointed column changes with column down, and speed matters
else if (_columnDown != null)
{
Refresh();
}
Expand Down Expand Up @@ -1097,7 +1057,7 @@ protected override void OnMouseLeave(EventArgs e)
bool refresh = false;
_currentX = null;
_currentY = null;
if (IsHoveringOnColumnCell)
if (IsHoveringOnColumnCell || ShowColumnTextOnHover)
{
refresh = true;
}
Expand Down Expand Up @@ -1592,13 +1552,15 @@ private void OrientationChanged()
/// <summary>
/// Call this function to change the CurrentCell to newCell
/// </summary>
private void CellChanged(Cell newCell)
/// <returns>true if CurrentCell was changed</returns>
private bool CellChanged(Cell newCell)
{
if (newCell == CurrentCell) return false;

_lastCell = CurrentCell;
CurrentCell = newCell;

if (PointedCellChanged is not null
&& !(_lastCell?.Column == CurrentCell.Column && _lastCell?.RowIndex == CurrentCell.RowIndex)) //TODO isn't this just `Cell.==`? --yoshi
if (PointedCellChanged is not null)
{
PointedCellChanged(this, new CellEventArgs(_lastCell, CurrentCell));
}
Expand All @@ -1611,6 +1573,8 @@ private void CellChanged(Cell newCell)
{
_hoverTimer.Stop();
}

return true;
}

private void VerticalBar_ValueChanged(object sender, EventArgs e)
Expand All @@ -1620,6 +1584,7 @@ private void VerticalBar_ValueChanged(object sender, EventArgs e)
Refresh();
}

PointMouseToNewCell();
if (_horizontalOrientation)
{
ColumnScroll?.Invoke(this, e);
Expand All @@ -1637,6 +1602,7 @@ private void HorizontalBar_ValueChanged(object sender, EventArgs e)
Refresh();
}

PointMouseToNewCell();
if (_horizontalOrientation)
{
RowScroll?.Invoke(this, e);
Expand Down Expand Up @@ -1894,6 +1860,18 @@ private Cell CalculatePointedCell(int x, int y)
if (!(IsPaintDown || rightButton) && newCell.RowIndex <= -1) // -2 if we're entering from the top
{
newCell.RowIndex = null;
return newCell;
}

if (QueryFrameLag != null)
{
newCell.RowIndex += CountLagFramesDisplay(newCell.RowIndex.Value);
}

newCell.RowIndex += FirstVisibleRow;
if (newCell.RowIndex < 0)
{
newCell.RowIndex = 0;
}

return newCell;
Expand Down
16 changes: 5 additions & 11 deletions src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private InputRoll MakeInputRoll(int? insertAfter = null)
InputPaintingMode = true,
LetKeysModifySelection = true,
Rotatable = true,
ShowColumnTextOnHover = true,
// user configurable
AlwaysScroll = Settings.FollowCursorAlwaysScroll,
Font = Settings.TasViewFont,
Expand Down Expand Up @@ -762,10 +763,6 @@ private void TasView_MouseDown(object sender, MouseEventArgs e)
UpdateActiveMovieInputs();
}

// only on mouse button down, check that the pointed to cell is the correct one (can be wrong due to scroll while playing)
roll._programmaticallyChangingRow = true;
roll.PointMouseToNewCell();

if (e.Button == MouseButtons.Middle)
{
if (MainForm.EmulatorPaused)
Expand Down Expand Up @@ -1276,12 +1273,7 @@ private void TasView_PointedCellChanged(object sender, InputRoll.CellEventArgs e
InputRoll roll = (InputRoll)sender;
toolTip1.SetToolTip(roll, null);

if (e.NewCell.RowIndex is null)
{
return;
}

if (!MouseButtonHeld)
if (e.NewCell.RowIndex is null || !MouseButtonHeld)
{
return;
}
Expand Down Expand Up @@ -1345,7 +1337,9 @@ private void TasView_PointedCellChanged(object sender, InputRoll.CellEventArgs e

if (MouseButtonHeld)
{
roll.MakeIndexVisible(roll.CurrentCell.RowIndex.Value); // todo: limit scrolling speed
roll.SuppressCellChange = true; // avoid inifinite recursion of scrolling cuasing PointedCellChanged
roll.MakeIndexVisible(roll.CurrentCell.RowIndex.Value);
roll.SuppressCellChange = false;
SetTasViewRowCount(); // refreshes
}
}
Expand Down
Loading