/// file: Pencil.cs /// Author: Maxime Rohmer /// Brief: Paint tool that is kind of the default tool /// Version: 0.1.0 /// Date: 17/06/2022 using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Paint_2 { public class Pencil : PaintTool { const int POST_PROCESSING_PRECISION = 3; private List> _drawings; private List> _drawingsRedo; private PaintToolUtils Utils; private bool _needsFullRefresh; private bool _isShiftPressed; private bool _isCtrlPressed; 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 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 bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; } public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = 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 bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; } public Pencil(string name) { Drawings = new List>(); DrawingsRedo = new List>(); Colors = new List(); ColorsRedo = new List(); Widths = new List(); WidthsRedo = new List(); Name = name; Utils = new PaintToolUtils(this); NeedsFullRefresh = false; } public void Add(Point point) { Drawings[Drawings.Count - 1].Add(point); } public void Paint(Bitmap canvas) { Graphics gr = Graphics.FromImage(canvas); int drawingCounter = 0; Size pointSize; foreach (List drawing in Drawings) { int pointCounter = 0; foreach (Point p in drawing) { pointSize = new Size(Widths[drawingCounter], Widths[drawingCounter]); gr.FillEllipse(new SolidBrush(Colors[drawingCounter]), new Rectangle(new Point(p.X - pointSize.Width / 2, p.Y - pointSize.Height / 2), pointSize)); if (pointCounter > 0) { gr.DrawLine(new Pen(Colors[drawingCounter], Widths[drawingCounter]), drawing[pointCounter - 1], p); } pointCounter += 1; } drawingCounter += 1; } } public string PaintSVG() { string result = ""; string newLine = Environment.NewLine; //foreach (List drawing in Drawings) for (int drawCount = 0; drawCount < Drawings.Count; drawCount++) { Point p1; Point p2; List drawing = Drawings[drawCount]; Color color = Colors[drawCount]; int width = Widths[drawCount]; for (int pointIndex = 0; pointIndex < drawing.Count; pointIndex++) { if (pointIndex >= 1) { p1 = drawing[pointIndex - 1]; p2 = drawing[pointIndex]; result += ""; result += newLine; result += ""; result += newLine; } } } return result; } 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() { Pencil result = new Pencil(Name); result.Width = Width; result.Color = Color; return (Object)(result); } } }