178 lines
6.2 KiB
C#
178 lines
6.2 KiB
C#
/// file: RectangleBorderPencil.cs
|
|
/// Author: Maxime Rohmer <maxluligames@gmail.com>
|
|
/// Brief: A tool that paints the outline of a rectangle
|
|
/// 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 RectangleBorderPencil:PaintTool
|
|
{
|
|
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 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 bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
|
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = 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 RectangleBorderPencil(string name)
|
|
{
|
|
NeedsFullRefresh = true;
|
|
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;
|
|
Utils = new PaintToolUtils(this);
|
|
}
|
|
public void Add(Point point)
|
|
{
|
|
List<Point> myDrawing = Drawings[Drawings.Count - 1];
|
|
if (myDrawing.Count == 0 || myDrawing.Count == 1)
|
|
{
|
|
myDrawing.Add(point);
|
|
}
|
|
else
|
|
{
|
|
myDrawing[1] = point;
|
|
}
|
|
Drawings[Drawings.Count - 1] = myDrawing;
|
|
}
|
|
public void Paint(Bitmap canvas)
|
|
{
|
|
Graphics gr = Graphics.FromImage(canvas);
|
|
int drawingCounter = 0;
|
|
Size pointSize;
|
|
|
|
foreach (List<Point> drawing in Drawings)
|
|
{
|
|
if (drawing.Count == 2)
|
|
{
|
|
Point start = drawing[0];
|
|
Point end = drawing[1];
|
|
|
|
List<Point> points;
|
|
if (drawingCounter == Drawings.Count - 1)
|
|
{
|
|
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
|
}
|
|
else
|
|
{
|
|
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
|
}
|
|
|
|
start = points[0];
|
|
end = points[1];
|
|
|
|
gr.DrawRectangle(new Pen(Colors[drawingCounter], Widths[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y)));
|
|
}
|
|
drawingCounter++;
|
|
}
|
|
}
|
|
public string PaintSVG()
|
|
{
|
|
string result = "";
|
|
string newLine = Environment.NewLine;
|
|
|
|
int drawingCounter = 0;
|
|
Size pointSize;
|
|
|
|
foreach (List<Point> drawing in Drawings)
|
|
{
|
|
if (drawing.Count == 2)
|
|
{
|
|
Point start = drawing[0];
|
|
Point end = drawing[1];
|
|
|
|
List<Point> points;
|
|
if (drawingCounter == Drawings.Count - 1)
|
|
{
|
|
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
|
}
|
|
else
|
|
{
|
|
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
|
}
|
|
|
|
result += "<rect x=\"" + start.X + "\" y=\"" + start.Y + "\" width=\"" + (end.X - start.X) + "\" height=\"" + (end.Y - start.Y) + "\" style=\"stroke:rgb(" + Colors[drawingCounter].R + ", " + Colors[drawingCounter].G + ", " + Colors[drawingCounter].B + ");\" stroke-width=\""+ Widths[drawingCounter]+"\" fill=\"none\"/>";
|
|
result += newLine;
|
|
}
|
|
drawingCounter++;
|
|
}
|
|
return result;
|
|
}
|
|
public void Start(Color color, int width)
|
|
{
|
|
Utils.StandartStart(color, width);
|
|
}
|
|
public void Clear()
|
|
{
|
|
Utils.StandartClear();
|
|
}
|
|
public void Stop()
|
|
{
|
|
List<Point> myDrawing = Drawings.Last();
|
|
Drawings[Drawings.Count - 1] = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, myDrawing[0], myDrawing[1]);
|
|
}
|
|
private Bitmap PostProcessing(List<Point> Drawing, Bitmap bmp, int width, Color color)
|
|
{
|
|
return bmp;
|
|
}
|
|
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()
|
|
{
|
|
RectangleBorderPencil result = new RectangleBorderPencil(Name);
|
|
result.Width = Width;
|
|
result.Color = Color;
|
|
return (Object)(result);
|
|
}
|
|
}
|
|
}
|
|
|