-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawMode.cs
More file actions
143 lines (125 loc) · 4.67 KB
/
DrawMode.cs
File metadata and controls
143 lines (125 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.Intrinsics.Arm;
using System.Text;
using System.Threading.Tasks;
namespace PolygonEditor
{
internal static class DrawMode
{
private static List<PointF> newPolygon = new List<PointF>();
private static List<Edge> newEdges = new List<Edge>();
private static PointF newPoint = new PointF();
public static void colorButton_Click(object sender, EventArgs e)
{
if (newPolygon.Count > 0)
newEdges.Last().edgeColor = Manager.currentColor;
}
#region workSpace events
public static void workSpace_MouseDown(object sender, MouseEventArgs e)
{
if (newPolygon.Count != 0)
{
if (e.Button == MouseButtons.Right)
{
if (newPolygon.Count > 2)
{
Manager.polygons.Add(newPolygon.ToList());
Manager.edges.Add(newEdges.ToList());
Manager.offsets.Add(new List<PointF>());
Manager.notFixed.Add(new List<PointF>());
Manager.offsetsValue.Add(0);
}
newPolygon.Clear();
newEdges.Clear();
}
else
{
if (Manager.isNearbyPoint(e.Location, newPolygon.First())
&& newPolygon.Count > 2)
{
Manager.polygons.Add(newPolygon.ToList());
Manager.edges.Add(newEdges.ToList());
Manager.offsets.Add(new List<PointF>());
Manager.notFixed.Add(new List<PointF>());
Manager.offsetsValue.Add(0);
newEdges.Clear();
newPolygon.Clear();
}
else
{
if (e.Location != newPolygon.Last())
{
newPolygon.Add(e.Location);
newEdges.Add(new Edge());
newEdges.Last().edgeColor = Manager.currentColor;
}
}
}
}
else if (e.Button == MouseButtons.Left)
{
newPolygon = new List<PointF>();
newEdges = new List<Edge>();
newPoint = e.Location;
newPolygon.Add(newPoint);
newEdges.Add(new Edge());
newEdges.Last().edgeColor = Manager.currentColor;
}
((PictureBox)sender).Invalidate();
}
public static void workSpace_MouseMove(object sender, MouseEventArgs e)
{
if (newPolygon.Count != 0)
{
newPoint = e.Location;
((PictureBox)sender).Invalidate();
}
}
private static void drawNewPolygon(PaintEventArgs e)
{
Graphics g = e.Graphics;
for (int j = 0; j < newPolygon.Count - 1; j++)
{
if (Manager.drawSet == DrawSet.Lib)
{
Manager.p.Color = newEdges[j].edgeColor;
g.DrawLine(Manager.p, newPolygon[j], newPolygon[j + 1]);
}
else
Manager.bresenhamDrawLine(g, newEdges[j].edgeColor, newPolygon[j], newPolygon[j + 1]);
Manager.drawVertex(g, newPolygon[j]);
}
Manager.drawVertex(g, newPolygon.Last());
if (Manager.drawSet == DrawSet.Lib)
{
Manager.dp.DashPattern = new float[] { 4.0F, 2.0F, 1.0F, 3.0F };
Manager.dp.Color = Manager.currentColor;
g.DrawLine(Manager.dp, newPolygon.Last(), newPoint);
}
else
Manager.bresenhamDrawLine(g, Manager.currentColor, newPolygon.Last(), newPoint);
}
public static void workSpace_Paint(object sender, PaintEventArgs e)
{
Manager.drawPolygons(sender, e);
if (newPolygon.Count != 0)
drawNewPolygon(e);
}
public static void workSpace_MouseUp(object sender, MouseEventArgs e)
{
((PictureBox)sender).Invalidate();
}
#endregion
public static void MainForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
newPolygon.Clear();
newEdges.Clear();
}
}
}
}