Files
wf/source/Hands/IHands.mc
2025-11-04 16:37:25 +02:00

59 lines
1.6 KiB
MonkeyC

import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
class IHands extends Drawable {
var CenterShift as [Float, Float];
var Radius as Float;
typedef HandsParams as {
:CenterShift as [Float, Float],
:Identifier as Object,
:Radius as Float,
};
enum HandType {
HOURS_HAND,
MINUTES_HAND,
SECONDS_HAND,
}
enum HandStyleType {
SIMPLE_HANDS,
}
static function getHands(style as HandStyleType) as IHands {
switch (style) {
case SIMPLE_HANDS:
default:
return new SimpleHands({});
}
}
function initialize(options as HandsParams) {
Drawable.initialize({:identifier => options[:Identifier]});
CenterShift = getOrElse(options[:CenterShift], [0.0, 0.0]);
Radius = getOrElse(options[:Radius], 0.9);
}
function draw(dc as Dc) as Void {
var now = System.getClockTime();
var center = getCenter(dc, CenterShift);
var length = Radius * min(center[0], center[1]);
var hourAngle = (now.hour % 12 + now.min / 60.0) * 30.0;
drawHand(dc, center[0], center[1], hourAngle, length, HOURS_HAND);
var minutesAngle = now.min * 6.0;
drawHand(dc, center[0], center[1], minutesAngle, length, MINUTES_HAND);
var secondsAngle = now.sec * 6.0;
drawHand(dc, center[0], center[1], secondsAngle, length, SECONDS_HAND);
}
function drawHand(dc as Dc, x as Float, y as Float, angle as Float, length as Float, handType as HandType) as Void {}
}