Example #1
0
        protected override void OnValueChanged(double newVal, double oldVal)
        {
            RadialScale scale = Owner as RadialScale;

            if (scale != null)
            {
                SetIndicatorGeometry(scale, Value);
            }
        }
Example #2
0
        //private static void TickPlacementPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        //{
        //    RadialScale scale = o as RadialScale;
        //    if (scale != null)
        //    {
        //        scale.RefreshLayout();
        //    }
        //}

        private static void RadialTypePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            RadialScale scale = o as RadialScale;

            if (scale != null)
            {
                scale.RefreshLayout();
            }
        }
Example #3
0
        protected override void UpdateIndicatorOverride(Scale owner)
        {
            base.UpdateIndicatorOverride(owner);
            RadialScale scale = Owner as RadialScale;

            if (scale != null)
            {
                SetIndicatorGeometry(scale, Value);
            }
        }
Example #4
0
        protected override void OnBarThicknesChanged(int newVal, int oldVal)
        {
            base.OnBarThicknesChanged(newVal, oldVal);
            RadialScale scale = Owner as RadialScale;

            if (scale != null)
            {
                SetIndicatorGeometry(scale, Value);
            }
        }
Example #5
0
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            TranslateTransform tt    = new TranslateTransform();
            RadialScale        scale = Owner as RadialScale;

            if (scale != null)
            {
                // Calculate the geometry again. The first time this was done the owner had a size of (0,0)
                // and so did the indicator. Once the owner has the correct size (MeasureOverride has been called)
                // we should re-calculate the shape of the indicator
                SetIndicatorGeometry(scale, Value);
                Point center = scale.GetIndicatorOffset();
                tt.X            = center.X;
                tt.Y            = center.Y;
                RenderTransform = tt;
            }
            return(base.ArrangeOverride(arrangeBounds));
        }
Example #6
0
        void marker_ManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e)
        {
            if (Owner is RadialScale)
            {
                RadialScale rs = (RadialScale)Owner;
                //Debug.WriteLine("radial angle: " + rs.GetAngleFromValue(Value));
                GetAngle(this.Center, rs.Center);
                // this.Angle = GetAngle(e.Position, this.RenderSize);
                double radius            = rs.GetIndicatorRadius();
                double diameter          = radius * 2;
                Size   rsSize            = new Size(diameter, radius);
                Point  radialScaleAbsPos = (((UIElement)rs).TransformToVisual((Frame)Window.Current.Content) as GeneralTransform).TransformPoint(new Point(0, 0));
                //Debug.WriteLine("position: " + e.Position + " size: " + rsSize + " center: " + RadialScaleHelper.GetCenterPosition(rs.RadialType, rsSize, rs.MinAngle, rs.MaxAngle, rs.SweepDirection) + " angle: " + GetAngle(e.Position, new Size(diameter, diameter)));

                //Debug.WriteLine("angle: " + GetAngle(this.Center, rs.Center));
                //Debug.WriteLine("Final Val: " + rs.GetValueFromAngle(GetAngle(this.Center.Add(e.Cumulative.Translation), rs.Center)));
                Value = rs.GetValueFromAngle(GetAngle(this.Center.Add(e.Position), rs.Center));
            }
        }
Example #7
0
 // Sets the indicator geometry based on the scale and the current value
 private void SetIndicatorGeometry(RadialScale scale, double value)
 {
     if (thePath != null)
     {
         double min = scale.MinAngle;
         double max = scale.GetAngleFromValue(Value);
         if (scale.SweepDirection == SweepDirection.Counterclockwise)
         {
             min = -min;
             max = -max;
         }
         double rad = scale.GetIndicatorRadius();
         if (rad > BarThickness)
         {
             Geometry geom = RadialScaleHelper.CreateArcGeometry(min, max, rad, BarThickness, scale.SweepDirection);
             // Stop the recursive loop. Only set a new geometry if it is different from the current one
             if (thePath.Data == null || thePath.Data.Bounds != geom.Bounds)
             {
                 thePath.Data = geom;
             }
         }
     }
 }
Example #8
0
        protected override Size MeasureOverride(Size availableSize)
        {
            // Call the base version to set the parent
            base.MeasureOverride(availableSize);
            // Return all the available size
            double width = 0, height = 0;

            if (!double.IsInfinity(availableSize.Width))
            {
                width = availableSize.Width;
            }
            if (!double.IsInfinity(availableSize.Height))
            {
                height = availableSize.Height;
            }
            RadialScale scale = Owner as RadialScale;

            if (scale != null)
            {
                // Every time a resize happens the indicator needs to be redrawn
                SetIndicatorGeometry(scale, Value);
            }
            return(new Size(width, height));
        }
Example #9
0
        private void PositionMarker()
        {
            if (Owner == null)
            {
                return;
            }
            if (Owner is RadialScale)
            {
                RadialScale rs = (RadialScale)Owner;
                // Get the angle based on the value
                double angle = rs.GetAngleFromValue(Value);
                if (rs.SweepDirection == SweepDirection.Counterclockwise)
                {
                    angle = -angle;
                }
                // Rotate the marker by angle
                TransformGroup tg = RenderTransform as TransformGroup;
                if (tg != null)
                {
                    RotateTransform rt = tg.Children[0] as RotateTransform;
                    if (rt != null)
                    {
                        rt.Angle = angle;
                    }
                }
                // Position the marker based on the radius
                Point  offset = rs.GetIndicatorOffset();
                double rad    = rs.GetIndicatorRadius();

                //position the marker
                double px = offset.X + (rad - DesiredSize.Height / 2) * Math.Sin(angle * Math.PI / 180);
                double py = offset.Y - (rad - DesiredSize.Height / 2) * Math.Cos(angle * Math.PI / 180);

                // Cache the intended position of the Indicator before it's centered
                this.Center = new Point(px, py);

                // Subtract the width of the Indicator's size so that it looks centered
                px -= DesiredSize.Width / 2;
                py -= DesiredSize.Height / 2;
                if (tg != null)
                {
                    TranslateTransform tt = tg.Children[1] as TranslateTransform;
                    if (tt != null)
                    {
                        tt.X = px;
                        tt.Y = py;
                    }
                }
            }
            //else
            //{
            //    LinearScale ls = Owner as LinearScale;
            //    Point offset = ls.GetIndicatorOffset(this);
            //    //the getIndicatorOffset returns only one correct dimension
            //    //for marker indicators the other dimension will have to be calculated again
            //    if (ls.Orientation == Orientation.Horizontal)
            //    {
            //        offset.X = ls.ActualWidth * (Value - ls.Minimum) / (ls.Maximum - ls.Minimum) - DesiredSize.Width / 2;
            //    }
            //    else
            //    {
            //        offset.Y = ls.ActualHeight - ls.ActualHeight * (Value - ls.Minimum) / (ls.Maximum - ls.Minimum) - DesiredSize.Height / 2;
            //    }
            //    TransformGroup tg = RenderTransform as TransformGroup;
            //    if (tg != null)
            //    {
            //        TranslateTransform tt = tg.Children[1] as TranslateTransform;
            //        if (tt != null)
            //        {
            //            tt.X = offset.X;
            //            tt.Y = offset.Y;
            //        }
            //    }
            //}
        }
Example #10
0
 // Sets the indicator geometry based on the scale and the current value
 private void SetIndicatorGeometry(RadialScale scale, double value)
 {
     if (thePath != null)
     {
         double min = scale.MinAngle;
         double max = scale.GetAngleFromValue(Value);
         if (scale.SweepDirection == SweepDirection.Counterclockwise)
         {
             min = -min;
             max = -max;
         }
         double rad = scale.GetIndicatorRadius();
         if (rad > BarThickness)
         {
             Geometry geom = RadialScaleHelper.CreateArcGeometry(min, max, rad, BarThickness, scale.SweepDirection);
             // Stop the recursive loop. Only set a new geometry if it is different from the current one
             if (thePath.Data == null || thePath.Data.Bounds != geom.Bounds)
             {
                 thePath.Data = geom;
             }
         }
     }
 }