diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.CircularGauge')
| -rw-r--r-- | Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs b/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs index 1d1d598c6..7e8f1fa8c 100644 --- a/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs +++ b/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs @@ -57,6 +57,7 @@ namespace Tango.CircularGauge private Ellipse pointerCap; private Ellipse lightIndicator; private bool isInitialValueSet = false; + private List<Path> _rangeIndicators; private Double arcradius1; private Double arcradius2; private int animatingSpeedFactor = 6; @@ -265,7 +266,7 @@ namespace Tango.CircularGauge /// </summary> public static readonly DependencyProperty OptimalRangeColorProperty = - DependencyProperty.Register("OptimalRangeColor", typeof(Color), typeof(CircularGaugeControl), null); + DependencyProperty.Register("OptimalRangeColor", typeof(Color), typeof(CircularGaugeControl), new PropertyMetadata(Colors.White, (d, e) => (d as CircularGaugeControl).DrawRangeIndicator())); /// <summary> /// Dependency property to Get/Set the Above Optimal Range Color @@ -891,6 +892,12 @@ namespace Tango.CircularGauge #endregion #region Constructor + + public CircularGaugeControl() + { + _rangeIndicators = new List<Path>(); + } + static CircularGaugeControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CircularGaugeControl), new FrameworkPropertyMetadata(typeof(CircularGaugeControl))); @@ -915,6 +922,8 @@ namespace Tango.CircularGauge gauge.OptimalRangeEndValue = gauge.MaxValue; } + (d as CircularGaugeControl).DrawRangeIndicator(); + } private static void OnOptimalRangeStartValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { @@ -925,7 +934,7 @@ namespace Tango.CircularGauge gauge.OptimalRangeStartValue = gauge.MinValue; } - + (d as CircularGaugeControl).DrawRangeIndicator(); } public virtual void OnCurrentValueChanged(DependencyPropertyChangedEventArgs e) @@ -1269,6 +1278,13 @@ namespace Tango.CircularGauge /// </summary> private void DrawRangeIndicator() { + if (rootGrid == null) return; + + foreach (var indicator in _rangeIndicators) + { + rootGrid.Children.Remove(indicator); + } + Double realworldunit = (ScaleSweepAngle / (MaxValue - MinValue)); Double optimalStartAngle; Double optimalEndAngle; @@ -1319,7 +1335,7 @@ namespace Tango.CircularGauge Point D = GetCircumferencePoint(optimalStartAngleFromStart, arcradius1); bool isReflexAngle = Math.Abs(optimalStartAngleFromStart - ScaleStartAngle) > 180.0; - DrawSegment(A, B, C, D, isReflexAngle, BelowOptimalRangeColor); + _rangeIndicators.Add(DrawSegment(A, B, C, D, isReflexAngle, BelowOptimalRangeColor)); // Calculating the Points for the Optimal Range segment from the center of the gauge @@ -1328,7 +1344,7 @@ namespace Tango.CircularGauge Point C1 = GetCircumferencePoint(optimalEndAngleFromStart, arcradius2); Point D1 = GetCircumferencePoint(optimalEndAngleFromStart, arcradius1); bool isReflexAngle1 = Math.Abs(optimalEndAngleFromStart - optimalStartAngleFromStart) > 180.0; - DrawSegment(A1, B1, C1, D1, isReflexAngle1, OptimalRangeColor); + _rangeIndicators.Add(DrawSegment(A1, B1, C1, D1, isReflexAngle1, OptimalRangeColor)); // Calculating the Points for the Above Optimal Range segment from the center of the gauge @@ -1337,12 +1353,12 @@ namespace Tango.CircularGauge Point C2 = GetCircumferencePoint(endAngle, arcradius2); Point D2 = GetCircumferencePoint(endAngle, arcradius1); bool isReflexAngle2 = Math.Abs(endAngle - optimalEndAngleFromStart) > 180.0; - DrawSegment(A2, B2, C2, D2, isReflexAngle2, AboveOptimalRangeColor); + _rangeIndicators.Add(DrawSegment(A2, B2, C2, D2, isReflexAngle2, AboveOptimalRangeColor)); } //Drawing the segment with two arc and two line - private void DrawSegment(Point p1, Point p2, Point p3, Point p4, bool reflexangle, Color clr) + private Path DrawSegment(Point p1, Point p2, Point p3, Point p4, bool reflexangle, Color clr) { // Segment Geometry @@ -1383,8 +1399,6 @@ namespace Tango.CircularGauge else rangestrokecolor = Colors.White; - - rangeIndicator = new Path() { StrokeLineJoin = PenLineJoin.Round, @@ -1410,8 +1424,10 @@ namespace Tango.CircularGauge //Set Z index of range indicator rangeIndicator.SetValue(Canvas.ZIndexProperty, 150); // Adding the segment to the root grid + rootGrid.Children.Add(rangeIndicator); + return rangeIndicator; } #endregion |
