110 lines
3.4 KiB
C#
110 lines
3.4 KiB
C#
/// file: DotPencil.cs
|
|
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
|
/// Brief: A variant of the default tool
|
|
/// Version: 0.1.0
|
|
/// Date: 25/05/2022
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Drawing;
|
|
|
|
namespace Paint_2
|
|
{
|
|
public class DotPencil:PaintTool
|
|
{
|
|
private List<List<Point>> _drawings;
|
|
private List<Color> _colors;
|
|
private List<int> _widths;
|
|
private Color _color;
|
|
private string _name;
|
|
private int _width;
|
|
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
|
public List<Color> Colors { get => _colors; set => _colors = value; }
|
|
public List<int> Widths { get => _widths; set => _widths = value; }
|
|
public Color Color { get => _color; set => _color = value; }
|
|
public int Width { get => _width; set => _width = value; }
|
|
public string Name { get => _name; set => _name = value; }
|
|
|
|
public DotPencil(string name)
|
|
{
|
|
Drawings = new List<List<Point>>();
|
|
Colors = new List<Color>();
|
|
Widths = new List<int>();
|
|
Name = name;
|
|
}
|
|
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<Point> drawing in Drawings)
|
|
{
|
|
int pointCounter = 0;
|
|
foreach (Point p in drawing)
|
|
{
|
|
if (pointCounter > 0)
|
|
{
|
|
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));
|
|
}
|
|
|
|
pointCounter += 1;
|
|
}
|
|
drawingCounter += 1;
|
|
}
|
|
}
|
|
public void Start(Color color, int width)
|
|
{
|
|
Color = color;
|
|
Width = width;
|
|
List<Point> points = new List<Point>();
|
|
Drawings.Add(points);
|
|
Colors.Add(Color);
|
|
Widths.Add(Width);
|
|
}
|
|
public void Clear()
|
|
{
|
|
Drawings = new List<List<Point>>();
|
|
}
|
|
public void Stop(Point point)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
public List<Color> GetLastColors(int colorNumber)
|
|
{
|
|
List<Color> result = new List<Color>();
|
|
if (Colors.Count <= colorNumber)
|
|
{
|
|
//We need to fill with black color
|
|
for (int i = Colors.Count; i > 0; i--)
|
|
{
|
|
result.Add(Colors[(Colors.Count) - i]);
|
|
}
|
|
for (int i = colorNumber - Colors.Count; i > 0; i--)
|
|
{
|
|
result.Add(Color.FromArgb(0x00, 0x00, 0x00));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = colorNumber; i > 0; i--)
|
|
{
|
|
result.Add(Colors[(Colors.Count) - i]);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
public override string ToString()
|
|
{
|
|
return Name;
|
|
}
|
|
}
|
|
}
|