commit
fda5a9fc6e
|
|
@ -4117,14 +4117,17 @@
|
||||||
{
|
{
|
||||||
"id": "vectorclock",
|
"id": "vectorclock",
|
||||||
"name": "Vector Clock",
|
"name": "Vector Clock",
|
||||||
"version": "0.02",
|
"version": "0.03",
|
||||||
"description": "A digital clock that uses the built-in vector font.",
|
"description": "A digital clock that uses the built-in vector font.",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"type": "clock",
|
"type": "clock",
|
||||||
"tags": "clock",
|
"tags": "clock",
|
||||||
"supports": ["BANGLEJS"],
|
"supports": ["BANGLEJS", "BANGLEJS2"],
|
||||||
"allow_emulator": true,
|
"allow_emulator": true,
|
||||||
"screenshots": [{"url":"bangle1-vector-clock-screenshot.png"}],
|
"screenshots": [
|
||||||
|
{"url":"bangle2-vector-clock-screenshot.png"},
|
||||||
|
{"url":"bangle1-vector-clock-screenshot.png"}
|
||||||
|
],
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"vectorclock.app.js","url":"app.js"},
|
{"name":"vectorclock.app.js","url":"app.js"},
|
||||||
{"name":"vectorclock.img","url":"app-icon.js","evaluate":true}
|
{"name":"vectorclock.img","url":"app-icon.js","evaluate":true}
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
0.1: New watch face
|
0.1: New watch face
|
||||||
0.2: Use Bangle.setUI for button/launcher handling
|
0.2: Use Bangle.setUI for button/launcher handling
|
||||||
|
0.3: Bangle.js 2 support
|
||||||
|
|
@ -5,9 +5,10 @@ function padNum(n, l) {
|
||||||
return ("0".repeat(l)+n).substr(-l);
|
return ("0".repeat(l)+n).substr(-l);
|
||||||
}
|
}
|
||||||
|
|
||||||
let rects = {};
|
var rects = {};
|
||||||
let rectsToClear = {};
|
var rectsToClear = {};
|
||||||
let commands = [];
|
var commands = [];
|
||||||
|
var showSeconds = true;
|
||||||
|
|
||||||
function pushCommand(command) {
|
function pushCommand(command) {
|
||||||
let hash = E.CRC32(E.toJS(arguments));
|
let hash = E.CRC32(E.toJS(arguments));
|
||||||
|
|
@ -20,17 +21,20 @@ function executeCommands() {
|
||||||
"ram";
|
"ram";
|
||||||
for (let hash in rectsToClear) delete rects[hash];
|
for (let hash in rectsToClear) delete rects[hash];
|
||||||
for (let r of rectsToClear) if (r) g.clearRect(r.x1, r.y1, r.x2, r.y2);
|
for (let r of rectsToClear) if (r) g.clearRect(r.x1, r.y1, r.x2, r.y2);
|
||||||
g.getModified(true);
|
for (let c of commands) rects[c.hash] = c.command();
|
||||||
for (let c of commands) {
|
|
||||||
c.command();
|
|
||||||
rects[c.hash] = g.getModified(true);
|
|
||||||
}
|
|
||||||
rectsToClear = Object.assign({}, rects);
|
rectsToClear = Object.assign({}, rects);
|
||||||
commands = [];
|
commands = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawVectorText(text, size, x, y, alignX, alignY) {
|
function drawVectorText(text, size, x, y, alignX, alignY) {
|
||||||
g.setFont("Vector", size).setFontAlign(alignX, alignY).drawString(text, x, y);
|
g.setFont("Vector", size).setFontAlign(alignX, alignY).drawString(text, x, y);
|
||||||
|
var m = g.stringMetrics(text);
|
||||||
|
return {
|
||||||
|
x1: x - m.width * (alignX / 2 + 0.5),
|
||||||
|
y1: y - m.height * (alignY / 2 + 0.5),
|
||||||
|
x2: x - m.width * (alignX / 2 - 0.5),
|
||||||
|
y2: y - m.height * (alignY / 2 - 0.5)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
|
|
@ -43,11 +47,12 @@ function draw() {
|
||||||
let secondsText = padNum(d.getSeconds(), 2);
|
let secondsText = padNum(d.getSeconds(), 2);
|
||||||
let dowText = locale.dow(d);
|
let dowText = locale.dow(d);
|
||||||
let dateText = locale.date(d, true);
|
let dateText = locale.date(d, true);
|
||||||
|
let width = g.getWidth() - 2;
|
||||||
|
|
||||||
g.setFont("Vector", 256);
|
g.setFont("Vector", 256);
|
||||||
let timeFontSize = g.getWidth() / ((g.stringWidth(timeText) / 256) + (Math.max(g.stringWidth(meridian), g.stringWidth(secondsText)) / 512 * 9 / 10));
|
let timeFontSize = width / ((g.stringWidth(timeText) / 256) + (Math.max(g.stringWidth(meridian), g.stringWidth(secondsText)) / 512 * 9 / 10));
|
||||||
let dowFontSize = g.getWidth() / (g.stringWidth(dowText) / 256);
|
let dowFontSize = width / (g.stringWidth(dowText) / 256);
|
||||||
let dateFontSize = g.getWidth() / (g.stringWidth(dateText) / 256);
|
let dateFontSize = width / (g.stringWidth(dateText) / 256);
|
||||||
|
|
||||||
let timeHeight = g.setFont("Vector", timeFontSize).getFontHeight() * 9 / 10;
|
let timeHeight = g.setFont("Vector", timeFontSize).getFontHeight() * 9 / 10;
|
||||||
let dowHeight = g.setFont("Vector", dowFontSize).getFontHeight();
|
let dowHeight = g.setFont("Vector", dowFontSize).getFontHeight();
|
||||||
|
|
@ -56,26 +61,28 @@ function draw() {
|
||||||
let remainingHeight = g.getHeight() - 24 - timeHeight - dowHeight - dateHeight;
|
let remainingHeight = g.getHeight() - 24 - timeHeight - dowHeight - dateHeight;
|
||||||
let spacer = remainingHeight / 4;
|
let spacer = remainingHeight / 4;
|
||||||
|
|
||||||
|
let x = 2;
|
||||||
let y = 24 + spacer;
|
let y = 24 + spacer;
|
||||||
|
|
||||||
pushCommand(drawVectorText, timeText, timeFontSize, 0, y, -1, -1);
|
pushCommand(drawVectorText, timeText, timeFontSize, x, y, -1, -1);
|
||||||
pushCommand(drawVectorText, meridian, timeFontSize*9/20, g.getWidth(), y, 1, -1);
|
pushCommand(drawVectorText, meridian, timeFontSize*9/20, x + width, y, 1, -1);
|
||||||
pushCommand(drawVectorText, secondsText, timeFontSize*9/20, g.getWidth(), y + timeHeight, 1, 1);
|
if (showSeconds) pushCommand(drawVectorText, secondsText, timeFontSize*9/20, x + width, y + timeHeight, 1, 1);
|
||||||
y += timeHeight + spacer;
|
y += timeHeight + spacer;
|
||||||
|
|
||||||
pushCommand(drawVectorText, dowText, dowFontSize, g.getWidth()/2, y, 0, -1);
|
pushCommand(drawVectorText, dowText, dowFontSize, x + width/2, y, 0, -1);
|
||||||
y += dowHeight + spacer;
|
y += dowHeight + spacer;
|
||||||
|
|
||||||
pushCommand(drawVectorText, dateText, dateFontSize, g.getWidth()/2, y, 0, -1);
|
pushCommand(drawVectorText, dateText, dateFontSize, x + width/2, y, 0, -1);
|
||||||
|
|
||||||
executeCommands();
|
executeCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
let timeout;
|
var timeout;
|
||||||
|
|
||||||
function tick() {
|
function tick() {
|
||||||
draw();
|
draw();
|
||||||
timeout = setTimeout(tick, 1000 - getTime() % 1 * 1000);
|
var period = showSeconds ? 1000 : 60 * 1000;
|
||||||
|
timeout = setTimeout(tick, period - getTime() * 1000 % period);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bangle.on('lcdPower', function(on) {
|
Bangle.on('lcdPower', function(on) {
|
||||||
|
|
@ -84,6 +91,13 @@ Bangle.on('lcdPower', function(on) {
|
||||||
if (on) tick();
|
if (on) tick();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Bangle.on('lock', function(locked) {
|
||||||
|
if (timeout) clearTimeout(timeout);
|
||||||
|
timeout = null;
|
||||||
|
showSeconds = !locked;
|
||||||
|
tick();
|
||||||
|
});
|
||||||
|
|
||||||
g.clear();
|
g.clear();
|
||||||
tick();
|
tick();
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
Loading…
Reference in New Issue