forked from bferdinandus/SwitchBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Track.pde
120 lines (97 loc) · 2.62 KB
/
Track.pde
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
public class Track extends Element
{
private Integer _length, _lengthInSwitchTracks = 1;
private Boolean _diagonal=false;
public Track(Integer id) {
super(id);
calculateLength();
}
public Boolean Diagonal() {
return _diagonal;
}
public void Diagonal(Boolean diagonal) {
_diagonal = diagonal;
}
public Integer LengthInSwitchTracks() {
return _lengthInSwitchTracks;
}
public void LengthInSwitchTracks(Integer lengthInSwitchTracks) {
_lengthInSwitchTracks = lengthInSwitchTracks;
calculateLength();
}
public Integer Length() {
return _length;
}
public Boolean MouseOverCheck(Integer x, Integer y) {
Integer x1 = _x, x2 = _x + _length,
y1 = _y, y2 = _y;
if (_diagonal) {
if (_flip) {
y2 = _y + Constants.switchTrackHeight;
} else {
y2 = _y - Constants.switchTrackHeight;
}
}
y1 -= (Constants.trackBoxHeight / 2);
y2 += (Constants.trackBoxHeight / 2) + 1;
_mouseOverSwitchTrack = (x >= x1 && x <= x2
&& y >= y1 && y <= y2);
return _mouseOverSwitchTrack;
}
public void Display() {
Integer x1 = _x, x2 = _x + _length,
y1 = _y, y2 = _y;
if (_diagonal) {
if (_flip) {
y2 = _y + Constants.switchTrackHeight;
} else {
y2 = _y - Constants.switchTrackHeight;
}
}
if (_mouseOverSwitchTrack) {
noStroke();
fill(230);
rect(x1, y1 - (Constants.trackBoxHeight / 2), _length, Constants.trackBoxHeight + abs(y1 - y2) + 1);
}
stroke(0);
strokeWeight(5);
if (_highlight) {
stroke(#F5DB7E);
} else {
stroke(0);
}
line(x1, y1, x2, y2);
if (Constants.useNodeCircle) {
_circle.display(x1, y1, #3EF761, 'A');
_circle.display(x2, y2, #F7923E, 'B');
}
if (Constants.debug) {
Integer letterX = x1 + abs((x1 - x2) / 2);
int letterY;
if (!_flip) {
letterY = y1 - abs((y1 - y2) / 2);
} else {
letterY = y1 + abs((y1 - y2) / 2);
}
textSize(20);
textAlign(CENTER, CENTER);
fill(#000000);
text(_id, letterX-1, letterY);
text(_id, letterX+1, letterY);
text(_id, letterX, letterY-1);
text(_id, letterX, letterY+1);
fill(#ffffff);
text(_id, letterX, letterY);
}
}
private void calculateLength() {
_length = _lengthInSwitchTracks * Constants.switchTrackWidth + (_lengthInSwitchTracks - 1) * circleDiameter();
}
private Integer circleDiameter() {
Integer circleDiameter = Constants.circleDiameter;
if (!Constants.useNodeCircle) {
circleDiameter = 0;
}
return circleDiameter;
}
}