summaryrefslogtreecommitdiff
path: root/source/MazarineView.mc
diff options
context:
space:
mode:
Diffstat (limited to 'source/MazarineView.mc')
-rw-r--r--source/MazarineView.mc392
1 files changed, 392 insertions, 0 deletions
diff --git a/source/MazarineView.mc b/source/MazarineView.mc
new file mode 100644
index 0000000..3a684c2
--- /dev/null
+++ b/source/MazarineView.mc
@@ -0,0 +1,392 @@
+// Mazarine
+//
+// Copyright (C) 2019 cy384, 2020 cos
+// All rights reserved.
+//
+// This software may be modified and distributed under the terms
+// of the BSD license. See the LICENSE file for details.
+
+using Toybox.WatchUi;
+using Toybox.Graphics;
+using Toybox.System;
+using Toybox.Math;
+using Toybox.Application;
+using Toybox.Time.Gregorian;
+
+class MazarineView extends WatchUi.WatchFace {
+
+ function initialize() {
+ WatchUi.WatchFace.initialize();
+ }
+
+ function onLayout(_) { }
+
+ function onShow() { }
+
+ function draw_root_window(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+
+ var min;
+ if (width > height) {
+ min = height;
+ } else {
+ min = width;
+ }
+
+ var iX, iY, oX, oY;
+ var furtherOuterRad = min * 0.46;
+ var outerRad = min * 0.48;
+ var innerRad = min * 0.52;
+
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+
+ // minute marks
+ dc.setPenWidth(2);
+ for (var x = 0; x <= 60; x += 1) {
+ var angle = x * (Math.PI / 30.0);
+
+ // make the 5 minute marks longer
+ if (x % 5 == 0) {
+ oX = width/2.0 + Math.sin(angle)*furtherOuterRad;
+ oY = height/2.0 + Math.cos(angle)*furtherOuterRad;
+ } else {
+ oX = width/2.0 + Math.sin(angle)*outerRad;
+ oY = height/2.0 + Math.cos(angle)*outerRad;
+ }
+
+ iX = width/2.0 + Math.sin(angle)*innerRad;
+ iY = height/2.0 + Math.cos(angle)*innerRad;
+
+ dc.drawLine(iX, iY, oX, oY);
+ }
+ }
+
+ function draw_battery_meter(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+
+ var stats = System.getSystemStats();
+ var battery_meter_width = 30;
+ var battery_meter_height = 5;
+ // var battery_meter_x = 1.0 * width/5.0 - battery_meter_width/2.0;
+ // var battery_meter_y = height/2.0 - battery_meter_height/2.0;
+ var battery_meter_x = width/2.0 - battery_meter_width/2.0;
+ var battery_meter_y = 7.0 * height/8.0 - battery_meter_height/2.0;
+ dc.setPenWidth(1);
+ dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK);
+ dc.drawRectangle(battery_meter_x - 1, battery_meter_y - 1,
+ battery_meter_width + 2, battery_meter_height + 2);
+ if (stats.battery < 25.0) {
+ dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_BLACK);
+ } else {
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+ }
+ dc.fillRectangle(battery_meter_x, battery_meter_y,
+ battery_meter_width * stats.battery/100.0, battery_meter_height);
+ }
+
+ function draw_timezone(dc, index, name, offset) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+ var font = Graphics.FONT_XTINY;
+ var x_pos = 1.0 * width/4.0;
+ // var x_pos = 1.0 * width/2.0;
+ // var y_pos = height/2.0-dc.getFontHeight(font)/2.0;
+ var y_pos = height/2.0-dc.getFontHeight(font)*2.5+index *
+ dc.getFontHeight(font);
+ // var y_pos = height/3.0-dc.getFontHeight(font)/2.0;
+ // now ⇒ Toybox::Time::Moment
+ var now = Time.now();
+ var dur = new Time.Duration(offset * Gregorian.SECONDS_PER_HOUR);
+ // add(offset * duration) ⇒ Toybox::Time::Moment
+ var when = now.add(dur);
+ var time = Gregorian.utcInfo(when, Time.FORMAT_MEDIUM);
+ // utcInfo(moment, format) ⇒ Toybox::Time::Gregorian::Info
+ // var time = Time.Moment(Time.now(), Time.FORMAT_MEDIUM);
+
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+ dc.drawText(x_pos, y_pos, font, name + " " + time.hour.format("%02d") +
+ ":" + time.min.format("%02d"), Graphics.TEXT_JUSTIFY_CENTER);
+ }
+
+ function draw_temperature(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+ var font = Graphics.FONT_XTINY;
+ var x_pos = 1.0 * width/4.0;
+ var y_pos = height/2.0-dc.getFontHeight(font)/2.0;
+
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+ dc.drawText(x_pos, y_pos, font, Toybox.SensorHistory
+ .getTemperatureHistory({}).next().data
+ .format("%.1d") + "°C", Graphics.TEXT_JUSTIFY_CENTER);
+ }
+
+ function draw_timezones(dc) {
+ draw_utc_offset(dc);
+ draw_timezone(dc, 1, "HK", 8);
+ // draw_timezone(dc, 3, "ACDT", 10.5);
+ draw_timezone(dc, 2, "NSW", 11);
+ draw_timezone(dc, 3, "NY", -4);
+ draw_timezone(dc, 4, "CA", -7);
+ }
+
+ function draw_utc_offset(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+ var font = Graphics.FONT_XTINY;
+ var x_pos = 1.0 * width/2.0;
+ var y_pos = 1.0 * height/4.0-dc.getFontHeight(font)/2.0;
+ var myTime = System.getClockTime();
+ var tz_string = "UTC ";
+
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+ if ( myTime.timeZoneOffset/3600 >= 0 ) {
+ tz_string += "+";
+ }
+ tz_string += myTime.timeZoneOffset/3600;
+ if ( myTime.timeZoneOffset % 3600 ) {
+ tz_string += ":" + myTime.timeZoneOffset / 60 % 60;
+ }
+ dc.drawText(x_pos, y_pos, font, tz_string,
+ Graphics.TEXT_JUSTIFY_CENTER);
+ }
+
+ function draw_dayday(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+ var today = Gregorian.info(Time.now(), Time.FORMAT_MEDIUM);
+ var clockTime = System.getClockTime();
+ var minute_hand_obscures = false;
+ var hour_hand_obscures = false;
+ var dayday_font = Graphics.FONT_XTINY;
+ var x_pos = 3.0 * width/4.0;
+ var y_pos = height/2.0-dc.getFontHeight(dayday_font)/2.0;
+
+ if (clockTime.hour % 12 == 2 and clockTime.min >= 35) {
+ hour_hand_obscures = true;
+ }
+
+ if (clockTime.hour % 12 == 3 and clockTime.min <= 35) {
+ hour_hand_obscures = true;
+ }
+
+ if (clockTime.min >= 14 and clockTime.min <= 17) {
+ minute_hand_obscures = true;
+ }
+
+ if ( minute_hand_obscures ) {
+ if ( clockTime.hour % 12 == 2 ) {
+ y_pos += 1.5 * dc.getFontHeight(dayday_font);
+ } else {
+ y_pos -= 1.5 * dc.getFontHeight(dayday_font);
+ }
+ } else if ( hour_hand_obscures ) {
+ if ( clockTime.min > 15 && clockTime.min < 30 ) {
+ y_pos -= 1.5 * dc.getFontHeight(dayday_font);
+ } else {
+ y_pos += 1.5 * dc.getFontHeight(dayday_font);
+ }
+ }
+
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+ dc.drawText(x_pos, y_pos, dayday_font, today.day_of_week + " " +
+ today.day, Graphics.TEXT_JUSTIFY_CENTER);
+ }
+
+ function draw_digital_time(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+ var time_font = Graphics.FONT_LARGE;
+ var x_pos = width/2.0;
+ var y_pos = 4*height/5.0-dc.getFontHeight(time_font)/2.0;
+ var clockTime = System.getClockTime();
+
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+ dc.drawText(x_pos, y_pos, time_font, clockTime.hour.format("%02d") +
+ ":" + clockTime.min.format("%02d"), Graphics.TEXT_JUSTIFY_CENTER);
+ }
+
+ function draw_minute_hand(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+
+ var min;
+ if (width > height) {
+ min = height;
+ } else {
+ min = width;
+ }
+
+ var clockTime = System.getClockTime();
+
+ var hourRad = min * 0.18;
+ var pointerOut = min * 0.45;
+ var pointerIn = min * 0.00;
+
+ // get the angle for minutes
+ var angle = (clockTime.min / 60.0) * (-2.0 * Math.PI);
+ angle += Math.PI;
+
+ // points for the hour nub
+ var pox = width/2.0 + Math.sin(angle)*pointerOut;
+ var poy = height/2.0 + Math.cos(angle)*pointerOut;
+
+ var pix = width/2.0 + Math.sin(angle)*pointerIn;
+ var piy = height/2.0 + Math.cos(angle)*pointerIn;
+
+ // draw the hand
+ dc.setPenWidth(4);
+ dc.drawLine(pix, piy, pox, poy);
+
+ // draw the arbor
+ dc.fillCircle(width/2.0, height/2.0, min*0.03);
+ }
+
+ function draw_hour_hand(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+
+ var min;
+ if (width > height) {
+ min = height;
+ } else {
+ min = width;
+ }
+
+ var clockTime = System.getClockTime();
+
+ var hourRad = min * 0.13;
+ var pointerOut = min * 0.34;
+ var pointerIn = min * 0.00;
+
+ // get the angle for the hour
+ var angle = ((clockTime.hour % 12) / 12.0) * (-2.0 * Math.PI);
+ angle += Math.PI;
+
+ // add the minutes
+ angle -= (clockTime.min / 60.0) * (Math.PI / 6);
+
+ // center of the circle
+ var cX = width/2.0 + Math.sin(angle)*hourRad;
+ var cY = height/2.0 + Math.cos(angle)*hourRad;
+
+ // points for the nub
+ var pox = width/2.0 + Math.sin(angle)*pointerOut;
+ var poy = height/2.0 + Math.cos(angle)*pointerOut;
+
+ var pix = width/2.0 + Math.sin(angle)*pointerIn;
+ var piy = height/2.0 + Math.cos(angle)*pointerIn;
+
+ dc.setPenWidth(5);
+ dc.drawLine(pix, piy, pox, poy);
+ }
+
+ function draw_second_hand(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+ var iX, iY, oX, oY;
+
+ var min;
+ if (width > height) {
+ min = height;
+ } else {
+ min = width;
+ }
+
+ var clockTime = System.getClockTime();
+
+ // var secondRad = min * 0.52;
+ // var secondRadBack = min * 0.0;
+ var furtherOuterRad = min * 0.46;
+ var outerRad = min * 0.48;
+ var innerRad = min * 0.52;
+
+ // get the angle for seconds
+ var angle = (clockTime.sec / 60.0) * (-2.0 * Math.PI);
+
+ for (var x = clockTime.sec - 1; x <= clockTime.sec + 1; x += 1) {
+ var angle = x * (Math.PI / 30.0);
+ dc.setPenWidth(4);
+ oX = width/2.0 + Math.sin(angle)*furtherOuterRad;
+ oY = height/2.0 - Math.cos(angle)*furtherOuterRad;
+ iX = width/2.0 + Math.sin(angle)*innerRad;
+ iY = height/2.0 - Math.cos(angle)*innerRad;
+ dc.setClip(oX-10, oY-10, 20, 20);
+
+ if ( x == clockTime.sec) {
+ dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_TRANSPARENT);
+ } else {
+ dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
+ dc.drawLine(iX, iY, oX, oY);
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+ dc.setPenWidth(2);
+
+ // make the 5 minute marks longer
+ if (x % 5 == 0) {
+ oX = width/2.0 + Math.sin(angle)*furtherOuterRad;
+ oY = height/2.0 - Math.cos(angle)*furtherOuterRad;
+ } else {
+ oX = width/2.0 + Math.sin(angle)*outerRad;
+ oY = height/2.0 - Math.cos(angle)*outerRad;
+ }
+ }
+
+ dc.drawLine(iX, iY, oX, oY);
+ }
+ }
+
+ // update event handler
+ function onUpdate(dc) {
+ var width = dc.getWidth();
+ var height = dc.getHeight();
+ // dc.setClip(0, 0, width, height);
+ dc.clearClip();
+
+ var min;
+ if (width > height) {
+ min = height;
+ } else {
+ min = width;
+ }
+
+ // bg
+ dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
+ dc.fillRectangle(0, 0, width, height);
+
+ // minute rings with marks
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+ draw_root_window(dc);
+ draw_digital_time(dc);
+ draw_dayday(dc);
+ draw_timezones(dc);
+
+ draw_battery_meter(dc);
+ // draw hour hand
+ dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
+ draw_hour_hand(dc);
+
+ // draw minute hand
+ dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
+ draw_minute_hand(dc);
+
+ dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
+
+ dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_TRANSPARENT);
+ draw_second_hand(dc);
+ }
+
+ function onPartialUpdate(dc) {
+ dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_TRANSPARENT);
+ draw_second_hand(dc);
+ }
+
+ function onHide() { }
+
+ function onEnterSleep() {
+ WatchUi.requestUpdate();
+ }
+
+ function onExitSleep() { }
+}