Compare commits
6 Commits
dfc8ca24dd
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| e243b37884 | |||
| 640796a1b1 | |||
| 44dd8b9f0c | |||
| 95217bb3c5 | |||
| 9b4cfb33bd | |||
| 15a4daf2f7 |
+114
-6
@@ -18,6 +18,8 @@ namespace Paint_2
|
||||
private List<List<Point>> _drawings;
|
||||
private List<List<Point>> _drawingsRedo;
|
||||
private bool _needsFullRefresh;
|
||||
private bool _isCtrlPressed;
|
||||
private bool _isShiftPressed;
|
||||
private PaintToolUtils Utils;
|
||||
private List<Color> _colors;
|
||||
private List<Color> _colorsRedo;
|
||||
@@ -34,13 +36,15 @@ namespace Paint_2
|
||||
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 BezierPencil(string name)
|
||||
{
|
||||
NeedsFullRefresh = false;
|
||||
NeedsFullRefresh = true;
|
||||
Drawings = new List<List<Point>>();
|
||||
DrawingsRedo = new List<List<Point>>();
|
||||
Colors = new List<Color>();
|
||||
@@ -84,13 +88,51 @@ namespace Paint_2
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
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]);
|
||||
pointSize = new Size(Widths[0] / 2, Widths[0] / 2);
|
||||
//ContinuousBezierGenerator(gr, points, Colors[Colors.Count-1], Widths[Widths.Count -1]);
|
||||
AdjustedBezierGenerator(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 AdjustedBezierGenerator(Graphics gr, List<Point> points, Color color, int width)
|
||||
{
|
||||
foreach (Point p in points)
|
||||
{
|
||||
gr.FillEllipse(new SolidBrush(color), new Rectangle(new Point(p.X - width / 2, p.Y - width / 2), new Size(width,width)));
|
||||
}
|
||||
if (points.Count >= 3)
|
||||
{
|
||||
float precision = 0.01f;
|
||||
for (float t = 0; t <= 1; t += precision)
|
||||
{
|
||||
List<Point> DumpList = new List<Point>();
|
||||
List<Point> WorkingList = new List<Point>();
|
||||
|
||||
foreach (Point p in points)
|
||||
{
|
||||
WorkingList.Add(new Point(p.X, p.Y));
|
||||
}
|
||||
while (WorkingList.Count > 1)
|
||||
{
|
||||
for (int i = 0; i < WorkingList.Count - 1; i++)
|
||||
{
|
||||
Point p1 = WorkingList[i];
|
||||
Point p2 = WorkingList[i + 1];
|
||||
Point tmp = Utils.Lerp(p1, p2, t);
|
||||
DumpList.Add(tmp);
|
||||
}
|
||||
WorkingList.Clear();
|
||||
foreach (Point p in DumpList)
|
||||
{
|
||||
WorkingList.Add(new Point(p.X, p.Y));
|
||||
}
|
||||
DumpList.Clear();
|
||||
}
|
||||
gr.FillEllipse(new SolidBrush(color), new Rectangle(WorkingList[0].X - Widths[0] / 2, WorkingList[0].Y - Widths[0] / 2, width, width));
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ContinuousBezierGenerator(Graphics gr, List<Point> points, Color color, int width)
|
||||
{
|
||||
if (points.Count >= 4 && points.Count % 2 == 0)
|
||||
{
|
||||
@@ -120,6 +162,72 @@ 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 >= 3)
|
||||
{
|
||||
float precision = 0.01f;
|
||||
for (float t = 0; t <= 1; t += precision)
|
||||
{
|
||||
List<Point> DumpList = new List<Point>();
|
||||
List<Point> WorkingList = new List<Point>();
|
||||
|
||||
foreach (Point p in points)
|
||||
{
|
||||
WorkingList.Add(new Point(p.X, p.Y));
|
||||
}
|
||||
while (WorkingList.Count > 1)
|
||||
{
|
||||
for (int i = 0; i < WorkingList.Count - 1; i++)
|
||||
{
|
||||
Point p1 = WorkingList[i];
|
||||
Point p2 = WorkingList[i + 1];
|
||||
Point tmp = Utils.Lerp(p1, p2, t);
|
||||
DumpList.Add(tmp);
|
||||
}
|
||||
WorkingList.Clear();
|
||||
foreach (Point p in DumpList)
|
||||
{
|
||||
WorkingList.Add(new Point(p.X, p.Y));
|
||||
}
|
||||
DumpList.Clear();
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
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);
|
||||
@@ -152,7 +260,7 @@ namespace Paint_2
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Utils.StandartStart(color,width);
|
||||
Utils.StandartStart(color, width);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace Paint_2
|
||||
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;
|
||||
@@ -32,6 +34,8 @@ namespace Paint_2
|
||||
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; }
|
||||
@@ -138,5 +142,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<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,13 @@ using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
internal class EllipseBorderPencil:PaintTool
|
||||
internal class EllipseBorderPencil : 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;
|
||||
@@ -34,6 +36,8 @@ namespace Paint_2
|
||||
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; }
|
||||
@@ -63,9 +67,11 @@ namespace Paint_2
|
||||
}
|
||||
Drawings[Drawings.Count - 1] = myDrawing;
|
||||
}
|
||||
public void Paint(Bitmap canvas)
|
||||
public string PaintSVG()
|
||||
{
|
||||
Graphics gr = Graphics.FromImage(canvas);
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
int drawingCounter = 0;
|
||||
Size pointSize;
|
||||
|
||||
@@ -73,33 +79,54 @@ namespace Paint_2
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
Point p1 = drawing[0];
|
||||
Point p2 = drawing[1];
|
||||
Point start = drawing[0];
|
||||
Point end = drawing[1];
|
||||
|
||||
Point start = new Point(0, 0);
|
||||
Point end = new Point(0, 0);
|
||||
|
||||
if (p2.X > p1.X)
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
start.X = p1.X;
|
||||
end.X = p2.X;
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
start.X = p2.X;
|
||||
end.X = p1.X;
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
if (p2.Y > p1.Y)
|
||||
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
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);
|
||||
int drawingCounter = 0;
|
||||
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)
|
||||
{
|
||||
start.Y = p1.Y;
|
||||
end.Y = p2.Y;
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
start.Y = p2.Y;
|
||||
end.Y = p1.Y;
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
gr.DrawEllipse(new Pen(Colors[drawingCounter], Widths[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y)));
|
||||
}
|
||||
drawingCounter++;
|
||||
@@ -115,10 +142,8 @@ namespace Paint_2
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
for (int i = 0; i < Drawings.Count; i++)
|
||||
{
|
||||
List<Point> Drawing = Drawings[i];
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
+51
-24
@@ -17,6 +17,8 @@ namespace Paint_2
|
||||
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;
|
||||
@@ -33,6 +35,8 @@ namespace Paint_2
|
||||
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; }
|
||||
@@ -72,38 +76,63 @@ namespace Paint_2
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
Point p1 = drawing[0];
|
||||
Point p2 = drawing[1];
|
||||
Point start = drawing[0];
|
||||
Point end = drawing[1];
|
||||
|
||||
Point start = new Point(0, 0);
|
||||
Point end = new Point(0, 0);
|
||||
|
||||
if (p2.X > p1.X)
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
start.X = p1.X;
|
||||
end.X = p2.X;
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
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;
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
gr.FillEllipse(new SolidBrush(Colors[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]);
|
||||
}
|
||||
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
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);
|
||||
@@ -114,10 +143,8 @@ namespace Paint_2
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
for (int i = 0; i < Drawings.Count; i++)
|
||||
{
|
||||
List<Point> Drawing = Drawings[i];
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
Generated
+43
-11
@@ -69,8 +69,10 @@
|
||||
this.btnLayerRemove = new System.Windows.Forms.Button();
|
||||
this.BtnAddLayer = new System.Windows.Forms.Button();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.DebugLabel = new System.Windows.Forms.Label();
|
||||
this.DebugLabel1 = new System.Windows.Forms.Label();
|
||||
this.panel4 = new System.Windows.Forms.Panel();
|
||||
this.btnSvgExport = new System.Windows.Forms.Button();
|
||||
this.DebugLabel2 = new System.Windows.Forms.Label();
|
||||
((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit();
|
||||
this.panelFile.SuspendLayout();
|
||||
this.panelDrawing.SuspendLayout();
|
||||
@@ -412,7 +414,7 @@
|
||||
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);
|
||||
//
|
||||
@@ -599,14 +601,14 @@
|
||||
this.label2.Size = new System.Drawing.Size(0, 16);
|
||||
this.label2.TabIndex = 36;
|
||||
//
|
||||
// DebugLabel
|
||||
// DebugLabel1
|
||||
//
|
||||
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.TabIndex = 38;
|
||||
this.DebugLabel.Text = "Debug";
|
||||
this.DebugLabel1.AutoSize = true;
|
||||
this.DebugLabel1.Location = new System.Drawing.Point(17, 64);
|
||||
this.DebugLabel1.Name = "DebugLabel1";
|
||||
this.DebugLabel1.Size = new System.Drawing.Size(48, 14);
|
||||
this.DebugLabel1.TabIndex = 38;
|
||||
this.DebugLabel1.Text = "Debug";
|
||||
//
|
||||
// panel4
|
||||
//
|
||||
@@ -624,14 +626,40 @@
|
||||
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(1014, 505);
|
||||
this.btnSvgExport.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.btnSvgExport.Name = "btnSvgExport";
|
||||
this.btnSvgExport.Size = new System.Drawing.Size(196, 33);
|
||||
this.btnSvgExport.TabIndex = 37;
|
||||
this.btnSvgExport.Text = "Export SVG";
|
||||
this.btnSvgExport.UseVisualStyleBackColor = false;
|
||||
this.btnSvgExport.Click += new System.EventHandler(this.btnSvgExport_Click);
|
||||
//
|
||||
// DebugLabel2
|
||||
//
|
||||
this.DebugLabel2.AutoSize = true;
|
||||
this.DebugLabel2.Location = new System.Drawing.Point(17, 78);
|
||||
this.DebugLabel2.Name = "DebugLabel2";
|
||||
this.DebugLabel2.Size = new System.Drawing.Size(48, 14);
|
||||
this.DebugLabel2.TabIndex = 39;
|
||||
this.DebugLabel2.Text = "Debug";
|
||||
//
|
||||
// PaintForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 14F);
|
||||
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.DebugLabel2);
|
||||
this.Controls.Add(this.btnSvgExport);
|
||||
this.Controls.Add(this.panel4);
|
||||
this.Controls.Add(this.DebugLabel);
|
||||
this.Controls.Add(this.DebugLabel1);
|
||||
this.Controls.Add(this.panel3);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.panelHoverColor);
|
||||
@@ -648,6 +676,8 @@
|
||||
this.Name = "PaintForm";
|
||||
this.Text = "Paint 2";
|
||||
this.Load += new System.EventHandler(this.PaintForm_Load);
|
||||
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.PaintForm_KeyDown);
|
||||
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.PaintForm_KeyUp);
|
||||
this.Resize += new System.EventHandler(this.PaintForm_Resize);
|
||||
((System.ComponentModel.ISupportInitialize)(this.canvas)).EndInit();
|
||||
this.panelFile.ResumeLayout(false);
|
||||
@@ -711,10 +741,12 @@
|
||||
private System.Windows.Forms.Button btnEyeDrop;
|
||||
private System.Windows.Forms.Button btnLayerRemove;
|
||||
private System.Windows.Forms.Button BtnAddLayer;
|
||||
private System.Windows.Forms.Label DebugLabel;
|
||||
private System.Windows.Forms.Label DebugLabel1;
|
||||
private System.Windows.Forms.Panel pnlLayers;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Panel panel4;
|
||||
private System.Windows.Forms.Button btnSvgExport;
|
||||
private System.Windows.Forms.Label DebugLabel2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+86
-8
@@ -42,6 +42,7 @@ namespace Paint_2
|
||||
Project = new Project("Untitled project", canvas.Size);
|
||||
SelectedLayers = new List<string>();
|
||||
SelectedLayers.Add(Project.GetAllLayers()[0].Id);
|
||||
this.KeyPreview = true;
|
||||
RefreshUi();
|
||||
}
|
||||
private Point MousePositionToCanvasPosition()
|
||||
@@ -50,6 +51,7 @@ namespace Paint_2
|
||||
}
|
||||
private void canvas_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
canvas.Focus();
|
||||
Color hoveringColor = GetHoverColor();
|
||||
Point mousePosition = MousePositionToCanvasPosition();
|
||||
int toolWidth = (int)nupPencilWidth.Value;
|
||||
@@ -93,7 +95,7 @@ namespace Paint_2
|
||||
private void RefreshUi()
|
||||
{
|
||||
lsbTools.DataSource = Project.AvaibleTools;
|
||||
DebugLabel.Text = "";
|
||||
DebugLabel1.Text = "";
|
||||
|
||||
PaintTool currentTool = Project.GetCurrentTool(SelectedLayers);
|
||||
if (currentTool != null && currentTool.NeedsFullRefresh)
|
||||
@@ -131,6 +133,26 @@ namespace Paint_2
|
||||
|
||||
pbxSample.Image = DrawSample(pbxSample.Size);
|
||||
|
||||
DebugLabel1.Text = "Control";
|
||||
DebugLabel2.Text = "Shift";
|
||||
|
||||
if (Project.GetCurrentTool(SelectedLayers).IsCtrlPressed)
|
||||
{
|
||||
DebugLabel1.ForeColor = Color.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLabel1.ForeColor = Color.Red;
|
||||
}
|
||||
if (Project.GetCurrentTool(SelectedLayers).IsShiftPressed)
|
||||
{
|
||||
DebugLabel2.ForeColor = Color.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLabel2.ForeColor = Color.Red;
|
||||
}
|
||||
|
||||
if (Project.RandomColor)
|
||||
{
|
||||
btnRandomColor.BackColor = FLAT_GREEN;
|
||||
@@ -174,7 +196,7 @@ namespace Paint_2
|
||||
if (currentTool is DotPencil)
|
||||
{
|
||||
DotPencil pencil = currentTool as DotPencil;
|
||||
pencil.Start(paint_tool_color,paint_tool_width);
|
||||
pencil.Start(paint_tool_color, paint_tool_width);
|
||||
int precision = 5;
|
||||
for (int i = 0; i <= precision; i++)
|
||||
{
|
||||
@@ -192,8 +214,8 @@ namespace Paint_2
|
||||
|
||||
Point p1 = new Point(0 - paint_tool_width / 2, 0 - paint_tool_width / 2);
|
||||
Point p2 = new Point(0 - paint_tool_width / 2, size.Height + paint_tool_width / 2);
|
||||
Point p3 = new Point(size.Width / 2 - paint_tool_width / 2,size.Height + paint_tool_width / 2);
|
||||
Point p4 = new Point(size.Width / 2 - paint_tool_width / 2, 0 - paint_tool_width/2);
|
||||
Point p3 = new Point(size.Width / 2 - paint_tool_width / 2, size.Height + paint_tool_width / 2);
|
||||
Point p4 = new Point(size.Width / 2 - paint_tool_width / 2, 0 - paint_tool_width / 2);
|
||||
Point p5 = new Point(size.Width + paint_tool_width / 2, 0 - paint_tool_width / 2);
|
||||
Point p6 = new Point(size.Width + paint_tool_width / 2, size.Height + paint_tool_width / 2);
|
||||
// I KNOW THIS IS HARD CODED BUT ITS ONLY PURPOSE IS TO BE PRETTY so it does'nt matter
|
||||
@@ -221,11 +243,10 @@ namespace Paint_2
|
||||
{
|
||||
if (currentTool is RectanglePencil || currentTool is RectangleBorderPencil || currentTool is EllipsePencil || currentTool is EllipseBorderPencil)
|
||||
{
|
||||
currentTool.Start(paint_tool_color,paint_tool_width);
|
||||
currentTool.Add(new Point(0 + size.Width / 10,0 + size.Height / 10));
|
||||
currentTool.Start(paint_tool_color, paint_tool_width);
|
||||
currentTool.Add(new Point(0 + size.Width / 10, 0 + size.Height / 10));
|
||||
currentTool.Add(new Point(size.Width - size.Width / 10, size.Height - size.Height / 10));
|
||||
currentTool.Stop();
|
||||
|
||||
currentTool.Paint(map);
|
||||
}
|
||||
}
|
||||
@@ -284,7 +305,7 @@ namespace Paint_2
|
||||
int toolId = lsbTools.SelectedIndex;
|
||||
Project.ChangeTool(SelectedLayers, toolId);
|
||||
//Yeah that is a little janky but I just want to refresh the tool
|
||||
nupPencilWidth_ValueChanged(sender,e);
|
||||
nupPencilWidth_ValueChanged(sender, e);
|
||||
RefreshUi();
|
||||
}
|
||||
|
||||
@@ -468,5 +489,62 @@ namespace Paint_2
|
||||
}
|
||||
DisplayLayers();
|
||||
}
|
||||
|
||||
private void btnSvgExport_Click(object sender, EventArgs e)
|
||||
{
|
||||
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
||||
fbd.Description = "Custom Description";
|
||||
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string SelectedPath = fbd.SelectedPath;
|
||||
|
||||
if (Project.SaveSvg(SelectedPath, tbxProjectName.Text))
|
||||
{
|
||||
MessageBox.Show("Svg saved at " + SelectedPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Ooops, could not save the SVG in " + SelectedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintForm_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
//empty for now
|
||||
}
|
||||
|
||||
private void PaintForm_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.ControlKey:
|
||||
Project.CtrlDown();
|
||||
break;
|
||||
case Keys.ShiftKey:
|
||||
Project.ShiftDown();
|
||||
break;
|
||||
default:
|
||||
//send the key to the tools
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintForm_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.ControlKey:
|
||||
Project.CtrlUp();
|
||||
break;
|
||||
case Keys.ShiftKey:
|
||||
Project.ShiftUp();
|
||||
break;
|
||||
default:
|
||||
//send the key to the tools
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ using System.Drawing;
|
||||
|
||||
namespace Paint_2
|
||||
{
|
||||
public interface PaintTool:ICloneable
|
||||
public interface PaintTool : ICloneable
|
||||
{
|
||||
List<List<Point>> Drawings { get; set; }
|
||||
List<List<Point>> DrawingsRedo { get; set; }
|
||||
@@ -25,6 +25,8 @@ namespace Paint_2
|
||||
bool NeedsFullRefresh { get; set; }
|
||||
int Width { get; set; }
|
||||
string Name { get; set; }
|
||||
bool IsCtrlPressed { get; set; }
|
||||
bool IsShiftPressed { get; set; }
|
||||
|
||||
void Start(Color color, int width);
|
||||
void Stop();
|
||||
@@ -34,6 +36,7 @@ namespace Paint_2
|
||||
void Clear();
|
||||
List<Color> GetLastColors(int colorNumber);
|
||||
void Paint(Bitmap canvas);
|
||||
string PaintSVG();
|
||||
string ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,33 @@ namespace Paint_2
|
||||
result.Reverse();
|
||||
return result;
|
||||
}
|
||||
public List<Point> ConvertRectangleIntoPositive(bool IsCtrlPressed,Point start, Point end)
|
||||
{
|
||||
Point newStart = new Point(start.X, start.Y);
|
||||
Point newEnd = new Point(end.X, end.Y);
|
||||
|
||||
int xDiff = end.X - start.X;
|
||||
int yDiff = end.Y - start.Y;
|
||||
|
||||
Size size = new Size(xDiff, yDiff);
|
||||
|
||||
if (xDiff < 0)
|
||||
{
|
||||
newStart = new Point(end.X, newStart.Y);
|
||||
}
|
||||
if (yDiff < 0)
|
||||
{
|
||||
newStart = new Point(newStart.X, end.Y);
|
||||
}
|
||||
|
||||
if (IsCtrlPressed)
|
||||
{
|
||||
size = new Size(Math.Max(Math.Abs(xDiff), Math.Abs(yDiff)), Math.Max(Math.Abs(xDiff), Math.Abs(yDiff)));
|
||||
}
|
||||
|
||||
newEnd = new Point(newStart.X + Math.Abs(size.Width), newStart.Y + Math.Abs(size.Height));
|
||||
return new List<Point> { newStart, newEnd };
|
||||
}
|
||||
public Point Lerp(Point start, Point end, float t)
|
||||
{
|
||||
int xDiff = end.X - start.X;
|
||||
@@ -101,5 +128,9 @@ namespace Paint_2
|
||||
Point result = new Point(resultX, resultY);
|
||||
return result;
|
||||
}
|
||||
public string StandartPaintSVG(List<List<Point>> Drawings,List<Color> Colors, List<int> Widths)
|
||||
{
|
||||
return "COUCOU";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace Paint_2
|
||||
private List<List<Point>> _drawingsRedo;
|
||||
private PaintToolUtils Utils;
|
||||
private bool _needsFullRefresh;
|
||||
private bool _isShiftPressed;
|
||||
private bool _isCtrlPressed;
|
||||
private List<Color> _colors;
|
||||
private List<Color> _colorsRedo;
|
||||
private List<int> _widths;
|
||||
@@ -35,6 +37,8 @@ namespace Paint_2
|
||||
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; }
|
||||
@@ -78,6 +82,37 @@ namespace Paint_2
|
||||
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)
|
||||
{
|
||||
Utils.StandartStart(color, width);
|
||||
@@ -123,5 +158,7 @@ namespace Paint_2
|
||||
result.Color = Color;
|
||||
return (Object)(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+71
-6
@@ -30,6 +30,7 @@ namespace Paint_2
|
||||
private bool _drawing;
|
||||
private string _name;
|
||||
|
||||
|
||||
public List<PaintTool> AvaibleTools { get => _avaibleTools; set => _avaibleTools = value; }
|
||||
//public Sketch CurrentLayer { get => _currentSketch; set => _currentSketch = value; }
|
||||
public List<Sketch> Layers { get => _layers; set => _layers = value; }
|
||||
@@ -272,14 +273,18 @@ namespace Paint_2
|
||||
}
|
||||
public Bitmap PaintLayers()
|
||||
{
|
||||
Bitmap result = new Bitmap(CanvasSize.Width, CanvasSize.Height);
|
||||
Graphics gr = Graphics.FromImage(result);
|
||||
foreach (string layerId in LayersToPrint)
|
||||
Bitmap result = null;
|
||||
if (CanvasSize.Width != 0 && CanvasSize.Height != 0)
|
||||
{
|
||||
Sketch layer = FindSketch(Layers, layerId);
|
||||
if (layer != null)
|
||||
result = new Bitmap(CanvasSize.Width, CanvasSize.Height);
|
||||
Graphics gr = Graphics.FromImage(result);
|
||||
foreach (string layerId in LayersToPrint)
|
||||
{
|
||||
gr.DrawImage(layer.Paint(), Point.Empty);
|
||||
Sketch layer = FindSketch(Layers, layerId);
|
||||
if (layer != null)
|
||||
{
|
||||
gr.DrawImage(layer.Paint(), Point.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -416,5 +421,65 @@ namespace Paint_2
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void CtrlDown()
|
||||
{
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.CtrlDown();
|
||||
}
|
||||
}
|
||||
public void CtrlUp()
|
||||
{
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.CtrlUp();
|
||||
}
|
||||
}
|
||||
public void ShiftDown()
|
||||
{
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.ShiftDown();
|
||||
}
|
||||
}
|
||||
public void ShiftUp()
|
||||
{
|
||||
foreach (Sketch layer in Layers)
|
||||
{
|
||||
layer.ShiftUp();
|
||||
}
|
||||
}
|
||||
public string 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>";
|
||||
return fileContent;
|
||||
}
|
||||
public bool SaveSvg(string path,string fileName)
|
||||
{
|
||||
bool result = false;
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
using (StreamWriter sw = File.CreateText(path + "\\" + fileName + ".svg"))
|
||||
{
|
||||
sw.WriteLine(ConvertToSVG());
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace Paint_2
|
||||
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;
|
||||
@@ -33,6 +35,8 @@ namespace Paint_2
|
||||
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; }
|
||||
@@ -72,38 +76,59 @@ namespace Paint_2
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
Point p1 = drawing[0];
|
||||
Point p2 = drawing[1];
|
||||
Point start = drawing[0];
|
||||
Point end = drawing[1];
|
||||
|
||||
Point start = new Point(0, 0);
|
||||
Point end = new Point(0, 0);
|
||||
|
||||
if (p2.X > p1.X)
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
start.X = p1.X;
|
||||
end.X = p2.X;
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
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;
|
||||
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);
|
||||
@@ -114,10 +139,8 @@ namespace Paint_2
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
for (int i = 0; i < Drawings.Count; i++)
|
||||
{
|
||||
List<Point> Drawing = Drawings[i];
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
+42
-28
@@ -17,6 +17,8 @@ namespace Paint_2
|
||||
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;
|
||||
@@ -36,6 +38,8 @@ namespace Paint_2
|
||||
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 bool IsShiftPressed { get => _isShiftPressed; set => _isShiftPressed = value; }
|
||||
public bool IsCtrlPressed { get => _isCtrlPressed; set => _isCtrlPressed = value; }
|
||||
|
||||
public RectanglePencil(string name)
|
||||
{
|
||||
@@ -51,6 +55,7 @@ namespace Paint_2
|
||||
}
|
||||
public void Add(Point point)
|
||||
{
|
||||
|
||||
List<Point> myDrawing = Drawings[Drawings.Count - 1];
|
||||
if (myDrawing.Count == 0 || myDrawing.Count == 1)
|
||||
{
|
||||
@@ -66,44 +71,55 @@ namespace Paint_2
|
||||
{
|
||||
Graphics gr = Graphics.FromImage(canvas);
|
||||
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)
|
||||
List<Point> points;
|
||||
if (drawingCounter == Drawings.Count - 1)
|
||||
{
|
||||
start.X = p1.X;
|
||||
end.X = p2.X;
|
||||
points = Utils.ConvertRectangleIntoPositive(IsCtrlPressed, drawing[0], drawing[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
start.X = p2.X;
|
||||
end.X = p1.X;
|
||||
points = Utils.ConvertRectangleIntoPositive(false, drawing[0], drawing[1]);
|
||||
}
|
||||
if (p2.Y > p1.Y)
|
||||
{
|
||||
start.Y = p1.Y;
|
||||
end.Y = p2.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
start.Y = p2.Y;
|
||||
end.Y = p1.Y;
|
||||
}
|
||||
|
||||
gr.FillRectangle(new SolidBrush(Colors[drawingCounter]), new Rectangle(start, new Size(end.X - start.X, end.Y - start.Y)));
|
||||
gr.FillRectangle(new SolidBrush(Colors[drawingCounter]), new Rectangle(points[0], new Size(points[1].X - points[0].X, points[1].Y - points[0].Y)));
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
}
|
||||
public string PaintSVG()
|
||||
{
|
||||
string result = "";
|
||||
string newLine = Environment.NewLine;
|
||||
|
||||
int drawingCounter = 0;
|
||||
|
||||
|
||||
foreach (List<Point> drawing in Drawings)
|
||||
{
|
||||
if (drawing.Count == 2)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
Point start = points[0];
|
||||
Point end = points[1];
|
||||
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;
|
||||
}
|
||||
drawingCounter++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void Start(Color color, int width)
|
||||
{
|
||||
Utils.StandartStart(color, width);
|
||||
@@ -114,10 +130,8 @@ namespace Paint_2
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
for (int i = 0; i < Drawings.Count; i++)
|
||||
{
|
||||
List<Point> Drawing = Drawings[i];
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
+37
-2
@@ -30,7 +30,7 @@ namespace Paint_2
|
||||
public string Name { get => _name; set => _name = value; }
|
||||
public string Id { get => id; set => id = value; }
|
||||
|
||||
public Sketch(string name,Size sketchSize, List<PaintTool> toolList,string guid)
|
||||
public Sketch(string name, Size sketchSize, List<PaintTool> toolList, string guid)
|
||||
{
|
||||
IsDrawing = false;
|
||||
Id = guid;
|
||||
@@ -52,7 +52,7 @@ namespace Paint_2
|
||||
CurrentTool = null;
|
||||
}
|
||||
}
|
||||
public Sketch(List<PaintTool> toolList,string guid) : this("Layer 1",new Size(500, 500), toolList,guid)
|
||||
public Sketch(List<PaintTool> toolList, string guid) : this("Layer 1", new Size(500, 500), toolList, guid)
|
||||
{
|
||||
//empty
|
||||
}
|
||||
@@ -116,6 +116,19 @@ namespace Paint_2
|
||||
CurrentTool.Paint(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()
|
||||
{
|
||||
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
|
||||
@@ -130,6 +143,28 @@ namespace Paint_2
|
||||
//Todo
|
||||
return Color.FromArgb(0x34, 0xF4, 0xFF);
|
||||
}
|
||||
public void CtrlDown()
|
||||
{
|
||||
if (!CurrentTool.IsCtrlPressed)
|
||||
{
|
||||
CurrentTool.IsCtrlPressed = true;
|
||||
}
|
||||
}
|
||||
public void CtrlUp()
|
||||
{
|
||||
CurrentTool.IsCtrlPressed = false;
|
||||
}
|
||||
public void ShiftDown()
|
||||
{
|
||||
if (!CurrentTool.IsShiftPressed)
|
||||
{
|
||||
CurrentTool.IsShiftPressed = true;
|
||||
}
|
||||
}
|
||||
public void ShiftUp()
|
||||
{
|
||||
CurrentTool.IsShiftPressed = false;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
|
||||
Reference in New Issue
Block a user