176 lines
5.9 KiB
C#
176 lines
5.9 KiB
C#
/// file: DotPencil.cs
|
|
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
|
/// Brief: A variant of the default tool
|
|
/// 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
|
|
{
|
|
public class DotPencil : PaintTool
|
|
{
|
|
const int POST_PROCESSING_PRECISION = 1;
|
|
|
|
private List<List<Point>> _drawings;
|
|
private List<List<Point>> _drawingsRedo;
|
|
private bool _needsFullRefresh;
|
|
private bool _isShiftPressed;
|
|
private bool _isCtrlPressed;
|
|
private PaintToolUtils Utils;
|
|
private List<Color> _colors;
|
|
private List<Color> _colorsRedo;
|
|
private List<int> _widths;
|
|
private List<int> _widthsRedo;
|
|
private Color _color;
|
|
private string _name;
|
|
private int _width;
|
|
|
|
public List<List<Point>> Drawings { get => _drawings; set => _drawings = value; }
|
|
public List<List<Point>> DrawingsRedo { get => _drawingsRedo; set => _drawingsRedo = value; }
|
|
public bool NeedsFullRefresh { get => _needsFullRefresh; set => _needsFullRefresh = value; }
|
|
public bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
|
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = value; }
|
|
public List<Color> Colors { get => _colors; set => _colors = value; }
|
|
public List<Color> ColorsRedo { get => _colorsRedo; set => _colorsRedo = value; }
|
|
public List<int> Widths { get => _widths; set => _widths = value; }
|
|
public List<int> WidthsRedo { get => _widthsRedo; set => _widthsRedo = 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 DotPencil(string name)
|
|
{
|
|
Drawings = new List<List<Point>>();
|
|
DrawingsRedo = new List<List<Point>>();
|
|
Colors = new List<Color>();
|
|
ColorsRedo = new List<Color>();
|
|
Widths = new List<int>();
|
|
WidthsRedo = new List<int>();
|
|
Name = name;
|
|
NeedsFullRefresh = false;
|
|
|
|
Utils = new PaintToolUtils(this);
|
|
}
|
|
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)
|
|
{
|
|
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)
|
|
{
|
|
Utils.StandartStart(color, width);
|
|
}
|
|
public void Clear()
|
|
{
|
|
Utils.StandartClear();
|
|
}
|
|
public void Stop()
|
|
{
|
|
for (int i = 0; i < POST_PROCESSING_PRECISION; i++)
|
|
{
|
|
List<Point> Drawing = Drawings[Drawings.Count - 1];
|
|
Drawings[Drawings.Count - 1] = PostProcessing(Drawing);
|
|
}
|
|
}
|
|
private List<Point> PostProcessing(List<Point> Drawing)
|
|
{
|
|
//THIS SHOULD BE REMOVED, IT IS ONLY HERE TO BE EASIER TO DEBUG THE CONCEPT
|
|
List<Point> NewDrawing = new List<Point>();
|
|
Point previous = new Point(-1, -1);
|
|
//Implementing a post processing
|
|
foreach (Point point in Drawing)
|
|
{
|
|
if (previous != new Point(-1, -1))
|
|
{
|
|
NewDrawing.Add(new Point((previous.X + point.X) / 2, (previous.Y + point.Y) / 2));
|
|
previous = point;
|
|
}
|
|
else
|
|
{
|
|
previous = point;
|
|
}
|
|
NewDrawing.Add(point);
|
|
}
|
|
return NewDrawing;
|
|
}
|
|
public List<Color> 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()
|
|
{
|
|
DotPencil result = new DotPencil(Name);
|
|
result.Width = Width;
|
|
result.Color = Color;
|
|
return (Object)(result);
|
|
}
|
|
|
|
public string PaintSVG()
|
|
{
|
|
string result = "";
|
|
string newLine = Environment.NewLine;
|
|
|
|
for (int drawCount = 0; drawCount < Drawings.Count; drawCount++)
|
|
{
|
|
Point p1;
|
|
Point p2;
|
|
List<Point> 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 += "<ellipse cx=\"" + p2.X + "\" cy=\"" + p2.Y + "\" rx=\"" + width / 2 + "\" ry=\"" + width / 2 + "\" style=\"fill:rgb(" + color.R + ", " + color.G + ", " + color.B + ");\"/>";
|
|
result += newLine;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|