Merge pull request #3210 from shansou504/master

Binaryclk - add settings to hide unused squares and to show date
pull/3218/head
Rob Pilling 2024-02-27 22:05:37 +00:00 committed by GitHub
commit 8dd0df6b86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 50 additions and 10 deletions

View File

@ -1,3 +1,4 @@
0.01: Added app
0.02: Removed unneeded squares
0.03: Added settings with fullscreen option
0.03: Added setting for fullscreen option
0.04: Added settings to hide unused squares and show date

View File

@ -1,11 +1,15 @@
var settings = Object.assign({
fullscreen: false,
fullscreen: false,
hidesq: false,
showdate: false,
}, require('Storage').readJSON("binaryclk.json", true) || {});
function draw() {
var dt = new Date();
var h = dt.getHours(), m = dt.getMinutes();
var h = dt.getHours(), m = dt.getMinutes(), d = dt.getDate();
const t = [];
t[0] = Math.floor(h/10);
t[1] = Math.floor(h%10);
t[2] = Math.floor(m/10);
@ -17,25 +21,44 @@ function draw() {
let i = 0;
var gap = 8;
var mgn = 20;
if (settings.fullscreen) {
gap = 12;
mgn = 0;
}
const sq = 29;
var pos = sq + gap;
for (let r = 3; r >= 0; r--) {
for (let c = 0; c < 4; c++) {
if (t[c] & Math.pow(2, r)) {
g.fillRect(mgn/2 + gap + c * pos, mgn + gap + i * pos, mgn/2 + gap + c * pos + sq, mgn + gap + i * pos + sq);
g.fillRect(Math.floor(mgn/2) + gap + c * pos, mgn + gap + i * pos, Math.floor(mgn/2) + gap + c * pos + sq, mgn + gap + i * pos + sq);
} else {
g.drawRect(mgn/2 + gap + c * pos, mgn + gap + i * pos, mgn/2 + gap + c * pos + sq, mgn + gap + i * pos + sq);
g.drawRect(Math.floor(mgn/2) + gap + c * pos, mgn + gap + i * pos, Math.floor(mgn/2) + gap + c * pos + sq, mgn + gap + i * pos + sq);
}
}
i++;
}
g.clearRect(mgn/2 + gap, mgn + gap, mgn/2 + gap + sq, mgn + 2 * gap + 2 * sq);
g.clearRect(mgn/2 + 3 * gap + 2 * sq, mgn + gap, mgn/2 + 3 * gap + 3 * sq, mgn + gap + sq);
var c1sqhide = 0;
var c3sqhide = 0;
if (settings.hidesq) {
c1sqhide = 2;
c3sqhide = 1;
}
if (settings.hidesq) {
g.clearRect(Math.floor(mgn/2), mgn, Math.floor(mgn/2) + pos, mgn + c1sqhide * pos);
g.clearRect(Math.floor(mgn/2) + 2 * pos + gap, mgn, Math.floor(mgn/2) + 3 * pos, mgn + c3sqhide * pos);
}
if (settings.showdate) {
g.setFontAlign(0, 0);
g.setFont("Vector",20);
g.drawRect(Math.floor(mgn/2) + gap, mgn + gap, Math.floor(mgn/2) + gap + sq, mgn + gap + sq);
g.drawString(d, Math.ceil(mgn/2) + gap + Math.ceil(sq/2) + 1, mgn + gap + Math.ceil(sq/2) + 1);
}
}
g.clear();

View File

@ -1,8 +1,8 @@
{
"id": "binaryclk",
"name": "Bin Clock",
"version": "0.03",
"description": "Clock face to show binary time in 24 hr format",
"version": "0.04",
"description": "Clock face to show binary time in 24 hour format",
"icon": "app-icon.png",
"screenshots": [{"url":"screenshot.png"}],
"type": "clock",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -2,6 +2,8 @@
var FILE = "binaryclk.json";
var settings = Object.assign({
fullscreen: false,
hidesq: false,
showdate: false,
}, require('Storage').readJSON(FILE, true) || {});
function writeSettings() {
@ -16,7 +18,21 @@
onchange: v => {
settings.fullscreen = v;
writeSettings();
}
},
},
'Hide Squares': {
value: settings.hidesq,
onchange: v => {
settings.hidesq = v;
writeSettings();
},
},
'Show Date': {
value: settings.showdate,
onchange: v => {
settings.showdate = v;
writeSettings();
},
},
});
})