Update FrmMain.cs - 2nd rev.
This time I have pre-computed all the font colors into a table named _fontColor. These pre-computed values are created as soon as the _displayColor table is finished being created. Using these pre-computed values is more efficient than computing them for every entry in the GameGrid and RomGrid.
This commit is contained in:
@@ -33,6 +33,7 @@ namespace ROMVault2
|
||||
private static readonly Color CWhite = Color.FromArgb(255, 255, 255);
|
||||
|
||||
private readonly Color[] _displayColor;
|
||||
private readonly Color[] _fontColor;
|
||||
|
||||
private bool _updatingGameGrid;
|
||||
|
||||
@@ -59,13 +60,6 @@ namespace ROMVault2
|
||||
_scaleFactorY *= factor.Height;
|
||||
}
|
||||
|
||||
// returns either white or black, depending of quick luminance of Color "a"
|
||||
// probably should be pre-computed into a table, corresponding to _displayColor
|
||||
private Color contrasty(Color a)
|
||||
{
|
||||
return (a.R << 1) + a.B + a.G + (a.G << 2) < 1024 ? Color.White : Color.Black;
|
||||
}
|
||||
|
||||
public FrmMain()
|
||||
{
|
||||
|
||||
@@ -77,6 +71,7 @@ namespace ROMVault2
|
||||
|
||||
|
||||
_displayColor = new Color[(int)RepStatus.EndValue];
|
||||
_fontColor = new Color[(int)RepStatus.EndValue];
|
||||
|
||||
// RepStatus.UnSet
|
||||
|
||||
@@ -108,6 +103,9 @@ namespace ROMVault2
|
||||
|
||||
_displayColor[(int)RepStatus.Deleted] = CWhite;
|
||||
|
||||
for (int i = 0; i < (int)RepStatus.EndValue; i++)
|
||||
_fontColor[i] = contrasty(_displayColor[i]);
|
||||
|
||||
_gameGridColumnXPositions = new int[(int)RepStatus.EndValue];
|
||||
|
||||
DirTree.Setup(ref DB.DirTree);
|
||||
@@ -752,7 +750,7 @@ namespace ROMVault2
|
||||
RvDir tRvDir = (RvDir)GameGrid.Rows[e.RowIndex].Tag;
|
||||
ReportStatus tDirStat = tRvDir.DirStatus;
|
||||
Color bgCol = Color.FromArgb(255, 255, 255);
|
||||
Color fgCol = contrasty(bgCol);
|
||||
Color fgCol = Color.FromArgb(0, 0, 0);
|
||||
|
||||
if (cellBounds.Width == 0 || cellBounds.Height == 0)
|
||||
return;
|
||||
@@ -762,13 +760,12 @@ namespace ROMVault2
|
||||
if (tDirStat.Get(t1) <= 0) continue;
|
||||
|
||||
bgCol = _displayColor[(int)t1];
|
||||
fgCol = contrasty(bgCol);
|
||||
fgCol = _fontColor[(int)t1];
|
||||
break;
|
||||
}
|
||||
|
||||
if (GameGrid.Columns[e.ColumnIndex].Name == "Type")
|
||||
{
|
||||
|
||||
e.CellStyle.BackColor = bgCol;
|
||||
e.CellStyle.SelectionBackColor = bgCol;
|
||||
e.CellStyle.ForeColor = fgCol;
|
||||
@@ -810,8 +807,8 @@ namespace ROMVault2
|
||||
else if (GameGrid.Columns[e.ColumnIndex].Name == "CGame")
|
||||
{
|
||||
e.CellStyle.BackColor = bgCol;
|
||||
e.CellStyle.ForeColor = contrasty(bgCol);
|
||||
|
||||
e.CellStyle.ForeColor = fgCol;
|
||||
|
||||
if (String.IsNullOrEmpty(tRvDir.FileName))
|
||||
e.Value = tRvDir.Name;
|
||||
else
|
||||
@@ -820,8 +817,8 @@ namespace ROMVault2
|
||||
else if (GameGrid.Columns[e.ColumnIndex].Name == "CDescription")
|
||||
{
|
||||
e.CellStyle.BackColor = bgCol;
|
||||
e.CellStyle.ForeColor = contrasty(bgCol);
|
||||
|
||||
e.CellStyle.ForeColor = fgCol;
|
||||
|
||||
if (tRvDir.Game != null)
|
||||
e.Value = tRvDir.Game.GetData(RvGame.GameData.Description);
|
||||
}
|
||||
@@ -1305,6 +1302,13 @@ namespace ROMVault2
|
||||
}
|
||||
}
|
||||
|
||||
// returns either white or black, depending of quick luminance of the Color " a "
|
||||
// called when the _displayColor is finished, in order to populate the _fontColor table.
|
||||
private Color contrasty(Color a)
|
||||
{
|
||||
return (a.R << 1) + a.B + a.G + (a.G << 2) < 1024 ? Color.White : Color.Black;
|
||||
}
|
||||
|
||||
private void AddRom(RvFile tRomTable, string pathAdd)
|
||||
{
|
||||
|
||||
@@ -1316,12 +1320,10 @@ namespace ROMVault2
|
||||
|
||||
for (int i = 0; i < RomGrid.Rows[row].Cells.Count; i++)
|
||||
{
|
||||
Color bc;
|
||||
DataGridViewCellStyle cs = RomGrid.Rows[row].Cells[i].Style;
|
||||
cs.BackColor = (bc = _displayColor[(int)tRomTable.RepStatus]);
|
||||
cs.ForeColor = contrasty(bc);
|
||||
cs.BackColor = _displayColor[(int)tRomTable.RepStatus];
|
||||
cs.ForeColor = _fontColor[(int)tRomTable.RepStatus];
|
||||
}
|
||||
|
||||
string fname = pathAdd + tRomTable.Name;
|
||||
if (!string.IsNullOrEmpty(tRomTable.FileName))
|
||||
fname += " (Found: " + tRomTable.FileName + ")";
|
||||
|
||||
Reference in New Issue
Block a user