-
Notifications
You must be signed in to change notification settings - Fork 1
/
SwitchTrack.pde
121 lines (103 loc) · 3 KB
/
SwitchTrack.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
121
public class SwitchTrack extends Element
{
private Constants.terminal _position;
public SwitchTrack(Integer id) {
super(id);
_position = Constants.terminal.B;
}
public void Toggle() {
if (_position == Constants.terminal.B) {
_position = Constants.terminal.C;
} else {
_position = Constants.terminal.B;
}
}
public void SwitchToTerminal(Constants.terminal terminal) {
_position = terminal;
}
private Map<String, Integer> GetCorners() {
Integer x1 = _x, x2 = _x + Constants.switchTrackWidth,
y1 = _y, y2 = _y - Constants.switchTrackHeight;
if (_flip) {
y2 = _y + Constants.switchTrackHeight;
}
if (_reverse) {
Integer t = x1;
x1 = x2;
x2 = t;
}
Map<String, Integer> corners = new HashMap<String, Integer>();
corners.put("x1", x1);
corners.put("x2", x2);
corners.put("y1", y1);
corners.put("y2", y2);
return corners;
}
public Boolean MouseOverCheck(Integer x, Integer y) {
Map<String, Integer> corners = GetCorners();
Integer x1 = corners.get("x1");
Integer x2 = corners.get("x2");
Integer y1 = corners.get("y1");
Integer y2 = corners.get("y2");
_mouseOverSwitchTrack = (x >= min(x1, x2) && x <= max(x1, x2)
&& y >= min(y1, y2) - (Constants.trackBoxHeight / 2) && y <= max(y1, y2) + (Constants.trackBoxHeight / 2) + 1);
return _mouseOverSwitchTrack;
}
public void Display() {
Map<String, Integer> corners = GetCorners();
Integer x1 = corners.get("x1");
Integer x2 = corners.get("x2");
Integer y1 = corners.get("y1");
Integer y2 = corners.get("y2");
if (_mouseOverSwitchTrack) {
noStroke();
fill(230);
rect(min(x1, x2), min(y1, y2) - (Constants.trackBoxHeight / 2), abs(x1-x2), abs(y1-y2) + Constants.trackBoxHeight + 1);
}
Integer highlightColor;
if (_highlight) {
highlightColor = #F5DB7E;
} else {
highlightColor = 0;
}
stroke(0);
if (_position == Constants.terminal.B) {
stroke(0);
strokeWeight(1);
line(x1, y1, x2, y2);
stroke(highlightColor);
strokeWeight(5);
line(x1, y1, x2, y1);
} else {
stroke(0);
strokeWeight(1);
line(x1, y1, x2, y1);
stroke(highlightColor);
strokeWeight(5);
line(x1, y1, x2, y2);
}
stroke(0);
strokeWeight(1);
if (Constants.useNodeCircle) {
_circle.display(x1, y1, #3EF761, 'A');
_circle.display(x2, y1, #F7923E, 'B');
_circle.display(x2, y2, #FC2424, 'C');
}
if (Constants.debug) {
int letterX;
if (!_reverse) {
letterX = x1 + abs((x1 - x2) / 2);
} else {
letterX = x1 - abs((x1 - x2) / 2);
}
int letterY;
if (!_flip) {
letterY = y1 - abs((y1 - y2) / 2);
} else {
letterY = y1 + abs((y1 - y2) / 2);
}
TextUtils text = new TextUtils().Size(20).Colour(#ffffff).OutlineColour(#000000).Align(CENTER, CENTER);
text.Text(_id.toString(), letterX, letterY);
}
}
}