MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / drawTime

Function drawTime

examples/drivers/m5core_ink-clock/main.js:22–58  ·  view source on GitHub ↗
(render, when)

Source from the content-addressed store, hash-verified

20import Preference from "preference";
21
22function drawTime(render, when) {
23 let backgroundColor = render.makeColor(255, 255, 255);
24 let digitsColor = render.makeColor(0, 0, 0);
25 let colonColor = render.makeColor(128, 128, 128);
26 let digits = parseBMP(new Resource("digits-alpha.bmp"));
27
28 const digitWidth = Math.idiv(digits.width, 10);
29 const digitHeight = digits.height;
30 const colonWidth = 16;
31 const timeWidth = (digitWidth << 2) + colonWidth;
32 const bounds = { x:(render.width - timeWidth) >> 1, y:(render.height - digitHeight) >> 1, width:timeWidth, height:digitHeight };
33
34 render.begin();
35 render.fillRectangle(backgroundColor, 0, 0, render.width, render.height);
36
37 let h = when.getHours();
38 let m = when.getMinutes();
39 let x = bounds.x;
40 let y = bounds.y;
41 render.fillRectangle(backgroundColor, 0, 0, render.width, render.height);
42 if (Math.idiv(h, 10)) {
43 render.drawGray(digits, digitsColor, x, y, Math.idiv(h, 10) * digitWidth, 0, digitWidth, digitHeight);
44 x += digitWidth;
45 }
46 else
47 x += digitWidth >> 1;
48 render.drawGray(digits, digitsColor, x, y, (h % 10) * digitWidth, 0, digitWidth, digitHeight);
49 x += digitWidth;
50
51 render.fillRectangle(colonColor, x + 6, y + 10, 6, 6);
52 render.fillRectangle(colonColor, x + 6, y + digitHeight - 18, 6, 6);
53 x += colonWidth;
54 render.drawGray(digits, digitsColor, x, y, Math.idiv(m, 10) * digitWidth, 0, digitWidth, digitHeight);
55 x += digitWidth;
56 render.drawGray(digits, digitsColor, x, y, (m % 10) * digitWidth, 0, digitWidth, digitHeight);
57 render.end();
58}
59
60export default function () {
61 const rtc = new device.peripheral.RTC;

Callers 1

main.jsFile · 0.85

Calls 6

idivMethod · 0.80
drawGrayMethod · 0.80
makeColorMethod · 0.65
beginMethod · 0.65
fillRectangleMethod · 0.65
endMethod · 0.65

Tested by

no test coverage detected