initial commit

This commit is contained in:
2025-10-09 14:37:45 +03:00
commit 9693a4d426
17 changed files with 476 additions and 0 deletions

View File

@ -0,0 +1,44 @@
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;
class IBackground extends Drawable {
var Marks as Array<IMark> = new Array();
typedef BackgroundParams as {
:Identifier as Object,
};
enum BackgroundStyleType {
SOLID_BACKGROUND,
}
static function getBackground(style as BackgroundStyleType) as IBackground {
switch (style) {
case SOLID_BACKGROUND:
default:
return new SolidBackground({});
}
}
function initialize(options as BackgroundParams) {
Drawable.initialize({:identifier => options[:Identifier]});
for (var s = 0; s < 60; s += 5) {
var mark = IMark.getMark(IMark.LINE_MARK, {:Seconds => s});
if (mark != null) {
Marks.add(mark);
}
}
}
function draw(dc as Dc) as Void {
drawBackground(dc);
for (var i = 0; i < Marks.size(); ++i) {
Marks[i].draw(dc);
}
}
function drawBackground(dc as Dc) as Void {}
}

View File

@ -0,0 +1,81 @@
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,
:Type as MarkType,
:Seconds as Number,
:Color as ColorType,
:HandsParams as IHands.HandsParams,
};
enum MarkType {
START_MARK,
PRIMARY_MARK,
SECONDARY_MARK,
TERTIARY_MARK,
}
enum MarkStyleType {
LINE_MARK,
DOT_MARK,
ARABIC_MARK,
EMPTY_MARK,
}
static function getMark(style as MarkStyleType, options as MarkParams) as IMark? {
switch (style) {
case EMPTY_MARK:
return null;
case LINE_MARK:
default:
return new LineMark(options);
}
}
function initialize(options as MarkParams) {
Drawable.initialize({:identifier => options[:Identifier]});
CenterShift = getOrElse(getOrElse(options[:HandsParams], {}), [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);
drawMark(dc, center[0], center[1]);
}
function drawMark(dc as Dc, x as Float, y as Float) as Void {}
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) as Void {
var angle = Math.toRadians(Seconds * 6.0);
dc.setColor(Color, Graphics.COLOR_TRANSPARENT);
dc.drawLine(x + InnerRadius * Math.cos(angle), y + InnerRadius * Math.sin(angle),
x + Radius * Math.cos(angle), y + Radius * Math.sin(angle));
}
}

View File

@ -0,0 +1,24 @@
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;
class SolidBackground extends IBackground {
var Color as ColorType;
typedef SolidBackgroundParams as {
:BackgroundParams as IBackground.BackgroundParams,
:Color as ColorType,
};
function initialize(options as SolidBackgroundParams) {
IBackground.initialize(getOrElse(options[:BackgroundParams], {}));
Color = getOrElse(options[:Color], Graphics.COLOR_BLACK);
}
function drawBackground(dc as Dc) as Void {
dc.setColor(Graphics.COLOR_TRANSPARENT, Color);
dc.clear();
}
}