diff --git a/McBitFont/Form1.Designer.cs b/McBitFont/Form1.Designer.cs index 0b435bc..d63753a 100644 --- a/McBitFont/Form1.Designer.cs +++ b/McBitFont/Form1.Designer.cs @@ -24,10 +24,10 @@ /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("adasd"); - System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("ddddd", 0); - System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("ffff"); - System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem(""); + System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem("adasd"); + System.Windows.Forms.ListViewItem listViewItem6 = new System.Windows.Forms.ListViewItem("ddddd", 0); + System.Windows.Forms.ListViewItem listViewItem7 = new System.Windows.Forms.ListViewItem("ffff"); + System.Windows.Forms.ListViewItem listViewItem8 = new System.Windows.Forms.ListViewItem(""); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.dotPanel = new System.Windows.Forms.Panel(); this.nudX = new System.Windows.Forms.NumericUpDown(); @@ -51,6 +51,9 @@ this.miniList = new System.Windows.Forms.ListView(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.button2 = new System.Windows.Forms.Button(); + this.hScroll = new System.Windows.Forms.HScrollBar(); + this.vScroll = new System.Windows.Forms.VScrollBar(); + this.label5 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.nudX)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudY)).BeginInit(); this.panel1.SuspendLayout(); @@ -61,14 +64,15 @@ this.dotPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.dotPanel.AutoScroll = true; this.dotPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.dotPanel.BackColor = System.Drawing.SystemColors.ControlDark; this.dotPanel.Location = new System.Drawing.Point(12, 12); this.dotPanel.Name = "dotPanel"; - this.dotPanel.Size = new System.Drawing.Size(613, 542); + this.dotPanel.Size = new System.Drawing.Size(593, 518); this.dotPanel.TabIndex = 0; + 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); // // nudX // @@ -171,6 +175,7 @@ this.cbZoom.Size = new System.Drawing.Size(59, 21); this.cbZoom.TabIndex = 6; this.cbZoom.TabStop = false; + this.cbZoom.SelectedIndexChanged += new System.EventHandler(this.cbZoom_SelectedIndexChanged); // // label4 // @@ -315,10 +320,10 @@ this.miniList.GridLines = true; this.miniList.HideSelection = false; this.miniList.Items.AddRange(new System.Windows.Forms.ListViewItem[] { - listViewItem1, - listViewItem2, - listViewItem3, - listViewItem4}); + listViewItem5, + listViewItem6, + listViewItem7, + listViewItem8}); this.miniList.LargeImageList = this.imageList1; this.miniList.Location = new System.Drawing.Point(634, 325); this.miniList.MultiSelect = false; @@ -339,6 +344,7 @@ // // button2 // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.button2.Location = new System.Drawing.Point(790, 156); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); @@ -347,11 +353,45 @@ this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // + // hScroll + // + this.hScroll.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.hScroll.Location = new System.Drawing.Point(12, 533); + this.hScroll.Name = "hScroll"; + this.hScroll.Size = new System.Drawing.Size(593, 21); + this.hScroll.TabIndex = 14; + this.hScroll.ValueChanged += new System.EventHandler(this.hScroll_ValueChanged); + // + // vScroll + // + 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); + this.vScroll.TabIndex = 15; + this.vScroll.ValueChanged += new System.EventHandler(this.vScroll_ValueChanged); + // + // label5 + // + this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(632, 25); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(35, 13); + this.label5.TabIndex = 16; + this.label5.Text = "label5"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(877, 566); + this.Controls.Add(this.label5); + this.Controls.Add(this.vScroll); + this.Controls.Add(this.hScroll); this.Controls.Add(this.button2); this.Controls.Add(this.miniList); this.Controls.Add(this.outBox); @@ -402,6 +442,9 @@ private System.Windows.Forms.ListView miniList; private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.Button button2; + private System.Windows.Forms.HScrollBar hScroll; + private System.Windows.Forms.VScrollBar vScroll; + private System.Windows.Forms.Label label5; } } diff --git a/McBitFont/Form1.cs b/McBitFont/Form1.cs index a5a9ce7..10a1bbb 100644 --- a/McBitFont/Form1.cs +++ b/McBitFont/Form1.cs @@ -14,70 +14,70 @@ 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; public bool[,] data; }; - FrameMiniature f; + private FrameMiniature f; private int cellSize = 10; private int dotWidth, dotHeight; - private Panel[,] dots = new Panel[255,255]; + private int pixelOffset = 5; + private int gap; + private int w, h; 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; - for (i = 0; i < dotWidth; i++) { - for (j = 0; j < dotHeight; j++) { - Panel p = new Panel(); - dots[i,j] = NewDot(i, j); - } - } + gap = (cellSize < 5) ? 0 : 1; + w = pixelOffset + dotWidth * (cellSize + gap); + h = pixelOffset + dotHeight * (cellSize + gap); + 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 Panel NewDot(int i, int j) { - Panel p = new Panel(); - p.Parent = dotPanel; - p.Width = cellSize; p.Height = cellSize; - p.BackColor = Color.White; - p.BorderStyle = BorderStyle.None; - p.Left = 5 + i * (cellSize + 1); - p.Top = 5 + j * (cellSize + 1); - p.Tag = i.ToString() + ',' + j.ToString(); - p.MouseMove += dot_MouseMove; - p.MouseDown += dot_MouseMove; - //p.Paint += dotPanel_Paint; - return p; - } - - 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; + 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; + } } - if (e.Button == MouseButtons.Right && p.BackColor != Color.White) { - p.BackColor = Color.White; - } - label3.Text = "Over: " + p.Tag; - p.Capture = false; } private void nudX_ValueChanged(object sender, EventArgs e) { @@ -88,157 +88,190 @@ 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); - } + f.width = ww; + f.height = hh; + t = new bool[ww, hh]; + for (int i=0; i= 0; i--) { + c = f.data[dotWidth - 1, j]; + for (int i = dotWidth - 1; i >= 0; i--) { if (i == 0) { - dots[i, j].BackColor = c; + f.data[i, j] = c; } else { - dots[i, j].BackColor = dots[i - 1, j].BackColor; + f.data[i, j] = f.data[i - 1, j]; } } } + dotPanel.Refresh(); } private void dotPanel_MouseMove(object sender, MouseEventArgs e) { - Panel p = (Panel)sender; - p.Capture = false; + if (e.X >= w || e.X <= pixelOffset || e.Y >= h || e.Y <= pixelOffset) return; + label3.Text = e.X.ToString() + ',' + e.Y.ToString(); + int i = (e.X - pixelOffset + hScroll.Value) / (cellSize + gap); + int j = (e.Y - pixelOffset + vScroll.Value) / (cellSize + gap); + label5.Text = i.ToString() + ',' + j.ToString(); + + if (e.Button == MouseButtons.Left && !f.data[i, j]) { + Graphics g = dotPanel.CreateGraphics(); + SolidBrush sbb = new SolidBrush(Color.Black); + f.data[i, j] = true; + int x = pixelOffset + i * (cellSize + gap) - hScroll.Value; + int y = pixelOffset + j * (cellSize + gap) - vScroll.Value; + g.FillRectangle(sbb, x, y, cellSize, cellSize); + } + if (e.Button == MouseButtons.Right && f.data[i, j]) { + Graphics g = dotPanel.CreateGraphics(); + SolidBrush sbw = new SolidBrush(Color.White); + f.data[i, j] = false; + int x = pixelOffset + i * (cellSize + gap) - hScroll.Value; + int y = pixelOffset + j * (cellSize + gap) - vScroll.Value; + g.FillRectangle(sbw, x, y, cellSize, cellSize); + } + } private void btnShiftUp_Click(object sender, EventArgs e) { + bool c; for (int i = 0; i < dotWidth; i++) { - Color c = dots[i, 0].BackColor; + c = f.data[i, 0]; for (int j = 0; j < dotHeight; j++) { if (j == dotHeight - 1) { - dots[i, j].BackColor = c; + f.data[i, j] = c; } else { - dots[i, j].BackColor = dots[i, j + 1].BackColor; + f.data[i, j] = f.data[i, j + 1]; } } } + dotPanel.Refresh(); } private void btnShiftDown_Click(object sender, EventArgs e) { + bool c; for (int i = 0; i < dotWidth; i++) { - Color c = dots[i, dotHeight - 1].BackColor; + c = f.data[i, dotHeight - 1]; for (int j = dotHeight-1; j >= 0; j--) { if (j == 0) { - dots[i, j].BackColor = c; + f.data[i, j] = c; } else { - dots[i, j].BackColor = dots[i, j - 1].BackColor; + 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; + f.data[i, j] = !f.data[i, j]; } } + dotPanel.Refresh(); } private void btnMirrorX_Click(object sender, EventArgs e) { int a, b, j; - Color c; + 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; + 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; + 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; + 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; @@ -260,41 +293,48 @@ namespace McBitFont { } private void button2_Click(object sender, EventArgs e) { - var bmp = new Bitmap(dotWidth, dotHeight); + int picSize = (dotWidth > dotHeight) ? dotWidth : dotHeight; + var bmp = new Bitmap(picSize, picSize); + Color c; for (int i=0; i 12 * 12; - int gap = (cellSize < 5) ? 0 : 1; + private void dotPanel_Paint(object sender, PaintEventArgs e) { + Graphics g = dotPanel.CreateGraphics(); + SolidBrush sbb = new SolidBrush(Color.Black); + SolidBrush sbw = new SolidBrush(Color.White); + SolidBrush sb; - 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 = 5 + i * (cellSize + gap); - dots[i, j].Top = 5 + j * (cellSize + gap); - if (large) pbZoom.PerformStep(); + for (int i=0; i