improve names (and translate german names)
parent
ed58557824
commit
0625b4c8c1
|
|
@ -9,57 +9,58 @@ const defaultSettings = {
|
||||||
|
|
||||||
const settings = Object.assign(defaultSettings, require('Storage').readJSON('cc_clock24.json', 1) || {});
|
const settings = Object.assign(defaultSettings, require('Storage').readJSON('cc_clock24.json', 1) || {});
|
||||||
|
|
||||||
const c = {
|
const center = {
|
||||||
"x": g.getWidth()/2,
|
"x": g.getWidth()/2,
|
||||||
"y": g.getHeight()/2
|
"y": g.getHeight()/2
|
||||||
};
|
};
|
||||||
|
|
||||||
const zahlpos = (function() {
|
const hourNumberPositions = (function() {
|
||||||
let z = [];
|
let z = [];
|
||||||
let sk = 1;
|
let sk = 1;
|
||||||
for (let i = -10; i < 50; i += 5){
|
for (let i = -10; i < 50; i += 5){
|
||||||
let win = i * 2 * Math.PI / 60;
|
let alpha = i * 2 * Math.PI / 60;
|
||||||
let xsk = c.x + 2 + Math.cos(win) * (c.x - 10),
|
let xsk = center.x + 2 + Math.cos(alpha) * (center.x - 10),
|
||||||
ysk = c.y + 2 + Math.sin(win) * (c.x - 10);
|
ysk = center.y + 2 + Math.sin(alpha) * (center.x - 10);
|
||||||
if (sk==3){ xsk -=10; }
|
if (sk==3){ xsk -= 10; }
|
||||||
if (sk==6){ ysk -=10; }
|
if (sk==6){ ysk -= 10; }
|
||||||
if (sk==9){ xsk +=10; }
|
if (sk==9){ xsk += 10; }
|
||||||
if (sk==12){ ysk +=10; }
|
if (sk==12){ ysk += 10; }
|
||||||
if (sk==10){ xsk +=3; }
|
if (sk==10){ xsk += 3; }
|
||||||
z.push([sk, xsk, ysk]);
|
z.push([sk, xsk, ysk]);
|
||||||
sk += 1;
|
sk += 1;
|
||||||
}
|
}
|
||||||
return z;
|
return z;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const zeiger = function(len, dia, tim) {
|
const calcHandPolygon = function(len, dia, alpha) {
|
||||||
const x = c.x + Math.cos(tim) * len/2,
|
const x = center.x + Math.cos(alpha) * len/2,
|
||||||
y = c.y + Math.sin(tim) * len/2,
|
y = center.y + Math.sin(alpha) * len/2,
|
||||||
d = {
|
d = {
|
||||||
"d": 3,
|
"d": 3,
|
||||||
"x": dia/2 * Math.cos(tim + Math.PI/2),
|
"x": dia/2 * Math.cos(alpha + Math.PI/2),
|
||||||
"y": dia/2 * Math.sin(tim + Math.PI/2)
|
"y": dia/2 * Math.sin(alpha + Math.PI/2)
|
||||||
},
|
},
|
||||||
pol = [
|
return [
|
||||||
c.x - d.x,
|
center.x - d.x,
|
||||||
c.y - d.y,
|
center.y - d.y,
|
||||||
c.x + d.x,
|
center.x + d.x,
|
||||||
c.y + d.y,
|
center.y + d.y,
|
||||||
x + d.x,
|
x + d.x,
|
||||||
y + d.y,
|
y + d.y,
|
||||||
x - d.x,
|
x - d.x,
|
||||||
y - d.y
|
y - d.y
|
||||||
];
|
];
|
||||||
return pol;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawHands = function(d) {
|
const drawHands = function(date) {
|
||||||
let m = d.getMinutes(), h = d.getHours(), s = d.getSeconds();
|
let m = date.getMinutes(),
|
||||||
|
h = date.getHours(),
|
||||||
|
s = date.getSeconds();
|
||||||
g.setColor(1, 1, 1);
|
g.setColor(1, 1, 1);
|
||||||
|
|
||||||
let numHoursForHourHand = settings.show24HourMode? 24 : 12;
|
let numHoursForHourHand = settings.show24HourMode? 24 : 12;
|
||||||
|
|
||||||
if(h > numHoursForHourHand){
|
if (h > numHoursForHourHand){
|
||||||
h = h - numHoursForHourHand;
|
h = h - numHoursForHourHand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,29 +70,32 @@ const drawHands = function(d) {
|
||||||
s = 2 * Math.PI / 60 * s - Math.PI/2;
|
s = 2 * Math.PI / 60 * s - Math.PI/2;
|
||||||
|
|
||||||
//g.setColor(1,0,0);
|
//g.setColor(1,0,0);
|
||||||
const hz = zeiger(settings.shortHrHand? 88 : 100, 5, h);
|
const hourPolygon = calcHandPolygon(settings.shortHrHand? 88 : 100, 5, h);
|
||||||
g.fillPoly(hz, true);
|
g.fillPoly(hourPolygon, true);
|
||||||
//g.setColor(1, 1, 1);
|
//g.setColor(1, 1, 1);
|
||||||
const minz = zeiger(150, 5, m);
|
const minutePolygon = calcHandPolygon(150, 5, m);
|
||||||
g.fillPoly(minz, true);
|
g.fillPoly(minutePolygon, true);
|
||||||
if (unlock){
|
if (unlock){
|
||||||
const sekz = zeiger(150, 2, s);
|
const secondPolygon = calcHandPolygon(150, 2, s);
|
||||||
g.fillPoly(sekz, true);
|
g.fillPoly(secondPolygon, true);
|
||||||
}
|
}
|
||||||
g.fillCircle(c.x, c.y, 4);
|
g.fillCircle(center.x, center.y, 4);
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawText = function(d) {
|
const drawText = function(date) {
|
||||||
g.setFont("Vector", 10);
|
g.setFont("Vector", 10);
|
||||||
g.setBgColor(0, 0, 0);
|
g.setBgColor(0, 0, 0);
|
||||||
g.setColor(1, 1, 1);
|
g.setColor(1, 1, 1);
|
||||||
const dateStr = require("locale").date(d);
|
|
||||||
g.drawString(dateStr, c.x, c.y + 20, true);
|
const dateStr = require("locale").date(date);
|
||||||
const batStr = Math.round(E.getBattery()/5) * 5 + "%";
|
g.drawString(dateStr, center.x, center.y + 20, true);
|
||||||
|
|
||||||
|
const batteryStr = Math.round(E.getBattery()/5) * 5 + "%";
|
||||||
|
|
||||||
if (Bangle.isCharging()) {
|
if (Bangle.isCharging()) {
|
||||||
g.setBgColor(1, 0, 0);
|
g.setBgColor(1, 0, 0);
|
||||||
}
|
}
|
||||||
g.drawString(batStr, c.x, c.y + 40, true);
|
g.drawString(batteryStr, center.x, center.y + 40, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawNumbers = function() {
|
const drawNumbers = function() {
|
||||||
|
|
@ -100,11 +104,11 @@ const drawNumbers = function() {
|
||||||
g.setColor(1, 1, 1);
|
g.setColor(1, 1, 1);
|
||||||
g.setBgColor(0, 0, 0);
|
g.setBgColor(0, 0, 0);
|
||||||
for(let i = 0; i < 12; i++){
|
for(let i = 0; i < 12; i++){
|
||||||
hour = zahlpos[i][0]
|
hour = hourNumberPositions[i][0]
|
||||||
if (settings.show24HourMode){
|
if (settings.show24HourMode){
|
||||||
hour *= 2;
|
hour *= 2;
|
||||||
}
|
}
|
||||||
g.drawString(hour, zahlpos[i][1], zahlpos[i][2], true);
|
g.drawString(hour, hourNumberPositions[i][1], hourNumberPositions[i][2], true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -139,16 +143,18 @@ const queueDraw = function() {
|
||||||
const draw = function() {
|
const draw = function() {
|
||||||
// draw black rectangle in the middle to clear screen from scale and hands
|
// draw black rectangle in the middle to clear screen from scale and hands
|
||||||
g.setColor(0, 0, 0);
|
g.setColor(0, 0, 0);
|
||||||
g.fillRect(10, 10, 2 * c.x - 10, 2 * c.x - 10);
|
g.fillRect(10, 10, 2 * center.x - 10, 2 * center.x - 10);
|
||||||
// prepare for drawing the text
|
// prepare for drawing the text
|
||||||
g.setFontAlign(0, 0);
|
g.setFontAlign(0, 0);
|
||||||
// do drawing
|
// do drawing
|
||||||
drawNumbers();
|
drawNumbers();
|
||||||
const d = new Date();
|
const date = new Date();
|
||||||
if (settings.textAboveHands) {
|
if (settings.textAboveHands) {
|
||||||
drawHands(d); drawText(d);
|
drawHands(date);
|
||||||
|
drawText(date);
|
||||||
} else {
|
} else {
|
||||||
drawText(d); drawHands(d);
|
drawText(date);
|
||||||
|
drawHands(date);
|
||||||
}
|
}
|
||||||
queueDraw();
|
queueDraw();
|
||||||
};
|
};
|
||||||
|
|
@ -158,14 +164,17 @@ const drawScale = function() {
|
||||||
// clear the screen
|
// clear the screen
|
||||||
g.setBgColor(0, 0, 0);
|
g.setBgColor(0, 0, 0);
|
||||||
g.clear();
|
g.clear();
|
||||||
|
|
||||||
// draw the ticks of the scale
|
// draw the ticks of the scale
|
||||||
for (let i = -14; i < 47; i++){
|
for (let i = -14; i < 47; i++){
|
||||||
const win= i * 2 * Math.PI/60;
|
const alpha = i * 2 * Math.PI/60;
|
||||||
let d = 2;
|
let d = 2;
|
||||||
if (i % 5==0){ d =5; }
|
if (i % 5 == 0) {
|
||||||
g.fillPoly(zeiger(300, d, win), true);
|
d = 5;
|
||||||
|
}
|
||||||
|
g.fillPoly(calcHandPolygon(300, d, alpha), true);
|
||||||
g.setColor(0, 0, 0);
|
g.setColor(0, 0, 0);
|
||||||
g.fillRect(10, 10, 2 * c.x - 10, 2 * c.x - 10);
|
g.fillRect(10, 10, 2 * center.x - 10, 2 * center.x - 10);
|
||||||
g.setColor(1, 1, 1);
|
g.setColor(1, 1, 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -181,7 +190,10 @@ Bangle.setUI({
|
||||||
Bangle.removeListener('charging', draw);
|
Bangle.removeListener('charging', draw);
|
||||||
|
|
||||||
// We clear drawTimout after removing all listeners, because they can add one again
|
// We clear drawTimout after removing all listeners, because they can add one again
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) {
|
||||||
|
clearTimeout(drawTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
require("widget_utils").show();
|
require("widget_utils").show();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue