コード例 #1
0
        protected override void ArrangeRanges(Size finalSize)
        {
            try
            {
                double maxRad = RadialScaleHelper.GetRadius(RadialType, finalSize, MinAngle, MaxAngle, SweepDirection);
                Point  center = RadialScaleHelper.GetCenterPosition(RadialType, finalSize, MinAngle, MaxAngle, SweepDirection);

                // Cache the center of the RadialScale
                this.Center = center;

                double x = center.X;
                double y = center.Y;
                // Calculate the ranges' radius
                double rad = maxRad;
                //if (TickPlacement == RadialTickPlacement.Outward)
                //{
                //    rad = maxRad - GetLabels().Max(p => p.DesiredSize.Height) - GetTicks().Max(p => p.DesiredSize.Height) - 1;
                //}
                // Draw the default range
                if (UseDefaultRange)
                {
                    double min = MinAngle, max = MaxAngle;
                    if (SweepDirection == SweepDirection.Counterclockwise)
                    {
                        min = -min;
                        max = -max;
                    }
                    // The null check needs to be done because otherwise the arrange pass will be called
                    // recursevely as I set new content for the path in every call
                    Geometry geom = RadialScaleHelper.CreateArcGeometry(min, max, rad, RangeThickness, SweepDirection);
                    if (def.Data == null || def.Data.Bounds != geom.Bounds)
                    {
                        def.Data = geom;
                    }
                    // Arrange the default range. move the start point of the
                    // figure (0, 0) in the center point (center)
                    def.Arrange(new Rect(center, finalSize));
                }

                // Arrange the rest of the ranges
                double prevAngle = MinAngle;
                if (SweepDirection == SweepDirection.Counterclockwise)
                {
                    prevAngle = -prevAngle;
                }

                for (int i = 0; i < ranges.Count; i++)
                {
                    Path       range     = ranges[i];
                    GaugeRange rng       = Ranges[i];
                    double     nextAngle = GetAngleFromValue(rng.Offset);
                    if (SweepDirection == SweepDirection.Counterclockwise)
                    {
                        nextAngle = -nextAngle;
                    }

                    range.Fill = new SolidColorBrush(rng.Color);
                    Geometry geom = RadialScaleHelper.CreateArcGeometry(prevAngle, nextAngle, rad, RangeThickness, SweepDirection);
                    // Check to avoid infinite loop
                    if (range.Data == null || range.Data.Bounds != geom.Bounds)
                    {
                        range.Data = geom;
                    }
                    // Arrange the default range. move the start point of the
                    // figure (0, 0) in the center point (center)
                    range.Arrange(new Rect(center, finalSize));
                    prevAngle = nextAngle;
                }
            }
            catch { /* In the designer this throws an argument exception. I don't know why. */ }
        }
コード例 #2
0
 internal Point GetIndicatorOffset()
 {
     return(RadialScaleHelper.GetCenterPosition(RadialType, this.DesiredSize /*new Size(ActualWidth, ActualHeight)*/, MinAngle, MaxAngle, SweepDirection));
 }