/// file: PaintToolUtils.cs /// Author: Maxime Rohmer /// Brief: A class that groups all the frequently used by painttools methods /// 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 PaintToolUtils { private PaintTool Target; private Color DEFAULT_COLOR = Color.FromArgb(59, 59, 59); public PaintToolUtils(PaintTool target) { Target = target; } public void StandartStart(Color color, int width) { Target.Color = color; Target.Width = width; List points = new List(); Target.Drawings.Add(points); Target.Colors.Add(Target.Color); Target.Widths.Add(Target.Width); } public void StandartClear() { Target.Drawings = new List>(); Target.DrawingsRedo = new List>(); Target.Colors = new List(); Target.ColorsRedo = new List(); Target.Widths = new List(); Target.WidthsRedo = new List(); } public void StandartUndo() { int last = Target.Drawings.Count - 1; if (Target.Drawings.Count > 1 && Target.Widths.Count > 1 && Target.Colors.Count > 1) { Target.DrawingsRedo.Add(Target.Drawings[last]); Target.Drawings.RemoveAt(Target.Drawings.Count - 1); Target.ColorsRedo.Add(Target.Colors[last]); Target.Colors.RemoveAt(Target.Colors.Count - 1); Target.WidthsRedo.Add(Target.Widths[last]); Target.Widths.RemoveAt(Target.Widths.Count - 1); } else if (Target.Drawings.Count == 1 && Target.Widths.Count == 1 && Target.Colors.Count == 1) { Target.DrawingsRedo.Add(Target.Drawings[0]); Target.Drawings.Clear(); Target.ColorsRedo.Add(Target.Colors[0]); Target.Colors.Clear(); Target.WidthsRedo.Add(Target.Widths[0]); Target.Widths.Clear(); } } public void StandartRedo() { if (Target.DrawingsRedo.Count > 0 && Target.WidthsRedo.Count > 0 && Target.ColorsRedo.Count > 0) { Target.Drawings.Add(Target.DrawingsRedo[Target.DrawingsRedo.Count - 1]); Target.DrawingsRedo.RemoveAt(Target.DrawingsRedo.Count - 1); Target.Colors.Add(Target.ColorsRedo[Target.ColorsRedo.Count - 1]); Target.ColorsRedo.RemoveAt(Target.ColorsRedo.Count - 1); Target.Widths.Add(Target.WidthsRedo[Target.WidthsRedo.Count - 1]); Target.WidthsRedo.RemoveAt(Target.WidthsRedo.Count - 1); } } public List SandartGetLastColors(int colorNumber) { List result = new List(); //We need to fill with black color for (int i = Target.Colors.Count; i > 0; i--) { Color targetColor = Target.Colors[(Target.Colors.Count) - i]; if (result.Count == 0 || result[result.Count - 1] != targetColor) { result.Add(targetColor); } } for (int i = colorNumber - result.Count; i > 0; i--) { result.Add(DEFAULT_COLOR); } result.Reverse(); return result; } public List ConvertRectangleIntoPositive(bool IsCtrlPressed,Point start, Point end) { Point newStart = new Point(start.X, start.Y); Point newEnd = new Point(end.X, end.Y); int xDiff = end.X - start.X; int yDiff = end.Y - start.Y; Size size = new Size(xDiff, yDiff); if (xDiff < 0) { newStart = new Point(end.X, newStart.Y); } if (yDiff < 0) { newStart = new Point(newStart.X, end.Y); } if (IsCtrlPressed) { size = new Size(Math.Max(Math.Abs(xDiff), Math.Abs(yDiff)), Math.Max(Math.Abs(xDiff), Math.Abs(yDiff))); } newEnd = new Point(newStart.X + Math.Abs(size.Width), newStart.Y + Math.Abs(size.Height)); return new List { newStart, newEnd }; } public Point Lerp(Point start, Point end, float t) { int xDiff = end.X - start.X; int yDiff = end.Y - start.Y; int resultX = start.X + (int)(t * xDiff); int resultY = start.Y + (int)(t * yDiff); Point result = new Point(resultX, resultY); return result; } public string StandartPaintSVG(List> Drawings,List Colors, List Widths) { return "COUCOU"; } } }