diff --git a/McBitFont/Form1.Designer.cs b/McBitFont/Form1.Designer.cs index edeeafd..26c3ec1 100644 --- a/McBitFont/Form1.Designer.cs +++ b/McBitFont/Form1.Designer.cs @@ -29,8 +29,20 @@ this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); + this.cbZoom = new System.Windows.Forms.ComboBox(); + this.label4 = new System.Windows.Forms.Label(); + this.pbZoom = new System.Windows.Forms.ProgressBar(); + this.panel1 = new System.Windows.Forms.Panel(); + this.btnShiftLeft = new System.Windows.Forms.Button(); + this.btnShiftRight = new System.Windows.Forms.Button(); + this.btnShiftUp = new System.Windows.Forms.Button(); + this.btnShiftDown = new System.Windows.Forms.Button(); + this.btnInvert = new System.Windows.Forms.Button(); + this.btnMirrorX = new System.Windows.Forms.Button(); + this.btnMirrorY = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.nudX)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudY)).BeginInit(); + this.panel1.SuspendLayout(); this.SuspendLayout(); // // dotPanel @@ -45,6 +57,7 @@ this.dotPanel.Name = "dotPanel"; this.dotPanel.Size = new System.Drawing.Size(527, 542); this.dotPanel.TabIndex = 0; + this.dotPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dotPanel_MouseMove); // // nudX // @@ -64,10 +77,11 @@ this.nudX.Size = new System.Drawing.Size(55, 20); this.nudX.TabIndex = 1; this.nudX.Value = new decimal(new int[] { - 5, + 32, 0, 0, 0}); + this.nudX.ValueChanged += new System.EventHandler(this.nudX_ValueChanged); // // nudY // @@ -87,10 +101,11 @@ this.nudY.Size = new System.Drawing.Size(55, 20); this.nudY.TabIndex = 2; this.nudY.Value = new decimal(new int[] { - 7, + 32, 0, 0, 0}); + this.nudY.ValueChanged += new System.EventHandler(this.nudY_ValueChanged); // // label1 // @@ -114,18 +129,160 @@ // // label3 // + this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(677, 148); + this.label3.Location = new System.Drawing.Point(545, 12); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(35, 13); this.label3.TabIndex = 0; this.label3.Text = "label3"; // + // cbZoom + // + this.cbZoom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cbZoom.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbZoom.FormattingEnabled = true; + this.cbZoom.Items.AddRange(new object[] { + "2", + "3", + "5", + "10", + "15", + "20", + "25", + "30", + "35", + "40", + "45", + "50"}); + this.cbZoom.Location = new System.Drawing.Point(545, 533); + this.cbZoom.Name = "cbZoom"; + this.cbZoom.Size = new System.Drawing.Size(59, 21); + this.cbZoom.TabIndex = 6; + this.cbZoom.TabStop = false; + // + // label4 + // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(542, 517); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(62, 13); + this.label4.TabIndex = 7; + this.label4.Text = "Zoom level:"; + // + // pbZoom + // + this.pbZoom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.pbZoom.Location = new System.Drawing.Point(610, 533); + this.pbZoom.Name = "pbZoom"; + this.pbZoom.Size = new System.Drawing.Size(169, 21); + this.pbZoom.Step = 1; + this.pbZoom.TabIndex = 8; + this.pbZoom.Visible = false; + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel1.Controls.Add(this.btnMirrorY); + this.panel1.Controls.Add(this.btnMirrorX); + this.panel1.Controls.Add(this.btnInvert); + this.panel1.Controls.Add(this.btnShiftDown); + this.panel1.Controls.Add(this.btnShiftUp); + this.panel1.Controls.Add(this.btnShiftRight); + this.panel1.Controls.Add(this.btnShiftLeft); + this.panel1.Location = new System.Drawing.Point(548, 70); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(231, 183); + this.panel1.TabIndex = 9; + // + // btnShiftLeft + // + this.btnShiftLeft.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnShiftLeft.Location = new System.Drawing.Point(8, 40); + this.btnShiftLeft.Name = "btnShiftLeft"; + this.btnShiftLeft.Size = new System.Drawing.Size(30, 30); + this.btnShiftLeft.TabIndex = 0; + this.btnShiftLeft.Text = "◀"; + this.btnShiftLeft.UseVisualStyleBackColor = true; + this.btnShiftLeft.Click += new System.EventHandler(this.btnShiftLeft_Click); + // + // btnShiftRight + // + this.btnShiftRight.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnShiftRight.Location = new System.Drawing.Point(80, 40); + this.btnShiftRight.Name = "btnShiftRight"; + this.btnShiftRight.Size = new System.Drawing.Size(30, 30); + this.btnShiftRight.TabIndex = 1; + this.btnShiftRight.Text = "▶"; + this.btnShiftRight.UseVisualStyleBackColor = true; + this.btnShiftRight.Click += new System.EventHandler(this.btnShiftRight_Click); + // + // btnShiftUp + // + this.btnShiftUp.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnShiftUp.Location = new System.Drawing.Point(44, 4); + this.btnShiftUp.Name = "btnShiftUp"; + this.btnShiftUp.Size = new System.Drawing.Size(30, 30); + this.btnShiftUp.TabIndex = 2; + this.btnShiftUp.Text = "▲"; + this.btnShiftUp.UseVisualStyleBackColor = true; + this.btnShiftUp.Click += new System.EventHandler(this.btnShiftUp_Click); + // + // btnShiftDown + // + this.btnShiftDown.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnShiftDown.Location = new System.Drawing.Point(44, 40); + this.btnShiftDown.Name = "btnShiftDown"; + this.btnShiftDown.Size = new System.Drawing.Size(30, 30); + this.btnShiftDown.TabIndex = 3; + this.btnShiftDown.Text = "▼"; + this.btnShiftDown.UseVisualStyleBackColor = true; + this.btnShiftDown.Click += new System.EventHandler(this.btnShiftDown_Click); + // + // btnInvert + // + this.btnInvert.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnInvert.Location = new System.Drawing.Point(8, 89); + this.btnInvert.Name = "btnInvert"; + this.btnInvert.Size = new System.Drawing.Size(30, 30); + this.btnInvert.TabIndex = 4; + this.btnInvert.Text = "◪"; + this.btnInvert.UseVisualStyleBackColor = true; + this.btnInvert.Click += new System.EventHandler(this.btnInvert_Click); + // + // btnMirrorX + // + this.btnMirrorX.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnMirrorX.Location = new System.Drawing.Point(44, 89); + this.btnMirrorX.Name = "btnMirrorX"; + this.btnMirrorX.Size = new System.Drawing.Size(30, 30); + this.btnMirrorX.TabIndex = 5; + this.btnMirrorX.Text = "◮"; + this.btnMirrorX.UseVisualStyleBackColor = true; + this.btnMirrorX.Click += new System.EventHandler(this.btnMirrorX_Click); + // + // btnMirrorY + // + this.btnMirrorY.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnMirrorY.Location = new System.Drawing.Point(80, 89); + this.btnMirrorY.Name = "btnMirrorY"; + this.btnMirrorY.Size = new System.Drawing.Size(30, 30); + this.btnMirrorY.TabIndex = 6; + this.btnMirrorY.Text = "⩥"; + this.btnMirrorY.UseVisualStyleBackColor = true; + this.btnMirrorY.Click += new System.EventHandler(this.btnMirrorY_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(791, 566); + this.Controls.Add(this.panel1); + this.Controls.Add(this.pbZoom); + this.Controls.Add(this.label4); + this.Controls.Add(this.cbZoom); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); @@ -134,10 +291,11 @@ this.Controls.Add(this.dotPanel); this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Form1"; + this.Text = "McBitFont"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.nudX)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nudY)).EndInit(); + this.panel1.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -151,6 +309,17 @@ private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; + private System.Windows.Forms.ComboBox cbZoom; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.ProgressBar pbZoom; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Button btnShiftLeft; + private System.Windows.Forms.Button btnShiftRight; + private System.Windows.Forms.Button btnShiftDown; + private System.Windows.Forms.Button btnShiftUp; + private System.Windows.Forms.Button btnInvert; + private System.Windows.Forms.Button btnMirrorX; + private System.Windows.Forms.Button btnMirrorY; } } diff --git a/McBitFont/Form1.cs b/McBitFont/Form1.cs index 1d919b4..62149c3 100644 --- a/McBitFont/Form1.cs +++ b/McBitFont/Form1.cs @@ -4,14 +4,17 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Windows.Forms.VisualStyles; namespace McBitFont { public partial class Form1 : Form { - private int cellSize = 50; + private int cellSize = 10; + private int dotWidth, dotHeight; private Panel[,] dots = new Panel[255,255]; public Form1() { @@ -21,20 +24,33 @@ namespace McBitFont { private void Form1_Load(object sender, EventArgs e) { int i, j; - for (i = 0; i < (int)nudX.Value; i++) { - for (j = 0; j < (int)nudY.Value; 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(); - p.Parent = dotPanel; - p.Width = cellSize; p.Height = cellSize; - p.BackColor = Color.White; - 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; - dots[i,j] = p; + dots[i,j] = NewDot(i, j); } } + + cbZoom.SelectedIndex = 3; + cbZoom.SelectedIndexChanged += cbZoom_SelectedIndexChanged; + } + + 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) { @@ -42,14 +58,188 @@ namespace McBitFont { if (e.Button == MouseButtons.Left && p.BackColor != Color.Black) { p.BackColor = Color.Black; - //label3.Text = "Mouse1 " + p.Tag; - //p.Update(); } if (e.Button == MouseButtons.Right && p.BackColor != Color.White) { p.BackColor = Color.White; - //label3.Text = "Mouse2 " + p.Tag; } - label3.Text = "MouseMove " + p.Tag; + label3.Text = "Over: " + p.Tag; + p.Capture = false; + } + + private void nudX_ValueChanged(object sender, EventArgs e) { + dotResize((int)nudX.Value, dotHeight); + } + + private void nudY_ValueChanged(object sender, EventArgs e) { + 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; + + //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; + } + + private void cbZoom_SelectedIndexChanged(object sender, EventArgs e) { + cellSize = Convert.ToInt32(cbZoom.Text); + dotScale(); + } + + private void btnShiftLeft_Click(object sender, EventArgs e) { + for (int j = 0; j < dotHeight; j++) { + Color c = dots[0, j].BackColor; + for (int i = 0; i < dotWidth; i++) { + if (i == dotWidth - 1) { + dots[i, j].BackColor = c; + } else { + dots[i, j].BackColor = dots[i+1, j].BackColor; + } + } + } + } + + private void btnShiftRight_Click(object sender, EventArgs e) { + for (int j = 0; j < dotHeight; j++) { + Color c = dots[dotWidth - 1, j].BackColor; + for (int i = dotWidth-1; i >= 0; i--) { + if (i == 0) { + dots[i, j].BackColor = c; + } else { + dots[i, j].BackColor = dots[i - 1, j].BackColor; + } + } + } + } + + private void dotPanel_MouseMove(object sender, MouseEventArgs e) { + Panel p = (Panel)sender; + p.Capture = false; + } + + 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; + } + } + } + } + + 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; + } + } + } + } + + 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; + } + } + } + + private void btnMirrorX_Click(object sender, EventArgs e) { + int a, b, j; + Color 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--; + } + } + } + + private void btnMirrorY_Click(object sender, EventArgs e) { + int a, b, i; + Color 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--; + } + } + } + + private void dotScale() { + bool large = dotWidth * dotHeight > 12 * 12; + int gap = (cellSize < 5) ? 0 : 1; + + 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(); + } + } + if (large) { + dotPanel.Visible = true; + pbZoom.Visible = false; + } + } }