feat: Implement pause and stop functions for stopwatches

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-03-09 13:29:58 -06:00
parent dda3130c56
commit f96bddf0ba

View File

@@ -113,22 +113,24 @@
var x = w / 2; var x = w / 2;
var y = g.getHeight() / 2; var y = g.getHeight() / 2;
if (stopWatch.start1 || stopWatch.elapsed1) {
let Tt1 = (stopWatch.elapsed1 || 0);
if (stopWatch.start1) { if (stopWatch.start1) {
let Tt1 = Date.now() - stopWatch.start1; Tt1 += Date.now() - stopWatch.start1;
}
let Ttxt1 = timeToText(Tt1); let Ttxt1 = timeToText(Tt1);
//g.drawLine(0, y-60, w, y-60);
//g.drawLine(0, y-34, w, y-34);
g.clearRect(0, y-60, w, y-34); g.clearRect(0, y-60, w, y-34);
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(Ttxt1, x, y-45); g.setFontAlign(0, 0).setFont("Vector", 26).drawString(Ttxt1, x, y-45);
} }
if (stopWatch.start2 || stopWatch.elapsed2) {
let Tt2 = (stopWatch.elapsed2 || 0);
if (stopWatch.start2) { if (stopWatch.start2) {
let Tt2 = Date.now() - stopWatch.start2; Tt2 += Date.now() - stopWatch.start2;
}
let Ttxt2 = timeToText(Tt2); let Ttxt2 = timeToText(Tt2);
//g.drawLine(0, y+88, w, y+88);
//g.drawLine(0, y+61, w, y+61);
g.clearRect(0, y+61, w, y+88); g.clearRect(0, y+61, w, y+88);
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(Ttxt2, x, y+76); g.setFontAlign(0, 0).setFont("Vector", 26).drawString(Ttxt2, x, y+76);
} }
@@ -185,6 +187,10 @@
let startSW1 = function() { let startSW1 = function() {
console.log("Starting stopwatch 1..."); console.log("Starting stopwatch 1...");
stopWatch.start1 = Date.now(); stopWatch.start1 = Date.now();
if (!stopWatch.elapsed1) {
stopWatch.elapsed1 = 0;
}
saveStopWatch();
if (!stopWatch1Timer) { if (!stopWatch1Timer) {
drawStopWatches(); drawStopWatches();
@@ -195,6 +201,10 @@
let startSW2 = function() { let startSW2 = function() {
console.log("Starting stopwatch 2..."); console.log("Starting stopwatch 2...");
stopWatch.start2 = Date.now(); stopWatch.start2 = Date.now();
if (!stopWatch.elapsed2) {
stopWatch.elapsed2 = 0;
}
saveStopWatch();
if (!stopWatch1Timer) { if (!stopWatch1Timer) {
drawStopWatches(); drawStopWatches();
@@ -202,6 +212,66 @@
} }
} }
let pauseSW1 = function() {
if (!stopWatch.start1) return;
stopWatch.elapsed1 += Date.now() - stopWatch.start1;
stopWatch.start1 = null;
saveStopWatch();
if (!stopWatch.start2) {
if (stopWatch1Timer) {
clearInterval(stopWatch1Timer);
stopWatch1Timer = null;
}
}
drawStopWatches();
};
let stopSW1 = function() {
stopWatch.start1 = null;
stopWatch.elapsed1 = null;
saveStopWatch();
if (!stopWatch.start2) {
if (stopWatch1Timer) {
clearInterval(stopWatch1Timer);
stopWatch1Timer = null;
}
}
paintFace();
drawStopWatches();
};
let pauseSW2 = function() {
if (!stopWatch.start2) return;
stopWatch.elapsed2 += Date.now() - stopWatch.start2;
stopWatch.start2 = null;
saveStopWatch();
if (!stopWatch.start1) {
if (stopWatch1Timer) {
clearInterval(stopWatch1Timer);
stopWatch1Timer = null;
}
}
drawStopWatches();
};
let stopSW2 = function() {
stopWatch.start2 = null;
stopWatch.elapsed2 = null;
saveStopWatch();
if (!stopWatch.start1) {
if (stopWatch1Timer) {
clearInterval(stopWatch1Timer);
stopWatch1Timer = null;
}
}
paintFace();
drawStopWatches();
};
let handleTouch = function(button, xy) { let handleTouch = function(button, xy) {
console.log(button, xy); console.log(button, xy);