From bbfa9156360bb49605450a1e1df9422b042597e4 Mon Sep 17 00:00:00 2001 From: Jim Westfall Date: Sun, 26 Oct 2014 19:07:05 -0700 Subject: [PATCH 1/6] Replace *CellDraw classes with CellFormatting functions. This fixes rendering and crashing issues in (Rom|Game)Grid with mono. --- ROMVault2/DirCellDraw.cs | 146 ---------------------------------- ROMVault2/FrmMain.Designer.cs | 2 + ROMVault2/FrmMain.cs | 129 ++++++++++++++++++++++++++---- ROMVault2/ROMVault2.csproj | 3 +- 4 files changed, 115 insertions(+), 165 deletions(-) delete mode 100644 ROMVault2/DirCellDraw.cs diff --git a/ROMVault2/DirCellDraw.cs b/ROMVault2/DirCellDraw.cs deleted file mode 100644 index 66de677..0000000 --- a/ROMVault2/DirCellDraw.cs +++ /dev/null @@ -1,146 +0,0 @@ -/****************************************************** - * ROMVault2 is written by Gordon J. * - * Contact gordon@romvault.com * - * Copyright 2014 * - ******************************************************/ - -using System.Diagnostics; -using System.Drawing; -using System.Globalization; -using System.Windows.Forms; -using ROMVault2.RvDB; -using ROMVault2.SupportedFiles; - -namespace ROMVault2 -{ - - public class RomCellDraw : DataGridViewImageCell - { - private readonly Color _bgCol; - private readonly string _bitmapName; - - public RomCellDraw(string name,Color bgCol) - { - _bitmapName = name; - _bgCol = bgCol; - - } - - protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) - { - graphics.FillRectangle(new SolidBrush(_bgCol), cellBounds); - - Bitmap bm= rvImages.GetBitmap(_bitmapName); - - if (bm != null) - { - graphics.DrawImage(bm, cellBounds.Left, cellBounds.Top, bm.Width,bm.Height); - bm.Dispose(); - } - - - else - Debug.WriteLine("Missing Graphic for " + _bitmapName); - } - - } - - public class DirCellDraw : DataGridViewImageCell - { - private readonly Color _bgCol; - private readonly RvDir _cellDir; - - public DirCellDraw(RvDir cellDir, Color bgCol) - { - _cellDir = cellDir; - _bgCol = bgCol; - } - - protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) - { - - graphics.FillRectangle(new SolidBrush(_bgCol), cellBounds); - - string bitmapName; - - switch (_cellDir.FileType) - { - case FileType.Zip: - if (_cellDir.RepStatus == RepStatus.DirCorrect && _cellDir.ZipStatus==ZipStatus.TrrntZip) - bitmapName = "ZipTZ"; - else - bitmapName = "Zip" + _cellDir.RepStatus; - break; - default: - bitmapName = "Dir" + _cellDir.RepStatus; - break; - } - - Bitmap bm = rvImages.GetBitmap(bitmapName); - - if (bm != null) - { - graphics.DrawImage(bm, cellBounds.Left + 10, cellBounds.Top, 21, 17); - bm.Dispose(); - } - else - Debug.WriteLine("Missing Graphic for " + bitmapName); - } - } - - public class DirCellStatusDraw : DataGridViewImageCell - { - private readonly RvDir _dir; - public DirCellStatusDraw(RvDir dir) - { - _dir = dir; - } - - protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) - { - Font drawFont = new Font("Arial", 9); - SolidBrush drawBrushBlack = new SolidBrush(Color.Black); - SolidBrush drawBrushWhite = new SolidBrush(Color.White); - - graphics.FillRectangle(drawBrushWhite, cellBounds); - - int gOff; - int columnIndex = 0; - for (int l = 0; l < RepairStatus.DisplayOrder.Length; l++) - { - if (l >= 13) columnIndex = l; - - if (_dir.DirStatus.Get(RepairStatus.DisplayOrder[l]) <= 0) continue; - - gOff = cellBounds.Left + FrmMain.GameGridColumnXPositions[columnIndex]; - Bitmap bm = rvImages.GetBitmap(@"G_" + RepairStatus.DisplayOrder[l]); - if (bm != null) - { - graphics.DrawImage(bm, gOff, cellBounds.Top, 21, 18); - bm.Dispose(); - } - else - Debug.WriteLine("Missing Graphics for " + "G_" + RepairStatus.DisplayOrder[l]); - - columnIndex++; - } - - columnIndex = 0; - for (int l = 0; l < RepairStatus.DisplayOrder.Length; l++) - { - if (l >= 13) - columnIndex = l; - - if (_dir.DirStatus.Get(RepairStatus.DisplayOrder[l]) > 0) - { - gOff = cellBounds.Left + FrmMain.GameGridColumnXPositions[columnIndex]; - graphics.DrawString(_dir.DirStatus.Get(RepairStatus.DisplayOrder[l]).ToString(CultureInfo.InvariantCulture), drawFont, drawBrushBlack, new PointF(gOff + 20, cellBounds.Top + 3)); - columnIndex++; - } - } - drawBrushBlack.Dispose(); - drawBrushWhite.Dispose(); - drawFont.Dispose(); - } - } -} \ No newline at end of file diff --git a/ROMVault2/FrmMain.Designer.cs b/ROMVault2/FrmMain.Designer.cs index 2bbf160..71507f0 100644 --- a/ROMVault2/FrmMain.Designer.cs +++ b/ROMVault2/FrmMain.Designer.cs @@ -654,6 +654,7 @@ this.GameGrid.ShowRowErrors = false; this.GameGrid.Size = new System.Drawing.Size(697, 267); this.GameGrid.TabIndex = 4; + this.GameGrid.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.GameGrid_CellFormatting); this.GameGrid.SelectionChanged += new System.EventHandler(this.GameGridSelectionChanged); this.GameGrid.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.GameGridMouseDoubleClick); this.GameGrid.MouseUp += new System.Windows.Forms.MouseEventHandler(this.GameGrid_MouseUp); @@ -746,6 +747,7 @@ this.RomGrid.ShowRowErrors = false; this.RomGrid.Size = new System.Drawing.Size(697, 315); this.RomGrid.TabIndex = 21; + this.RomGrid.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.RomGrid_CellFormatting); this.RomGrid.SelectionChanged += new System.EventHandler(this.RomGridSelectionChanged); this.RomGrid.MouseUp += new System.Windows.Forms.MouseEventHandler(this.RomGridMouseUp); // diff --git a/ROMVault2/FrmMain.cs b/ROMVault2/FrmMain.cs index 884be82..800fa24 100644 --- a/ROMVault2/FrmMain.cs +++ b/ROMVault2/FrmMain.cs @@ -13,6 +13,7 @@ using ROMVault2.Properties; using ROMVault2.RVRef; using ROMVault2.RvDB; using ROMVault2.Utils; +using ROMVault2.SupportedFiles; namespace ROMVault2 { @@ -477,6 +478,108 @@ namespace ROMVault2 DatMaker.MakeDatFromDir(thisDir); } + private void GameGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) + { + + Rectangle cellBounds = GameGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); + RvDir tRvDir = (ROMVault2.RvDB.RvDir)GameGrid.Rows[e.RowIndex].Tag; + + if (GameGrid.Columns[e.ColumnIndex].Name == "Type") + { + Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); + Graphics g = Graphics.FromImage(bmp); + + string bitmapName; + switch (tRvDir.FileType) + { + case FileType.Zip: + if (tRvDir.RepStatus == RepStatus.DirCorrect && tRvDir.ZipStatus == ZipStatus.TrrntZip) + bitmapName = "ZipTZ"; + else + bitmapName = "Zip" + tRvDir.RepStatus; + break; + default: + // hack because DirDirInToSort image doesnt exist. + if (tRvDir.RepStatus == RepStatus.DirInToSort) + bitmapName = "Dir" + RepStatus.DirUnknown; + else + bitmapName = "Dir" + tRvDir.RepStatus; + + break; + } + + Bitmap bm = rvImages.GetBitmap(bitmapName); + if (bm != null) + { + g.DrawImage(bm, (cellBounds.Width - cellBounds.Height) / 2, 0, 18, 18); + bm.Dispose(); + } + else + Debug.WriteLine("Missing Graphic for " + bitmapName); + + e.Value = bmp; + + } else if (GameGrid.Columns[e.ColumnIndex].Name == "CCorrect") { + Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); + Graphics g = Graphics.FromImage(bmp); + Font drawFont = new Font("Arial", 9); + SolidBrush drawBrushBlack = new SolidBrush(Color.Black); + + int gOff; + int columnIndex = 0; + for (int l = 0; l < RepairStatus.DisplayOrder.Length; l++) + { + if (l >= 13) columnIndex = l; + + if (tRvDir.DirStatus.Get(RepairStatus.DisplayOrder[l]) <= 0) continue; + + gOff = FrmMain.GameGridColumnXPositions[columnIndex]; + Bitmap bm = rvImages.GetBitmap(@"G_" + RepairStatus.DisplayOrder[l]); + if (bm != null) + { + g.DrawImage(bm, gOff, 0, 21, 18); + bm.Dispose(); + } + else + Debug.WriteLine("Missing Graphics for " + "G_" + RepairStatus.DisplayOrder[l]); + + columnIndex++; + } + + columnIndex = 0; + for (int l = 0; l < RepairStatus.DisplayOrder.Length; l++) + { + if (l >= 13) + columnIndex = l; + + if (tRvDir.DirStatus.Get(RepairStatus.DisplayOrder[l]) > 0) + { + gOff = FrmMain.GameGridColumnXPositions[columnIndex]; + g.DrawString(tRvDir.DirStatus.Get(RepairStatus.DisplayOrder[l]).ToString(CultureInfo.InvariantCulture), drawFont, drawBrushBlack, new PointF(gOff + 20, 3)); + columnIndex++; + } + } + drawBrushBlack.Dispose(); + drawFont.Dispose(); + e.Value = bmp; + } + } + + private void RomGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) + { + Rectangle cellBounds = RomGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); + RvFile tRvFile = (ROMVault2.RvDB.RvFile)RomGrid.Rows[e.RowIndex].Tag; + + if (RomGrid.Columns[e.ColumnIndex].Name == "CGot") + { + Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); + Graphics g = Graphics.FromImage(bmp); + string bitmapName = "R_" + tRvFile.DatStatus + "_" + tRvFile.RepStatus; + g.DrawImage(rvImages.GetBitmap(bitmapName), 0, 0, 54, 18); + e.Value = bmp; + } + } + private void splitContainer3_Panel1_Resize(object sender, EventArgs e) { gbDatInfo.Width = splitContainer3.Panel1.Width - (gbDatInfo.Left * 2); @@ -670,23 +773,19 @@ namespace ROMVault2 GameGrid.Rows[iRow].Selected = false; GameGrid.Rows[iRow].Tag = tChildDir; - GameGrid.Rows[iRow].Cells[0].Style.BackColor = bgCol; - GameGrid.Rows[iRow].Cells[1].Style.BackColor = bgCol; - GameGrid.Rows[iRow].Cells[2].Style.BackColor = bgCol; + GameGrid.Rows[iRow].Cells["Type"].Style.BackColor = bgCol; + GameGrid.Rows[iRow].Cells["Type"].Style.SelectionBackColor = bgCol; + GameGrid.Rows[iRow].Cells["CGame"].Style.BackColor = bgCol; + GameGrid.Rows[iRow].Cells["CDescription"].Style.BackColor = bgCol; + GameGrid.Rows[iRow].Cells["CCorrect"].Style.SelectionBackColor = Color.White; if (String.IsNullOrEmpty(tChildDir.FileName)) - GameGrid.Rows[iRow].Cells[1].Value = tChildDir.Name; + GameGrid.Rows[iRow].Cells["CGame"].Value = tChildDir.Name; else - GameGrid.Rows[iRow].Cells[1].Value = tChildDir.Name + " (Found: " + tChildDir.FileName + ")"; + GameGrid.Rows[iRow].Cells["CGame"].Value = tChildDir.Name + " (Found: " + tChildDir.FileName + ")"; if (tChildDir.Game != null) - GameGrid.Rows[iRow].Cells[2].Value = tChildDir.Game.GetData(RvGame.GameData.Description); - - DirCellDraw tDirCellDraw = new DirCellDraw(tChildDir, bgCol); - GameGrid.Rows[iRow].Cells[0] = tDirCellDraw; - - DirCellStatusDraw tCellStatusDraw = new DirCellStatusDraw(tChildDir); - GameGrid.Rows[iRow].Cells[3] = tCellStatusDraw; + GameGrid.Rows[iRow].Cells["CDescription"].Value = tChildDir.Game.GetData(RvGame.GameData.Description); } _updatingGameGrid = false; @@ -1085,11 +1184,7 @@ namespace ROMVault2 { RomGrid.Rows.Add(); int row = RomGrid.Rows.Count - 1; - - string imageName = "R_" + tRomTable.DatStatus + "_" + tRomTable.RepStatus; - - RomCellDraw tDirCellDraw = new RomCellDraw(imageName, _displayColor[(int)tRomTable.RepStatus]); - RomGrid.Rows[row].Cells[0] = tDirCellDraw; + 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]; diff --git a/ROMVault2/ROMVault2.csproj b/ROMVault2/ROMVault2.csproj index e08d2ef..269e5e3 100644 --- a/ROMVault2/ROMVault2.csproj +++ b/ROMVault2/ROMVault2.csproj @@ -163,7 +163,6 @@ FrmSettings.cs - Form @@ -333,4 +332,4 @@ --> - \ No newline at end of file + From d5fb529b7b4268874c79b6e228dea2d364bafe52 Mon Sep 17 00:00:00 2001 From: Jim Westfall Date: Sun, 26 Oct 2014 19:52:29 -0700 Subject: [PATCH 2/6] Need cellbounds to be the full wide and not just the visual. --- ROMVault2/FrmMain.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ROMVault2/FrmMain.cs b/ROMVault2/FrmMain.cs index 800fa24..c89da12 100644 --- a/ROMVault2/FrmMain.cs +++ b/ROMVault2/FrmMain.cs @@ -481,7 +481,7 @@ namespace ROMVault2 private void GameGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) { - Rectangle cellBounds = GameGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); + Rectangle cellBounds = GameGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); RvDir tRvDir = (ROMVault2.RvDB.RvDir)GameGrid.Rows[e.RowIndex].Tag; if (GameGrid.Columns[e.ColumnIndex].Name == "Type") @@ -567,7 +567,7 @@ namespace ROMVault2 private void RomGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) { - Rectangle cellBounds = RomGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); + Rectangle cellBounds = RomGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); RvFile tRvFile = (ROMVault2.RvDB.RvFile)RomGrid.Rows[e.RowIndex].Tag; if (RomGrid.Columns[e.ColumnIndex].Name == "CGot") From bb4b77a6d77a288320b3ac7b55a52e1ee6e685e3 Mon Sep 17 00:00:00 2001 From: Jim Westfall Date: Sun, 26 Oct 2014 19:58:01 -0700 Subject: [PATCH 3/6] Move (Rom|Game)Grid CellFormatting functions to be in the right #region sections --- ROMVault2/FrmMain.cs | 204 +++++++++++++++++++++---------------------- 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/ROMVault2/FrmMain.cs b/ROMVault2/FrmMain.cs index c89da12..0e4a104 100644 --- a/ROMVault2/FrmMain.cs +++ b/ROMVault2/FrmMain.cs @@ -478,108 +478,6 @@ namespace ROMVault2 DatMaker.MakeDatFromDir(thisDir); } - private void GameGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) - { - - Rectangle cellBounds = GameGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); - RvDir tRvDir = (ROMVault2.RvDB.RvDir)GameGrid.Rows[e.RowIndex].Tag; - - if (GameGrid.Columns[e.ColumnIndex].Name == "Type") - { - Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); - Graphics g = Graphics.FromImage(bmp); - - string bitmapName; - switch (tRvDir.FileType) - { - case FileType.Zip: - if (tRvDir.RepStatus == RepStatus.DirCorrect && tRvDir.ZipStatus == ZipStatus.TrrntZip) - bitmapName = "ZipTZ"; - else - bitmapName = "Zip" + tRvDir.RepStatus; - break; - default: - // hack because DirDirInToSort image doesnt exist. - if (tRvDir.RepStatus == RepStatus.DirInToSort) - bitmapName = "Dir" + RepStatus.DirUnknown; - else - bitmapName = "Dir" + tRvDir.RepStatus; - - break; - } - - Bitmap bm = rvImages.GetBitmap(bitmapName); - if (bm != null) - { - g.DrawImage(bm, (cellBounds.Width - cellBounds.Height) / 2, 0, 18, 18); - bm.Dispose(); - } - else - Debug.WriteLine("Missing Graphic for " + bitmapName); - - e.Value = bmp; - - } else if (GameGrid.Columns[e.ColumnIndex].Name == "CCorrect") { - Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); - Graphics g = Graphics.FromImage(bmp); - Font drawFont = new Font("Arial", 9); - SolidBrush drawBrushBlack = new SolidBrush(Color.Black); - - int gOff; - int columnIndex = 0; - for (int l = 0; l < RepairStatus.DisplayOrder.Length; l++) - { - if (l >= 13) columnIndex = l; - - if (tRvDir.DirStatus.Get(RepairStatus.DisplayOrder[l]) <= 0) continue; - - gOff = FrmMain.GameGridColumnXPositions[columnIndex]; - Bitmap bm = rvImages.GetBitmap(@"G_" + RepairStatus.DisplayOrder[l]); - if (bm != null) - { - g.DrawImage(bm, gOff, 0, 21, 18); - bm.Dispose(); - } - else - Debug.WriteLine("Missing Graphics for " + "G_" + RepairStatus.DisplayOrder[l]); - - columnIndex++; - } - - columnIndex = 0; - for (int l = 0; l < RepairStatus.DisplayOrder.Length; l++) - { - if (l >= 13) - columnIndex = l; - - if (tRvDir.DirStatus.Get(RepairStatus.DisplayOrder[l]) > 0) - { - gOff = FrmMain.GameGridColumnXPositions[columnIndex]; - g.DrawString(tRvDir.DirStatus.Get(RepairStatus.DisplayOrder[l]).ToString(CultureInfo.InvariantCulture), drawFont, drawBrushBlack, new PointF(gOff + 20, 3)); - columnIndex++; - } - } - drawBrushBlack.Dispose(); - drawFont.Dispose(); - e.Value = bmp; - } - } - - private void RomGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) - { - Rectangle cellBounds = RomGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); - RvFile tRvFile = (ROMVault2.RvDB.RvFile)RomGrid.Rows[e.RowIndex].Tag; - - if (RomGrid.Columns[e.ColumnIndex].Name == "CGot") - { - Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); - Graphics g = Graphics.FromImage(bmp); - string bitmapName = "R_" + tRvFile.DatStatus + "_" + tRvFile.RepStatus; - g.DrawImage(rvImages.GetBitmap(bitmapName), 0, 0, 54, 18); - e.Value = bmp; - } - } - private void splitContainer3_Panel1_Resize(object sender, EventArgs e) { gbDatInfo.Width = splitContainer3.Panel1.Width - (gbDatInfo.Left * 2); @@ -829,6 +727,92 @@ namespace ROMVault2 } } + private void GameGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) + { + + Rectangle cellBounds = GameGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); + RvDir tRvDir = (ROMVault2.RvDB.RvDir)GameGrid.Rows[e.RowIndex].Tag; + + if (GameGrid.Columns[e.ColumnIndex].Name == "Type") + { + Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); + Graphics g = Graphics.FromImage(bmp); + + string bitmapName; + switch (tRvDir.FileType) + { + case FileType.Zip: + if (tRvDir.RepStatus == RepStatus.DirCorrect && tRvDir.ZipStatus == ZipStatus.TrrntZip) + bitmapName = "ZipTZ"; + else + bitmapName = "Zip" + tRvDir.RepStatus; + break; + default: + // hack because DirDirInToSort image doesnt exist. + if (tRvDir.RepStatus == RepStatus.DirInToSort) + bitmapName = "Dir" + RepStatus.DirUnknown; + else + bitmapName = "Dir" + tRvDir.RepStatus; + + break; + } + + Bitmap bm = rvImages.GetBitmap(bitmapName); + if (bm != null) + { + g.DrawImage(bm, (cellBounds.Width - cellBounds.Height) / 2, 0, 18, 18); + bm.Dispose(); + } + else + Debug.WriteLine("Missing Graphic for " + bitmapName); + + e.Value = bmp; + + } else if (GameGrid.Columns[e.ColumnIndex].Name == "CCorrect") { + Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); + Graphics g = Graphics.FromImage(bmp); + Font drawFont = new Font("Arial", 9); + SolidBrush drawBrushBlack = new SolidBrush(Color.Black); + + int gOff; + int columnIndex = 0; + for (int l = 0; l < RepairStatus.DisplayOrder.Length; l++) + { + if (l >= 13) columnIndex = l; + + if (tRvDir.DirStatus.Get(RepairStatus.DisplayOrder[l]) <= 0) continue; + + gOff = FrmMain.GameGridColumnXPositions[columnIndex]; + Bitmap bm = rvImages.GetBitmap(@"G_" + RepairStatus.DisplayOrder[l]); + if (bm != null) + { + g.DrawImage(bm, gOff, 0, 21, 18); + bm.Dispose(); + } + else + Debug.WriteLine("Missing Graphics for " + "G_" + RepairStatus.DisplayOrder[l]); + + columnIndex++; + } + + columnIndex = 0; + for (int l = 0; l < RepairStatus.DisplayOrder.Length; l++) + { + if (l >= 13) + columnIndex = l; + + if (tRvDir.DirStatus.Get(RepairStatus.DisplayOrder[l]) > 0) + { + gOff = FrmMain.GameGridColumnXPositions[columnIndex]; + g.DrawString(tRvDir.DirStatus.Get(RepairStatus.DisplayOrder[l]).ToString(CultureInfo.InvariantCulture), drawFont, drawBrushBlack, new PointF(gOff + 20, 3)); + columnIndex++; + } + } + drawBrushBlack.Dispose(); + drawFont.Dispose(); + e.Value = bmp; + } + } #endregion @@ -1265,6 +1249,22 @@ namespace ROMVault2 } } } + + private void RomGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) + { + Rectangle cellBounds = RomGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); + RvFile tRvFile = (ROMVault2.RvDB.RvFile)RomGrid.Rows[e.RowIndex].Tag; + + if (RomGrid.Columns[e.ColumnIndex].Name == "CGot") + { + Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); + Graphics g = Graphics.FromImage(bmp); + string bitmapName = "R_" + tRvFile.DatStatus + "_" + tRvFile.RepStatus; + g.DrawImage(rvImages.GetBitmap(bitmapName), 0, 0, 54, 18); + e.Value = bmp; + } + } + #endregion private void RomGridSelectionChanged(object sender, EventArgs e) From 16ae35a8a1b9d237cbf397833c26ae5b5789a52f Mon Sep 17 00:00:00 2001 From: Jim Westfall Date: Sun, 26 Oct 2014 20:27:10 -0700 Subject: [PATCH 4/6] Make drawn text look better in GameGrid's CCorrect --- ROMVault2/FrmMain.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ROMVault2/FrmMain.cs b/ROMVault2/FrmMain.cs index 0e4a104..3799604 100644 --- a/ROMVault2/FrmMain.cs +++ b/ROMVault2/FrmMain.cs @@ -771,6 +771,8 @@ namespace ROMVault2 } else if (GameGrid.Columns[e.ColumnIndex].Name == "CCorrect") { Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); Graphics g = Graphics.FromImage(bmp); + g.Clear(Color.White); + g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; Font drawFont = new Font("Arial", 9); SolidBrush drawBrushBlack = new SolidBrush(Color.Black); From e950b00a679bedf19a2d084fb2b8f7b744ac3d80 Mon Sep 17 00:00:00 2001 From: Jim Westfall Date: Tue, 28 Oct 2014 17:42:33 -0700 Subject: [PATCH 5/6] GetFiles() for mono was missing initializing the Length --- ROMVault2/IO/RVIO.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ROMVault2/IO/RVIO.cs b/ROMVault2/IO/RVIO.cs index 6361ce1..476ad7a 100644 --- a/ROMVault2/IO/RVIO.cs +++ b/ROMVault2/IO/RVIO.cs @@ -193,6 +193,7 @@ namespace ROMVault2.IO { Name = tDi.Name, FullName = Path.Combine(FullName, tDi.Name), + Length = tDi.Length, LastWriteTime = tDi.LastWriteTimeUtc.Ticks }; files.Add(lDi); From 1d37e0004a680ab8d884e5896cd49cbd77445539 Mon Sep 17 00:00:00 2001 From: Jim Westfall Date: Sat, 8 Nov 2014 10:19:27 -0800 Subject: [PATCH 6/6] speed up populating GameGrid These changes speed up how long it takes to populate the GameGrid after clicking on a dat in the Tree. MAME 0.155 dat was used for testing. Before the changes population times were windows .net = 2.75 seconds linux mono = 23 seconds After the changes, both now take 300-400ms. This was done using 2 main changes. 1. Fully move populating the rows' Values to the CellFormatting function 2. Determine the total number of rows we will need and use GameGrid.rowCount to set the row count to that. This is much faster then doing individual Add()'s for each row. --- ROMVault2/FrmMain.cs | 91 ++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/ROMVault2/FrmMain.cs b/ROMVault2/FrmMain.cs index 3799604..bca0025 100644 --- a/ROMVault2/FrmMain.cs +++ b/ROMVault2/FrmMain.cs @@ -584,6 +584,7 @@ namespace ROMVault2 GameGridColumnXPositions = new int[(int)RepStatus.EndValue]; + int rowCount = 0; for (int j = 0; j < tDir.ChildCount; j++) { @@ -608,6 +609,8 @@ namespace ROMVault2 if (!show) continue; + rowCount++; + int columnIndex = 0; for (int l = 0; l < RepairStatus.DisplayOrder.Length; l++) { @@ -621,6 +624,7 @@ namespace ROMVault2 columnIndex++; } } + GameGrid.RowCount = rowCount; int t = 0; for (int l = 0; l < (int)RepStatus.EndValue; l++) @@ -630,6 +634,7 @@ namespace ROMVault2 t += colWidth; } + int row = 0; for (int j = 0; j < tDir.ChildCount; j++) { RvDir tChildDir = tDir.Child(j) as RvDir; @@ -652,38 +657,10 @@ namespace ROMVault2 show = show || !(gCorrect || gMissing || gUnknown || gInToSort || gFixes); if (!show) continue; - - Color bgCol = Color.FromArgb(255, 255, 255); - - - foreach (RepStatus t1 in RepairStatus.DisplayOrder) - { - if (tDirStat.Get(t1) <= 0) continue; - - bgCol = _displayColor[(int)t1]; - break; - } - - - GameGrid.Rows.Add(); - int iRow = GameGrid.Rows.Count - 1; - - GameGrid.Rows[iRow].Selected = false; - GameGrid.Rows[iRow].Tag = tChildDir; - - GameGrid.Rows[iRow].Cells["Type"].Style.BackColor = bgCol; - GameGrid.Rows[iRow].Cells["Type"].Style.SelectionBackColor = bgCol; - GameGrid.Rows[iRow].Cells["CGame"].Style.BackColor = bgCol; - GameGrid.Rows[iRow].Cells["CDescription"].Style.BackColor = bgCol; - GameGrid.Rows[iRow].Cells["CCorrect"].Style.SelectionBackColor = Color.White; - - if (String.IsNullOrEmpty(tChildDir.FileName)) - GameGrid.Rows[iRow].Cells["CGame"].Value = tChildDir.Name; - else - GameGrid.Rows[iRow].Cells["CGame"].Value = tChildDir.Name + " (Found: " + tChildDir.FileName + ")"; - - if (tChildDir.Game != null) - GameGrid.Rows[iRow].Cells["CDescription"].Value = tChildDir.Game.GetData(RvGame.GameData.Description); + + GameGrid.Rows[row].Selected = false; + GameGrid.Rows[row].Tag = tChildDir; + row++; } _updatingGameGrid = false; @@ -729,12 +706,31 @@ namespace ROMVault2 private void GameGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) { + + if (_updatingGameGrid) + return; Rectangle cellBounds = GameGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); RvDir tRvDir = (ROMVault2.RvDB.RvDir)GameGrid.Rows[e.RowIndex].Tag; + ReportStatus tDirStat = tRvDir.DirStatus; + Color bgCol = Color.FromArgb(255, 255, 255); + + if (cellBounds.Width == 0 || cellBounds.Height == 0) + return; + + foreach (RepStatus t1 in RepairStatus.DisplayOrder) + { + if (tDirStat.Get(t1) <= 0) continue; + + bgCol = _displayColor[(int)t1]; + break; + } if (GameGrid.Columns[e.ColumnIndex].Name == "Type") { + e.CellStyle.BackColor = bgCol; + e.CellStyle.SelectionBackColor = bgCol; + Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); Graphics g = Graphics.FromImage(bmp); @@ -768,7 +764,27 @@ namespace ROMVault2 e.Value = bmp; - } else if (GameGrid.Columns[e.ColumnIndex].Name == "CCorrect") { + } + else if (GameGrid.Columns[e.ColumnIndex].Name == "CGame") + { + e.CellStyle.BackColor = bgCol; + + if (String.IsNullOrEmpty(tRvDir.FileName)) + e.Value = tRvDir.Name; + else + e.Value = tRvDir.Name + " (Found: " + tRvDir.FileName + ")"; + } + else if (GameGrid.Columns[e.ColumnIndex].Name == "CDescription") + { + e.CellStyle.BackColor = bgCol; + + if (tRvDir.Game != null) + e.Value = tRvDir.Game.GetData(RvGame.GameData.Description); + } + else if (GameGrid.Columns[e.ColumnIndex].Name == "CCorrect") + { + e.CellStyle.SelectionBackColor = Color.White; + Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height); Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); @@ -814,6 +830,8 @@ namespace ROMVault2 drawFont.Dispose(); e.Value = bmp; } + else + Console.WriteLine("WARN: GameGrid_CellFormatting() unknown column: {0}", GameGrid.Columns[e.ColumnIndex].Name); } #endregion @@ -1254,9 +1272,16 @@ namespace ROMVault2 private void RomGrid_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e) { + + if (_updatingGameGrid) + return; + Rectangle cellBounds = RomGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); RvFile tRvFile = (ROMVault2.RvDB.RvFile)RomGrid.Rows[e.RowIndex].Tag; + if (cellBounds.Width == 0 || cellBounds.Height == 0) + return; + if (RomGrid.Columns[e.ColumnIndex].Name == "CGot") { Bitmap bmp = new Bitmap(cellBounds.Width, cellBounds.Height);