Files
Paint2/Paint_2/PaintToolUtils.cs

107 lines
4.0 KiB
C#

/// file: PaintToolUtils.cs
/// Author: Maxime Rohmer <maxluligames@gmail.com>
/// Brief: A class that groups all the frequently used by painttools methods
/// Version: 0.1.0
/// Date: 08/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<Point> points = new List<Point>();
Target.Drawings.Add(points);
Target.Colors.Add(Target.Color);
Target.Widths.Add(Target.Width);
}
public void StandartClear()
{
Target.Drawings = new List<List<Point>>();
Target.DrawingsRedo = new List<List<Point>>();
Target.Colors = new List<Color>();
Target.ColorsRedo = new List<Color>();
Target.Widths = new List<int>();
Target.WidthsRedo = new List<int>();
}
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<Color> SandartGetLastColors(int colorNumber)
{
List<Color> result = new List<Color>();
//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 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;
}
}
}