initial commit
This commit is contained in:
44
source/Background/IBackground.mc
Normal file
44
source/Background/IBackground.mc
Normal file
@ -0,0 +1,44 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class IBackground extends Drawable {
|
||||
|
||||
var Marks as Array<IMark> = [];
|
||||
|
||||
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.DOUBLE_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 {}
|
||||
}
|
||||
23
source/Background/Marks/DoubleLineMark.mc
Normal file
23
source/Background/Marks/DoubleLineMark.mc
Normal 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));
|
||||
}
|
||||
}
|
||||
85
source/Background/Marks/IMark.mc
Normal file
85
source/Background/Marks/IMark.mc
Normal file
@ -0,0 +1,85 @@
|
||||
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 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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
source/Background/Marks/LineMark.mc
Normal file
20
source/Background/Marks/LineMark.mc
Normal 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));
|
||||
}
|
||||
}
|
||||
24
source/Background/SolidBackground.mc
Normal file
24
source/Background/SolidBackground.mc
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user