Added support for SVG painting for all the current pencils

This commit is contained in:
2022-06-20 14:02:17 +02:00
parent 15a4daf2f7
commit 9b4cfb33bd
6 changed files with 256 additions and 39 deletions

View File

@@ -40,7 +40,7 @@ namespace Paint_2
public BezierPencil(string name)
{
NeedsFullRefresh = false;
NeedsFullRefresh = true;
Drawings = new List<List<Point>>();
DrawingsRedo = new List<List<Point>>();
Colors = new List<Color>();
@@ -86,11 +86,11 @@ namespace Paint_2
{
pointSize = new Size(Widths[0]/2, Widths[0]/2);
gr.FillEllipse(new SolidBrush(Colors[i]), new Rectangle(new Point(points[i].X - pointSize.Width / 2, points[i].Y - pointSize.Height / 2), pointSize));
ContinuousBezierGenerator(gr, points, i, Colors[Colors.Count-1], Widths[Widths.Count -1]);
ContinuousBezierGenerator(gr, points, Colors[Colors.Count-1], Widths[Widths.Count -1]);
}
}
}
private void ContinuousBezierGenerator(Graphics gr, List<Point> points, int i,Color color,int width)
private void ContinuousBezierGenerator(Graphics gr, List<Point> points,Color color,int width)
{
if (points.Count >= 4 && points.Count % 2 == 0)
{
@@ -120,6 +120,69 @@ namespace Paint_2
}
}
}
public string PaintSVG()
{
string result = "";
string newLine = Environment.NewLine;
Size pointSize;
List<Point> points = new List<Point>();
foreach (List<Point> drawing in Drawings)
{
if (drawing.Count > 0)
{
points.Add(drawing[0]);
}
}
if (points.Count > 0)
{
for (int i = 0; i < points.Count; i++)
{
pointSize = new Size(Widths[0] / 2, Widths[0] / 2);
//Not really usefull in the SVG world because only the last layer will be displayed
//result += "<ellipse cx=\"" + points[i].X + "\" cy=\"" + points[i].Y + "\" rx=\"" + pointSize.Width / 2 + "\" ry=\"" + pointSize.Height / 2 + "\" style=\"fill:rgb(" + Colors[i].R + ", " + Colors[i].G + ", " + Colors[i].B + ");\"/>";
//result += newLine;
result += ContinuousBezierGeneratorSVG(points, Colors[Colors.Count - 1], Widths[Widths.Count - 1]);
}
}
return result;
}
private string ContinuousBezierGeneratorSVG(List<Point> points, Color color, int width)
{
string result = "";
string newLine = Environment.NewLine;
if (points.Count >= 4 && points.Count % 2 == 0)
{
float precision = 0.01f;
for (float t = 0; t <= 1; t += precision)
{
List<Point> DumpList = new List<Point>();
List<Point> WorkingList = new List<Point>(points);
while (WorkingList.Count != 1)
{
if (WorkingList.Count > 1)
{
for (int pos = 0; pos < WorkingList.Count - 1; pos++)
{
DumpList.Add(Utils.Lerp(WorkingList[pos], WorkingList[pos + 1], t));
}
}
else
{
DumpList.Add(Utils.Lerp(WorkingList[0], WorkingList[1], precision));
}
WorkingList = new List<Point>(DumpList);
DumpList = new List<Point>();
}
result += "<ellipse cx=\"" + WorkingList[0].X + "\" cy=\"" + WorkingList[0].Y + "\" rx=\"" + width / 2 + "\" ry=\"" + width / 2 + "\" style=\"fill:rgb(" + color.R + ", " + color.G + ", " + color.B + ");\"/>";
result += newLine;
//gr.FillEllipse(new SolidBrush(color), new Rectangle(WorkingList[0].X - Widths[0] / 2, WorkingList[0].Y - Widths[0] / 2, width, width));
}
}
return result;
}
private void BezierGenerator(Graphics gr, Point p1, Point p2, Point p3, Point p4, int i)
{
gr.DrawLine(new Pen(Colors[i - 4], Widths[i - 4]), p1, p2);
@@ -182,10 +245,5 @@ namespace Paint_2
result.Color = Color;
return (Object)(result);
}
public string PaintSVG()
{
throw new NotImplementedException();
}
}
}

View File

@@ -63,6 +63,52 @@ namespace Paint_2
}
Drawings[Drawings.Count - 1] = myDrawing;
}
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 p1 = drawing[0];
Point p2 = drawing[1];
Point start = new Point(0, 0);
Point end = new Point(0, 0);
if (p2.X > p1.X)
{
start.X = p1.X;
end.X = p2.X;
}
else
{
start.X = p2.X;
end.X = p1.X;
}
if (p2.Y > p1.Y)
{
start.Y = p1.Y;
end.Y = p2.Y;
}
else
{
start.Y = p2.Y;
end.Y = p1.Y;
}
Size size = new Size((end.X - start.X) / 2, (end.Y - start.Y) / 2);
result += "<ellipse cx=\"" + (start.X + size.Width) + "\" cy=\"" + (start.Y + size.Height) + "\" rx=\"" + size.Width + "\" ry=\"" + size.Height + "\" 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 Paint(Bitmap canvas)
{
Graphics gr = Graphics.FromImage(canvas);
@@ -148,10 +194,5 @@ namespace Paint_2
result.Color = Color;
return (Object)(result);
}
public string PaintSVG()
{
throw new NotImplementedException();
}
}
}

View File

@@ -104,6 +104,52 @@ namespace Paint_2
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 p1 = drawing[0];
Point p2 = drawing[1];
Point start = new Point(0, 0);
Point end = new Point(0, 0);
if (p2.X > p1.X)
{
start.X = p1.X;
end.X = p2.X;
}
else
{
start.X = p2.X;
end.X = p1.X;
}
if (p2.Y > p1.Y)
{
start.Y = p1.Y;
end.Y = p2.Y;
}
else
{
start.Y = p2.Y;
end.Y = p1.Y;
}
Size size = new Size((end.X - start.X) / 2, (end.Y - start.Y) / 2);
result += "<ellipse cx=\"" + (start.X + size.Width) + "\" cy=\"" + (start.Y + size.Height) + "\" rx=\"" + size.Width + "\" ry=\"" + size.Height + "\" style=\"fill:rgb(" + Colors[drawingCounter].R + ", " + Colors[drawingCounter].G + ", " + Colors[drawingCounter].B + ");\"/>";
result += newLine;
}
drawingCounter++;
}
return result;
}
public void Start(Color color, int width)
{
Utils.StandartStart(color, width);
@@ -149,10 +195,5 @@ namespace Paint_2
result.Color = Color;
return (Object)(result);
}
public string PaintSVG()
{
throw new NotImplementedException();
}
}
}

View File

@@ -104,6 +104,51 @@ namespace Paint_2
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 p1 = drawing[0];
Point p2 = drawing[1];
Point start = new Point(0, 0);
Point end = new Point(0, 0);
if (p2.X > p1.X)
{
start.X = p1.X;
end.X = p2.X;
}
else
{
start.X = p2.X;
end.X = p1.X;
}
if (p2.Y > p1.Y)
{
start.Y = p1.Y;
end.Y = p2.Y;
}
else
{
start.Y = p2.Y;
end.Y = p1.Y;
}
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);
@@ -149,11 +194,6 @@ namespace Paint_2
result.Color = Color;
return (Object)(result);
}
public string PaintSVG()
{
throw new NotImplementedException();
}
}
}

View File

@@ -104,6 +104,52 @@ namespace Paint_2
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 p1 = drawing[0];
Point p2 = drawing[1];
Point start = new Point(0, 0);
Point end = new Point(0, 0);
if (p2.X > p1.X)
{
start.X = p1.X;
end.X = p2.X;
}
else
{
start.X = p2.X;
end.X = p1.X;
}
if (p2.Y > p1.Y)
{
start.Y = p1.Y;
end.Y = p2.Y;
}
else
{
start.Y = p2.Y;
end.Y = p1.Y;
}
result += "<rect x=\"" + start.X + "\" y=\"" + start.Y + "\" width=\"" + (end.X - start.X) + "\" height=\"" + (end.Y - start.Y) + "\" style=\"fill:rgb(" + Colors[drawingCounter].R + ", " + Colors[drawingCounter].G + ", " + Colors[drawingCounter].B + ");\"/>";
result += newLine;
//gr.DrawRectangle(new Pen(Colors[drawingCounter], Widths[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y)));
}
drawingCounter++;
}
return result;
}
public void Start(Color color, int width)
{
Utils.StandartStart(color, width);
@@ -149,10 +195,5 @@ namespace Paint_2
result.Color = Color;
return (Object)(result);
}
public string PaintSVG()
{
throw new NotImplementedException();
}
}
}

View File

@@ -122,15 +122,11 @@ namespace Paint_2
string newLine = Environment.NewLine;
foreach (PaintTool tool in ToolList)
{
//[DEBUG] REMOVE THIS IF AFTER TESTING PLEASE
if (tool is Pencil || tool is DotPencil)
{
result += "<!-- " + tool.Name + " -->";
result += newLine;
result += tool.PaintSVG();
}
}
return result;
}
public Bitmap ForcePaint()