From 1034bd98d6c75e8f5ab33102b0aae47dda50bbb1 Mon Sep 17 00:00:00 2001 From: Anton Mukhin Date: Sat, 24 May 2025 00:04:26 +0300 Subject: [PATCH] Fill canvas button and several small UI changes/fixes --- McBitFont/Form1.Designer.cs | 54 +++++++++++++----- McBitFont/Form1.cs | 62 +++++++++++++-------- McBitFont/Properties/Resources.Designer.cs | 20 +++++++ McBitFont/Properties/Resources.resx | 14 +++-- McBitFont/Resources/Canvas_Clear.png | Bin 0 -> 595 bytes McBitFont/Resources/Canvas_Fill.png | Bin 0 -> 547 bytes TODO.txt | 1 + icons/Canvas_Clear.png | Bin 0 -> 595 bytes icons/Canvas_Fill.png | Bin 0 -> 547 bytes 9 files changed, 112 insertions(+), 39 deletions(-) create mode 100644 McBitFont/Resources/Canvas_Clear.png create mode 100644 McBitFont/Resources/Canvas_Fill.png create mode 100644 icons/Canvas_Clear.png create mode 100644 icons/Canvas_Fill.png diff --git a/McBitFont/Form1.Designer.cs b/McBitFont/Form1.Designer.cs index 5498b4a..7cf13db 100644 --- a/McBitFont/Form1.Designer.cs +++ b/McBitFont/Form1.Designer.cs @@ -34,6 +34,7 @@ cbZoom = new System.Windows.Forms.ComboBox(); label4 = new System.Windows.Forms.Label(); panel1 = new System.Windows.Forms.Panel(); + btnFill = new System.Windows.Forms.Button(); btnClear = new System.Windows.Forms.Button(); btnMirrorY = new System.Windows.Forms.Button(); btnMirrorX = new System.Windows.Forms.Button(); @@ -96,8 +97,9 @@ toolTip1 = new System.Windows.Forms.ToolTip(components); chkLeftSide = new System.Windows.Forms.CheckBox(); chkTopSide = new System.Windows.Forms.CheckBox(); - label3 = new System.Windows.Forms.Label(); chkHexCodes = new System.Windows.Forms.CheckBox(); + label3 = new System.Windows.Forms.Label(); + FillToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)nudX).BeginInit(); ((System.ComponentModel.ISupportInitialize)nudY).BeginInit(); panel1.SuspendLayout(); @@ -209,6 +211,7 @@ // panel1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + panel1.Controls.Add(btnFill); panel1.Controls.Add(btnClear); panel1.Controls.Add(btnMirrorY); panel1.Controls.Add(btnMirrorX); @@ -223,6 +226,19 @@ panel1.Size = new System.Drawing.Size(140, 139); panel1.TabIndex = 9; // + // btnFill + // + btnFill.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 204); + btnFill.Location = new System.Drawing.Point(92, 9); + btnFill.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnFill.Name = "btnFill"; + btnFill.Size = new System.Drawing.Size(35, 35); + btnFill.TabIndex = 8; + btnFill.Text = "⬤"; + toolTip1.SetToolTip(btnFill, "Paint canvas black"); + btnFill.UseVisualStyleBackColor = true; + btnFill.Click += btnFill_Click; + // // btnClear // btnClear.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 204); @@ -232,7 +248,7 @@ btnClear.Size = new System.Drawing.Size(35, 35); btnClear.TabIndex = 7; btnClear.Text = "○"; - toolTip1.SetToolTip(btnClear, "Clear canvas"); + toolTip1.SetToolTip(btnClear, "Paint canvas white"); btnClear.UseVisualStyleBackColor = true; btnClear.Click += btnClear_Click; // @@ -713,14 +729,14 @@ // // canvasToolStripMenuItem // - canvasToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { ClearToolStripMenuItem, shiftUpToolStripMenuItem, shiftDownToolStripMenuItem, shiftLeftToolStripMenuItem, shiftRightToolStripMenuItem, invertToolStripMenuItem, mirrorXToolStripMenuItem, mirrorYToolStripMenuItem, applyToolStripMenuItem }); + canvasToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { ClearToolStripMenuItem, FillToolStripMenuItem, shiftUpToolStripMenuItem, shiftDownToolStripMenuItem, shiftLeftToolStripMenuItem, shiftRightToolStripMenuItem, invertToolStripMenuItem, mirrorXToolStripMenuItem, mirrorYToolStripMenuItem, applyToolStripMenuItem }); canvasToolStripMenuItem.Name = "canvasToolStripMenuItem"; canvasToolStripMenuItem.Size = new System.Drawing.Size(57, 20); canvasToolStripMenuItem.Text = "Canvas"; // // ClearToolStripMenuItem // - ClearToolStripMenuItem.Image = Properties.Resources.z_shading; + ClearToolStripMenuItem.Image = Properties.Resources.Canvas_Clear; ClearToolStripMenuItem.Name = "ClearToolStripMenuItem"; ClearToolStripMenuItem.ShortcutKeyDisplayString = ""; ClearToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.W; @@ -877,6 +893,18 @@ toolTip1.SetToolTip(chkTopSide, "Height changes will be made on Top/Bottom side"); chkTopSide.UseVisualStyleBackColor = true; // + // chkHexCodes + // + chkHexCodes.AutoSize = true; + chkHexCodes.Location = new System.Drawing.Point(618, 155); + chkHexCodes.Name = "chkHexCodes"; + chkHexCodes.Size = new System.Drawing.Size(95, 19); + chkHexCodes.TabIndex = 22; + chkHexCodes.Text = "Codes in Hex"; + toolTip1.SetToolTip(chkHexCodes, "Option to show symbol codes in Hexadecimal"); + chkHexCodes.UseVisualStyleBackColor = true; + chkHexCodes.CheckedChanged += chkHexCodes_CheckedChanged; + // // label3 // label3.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; @@ -887,16 +915,14 @@ label3.TabIndex = 21; label3.Text = "Cursor:"; // - // chkHexCodes + // FillToolStripMenuItem // - chkHexCodes.AutoSize = true; - chkHexCodes.Location = new System.Drawing.Point(618, 155); - chkHexCodes.Name = "chkHexCodes"; - chkHexCodes.Size = new System.Drawing.Size(95, 19); - chkHexCodes.TabIndex = 22; - chkHexCodes.Text = "Codes in Hex"; - chkHexCodes.UseVisualStyleBackColor = true; - chkHexCodes.CheckedChanged += chkHexCodes_CheckedChanged; + FillToolStripMenuItem.Image = Properties.Resources.Canvas_Fill; + FillToolStripMenuItem.Name = "FillToolStripMenuItem"; + FillToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.B; + FillToolStripMenuItem.Size = new System.Drawing.Size(197, 22); + FillToolStripMenuItem.Text = "Fill canvas"; + FillToolStripMenuItem.Click += btnFill_Click; // // MainForm // @@ -1019,6 +1045,8 @@ private System.Windows.Forms.ToolStripMenuItem importImageToolStripMenuItem; private System.Windows.Forms.Label label3; private System.Windows.Forms.CheckBox chkHexCodes; + private System.Windows.Forms.Button btnFill; + private System.Windows.Forms.ToolStripMenuItem FillToolStripMenuItem; } } diff --git a/McBitFont/Form1.cs b/McBitFont/Form1.cs index 598af25..b2bfc54 100644 --- a/McBitFont/Form1.cs +++ b/McBitFont/Form1.cs @@ -125,7 +125,7 @@ namespace McBitFont { return ff; } - public void ListViewItem_SetSpacing(ListView listview, short leftPadding, short topPadding) { + public static void ListViewItem_SetSpacing(ListView listview, short leftPadding, short topPadding) { const int LVM_FIRST = 0x1000; const int LVM_SETICONSPACING = LVM_FIRST + 53; SendMessage(listview.Handle, LVM_SETICONSPACING, IntPtr.Zero, (IntPtr)MakeLong(leftPadding, topPadding)); @@ -161,8 +161,8 @@ namespace McBitFont { if (monospaced) { Bitmap bmp; for (int i = 0; i < frames.Count; i++) { - frames[i] = frameResize(frames[i], (int)nudX.Value, dotHeight); - bmp = getMiniPictue(frames[i]); + frames[i] = FrameResize(frames[i], (int)nudX.Value, dotHeight); + bmp = GetMiniPictue(frames[i]); string s = frames[i].code.ToString().PadLeft(3, '0'); ilMiniatures.Images.RemoveByKey(s); ilMiniatures.Images.Add(s, (Image)bmp); @@ -174,7 +174,7 @@ namespace McBitFont { prjModified = true; } - dotResize((int)nudX.Value, dotHeight); + DotResize((int)nudX.Value, dotHeight); Cursor.Current = Cursors.Default; } @@ -182,8 +182,8 @@ namespace McBitFont { Cursor.Current = Cursors.WaitCursor; Bitmap bmp; for (int i = 0; i < frames.Count; i++) { - frames[i] = frameResize(frames[i], frames[i].width, (int)nudY.Value); - bmp = getMiniPictue(frames[i]); + frames[i] = FrameResize(frames[i], frames[i].width, (int)nudY.Value); + bmp = GetMiniPictue(frames[i]); string s = frames[i].code.ToString().PadLeft(3, '0'); ilMiniatures.Images.RemoveByKey(s); ilMiniatures.Images.Add(s, (Image)bmp); @@ -194,11 +194,11 @@ namespace McBitFont { prjModified = true; } - dotResize(dotWidth, (int)nudY.Value); + DotResize(dotWidth, (int)nudY.Value); Cursor.Current = Cursors.Default; } - private FrameMiniature frameResize(FrameMiniature ff, int neww, int newh) { + private FrameMiniature FrameResize(FrameMiniature ff, int neww, int newh) { int oldw = ff.width; int oldh = ff.height; int di = 0, dj = 0; @@ -226,8 +226,8 @@ namespace McBitFont { return ff; } - private void dotResize(int ww, int hh) { - f = frameResize(f, ww, hh); + private void DotResize(int ww, int hh) { + f = FrameResize(f, ww, hh); dotWidth = ww; dotHeight = hh; w = pixelOffset + dotWidth * (cellSize + gap); @@ -496,7 +496,7 @@ namespace McBitFont { int index = frames.FindIndex(x => x.code == f.code); frames[index] = f; - var sizedBMP = getMiniPictue(f); + var sizedBMP = GetMiniPictue(f); string s = f.code.ToString().PadLeft(3, '0'); ilMiniatures.Images.RemoveByKey(s); ilMiniatures.Images.Add(s, (Image)sizedBMP); @@ -505,7 +505,7 @@ namespace McBitFont { prjModified = true; } - private Bitmap getMiniPictue(FrameMiniature m) { + private static Bitmap GetMiniPictue(FrameMiniature m) { int picSize = (m.width > m.height) ? m.width : m.height; var bmp = new Bitmap(picSize, picSize); int imin = m.width < picSize ? (picSize - m.width) / 2 : 0; @@ -572,7 +572,7 @@ namespace McBitFont { return enc.GetString(new byte[] { (byte)code }); } - private FrameMiniature fillFrame(FrameMiniature ff, Font font, int sx, int sy) { + private FrameMiniature DrawFrameChar(FrameMiniature ff, Font font, int sx, int sy) { string s = decodeSymbol(ff.code); Bitmap bmp = new Bitmap(ff.width, ff.height); Graphics g = Graphics.FromImage(bmp); @@ -640,7 +640,7 @@ namespace McBitFont { for (i = imin; i <= imax; i++) { newf = new FrameMiniature(i, neww, newh); - if (form.cbFontBased.Checked) newf = fillFrame(newf, form.dlgFont.Font, (int)form.nudShiftX.Value, (int)form.nudShiftY.Value); + if (form.cbFontBased.Checked) newf = DrawFrameChar(newf, form.dlgFont.Font, (int)form.nudShiftX.Value, (int)form.nudShiftY.Value); frames.Add(newf); } @@ -654,7 +654,7 @@ namespace McBitFont { codepage = (form.cbEncoding.SelectedItem as New.EncodingItem).Code; foreach (FrameMiniature ff in frames) { var s = ff.code.ToString().PadLeft(3, '0'); - ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff)); + ilMiniatures.Images.Add(s, (Image)GetMiniPictue(ff)); var sss = decodeSymbol(ff.code); miniList.Items.Add(s, s + ' ' + append + sss, s); } @@ -764,14 +764,14 @@ namespace McBitFont { var s = ff.code.ToString().PadLeft(3, '0'); var sHex = 'x' + Convert.ToString(ff.code, 16).PadLeft(2, '0').ToUpper(); var sss = decodeSymbol(ff.code); - ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff)); + ilMiniatures.Images.Add(s, (Image)GetMiniPictue(ff)); miniList.Items.Add(s, (chkHexCodes.Checked ? sHex : s) + ' ' + sss, s); } nudX.ValueChanged -= nudX_ValueChanged; nudY.ValueChanged -= nudY_ValueChanged; nudX.Value = frames.First().width; nudY.Value = frames.First().height; - dotResize((int)nudX.Value, (int)nudY.Value); + DotResize((int)nudX.Value, (int)nudY.Value); nudX.ValueChanged += nudX_ValueChanged; nudY.ValueChanged += nudY_ValueChanged; f = CopyFrame(frames.First()); @@ -856,7 +856,7 @@ namespace McBitFont { } var s = ff.code.ToString().PadLeft(3, '0'); - ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff)); + ilMiniatures.Images.Add(s, (Image)GetMiniPictue(ff)); var sss = decodeSymbol(ff.code); miniList.Items.Add(s, s + ' ' + sss, s); CheckForAdd(); @@ -939,15 +939,32 @@ namespace McBitFont { } - private void btnClear_Click(object sender, EventArgs e) { + private void FillFrame(bool val) { history.AddPre(f); - Array.Clear(f.data, 0, f.data.Length); + + if (!val) Array.Clear(f.data); + else + for (int i = 0; i < f.width; i++) { + for (int j = 0; j < f.height; j++) { + f.data[i, j] = val; + } + } + history.AddPost(f); CheckHistoryButtons(); modified = true; + prjModified = true; dotPanel.Refresh(); } + private void btnClear_Click(object sender, EventArgs e) { + FillFrame(false); + } + + private void btnFill_Click(object sender, EventArgs e) { + FillFrame(true); + } + private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (prjModified) { if (MessageBox.Show("The project is modified.\nAre you sure you want to quit?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { @@ -1050,7 +1067,7 @@ namespace McBitFont { var key = ff.code.ToString().PadLeft(3, '0'); var text = decodeSymbol(ff.code); - ilMiniatures.Images.Add(key, (Image)getMiniPictue(ff)); + ilMiniatures.Images.Add(key, (Image)GetMiniPictue(ff)); miniList.Items.Add(key, key + ' ' + text, key); } @@ -1095,8 +1112,9 @@ namespace McBitFont { } else { item.Text = item.ImageKey + ' ' + symbol; } - + } } + } } diff --git a/McBitFont/Properties/Resources.Designer.cs b/McBitFont/Properties/Resources.Designer.cs index 2d26efd..281bcaa 100644 --- a/McBitFont/Properties/Resources.Designer.cs +++ b/McBitFont/Properties/Resources.Designer.cs @@ -110,6 +110,26 @@ namespace McBitFont.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Canvas_Clear { + get { + object obj = ResourceManager.GetObject("Canvas_Clear", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Canvas_Fill { + get { + object obj = ResourceManager.GetObject("Canvas_Fill", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/McBitFont/Properties/Resources.resx b/McBitFont/Properties/Resources.resx index e7614bc..cabd1c6 100644 --- a/McBitFont/Properties/Resources.resx +++ b/McBitFont/Properties/Resources.resx @@ -151,8 +151,8 @@ ..\Resources\arrow_right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\Famfamfam-Silk-Door-out.16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\calculator.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\asterisk_orange.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -160,9 +160,15 @@ ..\..\icons\famfamfam\arrow_down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Canvas_Clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\arrow_up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Famfamfam-Silk-Door-out.16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\file.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -208,7 +214,7 @@ ..\Resources\icon_64.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\calculator.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Canvas_Fill.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/McBitFont/Resources/Canvas_Clear.png b/McBitFont/Resources/Canvas_Clear.png new file mode 100644 index 0000000000000000000000000000000000000000..ead2bd198b08373e059d85c37921505ff12b926e GIT binary patch literal 595 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1enP_o1|q9iy!t)x7$D3!r6B|j-u!8128JvAsb zF{QHbWU39&)b`Afh>{3jAFJg2T)jk)8oi3#0-$aN1{?c|g2d$P)DnfH)bz|eTlM$5 z_p2*prr4^7oBA5~7C5J7WO`H;r3P2|g(O#HCtIed+uQMS*;H5oO~_3xNmQuF&B-ga zs<2f88*Bw+gM{^!>}-ls(yW49+@LCeJX@uVl9B=|ef{$Ca=mh6z5JqdeM3u2OML?) zeIp}XpbFjM%Dj@q3f;V7WvBrzsl~}fnFS@8`FRQ;0~3?-OG|8(N=q|StkM$GOp{Vl zOm&kIjZ<_D4O0?z6H|;0byJLuQ_M{bEsW9(la!#=mt>|P?9VHP1_Lla^g%NEhI$4d zCxh5l{zaLoKv#gQv@^5;%cF?d=z|=BanMprB-l zYeY$Kep*R+Vo@rCV@iHfs)A>3VtQ&&YGO)d;mK4R1_s9V%#etZ2wxwowic-?7f?V97Du6s& zrHqo20xNy}^73-Ma$~*xqI7*jOG`_A10#JSBVC{h-Qvo;lEez#ykcdj0WPV<$wiq3 zC7Jno3Lpa$lk!VTY?Vq&GgGY664OkRQc_HHlM;{3jAFJg2T)jk)8oi3#0-$aN1{?c|g2d$P)DnfH)bz|eTlM$5 z_p2*prr4^7oBA5~7C5J7WO`H;r3P2|g(O#HCtIed+uQMS*;H5oO~_3xNmQuF&B-ga zs<2f88*Bw+gM{^!>}-ls(yW49+@LCeJX@uVl9B=|ef{$Ca=mh6z5JqdeM3u2OML?) zeIp}XpbFjM%Dj@q3f;V7WvBrzsl~}fnFS@8`FRQ;0~3?-OG|8(N=q|StkM$GOp{Vl zOm&kIjZ<_D4O0?z6H|;0byJLuQ_M{bEsW9(la!#=mt>|P?9VHP1_Lla^g%NEhI$4d zCxh5l{zaLoKv#gQv@^5;%cF?d=z|=BanMprB-l zYeY$Kep*R+Vo@rCV@iHfs)A>3VtQ&&YGO)d;mK4R1_s9V%#etZ2wxwowic-?7f?V97Du6s& zrHqo20xNy}^73-Ma$~*xqI7*jOG`_A10#JSBVC{h-Qvo;lEez#ykcdj0WPV<$wiq3 zC7Jno3Lpa$lk!VTY?Vq&GgGY664OkRQc_HHlM;