Frame list management fixed

This commit is contained in:
Anton Mukhin
2023-05-10 12:15:43 +03:00
parent 40f006a309
commit e927b2685d

View File

@@ -13,6 +13,7 @@ using System.Runtime.InteropServices;
using System.IO; using System.IO;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices.ComTypes;
using System.Diagnostics;
namespace McBitFont { namespace McBitFont {
public partial class MainForm : Form { public partial class MainForm : Form {
@@ -69,7 +70,7 @@ namespace McBitFont {
frames.Add(new FrameMiniature(0, dotWidth, dotHeight)); frames.Add(new FrameMiniature(0, dotWidth, dotHeight));
miniList.Items.Add("0", "0 Single", "0"); miniList.Items.Add("0", "0 Single", "0");
miniList.Refresh(); miniList.Refresh();
f = frames.Find(x => x.code == 0); f = copyFrame(frames.Find(x => x.code == 0));
ListViewItem_SetSpacing(miniList, 50 + 2, 50 + 22); ListViewItem_SetSpacing(miniList, 50 + 2, 50 + 22);
} }
@@ -81,6 +82,12 @@ namespace McBitFont {
return (int)(((ushort)lowPart) | (uint)(highPart << 16)); 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) { public void ListViewItem_SetSpacing(ListView listview, short leftPadding, short topPadding) {
const int LVM_FIRST = 0x1000; const int LVM_FIRST = 0x1000;
const int LVM_SETICONSPACING = LVM_FIRST + 53; const int LVM_SETICONSPACING = LVM_FIRST + 53;
@@ -438,7 +445,7 @@ namespace McBitFont {
private void newToolStripMenuItem_Click(object sender, EventArgs e) { private void newToolStripMenuItem_Click(object sender, EventArgs e) {
if (prjModified) { 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(); saveToolStripMenuItem.PerformClick();
return; return;
} }
@@ -475,11 +482,14 @@ namespace McBitFont {
foreach (FrameMiniature ff in frames) { foreach (FrameMiniature ff in frames) {
var s = ff.code.ToString(); var s = ff.code.ToString();
ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff)); 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; nudX.Value =neww;
nudY.Value = newh; nudY.Value = newh;
f = frames.First(); f = copyFrame(frames.First());
dotPanel.Refresh(); dotPanel.Refresh();
miniList.Refresh(); miniList.Refresh();
form.Dispose(); 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) { if (MessageBox.Show("Current symbol is modified.\nDo you want to save the changes?", "Symbol was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) {
saveFrame(); saveFrame();
} }
modified = false;
} }
var sel = miniList.SelectedItems[0]; var sel = miniList.SelectedItems[0];
int code = Convert.ToInt32(sel.ImageKey); 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; nudX.Value = ff.width;
nudY.Value = ff.height; nudY.Value = ff.height;
f = ff; f = ff;
@@ -518,7 +529,7 @@ namespace McBitFont {
private void openToolStripMenuItem_Click(object sender, EventArgs e) { private void openToolStripMenuItem_Click(object sender, EventArgs e) {
if (prjModified) { 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(); saveToolStripMenuItem.PerformClick();
return; return;
} }
@@ -548,7 +559,7 @@ namespace McBitFont {
dotResize((int)nudX.Value, (int)nudY.Value); dotResize((int)nudX.Value, (int)nudY.Value);
nudX.ValueChanged += nudX_ValueChanged; nudX.ValueChanged += nudX_ValueChanged;
nudY.ValueChanged += nudY_ValueChanged; nudY.ValueChanged += nudY_ValueChanged;
f = frames.First(); f = copyFrame(frames.First());
dotPanel.Refresh(); dotPanel.Refresh();
miniList.Refresh(); miniList.Refresh();
modified = false; modified = false;
@@ -559,7 +570,6 @@ namespace McBitFont {
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
if (prjModified) { 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) { 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; e.Cancel = true;
} else { } else {
e.Cancel = false; e.Cancel = false;