51 lines
1.5 KiB
MonkeyC
51 lines
1.5 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;
|
|
|
|
enum HandType {
|
|
HOURS,
|
|
MINUTES,
|
|
SECONDS,
|
|
}
|
|
|
|
typedef HandsParams as {
|
|
:CenterShift as [Float, Float],
|
|
:Identifier as Object,
|
|
:Radius as Float,
|
|
};
|
|
|
|
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);
|
|
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);
|
|
|
|
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]];
|
|
}
|
|
} |