initial commit
This commit is contained in:
79
source/Hands/IHands.mc
Normal file
79
source/Hands/IHands.mc
Normal file
@ -0,0 +1,79 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.System;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class IHands extends Drawable {
|
||||
|
||||
var BackgroundColor as ColorType;
|
||||
var CenterShift as [Float, Float];
|
||||
var Color as ColorType;
|
||||
var Radius as Float;
|
||||
var Type as HandType;
|
||||
|
||||
typedef HandsParams as {
|
||||
:Identifier as Object,
|
||||
:Color as ColorType,
|
||||
:Type as HandType,
|
||||
: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,
|
||||
}
|
||||
|
||||
static function getHands(style as HandStyleType, options as HandsParams) as IHands? {
|
||||
switch (style) {
|
||||
case SIMPLE_HANDS:
|
||||
return new SimpleHands(options);
|
||||
case EMPTY_HANDS:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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 = 0.95 * getOrElse(field[:Radius], 1.0);
|
||||
|
||||
// properties
|
||||
BackgroundColor = options[:BackgroundColor];
|
||||
Color = options[:Color];
|
||||
Type = options[:Type];
|
||||
}
|
||||
|
||||
function draw(dc as Dc) as Void {
|
||||
var center = getCenter(dc, CenterShift);
|
||||
var length = Radius * min(center[0], center[1]);
|
||||
drawHand(dc, center[0], center[1], length);
|
||||
}
|
||||
|
||||
function drawHand(dc as Dc, x as Float, y as Float, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
source/Hands/SimpleHands.mc
Normal file
26
source/Hands/SimpleHands.mc
Normal file
@ -0,0 +1,26 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
|
||||
class SimpleHands extends IHands {
|
||||
|
||||
function initialize(options as IHands.HandsParams) {
|
||||
IHands.initialize(options);
|
||||
}
|
||||
|
||||
function drawHand(dc as Dc, x as Float, y as Float, length as Float) as Void {
|
||||
var angle = Math.toRadians(getAngle(null) - 90);
|
||||
length *= getLenght(Type);
|
||||
|
||||
dc.setColor(Color, Color);
|
||||
dc.drawLine(x, y, x + length * Math.cos(angle), y + length * Math.sin(angle));
|
||||
}
|
||||
|
||||
private function getLenght(handType as IHands.HandType) as Float {
|
||||
switch (handType) {
|
||||
case HOURS_HAND:
|
||||
return 0.7;
|
||||
default:
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user