105 lines
3.9 KiB
C#
105 lines
3.9 KiB
C#
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;
|
|
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>();
|
|
if (Target.Colors.Count <= colorNumber)
|
|
{
|
|
//We need to fill with black color
|
|
for (int i = Target.Colors.Count; i > 0; i--)
|
|
{
|
|
result.Add(Target.Colors[(Target.Colors.Count) - i]);
|
|
}
|
|
for (int i = colorNumber - Target.Colors.Count; i > 0; i--)
|
|
{
|
|
result.Add(Color.FromArgb(0x00, 0x00, 0x00));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = colorNumber; i > 0; i--)
|
|
{
|
|
result.Add(Target.Colors[(Target.Colors.Count) - i]);
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|