initial commit

This commit is contained in:
2025-10-09 14:37:45 +03:00
commit 375da5802b
24 changed files with 812 additions and 0 deletions

26
source/Hands/BatonHand.mc Normal file
View File

@ -0,0 +1,26 @@
import Toybox.Graphics;
import Toybox.Lang;
class BatonHand extends IHand {
function initialize(options as IHand.HandParams) {
IHand.initialize(options);
}
function drawHand(dc as Dc, start as Point2D, length as Float) as Void {
var angle = Math.toRadians(getAngle(null) - 90);
var direction = [Math.cos(angle), Math.sin(angle)] as Point2D;
// body part
dc.setColor(Color, Color);
fillSuperellipse(dc, start, direction, length, Width);
// fill
dc.setColor(BackgroundColor, BackgroundColor);
var holeStart = [
start[0] + direction[0] * length * 0.33,
start[1] + direction[1] * length * 0.33
] as Point2D;
fillSuperellipse(dc, holeStart, direction, length * 0.66, Width * 0.66);
}
}

99
source/Hands/IHand.mc Normal file
View File

@ -0,0 +1,99 @@
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 Rotate as Float;
var Type as HandType;
var Width as Float;
typedef HandParams as {
:Identifier as Object,
:Color as ColorType,
:Rotate as Float,
: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];
Rotate = getOrElse(options[:Rotate], 0.0);
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) * 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:
angle = (now.hour % 12 + now.min / 60.0) * 30.0;
break;
case MINUTES_HAND:
angle = now.min * 6.0;
break;
case SECONDS_HAND:
angle = now.sec * 6.0;
break;
}
return angle + Rotate;
}
function getLenght(handType as HandType) as Float {
switch (handType) {
case HOURS_HAND:
return 0.7;
default:
return 1.0;
}
}
}

View File

@ -0,0 +1,18 @@
import Toybox.Graphics;
import Toybox.Lang;
class SimpleHand extends IHand {
function initialize(options as IHand.HandParams) {
IHand.initialize(options);
}
function drawHand(dc as Dc, start as Point2D, length as Float) as Void {
var angle = Math.toRadians(getAngle(null) - 90);
dc.setColor(Color, Color);
dc.drawLine(
start[0], start[1],
start[0] + length * Math.cos(angle), start[1] + length * Math.sin(angle)
);
}
}