Files
wf/source/Hands/IHands.mc
2025-10-09 17:18:45 +03:00

48 lines
1.3 KiB
MonkeyC

import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
class IHands extends Drawable {
var CenterShift as [Float, Float];
enum HandType {
HOURS,
MINUTES,
SECONDS,
}
typedef HandsParams as {
:CenterShift as [Float, Float],
:Identifier as Object,
};
function initialize(options as HandsParams) {
Drawable.initialize({:identifier => options[:Identifier]});
CenterShift = getOrElse(options[:CenterShift], [0.0, 0.0]);
}
function draw(dc as Dc) as Void {
var now = System.getClockTime();
var center = getCenter(dc);
var length = 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);
var minutesAngle = now.min * 6.0;
drawHand(dc, center[0], center[1], minutesAngle, length, MINUTES);
var secondsAngle = now.sec * 6.0;
drawHand(dc, center[0], center[1], secondsAngle, length, SECONDS);
}
function drawHand(dc as Dc, x as Float, y as Float, angle as Float, length as Float, handType as HandType) as Void {}
function getCenter(dc as Dc) as [Float, Float] {
return [dc.getWidth() / 2.0 + CenterShift[0], dc.getHeight() / 2.0 + CenterShift[1]];
}
}