initial commit
This commit is contained in:
29
source/Background/Marks/ArabicMark.mc
Normal file
29
source/Background/Marks/ArabicMark.mc
Normal file
@ -0,0 +1,29 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class ArabicMark extends IMark {
|
||||
|
||||
var Font as FontType;
|
||||
|
||||
function initialize(options as IMark.MarkParams) {
|
||||
IMark.initialize(options);
|
||||
|
||||
Font = getOrElse(options[:Font], Graphics.FONT_SMALL);
|
||||
}
|
||||
|
||||
function drawMark(dc as Dc, x as Float, y as Float, length as Float) as Void {
|
||||
var angle = getAngle();
|
||||
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();
|
||||
}
|
||||
}
|
||||
18
source/Background/Marks/DotMark.mc
Normal file
18
source/Background/Marks/DotMark.mc
Normal file
@ -0,0 +1,18 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class DotMark extends IMark {
|
||||
|
||||
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 = getAngle();
|
||||
|
||||
dc.setColor(Color, Graphics.COLOR_TRANSPARENT);
|
||||
dc.fillCircle(x + length * InnerRadius * Math.cos(angle), y + length * InnerRadius * Math.sin(angle),
|
||||
length * Size / 2.0);
|
||||
}
|
||||
}
|
||||
22
source/Background/Marks/DoubleLineMark.mc
Normal file
22
source/Background/Marks/DoubleLineMark.mc
Normal file
@ -0,0 +1,22 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class DoubleLineMark extends IMark {
|
||||
|
||||
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 = getAngle();
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
121
source/Background/Marks/IMark.mc
Normal file
121
source/Background/Marks/IMark.mc
Normal file
@ -0,0 +1,121 @@
|
||||
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,
|
||||
:Seconds as Number,
|
||||
:Color as ColorType,
|
||||
:Font as FontType, // not used
|
||||
:Size as Float,
|
||||
:HandsParams as IHands.HandsParams,
|
||||
};
|
||||
|
||||
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, 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 new ArabicMark(options);
|
||||
case ROMAN_MARK:
|
||||
return 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]});
|
||||
|
||||
var handsParams = getOrElse(options[:HandsParams], {}) as IHands.HandsParams;
|
||||
|
||||
// scene
|
||||
CenterShift = getOrElse(handsParams[:CenterShift], [0.0, 0.0]);
|
||||
Radius = getOrElse(handsParams[:Radius], 1.0);
|
||||
|
||||
// properties
|
||||
Color = getOrElse(options[:Color], Graphics.COLOR_WHITE);
|
||||
Seconds = options[:Seconds];
|
||||
Size = getOrElse(options[:Size], 0.1);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
18
source/Background/Marks/LineMark.mc
Normal file
18
source/Background/Marks/LineMark.mc
Normal file
@ -0,0 +1,18 @@
|
||||
import Toybox.Graphics;
|
||||
import Toybox.Lang;
|
||||
import Toybox.WatchUi;
|
||||
|
||||
class LineMark extends IMark {
|
||||
|
||||
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 = getAngle();
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
41
source/Background/Marks/RomanMark.mc
Normal file
41
source/Background/Marks/RomanMark.mc
Normal file
@ -0,0 +1,41 @@
|
||||
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 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";
|
||||
case 12:
|
||||
return "XII";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user