From 6981a16a674c81ffcb0f13d96fff165065036708 Mon Sep 17 00:00:00 2001 From: LnmVolbo Date: Mon, 22 Jun 2015 19:37:52 -0700 Subject: [PATCH 1/2] Update FrmMain.cs Haven't got the knack of getting the edited source straight out of my visual studio IDE, so I'm just copying and pasting bits here. So I'm not really sure if it still compiles w/o errors. --- ROMVault2/FrmMain.cs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/ROMVault2/FrmMain.cs b/ROMVault2/FrmMain.cs index 28be2b3..643c2dc 100644 --- a/ROMVault2/FrmMain.cs +++ b/ROMVault2/FrmMain.cs @@ -59,6 +59,13 @@ 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() { @@ -745,6 +752,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); if (cellBounds.Width == 0 || cellBounds.Height == 0) return; @@ -754,13 +762,16 @@ namespace ROMVault2 if (tDirStat.Get(t1) <= 0) continue; bgCol = _displayColor[(int)t1]; + fgCol = contrasty(bgCol); break; } if (GameGrid.Columns[e.ColumnIndex].Name == "Type") { + e.CellStyle.BackColor = bgCol; e.CellStyle.SelectionBackColor = bgCol; + e.CellStyle.ForeColor = fgCol; Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); Graphics g = Graphics.FromImage(bmp); @@ -799,7 +810,8 @@ namespace ROMVault2 else if (GameGrid.Columns[e.ColumnIndex].Name == "CGame") { e.CellStyle.BackColor = bgCol; - + e.CellStyle.ForeColor = contrasty(bgCol); + if (String.IsNullOrEmpty(tRvDir.FileName)) e.Value = tRvDir.Name; else @@ -808,7 +820,8 @@ namespace ROMVault2 else if (GameGrid.Columns[e.ColumnIndex].Name == "CDescription") { e.CellStyle.BackColor = bgCol; - + e.CellStyle.ForeColor = contrasty(bgCol); + if (tRvDir.Game != null) e.Value = tRvDir.Game.GetData(RvGame.GameData.Description); } @@ -1302,8 +1315,13 @@ namespace ROMVault2 RomGrid.Rows[row].Tag = tRomTable; for (int i = 0; i < RomGrid.Rows[row].Cells.Count; i++) - RomGrid.Rows[row].Cells[i].Style.BackColor = _displayColor[(int)tRomTable.RepStatus]; - + { + Color bc; + DataGridViewCellStyle cs = RomGrid.Rows[row].Cells[i].Style; + cs.BackColor = (bc = _displayColor[(int)tRomTable.RepStatus]); + cs.ForeColor = contrasty(bc); + } + string fname = pathAdd + tRomTable.Name; if (!string.IsNullOrEmpty(tRomTable.FileName)) fname += " (Found: " + tRomTable.FileName + ")"; From 1b4caa8e340f666bd92ac8a1dc09e922bd8f1175 Mon Sep 17 00:00:00 2001 From: LnmVolbo Date: Tue, 23 Jun 2015 09:04:26 -0700 Subject: [PATCH 2/2] 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. --- ROMVault2/FrmMain.cs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/ROMVault2/FrmMain.cs b/ROMVault2/FrmMain.cs index 643c2dc..751be8d 100644 --- a/ROMVault2/FrmMain.cs +++ b/ROMVault2/FrmMain.cs @@ -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 + ")";