import Toybox.Application.Properties; import Toybox.Graphics; import Toybox.Lang; import Toybox.WatchUi; class IBackground extends Drawable { var Color as ColorType; var Hands as Array = []; var Marks as Array = []; typedef BackgroundParams as { :Identifier as Object, :Color as ColorType, :Hands as Array, }; enum BackgroundStyleType { SOLID_BACKGROUND, } static function getBackground(style as BackgroundStyleType, options as BackgroundParams) as IBackground { switch (style) { case SOLID_BACKGROUND: default: return new SolidBackground(options); } } function initialize(options as BackgroundParams) { var identifier = options[:Identifier]; Drawable.initialize({:identifier => identifier}); Color = Properties.getValue(Lang.format("$1$/Background/Color", [identifier])) as ColorType; for (var seconds = 0; seconds < 60; ++seconds) { var markType = IMark.getMarkType(seconds); var markIdentifier = Lang.format("$1$/Marks/$2$", [identifier, markType]); var markStyle = Properties.getValue(Lang.format("$1$/Type", [markIdentifier])) as IMark.MarkStyleType; var mark = IMark.getMark(markStyle, markType, { :Identifier => markIdentifier, :BackgroundColor => Color, :Color => Properties.getValue(Lang.format("$1$/Color", [markIdentifier])) as ColorType, :Seconds => seconds, :Size => markType == IMark.TERTIARY_MARK ? 0.033 : 0.1, }); if (mark != null) { Marks.add(mark); } } var hands = options[:Hands]; for (var i = 0; i < hands.size(); ++i) { var handType = hands[i]; var handIdentifier = Lang.format("$1$/Hands/$2$", [identifier, handType]); var handStyle = Properties.getValue(Lang.format("$1$/Type", [handIdentifier])) as IHand.HandStyleType; var handColor = Properties.getValue(Lang.format("$1$/Color", [handIdentifier])) as ColorType; // hand itself var hand = IHand.getHand(handStyle, { :Identifier => handIdentifier, :BackgroundColor => Color, :Color => handColor, :Type => handType, }); if (hand != null) { Hands.add(hand); } // counter hand hand = IHand.getHand(handStyle, { :Identifier => handIdentifier, :BackgroundColor => Color, :Color => handColor, :Rotate => 180.0, :Type => handType, :Field => { :Radius => 0.1, }, }); if (hand != null) { Hands.add(hand); } } } function draw(dc as Dc) as Void { drawBackground(dc); for (var i = 0; i < Marks.size(); ++i) { Marks[i].draw(dc); } var widths = [] as Array; var circleColor = null as ColorType; for (var i = 0; i < Hands.size(); ++i) { Hands[i].draw(dc); widths.add(Hands[i].Width); circleColor = Hands[i].Color; } var center = getCenter(dc, [0, 0]); var circleWidth = max(widths) * min(center); dc.setColor(circleColor, circleColor); dc.fillCircle(center[0], center[1], circleWidth); dc.setColor(Color, Color); dc.fillCircle(center[0], center[1], circleWidth * 0.5); } function drawBackground(dc as Dc) as Void {} }