diff --git a/apps.json b/apps.json index e5e9f8f02..33dae37c7 100644 --- a/apps.json +++ b/apps.json @@ -5062,5 +5062,21 @@ {"name":"ltherm.app.js","url":"app.js"}, {"name":"ltherm.img","url":"icon.js","evaluate":true} ] + }, + { + "id": "touchtimer", + "name": "Touch Timer", + "shortName": "Touch Timer", + "version": "0.01", + "description": "Quickly and easily create a timer touch-only.", + "icon": "app.png", + "tags": "tools", + "supports": ["BANGLEJS2"], + "readme": "README.md", + "storage": [ + { "name": "touchtimer.app.js", "url": "app.js" }, + { "name": "touchtimer.boot.js", "url": "boot.js" }, + { "name": "touchtimer.img", "url": "app-icon.js", "evaluate": true } + ] } ] diff --git a/apps/touchtimer/ChangeLog b/apps/touchtimer/ChangeLog new file mode 100644 index 000000000..193a476aa --- /dev/null +++ b/apps/touchtimer/ChangeLog @@ -0,0 +1 @@ +0.01: Initial creation of the touch timer app \ No newline at end of file diff --git a/apps/touchtimer/README.md b/apps/touchtimer/README.md new file mode 100644 index 000000000..99c755639 --- /dev/null +++ b/apps/touchtimer/README.md @@ -0,0 +1,3 @@ +# Touch Timer + +Quickly and easily create a timer touch-only. diff --git a/apps/touchtimer/app-icon.js b/apps/touchtimer/app-icon.js new file mode 100644 index 000000000..d58446bcc --- /dev/null +++ b/apps/touchtimer/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwkE/4A3mUQIAMRkYWQkBaFiQWQgMjn8zGYUDCxkxFA3zD4MfCxXygECMAURiReCDAM/IpUBFIJ2CAAIeB+ZJKBYI8BCwMBiABBDARSBC5EwFwMwEwUwh5FCEIJhJiEfGIIXC+IQBSwQeBNYR1Gn4xB+MDDYITBiEzFoIOCC4vwEAIxBAwQzBAoQtCBgaNEh4iEAwMwRQXxHgRnBLwsvFQJdCFoIGBl55DH4QAEEIK/BC4KjBC4RECiED+RnBXooxCn4uBKwPwgIiB+fxgQQCRwgeBLwRbBkAXBh5yCBwoACEAoVBC4fwJ4I+DC5EjJQQXDBYP/kJWDC4qmBBYYXFfIQXKiQvUL6AXGR5LzBR4YXIBAS/BC4UCeAQOFC4rvDN4LvCFYMgd4IXJmEABgMxC4bWBiADDC45EBZIRHBMYINCBQQXIIgIkB//wgIFDmBKBC5QNB+UDboU/kEzgCRBC5QTBNwUxLoZRDC5J5EmAqBkEAiYMCC5XzFIMRkECAgILDC5YYDAAUBIoQXNDAMhiMRkYJEC5oAKC7qKBACDfCK4IWRPwjqBkczAB0yGAcQGgYAOmByCfAYAP+MBC4QWR//yC4ciACMhC4YATC4T9BACUSLiQAdA=")) \ No newline at end of file diff --git a/apps/touchtimer/app.js b/apps/touchtimer/app.js new file mode 100644 index 000000000..7ffce959f --- /dev/null +++ b/apps/touchtimer/app.js @@ -0,0 +1,92 @@ +var DEBUG = true; + +var main = () => { + var button0 = new Button({ x1: 0, y1: 35, x2: 58, y1: 70 }, 0); + + button0.draw(); + + button0.onClick((value) => { + log("button with value clicked"); + log(value); + }); +}; + +// lib functions + +var log = (message) => { + if (DEBUG) { + console.log(JSON.stringify(message)); + } +}; + +var touchHandlers = []; + +Bangle.on("touch", (_button, xy) => { + touchHandlers.forEach((touchHandler) => { + touchHandler(xy); + }); +}); + +var BUTTON_BORDER_WITH = 2; + +class Button { + constructor(position, value) { + this.position = position; + this.value = value; + + this.onClickCallbacks = []; + + touchHandlers.push((xy) => { + var x = xy.x; + var y = xy.y; + + if ( + x >= this.position.x1 && + x <= this.position.x2 && + y >= this.position.y1 && + y <= this.position.y2 + ) { + this.onClickCallbacks.forEach((onClickCallback) => + onClickCallback(this.value) + ); + } + }); + } + + draw() { + g.clear(); + + g.setColor(g.theme.fg); + g.fillRect( + this.position.x1, + this.position.y1, + this.position.x2, + this.position.y2 + ); + + g.setColor(g.theme.bg); + g.fillRect( + this.position.x1 + BUTTON_BORDER_WITH, + this.position.y1 + BUTTON_BORDER_WITH, + this.position.x2 - BUTTON_BORDER_WITH, + this.position.y2 - BUTTON_BORDER_WITH + ); + + g.setColor(g.theme.fg); + g.setFontAlign(0, 0); + g.setFont("Vector", 40); + g.drawString( + this.value, + this.position.x2 - this.position.x1, + this.position.y2 - this.position.y1 + ); + } + + onClick(callback) { + this.onClickCallbacks.push(callback); + } +} + +// start main function + +main(); diff --git a/apps/touchtimer/app.png b/apps/touchtimer/app.png new file mode 100644 index 000000000..8ccdb17f0 Binary files /dev/null and b/apps/touchtimer/app.png differ