initial commit
This commit is contained in:
60
source/Hands/IHands.mc
Normal file
60
source/Hands/IHands.mc
Normal file
@ -0,0 +1,60 @@
|
||||
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 {
|
||||
:Identifier as Object,
|
||||
:Field as FieldParams,
|
||||
};
|
||||
|
||||
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]});
|
||||
|
||||
// scene
|
||||
var field = getOrElse(options[:Field], {}) as FieldParams;
|
||||
CenterShift = getOrElse(field[:CenterShift], [0.0, 0.0]);
|
||||
Radius = getOrElse(field[:Radius], 1.0);
|
||||
}
|
||||
|
||||
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 {}
|
||||
}
|
||||
Reference in New Issue
Block a user