Add the on-device data field catalogue, always-on mode, and real icons

Fields
  75 selectable fields across date/time, activity, body, system,
  environment, weather and custom text, numbered to match
  watchface.io/docs/datafields so the two catalogues line up.  All four
  slots (both top, both bottom) pick from the same table and the bottom
  captions follow the selection.  tools/gen_fields.py owns the table and
  emits FieldTable.mc, settings.xml and both languages' strings, so those
  cannot drift apart.

  Fields.Ctx fetches each API at most once per draw, and only if some slot
  asks -- the forecast, user profile and sensor history lookups are lazy.

  The rest of that catalogue is deliberately absent: OpenWeatherMap and
  StormGlass need network calls and user API keys, the per-sport weekly and
  28-day aggregates come from a phone-side Garmin Connect integration rather
  than any on-device API, and the app complications need those apps
  installed.  README section 7 lists what was left out and why.

Permissions
  UserProfile and SensorHistory are now declared; without them resting heart
  rate, VO2 max, pulse ox and body battery throw at runtime.  Sensor turns
  out to be rejected outright for type="watchface", so altitude and pressure
  read from Activity.Info instead.

Always-on display
  AMOLED devices need the lit-pixel count cut while asleep.  drawAmbient
  drops the band fill and the unlit ticks, dims what remains, hides the
  complications, and walks the layout within +/-4 px per minute so nothing
  burns in.  Gated on requiresBurnInProtection, so MIP devices are untouched.

Icons
  The comps' sunrise and weather icons have two- and three-pixel features.
  Rebuilding them from circles and lines looked right at 454 px and turned to
  mush at 280.  They are now rasterised from the design paths once per screen
  width and tinted with drawBitmap2(:tintColor) -- which needs
  packingFormat="png", since a palettised source is refused at runtime.
  Launcher icons are generated at the five sizes the devices ask for.

All 17 devices build; checked on fenix847mm and enduro3 in the simulator.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-09 23:53:18 +08:00
parent 398018b51e
commit d457f8244e
49 changed files with 1852 additions and 379 deletions

View File

@@ -11,6 +11,8 @@ import Toybox.Time;
import Toybox.Time.Gregorian;
import Toybox.WatchUi;
import Themes;
import Fields;
import Toybox.SensorHistory;
// Every literal below is a coordinate on the 500x500 design canvas, measured
// from design/watchface-*.svg. Nothing here is eyeballed: ring geometry comes
@@ -47,7 +49,7 @@ class Fenix8V3View extends WatchUi.WatchFace {
const LEFT_X = 157.00; // top complications, centred
const RIGHT_X = 343.70;
const ICON_CY = 90.00;
const ICON_CY = 89.50;
const VALUE_CY = 131.06;
const TIME_CY = 221.10;
@@ -89,22 +91,37 @@ class Fenix8V3View extends WatchUi.WatchFace {
private var mFontBand = Graphics.FONT_SMALL;
private var mFontComp = Graphics.FONT_MEDIUM;
private var mFontTime = Graphics.FONT_NUMBER_HOT;
private var mDow = null;
private var mMon = null;
private var mLabels = null;
private var mMeridiem = null;
private var mDateFmt = " ";
// Always-on display: AMOLED devices must cut lit pixels hard while
// asleep, and shift what is left so nothing burns in.
private var mSleeping = false;
private var mBurnIn = false;
private var mIconSunrise = null;
private var mIconSunset = null;
private var mIconWeather = null;
function initialize() {
WatchFace.initialize();
}
function onEnterSleep() as Void {
mSleeping = true;
WatchUi.requestUpdate();
}
function onExitSleep() as Void {
mSleeping = false;
WatchUi.requestUpdate();
}
function onLayout(dc as Dc) as Void {
mW = dc.getWidth();
mH = dc.getHeight();
mS = mW / 500.0;
mCx = mW / 2;
mCy = mH / 2;
var ds = System.getDeviceSettings();
mBurnIn = (ds != null) && (ds has :requiresBurnInProtection)
&& ds.requiresBurnInProtection;
var text = [Graphics.FONT_XTINY, Graphics.FONT_TINY, Graphics.FONT_SMALL,
Graphics.FONT_MEDIUM, Graphics.FONT_LARGE];
var nums = [Graphics.FONT_NUMBER_MILD, Graphics.FONT_NUMBER_MEDIUM,
@@ -115,28 +132,11 @@ class Fenix8V3View extends WatchUi.WatchFace {
loadStrings();
}
// Every piece of on-face wording lives in resources so resources-chn can
// replace it. loadResource is not cheap, so pull it all once per layout.
function loadStrings() as Void {
mDow = splitCsv(WatchUi.loadResource(Rez.Strings.DowNames) as String);
mMon = splitCsv(WatchUi.loadResource(Rez.Strings.MonNames) as String);
mLabels = splitCsv(WatchUi.loadResource(Rez.Strings.FieldLabels) as String);
mMeridiem = splitCsv(WatchUi.loadResource(Rez.Strings.Meridiem) as String);
mDateFmt = WatchUi.loadResource(Rez.Strings.DateFormat) as String;
}
// Monkey C has no String.split.
function splitCsv(str as String) as Array<String> {
var out = [] as Array<String>;
var rest = str;
var cut = rest.find(",");
while (cut != null) {
out.add(rest.substring(0, cut) as String);
rest = rest.substring(cut + 1, rest.length()) as String;
cut = rest.find(",");
}
out.add(rest);
return out;
Fields.loadStrings();
mIconSunrise = WatchUi.loadResource(Rez.Drawables.IconSunrise);
mIconSunset = WatchUi.loadResource(Rez.Drawables.IconSunset);
mIconWeather = WatchUi.loadResource(Rez.Drawables.IconWeather);
}
// Connect IQ exposes ascent and descent but not cap height, and the ascent
@@ -254,6 +254,15 @@ class Fenix8V3View extends WatchUi.WatchFace {
? info.floorsClimbedGoal.toFloat() : 10.0f;
p = info.floorsClimbed.toFloat() / goal;
}
} else if (idx == 5) { // Active minutes vs the weekly goal
if (info.activeMinutesWeek != null && info.activeMinutesWeekGoal != null
&& info.activeMinutesWeekGoal > 0) {
p = info.activeMinutesWeek.total.toFloat()
/ info.activeMinutesWeekGoal.toFloat();
}
} else if (idx == 6) { // Body battery is already 0..100
var bb = Fields.latest(SensorHistory.getBodyBatteryHistory({:period => 1}));
if (bb != null) { p = bb.toFloat() / 100.0; }
} else if (idx == 4) { // Move bar: an integer level, not a ratio
if (info.moveBarLevel != null) {
var span = (ActivityMonitor.MOVE_BAR_LEVEL_MAX
@@ -268,103 +277,6 @@ class Fenix8V3View extends WatchUi.WatchFace {
return p;
}
// ------------------------------------------------------------ data bits
function distanceString(info as ActivityMonitor.Info, ds as System.DeviceSettings) as String {
if (info == null || info.distance == null) { return "0.0"; }
var km = info.distance.toFloat() / 100000.0;
if (ds != null && ds.distanceUnits == System.UNIT_STATUTE) { km = km * 0.621371; }
return km.format("%.1f");
}
// TempUnit: 0 follow the watch, 1 force Celsius, 2 force Fahrenheit.
function tempString(c as Numeric?, ds as System.DeviceSettings) as String {
if (c == null) { return "--"; }
var t = c.toFloat();
var mode = getSetting("TempUnit", 0);
var fahrenheit = (mode == 2)
|| (mode == 0 && ds != null && ds.temperatureUnits == System.UNIT_STATUTE);
if (fahrenheit) { t = t * 9.0 / 5.0 + 32.0; }
return t.format("%d") + "°";
}
function clockString(m as Time.Moment?, ds as System.DeviceSettings) as String {
if (m == null) { return "--:--"; }
var g = Gregorian.info(m, Time.FORMAT_SHORT);
var h = g.hour;
if (ds == null || !ds.is24Hour) {
if (h == 0) { h = 12; } else if (h > 12) { h = h - 12; }
}
return h.format("%d") + ":" + g.min.format("%02d");
}
function here(weather as Weather.CurrentConditions?) as Position.Location? {
if (weather != null && weather.observationLocationPosition != null) {
return weather.observationLocationPosition;
}
var act = Activity.getActivityInfo();
if (act != null && act.currentLocation != null) { return act.currentLocation; }
return null;
}
// value string for a complication slot
function complicationValue(typeIdx as Number, info as ActivityMonitor.Info,
weather as Weather.CurrentConditions?, stats as System.Stats,
ds as System.DeviceSettings) as String {
if (typeIdx == 1) { // Calories
return info != null && info.calories != null ? info.calories.format("%d") : "0";
} else if (typeIdx == 2) { // Steps
return info != null && info.steps != null ? info.steps.format("%d") : "0";
} else if (typeIdx == 3) { // Distance
return distanceString(info, ds);
} else if (typeIdx == 4) { // Floors
return info != null && info.floorsClimbed != null
? info.floorsClimbed.format("%d") : "0";
} else if (typeIdx == 5) { // Battery
var pct = 0;
if (stats != null && stats.battery != null) { pct = (stats.battery * 100.0).toNumber(); }
return pct.format("%d") + "%";
} else if (typeIdx == 6 || typeIdx == 7) { // Sunrise / sunset
var loc = here(weather);
if (loc == null) { return "--:--"; }
var m = typeIdx == 6 ? Weather.getSunrise(loc, Time.now())
: Weather.getSunset(loc, Time.now());
return clockString(m, ds);
} else if (typeIdx == 9) { // Heart rate
var act = Activity.getActivityInfo();
if (act != null && act.currentHeartRate != null) {
return act.currentHeartRate.format("%d");
}
var hist = ActivityMonitor.getHeartRateHistory(1, true);
if (hist != null) {
var sample = hist.next();
if (sample != null && sample.heartRate != null
&& sample.heartRate != ActivityMonitor.INVALID_HR_SAMPLE) {
return sample.heartRate.format("%d");
}
}
return "--";
} else if (typeIdx == 8) { // Forecast high / low
var fc = Weather.getDailyForecast();
if (fc != null && fc.size() > 0) {
return tempString(fc[0].highTemperature, ds) + "/"
+ tempString(fc[0].lowTemperature, ds);
}
return "--/--";
}
// 0: current temperature
if (weather != null && weather.temperature != null) {
return tempString(weather.temperature, ds);
}
return "--";
}
// Short caption under a bottom-row value. Indexed like the field types, so
// the label always follows whatever the slot is set to.
function fieldLabel(typeIdx as Number) as String {
if (mLabels == null || typeIdx < 0 || typeIdx >= mLabels.size()) { return ""; }
return mLabels[typeIdx];
}
// ----------------------------------------------------------------- ring
function tick(dc as Dc, ang as Float, hw as Float) as Void {
var a0 = ang - hw;
@@ -441,79 +353,19 @@ class Fenix8V3View extends WatchUi.WatchFace {
}
}
// Filled half-ellipse, flat side down. The comp's dome is 14.90 wide but
// 8.93 tall, so it is not a plain semicircle.
function dome(dc as Dc, cx as Numeric, baseY as Numeric,
rx as Numeric, ry as Numeric) as Void {
var pts = [];
for (var i = 0; i <= 12; i++) {
var rad = Math.toRadians(180.0 - 15.0 * i);
pts.add([Math.round(px(cx) + Math.cos(rad) * px(rx)).toNumber(),
Math.round(px(baseY) - Math.sin(rad) * px(ry)).toNumber()]);
}
dc.fillPolygon(pts);
}
function stub(dc as Dc, x1 as Numeric, y1 as Numeric, x2 as Numeric, y2 as Numeric) as Void {
dc.drawLine(px(x1), px(y1), px(x2), px(y2));
}
// Sun over a horizon bar with a chevron. Every ray in the comp is a short
// stub roughly as long as the pen is wide -- drawing them longer is what
// made this icon read taller than the weather one.
// dir = -1 flips the chevron up, which is what the sunset slot uses.
function iconSun(dc as Dc, cx as Numeric, cy as Numeric, scale as Float,
col as Number, dir as Number) as Void {
var k = scale;
var ox = cx - 156.32 * k; // design-space offset of this icon
var oy = cy - 90.34 * k;
dc.setColor(col, Graphics.COLOR_TRANSPARENT);
dome(dc, ox + 156.39 * k, oy + 94.02 * k, 7.45 * k, 8.93 * k);
dc.setPenWidth(maxNum(2, px(2.96 * k)));
stub(dc, ox + 156.39 * k, oy + 79.4 * k, ox + 156.39 * k, oy + 81.1 * k);
stub(dc, ox + 148.2 * k, oy + 83.3 * k, ox + 146.5 * k, oy + 84.5 * k);
stub(dc, ox + 164.6 * k, oy + 84.5 * k, ox + 166.3 * k, oy + 83.3 * k);
stub(dc, ox + 142.6 * k, oy + 92.5 * k, ox + 144.7 * k, oy + 92.5 * k);
stub(dc, ox + 168.0 * k, oy + 92.5 * k, ox + 170.1 * k, oy + 92.5 * k);
dc.setPenWidth(maxNum(2, px(2.6 * k)));
var by = oy + 98.45 * k;
stub(dc, ox + 142.3 * k, by, ox + 170.3 * k, by);
stub(dc, ox + 152.6 * k, by, ox + 156.3 * k, by + dir * 3.05 * k);
stub(dc, ox + 156.3 * k, by + dir * 3.05 * k, ox + 160.0 * k, by);
}
// Sun peeking out from behind a cloud. The comp keeps a dark notch where
// the cloud crosses the sun; without it the two shapes merge into one blob
// and the icon reads much heavier than the sunrise one next to it. So the
// cloud is stamped twice: once inflated in black to cut the notch, then at
// true size in the accent colour.
function cloudBody(dc as Dc, ox as Numeric, oy as Numeric, k as Float,
grow as Float) as Void {
dc.fillCircle(px(ox + 336.6 * k), px(oy + 94.4 * k), px(8.7 * k + grow));
dc.fillCircle(px(ox + 346.4 * k), px(oy + 96.9 * k), px(6.3 * k + grow));
var g = px(grow);
dc.fillRoundedRectangle(px(ox + 328.0 * k) - g, px(oy + 95.5 * k) - g,
px(24.6 * k) + 2 * g, px(7.75 * k) + g,
px(3.4 * k));
}
function iconCloud(dc as Dc, cx as Numeric, cy as Numeric, scale as Float,
col as Number) as Void {
var k = scale;
var ox = cx - 343.55 * k;
var oy = cy - 89.25 * k;
dc.setColor(col, Graphics.COLOR_TRANSPARENT);
dc.fillCircle(px(ox + 347.0 * k), px(oy + 88.9 * k), px(7.8 * k));
dc.setPenWidth(maxNum(2, px(2.3 * k)));
stub(dc, ox + 346.2 * k, oy + 76.0 * k, ox + 346.2 * k, oy + 78.7 * k);
stub(dc, ox + 354.9 * k, oy + 87.7 * k, ox + 357.5 * k, oy + 87.7 * k);
dc.setPenWidth(maxNum(2, px(2.7 * k)));
stub(dc, ox + 339.5 * k, oy + 79.5 * k, ox + 338.1 * k, oy + 80.9 * k);
stub(dc, ox + 353.5 * k, oy + 80.9 * k, ox + 354.6 * k, oy + 79.8 * k);
dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
cloudBody(dc, ox, oy, k, 1.7 * k);
dc.setColor(col, Graphics.COLOR_TRANSPARENT);
cloudBody(dc, ox, oy, k, 0.0);
// The comps' sunrise and weather icons are traced outlines with two- and
// three-pixel features. Rebuilding them from circles and lines held up at
// 454 px and turned to mush at 280, so they ship as bitmaps rasterised
// from the design paths at each screen size (tools/gen_icons.py) and get
// the theme's accent applied through :tintColor.
function blitIcon(dc as Dc, bmp, cx as Numeric, cy as Numeric, col as Number) as Void {
if (bmp == null) { return; }
dc.drawBitmap2(px(cx) - bmp.getWidth() / 2, px(cy) - bmp.getHeight() / 2,
bmp, {:tintColor => col});
}
function maxNum(a as Number, b as Number) as Number {
@@ -522,47 +374,52 @@ class Fenix8V3View extends WatchUi.WatchFace {
function drawComplicationIcon(dc as Dc, cx as Numeric, cy as Numeric, scale as Float,
col as Number, typeIdx as Number, level as Float) as Void {
if (typeIdx == 6) {
iconSun(dc, cx, cy, scale, col, 1);
} else if (typeIdx == 7) {
iconSun(dc, cx, cy, scale, col, -1);
} else if (typeIdx == 0 || typeIdx == 8) {
iconCloud(dc, cx, cy, scale, col);
} else if (typeIdx == 5) {
if (typeIdx == 712 || typeIdx == 700) {
blitIcon(dc, mIconSunrise, cx, ICON_CY, col);
} else if (typeIdx == 717 || typeIdx == 731) {
blitIcon(dc, mIconSunset, cx, ICON_CY, col);
} else if (typeIdx == 306 || typeIdx == 639 || typeIdx == 300
|| typeIdx == 301 || typeIdx == 302 || typeIdx == 304
|| typeIdx == 305 || typeIdx == 308 || typeIdx == 309
|| typeIdx == 310 || typeIdx == 307) {
blitIcon(dc, mIconWeather, cx, ICON_CY, col);
} else if (typeIdx == 250 || typeIdx == 251 || typeIdx == 257) {
iconBattery(dc, cx - 14.4 * scale, cy, scale, col, level);
} else {
var r = 13.0 * scale;
dc.setColor(col, Graphics.COLOR_TRANSPARENT);
dc.setPenWidth(maxNum(2, px(3.0 * scale)));
if (typeIdx == 1) { // calories: flame
if (typeIdx == 2 || typeIdx == 603) { // calories: flame
dc.fillPolygon([[px(cx), px(cy - r)],
[px(cx + r * 0.72), px(cy + r * 0.25)],
[px(cx + r * 0.40), px(cy + r * 0.85)],
[px(cx - r * 0.40), px(cy + r * 0.85)],
[px(cx - r * 0.72), px(cy + r * 0.25)]]);
} else if (typeIdx == 2) { // steps: two prints
} else if (typeIdx == 1 || typeIdx == 14 || typeIdx == 707) { // steps
dc.fillRoundedRectangle(px(cx - r * 0.85), px(cy - r * 0.75),
px(r * 0.62), px(r * 1.15), px(r * 0.3));
dc.fillRoundedRectangle(px(cx + r * 0.22), px(cy - r * 0.35),
px(r * 0.62), px(r * 1.15), px(r * 0.3));
} else if (typeIdx == 3) { // distance: arrow
} else if (typeIdx == 3 || typeIdx == 9 || typeIdx == 615) { // distance
dc.fillPolygon([[px(cx), px(cy - r)],
[px(cx + r * 0.75), px(cy + r * 0.8)],
[px(cx), px(cy + r * 0.35)],
[px(cx - r * 0.75), px(cy + r * 0.8)]]);
} else if (typeIdx == 9) { // heart rate
} else if (typeIdx == 618 || typeIdx == 276 || typeIdx == 623) { // heart
dc.fillCircle(px(cx - r * 0.38), px(cy - r * 0.28), px(r * 0.44));
dc.fillCircle(px(cx + r * 0.38), px(cy - r * 0.28), px(r * 0.44));
dc.fillPolygon([[px(cx - r * 0.78), px(cy - r * 0.12)],
[px(cx + r * 0.78), px(cy - r * 0.12)],
[px(cx), px(cy + r * 0.85)]]);
} else { // floors: stairs
} else if (typeIdx == 4 || typeIdx == 5 || typeIdx == 6) { // stairs
for (var i = 0; i < 3; i++) {
dc.fillRectangle(px(cx - r * 0.85 + r * 0.58 * i),
px(cy + r * 0.6 - r * 0.55 * i),
px(r * 0.62), px(r * 0.4));
}
}
// Everything else -- dates, week numbers, custom text -- reads fine
// without a glyph, so no icon is drawn.
}
}
@@ -578,14 +435,10 @@ class Fenix8V3View extends WatchUi.WatchFace {
}
function drawTopComplication(dc as Dc, ti as Number, typeIdx as Number, isLeft as Boolean,
info as ActivityMonitor.Info, weather as Weather.CurrentConditions?,
stats as System.Stats, ds as System.DeviceSettings) as Void {
ctx as Fields.Ctx, level as Float) as Void {
var x = isLeft ? LEFT_X : RIGHT_X;
var level = 0.0f;
if (stats != null && stats.battery != null) { level = stats.battery / 100.0; }
drawComplicationIcon(dc, x, ICON_CY, 1.0, Themes.ACCENT[ti] as Number, typeIdx, level);
text(dc, x, VALUE_CY, mFontComp,
complicationValue(typeIdx, info, weather, stats, ds),
text(dc, x, VALUE_CY, mFontComp, Fields.value(typeIdx, ctx),
Graphics.TEXT_JUSTIFY_CENTER, Themes.TEXTPRIMARY[ti] as Number);
}
@@ -615,15 +468,12 @@ class Fenix8V3View extends WatchUi.WatchFace {
// FORMAT_SHORT, not FORMAT_MEDIUM: only the short form returns
// day_of_week and month as numbers rather than localised strings.
var g = Gregorian.info(Time.now(), Time.FORMAT_SHORT);
text(dc, DOW_CX, BAND_CY, mFontBand, mDow[g.day_of_week - 1],
text(dc, DOW_CX, BAND_CY, mFontBand, Fields.dow(g),
Graphics.TEXT_JUSTIFY_CENTER, col);
// DateFormat is "$1$ $2$" in English and "$1$$2$日" in Chinese, where
// the Chinese month names already carry their own 月.
text(dc, MD_CX, BAND_CY, mFontBand,
Lang.format(mDateFmt, [mMon[g.month - 1], g.day.format("%d")]),
text(dc, MD_CX, BAND_CY, mFontBand, Fields.monthDay(g),
Graphics.TEXT_JUSTIFY_CENTER, col);
if (ds == null || !ds.is24Hour) {
text(dc, AMPM_R, BAND_CY, mFontBand, mMeridiem[g.hour >= 12 ? 1 : 0],
text(dc, AMPM_R, BAND_CY, mFontBand, Fields.meridiem(g),
Graphics.TEXT_JUSTIFY_RIGHT, col);
}
}
@@ -653,49 +503,120 @@ class Fenix8V3View extends WatchUi.WatchFace {
dc.fillRectangle(px(COLON_X), px(COLON_Y2), px(COLON_W), px(COLON_H));
}
function drawBottom(dc as Dc, ti as Number, info as ActivityMonitor.Info,
weather as Weather.CurrentConditions?, stats as System.Stats,
ds as System.DeviceSettings) as Void {
function drawBottom(dc as Dc, ti as Number, ctx as Fields.Ctx) as Void {
var value = Themes.TEXTPRIMARY[ti] as Number;
var label = Themes.ACCENT[ti] as Number;
var left = getSetting("BottomLeft", 3);
var right = getSetting("BottomRight", 2);
text(dc, DIST_R, BOT_VAL_CY, mFontComp,
complicationValue(left, info, weather, stats, ds),
var right = getSetting("BottomRight", 1);
text(dc, DIST_R, BOT_VAL_CY, mFontComp, Fields.value(left, ctx),
Graphics.TEXT_JUSTIFY_RIGHT, value);
text(dc, DIST_R, BOT_LAB_CY, mFontComp, fieldLabel(left),
text(dc, DIST_R, BOT_LAB_CY, mFontComp, Fields.label(left),
Graphics.TEXT_JUSTIFY_RIGHT, label);
text(dc, STEP_L, BOT_VAL_CY, mFontComp,
complicationValue(right, info, weather, stats, ds),
text(dc, STEP_L, BOT_VAL_CY, mFontComp, Fields.value(right, ctx),
Graphics.TEXT_JUSTIFY_LEFT, value);
text(dc, STEP_L, BOT_LAB_CY, mFontComp, fieldLabel(right),
text(dc, STEP_L, BOT_LAB_CY, mFontComp, Fields.label(right),
Graphics.TEXT_JUSTIFY_LEFT, label);
}
// ------------------------------------------------------------------ AOD
function dim(col as Number, f as Float) as Number {
var r = (((col >> 16) & 0xFF) * f).toNumber();
var g = (((col >> 8) & 0xFF) * f).toNumber();
var b = ((col & 0xFF) * f).toNumber();
return (r << 16) | (g << 8) | b;
}
// Low-power face: no band fill, no unlit ticks, no complications -- just a
// dimmed time, the lit part of the ring, and the date. The whole thing
// walks a few pixels each minute so no pixel stays lit in one place.
function drawAmbient(dc as Dc, ti as Number, ds as System.DeviceSettings,
pTR as Float, pTL as Float, pBR as Float, pBL as Float) as Void {
var g = Gregorian.info(Time.now(), Time.FORMAT_SHORT);
var ox = ((g.min % 5) - 2) * 2.0 / mS; // +/- 4 device px, in design units
var oy = ((g.min / 5) % 5 - 2) * 2.0 / mS;
var top = Themes.RINGTOP[ti] as Array<Number>;
var bot = Themes.RINGBOTTOM[ti] as Array<Number>;
var litTR = (pTR * TOP_N).toNumber();
var litTL = (pTL * TOP_N).toNumber();
var litBR = (pBR * BOT_N).toNumber();
var litBL = (pBL * BOT_N).toNumber();
for (var i = 0; i < TOP_N; i++) {
var a = TOP_PH + TOP_PITCH * i;
if (i >= TOP_N - litTR) {
dc.setColor(dim(top[i], 0.45), Graphics.COLOR_TRANSPARENT);
tick(dc, a, TOP_HW);
}
if (i >= TOP_N - litTL) {
dc.setColor(dim(top[i], 0.45), Graphics.COLOR_TRANSPARENT);
tick(dc, -a, TOP_HW);
}
}
for (var i = 0; i < BOT_N; i++) {
var a = BOT_PH + BOT_PITCH * i;
if (i < litBL) {
dc.setColor(dim(bot[i], 0.45), Graphics.COLOR_TRANSPARENT);
tick(dc, 180.0 + a, BOT_HW);
}
if (i < litBR) {
dc.setColor(dim(bot[i], 0.45), Graphics.COLOR_TRANSPARENT);
tick(dc, 180.0 - a, BOT_HW);
}
}
var h = g.hour;
if (ds == null || !ds.is24Hour) {
if (h == 0) { h = 12; } else if (h > 12) { h = h - 12; }
}
var hours = Themes.HOURS[ti] as Array<Number>;
var mins = Themes.MINUTES[ti] as Array<Number>;
text(dc, HOURS_R + ox, TIME_CY + oy, mFontTime, h.format("%d"),
Graphics.TEXT_JUSTIFY_RIGHT, dim(hours[hours.size() / 2], 0.55));
text(dc, MINUTES_L + ox, TIME_CY + oy, mFontTime, g.min.format("%02d"),
Graphics.TEXT_JUSTIFY_LEFT, dim(mins[mins.size() / 2], 0.55));
dc.setColor(dim(Themes.COLON[ti] as Number, 0.55), Graphics.COLOR_TRANSPARENT);
dc.fillRectangle(px(COLON_X + ox), px(COLON_Y1 + oy), px(COLON_W), px(COLON_H));
dc.fillRectangle(px(COLON_X + ox), px(COLON_Y2 + oy), px(COLON_W), px(COLON_H));
var band = dim(Themes.ACCENT[ti] as Number, 0.55);
text(dc, DOW_CX + ox, BAND_CY + oy, mFontBand, Fields.dow(g),
Graphics.TEXT_JUSTIFY_CENTER, band);
text(dc, MD_CX + ox, BAND_CY + oy, mFontBand, Fields.monthDay(g),
Graphics.TEXT_JUSTIFY_CENTER, band);
}
// ----------------------------------------------------------------- main
function onUpdate(dc as Dc) as Void {
if (mW != dc.getWidth() || mDow == null) { onLayout(dc); }
if (mW != dc.getWidth() || !Fields.ready()) { onLayout(dc); }
if (dc has :setAntiAlias) { dc.setAntiAlias(true); }
var ti = themeIndex();
var info = ActivityMonitor.getInfo();
var stats = System.getSystemStats();
var ds = System.getDeviceSettings();
var weather = Weather.getCurrentConditions();
var ctx = new Fields.Ctx(ds, getSetting("TempUnit", 0));
var info = ctx.info();
var stats = ctx.stats();
dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK);
dc.clear();
drawRing(dc, ti,
metricProgress(getSetting("RingTR", 0), info),
metricProgress(getSetting("RingTL", 1), info),
metricProgress(getSetting("RingBR", 4), info),
metricProgress(getSetting("RingBL", 3), info));
var pTR = metricProgress(getSetting("RingTR", 0), info);
var pTL = metricProgress(getSetting("RingTL", 1), info);
var pBR = metricProgress(getSetting("RingBR", 4), info);
var pBL = metricProgress(getSetting("RingBL", 3), info);
if (mSleeping && mBurnIn) {
drawAmbient(dc, ti, ds, pTR, pTL, pBR, pBL);
return;
}
drawRing(dc, ti, pTR, pTL, pBR, pBL);
if (getBool("ShowTop", true)) {
var level = 0.0f;
if (stats != null && stats.battery != null) { level = stats.battery / 100.0; }
drawBattery(dc, ti, stats);
drawTopComplication(dc, ti, getSetting("LeftTop", 6), true, info, weather, stats, ds);
drawTopComplication(dc, ti, getSetting("RightTop", 8), false, info, weather, stats, ds);
drawTopComplication(dc, ti, getSetting("LeftTop", 712), true, ctx, level);
drawTopComplication(dc, ti, getSetting("RightTop", 639), false, ctx, level);
}
drawTime(dc, ti, ds);
@@ -705,7 +626,7 @@ class Fenix8V3View extends WatchUi.WatchFace {
}
if (getBool("ShowBottom", true)) {
drawBottom(dc, ti, info, weather, stats, ds);
drawBottom(dc, ti, ctx);
}
}
}