initial commit
This commit is contained in:
48
source/Hands/SimpleHands.mc
Normal file
48
source/Hands/SimpleHands.mc
Normal file
@ -0,0 +1,48 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
|
||||
class SimpleHands extends IHands {
|
||||
|
||||
var Color as ColorType;
|
||||
var SecondsColor as ColorType;
|
||||
|
||||
typedef SimpleHandsParams as {
|
||||
:HandsParams as IHands.HandsParams,
|
||||
:Color as ColorType,
|
||||
:SecondsColor as ColorType,
|
||||
};
|
||||
|
||||
function initialize(options as SimpleHandsParams) {
|
||||
IHands.initialize(getOrElse(options[:HandsParams], {}));
|
||||
|
||||
Color = getOrElse(options[:Color], Graphics.COLOR_WHITE);
|
||||
SecondsColor = getOrElse(options[:SecondsColor], Graphics.COLOR_RED);
|
||||
}
|
||||
|
||||
function drawHand(dc as Dc, x as Float, y as Float, angle as Float, length as Float, handType as IHands.HandType) as Void {
|
||||
var rad = (angle - 90) * Math.PI / 180.0;
|
||||
var color = getColor(handType);
|
||||
length *= getLenght(handType);
|
||||
|
||||
dc.setColor(color, color);
|
||||
dc.drawLine(x, y, x + length * Math.cos(rad), y + length * Math.sin(rad));
|
||||
}
|
||||
|
||||
private function getColor(handType as IHands.HandType) as ColorType {
|
||||
switch (handType) {
|
||||
case SECONDS_HAND:
|
||||
return SecondsColor;
|
||||
default:
|
||||
return Color;
|
||||
}
|
||||
}
|
||||
|
||||
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