ljhgfljiukghlkuyfgiyu

This commit is contained in:
2025-06-01 21:18:15 +03:00
parent a05352acf7
commit 1c034fded1
3 changed files with 54 additions and 8 deletions

View File

@@ -31,6 +31,7 @@ namespace McBitFont {
get { return Index < 0 ? Count : Count - Index - 1; }
}
public bool HistoryAction { get; set; } = false;
public bool Doing { get; set; } = false;
// Constructor
public ChangeHistory(MainForm form, int depth = 100) {
@@ -43,6 +44,7 @@ namespace McBitFont {
ResetIndices();
Add();
HistoryAction = false;
Doing = false;
}
private void ResetIndices() {
@@ -157,6 +159,7 @@ namespace McBitFont {
// Add canvas change
public void Add(FrameMiniature f, bool useIndex = true) {
if (Doing) return;
if (useIndex && CheckHistoryAction()) return;
TruncateTail();
@@ -171,6 +174,7 @@ namespace McBitFont {
// Add Font change
public void Add(List<FrameMiniature> ff, bool useIndex = true) {
if (Doing) return;
if (useIndex && CheckHistoryAction()) return;
TruncateTail();
@@ -185,11 +189,13 @@ namespace McBitFont {
timeline.Add(ChangeType.Font);
Index++;
fontIndex++;
Add(mainForm.f);
}
}
// Add Frame selection change
public void Add(int code, bool useIndex = true) {
if (Doing) return;
if (useIndex && CheckHistoryAction()) return;
if (useIndex) {
Add(mainForm.frames.Find(x => x.code == code));
@@ -208,7 +214,8 @@ namespace McBitFont {
}
private void Do(bool undo = true) {
ChangeType ct = timeline.ElementAt(Index + (undo ? 0 : 1));
Doing = true;
var ct = timeline.ElementAt(Index + (undo ? 0 : 1));
int dIndex = undo ? -1 : 1;
switch (ct) {
case ChangeType.Canvas:
@@ -217,6 +224,12 @@ namespace McBitFont {
break;
case ChangeType.Font:
Cursor.Current = Cursors.WaitCursor;
string selItem = "";
int selCode = 0;
if (mainForm.miniList.SelectedItems.Count > 0) {
selItem = mainForm.miniList.SelectedItems[0].Name;
selCode = Convert.ToInt32(selItem);
}
fontIndex += dIndex;
mainForm.frames.Clear();
mainForm.miniList.Clear();
@@ -225,6 +238,18 @@ namespace McBitFont {
mainForm.frames.Add(CopyFrameSimple(f));
}
mainForm.FillFrameLists();
FrameMiniature fff;
if (selItem != "") {
var selection = mainForm.miniList.Items.Find(selItem, false);
if (selection.Length > 0) selection[0].Selected = true;
fff = mainForm.frames.Find(x => x.code == selCode);
} else {
mainForm.miniList.Items[0].Selected = true;
fff = mainForm.frames[0];
}
mainForm.f = mainForm.CopyFrame(fff);
mainForm.nudY.Value = mainForm.dotHeight = fff.height;
mainForm.nudX.Value = mainForm.dotWidth = fff.width;
Cursor.Current = Cursors.Default;
break;
case ChangeType.Frame:
@@ -233,14 +258,34 @@ namespace McBitFont {
var s = selFrameChanges[selFrameIndex].ToString().PadLeft(3, '0');
var sel = mainForm.miniList.Items.Find(s, false);
if (sel.Length > 0) sel[0].Selected = true;
//if (undo) Undo(); else Redo();
break;
break;
default:
break;
}
Index += dIndex;
if (ct == ChangeType.Frame)
if (undo) Undo(); else Redo();
Doing = false;
// Frame select change + Canvas change workarounds
if (ct == ChangeType.Frame && undo) {
Undo();
return;
}
if (Index < Count - 1) {
var nextctframe = timeline.ElementAt(Index + 1) == ChangeType.Frame;
if (ct == ChangeType.Canvas && !undo && nextctframe) {
Redo();
return;
}
}
//Font change + Canvas change workarounds
if (Index >= 0) {
var prevctfont = timeline.ElementAt(Index) == ChangeType.Font;
if (ct == ChangeType.Canvas && undo && prevctfont) {
Undo();
return;
}
}
if (!undo && ct == ChangeType.Font)
Redo();
}
// Undo last change

View File

@@ -1122,8 +1122,6 @@
#endregion
private System.Windows.Forms.Panel dotPanel;
private System.Windows.Forms.NumericUpDown nudX;
private System.Windows.Forms.NumericUpDown nudY;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label lblType;
@@ -1209,6 +1207,8 @@
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
public System.Windows.Forms.ListView miniList;
public System.Windows.Forms.ImageList ilMiniatures;
public System.Windows.Forms.NumericUpDown nudX;
public System.Windows.Forms.NumericUpDown nudY;
}
}

View File

@@ -150,7 +150,7 @@ namespace McBitFont {
return (int)(((ushort)lowPart) | (uint)(highPart << 16));
}
private FrameMiniature CopyFrame(FrameMiniature frame, bool clipboard = false) {
public FrameMiniature CopyFrame(FrameMiniature frame, bool clipboard = false) {
int width = chkRectSelect.Checked && clipboard ? selection2.X - selection1.X + 1 : frame.width;
int height = chkRectSelect.Checked && clipboard ? selection2.Y - selection1.Y + 1 : frame.height;
var ff = new FrameMiniature(frame.code, width, height);
@@ -236,6 +236,7 @@ namespace McBitFont {
}
DotResize(dotWidth, (int)nudY.Value);
history.Add(frames);
Cursor.Current = Cursors.Default;
}