From dfc8ca24dd992fe69301d82ff214e939e1ffc28e Mon Sep 17 00:00:00 2001 From: maxluli Date: Fri, 17 Jun 2022 13:51:51 +0200 Subject: [PATCH] Added new tools and their preview --- Paint_2/BezierPencil.cs | 2 +- Paint_2/DotPencil.cs | 2 +- Paint_2/EllipseBorderPencil.cs | 154 +++++++++++++++++++++++++++++++ Paint_2/EllipsePencil.cs | 153 ++++++++++++++++++++++++++++++ Paint_2/Form1.cs | 23 ++++- Paint_2/PaintTool.cs | 2 +- Paint_2/PaintToolUtils.cs | 2 +- Paint_2/Paint_2.csproj | 3 + Paint_2/Pencil.cs | 2 +- Paint_2/Project.cs | 14 ++- Paint_2/RectangleBorderPencil.cs | 154 +++++++++++++++++++++++++++++++ Paint_2/RectanglePencil.cs | 7 +- Paint_2/Sketch.cs | 4 +- 13 files changed, 506 insertions(+), 16 deletions(-) create mode 100644 Paint_2/EllipseBorderPencil.cs create mode 100644 Paint_2/EllipsePencil.cs create mode 100644 Paint_2/RectangleBorderPencil.cs diff --git a/Paint_2/BezierPencil.cs b/Paint_2/BezierPencil.cs index cd0fe98..9d26647 100644 --- a/Paint_2/BezierPencil.cs +++ b/Paint_2/BezierPencil.cs @@ -2,7 +2,7 @@ /// Author: Maxime Rohmer /// Brief: A unique tool that draws Bezier curves /// Version: 0.1.0 -/// Date: 08/06/2022 +/// Date: 17/06/2022 using System; using System.Collections.Generic; diff --git a/Paint_2/DotPencil.cs b/Paint_2/DotPencil.cs index 50eb057..18504a8 100644 --- a/Paint_2/DotPencil.cs +++ b/Paint_2/DotPencil.cs @@ -2,7 +2,7 @@ /// Author: Maxime Rohmer /// Brief: A variant of the default tool /// Version: 0.1.0 -/// Date: 08/06/2022 +/// Date: 17/06/2022 using System; using System.Collections.Generic; diff --git a/Paint_2/EllipseBorderPencil.cs b/Paint_2/EllipseBorderPencil.cs new file mode 100644 index 0000000..2d5e88d --- /dev/null +++ b/Paint_2/EllipseBorderPencil.cs @@ -0,0 +1,154 @@ +/// file: EllipseBorderPencil.cs +/// Author: Maxime Rohmer +/// Brief: A tool that paints the outline of an ellipse +/// Version: 0.1.0 +/// Date: 17/06/2022 + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; + +namespace Paint_2 +{ + internal class EllipseBorderPencil:PaintTool + { + private List> _drawings; + private List> _drawingsRedo; + private bool _needsFullRefresh; + private PaintToolUtils Utils; + private List _colors; + private List _colorsRedo; + private List _widths; + private List _widthsRedo; + private Color _color; + private string _name; + private int _width; + + public List> Drawings { get => _drawings; set => _drawings = value; } + public List> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; } + public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; } + public List Colors { get => _colors; set => _colors = value; } + public List ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; } + public List Widths { get => _widths; set => _widths = value; } + public List WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; } + public Color Color { get => _color; set => _color = value; } + public string Name { get => _name; set => _name = value; } + public int Width { get => _width; set => _width = value; } + + public EllipseBorderPencil(string name) + { + NeedsFullRefresh = true; + Drawings = new List>(); + DrawingsRedo = new List>(); + Colors = new List(); + ColorsRedo = new List(); + Widths = new List(); + WidthsRedo = new List(); + Name = name; + Utils = new PaintToolUtils(this); + } + public void Add(Point point) + { + List myDrawing = Drawings[Drawings.Count - 1]; + if (myDrawing.Count == 0 || myDrawing.Count == 1) + { + myDrawing.Add(point); + } + else + { + myDrawing[1] = point; + } + Drawings[Drawings.Count - 1] = myDrawing; + } + public void Paint(Bitmap canvas) + { + Graphics gr = Graphics.FromImage(canvas); + int drawingCounter = 0; + Size pointSize; + + foreach (List drawing in Drawings) + { + if (drawing.Count == 2) + { + Point p1 = drawing[0]; + Point p2 = drawing[1]; + + Point start = new Point(0, 0); + Point end = new Point(0, 0); + + if (p2.X > p1.X) + { + start.X = p1.X; + end.X = p2.X; + } + else + { + start.X = p2.X; + end.X = p1.X; + } + if (p2.Y > p1.Y) + { + start.Y = p1.Y; + end.Y = p2.Y; + } + else + { + start.Y = p2.Y; + end.Y = p1.Y; + } + + gr.DrawEllipse(new Pen(Colors[drawingCounter], Widths[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y))); + } + drawingCounter++; + } + } + public void Start(Color color, int width) + { + Utils.StandartStart(color, width); + } + public void Clear() + { + Utils.StandartClear(); + } + public void Stop() + { + for (int i = 0; i < Drawings.Count; i++) + { + List Drawing = Drawings[i]; + } + } + private Bitmap PostProcessing(List Drawing, Bitmap bmp, int width, Color color) + { + return bmp; + } + public List GetLastColors(int colorNumber) + { + return Utils.SandartGetLastColors(colorNumber); + } + public override string ToString() + { + return Name; + } + + public void Undo() + { + Utils.StandartUndo(); + } + + public void Redo() + { + Utils.StandartRedo(); + } + + public object Clone() + { + EllipseBorderPencil result = new EllipseBorderPencil(Name); + result.Width = Width; + result.Color = Color; + return (Object)(result); + } + } +} diff --git a/Paint_2/EllipsePencil.cs b/Paint_2/EllipsePencil.cs new file mode 100644 index 0000000..e934dd1 --- /dev/null +++ b/Paint_2/EllipsePencil.cs @@ -0,0 +1,153 @@ +/// file: EllipsePencil.cs +/// Author: Maxime Rohmer +/// Brief: A tool that paints an ellipse +/// Version: 0.1.0 +/// Date: 17/06/2022 +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; + +namespace Paint_2 +{ + internal class EllipsePencil : PaintTool + { + private List> _drawings; + private List> _drawingsRedo; + private bool _needsFullRefresh; + private PaintToolUtils Utils; + private List _colors; + private List _colorsRedo; + private List _widths; + private List _widthsRedo; + private Color _color; + private string _name; + private int _width; + + public List> Drawings { get => _drawings; set => _drawings = value; } + public List> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; } + public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; } + public List Colors { get => _colors; set => _colors = value; } + public List ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; } + public List Widths { get => _widths; set => _widths = value; } + public List WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; } + public Color Color { get => _color; set => _color = value; } + public string Name { get => _name; set => _name = value; } + public int Width { get => _width; set => _width = value; } + + public EllipsePencil(string name) + { + NeedsFullRefresh = true; + Drawings = new List>(); + DrawingsRedo = new List>(); + Colors = new List(); + ColorsRedo = new List(); + Widths = new List(); + WidthsRedo = new List(); + Name = name; + Utils = new PaintToolUtils(this); + } + public void Add(Point point) + { + List myDrawing = Drawings[Drawings.Count - 1]; + if (myDrawing.Count == 0 || myDrawing.Count == 1) + { + myDrawing.Add(point); + } + else + { + myDrawing[1] = point; + } + Drawings[Drawings.Count - 1] = myDrawing; + } + public void Paint(Bitmap canvas) + { + Graphics gr = Graphics.FromImage(canvas); + int drawingCounter = 0; + Size pointSize; + + foreach (List drawing in Drawings) + { + if (drawing.Count == 2) + { + Point p1 = drawing[0]; + Point p2 = drawing[1]; + + Point start = new Point(0, 0); + Point end = new Point(0, 0); + + if (p2.X > p1.X) + { + start.X = p1.X; + end.X = p2.X; + } + else + { + start.X = p2.X; + end.X = p1.X; + } + if (p2.Y > p1.Y) + { + start.Y = p1.Y; + end.Y = p2.Y; + } + else + { + start.Y = p2.Y; + end.Y = p1.Y; + } + + gr.FillEllipse(new SolidBrush(Colors[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y))); + } + drawingCounter++; + } + } + public void Start(Color color, int width) + { + Utils.StandartStart(color, width); + } + public void Clear() + { + Utils.StandartClear(); + } + public void Stop() + { + for (int i = 0; i < Drawings.Count; i++) + { + List Drawing = Drawings[i]; + } + } + private Bitmap PostProcessing(List Drawing, Bitmap bmp, int width, Color color) + { + return bmp; + } + public List GetLastColors(int colorNumber) + { + return Utils.SandartGetLastColors(colorNumber); + } + public override string ToString() + { + return Name; + } + + public void Undo() + { + Utils.StandartUndo(); + } + + public void Redo() + { + Utils.StandartRedo(); + } + + public object Clone() + { + EllipsePencil result = new EllipsePencil(Name); + result.Width = Width; + result.Color = Color; + return (Object)(result); + } + } +} diff --git a/Paint_2/Form1.cs b/Paint_2/Form1.cs index b1f043a..e6a0d9e 100644 --- a/Paint_2/Form1.cs +++ b/Paint_2/Form1.cs @@ -2,7 +2,7 @@ /// Author: Maxime Rohmer /// Brief: Class that is controlling the view /// Version: 0.1.0 -/// Date: 08/06/2022 +/// Date: 17/06/2022 using System; using System.Collections.Generic; @@ -156,11 +156,14 @@ namespace Paint_2 if (Project.GetCurrentTool(SelectedLayers) != null) { PaintTool currentTool = (PaintTool)Project.GetCurrentTool(SelectedLayers).Clone(); + Color paint_tool_color = Project.GetCurrentToolColor(SelectedLayers); + int paint_tool_width = Project.GetCurrentToolWidth(SelectedLayers); + //Would have loved to use a switch case but I cant if (currentTool is Pencil) { Pencil pencil = currentTool as Pencil; - pencil.Start(Project.GetCurrentToolColor(SelectedLayers), Project.GetCurrentToolWidth(SelectedLayers)); + pencil.Start(paint_tool_color, paint_tool_width); pencil.Add(new Point(0, size.Height)); pencil.Add(new Point(size.Width, 0)); pencil.Stop(); @@ -171,7 +174,7 @@ namespace Paint_2 if (currentTool is DotPencil) { DotPencil pencil = currentTool as DotPencil; - pencil.Start(Project.GetCurrentToolColor(SelectedLayers), Project.GetCurrentToolWidth(SelectedLayers)); + pencil.Start(paint_tool_color,paint_tool_width); int precision = 5; for (int i = 0; i <= precision; i++) { @@ -186,8 +189,6 @@ namespace Paint_2 if (currentTool is BezierPencil) { BezierPencil pencil = currentTool as BezierPencil; - Color paint_tool_color = Project.GetCurrentToolColor(SelectedLayers); - int paint_tool_width = Project.GetCurrentToolWidth(SelectedLayers); Point p1 = new Point(0 - paint_tool_width / 2, 0 - paint_tool_width / 2); Point p2 = new Point(0 - paint_tool_width / 2, size.Height + paint_tool_width / 2); @@ -216,6 +217,18 @@ namespace Paint_2 pencil.Stop(); pencil.Paint(map); } + else + { + if (currentTool is RectanglePencil || currentTool is RectangleBorderPencil || currentTool is EllipsePencil || currentTool is EllipseBorderPencil) + { + currentTool.Start(paint_tool_color,paint_tool_width); + currentTool.Add(new Point(0 + size.Width / 10,0 + size.Height / 10)); + currentTool.Add(new Point(size.Width - size.Width / 10, size.Height - size.Height / 10)); + currentTool.Stop(); + + currentTool.Paint(map); + } + } } } } diff --git a/Paint_2/PaintTool.cs b/Paint_2/PaintTool.cs index 4ddf8f5..934f2a3 100644 --- a/Paint_2/PaintTool.cs +++ b/Paint_2/PaintTool.cs @@ -2,7 +2,7 @@ /// Author: Maxime Rohmer /// Brief: Interface that is here to define what is a paint tool /// Version: 0.1.0 -/// Date: 08/06/2022 +/// Date: 17/06/2022 using System; using System.Collections.Generic; diff --git a/Paint_2/PaintToolUtils.cs b/Paint_2/PaintToolUtils.cs index f7bb2ae..2eb24d7 100644 --- a/Paint_2/PaintToolUtils.cs +++ b/Paint_2/PaintToolUtils.cs @@ -2,7 +2,7 @@ /// Author: Maxime Rohmer /// Brief: A class that groups all the frequently used by painttools methods /// Version: 0.1.0 -/// Date: 08/06/2022 +/// Date: 17/06/2022 using System; using System.Collections.Generic; diff --git a/Paint_2/Paint_2.csproj b/Paint_2/Paint_2.csproj index ba90cc9..daa5196 100644 --- a/Paint_2/Paint_2.csproj +++ b/Paint_2/Paint_2.csproj @@ -54,6 +54,8 @@ ColorPicker.cs + + Form @@ -66,6 +68,7 @@ + diff --git a/Paint_2/Pencil.cs b/Paint_2/Pencil.cs index 599c45e..30e7c96 100644 --- a/Paint_2/Pencil.cs +++ b/Paint_2/Pencil.cs @@ -2,7 +2,7 @@ /// Author: Maxime Rohmer /// Brief: Paint tool that is kind of the default tool /// Version: 0.1.0 -/// Date: 08/06/2022 +/// Date: 17/06/2022 using System; using System.Collections.Generic; diff --git a/Paint_2/Project.cs b/Paint_2/Project.cs index f3e5429..cccf3c2 100644 --- a/Paint_2/Project.cs +++ b/Paint_2/Project.cs @@ -1,4 +1,9 @@ -using System; +/// file: Project.cs +/// Author: Maxime Rohmer +/// Brief: A controller that manipulates that gives the view all the info it needs and controlls the layers and tools +/// Version: 0.1.0 +/// Date: 17/06/2022 +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -46,9 +51,12 @@ namespace Paint_2 AvaibleTools.Add(new Pencil("Default Pencil")); AvaibleTools.Add(new DotPencil("Dotted Line")); AvaibleTools.Add(new BezierPencil("Bezier Generator")); - AvaibleTools.Add(new RectanglePencil("Rectangle tool")); + AvaibleTools.Add(new RectanglePencil("Box tool")); + AvaibleTools.Add(new RectangleBorderPencil("Rectangle tool")); + AvaibleTools.Add(new EllipsePencil("Ball tool")); + AvaibleTools.Add(new EllipseBorderPencil("Ellipse tool")); //We create a single first layer with the default toolSet - + Layers = new List(); LayersToPrint = new List(); diff --git a/Paint_2/RectangleBorderPencil.cs b/Paint_2/RectangleBorderPencil.cs new file mode 100644 index 0000000..a0895e2 --- /dev/null +++ b/Paint_2/RectangleBorderPencil.cs @@ -0,0 +1,154 @@ +/// file: RectangleBorderPencil.cs +/// Author: Maxime Rohmer +/// Brief: A tool that paints the outline of a rectangle +/// Version: 0.1.0 +/// Date: 17/06/2022 +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; + +namespace Paint_2 +{ + internal class RectangleBorderPencil:PaintTool + { + private List> _drawings; + private List> _drawingsRedo; + private bool _needsFullRefresh; + private PaintToolUtils Utils; + private List _colors; + private List _colorsRedo; + private List _widths; + private List _widthsRedo; + private Color _color; + private string _name; + private int _width; + + public List> Drawings { get => _drawings; set => _drawings = value; } + public List> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; } + public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; } + public List Colors { get => _colors; set => _colors = value; } + public List ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; } + public List Widths { get => _widths; set => _widths = value; } + public List WidthsRedo { get => _widthsRedo; set => _widthsRedo = value; } + public Color Color { get => _color; set => _color = value; } + public string Name { get => _name; set => _name = value; } + public int Width { get => _width; set => _width = value; } + + public RectangleBorderPencil(string name) + { + NeedsFullRefresh = true; + Drawings = new List>(); + DrawingsRedo = new List>(); + Colors = new List(); + ColorsRedo = new List(); + Widths = new List(); + WidthsRedo = new List(); + Name = name; + Utils = new PaintToolUtils(this); + } + public void Add(Point point) + { + List myDrawing = Drawings[Drawings.Count - 1]; + if (myDrawing.Count == 0 || myDrawing.Count == 1) + { + myDrawing.Add(point); + } + else + { + myDrawing[1] = point; + } + Drawings[Drawings.Count - 1] = myDrawing; + } + public void Paint(Bitmap canvas) + { + Graphics gr = Graphics.FromImage(canvas); + int drawingCounter = 0; + Size pointSize; + + foreach (List drawing in Drawings) + { + if (drawing.Count == 2) + { + Point p1 = drawing[0]; + Point p2 = drawing[1]; + + Point start = new Point(0, 0); + Point end = new Point(0, 0); + + if (p2.X > p1.X) + { + start.X = p1.X; + end.X = p2.X; + } + else + { + start.X = p2.X; + end.X = p1.X; + } + if (p2.Y > p1.Y) + { + start.Y = p1.Y; + end.Y = p2.Y; + } + else + { + start.Y = p2.Y; + end.Y = p1.Y; + } + + gr.DrawRectangle(new Pen(Colors[drawingCounter], Widths[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y))); + } + drawingCounter++; + } + } + public void Start(Color color, int width) + { + Utils.StandartStart(color, width); + } + public void Clear() + { + Utils.StandartClear(); + } + public void Stop() + { + for (int i = 0; i < Drawings.Count; i++) + { + List Drawing = Drawings[i]; + } + } + private Bitmap PostProcessing(List Drawing, Bitmap bmp, int width, Color color) + { + return bmp; + } + public List GetLastColors(int colorNumber) + { + return Utils.SandartGetLastColors(colorNumber); + } + public override string ToString() + { + return Name; + } + + public void Undo() + { + Utils.StandartUndo(); + } + + public void Redo() + { + Utils.StandartRedo(); + } + + public object Clone() + { + RectangleBorderPencil result = new RectangleBorderPencil(Name); + result.Width = Width; + result.Color = Color; + return (Object)(result); + } + } +} + diff --git a/Paint_2/RectanglePencil.cs b/Paint_2/RectanglePencil.cs index b4a71f1..8750a58 100644 --- a/Paint_2/RectanglePencil.cs +++ b/Paint_2/RectanglePencil.cs @@ -1,4 +1,9 @@ -using System; +/// file: RectanglePencil.cs +/// Author: Maxime Rohmer +/// Brief: A tool that paints a Rectangle +/// Version: 0.1.0 +/// Date: 17/06/2022 +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/Paint_2/Sketch.cs b/Paint_2/Sketch.cs index 22f6fc9..f95d22a 100644 --- a/Paint_2/Sketch.cs +++ b/Paint_2/Sketch.cs @@ -1,8 +1,8 @@ /// file: Sketch.cs /// Author: Maxime Rohmer -/// Brief: Class that is used to store and controll the tools and the bitmap +/// Brief: This is a layer wich can controll a set of tools and is controlled by the Project /// Version: 0.1.0 -/// Date: 08/06/2022 +/// Date: 17/06/2022 using System; using System.Collections.Generic;