-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathConnectionTracker.cs
More file actions
217 lines (189 loc) · 4.66 KB
/
ConnectionTracker.cs
File metadata and controls
217 lines (189 loc) · 4.66 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using System;
using System.Collections;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
namespace Netron.GraphLib
{
/// <summary>
/// Tracker for connection objects.
/// </summary>
[Serializable]
public class ConnectionTracker : Tracker
{
#region Fields
private ArrayList grips = new ArrayList();
#endregion
#region Constructor
/// <summary>
/// Default constructor.
/// </summary>
public ConnectionTracker() : base() {}
/// <summary>
/// Constructor for a connection tracker with a list of connection segment points for the handles
/// </summary>
/// <param name="l">list of points for the handles</param>
public ConnectionTracker(ArrayList l) : base()
{
if (l != null)
{
grips = l;
}
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="points"></param>
public ConnectionTracker(PointF[] points) :base()
{
for(int k=0; k<points.Length; k++)
{
grips.Add(points[k]);
}
}
/// <summary>
/// Constructor for a connection tracker with a list of connection segment points for
/// the handles and a resize state.
/// </summary>
/// <param name="l">list of points for the handles</param>
/// <param name="resizable">Resize state.</param>
public ConnectionTracker(ArrayList l, bool resizable) : base(resizable)
{
if (l != null)
{
grips = l;
}
}
#endregion
#region Methods
/// <summary>
/// Starts tracking.
/// </summary>
/// <param name="p">Current mouse location</param>
/// <param name="h">Handle</param>
public override void Start(PointF p, Point h)
{
if( h.X < 0 || h.X > grips.Count )
return;
base.Start( p, h );
}
/// <summary>
/// Performs a hit check.
/// </summary>
/// <param name="p">Current mouse location</param>
/// <returns>Grip</returns>
public override Point Hit(PointF p)
{
if( Resizable )
{
for (int i=0; i<grips.Count; i++ )
{
PointF pt = (PointF) grips[i];
RectangleF r = new RectangleF(pt.X,pt.Y,0,0);
r.Inflate(3,3);
if( r.Contains( p ) )
return new Point(i+1,0);
}
}
return Point.Empty;
}
/// <summary>
/// Returns cursor to a point
/// </summary>
/// <param name="p">Current mouse location</param>
/// <returns>Cursor</returns>
public override Cursor Cursor(PointF p)
{
Point h = Hit(p);
if (h == Point.Empty) return Cursors.No;
return MouseCursors.Grip;
}
/// <summary>
/// Moves the tracking rectangle
/// </summary>
/// <param name="p">Current mouse location</param>
/// <param name="maxSize"></param>
/// <param name="snap"></param>
/// <param name="snapSize"></param>
public override void Move(PointF p,Size maxSize, bool snap, int snapSize)
{
Point h = mCurrentHandle;
if( h.X < 0 || h.X > grips.Count )
return;
if( h.X == 0 )
{
for( int i=0; i<grips.Count; i++)
{
PointF pt = (PointF)grips[i];
PointF a = new PointF(0,0);
a.X = p.X - mCurrentPoint.X;
a.Y = p.Y - mCurrentPoint.Y;
pt.X += a.X;
pt.Y += a.Y;
grips[i] = pt;
}
}
else
{
PointF pt = (PointF)grips[h.X-1];
PointF a = new PointF(0,0);
a.X = p.X - mCurrentPoint.X;
a.Y = p.Y - mCurrentPoint.Y;
pt.X += a.X;
pt.Y += a.Y;
grips[h.X-1] = pt;
}
mCurrentPoint = p;
}
/// <summary>
/// Moves the tracking rectangle
/// </summary>
/// <param name="p">Current mouse location</param>
public virtual void MoveAll(PointF p)
{
for( int i=0; i<grips.Count; i++)
{
PointF pt = (PointF)grips[i];
PointF a = new PointF(0,0);
a.X = p.X - mCurrentPoint.X;
a.Y = p.Y - mCurrentPoint.Y;
pt.X += a.X;
pt.Y += a.Y;
grips[i] = pt;
}
mCurrentPoint = p;
}
/// <summary>
/// Paints the tracker.
/// </summary>
/// <param name="g"></param>
public override void Paint(Graphics g)
{
if (!Resizable)
return;
foreach (PointF p in grips )
{
if ((p.X != 0) || (p.Y != 0))
{
RectangleF r = new RectangleF(p.X-4,p.Y-4,8,8);
g.FillRectangle(new SolidBrush(Color.Green), r.X, r.Y, r.Width - 1, r.Height - 1);
g.DrawRectangle(new Pen(Color.Black, 1), r.X, r.Y, r.Width - 1, r.Height - 1);
}
}
}
/// <summary>
/// Gets the grip rectangle
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override RectangleF Grip(Point p)
{
RectangleF r = new RectangleF(0, 0, handleSize.Width, handleSize.Height);
PointF pt = (PointF)grips[p.X-1];
r.X = pt.X - handleSize.Width/2+1;
r.Y = pt.Y - handleSize.Height/2+1;
return r;
}
#endregion
}
}