private void RenderArc(double Angle, Path pathRoot, PathFigure pathFigure, ArcSegment arcSegment) { Point startPoint = new Point(Radius, 0); Point endPoint = ComputeCartesianCoordinate(Angle, Radius); endPoint.X += Radius; endPoint.Y += Radius; pathRoot.Width = Radius * 2 + StrokeThickness; pathRoot.Height = Radius * 2 + StrokeThickness; pathRoot.Margin = new Thickness(StrokeThickness, StrokeThickness, 0, 0); bool largeArc = Angle > 180.0; Size outerArcSize = new Size(Radius, Radius); pathFigure.StartPoint = startPoint; if (startPoint.X == Math.Round(endPoint.X) && startPoint.Y == Math.Round(endPoint.Y)) { endPoint.X -= 0.01; } arcSegment.Point = endPoint; arcSegment.Size = outerArcSize; arcSegment.IsLargeArc = largeArc; }
public Path GetCircleSegment(Point centrePoint, Point currentPoint, double radius, double stripWidth, double angle) { var path = new Path { Stroke = _strokeBrush }; var pathGeometry = new PathGeometry(); var circleStart = new Point(centrePoint.X, centrePoint.Y - radius); // Arc var arcSegment = new ArcSegment { IsLargeArc = angle > 180.0, Point = _mathHelper.ScaleUnitCirclePoint(centrePoint, angle, radius), Size = new Size(radius, radius), SweepDirection = SweepDirection.Clockwise }; //The path figure includes first, the first line from the centre to line1End, then the arc var pathFigure = new PathFigure { StartPoint = circleStart, IsClosed = false }; pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); path.Data = pathGeometry; path.StrokeThickness = stripWidth; return path; }
public static Path GetCircleSegment(Point centerPoint, double radius, double angle) { var path = new Path(); var pathGeometry = new PathGeometry(); var circleStart = new Point(centerPoint.X, centerPoint.Y - radius); var arcSegment = new ArcSegment { IsLargeArc = angle > 180.0, Point = ScaleUnitCirclePoint(centerPoint, angle, radius), Size = new Size(radius, radius), SweepDirection = SweepDirection.Clockwise }; var pathFigure = new PathFigure { StartPoint = circleStart, IsClosed = false }; pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); path.Data = pathGeometry; return path; }
/// <summary> /// Override for the path's redraw mehtod, controlling how the path is drawns /// </summary> protected override void Redraw() { Debug.Assert(GetValue(StartAngleProperty) != DependencyProperty.UnsetValue); Debug.Assert(GetValue(RadiusProperty) != DependencyProperty.UnsetValue); Debug.Assert(GetValue(AngleProperty) != DependencyProperty.UnsetValue); if (Radius == 0 || !(Thickness > 0)) return; Width = Height = 2 * (Radius); var endAngle = StartAngle + Angle; var smallRadius = Radius - Thickness; var startX = Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius; var startY = Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius; // path container var figure = new PathFigure { StartPoint = new Point(startX, startY), IsClosed = true, IsFilled = true }; // outer arc var outerArcX = Radius + Math.Sin(endAngle * Math.PI / 180) * Radius; var outerArcY = Radius - Math.Cos(endAngle * Math.PI / 180) * Radius; var outerArc = new ArcSegment { IsLargeArc = Angle >= 180.0, Point = new Point(outerArcX, outerArcY), Size = new Size(Radius, Radius), SweepDirection = SweepDirection.Clockwise, }; figure.Segments.Add(outerArc); // start angle line var lineX = smallRadius + Math.Sin(endAngle * Math.PI / 180) * smallRadius; var lineY = smallRadius - Math.Cos(endAngle * Math.PI / 180) * smallRadius; var line = new LineSegment { Point = new Point(lineX + Thickness, lineY + Thickness) }; figure.Segments.Add(line); // inner arc var innerArcX = smallRadius + Math.Sin(StartAngle * Math.PI / 180) * smallRadius ; var innerArcY = smallRadius - Math.Cos(StartAngle * Math.PI / 180) * smallRadius; var innerArc = new ArcSegment { IsLargeArc = Angle >= 180.0, Point = new Point(innerArcX + Thickness, innerArcY + Thickness), Size = new Size(smallRadius, smallRadius), SweepDirection = SweepDirection.Counterclockwise, }; figure.Segments.Add(innerArc); Data = new PathGeometry { Figures = { figure } }; InvalidateArrange(); }
public PieSlice() { pathFigure = new PathFigure { IsClosed = false ,IsFilled = false}; arcSegment = new ArcSegment { SweepDirection = SweepDirection.Clockwise }; pathFigure.Segments.Add(arcSegment); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); this.Data = pathGeometry; UpdateValues(); }
public PiePath() { pathFigure = new PathFigure { IsClosed = true }; lineSegment = new LineSegment(); arcSegment = new ArcSegment { SweepDirection = SweepDirection.Clockwise }; pathFigure.Segments.Add(lineSegment); pathFigure.Segments.Add(arcSegment); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); this.Data = pathGeometry; UpdateValues(); }
public void UpdatePath() { // ensure variables if (GetValue(StartAngleProperty) == DependencyProperty.UnsetValue) throw new ArgumentNullException("Start Angle is required"); if (GetValue(RadiusProperty) == DependencyProperty.UnsetValue) throw new ArgumentNullException("Radius is required"); if (GetValue(AngleProperty) == DependencyProperty.UnsetValue) throw new ArgumentNullException("Angle is required"); Width = Height = 2 * (Radius + StrokeThickness); var endAngle = StartAngle + Angle; // path container var figureP = new Point(Radius, Radius); var figure = new PathFigure { StartPoint = figureP, IsClosed = true, }; // start angle line var lineX = Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius; var lineY = Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius; var lineP = new Point(lineX, lineY); var line = new LineSegment { Point = lineP }; figure.Segments.Add(line); // outer arc var arcX = Radius + Math.Sin(endAngle * Math.PI / 180) * Radius; var arcY = Radius - Math.Cos(endAngle * Math.PI / 180) * Radius; var arcS = new Size(Radius, Radius); var arcP = new Point(arcX, arcY); var arc = new ArcSegment { IsLargeArc = Angle >= 180.0, Point = arcP, Size = arcS, SweepDirection = SweepDirection.Clockwise, }; figure.Segments.Add(arc); // finalé Data = new PathGeometry { Figures = { figure } }; InvalidateArrange(); }
/// <summary> /// Override for the path's redraw mehtod, controlling how the path is drawns /// </summary> protected override void Redraw() { Debug.Assert(GetValue(StartAngleProperty) != DependencyProperty.UnsetValue); Debug.Assert(GetValue(RadiusProperty) != DependencyProperty.UnsetValue); Debug.Assert(GetValue(AngleProperty) != DependencyProperty.UnsetValue); Width = Height = 2 * (Radius); var endAngle = StartAngle + Angle; // path container var figure = new PathFigure { StartPoint = new Point(Radius, Radius), IsClosed = true, IsFilled = true }; // start angle line var lineX = Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius; var lineY = Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius; var line = new LineSegment { Point = new Point(lineX, lineY) }; figure.Segments.Add(line); // outer arc var arcX = Radius + Math.Sin(endAngle * Math.PI / 180) * Radius; var arcY = Radius - Math.Cos(endAngle * Math.PI / 180) * Radius; var arc = new ArcSegment { IsLargeArc = Angle >= 180.0, Point = new Point(arcX, arcY), Size = new Size(Radius, Radius), SweepDirection = SweepDirection.Clockwise, }; figure.Segments.Add(arc); Data = new PathGeometry { Figures = { figure } }; InvalidateArrange(); }
public static Geometry CreateArcGeometry(double minAngle, double maxAngle, double radius, int thickness, SweepDirection sweepDirection) { //the range will have 4 segments (arc, line, arc, line) //if the sweep angle is bigger than 180 use the large arc //first use the same sweep direction as the control. invert for the second arc. PathFigure figure = new PathFigure(); figure.IsClosed = true; figure.StartPoint = new Point((radius - thickness) * Math.Sin(minAngle * Math.PI / 180), -(radius - thickness) * Math.Cos(minAngle * Math.PI / 180)); //first arc segment ArcSegment arc = new ArcSegment(); arc.Point = new Point((radius - thickness) * Math.Sin(maxAngle * Math.PI / 180), -(radius - thickness) * Math.Cos(maxAngle * Math.PI / 180)); arc.Size = new Size(radius - thickness, radius - thickness); arc.SweepDirection = sweepDirection; if (Math.Abs(maxAngle - minAngle) > 180) arc.IsLargeArc = true; figure.Segments.Add(arc); //first line segment LineSegment line = new LineSegment(); line.Point = new Point(radius * Math.Sin(maxAngle * Math.PI / 180), -radius * Math.Cos(maxAngle * Math.PI / 180)); figure.Segments.Add(line); //second arc segment arc = new ArcSegment(); arc.Point = new Point(radius * Math.Sin(minAngle * Math.PI / 180), -radius * Math.Cos(minAngle * Math.PI / 180)); arc.Size = new Size(radius, radius); arc.SweepDirection = SweepDirection.Counterclockwise; if (sweepDirection == SweepDirection.Counterclockwise) arc.SweepDirection = SweepDirection.Clockwise; if (Math.Abs(maxAngle - minAngle) > 180) arc.IsLargeArc = true; figure.Segments.Add(arc); PathGeometry path = new PathGeometry(); path.Figures.Add(figure); return path; }
/// <summary> /// Initializes a new instance of the <see cref="Arc"/> class" /// </summary> public Arc() { this.Stroke = new SolidColorBrush(Colors.White); this.StrokeThickness = 2; this.Fill = new SolidColorBrush(Colors.Red); this.UseLayoutRounding = true; this.pathGeometry = new PathGeometry(); this.pathFigure = new PathFigure(); this.pathFigure.IsClosed = true; this.pathFigure.IsFilled = true; this.arcSegment = new ArcSegment(); this.arcSegment.IsLargeArc = false; this.arcSegment.SweepDirection = SweepDirection.Clockwise; this.lineSegment = new LineSegment(); this.pathFigure.Segments.Add(this.arcSegment); this.pathFigure.Segments.Add(this.lineSegment); this.pathGeometry.Figures.Add(this.pathFigure); this.Data = this.pathGeometry; this.ellipseGeometry = new EllipseGeometry(); this.Tapped += this.OnArcTapped; }
private PathGeometry DrawGeometry() { bool largeArc = WedgeAngle > 180.0; Size outerArcSize = new Size(Radius, Radius); Size innerArcSize = new Size(InnerRadius, InnerRadius); Point innerArcStartPoint = Utilities.ComputeCartesianCoordinate(RotationAngle, InnerRadius); Point ButtomLineEndPoint = Utilities.ComputeCartesianCoordinate(RotationAngle, Radius); Point OuterArcEndPoint = Utilities.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius); Point EndLineEndPoint = Utilities.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius); innerArcStartPoint.X += CentreX; innerArcStartPoint.Y += CentreY; ButtomLineEndPoint.X += CentreX; ButtomLineEndPoint.Y += CentreY; OuterArcEndPoint.X += CentreX; OuterArcEndPoint.Y += CentreY; EndLineEndPoint.X += CentreX; EndLineEndPoint.Y += CentreY; PathFigure path = new PathFigure(); path.StartPoint = innerArcStartPoint; ArcSegment InnerArc = new ArcSegment(); InnerArc.Size = innerArcSize; InnerArc.SweepDirection = SweepDirection.Counterclockwise; InnerArc.Point = innerArcStartPoint; InnerArc.IsLargeArc = largeArc; LineSegment ButtomLine = new LineSegment(); ButtomLine.Point = ButtomLineEndPoint; ArcSegment OuterArc = new ArcSegment(); OuterArc.SweepDirection = SweepDirection.Clockwise; OuterArc.Point = OuterArcEndPoint; OuterArc.Size = outerArcSize; OuterArc.IsLargeArc = largeArc; LineSegment EndLine = new LineSegment(); EndLine.Point = EndLineEndPoint; path.Segments.Add(ButtomLine); path.Segments.Add(OuterArc); path.Segments.Add(EndLine); path.Segments.Add(InnerArc); PathGeometry myPath = new PathGeometry(); myPath.Figures.Add(path); return myPath; }
private void UpdatePath() { var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(Radius, Radius); pathFigure.IsClosed = true; // Starting Point var lineSegment = new LineSegment { Point = new Point( Radius + Math.Sin(StartAngle * Math.PI / 180) * Radius, Radius - Math.Cos(StartAngle * Math.PI / 180) * Radius) }; // Arc var arcSegment = new ArcSegment(); arcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0; arcSegment.Point = new Point( Radius + Math.Sin(EndAngle * Math.PI / 180) * Radius, Radius - Math.Cos(EndAngle * Math.PI / 180) * Radius); arcSegment.Size = new Size(Radius, Radius); arcSegment.SweepDirection = SweepDirection.Clockwise; pathFigure.Segments.Add(lineSegment); pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); this.Data = pathGeometry; this.InvalidateArrange(); }
public void InitializePieChart() { // draw the full circle/arc _arcSegment360 = new ArcSegment { SweepDirection = SweepDirection.Clockwise }; _pathFigure360 = new PathFigure { Segments = new PathSegmentCollection { _arcSegment360 } }; _pathRoot360 = new Path { Stroke = Segment360Color, StrokeThickness = StrokeThickness, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Data = new PathGeometry { Figures = new PathFigureCollection { _pathFigure360 } } }; //draw a circle with the given angle _arcSegment = new ArcSegment { SweepDirection = SweepDirection.Clockwise }; _pathFigure = new PathFigure { Segments = new PathSegmentCollection { _arcSegment } }; _pathRoot = new Path { Stroke = SegmentColor, StrokeThickness = StrokeThickness, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Data = new PathGeometry { Figures = new PathFigureCollection { _pathFigure } } }; Content = new Grid { Background = BackgroundColor, Children = { _pathRoot360, _pathRoot, } }; }
public static WMedia.Geometry ToWindows(this Geometry geometry) { WMedia.Geometry wGeometry = null; if (geometry is LineGeometry) { LineGeometry lineGeometry = geometry as LineGeometry; wGeometry = new WMedia.LineGeometry { StartPoint = lineGeometry.StartPoint.ToWindows(), EndPoint = lineGeometry.EndPoint.ToWindows() }; } else if (geometry is RectangleGeometry) { var rect = (geometry as RectangleGeometry).Rect; wGeometry = new WMedia.RectangleGeometry { Rect = new WFoundation.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry ellipseGeometry = geometry as EllipseGeometry; wGeometry = new WMedia.EllipseGeometry { Center = ellipseGeometry.Center.ToWindows(), RadiusX = ellipseGeometry.RadiusX, RadiusY = ellipseGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup geometryGroup = geometry as GeometryGroup; wGeometry = new WMedia.GeometryGroup { FillRule = ConvertFillRule(geometryGroup.FillRule) }; foreach (Geometry children in geometryGroup.Children) { WMedia.Geometry winChild = children.ToWindows(); (wGeometry as WMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry pathGeometry = geometry as PathGeometry; WMedia.PathGeometry wPathGeometry = new WMedia.PathGeometry { FillRule = ConvertFillRule(pathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in pathGeometry.Figures) { WMedia.PathFigure wPathFigure = new WMedia.PathFigure { StartPoint = xamPathFigure.StartPoint.ToWindows(), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; wPathGeometry.Figures.Add(wPathFigure); foreach (PathSegment pathSegment in xamPathFigure.Segments) { // LineSegment if (pathSegment is LineSegment) { LineSegment lineSegment = pathSegment as LineSegment; WMedia.LineSegment winSegment = new WMedia.LineSegment { Point = lineSegment.Point.ToWindows() }; wPathFigure.Segments.Add(winSegment); } // PolylineSegment if (pathSegment is PolyLineSegment) { PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment; WMedia.PolyLineSegment wSegment = new WMedia.PolyLineSegment(); foreach (var point in polyLineSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // BezierSegment if (pathSegment is BezierSegment) { BezierSegment bezierSegment = pathSegment as BezierSegment; WMedia.BezierSegment wSegment = new WMedia.BezierSegment { Point1 = bezierSegment.Point1.ToWindows(), Point2 = bezierSegment.Point2.ToWindows(), Point3 = bezierSegment.Point3.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyBezierSegment else if (pathSegment is PolyBezierSegment) { PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; WMedia.PolyBezierSegment wSegment = new WMedia.PolyBezierSegment(); foreach (var point in polyBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // QuadraticBezierSegment if (pathSegment is QuadraticBezierSegment) { QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment; WMedia.QuadraticBezierSegment wSegment = new WMedia.QuadraticBezierSegment { Point1 = quadraticBezierSegment.Point1.ToWindows(), Point2 = quadraticBezierSegment.Point2.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyQuadraticBezierSegment else if (pathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment; WMedia.PolyQuadraticBezierSegment wSegment = new WMedia.PolyQuadraticBezierSegment(); foreach (var point in polyQuadraticBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // ArcSegment else if (pathSegment is ArcSegment) { ArcSegment arcSegment = pathSegment as ArcSegment; WMedia.ArcSegment wSegment = new WMedia.ArcSegment { Size = new WFoundation.Size(arcSegment.Size.Width, arcSegment.Size.Height), RotationAngle = arcSegment.RotationAngle, IsLargeArc = arcSegment.IsLargeArc, SweepDirection = arcSegment.SweepDirection == SweepDirection.Clockwise ? WMedia.SweepDirection.Clockwise : WMedia.SweepDirection.Counterclockwise, Point = arcSegment.Point.ToWindows() }; wPathFigure.Segments.Add(wSegment); } } } wGeometry = wPathGeometry; } return(wGeometry); }
protected override void OnApplyTemplate() { // Draw Scale var scale = this.GetTemplateChild(ScalePartName) as Path; if (scale != null) { var pg = new PathGeometry(); var pf = new PathFigure(); pf.IsClosed = false; var middleOfScale = 77 - this.ScaleWidth / 2; pf.StartPoint = this.ScalePoint(-150, middleOfScale); var seg = new ArcSegment(); seg.SweepDirection = SweepDirection.Clockwise; seg.IsLargeArc = true; seg.Size = new Size(middleOfScale, middleOfScale); seg.Point = this.ScalePoint(150, middleOfScale); pf.Segments.Add(seg); pg.Figures.Add(pf); scale.Data = pg; } OnValueChanged(this); base.OnApplyTemplate(); }
/// <summary> /// Updates the needle rotation, the trail, and the value text according to the new value. /// </summary> private static void OnValueChanged(DependencyObject d) { RadialGauge c = (RadialGauge)d; if (!Double.IsNaN(c.Value)) { var middleOfScale = 100 - ScalePadding - c.ScaleWidth / 2; var valueText = c.GetTemplateChild(ValueTextPartName) as TextBlock; c.ValueAngle = c.ValueToAngle(c.Value); // Needle if (c._needle != null) { c._needle.RotationAngleInDegrees = (float)c.ValueAngle; } // Trail var trail = c.GetTemplateChild(TrailPartName) as Path; if (trail != null) { if (c.ValueAngle > MinAngle) { trail.Visibility = Visibility.Visible; var pg = new PathGeometry(); var pf = new PathFigure(); pf.IsClosed = false; pf.StartPoint = c.ScalePoint(MinAngle, middleOfScale); var seg = new ArcSegment(); seg.SweepDirection = SweepDirection.Clockwise; // We start from -150, so +30 becomes a large arc. seg.IsLargeArc = c.ValueAngle > (180 + MinAngle); seg.Size = new Size(middleOfScale, middleOfScale); seg.Point = c.ScalePoint(Math.Min(c.ValueAngle, MaxAngle), 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 = c.Value.ToString(c.ValueStringFormat); } } }
protected override void OnApplyTemplate() { // Scale. var scale = this.GetTemplateChild(ScalePartName) as Path; if (scale != null) { var pg = new PathGeometry(); var pf = new PathFigure(); pf.IsClosed = false; var middleOfScale = 100 - ScalePadding - this.ScaleWidth / 2; pf.StartPoint = this.ScalePoint(MinAngle, middleOfScale); var seg = new ArcSegment(); seg.SweepDirection = SweepDirection.Clockwise; seg.IsLargeArc = true; seg.Size = new Size(middleOfScale, middleOfScale); seg.Point = this.ScalePoint(MaxAngle, middleOfScale); pf.Segments.Add(seg); pg.Figures.Add(pf); scale.Data = pg; } var container = this.GetTemplateChild(ContainerPartName) as Grid; _root = container.GetVisual(); _compositor = _root.Compositor; // Ticks. SpriteVisual tick; for (double i = Minimum; i <= Maximum; i += TickSpacing) { tick = _compositor.CreateSpriteVisual(); tick.Size = new Vector2(TickWidth, TickHeight); tick.Brush = _compositor.CreateColorBrush(TickBrush.Color); tick.Offset = new Vector3(100 - TickWidth / 2, 0.0f, 0); tick.CenterPoint = new Vector3(TickWidth / 2, 100.0f, 0); tick.RotationAngleInDegrees = (float)ValueToAngle(i); _root.Children.InsertAtTop(tick); } // Scale Ticks. for (double i = Minimum; i <= Maximum; i += TickSpacing) { tick = _compositor.CreateSpriteVisual(); tick.Size = new Vector2(ScaleTickWidth, (float)ScaleWidth); tick.Brush = _compositor.CreateColorBrush(ScaleTickBrush.Color); tick.Offset = new Vector3(100 - ScaleTickWidth / 2, ScalePadding, 0); tick.CenterPoint = new Vector3(ScaleTickWidth / 2, 100 - ScalePadding, 0); tick.RotationAngleInDegrees = (float)ValueToAngle(i); _root.Children.InsertAtTop(tick); } // Needle. _needle = _compositor.CreateSpriteVisual(); _needle.Size = new Vector2(NeedleWidth, NeedleHeight); _needle.Brush = _compositor.CreateColorBrush(NeedleBrush.Color); _needle.CenterPoint = new Vector3(NeedleWidth / 2, NeedleHeight, 0); _needle.Offset = new Vector3(100 - NeedleWidth / 2, 100 - NeedleHeight, 0); _root.Children.InsertAtTop(_needle); OnValueChanged(this); base.OnApplyTemplate(); }
private ArcSegment CreateArc(CornerPosition position, double start, double width, double height) { ArcSegment arc = null; switch (position) { case CornerPosition.TopLeft: arc = new ArcSegment { Size = new Size(this.CornerRadius.TopLeft, this.CornerRadius.TopLeft), Point = new Point(this.CornerRadius.TopLeft, start), RotationAngle = 0, IsLargeArc = false, SweepDirection = SweepDirection.Clockwise }; break; case CornerPosition.TopRight: arc = new ArcSegment { Size = new Size(this.CornerRadius.TopRight, this.CornerRadius.TopRight), Point = new Point(width, start + this.CornerRadius.TopRight), RotationAngle = 0, IsLargeArc = false, SweepDirection = SweepDirection.Clockwise }; break; case CornerPosition.BottomRight: arc = new ArcSegment { Size = new Size(this.CornerRadius.BottomRight, this.CornerRadius.BottomRight), Point = new Point(width - this.CornerRadius.BottomRight, height), RotationAngle = 0, IsLargeArc = false, SweepDirection = SweepDirection.Clockwise }; break; case CornerPosition.BottomLeft: arc = new ArcSegment { Size = new Size(this.CornerRadius.BottomLeft, this.CornerRadius.BottomLeft), Point = new Point(start, height - this.CornerRadius.BottomLeft), RotationAngle = 0, IsLargeArc = false, SweepDirection = SweepDirection.Clockwise }; break; } return arc; }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { // Path Demonstration LineSegment lineSeg1 = new LineSegment(); lineSeg1.Point = new Point(500, 500); LineSegment lineSeg2 = new LineSegment(); lineSeg2.Point = new Point(0, 500); ArcSegment arcSeg = new ArcSegment(); arcSeg.Point = new Point(0, 0); arcSeg.Size = new Size(250, 250); arcSeg.IsLargeArc = true; BezierSegment bzSeg = new BezierSegment(); bzSeg.Point1 = new Point(125, 125); bzSeg.Point2 = new Point(375, 375); bzSeg.Point3 = new Point(500, 250); // Add Segment to PathSegmentCollention PathSegmentCollection myPathSegCol1 = new PathSegmentCollection(); myPathSegCol1.Add(lineSeg1); PathSegmentCollection myPathSegCol2 = new PathSegmentCollection(); myPathSegCol2.Add(lineSeg2); PathSegmentCollection myPathSegCol3 = new PathSegmentCollection(); myPathSegCol3.Add(arcSeg); PathSegmentCollection myPathSegCol4 = new PathSegmentCollection(); myPathSegCol4.Add(bzSeg); // Add Segment Collection to Figure PathFigure myPathFig1 = new PathFigure { StartPoint = new Point(0, 0), Segments = myPathSegCol1 }; PathFigure myPathFig2 = new PathFigure { StartPoint = new Point(500, 0), Segments = myPathSegCol2 }; PathFigure myPathFig3 = new PathFigure { StartPoint = new Point(0, -0.1), Segments = myPathSegCol3 }; PathFigure myPathFig4 = new PathFigure { StartPoint = new Point(0, 250), Segments = myPathSegCol4 }; // Add Figures to Geometry PathGeometry myPathGeo1 = new PathGeometry(); myPathGeo1.Figures.Add(myPathFig1); myPathGeo1.Figures.Add(myPathFig2); PathGeometry myPathGeo2 = new PathGeometry(); myPathGeo2.Figures.Add(myPathFig3); PathGeometry myPathGeo3 = new PathGeometry(); myPathGeo3.Figures.Add(myPathFig4); // Add Geometry to Path Path myPath1 = new Path { Stroke = new SolidColorBrush(Colors.Cyan), StrokeThickness = 12, StrokeLineJoin = PenLineJoin.Round, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Data = myPathGeo1, Stretch = Stretch.Uniform }; Path myPath2 = new Path { Stroke = new SolidColorBrush(Colors.Crimson), StrokeThickness = 12, StrokeLineJoin = PenLineJoin.Round, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Data = myPathGeo2, Stretch = Stretch.Uniform }; Path myPath3 = new Path { Stroke = new SolidColorBrush(Colors.Crimson), StrokeThickness = 12, StrokeLineJoin = PenLineJoin.Round, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Data = myPathGeo3, Stretch = Stretch.Uniform }; // Another way, read from XAML. Path tempPath = XamlReader.Load("<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Stroke='Blue' Data='M 0 0 Q 10 10 20 0'/>") as Path; Geometry geo = tempPath.Data; tempPath.Data = null; // YOu can NOT use the data for another path before the original one is empty!! Path myPath4 = new Path { Stroke = new SolidColorBrush(Colors.Coral), StrokeThickness = 12, StrokeLineJoin = PenLineJoin.Round, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Stretch = Stretch.Uniform, Data = geo }; ThirdPgGrid.Children.Add(myPath1); ThirdPgGrid.Children.Add(myPath2); ThirdPgGrid.Children.Add(myPath3); ThirdPgGrid.Children.Add(myPath4); }
private void UpdatePath() { var innerRadius = this.InnerRadius + this.StrokeThickness / 2; var outerRadius = this.Radius - this.StrokeThickness / 2; if (_isUpdating || this.ActualWidth == 0 || innerRadius <= 0 || outerRadius < innerRadius) { return; } var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure(); pathFigure.IsClosed = true; var center = this.Center ?? new Point( outerRadius + this.StrokeThickness / 2, outerRadius + this.StrokeThickness / 2); // Starting Point pathFigure.StartPoint = new Point( center.X + Math.Sin(StartAngle * Math.PI / 180) * innerRadius, center.Y - Math.Cos(StartAngle * Math.PI / 180) * innerRadius); // Inner Arc var innerArcSegment = new ArcSegment(); innerArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0; innerArcSegment.Point = new Point( center.X + Math.Sin(EndAngle * Math.PI / 180) * innerRadius, center.Y - Math.Cos(EndAngle * Math.PI / 180) * innerRadius); innerArcSegment.Size = new Size(innerRadius, innerRadius); innerArcSegment.SweepDirection = SweepDirection.Clockwise; var lineSegment = new LineSegment { Point = new Point( center.X + Math.Sin(EndAngle * Math.PI / 180) * outerRadius, center.Y - Math.Cos(EndAngle * Math.PI / 180) * outerRadius) }; // Outer Arc var outerArcSegment = new ArcSegment(); outerArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0; outerArcSegment.Point = new Point( center.X + Math.Sin(StartAngle * Math.PI / 180) * outerRadius, center.Y - Math.Cos(StartAngle * Math.PI / 180) * outerRadius); outerArcSegment.Size = new Size(outerRadius, outerRadius); outerArcSegment.SweepDirection = SweepDirection.Counterclockwise; pathFigure.Segments.Add(innerArcSegment); pathFigure.Segments.Add(lineSegment); pathFigure.Segments.Add(outerArcSegment); pathGeometry.Figures.Add(pathFigure); this.InvalidateArrange(); this.Data = pathGeometry; }
/// <summary> /// Main parser routine, which loops over each char in received string, and performs actions according to command/parameter being passed /// </summary> /// <param name="path">String with path data definition</param> /// <returns>PathGeometry object created from string definition</returns> private PathGeometry parse(string path) { PathGeometry _pathGeometry = null; _formatProvider = CultureInfo.InvariantCulture; _pathString = path; _pathLength = path.Length; _curIndex = 0; _secondLastPoint = new Point(0, 0); _lastPoint = new Point(0, 0); _lastStart = new Point(0, 0); _figureStarted = false; bool first = true; char last_cmd = ' '; while (ReadToken()) // Empty path is allowed in XAML { char cmd = _token; if (first) { if ((cmd != 'M') && (cmd != 'm')) // Path starts with M|m { ThrowBadToken(); } first = false; } switch (cmd) { case 'm': case 'M': // XAML allows multiple points after M/m _lastPoint = ReadPoint(cmd, !AllowComma); _figure = new PathFigure(); _figure.StartPoint = _lastPoint; _figure.IsFilled = IsFilled; _figure.IsClosed = !IsClosed; //context.BeginFigure(_lastPoint, IsFilled, !IsClosed); _figureStarted = true; _lastStart = _lastPoint; last_cmd = 'M'; while (IsNumber(AllowComma)) { _lastPoint = ReadPoint(cmd, !AllowComma); LineSegment _lineSegment = new LineSegment(); _lineSegment.Point = _lastPoint; _figure.Segments.Add(_lineSegment); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'L'; } break; case 'l': case 'L': case 'h': case 'H': case 'v': case 'V': EnsureFigure(); do { switch (cmd) { case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'h': _lastPoint.X += ReadNumber(!AllowComma); break; case 'H': _lastPoint.X = ReadNumber(!AllowComma); break; case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break; case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break; } LineSegment _lineSegment = new LineSegment(); _lineSegment.Point = _lastPoint; _figure.Segments.Add(_lineSegment); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); } while (IsNumber(AllowComma)); last_cmd = 'L'; break; case 'c': case 'C': // cubic Bezier case 's': case 'S': // smooth cublic Bezier EnsureFigure(); do { Point p; if ((cmd == 's') || (cmd == 'S')) { if (last_cmd == 'C') { p = Reflect(); } else { p = _lastPoint; } _secondLastPoint = ReadPoint(cmd, !AllowComma); } else { p = ReadPoint(cmd, !AllowComma); _secondLastPoint = ReadPoint(cmd, AllowComma); } _lastPoint = ReadPoint(cmd, AllowComma); BezierSegment _bizierSegment = new BezierSegment(); _bizierSegment.Point1 = p; _bizierSegment.Point2 = _secondLastPoint; _bizierSegment.Point3 = _lastPoint; _figure.Segments.Add(_bizierSegment); //context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'C'; } while (IsNumber(AllowComma)); break; case 'q': case 'Q': // quadratic Bezier case 't': case 'T': // smooth quadratic Bezier EnsureFigure(); do { if ((cmd == 't') || (cmd == 'T')) { if (last_cmd == 'Q') { _secondLastPoint = Reflect(); } else { _secondLastPoint = _lastPoint; } _lastPoint = ReadPoint(cmd, !AllowComma); } else { _secondLastPoint = ReadPoint(cmd, !AllowComma); _lastPoint = ReadPoint(cmd, AllowComma); } QuadraticBezierSegment _quadraticBezierSegment = new QuadraticBezierSegment(); _quadraticBezierSegment.Point1 = _secondLastPoint; _quadraticBezierSegment.Point2 = _lastPoint; _figure.Segments.Add(_quadraticBezierSegment); //context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); last_cmd = 'Q'; } while (IsNumber(AllowComma)); break; case 'a': case 'A': EnsureFigure(); do { // A 3,4 5, 0, 0, 6,7 double w = ReadNumber(!AllowComma); double h = ReadNumber(AllowComma); double rotation = ReadNumber(AllowComma); bool large = ReadBool(); bool sweep = ReadBool(); _lastPoint = ReadPoint(cmd, AllowComma); ArcSegment _arcSegment = new ArcSegment(); _arcSegment.Point = _lastPoint; _arcSegment.Size = new Size(w, h); _arcSegment.RotationAngle = rotation; _arcSegment.IsLargeArc = large; _arcSegment.SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise; _figure.Segments.Add(_arcSegment); //context.ArcTo( // _lastPoint, // new Size(w, h), // rotation, // large, // sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, // IsStroked, // !IsSmoothJoin // ); } while (IsNumber(AllowComma)); last_cmd = 'A'; break; case 'z': case 'Z': EnsureFigure(); _figure.IsClosed = IsClosed; //context.SetClosedState(IsClosed); _figureStarted = false; last_cmd = 'Z'; _lastPoint = _lastStart; // Set reference point to be first point of current figure break; default: ThrowBadToken(); break; } } if (null != _figure) { _pathGeometry = new PathGeometry(); _pathGeometry.Figures.Add(_figure); } return _pathGeometry; }
private static void OnValueChanged(DependencyObject d) { RadialGauge c = (RadialGauge)d; if (!Double.IsNaN(c.Value)) { var middleOfScale = 77 - c.ScaleWidth / 2; var needle = c.GetTemplateChild(NeedlePartName) as Path; var valueText = c.GetTemplateChild(ValueTextPartName) as TextBlock; c.ValueAngle = c.ValueToAngle(c.Value); // Needle if (needle != null) { needle.RenderTransform = new RotateTransform() { Angle = c.ValueAngle }; } // Trail var trail = c.GetTemplateChild(TrailPartName) as Path; if (trail != null) { if (c.ValueAngle > -146) { trail.Visibility = Visibility.Visible; var pg = new PathGeometry(); var pf = new PathFigure(); pf.IsClosed = false; pf.StartPoint = c.ScalePoint(-150, middleOfScale); var seg = new ArcSegment(); seg.SweepDirection = SweepDirection.Clockwise; // We start from -150, so +30 becomes a large arc. seg.IsLargeArc = c.ValueAngle > 30; seg.Size = new Size(middleOfScale, middleOfScale); seg.Point = c.ScalePoint(c.ValueAngle, middleOfScale); pf.Segments.Add(seg); pg.Figures.Add(pf); trail.Data = pg; } else { trail.Visibility = Visibility.Collapsed; } } // Value Text if (valueText != null) { valueText.Text = c.Value.ToString(c.ValueStringFormat); } } }
private void Draw() { if (ActualHeight > 0) { FreeLabel.FontSize = ActualHeight*0.25; } var value = double.NaN; var lot = ParkingLot; if (lot != null && lot.TotalLots != 0) { value = ((double)lot.FreeLots) / ((double)lot.TotalLots); } if (double.IsNaN(value) || double.IsInfinity(value)) { ValueInvertedCircle.Visibility = ValuePath.Visibility = Visibility.Collapsed; FreeLabel.Text = "?"; if (lot != null) { PlayAnimation(); } return; } if (value < 0) { value = 0; }else if (value > 1) { value = 1; } ValueInvertedCircle.Visibility = ValuePath.Visibility = Visibility.Visible; FreeLabel.Text = Math.Round(value * 100) + "%"; ValuePath.SetValue(Path.DataProperty, null); var pg = new PathGeometry(); var fig = new PathFigure(); var height = ActualHeight; var width = ActualWidth; var radius = height / 2; var theta = (360 * value) - 90; var xC = radius; var yC = radius; if (value == 1) theta += 1; var finalPointX = xC + (radius * Math.Cos(theta * 0.0174)); var finalPointY = yC + (radius * Math.Sin(theta * 0.0174)); fig.StartPoint = new Point(radius, radius); var firstLine = new LineSegment {Point = new Point(radius, 0)}; fig.Segments.Add(firstLine); if (value > 0.25) { var firstQuart = new ArcSegment { Point = new Point(width, radius), SweepDirection = SweepDirection.Clockwise, Size = new Size(radius, radius) }; fig.Segments.Add(firstQuart); } if (value > 0.5) { var secondQuart = new ArcSegment { Point = new Point(radius, height), SweepDirection = SweepDirection.Clockwise, Size = new Size(radius, radius) }; fig.Segments.Add(secondQuart); } if (value > 0.75) { var thirdQuart = new ArcSegment { Point = new Point(0, radius), SweepDirection = SweepDirection.Clockwise, Size = new Size(radius, radius) }; fig.Segments.Add(thirdQuart); } var finalQuart = new ArcSegment { Point = new Point(finalPointX, finalPointY), SweepDirection = SweepDirection.Clockwise, Size = new Size(radius, radius) }; fig.Segments.Add(finalQuart); var lastLine = new LineSegment {Point = new Point(radius, radius)}; fig.Segments.Add(lastLine); pg.Figures.Add(fig); ValuePath.SetValue(Path.DataProperty, pg); PlayAnimation(); }
public object ConvertToNative(Geometry geometry) { winMedia.Geometry winGeometry = null; // Determine what type of geometry we're dealing with. if (geometry is LineGeometry) { LineGeometry xamGeometry = geometry as LineGeometry; winGeometry = new winMedia.LineGeometry { StartPoint = ConvertPoint(xamGeometry.StartPoint), EndPoint = ConvertPoint(xamGeometry.EndPoint) }; } else if (geometry is RectangleGeometry) { Rect rect = (geometry as RectangleGeometry).Rect; winGeometry = new winMedia.RectangleGeometry { Rect = new winFound.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry xamGeometry = geometry as EllipseGeometry; winGeometry = new winMedia.EllipseGeometry { Center = ConvertPoint(xamGeometry.Center), RadiusX = xamGeometry.RadiusX, RadiusY = xamGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup xamGeometry = geometry as GeometryGroup; winGeometry = new winMedia.GeometryGroup { FillRule = ConvertFillRule(xamGeometry.FillRule) }; foreach (Geometry xamChild in xamGeometry.Children) { winMedia.Geometry winChild = ConvertToNative(xamChild) as winMedia.Geometry; (winGeometry as winMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry xamPathGeometry = geometry as PathGeometry; winMedia.PathGeometry winPathGeometry = new winMedia.PathGeometry { FillRule = ConvertFillRule(xamPathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in xamPathGeometry.Figures) { winMedia.PathFigure winPathFigure = new winMedia.PathFigure { StartPoint = ConvertPoint(xamPathFigure.StartPoint), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; winPathGeometry.Figures.Add(winPathFigure); foreach (PathSegment xamPathSegment in xamPathFigure.Segments) { // LineSegment if (xamPathSegment is LineSegment) { LineSegment xamSegment = xamPathSegment as LineSegment; winMedia.LineSegment winSegment = new winMedia.LineSegment { Point = ConvertPoint(xamSegment.Point) }; winPathFigure.Segments.Add(winSegment); } // PolylineSegment if (xamPathSegment is PolyLineSegment) { PolyLineSegment xamSegment = xamPathSegment as PolyLineSegment; winMedia.PolyLineSegment winSegment = new winMedia.PolyLineSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // BezierSegment if (xamPathSegment is BezierSegment) { BezierSegment xamSegment = xamPathSegment as BezierSegment; winMedia.BezierSegment winSegment = new winMedia.BezierSegment { Point1 = ConvertPoint(xamSegment.Point1), Point2 = ConvertPoint(xamSegment.Point2), Point3 = ConvertPoint(xamSegment.Point3) }; winPathFigure.Segments.Add(winSegment); } // PolyBezierSegment else if (xamPathSegment is PolyBezierSegment) { PolyBezierSegment xamSegment = xamPathSegment as PolyBezierSegment; winMedia.PolyBezierSegment winSegment = new winMedia.PolyBezierSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // QuadraticBezierSegment if (xamPathSegment is QuadraticBezierSegment) { QuadraticBezierSegment xamSegment = xamPathSegment as QuadraticBezierSegment; winMedia.QuadraticBezierSegment winSegment = new winMedia.QuadraticBezierSegment { Point1 = ConvertPoint(xamSegment.Point1), Point2 = ConvertPoint(xamSegment.Point2), }; winPathFigure.Segments.Add(winSegment); } // PolyQuadraticBezierSegment else if (xamPathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment xamSegment = xamPathSegment as PolyQuadraticBezierSegment; winMedia.PolyQuadraticBezierSegment winSegment = new winMedia.PolyQuadraticBezierSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // ArcSegment else if (xamPathSegment is ArcSegment) { ArcSegment xamSegment = xamPathSegment as ArcSegment; winMedia.ArcSegment winSegment = new winMedia.ArcSegment(); winSegment.Size = new winFound.Size(xamSegment.Size.Width, xamSegment.Size.Height); winSegment.RotationAngle = xamSegment.RotationAngle; winSegment.IsLargeArc = xamSegment.IsLargeArc; winSegment.SweepDirection = xamSegment.SweepDirection == SweepDirection.Clockwise ? winMedia.SweepDirection.Clockwise : winMedia.SweepDirection.Counterclockwise; winSegment.Point = ConvertPoint(xamSegment.Point); winPathFigure.Segments.Add(winSegment); } } } winGeometry = winPathGeometry; } // Set transform. if (geometry.Transform != null) { winGeometry.Transform = (winMedia.Transform)geometry.Transform.GetNativeObject(); } return(winGeometry); }
public static Windows.UI.Xaml.Shapes.Path GetGeometry(double width, double widthPoint1, double widthPoint2, double widthPoint3, double heightPoint1, double heightPoint2, SolidColorBrush color) { Windows.UI.Xaml.Shapes.Path myPath = new Windows.UI.Xaml.Shapes.Path(); myPath.Stroke = color; myPath.StrokeThickness = 15; LineGeometry myLineGeometry = new LineGeometry(); myLineGeometry.StartPoint = new Point(widthPoint1, heightPoint2); myLineGeometry.EndPoint = new Point(widthPoint1, heightPoint1); ArcSegment arc2 = new ArcSegment(); arc2.Point = new Point(widthPoint2, heightPoint1); arc2.RotationAngle = 180; arc2.SweepDirection = SweepDirection.Clockwise; arc2.Size = new Size((double)(width / 6), heightPoint1); LineGeometry line3 = new LineGeometry(); line3.StartPoint = new Point(widthPoint2, heightPoint1); line3.EndPoint = new Point(widthPoint2, heightPoint2); ArcSegment arc4 = new ArcSegment(); arc4.Point = new Point(widthPoint3, heightPoint2); arc4.RotationAngle = 180; arc4.SweepDirection = SweepDirection.Clockwise; arc4.Size = new Size(width / 12, heightPoint1 / 2); LineGeometry line5 = new LineGeometry(); line5.StartPoint = new Point(widthPoint3, heightPoint2); line5.EndPoint = new Point(widthPoint3, heightPoint1); PathFigure pathfigureforarc2 = new PathFigure(); pathfigureforarc2.StartPoint = new Point(widthPoint1, heightPoint1); pathfigureforarc2.Segments.Add(arc2); pathfigureforarc2.IsFilled = false; PathFigure pathfigureforarc4 = new PathFigure(); pathfigureforarc4.StartPoint = new Point(widthPoint2, heightPoint2); pathfigureforarc4.Segments.Add(arc4); pathfigureforarc4.IsFilled = false; PathGeometry pathgeoforarc2 = new PathGeometry(); pathgeoforarc2.Figures.Add(pathfigureforarc2); PathGeometry pathgeoforarc4 = new PathGeometry(); pathgeoforarc4.Figures.Add(pathfigureforarc4); GeometryGroup myGeometryGroup = new GeometryGroup(); myGeometryGroup.Children.Add(myLineGeometry); myGeometryGroup.Children.Add(pathgeoforarc2); myGeometryGroup.Children.Add(line3); myGeometryGroup.Children.Add(pathgeoforarc4); myGeometryGroup.Children.Add(line5); myPath.Data = myGeometryGroup; return myPath; }
private void AddArc(Point point, Size size, bool largeArc, SweepDirection sweepDirection) //在图形中添加一条弧线 { ArcSegment segment = new ArcSegment(); segment.Point = point; segment.Size = size; segment.IsLargeArc = largeArc; segment.SweepDirection = sweepDirection; figure.Segments.Add(segment); }
private void buildPath() { Point centerPoint; if (IsExploaded) centerPoint = calculateExplodedCenterPoint(); else centerPoint = calculateStartingCenterPoint(); if (RenderAsCircle) this.Data = buildSingleItemPath(centerPoint); else { var pf = new PathFigure(); if (InnerRadius == 0) pf.StartPoint = centerPoint; else pf.StartPoint = Utils.ComputeCartesianCoordinate(StartAngle, InnerRadius).Offset(centerPoint.X, centerPoint.Y); pf.Segments = new PathSegmentCollection(); //add start line var startLine = new LineSegment(); startLine.Point = Utils.ComputeCartesianCoordinate(StartAngle, Radius).Offset(centerPoint.X, centerPoint.Y); pf.Segments.Add(startLine); //add arc segment var arc = new ArcSegment() { Point = Utils.ComputeCartesianCoordinate(EndAngle, Radius).Offset(centerPoint.X, centerPoint.Y), Size = new Windows.Foundation.Size(Radius, Radius), SweepDirection = SweepDirection.Clockwise, IsLargeArc = (EndAngle - StartAngle > 180), }; pf.Segments.Add(arc); //add closing line var endLine = new LineSegment(); if (InnerRadius == 0) endLine.Point = centerPoint; else endLine.Point = Utils.ComputeCartesianCoordinate(EndAngle, InnerRadius).Offset(centerPoint.X, centerPoint.Y); pf.Segments.Add(endLine); if (InnerRadius != 0) { //add inner arc segment var innerArc = new ArcSegment() { Point = Utils.ComputeCartesianCoordinate(StartAngle, InnerRadius).Offset(centerPoint.X, centerPoint.Y), Size = new Windows.Foundation.Size(InnerRadius, InnerRadius), SweepDirection = SweepDirection.Counterclockwise, IsLargeArc = (EndAngle - StartAngle > 180) }; pf.Segments.Add(innerArc); } this.Data = new PathGeometry() { Figures = new PathFigureCollection() { pf } }; } }
private static PathSegmentCollection Clone(PathSegmentCollection pathSegColl) { PathSegmentCollection collClone = new PathSegmentCollection(); foreach (PathSegment item in pathSegColl) { PathSegment clone = null; if (item is LineSegment) { LineSegment seg = item as LineSegment; clone = new LineSegment() { Point = seg.Point }; } else if (item is PolyLineSegment) { PolyLineSegment seg = item as PolyLineSegment; clone = new PolyLineSegment() { Points = getPoints(seg.Points) }; } else if (item is BezierSegment) { BezierSegment seg = item as BezierSegment; clone = new BezierSegment() { Point1 = seg.Point1, Point2 = seg.Point2, Point3 = seg.Point3 }; } else if (item is PolyBezierSegment) { PolyBezierSegment seg = item as PolyBezierSegment; clone = new PolyBezierSegment() { Points = getPoints(seg.Points) }; } else if (item is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment seg = item as PolyQuadraticBezierSegment; clone = new PolyQuadraticBezierSegment() { Points = getPoints(seg.Points) }; } else if (item is QuadraticBezierSegment) { QuadraticBezierSegment seg = item as QuadraticBezierSegment; clone = new QuadraticBezierSegment() { Point1 = seg.Point1, Point2 = seg.Point2 }; } else if (item is Windows.UI.Xaml.Media.ArcSegment) { Windows.UI.Xaml.Media.ArcSegment seg = item as Windows.UI.Xaml.Media.ArcSegment; clone = new Windows.UI.Xaml.Media.ArcSegment() { IsLargeArc = seg.IsLargeArc, Point = seg.Point, RotationAngle = seg.RotationAngle, Size = seg.Size, SweepDirection = seg.SweepDirection }; } collClone.Add(clone); } return(collClone); }
private void BuildArc(int radius, int arcThickness, Windows.UI.Color color, double angleStart, double angleEnd) { double angleChange = 44; Point startPoint = CalculateCartesianPoint(angleStart, radius); Point endPoint = CalculateCartesianPoint(angleEnd, radius); // Create an ArcSegment to define the geometry of the path. // The Size property of this segment is animated. ArcSegment myArcSegment = new ArcSegment(); myArcSegment.Size = new Size(radius, radius); myArcSegment.SweepDirection = SweepDirection.Clockwise; myArcSegment.Point = endPoint; myArcSegment.IsLargeArc = false; PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); myPathSegmentCollection.Add(myArcSegment); // Create a PathFigure to be used for the PathGeometry of myPath. PathFigure myPathFigure = new PathFigure(); myPathFigure.StartPoint = startPoint; myPathFigure.Segments = myPathSegmentCollection; PathFigureCollection myPathFigureCollection = new PathFigureCollection(); myPathFigureCollection.Add(myPathFigure); PathGeometry myPathGeometry = new PathGeometry(); myPathGeometry.Figures = myPathFigureCollection; // Create a path to draw a geometry with. Windows.UI.Xaml.Shapes.Path myPath = new Windows.UI.Xaml.Shapes.Path(); myPath.Stroke = new SolidColorBrush(color); myPath.StrokeThickness = arcThickness; // specify the shape of the path using the path geometry. myPath.Data = myPathGeometry; Canvas containerCanvas = new Canvas(); containerCanvas.Children.Add(myPath); containerCanvas.PointerPressed += (o,a) => { sbPressButton.Begin(); Messenger.Default.Send(new ArcMenuItemSelectedMessage(this.MenuId.ToString()) { Identifier = "AMS" }); }; layoutRoot.Children.Add(containerCanvas); ((CompositeTransform)pthTriangle.RenderTransform).TranslateX = radius; //((CompositeTransform)pthTriangle.RenderTransform).TranslateY = radius; ((CompositeTransform)grdTriangle.RenderTransform).Rotation = angleStart + (angleChange/2); }
private void UpdatePath() { var radius = this.Radius - this.StrokeThickness / 2; if (_isUpdating || this.ActualWidth == 0 || radius <= 0) { return; } var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(radius, radius); pathFigure.IsClosed = true; // Starting Point var lineSegment = new LineSegment { Point = new Point( radius + Math.Sin(StartAngle * Math.PI / 180) * radius, radius - Math.Cos(StartAngle * Math.PI / 180) * radius) }; // Arc var arcSegment = new ArcSegment(); arcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0; arcSegment.Point = new Point( radius + Math.Sin(EndAngle * Math.PI / 180) * radius, radius - Math.Cos(EndAngle * Math.PI / 180) * radius); arcSegment.Size = new Size(radius, radius); arcSegment.SweepDirection = SweepDirection.Clockwise; pathFigure.Segments.Add(lineSegment); pathFigure.Segments.Add(arcSegment); pathGeometry.Figures.Add(pathFigure); this.Data = pathGeometry; this.InvalidateArrange(); }
/// <summary> /// Main parser routine, which loops over each char in received string, and performs actions according to command/parameter being passed /// </summary> /// <param name="path">String with path data definition</param> /// <returns>PathGeometry object created from string definition</returns> private PathGeometry Parse(string path) { PathGeometry pathGeometry = null; _formatProvider = CultureInfo.InvariantCulture; _pathString = path; _pathLength = path.Length; _curIndex = 0; _secondLastPoint = new Point(0, 0); _lastPoint = new Point(0, 0); _lastStart = new Point(0, 0); _figureStarted = false; var first = true; var lastCmd = ' '; while (ReadToken()) // Empty path is allowed in XAML { char cmd = _token; if (first) { if ((cmd != 'M') && (cmd != 'm') && (cmd != 'f') && (cmd != 'F')) // Path starts with M|m { ThrowBadToken(); } first = false; } switch (cmd) { case 'f': case 'F': pathGeometry = new PathGeometry(); var num = ReadNumber(!AllowComma); // ReSharper disable once CompareOfFloatsByEqualityOperator pathGeometry.FillRule = num == 0 ? FillRule.EvenOdd : FillRule.Nonzero; break; case 'm': case 'M': // XAML allows multiple points after M/m _lastPoint = ReadPoint(cmd, !AllowComma); _figure = new PathFigure { StartPoint = _lastPoint, IsFilled = IsFilled, IsClosed = !IsClosed }; //context.BeginFigure(_lastPoint, IsFilled, !IsClosed); _figureStarted = true; _lastStart = _lastPoint; lastCmd = 'M'; while (IsNumber(AllowComma)) { _lastPoint = ReadPoint(cmd, !AllowComma); var lineSegment = new LineSegment {Point = _lastPoint}; _figure.Segments.Add(lineSegment); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); lastCmd = 'L'; } break; case 'l': case 'L': case 'h': case 'H': case 'v': case 'V': EnsureFigure(); do { switch (cmd) { case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break; case 'h': _lastPoint.X += ReadNumber(!AllowComma); break; case 'H': _lastPoint.X = ReadNumber(!AllowComma); break; case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break; case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break; } var lineSegment = new LineSegment {Point = _lastPoint}; _figure.Segments.Add(lineSegment); //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin); } while (IsNumber(AllowComma)); lastCmd = 'L'; break; case 'c': case 'C': // cubic Bezier case 's': case 'S': // smooth cublic Bezier EnsureFigure(); do { Point p; if ((cmd == 's') || (cmd == 'S')) { p = lastCmd == 'C' ? Reflect() : _lastPoint; _secondLastPoint = ReadPoint(cmd, !AllowComma); } else { p = ReadPoint(cmd, !AllowComma); _secondLastPoint = ReadPoint(cmd, AllowComma); } _lastPoint = ReadPoint(cmd, AllowComma); var bizierSegment = new BezierSegment { Point1 = p, Point2 = _secondLastPoint, Point3 = _lastPoint }; _figure.Segments.Add(bizierSegment); //context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); lastCmd = 'C'; } while (IsNumber(AllowComma)); break; case 'q': case 'Q': // quadratic Bezier case 't': case 'T': // smooth quadratic Bezier EnsureFigure(); do { if ((cmd == 't') || (cmd == 'T')) { _secondLastPoint = lastCmd == 'Q' ? Reflect() : _lastPoint; _lastPoint = ReadPoint(cmd, !AllowComma); } else { _secondLastPoint = ReadPoint(cmd, !AllowComma); _lastPoint = ReadPoint(cmd, AllowComma); } var quadraticBezierSegment = new QuadraticBezierSegment { Point1 = _secondLastPoint, Point2 = _lastPoint }; _figure.Segments.Add(quadraticBezierSegment); //context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin); lastCmd = 'Q'; } while (IsNumber(AllowComma)); break; case 'a': case 'A': EnsureFigure(); do { // A 3,4 5, 0, 0, 6,7 var w = ReadNumber(!AllowComma); var h = ReadNumber(AllowComma); var rotation = ReadNumber(AllowComma); var large = ReadBool(); var sweep = ReadBool(); _lastPoint = ReadPoint(cmd, AllowComma); var arcSegment = new ArcSegment { Point = _lastPoint, Size = new Size(w, h), RotationAngle = rotation, IsLargeArc = large, SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise }; _figure.Segments.Add(arcSegment); //context.ArcTo( // _lastPoint, // new Size(w, h), // rotation, // large, // sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, // IsStroked, // !IsSmoothJoin // ); } while (IsNumber(AllowComma)); lastCmd = 'A'; break; case 'z': case 'Z': EnsureFigure(); _figure.IsClosed = IsClosed; //context.SetClosedState(IsClosed); _figureStarted = false; lastCmd = 'Z'; _lastPoint = _lastStart; // Set reference point to be first point of current figure break; default: ThrowBadToken(); break; } if (null != _figure) { if (_figure.IsClosed) { if (null == pathGeometry) pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(_figure); _figure = null; first = true; } } } if (null != _figure) { if (null == pathGeometry) pathGeometry = new PathGeometry(); if (!pathGeometry.Figures.Contains(_figure)) pathGeometry.Figures.Add(_figure); } return pathGeometry; }
private void RenderArc() { if (FirstRadius <= 0 || ScreenHeight <= 0 || ScreenWidth <= 0) return; double __end_angle = ((_end_angle - _start_angle) == 360.0) ? _end_angle - 0.01 : _end_angle; double begin = _start_angle * (Math.PI / 180); double end = __end_angle * (Math.PI / 180); double radius = (FirstRadius - (InnerRadius / 4)); if (radius <= 0) return; double startX = (ScreenWidth / 2) + (radius * Math.Cos(begin)); double startY = (ScreenHeight / 2) - (radius * Math.Sin(begin)); double endX = (ScreenWidth / 2) + (radius * Math.Cos(end)); double endY = (ScreenHeight / 2) - (radius * Math.Sin(end)); PathGeometry outerGeometry = new PathGeometry(); PathGeometry innerBorderGeometry = new PathGeometry(); PathFigure outerFigure = new PathFigure(); outerFigure.StartPoint = new Point(startX, startY); var outerArc = new ArcSegment(); outerArc.Point = new Point(endX, endY); outerArc.Size = new Size(radius, radius); outerArc.RotationAngle = 0; outerArc.IsLargeArc = (((__end_angle - _start_angle)%360) > 180.0); outerArc.SweepDirection = SweepDirection.Counterclockwise; outerFigure.Segments.Add(outerArc); outerGeometry.Figures.Add(outerFigure); #region inner border radius = (FirstRadius - (InnerRadius/2) - InnerBorderMargin); startX = (ScreenWidth / 2) + (radius * Math.Cos(begin)); startY = (ScreenHeight / 2) - (radius * Math.Sin(begin)); endX = (ScreenWidth / 2) + (radius * Math.Cos(end)); endY = (ScreenHeight / 2) - (radius * Math.Sin(end)); PathFigure innerBorderFigure = new PathFigure(); innerBorderFigure.StartPoint = new Point(startX, startY); var innerBorderArc = new ArcSegment(); innerBorderArc.Point = new Point(endX, endY); innerBorderArc.Size = new Size(radius, radius); innerBorderArc.RotationAngle = 0; innerBorderArc.IsLargeArc = (((__end_angle - _start_angle) % 360) > 180.0); innerBorderArc.SweepDirection = SweepDirection.Counterclockwise; innerBorderFigure.Segments.Add(innerBorderArc); innerBorderGeometry.Figures.Add(innerBorderFigure); #endregion #region outer border PathGeometry outerBorderGeometry = new PathGeometry(); radius = (FirstRadius + OuterBorderMargin); startX = (ScreenWidth / 2) + (radius * Math.Cos(begin)); startY = (ScreenHeight / 2) - (radius * Math.Sin(begin)); endX = (ScreenWidth / 2) + (radius * Math.Cos(end)); endY = (ScreenHeight / 2) - (radius * Math.Sin(end)); PathFigure outerBorderFigure = new PathFigure(); outerBorderFigure.StartPoint = new Point(startX, startY); var outerBorderArc = new ArcSegment(); outerBorderArc.Point = new Point(endX, endY); outerBorderArc.Size = new Size(radius, radius); outerBorderArc.RotationAngle = 0; outerBorderArc.IsLargeArc = (((__end_angle - _start_angle) % 360) > 180.0); outerBorderArc.SweepDirection = SweepDirection.Counterclockwise; outerBorderFigure.Segments.Add(outerBorderArc); outerBorderGeometry.Figures.Add(outerBorderFigure); #endregion ThicknessArc.Data = outerGeometry; InnerBorder.Data = innerBorderGeometry; OuterBorder.Data = outerBorderGeometry; }
private void UpdatePath() { if (_isUpdating) { return; } var pathGeometry = new PathGeometry(); var pathFigure = new PathFigure(); pathFigure.IsClosed = false; var center = new Point( Radius , Radius); // Starting Point pathFigure.StartPoint = new Point( center.X + Math.Sin(StartAngle * Math.PI / 180) * (Radius - StrokeThickness/2), center.Y - Math.Cos(StartAngle * Math.PI / 180) * (Radius - StrokeThickness / 2)); // Outer Arc var outerArcSegment = new ArcSegment(); outerArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0; outerArcSegment.Point = new Point( center.X + Math.Sin(Math.Min(359.99, EndAngle) * Math.PI / 180) * (Radius - StrokeThickness / 2), center.Y - Math.Cos(Math.Min(359.99, EndAngle) * Math.PI / 180) * (Radius - StrokeThickness / 2)); outerArcSegment.Size = new Size(Math.Max((Radius - StrokeThickness / 2), 0), Math.Max((Radius - StrokeThickness / 2), 0)); outerArcSegment.SweepDirection = SweepDirection.Clockwise; pathFigure.Segments.Add(outerArcSegment); pathGeometry.Figures.Add(pathFigure); this.InvalidateArrange(); this.Data = pathGeometry; }