-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
191 lines (150 loc) · 4.05 KB
/
sketch.js
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
const modeNormal = "Normal" // Normal clock
const modeAutoTest = "AutoTest" // Test all minutes automatically, start at 01:00
const modeManualTest = "ManualTest" // Test all hours (1-12) and then all 5 minutes intervalls.
const modeEffectTest = "EffectTest" // Test minute switcher test.
const defaultMode = modeManualTest;
const millisecondsPerMinute = 60000;
const defaultSize = 600;
var timeDiplayer;
var t;
var mousePressedEventStart; // Remember the time when mouse was pressed (to check if it was hold for 1s)
var mouseReleasedEvent; // Remember when the mouse was released (to check for doubleClick)
var mode = defaultMode;
var hint = "";
var isFullScreen = false;
var eventLog = [];
var settings;
function setup() {
noLoop();
settings = new Settings();
createCanvas(defaultSize, defaultSize);
timeDiplayer = new TimeDisplayer(new LanguageTimeObjPlatt);
frameRate(1);
setMode(defaultMode);
}
// --------------------------------------------------------------------
function draw() {
if (mode == modeNormal)
t = new Date();
timeDiplayer.displayTime(t);
if (mode == modeAutoTest) {
// Autotest: Add 1 minute for next draw
t.setTime(t.getTime() + 1 * millisecondsPerMinute); // add 1 minute
}
else if (mode == modeManualTest) {
// Manual test: Add 1h or 5min, draw at mouseclick
let delta = 5 * millisecondsPerMinute;
if (t.getHours() != 11 && t.getHours() != 23)
delta = delta * 12;
t.setTime(t.getTime() + delta);
}
// Hint to toggle
textAlign(CENTER, TOP);
textSize(9);
fill(0);
text(hint, width/2, 2);
showEvents();
}
// --------------------------------------------------------------------
function mousePressed() {
eventLog.push("Mouse Pressed");
showEvents();
mousePressedEventStart = new Date();
}
function mouseReleased() {
eventLog.push("Mouse Released");
showEvents();
let now = new Date();
if (now - mouseReleasedEvent < 200)
toggleFullscreen();
else if (new Date() - mousePressedEventStart > 1000)
toggleMode();
mouseReleasedEvent = now;
}
function mouseClicked() {
eventLog.push("Mouse Clicked");
showEvents();
if (mode == modeEffectTest || mode == modeManualTest) draw();
}
function toggleFullscreen() {
isFullScreen = !isFullScreen;
if (isFullScreen) {
if (!fullscreen()) fullscreen(true);
resizeCanvas(windowWidth, windowHeight);
}
else {
if (fullscreen()) fullscreen(false);
resizeCanvas(defaultSize, defaultSize);
}
timeDiplayer.setSize();
draw();
}
function windowResized() {
if (isFullScreen) {
resizeCanvas(windowWidth, windowHeight);
timeDiplayer.setSize();
draw();
}
}
function keyPressed() {
eventLog.push("Key Pressed");
showEvents();
toggleMode();
}
/*
function touchStarted() {
eventLog.push("Touch started");
showEvents();
mousePressedEventStart = new Date();
}
function touchEnded() {
eventLog.push("Touch ended");
showEvents();
if (new Date() - mousePressedEventStart > 1000)
toggleMode();
}
*/
function showEvents() {
textSize(9);
textAlign(LEFT, TOP);
for (let i=0; i<eventLog.length; i++)
text(eventLog[i], 4, 10+i*10);
}
function toggleMode() {
// Toggle between Debug and Normal mode
if (mode == modeManualTest)
setMode(modeNormal)
else if (mode == modeNormal)
setMode(modeManualTest);
}
function setMode(_mode)
{
mode = _mode
switch (mode) {
case modeNormal:
hint = "press any key or hold mouse for 1 second to switch to debug mode";
settings.minuteSwitchIntervall = 1;
loop();
break;
case modeManualTest:
hint = "press any key or hold mouse for 1 second to switch to clock mode." + char(10) + "Click to display next time.";
t = new Date(2000, 1, 1, 12, 0);
noLoop();
settings.minuteSwitchIntervall = 0;
break;
case modeAutoTest:
hint = ""
t = new Date(2000, 1, 1, 12, 0);
loop();
settings.minuteSwitchIntervall = 0;
break;
case modeEffectTest:
hint = ""
noLoop();
settings.minuteSwitchIntervall = 1;
timeDiplayer.minuteSwitcher.isMinuteSwitchTest = true;
break;
}
hint = hint + (hint.length > 0 ? char(10) : "") + "Double click to toggle full screen mode."
draw();
}