BangleApps/apps/ffcniftyb/app.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-06-08 20:50:19 +00:00
var scale;
var screen;
var center;
var buf;
var img;
2021-10-22 22:29:49 +00:00
2022-06-08 20:50:19 +00:00
function format(value) {
return ("0" + value).substr(-2);
2021-10-22 22:29:49 +00:00
}
function renderEllipse(g) {
g.fillEllipse(center.x - 5 * scale, center.y - 70 * scale, center.x + 160 * scale, center.y + 90 * scale);
}
2022-06-08 20:50:19 +00:00
function renderText(g, date) {
const hour = date.getHours() - (this.is12Hour && date.getHours() > 12 ? 12 : 0);
const month = date.getMonth() + 1;
2021-10-22 22:29:49 +00:00
2022-06-08 20:50:19 +00:00
const monthName = require("date_utils").month(month, 1);
const dayName = require("date_utils").dow(date.getDay(), 1);
2021-10-22 22:29:49 +00:00
g.setFontAlign(1, 0).setFont("Vector", 90 * scale);
2022-06-08 20:50:19 +00:00
g.drawString(format(hour), center.x + 32 * scale, center.y - 31 * scale);
g.drawString(format(date.getMinutes()), center.x + 32 * scale, center.y + 46 * scale);
2021-10-22 22:29:49 +00:00
g.setFontAlign(1, 0).setFont("Vector", 16 * scale);
2022-06-08 20:50:19 +00:00
g.drawString(date.getFullYear(), center.x + 80 * scale, center.y - 42 * scale);
g.drawString(format(month), center.x + 80 * scale, center.y - 26 * scale);
g.drawString(format(date.getDate()), center.x + 80 * scale, center.y - 10 * scale);
g.drawString(monthName, center.x + 80 * scale, center.y + 44 * scale);
g.drawString(dayName, center.x + 80 * scale, center.y + 60 * scale);
2021-10-22 22:29:49 +00:00
}
2022-06-08 20:50:19 +00:00
const ClockFace = require("ClockFace");
const clock = new ClockFace({
init: function () {
const appRect = Bangle.appRect;
screen = {
width: appRect.w,
height: appRect.h
};
center = {
x: screen.width / 2,
y: screen.height / 2
};
buf = Graphics.createArrayBuffer(screen.width, screen.height, 1, { msb: true });
scale = g.getWidth() / screen.width;
img = {
width: screen.width,
height: screen.height,
transparent: 0,
bpp: 1,
buffer: buf.buffer
};
// default to RED (see settings.js)
// don't use || to default because 0 is a valid color
this.color = this.color === undefined ? 63488 : this.color;
},
draw: function (date) {
// render outside text with ellipse
buf.clear();
renderText(buf.setColor(1), date);
renderEllipse(buf.setColor(0));
g.setColor(this.color).drawImage(img, 0, 24);
// render ellipse with inside text
buf.clear();
renderEllipse(buf.setColor(1));
renderText(buf.setColor(0), date);
g.setColor(this.color).drawImage(img, 0, 24);
},
settingsFile: "ffcniftyb.json"
2021-10-22 22:29:49 +00:00
});
2022-06-08 20:50:19 +00:00
clock.start();