コード例 #1
0
        private static void OnFaceChanged(DependencyObject d)
        {
            AnimatedRadialGauge radialGauge = (AnimatedRadialGauge)d;

            var container = radialGauge.GetTemplateChild(ContainerPartName) as Grid;

            if (container == null || DesignTimeHelpers.IsRunningInLegacyDesignerMode)
            {
                // Bad template.
                return;
            }

            radialGauge._root = container.GetVisual();
            radialGauge._root.Children.RemoveAll();
            radialGauge._compositor = radialGauge._root.Compositor;

            if (radialGauge.TickSpacing > 0)
            {
                // Ticks.
                SpriteVisual tick;
                for (double i = radialGauge.Minimum; i <= radialGauge.Maximum; i += radialGauge.TickSpacing)
                {
                    tick                        = radialGauge._compositor.CreateSpriteVisual();
                    tick.Size                   = new Vector2((float)radialGauge.TickWidth, (float)radialGauge.TickLength);
                    tick.Brush                  = radialGauge._compositor.CreateColorBrush(radialGauge.TickBrush.Color);
                    tick.Offset                 = new Vector3(100 - ((float)radialGauge.TickWidth / 2), 0.0f, 0);
                    tick.CenterPoint            = new Vector3((float)radialGauge.TickWidth / 2, 100.0f, 0);
                    tick.RotationAngleInDegrees = (float)radialGauge.ValueToAngle(i);
                    radialGauge._root.Children.InsertAtTop(tick);
                }

                // Scale Ticks.
                for (double i = radialGauge.Minimum; i <= radialGauge.Maximum; i += radialGauge.TickSpacing)
                {
                    tick                        = radialGauge._compositor.CreateSpriteVisual();
                    tick.Size                   = new Vector2((float)radialGauge.ScaleTickWidth, (float)radialGauge.ScaleWidth);
                    tick.Brush                  = radialGauge._compositor.CreateColorBrush(radialGauge.ScaleTickBrush.Color);
                    tick.Offset                 = new Vector3(100 - ((float)radialGauge.ScaleTickWidth / 2), (float)radialGauge.ScalePadding, 0);
                    tick.CenterPoint            = new Vector3((float)radialGauge.ScaleTickWidth / 2, 100 - (float)radialGauge.ScalePadding, 0);
                    tick.RotationAngleInDegrees = (float)radialGauge.ValueToAngle(i);
                    radialGauge._root.Children.InsertAtTop(tick);
                }
            }

            // Needle.
            radialGauge._needle             = radialGauge._compositor.CreateSpriteVisual();
            radialGauge._needle.Size        = new Vector2((float)radialGauge.NeedleWidth, (float)(radialGauge.NeedleLength - radialGauge.NeedlePadding));
            radialGauge._needle.Brush       = radialGauge._compositor.CreateColorBrush(radialGauge.NeedleBrush.Color);
            radialGauge._needle.CenterPoint = new Vector3((float)radialGauge.NeedleWidth / 2, (float)radialGauge.NeedleLength, 0);
            radialGauge._needle.Offset      = new Vector3(100 - ((float)radialGauge.NeedleWidth / 2), 100 - (float)radialGauge.NeedleLength, 0);
            radialGauge._root.Children.InsertAtTop(radialGauge._needle);

            OnValueChanged(radialGauge);
        }
コード例 #2
0
        private static void OnInteractivityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AnimatedRadialGauge radialGauge = (AnimatedRadialGauge)d;

            if (radialGauge.IsInteractive)
            {
                radialGauge.Tapped            += radialGauge.RadialGauge_Tapped;
                radialGauge.ManipulationDelta += radialGauge.RadialGauge_ManipulationDelta;
                radialGauge.ManipulationMode   = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
            }
            else
            {
                radialGauge.Tapped            -= radialGauge.RadialGauge_Tapped;
                radialGauge.ManipulationDelta -= radialGauge.RadialGauge_ManipulationDelta;
                radialGauge.ManipulationMode   = ManipulationModes.None;
            }
        }
コード例 #3
0
        private static void OnScaleChanged(DependencyObject d)
        {
            AnimatedRadialGauge radialGauge = (AnimatedRadialGauge)d;

            radialGauge.UpdateNormalizedAngles();

            var scale = radialGauge.GetTemplateChild(ScalePartName) as Path;

            if (scale != null)
            {
                if (radialGauge.NormalizedMaxAngle - radialGauge.NormalizedMinAngle == 360)
                {
                    // Draw full circle.
                    var eg = new EllipseGeometry();
                    eg.Center  = new Windows.Foundation.Point(100, 100);
                    eg.RadiusX = 100 - radialGauge.ScalePadding - (radialGauge.ScaleWidth / 2);
                    eg.RadiusY = eg.RadiusX;
                    scale.Data = eg;
                }
                else
                {
                    // Draw arc.
                    var pg = new PathGeometry();
                    var pf = new PathFigure();
                    pf.IsClosed = false;
                    var middleOfScale = 100 - radialGauge.ScalePadding - (radialGauge.ScaleWidth / 2);
                    pf.StartPoint = radialGauge.ScalePoint(radialGauge.NormalizedMinAngle, middleOfScale);
                    var seg = new ArcSegment();
                    seg.SweepDirection = SweepDirection.Clockwise;
                    seg.IsLargeArc     = radialGauge.NormalizedMaxAngle > (radialGauge.NormalizedMinAngle + 180);
                    seg.Size           = new Size(middleOfScale, middleOfScale);
                    seg.Point          = radialGauge.ScalePoint(radialGauge.NormalizedMaxAngle, middleOfScale);
                    pf.Segments.Add(seg);
                    pg.Figures.Add(pf);
                    scale.Data = pg;
                }

                if (!DesignTimeHelpers.IsRunningInLegacyDesignerMode)
                {
                    OnFaceChanged(radialGauge);
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RadialGaugeAutomationPeer"/> class.
 /// </summary>
 /// <param name="owner">The owner element to create for.</param>
 public RadialGaugeAutomationPeer(AnimatedRadialGauge owner)
     : base(owner)
 {
 }
コード例 #5
0
        private static void OnValueChanged(DependencyObject d)
        {
            AnimatedRadialGauge radialGauge = (AnimatedRadialGauge)d;

            if (!double.IsNaN(radialGauge.Value))
            {
                if (radialGauge.StepSize != 0)
                {
                    radialGauge.Value = radialGauge.RoundToMultiple(radialGauge.Value, radialGauge.StepSize);
                }

                var middleOfScale = 100 - radialGauge.ScalePadding - (radialGauge.ScaleWidth / 2);
                var valueText     = radialGauge.GetTemplateChild(ValueTextPartName) as TextBlock;
                radialGauge.ValueAngle = radialGauge.ValueToAngle(radialGauge.Value);

                // Needle
                if (radialGauge._needle != null)
                {
                    radialGauge._needle.RotationAngleInDegrees = (float)radialGauge.ValueAngle;
                }

                // Trail
                var trail = radialGauge.GetTemplateChild(TrailPartName) as Path;
                if (trail != null)
                {
                    if (radialGauge.ValueAngle > radialGauge.NormalizedMinAngle)
                    {
                        trail.Visibility = Visibility.Visible;

                        if (radialGauge.ValueAngle - radialGauge.NormalizedMinAngle == 360)
                        {
                            // Draw full circle.
                            var eg = new EllipseGeometry();
                            eg.Center  = new Windows.Foundation.Point(100, 100);
                            eg.RadiusX = 100 - radialGauge.ScalePadding - (radialGauge.ScaleWidth / 2);
                            eg.RadiusY = eg.RadiusX;
                            trail.Data = eg;
                        }
                        else
                        {
                            // Draw arc.
                            var pg = new PathGeometry();
                            var pf = new PathFigure();
                            pf.IsClosed   = false;
                            pf.StartPoint = radialGauge.ScalePoint(radialGauge.NormalizedMinAngle, middleOfScale);
                            var seg = new ArcSegment();
                            seg.SweepDirection = SweepDirection.Clockwise;
                            seg.IsLargeArc     = radialGauge.ValueAngle > (180 + radialGauge.NormalizedMinAngle);
                            seg.Size           = new Size(middleOfScale, middleOfScale);
                            seg.Point          = radialGauge.ScalePoint(Math.Min(radialGauge.ValueAngle, radialGauge.NormalizedMaxAngle), middleOfScale); // On overflow, stop trail at MaxAngle.
                            pf.Segments.Add(seg);
                            pg.Figures.Add(pf);
                            trail.Data = pg;
                        }
                    }
                    else
                    {
                        trail.Visibility = Visibility.Collapsed;
                    }
                }

                // Value Text
                if (valueText != null)
                {
                    valueText.Text = radialGauge.Value.ToString(radialGauge.ValueStringFormat);
                }
            }
        }