From f307827fb683b5c2be8a5b056143fc60ffd562ab Mon Sep 17 00:00:00 2001 From: Anton Mukhin Date: Wed, 3 May 2023 12:57:24 +0300 Subject: [PATCH] Successfully implemented manual drawing --- McBitFont/Form1.Designer.cs | 2 +- McBitFont/Form1.cs | 366 +++++++++++++++++------------------- McBitFont/Form1.resx | 2 +- 3 files changed, 173 insertions(+), 197 deletions(-) diff --git a/McBitFont/Form1.Designer.cs b/McBitFont/Form1.Designer.cs index 5c60b7d..d63753a 100644 --- a/McBitFont/Form1.Designer.cs +++ b/McBitFont/Form1.Designer.cs @@ -70,7 +70,6 @@ this.dotPanel.Name = "dotPanel"; this.dotPanel.Size = new System.Drawing.Size(593, 518); this.dotPanel.TabIndex = 0; - this.dotPanel.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dotPanel_Scroll); this.dotPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.dotPanel_Paint); this.dotPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dotPanel_MouseMove); this.dotPanel.Resize += new System.EventHandler(this.cbZoom_SelectedIndexChanged); @@ -368,6 +367,7 @@ // this.vScroll.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); + this.vScroll.LargeChange = 25; this.vScroll.Location = new System.Drawing.Point(608, 12); this.vScroll.Name = "vScroll"; this.vScroll.Size = new System.Drawing.Size(21, 518); diff --git a/McBitFont/Form1.cs b/McBitFont/Form1.cs index 8bf604c..10a1bbb 100644 --- a/McBitFont/Form1.cs +++ b/McBitFont/Form1.cs @@ -14,6 +14,12 @@ namespace McBitFont { public partial class Form1 : Form { struct FrameMiniature { + public FrameMiniature(int cc, int ww, int hh) { + code = cc; + width = ww; + height = hh; + data = new bool[ww, hh]; + } public int code; public int width; public int height; @@ -26,14 +32,13 @@ namespace McBitFont { private int pixelOffset = 5; private int gap; private int w, h; - //private Panel[,] dots = new Panel[255,255]; public Form1() { InitializeComponent(); + this.dotPanel.MouseWheel += new MouseEventHandler(this.dotPanel_MouseWheel); } private void Form1_Load(object sender, EventArgs e) { - int i, j; dotWidth = (int)nudX.Value; dotHeight = (int)nudY.Value; @@ -46,24 +51,33 @@ namespace McBitFont { cbZoom.SelectedIndex = 3; cbZoom.SelectedIndexChanged += cbZoom_SelectedIndexChanged; - f.code = 1; - f.width = dotWidth; - f.height = dotHeight; - f.data = new bool[dotWidth, dotHeight]; + f = new FrameMiniature(1, dotWidth, dotHeight); } - private void dot_MouseMove(object sender, MouseEventArgs e) { - //Panel p = (Panel)sender; - - //if (e.Button == MouseButtons.Left && p.BackColor != Color.Black) { - // p.BackColor = Color.Black; - //} - //if (e.Button == MouseButtons.Right && p.BackColor != Color.White) { - // p.BackColor = Color.White; - //} - //label3.Text = "Over: " + p.Tag; - //p.Capture = false; + private void dotPanel_MouseWheel(object sender, MouseEventArgs e) { + int t = e.Delta / 120; + if (e.Delta == 0) return; + if (ModifierKeys.HasFlag(Keys.Shift)) { + t += cbZoom.SelectedIndex; + if (t > cbZoom.Items.Count - 1) return; + if (t < 0) return; + cbZoom.SelectedIndex = t; + } else if (ModifierKeys.HasFlag(Keys.Control)) { + if (hScroll.Enabled) { + t = t * -1 * (cellSize + gap) + hScroll.Value; + if (t < hScroll.Minimum) t = hScroll.Minimum; + if (t > hScroll.Maximum) t = hScroll.Maximum; + hScroll.Value = t; + } + } else { + if (vScroll.Enabled) { + t = t * -1 * (cellSize + gap) + vScroll.Value; + if (t < vScroll.Minimum) t = vScroll.Minimum; + if (t > vScroll.Maximum) t = vScroll.Maximum; + vScroll.Value = t; + } + } } private void nudX_ValueChanged(object sender, EventArgs e) { @@ -74,40 +88,29 @@ namespace McBitFont { dotResize(dotWidth, (int)nudY.Value); } - private void dotResize(int w, int h) { - ////Width - //if (w > dotWidth) { - // for (int i = dotWidth; i < w; i++) { - // for (int j = 0; j < dotHeight; j++) { - // dots[i, j] = NewDot(i, j); - // } - // } - //} - //if (w < dotWidth) { - // for (int i = w; i < dotWidth; i++) { - // for (int j = 0; j < dotHeight; j++) { - // dots[i, j].Dispose(); - // } - // } - //} - //dotWidth = w; + private void dotResize(int ww, int hh) { + int imax, jmax; + bool[,] t; + + if (ww < dotWidth) imax = ww; + else imax = dotWidth; + if (hh < dotHeight) jmax = hh; + else jmax = dotHeight; - ////Height - //if (h > dotHeight) { - // for (int i = 0; i < dotWidth; i++) { - // for (int j = dotHeight; j < h; j++) { - // dots[i, j] = NewDot(i, j); - // } - // } - //} - //if (h < dotHeight) { - // for (int i = 0; i < dotWidth; i++) { - // for (int j = h; j < dotHeight; j++) { - // dots[i, j].Dispose(); - // } - // } - //} - //dotHeight = h; + f.width = ww; + f.height = hh; + t = new bool[ww, hh]; + for (int i=0; i= 0; i--) { - // if (i == 0) { - // dots[i, j].BackColor = c; - // } else { - // dots[i, j].BackColor = dots[i - 1, j].BackColor; - // } - // } - //} + bool c; + for (int j = 0; j < dotHeight; j++) { + c = f.data[dotWidth - 1, j]; + for (int i = dotWidth - 1; i >= 0; i--) { + if (i == 0) { + f.data[i, j] = c; + } else { + f.data[i, j] = f.data[i - 1, j]; + } + } + } + dotPanel.Refresh(); } private void dotPanel_MouseMove(object sender, MouseEventArgs e) { @@ -176,7 +181,6 @@ namespace McBitFont { Graphics g = dotPanel.CreateGraphics(); SolidBrush sbb = new SolidBrush(Color.Black); f.data[i, j] = true; - //dotPanel.Refresh(); int x = pixelOffset + i * (cellSize + gap) - hScroll.Value; int y = pixelOffset + j * (cellSize + gap) - vScroll.Value; g.FillRectangle(sbb, x, y, cellSize, cellSize); @@ -185,7 +189,6 @@ namespace McBitFont { Graphics g = dotPanel.CreateGraphics(); SolidBrush sbw = new SolidBrush(Color.White); f.data[i, j] = false; - //dotPanel.Refresh(); int x = pixelOffset + i * (cellSize + gap) - hScroll.Value; int y = pixelOffset + j * (cellSize + gap) - vScroll.Value; g.FillRectangle(sbw, x, y, cellSize, cellSize); @@ -194,115 +197,117 @@ namespace McBitFont { } private void btnShiftUp_Click(object sender, EventArgs e) { - //for (int i = 0; i < dotWidth; i++) { - // Color c = dots[i, 0].BackColor; - // for (int j = 0; j < dotHeight; j++) { - // if (j == dotHeight - 1) { - // dots[i, j].BackColor = c; - // } else { - // dots[i, j].BackColor = dots[i, j + 1].BackColor; - // } - // } - //} + bool c; + for (int i = 0; i < dotWidth; i++) { + c = f.data[i, 0]; + for (int j = 0; j < dotHeight; j++) { + if (j == dotHeight - 1) { + f.data[i, j] = c; + } else { + f.data[i, j] = f.data[i, j + 1]; + } + } + } + dotPanel.Refresh(); } private void btnShiftDown_Click(object sender, EventArgs e) { - //for (int i = 0; i < dotWidth; i++) { - // Color c = dots[i, dotHeight - 1].BackColor; - // for (int j = dotHeight-1; j >= 0; j--) { - // if (j == 0) { - // dots[i, j].BackColor = c; - // } else { - // dots[i, j].BackColor = dots[i, j - 1].BackColor; - // } - // } - //} + bool c; + for (int i = 0; i < dotWidth; i++) { + c = f.data[i, dotHeight - 1]; + for (int j = dotHeight-1; j >= 0; j--) { + if (j == 0) { + f.data[i, j] = c; + } else { + f.data[i, j] = f.data[i, j - 1]; + } + } + } + dotPanel.Refresh(); } private void btnInvert_Click(object sender, EventArgs e) { - //for (int i = 0; i < dotWidth; i++) { - // for (int j = 0; j < dotHeight; j++) { - // if (dots[i, j].BackColor == Color.White) - // dots[i, j].BackColor = Color.Black; - // else - // dots[i, j].BackColor = Color.White; - // } - //} + for (int i = 0; i < dotWidth; i++) { + for (int j = 0; j < dotHeight; j++) { + f.data[i, j] = !f.data[i, j]; + } + } + dotPanel.Refresh(); } private void btnMirrorX_Click(object sender, EventArgs e) { - //int a, b, j; - //Color c; + int a, b, j; + bool c; - //for (j = 0; j < dotHeight; j++) { - // a = 0; - // b = dotWidth - 1; - // while (a < b) { - // c = dots[a, j].BackColor; - // dots[a, j].BackColor = dots[b, j].BackColor; - // dots[b, j].BackColor = c; - // a++; - // b--; - // } - //} + for (j = 0; j < dotHeight; j++) { + a = 0; + b = dotWidth - 1; + while (a < b) { + c = f.data[a, j]; + f.data[a, j] = f.data[b, j]; + f.data[b, j] = c; + a++; + b--; + } + } + dotPanel.Refresh(); } private void btnMirrorY_Click(object sender, EventArgs e) { - //int a, b, i; - //Color c; + int a, b, i; + bool c; - //for (i = 0; i < dotWidth; i++) { - // a = 0; - // b = dotHeight - 1; - // while (a < b) { - // c = dots[i, a].BackColor; - // dots[i, a].BackColor = dots[i, b].BackColor; - // dots[i, b].BackColor = c; - // a++; - // b--; - // } - //} + for (i = 0; i < dotWidth; i++) { + a = 0; + b = dotHeight - 1; + while (a < b) { + c = f.data[i, a]; + f.data[i, a] = f.data[i, b]; + f.data[i, b] = c; + a++; + b--; + } + } + dotPanel.Refresh(); } private void button1_Click(object sender, EventArgs e) { - //for (int i = 0; i < dotWidth; i++) { - // for (int j = 0; j < dotHeight; j++) { - // if (dots[i, j].BackColor == Color.Black) f.data[i, j] = true; - // else f.data[i, j] = false; - // } - //} - - //outBox.Clear(); - //String str; - //Byte b = 0; - //for (ushort i = 0; i < dotWidth; i++) { - // str = ""; - // for (ushort j = 0; j < dotHeight; j++) { - // if (j % 8 == 0) b = 0; - // if (f.data[i, j]) { - // b |= (Byte)(1 << (j % 8)); - // } - // if ( ((j + 1) % 8 == 0) || j+1 == dotHeight ) { - // if (str.Length > 0) str += " "; - // str += "0x" + Convert.ToString(b, 16).PadLeft(2, '0') + ','; - // } - // } - // outBox.AppendText(str); - // outBox.AppendText(Environment.NewLine); - //} + outBox.Clear(); + String str; + Byte b = 0; + for (ushort i = 0; i < dotWidth; i++) { + str = ""; + for (ushort j = 0; j < dotHeight; j++) { + if (j % 8 == 0) b = 0; + if (f.data[i, j]) { + b |= (Byte)(1 << (j % 8)); + } + if ( ((j + 1) % 8 == 0) || j+1 == dotHeight ) { + if (str.Length > 0) str += " "; + str += "0x" + Convert.ToString(b, 16).PadLeft(2, '0') + ','; + } + } + outBox.AppendText(str); + outBox.AppendText(Environment.NewLine); + } } private void button2_Click(object sender, EventArgs e) { - //var bmp = new Bitmap(dotWidth, dotHeight); - //for (int i=0; i dotHeight) ? dotWidth : dotHeight; + var bmp = new Bitmap(picSize, picSize); + Color c; + for (int i=0; i 12 * 12; - - //if (large) { - // pbZoom.Maximum = dotWidth * dotHeight; - // pbZoom.Value = 0; - // pbZoom.Visible = true; - // dotPanel.Visible = false; - //} - //for (int i = 0; i < dotWidth; i++) { - // for (int j = 0; j < dotHeight; j++) { - // dots[i, j].Width = cellSize; dots[i, j].Height = cellSize; - // dots[i, j].Left = pixelOffset + i * (cellSize + gap); - // dots[i, j].Top = pixelOffset + j * (cellSize + gap); - // if (large) pbZoom.PerformStep(); - // } - //} - //if (large) { - // dotPanel.Visible = true; - // pbZoom.Visible = false; - //} - - } - } } diff --git a/McBitFont/Form1.resx b/McBitFont/Form1.resx index 1786bb5..13b1858 100644 --- a/McBitFont/Form1.resx +++ b/McBitFont/Form1.resx @@ -125,7 +125,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAA8 - BwAAAk1TRnQBSQFMAwEBAAEoAQABKAEAATIBAAEyAQAE/wEFAQAI/wFCAU0BdgcAAXYDAAEoAwAByAMA + BwAAAk1TRnQBSQFMAwEBAAEwAQABMAEAATIBAAEyAQAE/wEFAQAI/wFCAU0BdgcAAXYDAAEoAwAByAMA ATIDAAEBAQABBAUAAYgBExgAAYACAAGAAwACgAEAAYADAAGAAQABgAEAAoACAAPAAQADgAMAAf8CAAH/ AwAC/wEAAf8DAAH/AQAB/wEAAv8CAAP//wA1AAEPAYgB8AEAAQ8BiAHwAQABDwGIAfBZAAEHAQABgAEA AQcBAAFwAQABCAEAAXBZAAEHAQABgAEAAQcBAAFwAQABCAEAAXBZAAEHAQABgAEAAQcBAAFwAQABCAEA