Beispiel #1
0
        protected override Size ArrangeOverride(Size arrangeSize)
        {
            var arc = Arc.Fill(arrangeSize, 0, 360);
            arc = new Arc(arc.Centre, 0, 360, 0, false);
            foreach (UIElement child in this.InternalChildren)
            {
                if (child == null)
                {
                    continue;
                }
                double r = GetRadius(child);
                double a = GetAngle(child);

                if (double.IsNaN(r) || double.IsNaN(a))
                {
                    child.Arrange(new Rect());
                }
                else
                {
                    var p = arc.GetPoint(a, r);
                    var mp = child.DesiredSize.MidPoint();
                    var v = new Vector(mp.X, mp.Y);
                    var cp = p - v;
                    child.Arrange(new Rect(cp, child.DesiredSize));
                }
            }
            return arrangeSize;
        }
        protected override Size MeasureOverride(Size availableSize)
        {
            var bounds = new Rect();
            var midPoint = new Point(0, 0);
            var arc = new Arc(midPoint, this.MinAngle, this.MaxAngle, this.ReservedSpace, this.IsDirectionReversed);
            for (int i = 0; i < this.AllTicks.Count; i++)
            {
                var tick = this.AllTicks[i];
                var text = this.AllTexts[i];
                var angle = TickHelper.ToAngle(tick, this.Minimum, this.Maximum, arc);
                var point = arc.GetPoint(angle);
                var textPosition = new TextPosition(text, new TextPositionOptions(this.TextOrientation, angle), point, angle);
                bounds.Union(textPosition.TransformedBounds);
            }
            var points = new[] { bounds.TopLeft, bounds.TopRight, bounds.BottomRight, bounds.BottomLeft };

            this.TextSpace = 2 * points.Max(p => (p - midPoint).Length);
            return bounds.Size;
        }
        private static PathGeometry ArcBlock(Arc arc, double fromAngle, double toAngle, double tickLength)
        {
            PathGeometry geometry = new PathGeometry();
            PathFigure figure = new PathFigure();

            geometry.Figures.Add(figure);
            var op1 = arc.GetPoint(fromAngle);
            var ip1 = arc.GetPoint(fromAngle, -1 * tickLength);
            var op2 = arc.GetPoint(toAngle);
            var ip2 = arc.GetPoint(toAngle, -1 * tickLength);

            figure.StartPoint = op1;
            var rotationAngle = toAngle - fromAngle;
            var isLargeArc = arc.IsLargeAngle(fromAngle, toAngle);
            var sweepDirection = arc.SweepDirection(fromAngle, toAngle);
            figure.Segments.Add(new ArcSegment(op2, new Size(arc.Radius, arc.Radius), rotationAngle, isLargeArc, sweepDirection, true));
            figure.Segments.Add(new LineSegment(ip2, true));
            sweepDirection = arc.SweepDirection(toAngle, fromAngle);
            var ri = arc.Radius - tickLength;
            if (ri < 0)
            {
                ri = 0;
            }
            figure.Segments.Add(new ArcSegment(ip1, new Size(ri, ri), rotationAngle, isLargeArc, sweepDirection, true));
            figure.Segments.Add(new LineSegment(op1, true));
            figure.IsClosed = true;
            figure.Freeze();
            geometry.Freeze();
            return geometry;
        }
 protected override Size MeasureOverride(Size availableSize)
 {
     var rect = new Rect();
     var arc = new Arc(new Point(0, 0), this.MinAngle, this.MaxAngle, this.ReservedSpace / 2 + this.TickLength, this.IsDirectionReversed);
     rect.Union(arc.GetPoint(arc.Start));
     var a = TickHelper.ToAngle(this.Value, this.Minimum, this.Maximum, arc);
     rect.Union(arc.GetPoint(a));
     foreach (var p in arc.GetQuadrants(arc.Start, a))
     {
         rect.Union(p);
     }
     return rect.Size;
 }
Beispiel #5
0
 internal static double ToAngle(double tick, double minimum, double maximum, Arc arc)
 {
     var dv = (tick - minimum) / (maximum - minimum);
     var a = dv * (arc.End - arc.Start) + arc.Start;
     return a;
 }
Beispiel #6
0
        internal static Arc Fill(Size availableSize, double start, double end)
        {
            if (availableSize.Width == 0 ||
                double.IsNaN(availableSize.Width) ||
                availableSize.Height == 0 ||
                double.IsNaN(availableSize.Height))
            {
                return new Arc(new Point(0, 0), start, end, 0, false);
            }

            var p0 = new Point(0, 0);
            var arc = new Arc(p0, start, end, 1, false);
            var rect = new Rect();
            var ps = arc.GetPoint(start);
            rect.Union(ps);
            rect.Union(arc.GetPoint(end));
            foreach (var quadrant in arc.GetQuadrants(start, end))
            {
                rect.Union(quadrant);
            }
            var wf = availableSize.Width / rect.Width;
            var hf = availableSize.Height / rect.Height;
            var r = Math.Min(wf, hf);
            rect.Scale(r, r);
            var v = rect.FindTranslationToCenter(availableSize);
            return new Arc(p0 + v, start, end, r, false);
        }