initial commit

This commit is contained in:
2025-10-09 14:37:45 +03:00
commit 67b9a5a342
20 changed files with 590 additions and 0 deletions

View File

@ -0,0 +1,28 @@
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;
class ArabicMark extends IMark {
var InnerRadius as Float = 0.9;
var Font as Graphics.FontType = Graphics.FONT_SMALL;
function initialize(options as IMark.MarkParams) {
IMark.initialize(options);
}
function drawMark(dc as Dc, x as Float, y as Float, length as Float) as Void {
var angle = Math.toRadians(Seconds * 6.0 - 90);
var text = secondsToText();
var dimentions = dc.getTextDimensions(text, Font);
dc.setColor(Color, Graphics.COLOR_TRANSPARENT);
dc.drawText(x + length * InnerRadius * Math.cos(angle) - dimentions[0] / 2.0,
y + length * InnerRadius * Math.sin(angle) - dimentions[1] / 2.0,
Font, text, Graphics.TEXT_JUSTIFY_LEFT);
}
function secondsToText() as String? {
return getHours().toString();
}
}

View File

@ -0,0 +1,23 @@
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;
class DoubleLineMark extends IMark {
var InnerRadius as Float = 0.9;
var Offset as Float = Math.toRadians(1.0);
function initialize(options as IMark.MarkParams) {
IMark.initialize(options);
}
function drawMark(dc as Dc, x as Float, y as Float, length as Float) as Void {
var angle = Math.toRadians(Seconds * 6.0 - 90);
dc.setColor(Color, Color);
dc.drawLine(x + length * InnerRadius * Math.cos(angle - Offset), y + length * InnerRadius * Math.sin(angle - Offset),
x + length * Radius * Math.cos(angle - Offset), y + length * Radius * Math.sin(angle - Offset));
dc.drawLine(x + length * InnerRadius * Math.cos(angle + Offset), y + length * InnerRadius * Math.sin(angle + Offset),
x + length * Radius * Math.cos(angle + Offset), y + length * Radius * Math.sin(angle + Offset));
}
}

View File

@ -0,0 +1,102 @@
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;
class IMark extends Drawable {
var CenterShift as [Float, Float];
var Color as ColorType;
var Radius as Float;
var Seconds as Number;
typedef MarkParams as {
:Identifier as Object,
:Seconds as Number,
:Color as ColorType,
:HandsParams as IHands.HandsParams,
};
enum MarkType {
START_MARK,
PRIMARY_MARK,
SECONDARY_MARK,
TERTIARY_MARK,
}
enum MarkStyleType {
LINE_MARK,
DOUBLE_LINE_MARK,
DOT_MARK,
ARABIC_MARK,
ROMAN_MARK,
EMPTY_MARK,
}
static function getMark(style as MarkStyleType, options as MarkParams) as IMark? {
switch (style) {
case LINE_MARK:
return new LineMark(options);
case DOUBLE_LINE_MARK:
return new DoubleLineMark(options);
case ARABIC_MARK:
return new ArabicMark(options);
case ROMAN_MARK:
return new RomanMark(options);
case EMPTY_MARK:
default:
return null;
}
}
function initialize(options as MarkParams) {
Drawable.initialize({:identifier => options[:Identifier]});
CenterShift = getOrElse(getOrElse(options[:HandsParams], {})[:CenterShift], [0.0, 0.0]);
Color = getOrElse(options[:Color], Graphics.COLOR_WHITE);
Radius = getOrElse(options[:Radius], 1.0);
Seconds = options[:Seconds];
}
function draw(dc as Dc) as Void {
var center = getCenter(dc, CenterShift);
var length = min(center[0], center[1]);
drawMark(dc, center[0], center[1], length);
}
function drawMark(dc as Dc, x as Float, y as Float, length as Float) as Void {}
function getHours() as Number? {
if (Seconds % 5 != 0) {
return null;
}
var hours = Seconds / 5;
if (hours == 0) {
return 12;
}
return hours;
}
function getMarkType() as MarkType {
switch (Seconds) {
case 0:
return START_MARK;
case 15:
case 30:
case 45:
return PRIMARY_MARK;
case 5:
case 10:
case 20:
case 25:
case 35:
case 40:
case 50:
case 55:
return SECONDARY_MARK;
default:
return TERTIARY_MARK;
}
}
}

View File

@ -0,0 +1,20 @@
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;
class LineMark extends IMark {
var InnerRadius as Float = 0.9;
function initialize(options as IMark.MarkParams) {
IMark.initialize(options);
}
function drawMark(dc as Dc, x as Float, y as Float, length as Float) as Void {
var angle = Math.toRadians(Seconds * 6.0 - 90);
dc.setColor(Color, Color);
dc.drawLine(x + length * InnerRadius * Math.cos(angle), y + length * InnerRadius * Math.sin(angle),
x + length * Radius * Math.cos(angle), y + length * Radius * Math.sin(angle));
}
}

View File

@ -0,0 +1,42 @@
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;
class RomanMark extends ArabicMark {
function initialize(options as IMark.MarkParams) {
ArabicMark.initialize(options);
}
function secondsToText() as String? {
switch (getHours()) {
case 0:
case 12:
return "XII";
case 1:
return "I";
case 2:
return "II";
case 3:
return "III";
case 4:
return "IV";
case 5:
return "V";
case 6:
return "VI";
case 7:
return "VII";
case 8:
return "VIII";
case 9:
return "IX";
case 10:
return "X";
case 11:
return "XI";
default:
return null;
}
}
}