-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlPanel.pde
More file actions
231 lines (194 loc) · 6.18 KB
/
ControlPanel.pde
File metadata and controls
231 lines (194 loc) · 6.18 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
218
219
220
221
222
223
224
225
226
227
228
229
230
//
// IceTimer - Graphical timer and match scheduler for pick-up ice hockey
// Copyright (C) 2014 Joe Cridge
//
// This file is part of IceTimer.
//
// IceTimer is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// IceTimer is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with IceTimer. If not, see <http://www.gnu.org/licenses/>.
//
// Joe Cridge, July 2014.
// <joe.cridge@me.com>
//
class ControlPanel {
final int FULL_ICE = 0;
final int HALF_ICE = 1;
final int THIRD_ICE = 2;
int halfIceThresh, thirdIceThresh;
boolean isActive;
String title;
color highlightColour;
PImage logo;
PFont panelFont;
Spinner hourSpinner, minSpinner, teamSpinner;
Radio simRadio;
Button startButton, endButton;
ControlPanel(String title_, PImage logo_, int endHour_, int endMin_, int nTeams_, int nSim_, int halfIceThresh_, int thirdIceThresh_) {
title = title_;
logo = logo_;
isActive = true;
highlightColour = TIMER_GREEN;
panelFont = loadFont("fonts/SquarishSansCTRegular-24.vlw");
// Store the values of non-editable properties
// These can be set in prefs.csv
halfIceThresh = halfIceThresh_;
thirdIceThresh = thirdIceThresh_;
String[] labels = {
"Full ice", "Half ice", "Third ice"
};
// Create widgets
// Padding offset is used to cope with different screen sizes
int xOffset = max(0, width/2-571);
hourSpinner = new Spinner(486+xOffset, 82, endHour_, 0, 23, 1, highlightColour, TIMER_GREY);
minSpinner = new Spinner(556+xOffset, 82, endMin_, 0, 55, 5, highlightColour, TIMER_GREY);
teamSpinner = new Spinner(486+xOffset, 110, nTeams_, 3, 30, 1, highlightColour, TIMER_GREY);
simRadio = new Radio(657+xOffset, 53, labels, nSim_-1, highlightColour, TIMER_GREY);
startButton = new Button(width-1000 >= 40 ? width-116 : width-106, 62, "START", highlightColour, TIMER_GREY);
endButton = new Button(width-1000 >= 40 ? width-116 : width-106, 104, "END", highlightColour, TIMER_GREY);
// Disable 'END' button
endButton.isActive = false;
}
void activate() {
// Enable widgets
hourSpinner.isActive = true;
minSpinner.isActive = true;
teamSpinner.isActive = true;
simRadio.isActive = true;
startButton.isActive = true;
// Disable 'END' button
endButton.isActive = false;
// Flag change
isActive = true;
}
void adjustSimRadio() {
// Makes sure that only allowed options are selectable
// Get current values
int currentIce = simRadio.getSelectedIndex();
int newNTeams = teamSpinner.getValue();
// Set default option
simRadio.enableAll();
if (newNTeams < halfIceThresh) {
simRadio.setSelected(FULL_ICE);
} else if (newNTeams >= halfIceThresh && newNTeams < thirdIceThresh) {
simRadio.setSelected(HALF_ICE);
} else {
simRadio.setSelected(THIRD_ICE);
}
// Disable options with unavailable fixtures
if (newNTeams > 12) {
simRadio.disableOption(FULL_ICE);
}
if (newNTeams < 5 || newNTeams > 17) {
simRadio.disableOption(HALF_ICE);
}
if (newNTeams < 8) {
simRadio.disableOption(THIRD_ICE);
}
}
void deactivate() {
// Disable widgets
hourSpinner.isActive = false;
minSpinner.isActive = false;
teamSpinner.isActive = false;
simRadio.isActive = false;
startButton.isActive = false;
// Enable 'END' button
endButton.isActive = true;
// Flag change
isActive = false;
}
void display() {
// Introduce variable padding to cope with different screen sizes
int xOffset = max(0, width/2-571);
// Draw shadow
for (int i = 0; i < 15; i++) {
fill(0, 0, 0, 90-6*i);
rect(0, 150+i, width, 1);
}
// Draw panel
fill(0);
rect(0, 0, width, 150);
// Draw logo
tint(highlightColour);
image(logo, 56, 28, 240, 240*(111.0/300.0));
// Print title
textFont(panelFont);
textAlign(LEFT);
fill(TIMER_GREY);
text(title, 356+xOffset, 53);
// Print labels
if (isActive) {
fill(highlightColour);
} else {
fill(TIMER_GREY);
}
text("End time", 356+xOffset, 83);
text(":", 542+xOffset, 82);
text("Teams", 356+xOffset, 111);
// Display widgets
hourSpinner.display();
minSpinner.display();
teamSpinner.display();
simRadio.display();
startButton.display();
endButton.display();
}
int getEndHour() {
return hourSpinner.getValue();
}
int getEndMin() {
return minSpinner.getValue();
}
int getNSim() {
int n = 1 + simRadio.getSelectedIndex();
return n;
}
int getNTeams() {
return teamSpinner.getValue();
}
void respond(int clickX, int clickY) {
// Delegate click to widgets
hourSpinner.respond(clickX, clickY);
minSpinner.respond(clickX, clickY);
teamSpinner.respond(clickX, clickY);
simRadio.respond(clickX, clickY);
startButton.respond(clickX, clickY);
endButton.respond(clickX, clickY);
// Adjust ice options given number of teams
if (teamSpinner.changeMade) {
adjustSimRadio();
teamSpinner.changeMade = false;
}
// Pass on start or end of session
if (startButton.wasPressed) {
startButton.wasPressed = false;
deactivate();
} else if (endButton.wasPressed) {
endButton.wasPressed = false;
activate();
}
}
void setHighlightColour(color newColour) {
highlightColour = newColour;
// Set widget colours to match
hourSpinner.setActiveColour(newColour);
minSpinner.setActiveColour(newColour);
teamSpinner.setActiveColour(newColour);
simRadio.setActiveColour(newColour);
startButton.setActiveColour(newColour);
endButton.setActiveColour(newColour);
}
void setTitle(String newTitle) {
title = newTitle;
}
}