initial commit

This commit is contained in:
2025-10-09 14:37:45 +03:00
commit 7471a6d2d7
15 changed files with 337 additions and 0 deletions

48
source/Hands/IHands.mc Normal file
View File

@ -0,0 +1,48 @@
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
class IHands extends Drawable {
var CenterShift as [Float, Float];
enum HandType {
HOURS,
MINUTES,
SECONDS,
}
typedef HandsParams as {
:CenterShift as [Float, Float],
:Identifier as Object,
};
function initialize(options as HandsParams) {
Drawable.initialize({:identifier => options[:Identifier]});
CenterShift = getOrElse(options[:CenterShift], [0.0, 0.0]);
}
function draw(dc as Dc) as Void {
var now = System.getClockTime();
var center = getCenter(dc);
var length = 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);
var minutesAngle = now.min * 6.0;
drawHand(dc, center[0], center[1], minutesAngle, length, MINUTES);
var secondsAngle = now.sec * 6.0;
drawHand(dc, center[0], center[1], secondsAngle, length, SECONDS);
}
function drawHand(dc as Dc, x as Float, y as Float, angle as Float, length as Float, handType as HandType) as Void {}
function getCenter(dc as Dc) as [Float, Float] {
return [dc.getWidth() / 2.0 + CenterShift[0], dc.getHeight() / 2.0 + CenterShift[1]];
}
}

View 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 IHands.SECONDS:
return SecondsColor;
default:
return Color;
}
}
private function getLenght(handType as IHands.HandType) as Float {
switch (handType) {
case IHands.HOURS:
return 0.6;
default:
return 0.9;
}
}
}