initial commit
This commit is contained in:
47
source/Hands/Hands.mc
Normal file
47
source/Hands/Hands.mc
Normal file
@ -0,0 +1,47 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.System;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class Hands extends Drawable {
|
||||
|
||||
var CenterShift as [Float, Float];
|
||||
|
||||
enum HandType {
|
||||
HOURS,
|
||||
MINUTES,
|
||||
SECONDS,
|
||||
}
|
||||
|
||||
typedef HandsParams as {
|
||||
:CenterShift as [Float, Float],
|
||||
};
|
||||
|
||||
function initialize(options as HandsParams) {
|
||||
WatchUi.Drawable.initialize({});
|
||||
|
||||
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]];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user