From 15a4daf2f7d8f32dd81f4a9ded578e610ac787f9 Mon Sep 17 00:00:00 2001 From: maxluli Date: Mon, 20 Jun 2022 13:01:22 +0200 Subject: [PATCH] Added painting in SVG (ONLY FOR THE PENCIL AND DOT PENCIL FOR) --- Paint_2/BezierPencil.cs | 5 ++++ Paint_2/DotPencil.cs | 29 +++++++++++++++++++ Paint_2/EllipseBorderPencil.cs | 7 +++-- Paint_2/EllipsePencil.cs | 5 ++++ Paint_2/Form1.Designer.cs | 48 ++++++++++++++++++++++---------- Paint_2/Form1.cs | 5 ++++ Paint_2/PaintTool.cs | 1 + Paint_2/PaintToolUtils.cs | 4 +++ Paint_2/Pencil.cs | 33 ++++++++++++++++++++++ Paint_2/Project.cs | 19 +++++++++++++ Paint_2/RectangleBorderPencil.cs | 5 ++++ Paint_2/RectanglePencil.cs | 5 ++++ Paint_2/Sketch.cs | 17 +++++++++++ 13 files changed, 166 insertions(+), 17 deletions(-) diff --git a/Paint_2/BezierPencil.cs b/Paint_2/BezierPencil.cs index 9d26647..73c36a6 100644 --- a/Paint_2/BezierPencil.cs +++ b/Paint_2/BezierPencil.cs @@ -182,5 +182,10 @@ namespace Paint_2 result.Color = Color; return (Object)(result); } + + public string PaintSVG() + { + throw new NotImplementedException(); + } } } diff --git a/Paint_2/DotPencil.cs b/Paint_2/DotPencil.cs index 18504a8..6f47819 100644 --- a/Paint_2/DotPencil.cs +++ b/Paint_2/DotPencil.cs @@ -138,5 +138,34 @@ namespace Paint_2 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 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 += ""; + result += newLine; + } + + } + } + + return result; + } } } diff --git a/Paint_2/EllipseBorderPencil.cs b/Paint_2/EllipseBorderPencil.cs index 2d5e88d..ebfa8be 100644 --- a/Paint_2/EllipseBorderPencil.cs +++ b/Paint_2/EllipseBorderPencil.cs @@ -67,8 +67,6 @@ namespace Paint_2 { Graphics gr = Graphics.FromImage(canvas); int drawingCounter = 0; - Size pointSize; - foreach (List drawing in Drawings) { if (drawing.Count == 2) @@ -150,5 +148,10 @@ namespace Paint_2 result.Color = Color; return (Object)(result); } + + public string PaintSVG() + { + throw new NotImplementedException(); + } } } diff --git a/Paint_2/EllipsePencil.cs b/Paint_2/EllipsePencil.cs index e934dd1..4778b98 100644 --- a/Paint_2/EllipsePencil.cs +++ b/Paint_2/EllipsePencil.cs @@ -149,5 +149,10 @@ namespace Paint_2 result.Color = Color; return (Object)(result); } + + public string PaintSVG() + { + throw new NotImplementedException(); + } } } diff --git a/Paint_2/Form1.Designer.cs b/Paint_2/Form1.Designer.cs index 823ed42..9c071a8 100644 --- a/Paint_2/Form1.Designer.cs +++ b/Paint_2/Form1.Designer.cs @@ -71,6 +71,7 @@ this.label2 = new System.Windows.Forms.Label(); this.DebugLabel = new System.Windows.Forms.Label(); this.panel4 = new System.Windows.Forms.Panel(); + this.btnSvgExport = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit(); this.panelFile.SuspendLayout(); this.panelDrawing.SuspendLayout(); @@ -93,7 +94,7 @@ this.tbxProjectName.Location = new System.Drawing.Point(2, 4); this.tbxProjectName.Margin = new System.Windows.Forms.Padding(2); 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.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.Location = new System.Drawing.Point(6, 23); 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.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.Location = new System.Drawing.Point(3, 38); 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.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.Location = new System.Drawing.Point(3, 7); 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.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.Location = new System.Drawing.Point(6, 5); 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.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.Location = new System.Drawing.Point(7, 23); 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.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.Location = new System.Drawing.Point(7, 5); 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.Text = "Hovering color"; // @@ -307,7 +308,7 @@ 0, 0}); 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.Value = new decimal(new int[] { 10, @@ -408,11 +409,11 @@ 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.FormattingEnabled = true; - this.lsbTools.ItemHeight = 14; + this.lsbTools.ItemHeight = 18; this.lsbTools.Location = new System.Drawing.Point(6, 20); this.lsbTools.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); 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.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.Location = new System.Drawing.Point(3, 2); 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.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.Location = new System.Drawing.Point(3, 8); 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.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.Location = new System.Drawing.Point(7, 8); 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; // // DebugLabel @@ -604,7 +605,7 @@ this.DebugLabel.AutoSize = true; this.DebugLabel.Location = new System.Drawing.Point(18, 86); 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.Text = "Debug"; // @@ -624,12 +625,28 @@ this.panel4.Size = new System.Drawing.Size(507, 39); 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 // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 14F); + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(34)))), ((int)(((byte)(34)))), ((int)(((byte)(34))))); this.ClientSize = new System.Drawing.Size(1222, 618); + this.Controls.Add(this.btnSvgExport); this.Controls.Add(this.panel4); this.Controls.Add(this.DebugLabel); this.Controls.Add(this.panel3); @@ -715,6 +732,7 @@ private System.Windows.Forms.Panel pnlLayers; private System.Windows.Forms.Label label3; private System.Windows.Forms.Panel panel4; + private System.Windows.Forms.Button btnSvgExport; } } diff --git a/Paint_2/Form1.cs b/Paint_2/Form1.cs index e6a0d9e..821b72c 100644 --- a/Paint_2/Form1.cs +++ b/Paint_2/Form1.cs @@ -468,5 +468,10 @@ namespace Paint_2 } DisplayLayers(); } + + private void btnSvgExport_Click(object sender, EventArgs e) + { + Project.ConvertToSVG(); + } } } diff --git a/Paint_2/PaintTool.cs b/Paint_2/PaintTool.cs index 934f2a3..68d7d11 100644 --- a/Paint_2/PaintTool.cs +++ b/Paint_2/PaintTool.cs @@ -34,6 +34,7 @@ namespace Paint_2 void Clear(); List GetLastColors(int colorNumber); void Paint(Bitmap canvas); + string PaintSVG(); string ToString(); } } diff --git a/Paint_2/PaintToolUtils.cs b/Paint_2/PaintToolUtils.cs index 2eb24d7..151bb56 100644 --- a/Paint_2/PaintToolUtils.cs +++ b/Paint_2/PaintToolUtils.cs @@ -101,5 +101,9 @@ namespace Paint_2 Point result = new Point(resultX, resultY); return result; } + public string StandartPaintSVG(List> Drawings,List Colors, List Widths) + { + return "COUCOU"; + } } } diff --git a/Paint_2/Pencil.cs b/Paint_2/Pencil.cs index 30e7c96..a15fc7a 100644 --- a/Paint_2/Pencil.cs +++ b/Paint_2/Pencil.cs @@ -78,6 +78,37 @@ namespace Paint_2 drawingCounter += 1; } } + public string PaintSVG() + { + string result = ""; + string newLine = Environment.NewLine; + + //foreach (List drawing in Drawings) + for (int drawCount = 0; drawCount < Drawings.Count; drawCount++) + { + Point p1; + Point p2; + List 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 += ""; + result += newLine; + result += ""; + result += newLine; + } + + } + } + + return result; + } public void Start(Color color, int width) { Utils.StandartStart(color, width); @@ -123,5 +154,7 @@ namespace Paint_2 result.Color = Color; return (Object)(result); } + + } } diff --git a/Paint_2/Project.cs b/Paint_2/Project.cs index cccf3c2..cae4ece 100644 --- a/Paint_2/Project.cs +++ b/Paint_2/Project.cs @@ -416,5 +416,24 @@ namespace Paint_2 } return result; } + + public void ConvertToSVG() + { + string fileContent = ""; + string newLine = Environment.NewLine; + + fileContent += ""; + fileContent += newLine; + + foreach (Sketch layer in Layers) + { + fileContent += ""; + fileContent += newLine; + fileContent += layer.PaintSVG(); + } + + fileContent += newLine; + fileContent += ""; + } } } diff --git a/Paint_2/RectangleBorderPencil.cs b/Paint_2/RectangleBorderPencil.cs index a0895e2..130e98a 100644 --- a/Paint_2/RectangleBorderPencil.cs +++ b/Paint_2/RectangleBorderPencil.cs @@ -149,6 +149,11 @@ namespace Paint_2 result.Color = Color; return (Object)(result); } + + public string PaintSVG() + { + throw new NotImplementedException(); + } } } diff --git a/Paint_2/RectanglePencil.cs b/Paint_2/RectanglePencil.cs index 8750a58..22ccfe2 100644 --- a/Paint_2/RectanglePencil.cs +++ b/Paint_2/RectanglePencil.cs @@ -149,5 +149,10 @@ namespace Paint_2 result.Color = Color; return (Object)(result); } + + public string PaintSVG() + { + throw new NotImplementedException(); + } } } diff --git a/Paint_2/Sketch.cs b/Paint_2/Sketch.cs index f95d22a..ca94d16 100644 --- a/Paint_2/Sketch.cs +++ b/Paint_2/Sketch.cs @@ -116,6 +116,23 @@ namespace Paint_2 CurrentTool.Paint(Drawing); return Drawing; } + public string PaintSVG() + { + string result = ""; + string newLine = Environment.NewLine; + + foreach (PaintTool tool in ToolList) + { + //[DEBUG] REMOVE THIS IF AFTER TESTING PLEASE + if (tool is Pencil || tool is DotPencil) + { + result += ""; + result += newLine; + result += tool.PaintSVG(); + } + } + return result; + } public Bitmap ForcePaint() { Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);