From 02f2ddad586fc60ba7b4d4428f8a42fc3915a26a Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Thu, 21 Nov 2024 17:24:09 +0100 Subject: [PATCH] Massive performance increase for drawing arms Fixed formatting when steps pass 10k --- KittieCats/resources/drawables/arm_hour.svg | 41 ++++++++++++-- KittieCats/resources/drawables/arm_minute.svg | 41 ++++++++++++-- KittieCats/resources/drawables/arm_second.svg | 49 ++++++++++++++--- .../resources/drawables/arm_second_xmas.svg | 49 ++++++++++++++--- KittieCats/source/ComplicationSubscriber.mc | 5 +- KittieCats/source/KittieCatsView.mc | 55 +++++++++++-------- 6 files changed, 186 insertions(+), 54 deletions(-) diff --git a/KittieCats/resources/drawables/arm_hour.svg b/KittieCats/resources/drawables/arm_hour.svg index 6ccd3e8..48121cc 100644 --- a/KittieCats/resources/drawables/arm_hour.svg +++ b/KittieCats/resources/drawables/arm_hour.svg @@ -1,7 +1,38 @@ - - + + + + + id="Hours" + d="M 7.22266,90.28315 V 76.74068 c 0.90283,0 1.80566,-0.90283 1.80566,-1.80567 V 4.51416 A 4.51416,4.51416 0 0 0 0,4.51416 v 70.42085 c 0,0.90284 0.90283,1.80567 1.80567,1.80567 v 13.54247 z" + style="fill:#ffffff;fill-opacity:1;stroke-width:0.902833" /> diff --git a/KittieCats/resources/drawables/arm_minute.svg b/KittieCats/resources/drawables/arm_minute.svg index 2895a27..0f22c62 100644 --- a/KittieCats/resources/drawables/arm_minute.svg +++ b/KittieCats/resources/drawables/arm_minute.svg @@ -1,7 +1,38 @@ - - + + + + + id="Minutes" + d="m 8.736855,175.75556 v -13.54247 c 0.90283,0 1.80566,-0.90283 1.80566,-1.80567 V 6.0283512 c 0,-6.01887498 -9.02832,-6.01887498 -9.02832,0 V 160.40742 c 0,0.90284 0.90283,1.80567 1.80567,1.80567 v 13.54247 z" + style="fill:none;stroke:#ffffff;stroke-width:3.02839;stroke-dasharray:none;stroke-opacity:1" /> diff --git a/KittieCats/resources/drawables/arm_second.svg b/KittieCats/resources/drawables/arm_second.svg index 848d727..f44868f 100644 --- a/KittieCats/resources/drawables/arm_second.svg +++ b/KittieCats/resources/drawables/arm_second.svg @@ -1,11 +1,42 @@ - - + + + + + id="SecondsShadow" + d="m 13.61862,1.1982197 c 2.02769,-0.06684 3.97909,0.925005 5.3172,2.409994 1.90372,-2.144888 5.23527,-3.13321604 7.89266,-1.809342 2.52051,1.170679 3.91015,3.996942 3.91897,6.69623 3.40938,-0.16756 6.23883,3.0912163 6.09772,6.4042023 0.0693,3.38999 -2.06308,6.87354 -5.26051,8.10494 0.76688,2.96527 0.94193,6.65112 -1.3959,8.98247 -1.90655,1.93296 -4.93353,1.60821 -7.27125,0.75847 -2.4847,-0.99457 -5.27721,-0.96489 -7.77774,-0.0439 -2.35161,0.80511 -5.3357502,1.25171 -7.3125902,-0.62986 -2.35998,-2.3436 -2.2342,-6.06153 -1.4726,-9.06731 -4.36788,-1.67729 -6.77076995,-7.59564 -4.27716,-11.69914 1.06599,-1.7378093 3.07422,-2.8516933 5.11404,-2.8123373 -0.0413,-3.591749 2.61044,-7.293038 6.4271602,-7.294408 z m -1.7574,4.757111 c -1.81191,2.461002 -0.69753,6.5363503 2.10233,7.7400003 1.83209,0.754723 3.6239,-1.046341 3.67148,-2.833606 0.27419,-2.4515423 -1.11313,-5.5936703 -3.83477,-5.8429673 -0.74928,-0.0043 -1.45448,0.379707 -1.93904,0.936573 z m 10.35556,-0.159374 c -2.08352,1.748987 -2.73576,5.3711023 -0.77164,7.4382223 1.55853,1.421385 3.90042,0.146312 4.71545,-1.489157 1.13569,-1.9537753 1.2561,-5.0577033 -0.84008,-6.4169763 -1.00328,-0.592007 -2.26821,-0.261696 -3.10373,0.467911 z M 5.4849698,13.100839 c -1.56954,2.408565 0.28195,5.985475 2.95477,6.615655 1.9636602,0.49207 3.2626102,-1.78145 2.7510902,-3.4832 -0.42569,-2.104647 -2.4609702,-4.499985 -4.8119002,-3.776243 -0.34917,0.12866 -0.65856,0.356552 -0.89396,0.643788 z M 29.79948,12.467262 c -2.35708,0.879767 -3.94907,4.016492 -2.65012,6.313882 1.02886,1.61396 3.37794,0.97766 4.42757,-0.28266 1.44246,-1.41706 2.18595,-4.20365 0.53257,-5.729753 -0.64676,-0.478385 -1.56847,-0.586192 -2.31002,-0.301487 z m -15.45702,5.213092 c -3.16888,2.49136 -5.4173502,6.72605 -4.3986602,10.80009 0.7864802,2.05737 3.2771402,0.72905 4.7472202,0.35071 2.34808,-0.80131 4.91393,-1.09759 7.31867,-0.35434 1.7404,0.36092 3.39777,1.43912 5.22653,0.96777 1.36569,-1.08041 1.07795,-3.12191 0.86589,-4.65793 -0.80209,-3.86387 -3.67062,-7.23932 -7.29214,-8.76146 -2.27512,-0.82849 -4.71598,0.16902 -6.46751,1.65517 z" + style="fill:#000000;fill-opacity:0.501873;stroke-width:0.75242" /> - + id="Seconds" + d="m 12.5486,0.00318566 c 2.02769,-0.06687 3.97909,0.925006 5.3172,2.40999404 1.90371,-2.14488804 5.23526,-3.13321604 7.89266,-1.80934104 2.52051,1.17067904 3.91015,3.99694204 3.91896,6.69622904 3.40939,-0.16756 6.23884,3.0912163 6.09773,6.4041993 0.0693,3.389997 -2.06309,6.873547 -5.26051,8.104947 0.76688,2.96527 0.94193,6.65112 -1.3959,8.98247 -1.90655,1.93295 -4.93353,1.60821 -7.27125,0.75847 -2.4847,-0.99458 -5.27721,-0.9649 -7.77775,-0.0439 -2.35161,0.8051 -5.3357402,1.2517 -7.3125902,-0.62986 -2.35997,-2.3436 -2.2342,-6.06154 -1.47259,-9.06731 -4.36787995,-1.67729 -6.77078,-7.595648 -4.27717,-11.699145 1.06599,-1.7378083 3.07423,-2.8516923 5.11405,-2.8123363 -0.0413,-3.591749 2.61044,-7.29303804 6.4271602,-7.29440804 z M 10.7912,4.7602967 c -1.8119202,2.461002 -0.69753,6.5363503 2.10233,7.7400003 1.83209,0.754727 3.6239,-1.04634 3.67148,-2.8336053 0.27418,-2.451543 -1.11313,-5.593671 -3.83477,-5.842967 -0.74928,-0.0043 -1.45448,0.379707 -1.93904,0.936572 z m 10.35556,-0.159374 c -2.08352,1.748988 -2.73576,5.371102 -0.77164,7.4382223 1.55853,1.421381 3.90041,0.146312 4.71545,-1.489156 1.13569,-1.9537753 1.2561,-5.0577043 -0.84008,-6.4169773 -1.00328,-0.592007 -2.26821,-0.261696 -3.10373,0.467911 z M 4.4149498,11.905806 c -1.56955,2.408558 0.28195,5.985468 2.95476,6.615648 1.96367,0.49207 3.2626102,-1.78144 2.7511002,-3.48319 -0.4256902,-2.10465 -2.4609702,-4.499988 -4.8119002,-3.776246 -0.34918,0.128659 -0.65856,0.356552 -0.89396,0.643788 z M 28.72946,11.272229 c -2.35708,0.879766 -3.94907,4.016485 -2.65012,6.313885 1.02886,1.61395 3.37794,0.97765 4.42757,-0.28263 1.44246,-1.41706 2.18595,-4.203652 0.53257,-5.729751 -0.64677,-0.478385 -1.56847,-0.586192 -2.31002,-0.301487 z m -15.45702,5.213095 c -3.16888,2.49136 -5.4173502,6.72604 -4.3986602,10.80009 0.78648,2.05737 3.2771402,0.72905 4.7472202,0.35071 2.34807,-0.80132 4.91393,-1.0976 7.31867,-0.35434 1.7404,0.36092 3.39777,1.43912 5.22653,0.96777 1.36569,-1.08041 1.07795,-3.12191 0.86589,-4.65793 -0.8021,-3.86388 -3.67062,-7.23933 -7.29214,-8.76147 -2.27512,-0.828479 -4.71598,0.16902 -6.46751,1.65518 z" + style="fill:#c7ae54;fill-opacity:1;stroke-width:0.75242" /> + diff --git a/KittieCats/resources/drawables/arm_second_xmas.svg b/KittieCats/resources/drawables/arm_second_xmas.svg index f75b3c8..4ce1213 100644 --- a/KittieCats/resources/drawables/arm_second_xmas.svg +++ b/KittieCats/resources/drawables/arm_second_xmas.svg @@ -1,11 +1,42 @@ - - + + + + + id="SecondsShadow" + d="m 13.61862,1.1982197 c 2.02769,-0.06684 3.97909,0.925005 5.3172,2.409994 1.90372,-2.144888 5.23527,-3.13321604 7.89266,-1.809342 2.52051,1.170679 3.91015,3.996942 3.91897,6.69623 3.40938,-0.16756 6.23883,3.0912163 6.09772,6.4042023 0.0693,3.38999 -2.06308,6.87354 -5.26051,8.10494 0.76688,2.96527 0.94193,6.65112 -1.3959,8.98247 -1.90655,1.93296 -4.93353,1.60821 -7.27125,0.75847 -2.4847,-0.99457 -5.27721,-0.96489 -7.77774,-0.0439 -2.35161,0.80511 -5.3357502,1.25171 -7.3125902,-0.62986 -2.35998,-2.3436 -2.2342,-6.06153 -1.4726,-9.06731 -4.36788,-1.67729 -6.77076995,-7.59564 -4.27716,-11.69914 1.06599,-1.7378093 3.07422,-2.8516933 5.11404,-2.8123373 -0.0413,-3.591749 2.61044,-7.293038 6.4271602,-7.294408 z m -1.7574,4.757111 c -1.81191,2.461002 -0.69753,6.5363503 2.10233,7.7400003 1.83209,0.754723 3.6239,-1.046341 3.67148,-2.833606 0.27419,-2.4515423 -1.11313,-5.5936703 -3.83477,-5.8429673 -0.74928,-0.0043 -1.45448,0.379707 -1.93904,0.936573 z m 10.35556,-0.159374 c -2.08352,1.748987 -2.73576,5.3711023 -0.77164,7.4382223 1.55853,1.421385 3.90042,0.146312 4.71545,-1.489157 1.13569,-1.9537753 1.2561,-5.0577033 -0.84008,-6.4169763 -1.00328,-0.592007 -2.26821,-0.261696 -3.10373,0.467911 z M 5.4849698,13.100839 c -1.56954,2.408565 0.28195,5.985475 2.95477,6.615655 1.9636602,0.49207 3.2626102,-1.78145 2.7510902,-3.4832 -0.42569,-2.104647 -2.4609702,-4.499985 -4.8119002,-3.776243 -0.34917,0.12866 -0.65856,0.356552 -0.89396,0.643788 z M 29.79948,12.467262 c -2.35708,0.879767 -3.94907,4.016492 -2.65012,6.313882 1.02886,1.61396 3.37794,0.97766 4.42757,-0.28266 1.44246,-1.41706 2.18595,-4.20365 0.53257,-5.729753 -0.64676,-0.478385 -1.56847,-0.586192 -2.31002,-0.301487 z m -15.45702,5.213092 c -3.16888,2.49136 -5.4173502,6.72605 -4.3986602,10.80009 0.7864802,2.05737 3.2771402,0.72905 4.7472202,0.35071 2.34808,-0.80131 4.91393,-1.09759 7.31867,-0.35434 1.7404,0.36092 3.39777,1.43912 5.22653,0.96777 1.36569,-1.08041 1.07795,-3.12191 0.86589,-4.65793 -0.80209,-3.86387 -3.67062,-7.23932 -7.29214,-8.76146 -2.27512,-0.82849 -4.71598,0.16902 -6.46751,1.65517 z" + style="fill:#000000;fill-opacity:0.501873;stroke-width:0.75242" /> - + id="Seconds" + d="m 12.5486,0.00318566 c 2.02769,-0.06687 3.97909,0.925006 5.3172,2.40999404 1.90371,-2.14488804 5.23526,-3.13321604 7.89266,-1.80934104 2.52051,1.17067904 3.91015,3.99694204 3.91896,6.69622904 3.40939,-0.16756 6.23884,3.0912163 6.09773,6.4041993 0.0693,3.389997 -2.06309,6.873547 -5.26051,8.104947 0.76688,2.96527 0.94193,6.65112 -1.3959,8.98247 -1.90655,1.93295 -4.93353,1.60821 -7.27125,0.75847 -2.4847,-0.99458 -5.27721,-0.9649 -7.77775,-0.0439 -2.35161,0.8051 -5.3357402,1.2517 -7.3125902,-0.62986 -2.35997,-2.3436 -2.2342,-6.06154 -1.47259,-9.06731 -4.36787995,-1.67729 -6.77078,-7.595648 -4.27717,-11.699145 1.06599,-1.7378083 3.07423,-2.8516923 5.11405,-2.8123363 -0.0413,-3.591749 2.61044,-7.29303804 6.4271602,-7.29440804 z M 10.7912,4.7602967 c -1.8119202,2.461002 -0.69753,6.5363503 2.10233,7.7400003 1.83209,0.754727 3.6239,-1.04634 3.67148,-2.8336053 0.27418,-2.451543 -1.11313,-5.593671 -3.83477,-5.842967 -0.74928,-0.0043 -1.45448,0.379707 -1.93904,0.936572 z m 10.35556,-0.159374 c -2.08352,1.748988 -2.73576,5.371102 -0.77164,7.4382223 1.55853,1.421381 3.90041,0.146312 4.71545,-1.489156 1.13569,-1.9537753 1.2561,-5.0577043 -0.84008,-6.4169773 -1.00328,-0.592007 -2.26821,-0.261696 -3.10373,0.467911 z M 4.4149498,11.905806 c -1.56955,2.408558 0.28195,5.985468 2.95476,6.615648 1.96367,0.49207 3.2626102,-1.78144 2.7511002,-3.48319 -0.4256902,-2.10465 -2.4609702,-4.499988 -4.8119002,-3.776246 -0.34918,0.128659 -0.65856,0.356552 -0.89396,0.643788 z M 28.72946,11.272229 c -2.35708,0.879766 -3.94907,4.016485 -2.65012,6.313885 1.02886,1.61395 3.37794,0.97765 4.42757,-0.28263 1.44246,-1.41706 2.18595,-4.203652 0.53257,-5.729751 -0.64677,-0.478385 -1.56847,-0.586192 -2.31002,-0.301487 z m -15.45702,5.213095 c -3.16888,2.49136 -5.4173502,6.72604 -4.3986602,10.80009 0.78648,2.05737 3.2771402,0.72905 4.7472202,0.35071 2.34807,-0.80132 4.91393,-1.0976 7.31867,-0.35434 1.7404,0.36092 3.39777,1.43912 5.22653,0.96777 1.36569,-1.08041 1.07795,-3.12191 0.86589,-4.65793 -0.8021,-3.86388 -3.67062,-7.23933 -7.29214,-8.76147 -2.27512,-0.828479 -4.71598,0.16902 -6.46751,1.65518 z" + style="fill:#36ad76;fill-opacity:1;stroke-width:0.75242" /> + diff --git a/KittieCats/source/ComplicationSubscriber.mc b/KittieCats/source/ComplicationSubscriber.mc index b2b3fe6..f20159e 100644 --- a/KittieCats/source/ComplicationSubscriber.mc +++ b/KittieCats/source/ComplicationSubscriber.mc @@ -76,7 +76,8 @@ class ComplicationSubscriber function onComplicationChanged(complicationId as Complications.Id) as Void { - var complicationValue = Complications.getComplication(complicationId).value; + var complication = Complications.getComplication(complicationId); + var complicationValue = complication.value; switch (complicationId) { @@ -88,7 +89,7 @@ class ComplicationSubscriber case self.stepsComplicationId: { - self.steps = complicationValue; + self.steps = complication.unit.equals("K") ? Math.floor(complicationValue * 1000) : complicationValue; break; } diff --git a/KittieCats/source/KittieCatsView.mc b/KittieCats/source/KittieCatsView.mc index 047ebca..9013dc6 100644 --- a/KittieCats/source/KittieCatsView.mc +++ b/KittieCats/source/KittieCatsView.mc @@ -8,7 +8,7 @@ import Toybox.WatchUi; class KittieCatsView extends WatchUi.WatchFace { - private var theme; + private var theme = null; private var backgroundHi; private var backgroundLo; @@ -22,6 +22,9 @@ class KittieCatsView extends WatchUi.WatchFace private var icons; private var iconSize; + private var screenCenterX; + private var screenCenterY; + private var sleepTime; private var wakeTime; @@ -36,26 +39,31 @@ class KittieCatsView extends WatchUi.WatchFace function onLayout(dc as Dc) as Void { + self.screenCenterX = Math.floor(dc.getWidth() / 2); + self.screenCenterY = Math.floor(dc.getHeight() / 2); } function onShow() as Void { - self.theme = ThemeManager.getInstance().getCurrentTheme(); + var currentTheme = ThemeManager.getInstance().getCurrentTheme(); + if (currentTheme != self.theme) + { + self.theme = currentTheme; - self.backgroundHi = Application.loadResource(self.theme.BackgroundHi); - self.backgroundLo = Application.loadResource(self.theme.BackgroundLo); + self.backgroundHi = Application.loadResource(self.theme.BackgroundHi); + self.backgroundLo = Application.loadResource(self.theme.BackgroundLo); - self.armHour = Application.loadResource(self.theme.ArmHour); - self.armMinute = Application.loadResource(self.theme.ArmMinute); - self.armSecond = Application.loadResource(self.theme.ArmSecond); + self.armHour = Application.loadResource(self.theme.ArmHour); + self.armMinute = Application.loadResource(self.theme.ArmMinute); + self.armSecond = Application.loadResource(self.theme.ArmSecond); - self.minuteOrnamentLo = Application.loadResource(self.theme.MinuteOrnamentLo); - - - self.icons = Application.loadResource(Rez.Drawables.Icons); - self.iconSize = self.icons.getHeight(); + self.minuteOrnamentLo = self.theme.MinuteOrnamentLo != null ? Application.loadResource(self.theme.MinuteOrnamentLo) : null; + + self.icons = Application.loadResource(Rez.Drawables.Icons); + self.iconSize = self.icons.getHeight(); + } var profile = UserProfile.getProfile(); self.sleepTime = profile.sleepTime; @@ -87,7 +95,6 @@ class KittieCatsView extends WatchUi.WatchFace dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK); dc.clear(); - dc.setAntiAlias(true); dc.drawBitmap(0, 0, highPowerMode ? self.backgroundHi : self.backgroundLo); @@ -105,12 +112,12 @@ class KittieCatsView extends WatchUi.WatchFace // --- Arms --- // Base the hour arm on minutes as well, to prevent the arm from staying on the // current hour tick mark right up until the 59th minute - self.drawArm(dc, self.armHour, (clockTime.hour * 60) + clockTime.min, 720, highPowerMode ? self.theme.ArmHourTintHi : self.theme.ArmHourTintLo); - self.drawArm(dc, self.armMinute, clockTime.min, 60, highPowerMode ? self.theme.ArmMinuteTintHi : self.theme.ArmMinuteTintLo); + self.drawArm(dc, self.armHour, 0, (clockTime.hour * 60) + clockTime.min, 720, highPowerMode ? self.theme.ArmHourTintHi : self.theme.ArmHourTintLo); + self.drawArm(dc, self.armMinute, 0, clockTime.min, 60, highPowerMode ? self.theme.ArmMinuteTintHi : self.theme.ArmMinuteTintLo); if (highPowerMode) { - self.drawArm(dc, self.armSecond, clockTime.sec, 60, null); + self.drawArm(dc, self.armSecond, 75, clockTime.sec, 60, null); // --- Complications --- @@ -131,8 +138,8 @@ class KittieCatsView extends WatchUi.WatchFace else if (self.minuteOrnamentLo != null) { var angle = (clockTime.min.toFloat() / 60 * (Math.PI * 2)) - (Math.PI / 2); - var x = Math.cos(angle) * self.theme.MinuteOrnamentOffset + 195; - var y = Math.sin(angle) * self.theme.MinuteOrnamentOffset + 195; + var x = Math.cos(angle) * self.theme.MinuteOrnamentOffset + screenCenterX; + var y = Math.sin(angle) * self.theme.MinuteOrnamentOffset + screenCenterY; dc.drawBitmap(x - (self.minuteOrnamentLo.getWidth() / 2), y, self.minuteOrnamentLo); } @@ -165,7 +172,7 @@ class KittieCatsView extends WatchUi.WatchFace var now = Time.now(); var today = Time.today(); - if (now.greaterThan(today.add(self.sleepTime)) && now.lessThan(today.add(self.wakeTime))) + if (now.greaterThan(today.add(self.sleepTime)) || now.lessThan(today.add(self.wakeTime))) { return false; } @@ -175,17 +182,17 @@ class KittieCatsView extends WatchUi.WatchFace - private function drawArm(dc as Dc, bitmap as BitmapType, value as Lang.Numeric, max as Lang.Numeric, tintColor as Lang.Numeric or Null) as Void + private function drawArm(dc as Dc, bitmap as BitmapType, armOffset as Lang.Numeric, value as Lang.Numeric, max as Lang.Numeric, tintColor as Lang.Numeric or Null) as Void { var offsetX = Math.floor(bitmap.getWidth() / 2); - var offsetY = Math.floor(bitmap.getWidth() / 2); + var offsetY = bitmap.getHeight().toFloat() + armOffset; var rotation = new Graphics.AffineTransform(); rotation.translate(offsetX, offsetY); rotation.rotate(((Math.PI * 2) / max) * value); rotation.translate(-offsetX, -offsetY); - dc.drawBitmap2(0, 0, bitmap, { + dc.drawBitmap2(screenCenterX - offsetX, screenCenterY - offsetY, bitmap, { :tintColor => tintColor, :filterMode => Graphics.FILTER_MODE_BILINEAR, :transform => rotation @@ -194,9 +201,9 @@ class KittieCatsView extends WatchUi.WatchFace private function drawValue(dc as Dc, x as Lang.Numeric, y as Lang.Numeric, font as Graphics.FontType, - text as Lang.Object or Null, nullText as Lang.Object, justification as Graphics.TextJustification or Lang.Number) as Void + value as Lang.Number or Null, nullText as Lang.Object, justification as Graphics.TextJustification or Lang.Number) as Void { - dc.drawText(x, y, font, text == null ? nullText : text, justification); + dc.drawText(x, y, font, value == null ? nullText : value.format("%d"), justification); }