Added Redo feature
This commit is contained in:
@@ -15,23 +15,33 @@ namespace Paint_2
|
|||||||
public class DotPencil:PaintTool
|
public class DotPencil:PaintTool
|
||||||
{
|
{
|
||||||
private List<List<Point>> _drawings;
|
private List<List<Point>> _drawings;
|
||||||
|
private List<List<Point>> _drawingsRedo;
|
||||||
private List<Color> _colors;
|
private List<Color> _colors;
|
||||||
|
private List<Color> _colorsRedo;
|
||||||
private List<int> _widths;
|
private List<int> _widths;
|
||||||
|
private List<int> _widthsRedo;
|
||||||
private Color _color;
|
private Color _color;
|
||||||
private string _name;
|
private string _name;
|
||||||
private int _width;
|
private int _width;
|
||||||
|
|
||||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||||
|
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||||
|
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||||
|
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; }
|
||||||
public Color Color { get => _color; set => _color = value; }
|
public Color Color { get => _color; set => _color = value; }
|
||||||
public int Width { get => _width; set => _width = value; }
|
|
||||||
public string Name { get => _name; set => _name = value; }
|
public string Name { get => _name; set => _name = value; }
|
||||||
|
public int Width { get => _width; set => _width = value; }
|
||||||
|
|
||||||
public DotPencil(string name)
|
public DotPencil(string name)
|
||||||
{
|
{
|
||||||
Drawings = new List<List<Point>>();
|
Drawings = new List<List<Point>>();
|
||||||
|
DrawingsRedo = new List<List<Point>>();
|
||||||
Colors = new List<Color>();
|
Colors = new List<Color>();
|
||||||
|
ColorsRedo = new List<Color>();
|
||||||
Widths = new List<int>();
|
Widths = new List<int>();
|
||||||
|
WidthsRedo = new List<int>();
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
public void Add(Point point)
|
public void Add(Point point)
|
||||||
@@ -108,18 +118,38 @@ namespace Paint_2
|
|||||||
|
|
||||||
public void Undo()
|
public void Undo()
|
||||||
{
|
{
|
||||||
|
int last = Drawings.Count - 1;
|
||||||
if (Drawings.Count > 1)
|
if (Drawings.Count > 1)
|
||||||
{
|
{
|
||||||
|
DrawingsRedo.Add(Drawings[last]);
|
||||||
Drawings.RemoveAt(Drawings.Count - 1);
|
Drawings.RemoveAt(Drawings.Count - 1);
|
||||||
|
ColorsRedo.Add(Colors[last]);
|
||||||
Colors.RemoveAt(Colors.Count - 1);
|
Colors.RemoveAt(Colors.Count - 1);
|
||||||
|
WidthsRedo.Add(Widths[last]);
|
||||||
Widths.RemoveAt(Widths.Count - 1);
|
Widths.RemoveAt(Widths.Count - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
DrawingsRedo.Add(Drawings[0]);
|
||||||
Drawings.Clear();
|
Drawings.Clear();
|
||||||
|
ColorsRedo.Add(Colors[0]);
|
||||||
Colors.Clear();
|
Colors.Clear();
|
||||||
|
WidthsRedo.Add(Widths[0]);
|
||||||
Widths.Clear();
|
Widths.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Redo()
|
||||||
|
{
|
||||||
|
if (DrawingsRedo.Count > 0 && WidthsRedo.Count > 0 && ColorsRedo.Count > 0)
|
||||||
|
{
|
||||||
|
Drawings.Add(DrawingsRedo[DrawingsRedo.Count - 1]);
|
||||||
|
DrawingsRedo.RemoveAt(DrawingsRedo.Count - 1);
|
||||||
|
Colors.Add(ColorsRedo[ColorsRedo.Count - 1]);
|
||||||
|
ColorsRedo.RemoveAt(ColorsRedo.Count - 1);
|
||||||
|
Widths.Add(WidthsRedo[WidthsRedo.Count - 1]);
|
||||||
|
WidthsRedo.RemoveAt(WidthsRedo.Count - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
Paint_2/Form1.Designer.cs
generated
19
Paint_2/Form1.Designer.cs
generated
@@ -74,6 +74,7 @@
|
|||||||
this.label2 = new System.Windows.Forms.Label();
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
this.lsbTools = new System.Windows.Forms.ListBox();
|
this.lsbTools = new System.Windows.Forms.ListBox();
|
||||||
this.btnUndo = new System.Windows.Forms.Button();
|
this.btnUndo = new System.Windows.Forms.Button();
|
||||||
|
this.btnRedo = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit();
|
||||||
this.panelFile.SuspendLayout();
|
this.panelFile.SuspendLayout();
|
||||||
this.panelDrawing.SuspendLayout();
|
this.panelDrawing.SuspendLayout();
|
||||||
@@ -574,6 +575,7 @@
|
|||||||
//
|
//
|
||||||
this.panelTools.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
this.panelTools.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.panelTools.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31)))));
|
this.panelTools.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31)))));
|
||||||
|
this.panelTools.Controls.Add(this.btnRedo);
|
||||||
this.panelTools.Controls.Add(this.btnUndo);
|
this.panelTools.Controls.Add(this.btnUndo);
|
||||||
this.panelTools.Controls.Add(this.btnRandomColor);
|
this.panelTools.Controls.Add(this.btnRandomColor);
|
||||||
this.panelTools.Controls.Add(this.label2);
|
this.panelTools.Controls.Add(this.label2);
|
||||||
@@ -646,12 +648,26 @@
|
|||||||
this.btnUndo.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214)))));
|
this.btnUndo.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214)))));
|
||||||
this.btnUndo.Location = new System.Drawing.Point(3, 547);
|
this.btnUndo.Location = new System.Drawing.Point(3, 547);
|
||||||
this.btnUndo.Name = "btnUndo";
|
this.btnUndo.Name = "btnUndo";
|
||||||
this.btnUndo.Size = new System.Drawing.Size(157, 43);
|
this.btnUndo.Size = new System.Drawing.Size(75, 43);
|
||||||
this.btnUndo.TabIndex = 35;
|
this.btnUndo.TabIndex = 35;
|
||||||
this.btnUndo.Text = "Undo";
|
this.btnUndo.Text = "Undo";
|
||||||
this.btnUndo.UseVisualStyleBackColor = false;
|
this.btnUndo.UseVisualStyleBackColor = false;
|
||||||
this.btnUndo.Click += new System.EventHandler(this.btnUndo_Click);
|
this.btnUndo.Click += new System.EventHandler(this.btnUndo_Click);
|
||||||
//
|
//
|
||||||
|
// btnRedo
|
||||||
|
//
|
||||||
|
this.btnRedo.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(41)))), ((int)(((byte)(41)))), ((int)(((byte)(41)))));
|
||||||
|
this.btnRedo.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
||||||
|
this.btnRedo.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
|
this.btnRedo.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214)))));
|
||||||
|
this.btnRedo.Location = new System.Drawing.Point(85, 547);
|
||||||
|
this.btnRedo.Name = "btnRedo";
|
||||||
|
this.btnRedo.Size = new System.Drawing.Size(75, 43);
|
||||||
|
this.btnRedo.TabIndex = 36;
|
||||||
|
this.btnRedo.Text = "Redo";
|
||||||
|
this.btnRedo.UseVisualStyleBackColor = false;
|
||||||
|
this.btnRedo.Click += new System.EventHandler(this.btnRedo_Click);
|
||||||
|
//
|
||||||
// PaintForm
|
// PaintForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F);
|
||||||
@@ -739,6 +755,7 @@
|
|||||||
private System.Windows.Forms.Label lblWidth;
|
private System.Windows.Forms.Label lblWidth;
|
||||||
private System.Windows.Forms.Button btnRandomColor;
|
private System.Windows.Forms.Button btnRandomColor;
|
||||||
private System.Windows.Forms.Button btnUndo;
|
private System.Windows.Forms.Button btnUndo;
|
||||||
|
private System.Windows.Forms.Button btnRedo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -253,5 +253,11 @@ namespace Paint_2
|
|||||||
sketch.Undo();
|
sketch.Undo();
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnRedo_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
sketch.Redo();
|
||||||
|
ForceRefresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,12 @@ namespace Paint_2
|
|||||||
internal interface PaintTool
|
internal interface PaintTool
|
||||||
{
|
{
|
||||||
List<List<Point>> Drawings { get; set; }
|
List<List<Point>> Drawings { get; set; }
|
||||||
|
List<List<Point>> DrawingsRedo { get; set; }
|
||||||
List<Color> Colors { get; set; }
|
List<Color> Colors { get; set; }
|
||||||
|
List<Color> ColorsRedo { get; set; }
|
||||||
Color Color { get; set; }
|
Color Color { get; set; }
|
||||||
List<int> Widths { get; set; }
|
List<int> Widths { get; set; }
|
||||||
|
List<int> WidthsRedo { get; set; }
|
||||||
int Width { get; set; }
|
int Width { get; set; }
|
||||||
string Name { get; set; }
|
string Name { get; set; }
|
||||||
|
|
||||||
@@ -25,6 +28,7 @@ namespace Paint_2
|
|||||||
void Stop(Point point);
|
void Stop(Point point);
|
||||||
void Add(Point point);
|
void Add(Point point);
|
||||||
void Undo();
|
void Undo();
|
||||||
|
void Redo();
|
||||||
void Clear();
|
void Clear();
|
||||||
List<Color> GetLastColors(int colorNumber);
|
List<Color> GetLastColors(int colorNumber);
|
||||||
void Paint(Bitmap canvas);
|
void Paint(Bitmap canvas);
|
||||||
|
|||||||
@@ -15,23 +15,33 @@ namespace Paint_2
|
|||||||
internal class Pencil : PaintTool
|
internal class Pencil : PaintTool
|
||||||
{
|
{
|
||||||
private List<List<Point>> _drawings;
|
private List<List<Point>> _drawings;
|
||||||
|
private List<List<Point>> _drawingsRedo;
|
||||||
private List<Color> _colors;
|
private List<Color> _colors;
|
||||||
|
private List<Color> _colorsRedo;
|
||||||
private List<int> _widths;
|
private List<int> _widths;
|
||||||
|
private List<int> _widthsRedo;
|
||||||
private Color _color;
|
private Color _color;
|
||||||
private string _name;
|
private string _name;
|
||||||
private int _width;
|
private int _width;
|
||||||
|
|
||||||
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
||||||
|
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
||||||
public List<Color> Colors { get => _colors; set => _colors = value; }
|
public List<Color> Colors { get => _colors; set => _colors = value; }
|
||||||
|
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
||||||
public List<int> Widths { get => _widths; set => _widths = value; }
|
public List<int> Widths { get => _widths; set => _widths = value; }
|
||||||
|
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; }
|
||||||
public Color Color { get => _color; set => _color = value; }
|
public Color Color { get => _color; set => _color = value; }
|
||||||
public int Width { get => _width; set => _width = value; }
|
|
||||||
public string Name { get => _name; set => _name = value; }
|
public string Name { get => _name; set => _name = value; }
|
||||||
|
public int Width { get => _width; set => _width = value; }
|
||||||
|
|
||||||
public Pencil(string name)
|
public Pencil(string name)
|
||||||
{
|
{
|
||||||
Drawings = new List<List<Point>>();
|
Drawings = new List<List<Point>>();
|
||||||
|
DrawingsRedo = new List<List<Point>>();
|
||||||
Colors = new List<Color>();
|
Colors = new List<Color>();
|
||||||
|
ColorsRedo = new List<Color>();
|
||||||
Widths = new List<int>();
|
Widths = new List<int>();
|
||||||
|
WidthsRedo = new List<int>();
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
public void Add(Point point)
|
public void Add(Point point)
|
||||||
@@ -109,18 +119,38 @@ namespace Paint_2
|
|||||||
|
|
||||||
public void Undo()
|
public void Undo()
|
||||||
{
|
{
|
||||||
|
int last = Drawings.Count - 1;
|
||||||
if (Drawings.Count > 1)
|
if (Drawings.Count > 1)
|
||||||
{
|
{
|
||||||
|
DrawingsRedo.Add(Drawings[last]);
|
||||||
Drawings.RemoveAt(Drawings.Count -1);
|
Drawings.RemoveAt(Drawings.Count -1);
|
||||||
|
ColorsRedo.Add(Colors[last]);
|
||||||
Colors.RemoveAt(Colors.Count -1);
|
Colors.RemoveAt(Colors.Count -1);
|
||||||
|
WidthsRedo.Add(Widths[last]);
|
||||||
Widths.RemoveAt(Widths.Count -1);
|
Widths.RemoveAt(Widths.Count -1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
DrawingsRedo.Add(Drawings[0]);
|
||||||
Drawings.Clear();
|
Drawings.Clear();
|
||||||
|
ColorsRedo.Add(Colors[0]);
|
||||||
Colors.Clear();
|
Colors.Clear();
|
||||||
|
WidthsRedo.Add(Widths[0]);
|
||||||
Widths.Clear();
|
Widths.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Redo()
|
||||||
|
{
|
||||||
|
if (DrawingsRedo.Count > 0 && WidthsRedo.Count > 0 && ColorsRedo.Count > 0)
|
||||||
|
{
|
||||||
|
Drawings.Add(DrawingsRedo[DrawingsRedo.Count -1]);
|
||||||
|
DrawingsRedo.RemoveAt(DrawingsRedo.Count - 1);
|
||||||
|
Colors.Add(ColorsRedo[ColorsRedo.Count -1]);
|
||||||
|
ColorsRedo.RemoveAt(ColorsRedo.Count - 1);
|
||||||
|
Widths.Add(WidthsRedo[WidthsRedo.Count -1]);
|
||||||
|
WidthsRedo.RemoveAt(WidthsRedo.Count - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ namespace Paint_2
|
|||||||
{
|
{
|
||||||
CurrentTool.Undo();
|
CurrentTool.Undo();
|
||||||
}
|
}
|
||||||
|
public void Redo()
|
||||||
|
{
|
||||||
|
CurrentTool.Redo();
|
||||||
|
}
|
||||||
public void StartDrawing(Point location,Color color,int width)
|
public void StartDrawing(Point location,Color color,int width)
|
||||||
{
|
{
|
||||||
CurrentTool.Start(color,width);
|
CurrentTool.Start(color,width);
|
||||||
|
|||||||
Reference in New Issue
Block a user