initial commit
This commit is contained in:
120
source/Background/Marks/IMark.mc
Normal file
120
source/Background/Marks/IMark.mc
Normal file
@ -0,0 +1,120 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class IMark extends Drawable {
|
||||
|
||||
var CenterShift as [Float, Float];
|
||||
var Color as ColorType;
|
||||
var InnerRadius as Float;
|
||||
var Radius as Float;
|
||||
var Seconds as Number;
|
||||
var Size as Float;
|
||||
|
||||
typedef MarkParams as {
|
||||
:Identifier as Object,
|
||||
:Color as ColorType,
|
||||
:Font as FontType, // not used
|
||||
:Seconds as Number,
|
||||
:Size as Float,
|
||||
:Field as FieldParams,
|
||||
};
|
||||
|
||||
enum MarkType {
|
||||
START_MARK = 0,
|
||||
PRIMARY_MARK = 1,
|
||||
SECONDARY_MARK = 2,
|
||||
TERTIARY_MARK = 3,
|
||||
}
|
||||
|
||||
enum MarkStyleType {
|
||||
EMPTY_MARK = 0,
|
||||
LINE_MARK = 1,
|
||||
DOUBLE_LINE_MARK = 2,
|
||||
DOT_MARK = 3,
|
||||
ARABIC_MARK = 4,
|
||||
ROMAN_MARK = 5,
|
||||
}
|
||||
|
||||
static function getMark(style as MarkStyleType, type as MarkType, options as MarkParams) as IMark? {
|
||||
switch (style) {
|
||||
case LINE_MARK:
|
||||
return new LineMark(options);
|
||||
case DOUBLE_LINE_MARK:
|
||||
return new DoubleLineMark(options);
|
||||
case DOT_MARK:
|
||||
return new DotMark(options);
|
||||
case ARABIC_MARK:
|
||||
return type == TERTIARY_MARK ? null : new ArabicMark(options);
|
||||
case ROMAN_MARK:
|
||||
return type == TERTIARY_MARK ? null : new RomanMark(options);
|
||||
case EMPTY_MARK:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static function getMarkType(seconds as Number) 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;
|
||||
}
|
||||
}
|
||||
|
||||
function initialize(options as MarkParams) {
|
||||
Drawable.initialize({:identifier => options[:Identifier]});
|
||||
|
||||
// scene
|
||||
var field = getOrElse(options[:Field], {}) as FieldParams;
|
||||
CenterShift = getOrElse(field[:CenterShift], [0.0, 0.0]);
|
||||
Radius = getOrElse(field[:Radius], 1.0);
|
||||
|
||||
// properties
|
||||
Color = options[:Color];
|
||||
Seconds = options[:Seconds];
|
||||
Size = options[:Size];
|
||||
|
||||
// calculated
|
||||
InnerRadius = Radius * (1 - Size);
|
||||
}
|
||||
|
||||
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 getAngle() as Float {
|
||||
return Math.toRadians(Seconds * 6.0 - 90);
|
||||
}
|
||||
|
||||
function getHours() as Number? {
|
||||
if (Seconds % 5 != 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var hours = Seconds / 5;
|
||||
if (hours == 0) {
|
||||
return 12;
|
||||
}
|
||||
|
||||
return hours;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user