Compare commits

..

2 Commits

13 changed files with 390 additions and 24 deletions
+66 -3
View File
@@ -40,7 +40,7 @@ namespace Paint_2
public BezierPencil(string name) public BezierPencil(string name)
{ {
NeedsFullRefresh = false; NeedsFullRefresh = true;
Drawings = new List<List<Point>>(); Drawings = new List<List<Point>>();
DrawingsRedo = new List<List<Point>>(); DrawingsRedo = new List<List<Point>>();
Colors = new List<Color>(); Colors = new List<Color>();
@@ -86,11 +86,11 @@ namespace Paint_2
{ {
pointSize = new Size(Widths[0]/2, Widths[0]/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)); 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) 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) 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); gr.DrawLine(new Pen(Colors[i - 4], Widths[i - 4]), p1, p2);
+29
View File
@@ -138,5 +138,34 @@ namespace Paint_2
result.Color = Color; result.Color = Color;
return (Object)(result); 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;
}
} }
} }
+46 -2
View File
@@ -63,12 +63,56 @@ namespace Paint_2
} }
Drawings[Drawings.Count - 1] = myDrawing; 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) public void Paint(Bitmap canvas)
{ {
Graphics gr = Graphics.FromImage(canvas); Graphics gr = Graphics.FromImage(canvas);
int drawingCounter = 0; int drawingCounter = 0;
Size pointSize;
foreach (List<Point> drawing in Drawings) foreach (List<Point> drawing in Drawings)
{ {
if (drawing.Count == 2) if (drawing.Count == 2)
+46
View File
@@ -104,6 +104,52 @@ namespace Paint_2
drawingCounter++; 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) public void Start(Color color, int width)
{ {
Utils.StandartStart(color, width); Utils.StandartStart(color, width);
+33 -15
View File
@@ -71,6 +71,7 @@
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.DebugLabel = new System.Windows.Forms.Label(); this.DebugLabel = new System.Windows.Forms.Label();
this.panel4 = new System.Windows.Forms.Panel(); this.panel4 = new System.Windows.Forms.Panel();
this.btnSvgExport = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit();
this.panelFile.SuspendLayout(); this.panelFile.SuspendLayout();
this.panelDrawing.SuspendLayout(); this.panelDrawing.SuspendLayout();
@@ -93,7 +94,7 @@
this.tbxProjectName.Location = new System.Drawing.Point(2, 4); this.tbxProjectName.Location = new System.Drawing.Point(2, 4);
this.tbxProjectName.Margin = new System.Windows.Forms.Padding(2); this.tbxProjectName.Margin = new System.Windows.Forms.Padding(2);
this.tbxProjectName.Name = "tbxProjectName"; this.tbxProjectName.Name = "tbxProjectName";
this.tbxProjectName.Size = new System.Drawing.Size(225, 32); this.tbxProjectName.Size = new System.Drawing.Size(225, 38);
this.tbxProjectName.TabIndex = 0; this.tbxProjectName.TabIndex = 0;
this.tbxProjectName.Text = "Untitled Project"; this.tbxProjectName.Text = "Untitled Project";
// //
@@ -144,7 +145,7 @@
this.lblSelectedColor.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lblSelectedColor.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.lblSelectedColor.Location = new System.Drawing.Point(6, 23); this.lblSelectedColor.Location = new System.Drawing.Point(6, 23);
this.lblSelectedColor.Name = "lblSelectedColor"; this.lblSelectedColor.Name = "lblSelectedColor";
this.lblSelectedColor.Size = new System.Drawing.Size(202, 14); this.lblSelectedColor.Size = new System.Drawing.Size(256, 18);
this.lblSelectedColor.TabIndex = 1; this.lblSelectedColor.TabIndex = 1;
this.lblSelectedColor.Text = "Hex:FFFFFF R:255 G:255 B:255"; this.lblSelectedColor.Text = "Hex:FFFFFF R:255 G:255 B:255";
// //
@@ -192,7 +193,7 @@
this.lblHeight.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lblHeight.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.lblHeight.Location = new System.Drawing.Point(3, 38); this.lblHeight.Location = new System.Drawing.Point(3, 38);
this.lblHeight.Name = "lblHeight"; this.lblHeight.Name = "lblHeight";
this.lblHeight.Size = new System.Drawing.Size(53, 14); this.lblHeight.Size = new System.Drawing.Size(66, 18);
this.lblHeight.TabIndex = 34; this.lblHeight.TabIndex = 34;
this.lblHeight.Text = "H:2000"; this.lblHeight.Text = "H:2000";
// //
@@ -202,7 +203,7 @@
this.lblWidth.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lblWidth.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.lblWidth.Location = new System.Drawing.Point(3, 7); this.lblWidth.Location = new System.Drawing.Point(3, 7);
this.lblWidth.Name = "lblWidth"; this.lblWidth.Name = "lblWidth";
this.lblWidth.Size = new System.Drawing.Size(57, 14); this.lblWidth.Size = new System.Drawing.Size(69, 18);
this.lblWidth.TabIndex = 33; this.lblWidth.TabIndex = 33;
this.lblWidth.Text = "W:2000"; this.lblWidth.Text = "W:2000";
// //
@@ -238,7 +239,7 @@
this.label14.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.label14.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.label14.Location = new System.Drawing.Point(6, 5); this.label14.Location = new System.Drawing.Point(6, 5);
this.label14.Name = "label14"; this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(120, 18); this.label14.Size = new System.Drawing.Size(150, 22);
this.label14.TabIndex = 29; this.label14.TabIndex = 29;
this.label14.Text = "Selected color"; this.label14.Text = "Selected color";
// //
@@ -273,7 +274,7 @@
this.lblHoveringColor.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lblHoveringColor.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.lblHoveringColor.Location = new System.Drawing.Point(7, 23); this.lblHoveringColor.Location = new System.Drawing.Point(7, 23);
this.lblHoveringColor.Name = "lblHoveringColor"; this.lblHoveringColor.Name = "lblHoveringColor";
this.lblHoveringColor.Size = new System.Drawing.Size(202, 14); this.lblHoveringColor.Size = new System.Drawing.Size(256, 18);
this.lblHoveringColor.TabIndex = 1; this.lblHoveringColor.TabIndex = 1;
this.lblHoveringColor.Text = "Hex:FFFFFF R:255 G:255 B:255"; this.lblHoveringColor.Text = "Hex:FFFFFF R:255 G:255 B:255";
// //
@@ -284,7 +285,7 @@
this.label15.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.label15.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.label15.Location = new System.Drawing.Point(7, 5); this.label15.Location = new System.Drawing.Point(7, 5);
this.label15.Name = "label15"; this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(120, 18); this.label15.Size = new System.Drawing.Size(150, 22);
this.label15.TabIndex = 29; this.label15.TabIndex = 29;
this.label15.Text = "Hovering color"; this.label15.Text = "Hovering color";
// //
@@ -307,7 +308,7 @@
0, 0,
0}); 0});
this.nupPencilWidth.Name = "nupPencilWidth"; this.nupPencilWidth.Name = "nupPencilWidth";
this.nupPencilWidth.Size = new System.Drawing.Size(55, 27); this.nupPencilWidth.Size = new System.Drawing.Size(55, 33);
this.nupPencilWidth.TabIndex = 17; this.nupPencilWidth.TabIndex = 17;
this.nupPencilWidth.Value = new decimal(new int[] { this.nupPencilWidth.Value = new decimal(new int[] {
10, 10,
@@ -408,11 +409,11 @@
this.lsbTools.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lsbTools.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lsbTools.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.lsbTools.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.lsbTools.FormattingEnabled = true; this.lsbTools.FormattingEnabled = true;
this.lsbTools.ItemHeight = 14; this.lsbTools.ItemHeight = 18;
this.lsbTools.Location = new System.Drawing.Point(6, 20); this.lsbTools.Location = new System.Drawing.Point(6, 20);
this.lsbTools.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.lsbTools.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.lsbTools.Name = "lsbTools"; this.lsbTools.Name = "lsbTools";
this.lsbTools.Size = new System.Drawing.Size(183, 142); this.lsbTools.Size = new System.Drawing.Size(183, 128);
this.lsbTools.TabIndex = 32; this.lsbTools.TabIndex = 32;
this.lsbTools.SelectedIndexChanged += new System.EventHandler(this.lsbTools_SelectedIndexChanged); this.lsbTools.SelectedIndexChanged += new System.EventHandler(this.lsbTools_SelectedIndexChanged);
// //
@@ -432,7 +433,7 @@
this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.label1.Location = new System.Drawing.Point(3, 2); this.label1.Location = new System.Drawing.Point(3, 2);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(84, 16); this.label1.Size = new System.Drawing.Size(108, 20);
this.label1.TabIndex = 36; this.label1.TabIndex = 36;
this.label1.Text = "Paint tools"; this.label1.Text = "Paint tools";
// //
@@ -546,7 +547,7 @@
this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247))))); this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.label3.Location = new System.Drawing.Point(3, 8); this.label3.Location = new System.Drawing.Point(3, 8);
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(49, 16); this.label3.Size = new System.Drawing.Size(63, 20);
this.label3.TabIndex = 37; this.label3.TabIndex = 37;
this.label3.Text = "Layers"; this.label3.Text = "Layers";
// //
@@ -596,7 +597,7 @@
this.label2.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.Location = new System.Drawing.Point(7, 8); this.label2.Location = new System.Drawing.Point(7, 8);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(0, 16); this.label2.Size = new System.Drawing.Size(0, 20);
this.label2.TabIndex = 36; this.label2.TabIndex = 36;
// //
// DebugLabel // DebugLabel
@@ -604,7 +605,7 @@
this.DebugLabel.AutoSize = true; this.DebugLabel.AutoSize = true;
this.DebugLabel.Location = new System.Drawing.Point(18, 86); this.DebugLabel.Location = new System.Drawing.Point(18, 86);
this.DebugLabel.Name = "DebugLabel"; this.DebugLabel.Name = "DebugLabel";
this.DebugLabel.Size = new System.Drawing.Size(48, 14); this.DebugLabel.Size = new System.Drawing.Size(55, 18);
this.DebugLabel.TabIndex = 38; this.DebugLabel.TabIndex = 38;
this.DebugLabel.Text = "Debug"; this.DebugLabel.Text = "Debug";
// //
@@ -624,12 +625,28 @@
this.panel4.Size = new System.Drawing.Size(507, 39); this.panel4.Size = new System.Drawing.Size(507, 39);
this.panel4.TabIndex = 37; this.panel4.TabIndex = 37;
// //
// btnSvgExport
//
this.btnSvgExport.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(59)))), ((int)(((byte)(59)))));
this.btnSvgExport.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnSvgExport.Font = new System.Drawing.Font("Cascadia Code", 10.2F);
this.btnSvgExport.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
this.btnSvgExport.Location = new System.Drawing.Point(1039, 545);
this.btnSvgExport.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnSvgExport.Name = "btnSvgExport";
this.btnSvgExport.Size = new System.Drawing.Size(150, 33);
this.btnSvgExport.TabIndex = 37;
this.btnSvgExport.Text = "Export SVG";
this.btnSvgExport.UseVisualStyleBackColor = false;
this.btnSvgExport.Click += new System.EventHandler(this.btnSvgExport_Click);
//
// PaintForm // PaintForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 14F); this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(34)))), ((int)(((byte)(34))))); this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(34)))), ((int)(((byte)(34)))));
this.ClientSize = new System.Drawing.Size(1222, 618); this.ClientSize = new System.Drawing.Size(1222, 618);
this.Controls.Add(this.btnSvgExport);
this.Controls.Add(this.panel4); this.Controls.Add(this.panel4);
this.Controls.Add(this.DebugLabel); this.Controls.Add(this.DebugLabel);
this.Controls.Add(this.panel3); this.Controls.Add(this.panel3);
@@ -715,6 +732,7 @@
private System.Windows.Forms.Panel pnlLayers; private System.Windows.Forms.Panel pnlLayers;
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;
private System.Windows.Forms.Panel panel4; private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Button btnSvgExport;
} }
} }
+5
View File
@@ -468,5 +468,10 @@ namespace Paint_2
} }
DisplayLayers(); DisplayLayers();
} }
private void btnSvgExport_Click(object sender, EventArgs e)
{
Project.ConvertToSVG();
}
} }
} }
+1
View File
@@ -34,6 +34,7 @@ namespace Paint_2
void Clear(); void Clear();
List<Color> GetLastColors(int colorNumber); List<Color> GetLastColors(int colorNumber);
void Paint(Bitmap canvas); void Paint(Bitmap canvas);
string PaintSVG();
string ToString(); string ToString();
} }
} }
+4
View File
@@ -101,5 +101,9 @@ namespace Paint_2
Point result = new Point(resultX, resultY); Point result = new Point(resultX, resultY);
return result; return result;
} }
public string StandartPaintSVG(List<List<Point>> Drawings,List<Color> Colors, List<int> Widths)
{
return "COUCOU";
}
} }
} }
+33
View File
@@ -78,6 +78,37 @@ namespace Paint_2
drawingCounter += 1; drawingCounter += 1;
} }
} }
public string PaintSVG()
{
string result = "";
string newLine = Environment.NewLine;
//foreach (List<Point> drawing in Drawings)
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;
result += "<line x1=\"" + p1.X + "\" y1=\"" + p1.Y + "\" x2=\"" + p2.X + "\" y2=\"" + p2.Y + "\" style=\"stroke: rgb(" + color.R + ", " + color.G + ", " + color.B + "); stroke-width:" + width + "\"/>";
result += newLine;
}
}
}
return result;
}
public void Start(Color color, int width) public void Start(Color color, int width)
{ {
Utils.StandartStart(color, width); Utils.StandartStart(color, width);
@@ -123,5 +154,7 @@ namespace Paint_2
result.Color = Color; result.Color = Color;
return (Object)(result); return (Object)(result);
} }
} }
} }
+19
View File
@@ -416,5 +416,24 @@ namespace Paint_2
} }
return result; return result;
} }
public void ConvertToSVG()
{
string fileContent = "";
string newLine = Environment.NewLine;
fileContent += "<svg version=\"1.1\" width=\"100%\" viewbox=\"0 0 "+CanvasSize.Width+" "+CanvasSize.Height+"\" xmlns = \"http://www.w3.org/2000/svg\">";
fileContent += newLine;
foreach (Sketch layer in Layers)
{
fileContent += "<!-- "+layer.Name+" -->";
fileContent += newLine;
fileContent += layer.PaintSVG();
}
fileContent += newLine;
fileContent += "</svg>";
}
} }
} }
+45
View File
@@ -104,6 +104,51 @@ namespace Paint_2
drawingCounter++; 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) public void Start(Color color, int width)
{ {
Utils.StandartStart(color, width); Utils.StandartStart(color, width);
+46
View File
@@ -104,6 +104,52 @@ namespace Paint_2
drawingCounter++; 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) public void Start(Color color, int width)
{ {
Utils.StandartStart(color, width); Utils.StandartStart(color, width);
+13
View File
@@ -116,6 +116,19 @@ namespace Paint_2
CurrentTool.Paint(Drawing); CurrentTool.Paint(Drawing);
return Drawing; return Drawing;
} }
public string PaintSVG()
{
string result = "";
string newLine = Environment.NewLine;
foreach (PaintTool tool in ToolList)
{
result += "<!-- " + tool.Name + " -->";
result += newLine;
result += tool.PaintSVG();
}
return result;
}
public Bitmap ForcePaint() public Bitmap ForcePaint()
{ {
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height); Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);