| 20 | import Preference from "preference"; |
| 21 | |
| 22 | function 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 | |
| 60 | export default function () { |
| 61 | const rtc = new device.peripheral.RTC; |