mirror of https://github.com/espruino/BangleApps
0.15: Add color scheme, different size screen support
parent
fec0aad0eb
commit
547d9c8bf5
|
@ -312,9 +312,9 @@
|
||||||
{ "id": "aclock",
|
{ "id": "aclock",
|
||||||
"name": "Analog Clock",
|
"name": "Analog Clock",
|
||||||
"icon": "clock-analog.png",
|
"icon": "clock-analog.png",
|
||||||
"version": "0.14",
|
"version": "0.15",
|
||||||
"description": "An Analog Clock",
|
"description": "An Analog Clock",
|
||||||
"tags": "clock",
|
"tags": "clock,b2",
|
||||||
"type":"clock",
|
"type":"clock",
|
||||||
"allow_emulator":true,
|
"allow_emulator":true,
|
||||||
"storage": [
|
"storage": [
|
||||||
|
|
|
@ -9,3 +9,4 @@
|
||||||
0.12: Fix regression after 0.11
|
0.12: Fix regression after 0.11
|
||||||
0.13: Fix broken date padding (fix #376)
|
0.13: Fix broken date padding (fix #376)
|
||||||
0.14: Remove hardcoded hour buzz (you can install widchime if you miss it)
|
0.14: Remove hardcoded hour buzz (you can install widchime if you miss it)
|
||||||
|
0.15: Add color scheme support
|
||||||
|
|
|
@ -2,13 +2,16 @@
|
||||||
const locale = require('locale');
|
const locale = require('locale');
|
||||||
const p = Math.PI / 2;
|
const p = Math.PI / 2;
|
||||||
const pRad = Math.PI / 180;
|
const pRad = Math.PI / 180;
|
||||||
const faceWidth = 100; // watch face radius (240/2 - 24px for widget area)
|
const faceWidth = g.getWidth()/2 - 20; // watch face radius (240/2 - 24px for widget area)
|
||||||
const widgetHeight=24+1;
|
const widgetHeight=24+1;
|
||||||
let timer = null;
|
let timer = null;
|
||||||
let currentDate = new Date();
|
let currentDate = new Date();
|
||||||
const centerX = g.getWidth() / 2;
|
const centerX = g.getWidth() / 2;
|
||||||
const centerY = (g.getWidth() / 2) + widgetHeight/2;
|
const centerY = (g.getWidth() / 2) + widgetHeight/2;
|
||||||
|
g.theme.dark=false;
|
||||||
|
let colSecA = g.theme.dark ? "#00A" : "#58F"; // before the second
|
||||||
|
let colSecB = g.theme.dark ? "#58F" : "#00A"; // after the second
|
||||||
|
let colSec1 = g.theme.dark ? "#F83" : "#000"; // ON the second
|
||||||
|
|
||||||
const seconds = (angle) => {
|
const seconds = (angle) => {
|
||||||
const a = angle * pRad;
|
const a = angle * pRad;
|
||||||
|
@ -46,40 +49,35 @@ const drawAll = () => {
|
||||||
// draw all secs
|
// draw all secs
|
||||||
|
|
||||||
for (let i = 0; i < 60; i++) {
|
for (let i = 0; i < 60; i++) {
|
||||||
if (i > currentSec) {
|
g.setColor((i > currentSec) ? colSecA : colSecB);
|
||||||
g.setColor(0, 0, 0.6);
|
|
||||||
} else {
|
|
||||||
g.setColor(0.3, 0.3, 1);
|
|
||||||
}
|
|
||||||
seconds((360 * i) / 60);
|
seconds((360 * i) / 60);
|
||||||
}
|
}
|
||||||
onSecond();
|
onSecond();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetSeconds = () => {
|
const resetSeconds = () => {
|
||||||
g.setColor(0, 0, 0.6);
|
g.setColor(colSecA);
|
||||||
for (let i = 0; i < 60; i++) {
|
for (let i = 0; i < 60; i++) {
|
||||||
seconds((360 * i) / 60);
|
seconds((360 * i) / 60);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSecond = () => {
|
const onSecond = () => {
|
||||||
g.setColor(0.3, 0.3, 1);
|
g.setColor(colSecB);
|
||||||
seconds((360 * currentDate.getSeconds()) / 60);
|
seconds((360 * currentDate.getSeconds()) / 60);
|
||||||
if (currentDate.getSeconds() === 59) {
|
if (currentDate.getSeconds() === 59) {
|
||||||
resetSeconds();
|
resetSeconds();
|
||||||
onMinute();
|
onMinute();
|
||||||
}
|
}
|
||||||
g.setColor(1, 0.7, 0.2);
|
g.setColor(colSec1);
|
||||||
currentDate = new Date();
|
currentDate = new Date();
|
||||||
seconds((360 * currentDate.getSeconds()) / 60);
|
seconds((360 * currentDate.getSeconds()) / 60);
|
||||||
g.setColor(1, 1, 1);
|
g.setColor(g.theme.fg);
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawDate = () => {
|
const drawDate = () => {
|
||||||
g.reset();
|
g.reset();
|
||||||
g.setColor(1, 0, 0);
|
g.setColor("#f00");
|
||||||
g.setFont('6x8', 2);
|
g.setFont('6x8', 2);
|
||||||
|
|
||||||
const dayString = locale.dow(currentDate, true);
|
const dayString = locale.dow(currentDate, true);
|
||||||
|
@ -89,7 +87,7 @@ const drawDate = () => {
|
||||||
// console.log(`${dayString}|${dateString}`);
|
// console.log(`${dayString}|${dateString}`);
|
||||||
// center date
|
// center date
|
||||||
const l = (g.getWidth() - g.stringWidth(dateDisplay)) / 2;
|
const l = (g.getWidth() - g.stringWidth(dateDisplay)) / 2;
|
||||||
const t = centerY + 37;
|
const t = centerY + faceWidth*0.37;
|
||||||
g.drawString(dateDisplay, l, t, true);
|
g.drawString(dateDisplay, l, t, true);
|
||||||
// console.log(l, t);
|
// console.log(l, t);
|
||||||
};
|
};
|
||||||
|
@ -99,7 +97,7 @@ const onMinute = () => {
|
||||||
resetSeconds();
|
resetSeconds();
|
||||||
}
|
}
|
||||||
// clear existing hands
|
// clear existing hands
|
||||||
g.setColor(0, 0, 0);
|
g.setColor(g.theme.bg);
|
||||||
// Hour
|
// Hour
|
||||||
hand((360 * (currentDate.getHours() + currentDate.getMinutes() / 60)) / 12, -8, faceWidth - 35);
|
hand((360 * (currentDate.getHours() + currentDate.getMinutes() / 60)) / 12, -8, faceWidth - 35);
|
||||||
// Minute
|
// Minute
|
||||||
|
@ -107,10 +105,10 @@ const onMinute = () => {
|
||||||
|
|
||||||
// get new date, then draw new hands
|
// get new date, then draw new hands
|
||||||
currentDate = new Date();
|
currentDate = new Date();
|
||||||
g.setColor(1, 0.9, 0.9);
|
g.setColor(g.theme.fg);
|
||||||
// Hour
|
// Hour
|
||||||
hand((360 * (currentDate.getHours() + currentDate.getMinutes() / 60)) / 12, -8, faceWidth - 35);
|
hand((360 * (currentDate.getHours() + currentDate.getMinutes() / 60)) / 12, -8, faceWidth - 35);
|
||||||
g.setColor(1, 1, 0.9);
|
g.setColor(g.theme.fg);
|
||||||
// Minute
|
// Minute
|
||||||
hand((360 * currentDate.getMinutes()) / 60, -8, faceWidth - 10);
|
hand((360 * currentDate.getMinutes()) / 60, -8, faceWidth - 10);
|
||||||
drawDate();
|
drawDate();
|
||||||
|
@ -137,8 +135,9 @@ g.clear();
|
||||||
resetSeconds();
|
resetSeconds();
|
||||||
startTimers();
|
startTimers();
|
||||||
drawAll();
|
drawAll();
|
||||||
|
|
||||||
|
// Show launcher when button pressed
|
||||||
|
Bangle.setUI("clock");
|
||||||
|
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
// Show launcher when middle button pressed
|
|
||||||
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });
|
|
||||||
|
|
Loading…
Reference in New Issue