initial commit
This commit is contained in:
94
source/Hands/IHand.mc
Normal file
94
source/Hands/IHand.mc
Normal file
@ -0,0 +1,94 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.System;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class IHand extends Drawable {
|
||||
|
||||
var BackgroundColor as ColorType;
|
||||
var CenterShift as Point2D;
|
||||
var Color as ColorType;
|
||||
var Radius as Float;
|
||||
var Type as HandType;
|
||||
var Width as Float;
|
||||
|
||||
typedef HandParams as {
|
||||
:Identifier as Object,
|
||||
:Color as ColorType,
|
||||
:Type as HandType,
|
||||
:Width as Float,
|
||||
:Field as FieldParams,
|
||||
};
|
||||
|
||||
enum HandType {
|
||||
OTHER_HAND = 0,
|
||||
HOURS_HAND = 1,
|
||||
MINUTES_HAND = 2,
|
||||
SECONDS_HAND = 3,
|
||||
}
|
||||
|
||||
enum HandStyleType {
|
||||
EMPTY_HANDS = 0,
|
||||
SIMPLE_HANDS = 1,
|
||||
BATON_HANDS = 2,
|
||||
}
|
||||
|
||||
static function getHand(style as HandStyleType, options as HandParams) as IHand? {
|
||||
switch (style) {
|
||||
case SIMPLE_HANDS:
|
||||
return new SimpleHand(options);
|
||||
case BATON_HANDS:
|
||||
return new BatonHand(options);
|
||||
case EMPTY_HANDS:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function initialize(options as HandParams) {
|
||||
Drawable.initialize({:identifier => options[:Identifier]});
|
||||
|
||||
// scene
|
||||
var field = getOrElse(options[:Field], {}) as FieldParams;
|
||||
CenterShift = getOrElse(field[:CenterShift], [0.0, 0.0]);
|
||||
Radius = 0.95 * getOrElse(field[:Radius], 1.0);
|
||||
|
||||
// properties
|
||||
BackgroundColor = options[:BackgroundColor];
|
||||
Color = options[:Color];
|
||||
Type = options[:Type];
|
||||
Width = Radius * getOrElse(options[:Witdh], 0.05);
|
||||
}
|
||||
|
||||
function draw(dc as Dc) as Void {
|
||||
var center = getCenter(dc, CenterShift);
|
||||
var length = Radius * min(center[0], center[1]) * getLenght(Type);
|
||||
drawHand(dc, center, length);
|
||||
}
|
||||
|
||||
function drawHand(dc as Dc, start as Point2D, length as Float) as Void {}
|
||||
|
||||
function getAngle(angle as Float?) as Float? {
|
||||
var now = System.getClockTime();
|
||||
switch (Type) {
|
||||
case HOURS_HAND:
|
||||
return (now.hour % 12 + now.min / 60.0) * 30.0;
|
||||
case MINUTES_HAND:
|
||||
return now.min * 6.0;
|
||||
case SECONDS_HAND:
|
||||
return now.sec * 6.0;
|
||||
case OTHER_HAND:
|
||||
default:
|
||||
return angle;
|
||||
}
|
||||
}
|
||||
|
||||
function getLenght(handType as HandType) as Float {
|
||||
switch (handType) {
|
||||
case HOURS_HAND:
|
||||
return 0.7;
|
||||
default:
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user