TODO feature: Undo/Redo for canvas changes
This commit is contained in:
@@ -12,11 +12,13 @@ namespace McBitFont {
|
||||
public int Depth { get; set; }
|
||||
public int Index { get; set; }
|
||||
public int Count {
|
||||
get { return stack.Count; }
|
||||
get { return stack.Count - 1; }
|
||||
}
|
||||
public int Redos {
|
||||
get {
|
||||
return Count - Index - 1;
|
||||
var r = Count - Index - 1;
|
||||
|
||||
return r < 0 ? 0 : r;
|
||||
}
|
||||
}
|
||||
public int Undos {
|
||||
@@ -26,9 +28,9 @@ namespace McBitFont {
|
||||
}
|
||||
|
||||
|
||||
public CanvasHistory(int depth = 5, int index = -1) {
|
||||
public CanvasHistory(int depth = 50) {
|
||||
Depth = depth;
|
||||
Index = index;
|
||||
Index = -1;
|
||||
stack = [];
|
||||
}
|
||||
|
||||
@@ -37,38 +39,47 @@ namespace McBitFont {
|
||||
Index = -1;
|
||||
}
|
||||
|
||||
public void Add(bool[,] data, bool useIndex = true) {
|
||||
public void AddPre(MainForm.FrameMiniature f, bool useIndex = true) {
|
||||
if (Count < 0) stack.Add(new bool[f.width, f.height]);
|
||||
if (Index < Count - 1) {
|
||||
stack.RemoveRange(Index + 1, Count - Index - 1);
|
||||
}
|
||||
stack.Add(data);
|
||||
bool[,] d = new bool[f.width, f.height];
|
||||
Array.Copy(f.data, d, f.data.Length);
|
||||
stack.Insert(Count, d);
|
||||
if (useIndex) {
|
||||
if (Count > Depth) stack.RemoveAt(0);
|
||||
else Index++;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPost(MainForm.FrameMiniature f) {
|
||||
var d = stack.ElementAt(Count);
|
||||
Array.Copy(f.data, d, f.data.Length);
|
||||
}
|
||||
|
||||
public void ApplyAdded() {
|
||||
if (Count > Depth)
|
||||
while (Count > Depth) stack.RemoveAt(0);
|
||||
else Index = Count - 1;
|
||||
while (Count > Depth) stack.RemoveAt(0);
|
||||
Index = Count - 1;
|
||||
}
|
||||
|
||||
public void Remove(bool useIndex = true) {
|
||||
stack.RemoveAt(stack.Count - 1);
|
||||
stack.RemoveAt(Count - 1);
|
||||
if (useIndex) Index--;
|
||||
}
|
||||
|
||||
public void Undo(ref bool[,] data) {
|
||||
public void Undo(MainForm.FrameMiniature f) {
|
||||
if (Index < 0) return;
|
||||
data = stack.ElementAt(Index);
|
||||
var d = stack.ElementAt(Index);
|
||||
Array.Copy(d, f.data, d.Length);
|
||||
Index--;
|
||||
}
|
||||
|
||||
public void Redo(ref bool[,] data) {
|
||||
public void Redo(MainForm.FrameMiniature f) {
|
||||
if (Index >= Count - 1) return;
|
||||
Index++;
|
||||
data = stack.ElementAt(Index);
|
||||
var d = stack.ElementAt(Index + 1);
|
||||
Array.Copy(d, f.data, d.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user