From e927b2685d14be7a3875a90571601ae0fc521ad0 Mon Sep 17 00:00:00 2001 From: Anton Mukhin Date: Wed, 10 May 2023 12:15:43 +0300 Subject: [PATCH] Frame list management fixed --- McBitFont/Form1.cs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/McBitFont/Form1.cs b/McBitFont/Form1.cs index bb7cb66..e89526f 100644 --- a/McBitFont/Form1.cs +++ b/McBitFont/Form1.cs @@ -13,6 +13,7 @@ using System.Runtime.InteropServices; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.InteropServices.ComTypes; +using System.Diagnostics; namespace McBitFont { public partial class MainForm : Form { @@ -69,7 +70,7 @@ namespace McBitFont { frames.Add(new FrameMiniature(0, dotWidth, dotHeight)); miniList.Items.Add("0", "0 Single", "0"); miniList.Refresh(); - f = frames.Find(x => x.code == 0); + f = copyFrame(frames.Find(x => x.code == 0)); ListViewItem_SetSpacing(miniList, 50 + 2, 50 + 22); } @@ -81,6 +82,12 @@ namespace McBitFont { return (int)(((ushort)lowPart) | (uint)(highPart << 16)); } + FrameMiniature copyFrame(FrameMiniature frame) { + var ff = new FrameMiniature(frame.code, frame.width, frame.height); + Array.Copy(frame.data, ff.data, frame.data.Length); + return ff; + } + public void ListViewItem_SetSpacing(ListView listview, short leftPadding, short topPadding) { const int LVM_FIRST = 0x1000; const int LVM_SETICONSPACING = LVM_FIRST + 53; @@ -438,7 +445,7 @@ namespace McBitFont { private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (prjModified) { - if (MessageBox.Show("The project is modified.\nAre you sure you want to quit?", "Project was modified!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { + if (MessageBox.Show("The project is modified.\nDo you want to save it first?", "Project was modified!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { saveToolStripMenuItem.PerformClick(); return; } @@ -475,11 +482,14 @@ namespace McBitFont { foreach (FrameMiniature ff in frames) { var s = ff.code.ToString(); ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff)); - miniList.Items.Add(s, s+' '+append+(char)ff.code, s); + var sss = s + ' ' + append + (char)(ff.code); + //byte[] aaa = { (byte)ff.code} + //Debug.WriteLine(sss.ToString() + Encoding.UTF8.GetString(new byte[] { 0x10, 0x04 })); + miniList.Items.Add(s, s+' '+append+(char)(ff.code), s); } nudX.Value =neww; nudY.Value = newh; - f = frames.First(); + f = copyFrame(frames.First()); dotPanel.Refresh(); miniList.Refresh(); form.Dispose(); @@ -492,10 +502,11 @@ namespace McBitFont { if (MessageBox.Show("Current symbol is modified.\nDo you want to save the changes?", "Symbol was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) { saveFrame(); } + modified = false; } var sel = miniList.SelectedItems[0]; int code = Convert.ToInt32(sel.ImageKey); - FrameMiniature ff = frames.Find(x => x.code == code); + FrameMiniature ff = copyFrame(frames.Find(x => x.code == code)); nudX.Value = ff.width; nudY.Value = ff.height; f = ff; @@ -518,7 +529,7 @@ namespace McBitFont { private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (prjModified) { - if (MessageBox.Show("The project is modified.\nDo you want to save the changes?", "Project was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) { + if (MessageBox.Show("The project is modified.\nDo you want to save it first?", "Project was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) { saveToolStripMenuItem.PerformClick(); return; } @@ -548,7 +559,7 @@ namespace McBitFont { dotResize((int)nudX.Value, (int)nudY.Value); nudX.ValueChanged += nudX_ValueChanged; nudY.ValueChanged += nudY_ValueChanged; - f = frames.First(); + f = copyFrame(frames.First()); dotPanel.Refresh(); miniList.Refresh(); modified = false; @@ -559,7 +570,6 @@ namespace McBitFont { 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) { - saveToolStripMenuItem.PerformClick(); e.Cancel = true; } else { e.Cancel = false;