diff --git a/antonclk/antonclk.app.js b/antonclk/antonclk.app.js index d0939be..0e7f42b 100644 --- a/antonclk/antonclk.app.js +++ b/antonclk/antonclk.app.js @@ -113,22 +113,24 @@ var x = w / 2; var y = g.getHeight() / 2; - if (stopWatch.start1) { - let Tt1 = Date.now() - stopWatch.start1; + if (stopWatch.start1 || stopWatch.elapsed1) { + let Tt1 = (stopWatch.elapsed1 || 0); + if (stopWatch.start1) { + Tt1 += Date.now() - stopWatch.start1; + } 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.setFontAlign(0, 0).setFont("Vector", 26).drawString(Ttxt1, x, y-45); } - if (stopWatch.start2) { - let Tt2 = Date.now() - stopWatch.start2; + if (stopWatch.start2 || stopWatch.elapsed2) { + let Tt2 = (stopWatch.elapsed2 || 0); + if (stopWatch.start2) { + Tt2 += Date.now() - stopWatch.start2; + } 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.setFontAlign(0, 0).setFont("Vector", 26).drawString(Ttxt2, x, y+76); } @@ -185,6 +187,10 @@ let startSW1 = function() { console.log("Starting stopwatch 1..."); stopWatch.start1 = Date.now(); + if (!stopWatch.elapsed1) { + stopWatch.elapsed1 = 0; + } + saveStopWatch(); if (!stopWatch1Timer) { drawStopWatches(); @@ -195,6 +201,10 @@ let startSW2 = function() { console.log("Starting stopwatch 2..."); stopWatch.start2 = Date.now(); + if (!stopWatch.elapsed2) { + stopWatch.elapsed2 = 0; + } + saveStopWatch(); if (!stopWatch1Timer) { 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) { console.log(button, xy);