-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathConnectionPainter.cs
More file actions
165 lines (153 loc) · 3.9 KB
/
ConnectionPainter.cs
File metadata and controls
165 lines (153 loc) · 3.9 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
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.Serialization;
namespace Netron.GraphLib
{
/// <summary>
/// Abstract base class to paint a connection
/// </summary>
[Serializable] public abstract class ConnectionPainter : ISerializable
{
#region Fields
/// <summary>
/// the underlying connection of this painter
/// </summary>
private Connection mConnection;
/// <summary>
/// the pen to draw with
/// </summary>
[NonSerialized] private Pen mPen;
/// <summary>
/// whether the connection is selected
/// </summary>
private bool mSelected ;
/// <summary>
/// whether the connection is hovered
/// </summary>
private bool mIsHovered ;
/// <summary>
/// the set of points to use when drawing
/// </summary>
private PointF[] mPoints;
#endregion
#region Constructor
/// <summary>
/// Creates a connection painter based on the given connection
/// </summary>
/// <param name="connection"></param>
protected ConnectionPainter(Connection connection)
{
mConnection = connection;
mPen = connection.Pen;
mPoints = connection.GetConnectionPoints();
}
/// <summary>
/// Deserialization constructor
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
protected ConnectionPainter(SerializationInfo info, StreamingContext context)
{
//nothing; the connection is set via the property and this will init the mPoints
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the connection this painter paints
/// </summary>
public Connection Connection
{
get{return mConnection;}
set{
//this property set is not supposed to be used but cannot make it separately internal from the get property in Net1.1
mConnection = value;
mPen = value.Pen;
mPoints = value.GetConnectionPoints();
}
}
/// <summary>
/// Gets or sets the points upon which the painting of this connection painter is based
/// </summary>
public virtual PointF[] Points
{
get{return mPoints;}
set{mPoints = value;}
}
/// <summary>
/// Gets or sets whether the mouse is hovering over this object
/// </summary>
internal virtual bool IsHovered
{
get{return mIsHovered;}
set
{
mIsHovered = value;
if(value) mPen.Width=2F; else mPen.Width=1F;
}
}
/// <summary>
/// Gets or sets whether the connection is selected
/// </summary>
public virtual bool Selected
{
get{return mSelected;}
set
{
mSelected = value;
mPen = mConnection.Pen;
//showManips = value;
}
}
/// <summary>
/// Gets or sets the pen used by the painter
/// </summary>
public Pen Pen
{
get{return mPen;}
set{mPen = value;}
}
#endregion
#region Methods
/// <summary>
/// Post-deserialization actions
/// </summary>
public virtual void PostDeserialization()
{
mPen = mConnection.Pen;
}
/// <summary>
/// Handles the addition of a new (intermediate) connection point
/// </summary>
/// <param name="p"></param>
internal virtual void AddConnectionPoint(PointF p){}
/// <summary>
/// Handles the removal of an (intermediate) connection point
/// </summary>
/// <param name="p"></param>
internal virtual void RemoveConnectionPoint(PointF p){}
/// <summary>
/// Paints the connection on the canvas
/// </summary>
/// <param name="g"></param>
public virtual void Paint(Graphics g){}
/// <summary>
/// Returns true if the given point hit the connection
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public virtual bool Hit(PointF p){return false;}
#endregion
#region ISerializable Members
/// <summary>
/// Serializator
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
//nothing; the connection is serialized elsewhere
}
#endregion
}
}