From 8069e80ce120c7532397996eb4c2d2b9cadbd40a Mon Sep 17 00:00:00 2001 From: Gyuri Horak Date: Fri, 27 Oct 2023 20:17:18 +0200 Subject: [PATCH] #4 next nav point on track --- source/RepaFieldStamina.mc | 20 -------------------- source/RepaFieldTrack.mc | 28 ++++++++++++++++++++++++++++ source/RepaFieldView.mc | 18 +++++++++++++++--- 3 files changed, 43 insertions(+), 23 deletions(-) delete mode 100644 source/RepaFieldStamina.mc diff --git a/source/RepaFieldStamina.mc b/source/RepaFieldStamina.mc deleted file mode 100644 index c218689..0000000 --- a/source/RepaFieldStamina.mc +++ /dev/null @@ -1,20 +0,0 @@ -import Toybox.Application; -import Toybox.Graphics; -import Toybox.WatchUi; - -// TODO: stamina not supported yet in the API - -class Stamina extends WatchUi.Drawable { - - function initialize() { - var dictionary = { - :identifier => "Stamina" - }; - - Drawable.initialize(dictionary); - } - - function draw(dc as Dc) as Void { - dc.setColor(0xFF8800, Graphics.COLOR_TRANSPARENT); - } -} diff --git a/source/RepaFieldTrack.mc b/source/RepaFieldTrack.mc index 4618163..3da679b 100644 --- a/source/RepaFieldTrack.mc +++ b/source/RepaFieldTrack.mc @@ -6,6 +6,7 @@ import Toybox.Lang; class Track extends WatchUi.Drawable { hidden var _toDestination as Float; + hidden var _toNextPoint as Float; hidden var _distance as Float; hidden var _offCourse as Float; @@ -17,6 +18,7 @@ class Track extends WatchUi.Drawable { Drawable.initialize(dictionary); _toDestination = 0.0f; + _toNextPoint = 0.0f; _distance = 0.0f; _offCourse = 0.0f; } @@ -25,6 +27,10 @@ class Track extends WatchUi.Drawable { _toDestination = tdst; } + function setToNextPoint(tnp as Float) as Void { + _toNextPoint = tnp; + } + function setDistance(dst as Float) as Void { _distance = dst; } @@ -33,6 +39,13 @@ class Track extends WatchUi.Drawable { _offCourse = off; } + function setTrackData(tdst as Float, tnp as Float, dst as Float, off as Float) as Void { + _toDestination = tdst; + _toNextPoint = tnp; + _distance = dst; + _offCourse = off; + } + function draw(dc as Dc) as Void { if (_toDestination == 0.0f) { return; @@ -78,5 +91,20 @@ class Track extends WatchUi.Drawable { acurrent = aend; } dc.drawArc(w / 2, h / 2, w / 2 - 2, Graphics.ARC_COUNTER_CLOCKWISE, astart, acurrent); + + // next point + if (_toNextPoint > 0.0f) { + var nextPercentage = _toNextPoint / _toDestination; + + var anext = acurrent + (aend - acurrent) * nextPercentage; + if (anext < astart + 1) { + anext = astart + 1; + } else if (anext > aend) { + anext = aend; + } + dc.setPenWidth((dc.getWidth() * 0.01).toNumber()); + dc.setColor(0xFFFF00, Graphics.COLOR_TRANSPARENT); + dc.drawArc(w / 2, h / 2, w / 2 - 2, Graphics.ARC_COUNTER_CLOCKWISE, acurrent, anext); + } } } diff --git a/source/RepaFieldView.mc b/source/RepaFieldView.mc index 0c5cd18..f3406ab 100644 --- a/source/RepaFieldView.mc +++ b/source/RepaFieldView.mc @@ -84,6 +84,8 @@ class RepaFieldView extends WatchUi.DataField { hidden var ahrValue as Numeric; hidden var mhrValue as Numeric; hidden var toDestination as Float; + hidden var toNextPoint as Float; + hidden var nextPointName as String; hidden var distance as Float; hidden var timer as Numeric; hidden var timerState as Number; @@ -123,6 +125,8 @@ class RepaFieldView extends WatchUi.DataField { vsZones = [-16.6, -1.6, 1.6, 5.0, 10.0, 16.6, 25.0]; vsZoneColors = gradeZoneColors; toDestination = 0.0f; + toNextPoint = 0.0f; + nextPointName = ""; distance = 0.0f; timer = 0; timerState = Activity.TIMER_STATE_OFF; @@ -299,6 +303,16 @@ class RepaFieldView extends WatchUi.DataField { } else { toDestination = 0.0f; } + if (info has :distanceToNextPoint && info.distanceToNextPoint != null) { + toNextPoint = info.distanceToNextPoint as Float; + } else { + toNextPoint = 0.0f; + } + if (info has :nameOfNextPoint && info.nameOfNextPoint != null) { + nextPointName = info.nameOfNextPoint as String; + } else { + nextPointName = ""; + } if (info has :offCourseDistance && info.offCourseDistance != null) { offCourse = info.offCourseDistance as Float; } else { @@ -390,9 +404,7 @@ class RepaFieldView extends WatchUi.DataField { // track if (fTrack != null) { - fTrack.setToDestination(toDestination); - fTrack.setDistance(distance); - fTrack.setOffCourse(offCourse); + fTrack.setTrackData(toDestination, toNextPoint, distance, offCourse); } // time