private void saveSprite8() { string hexValue1 = ""; foreach (DataGridViewRow row in dataGridView1.Rows) { ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; if (scanlineInfo != null) { byte b1 = extractByte(row.Cells, 0, 7); byte bkColor = scanlineInfo.backColorIndex; byte fgColor = scanlineInfo.frontColorIndex; //byte height = scanlineInfo.repeat; // + ToHex(height) + "," + ToHex(bkColor) + "," + ToHex(fgColor); // Convert integer 182 as a hex in a string variable hexValue1 = ToHex2(b1) + hexValue1; } } string prefix = "hex 00"; //Debug.WriteLine("hexValue = " + hexValue1 + " --- binValue = " + binValue1 + "hexPlainValue = " + hexPlainValue1); Debug.WriteLine("Bitmap0\n\t" + prefix + hexValue1); }
private void SaveToFile() { string file = "c:\\temp\\mygrid.bin"; using (BinaryWriter bw = new BinaryWriter(File.Open(file, FileMode.Create))) { bw.Write(dataGridView1.Columns.Count); bw.Write(dataGridView1.Rows.Count); foreach (DataGridViewRow row in dataGridView1.Rows) { ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; byte[] obj = SerializeToBytes(scanlineInfo); int size = obj.Length; bw.Write(size); bw.Write(obj); for (int j = 0; j < row.Cells.Count; ++j) { object val = row.Cells[j].Tag; if (val == null) { bw.Write(false); bw.Write(false); } else { bw.Write(true); bw.Write(true); } } } } }
private void drawBackground(int rowIndex) { if (dataGridView1.CurrentCell != null) { DataGridViewRow row = dataGridView1.Rows[rowIndex]; ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; scanlineInfo.backColor = defaultBackColor; scanlineInfo.backColorIndex = defaultBackColorIndex; dataGridView1.Rows[rowIndex].DefaultCellStyle.BackColor = scanlineInfo.backColor; } }
private void buttonDecRowHeight_Click(object sender, EventArgs e) { DataGridViewRow row = (DataGridViewRow)dataGridView1.CurrentRow; ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; if (scanlineInfo != null && row.Height > 0) { scanlineInfo.repeat--; row.Height -= ROW_HEIGHT; } dataGridView1.Focus(); }
private void updateTotalHeight() { int total = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; if (scanlineInfo != null) { total += scanlineInfo.repeat; } } labelTotalHeight.Text = "" + total; }
private void addScanlineInfoTo(DataGridViewRow row) { //store line info ScanlineInfo scanLine = new ScanlineInfo(); scanLine.frontColor = Color.Empty; scanLine.backColor = Color.Empty; scanLine.repeat = 1; scanLine.type = RowType.Asymmetric; row.Tag = scanLine; row.DefaultCellStyle.BackColor = scanLine.backColor; row.Height = ROW_HEIGHT; row.Cells[0].Tag = null; row.Cells[0].Style.BackColor = Color.Empty; }
private void saveSprite48() { string hexValue1 = ""; string hexValue2 = ""; string hexValue3 = ""; string hexValue4 = ""; string hexValue5 = ""; string hexValue6 = ""; foreach (DataGridViewRow row in dataGridView1.Rows) { ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; if (scanlineInfo != null) { byte b1 = extractByte(row.Cells, 0, 7); byte b2 = extractByte(row.Cells, 8, 15); byte b3 = extractByte(row.Cells, 16, 23); byte b4 = extractByte(row.Cells, 24, 31); byte b5 = extractByte(row.Cells, 32, 39); byte b6 = extractByte(row.Cells, 40, 47); byte bkColor = scanlineInfo.backColorIndex; byte fgColor = scanlineInfo.frontColorIndex; //byte height = scanlineInfo.repeat; // + ToHex(height) + "," + ToHex(bkColor) + "," + ToHex(fgColor); // Convert integer 182 as a hex in a string variable hexValue1 = ToHex2(b1) + hexValue1; hexValue2 = ToHex2(b2) + hexValue2; hexValue3 = ToHex2(b3) + hexValue3; hexValue4 = ToHex2(b4) + hexValue4; hexValue5 = ToHex2(b5) + hexValue5; hexValue6 = ToHex2(b6) + hexValue6; } } string prefix = "hex 00"; //Debug.WriteLine("hexValue = " + hexValue1 + " --- binValue = " + binValue1 + "hexPlainValue = " + hexPlainValue1); Debug.WriteLine("Bitmap0\n\t" + prefix + hexValue1); Debug.WriteLine("Bitmap1\n\t" + prefix + hexValue2); Debug.WriteLine("Bitmap2\n\t" + prefix + hexValue3); Debug.WriteLine("Bitmap3\n\t" + prefix + hexValue4); Debug.WriteLine("Bitmap4\n\t" + prefix + hexValue5); Debug.WriteLine("Bitmap5\n\t" + prefix + hexValue6); }
private void labelColor_MouseClick(object sender, MouseEventArgs e) { Label labelColor = (Label)sender; switch (e.Button) { case MouseButtons.Left: { labelFGColor.BackColor = labelColor.BackColor; //default color defaultFrontColor = labelFGColor.BackColor; defaultFrontColorIndex = (byte)labelColor.Tag; if (dataGridView1.CurrentCell != null) { DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex]; ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; scanlineInfo.frontColor = labelColor.BackColor; //save color index scanlineInfo.frontColorIndex = (byte)labelColor.Tag; foreach (DataGridViewCell cell in row.Cells) { if (cell.Tag != null && (int)cell.Tag == 1) { updatePixelAtRow(false, cell, erasure); } } } break; } case MouseButtons.Right: { labelBKColor.BackColor = labelColor.BackColor; //default color defaultBackColor = labelBKColor.BackColor; defaultBackColorIndex = (byte)labelColor.Tag; drawBackground(dataGridView1.CurrentCell.RowIndex); break; } } Debug.WriteLine(" = " + labelColor.BackColor); }
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) { labelCurrentLine.Text = "" + (1 + e.RowIndex); DataGridViewRow row = ((DataGridView)sender).Rows[e.RowIndex]; ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; labelFGColor.BackColor = scanlineInfo.frontColor; labelBKColor.BackColor = scanlineInfo.backColor; //dataGridView1.RowHeadersDefaultCellStyle.BackColor = scanlineInfo.frontColor; row.HeaderCell.Style.BackColor = Color.DarkGray;// scanlineInfo.frontColor; //dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].SelectedAppearance.BackColor = scanlineInfo.frontColor; //dataGridView1.Rows[03].Cells[3].SelectedAppearance.BackColor = Color.Red; //dataGridView1.DisplayLayout.Override.SelectedAppearancesEnabled = false; /* * //dataGridView1.DefaultCellStyle.ActiveAppearance.BackColor = Color.LightSeaGreen; * * //dataGridView1.DefaultCellStyle.SelectionForeColor = scanlineInfo.frontColor; * dataGridView1.DefaultCellStyle.SelectionBackColor = scanlineInfo.frontColor; * * // Set the selection background color for all the cells. * dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White; * dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black; * * // Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default * // value won't override DataGridView.DefaultCellStyle.SelectionBackColor. * * * // Set the background color for all rows and for alternating rows. * // The value for alternating rows overrides the value for all rows. * dataGridView1.RowsDefaultCellStyle.BackColor = Color.LightGray; * dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.DarkGray; * * // Set the row and column header styles. * dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; * dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Black; * dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Black; */ }
private void savePlayfield(DataGridViewRow row) { ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; if (scanlineInfo != null) { byte pf0 = extractPF0(row.Cells, 0, 3); //user 4 bits to store pattern type pf0 = (byte)(pf0 ^ (byte)scanlineInfo.type); byte pf1 = extractPF1(row.Cells, 4, 11); byte pf2 = extractPF2(row.Cells, 12, 19); byte bkColor = scanlineInfo.backColorIndex; byte fgColor = scanlineInfo.frontColorIndex; byte height = scanlineInfo.repeat; string prefix = ".byte " + ToHex(height) + "," + ToHex(bkColor) + "," + ToHex(fgColor); // Convert integer 182 as a hex in a string variable string hexValue1 = "," + ToHex(pf0) + "," + ToHex(pf1) + "," + ToHex(pf2); //string binValue1 = ToBin(pf0) + "," + ToBin(pf1) + "," + ToBin(pf2) + ";"; //string hexPlainValue1 = ToHex2(pf0) + "" + ToHex2(pf1) + "" + ToHex2(pf2) + ""; //second half if needed if (RowType.Asymmetric == scanlineInfo.type) { pf0 = extractPF0(row.Cells, 20, 23); pf1 = extractPF1(row.Cells, 24, 31); pf2 = extractPF2(row.Cells, 32, 39); string hexValue2 = "," + ToHex(pf0) + "," + ToHex(pf1) + "," + ToHex(pf2); //string binValue2 = "," + ToBin(pf0) + "," + ToBin(pf1) + "," + ToBin(pf2) + ";"; //string hexPlainValue2 = "" + ToHex2(pf0) + "" + ToHex2(pf1) + "" + ToHex2(pf2) + ""; //Debug.WriteLine("hexValue = " + hexValue1 + hexValue2 + " --- binValue = " + binValue1 + binValue2 + "hexPlainValue = " + hexPlainValue1 + hexPlainValue2); hexValue1 += hexValue2; } //Debug.WriteLine("hexValue = " + hexValue1 + " --- binValue = " + binValue1 + "hexPlainValue = " + hexPlainValue1); Debug.WriteLine(prefix + hexValue1 + "; line #" + row.Index); } }
private void dataGridView1_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { DataGridViewRow row = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex]; ScanlineInfo scanlineInfo = (ScanlineInfo)row.Tag; scanlineInfo.type++; if (scanlineInfo.type > RowType.Repeatable) { scanlineInfo.type = RowType.Asymmetric; } Debug.WriteLine("scanlineInfo.type = " + scanlineInfo.type); switch (scanlineInfo.type) { case RowType.Asymmetric: row.HeaderCell.Value = "] {"; break; case RowType.Repeatable: row.HeaderCell.Value = "] ]"; break; case RowType.Symmetric: row.HeaderCell.Value = "[ ]"; break; } if (scanlineInfo.type != RowType.Asymmetric) { for (int i = 0; i < row.Cells.Count / 2; i++) { updatePixelAtRow(false, row.Cells[i], erasure); } } }
private void LoadFromFile() { //Deactivate events this.dataGridView1.RowEnter -= dataGridView1_RowEnter; dataGridView1.Rows.Clear(); string file = "c:\\temp\\mygrid.bin"; using (BinaryReader bw = new BinaryReader(File.Open(file, FileMode.Open))) { int n = bw.ReadInt32(); int m = bw.ReadInt32(); for (int i = 0; i < m; ++i) { dataGridView1.Rows.Add(); int s = bw.ReadInt32(); ScanlineInfo scanlineInfo = (ScanlineInfo)DeserializeFromBytes(bw.ReadBytes(s)); dataGridView1.Rows[i].Tag = scanlineInfo; for (int j = 0; j < n; ++j) { if (bw.ReadBoolean()) { dataGridView1.Rows[i].Cells[j].Tag = Convert.ToInt32(bw.ReadBoolean()); dataGridView1.Rows[i].Cells[j].Style.BackColor = scanlineInfo.frontColor; } else { bw.ReadBoolean(); } } dataGridView1.Rows[i].DefaultCellStyle.BackColor = scanlineInfo.backColor; } } //Reactivate events this.dataGridView1.RowEnter += dataGridView1_RowEnter; }
/** * Plot pixel at a given cell coordinate */ private void updatePixelAtRow(bool forceOverwrite, DataGridViewCell cell, bool erasure) { ScanlineInfo scanlineInfo = (ScanlineInfo)dataGridView1.Rows[cell.RowIndex].Tag; if (scanlineInfo != null) { if (scanlineInfo.frontColor == Color.Empty) { scanlineInfo.frontColor = defaultFrontColor; } //only update market pixels if (forceOverwrite || (cell.Tag != null && (int)cell.Tag == 1)) { if (erasure) { cell.Tag = null; cell.Style.BackColor = Color.Empty;// scanlineInfo.backColor; } else { cell.Tag = 1; cell.Style.BackColor = scanlineInfo.frontColor; } } int mid = dataGridView1.ColumnCount / 2; int max = dataGridView1.ColumnCount - 1; switch (scanlineInfo.type) { case RowType.Asymmetric: break; case RowType.Repeatable: if (cell.ColumnIndex < mid) { dataGridView1.Rows[cell.RowIndex].Cells[cell.ColumnIndex + mid].Tag = cell.Tag; dataGridView1.Rows[cell.RowIndex].Cells[cell.ColumnIndex + mid].Style.BackColor = cell.Style.BackColor; } else if (cell.ColumnIndex >= mid) { dataGridView1.Rows[cell.RowIndex].Cells[cell.ColumnIndex - mid].Tag = cell.Tag; dataGridView1.Rows[cell.RowIndex].Cells[cell.ColumnIndex - mid].Style.BackColor = cell.Style.BackColor; } break; case RowType.Symmetric: if (cell.ColumnIndex < mid) { dataGridView1.Rows[cell.RowIndex].Cells[max - cell.ColumnIndex].Tag = cell.Tag; dataGridView1.Rows[cell.RowIndex].Cells[max - cell.ColumnIndex].Style.BackColor = cell.Style.BackColor; } else if (cell.ColumnIndex >= mid) { dataGridView1.Rows[cell.RowIndex].Cells[max - cell.ColumnIndex].Tag = cell.Tag; dataGridView1.Rows[cell.RowIndex].Cells[max - cell.ColumnIndex].Style.BackColor = cell.Style.BackColor; } break; } } }