aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Touch/Controls/TouchArcProgress.cs
blob: 510fd500d269efc00b57f767d51f37ea1eb0f586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Tango.Touch.Controls
{
    public class TouchArcProgress : ProgressBar
    {
        private SharedUI.Shapes.Arc _arc;
        private SharedUI.Shapes.Arc _arc_base;

        public double RingThickness
        {
            get { return (double)GetValue(RingThicknessProperty); }
            set { SetValue(RingThicknessProperty, value); }
        }
        public static readonly DependencyProperty RingThicknessProperty =
            DependencyProperty.Register("RingThickness", typeof(double), typeof(TouchArcProgress), new PropertyMetadata(3.0));



        public int MinArcAngle
        {
            get { return (int)GetValue(MinArcAngleProperty); }
            set { SetValue(MinArcAngleProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MinArcAngle.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MinArcAngleProperty =
            DependencyProperty.Register("MinArcAngle", typeof(int), typeof(TouchArcProgress), new PropertyMetadata(40));



        public int MaxArcAngle
        {
            get { return (int)GetValue(MaxArcAngleProperty); }
            set { SetValue(MaxArcAngleProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MaxArcAngle.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MaxArcAngleProperty =
            DependencyProperty.Register("MaxArcAngle", typeof(int), typeof(TouchArcProgress), new PropertyMetadata(320));



        static TouchArcProgress()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchArcProgress), new FrameworkPropertyMetadata(typeof(TouchArcProgress)));
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _arc = GetTemplateChild("PART_ArcValue") as SharedUI.Shapes.Arc;
            _arc_base = GetTemplateChild("PART_ArcBase") as SharedUI.Shapes.Arc;
            SetArcBase();
            SetArc();
        }

        protected override void OnValueChanged(double oldValue, double newValue)
        {
            base.OnValueChanged(oldValue, newValue);
            SetArc();
        }

        protected override void OnMinimumChanged(double oldMinimum, double newMinimum)
        {
            base.OnMinimumChanged(oldMinimum, newMinimum);
            SetArcBase();
            SetArc();
        }

        protected override void OnMaximumChanged(double oldMaximum, double newMaximum)
        {
            base.OnMaximumChanged(oldMaximum, newMaximum);
            SetArcBase();
            SetArc();
        }

        private void SetArcBase()
        {
            if (_arc_base != null)
            {
                _arc_base.StartAngle = ((MaxArcAngle - MinArcAngle) * (Minimum / (Maximum - Minimum))) + MinArcAngle;
                _arc_base.EndAngle = ((MaxArcAngle - MinArcAngle) * (Maximum / (Maximum - Minimum))) + MinArcAngle;
            }
        }

        private void SetArc()
        {
            if (_arc != null)
            {
                _arc.StartAngle = ((MaxArcAngle - MinArcAngle) * (Minimum / (Maximum - Minimum))) + MinArcAngle;
                _arc.EndAngle = ((MaxArcAngle - MinArcAngle) * (Value / (Maximum - Minimum))) + MinArcAngle;
            }
        }
    }
}