public static void AddCircleFigure(this CanvasPathBuilder builder, float centerX, float centerY, float radius) { builder.BeginFigure(new Vector2(centerX, centerY - radius)); builder.AddArc(new Vector2(centerX, centerY + radius), radius, radius, 0, CanvasSweepDirection.Clockwise, CanvasArcSize.Large); builder.AddArc(new Vector2(centerX, centerY - radius), radius, radius, 0, CanvasSweepDirection.Clockwise, CanvasArcSize.Large); builder.EndFigure(CanvasFigureLoop.Closed); }
CanvasGeometry MakeDirectionIcon(ICanvasResourceCreator creator) { var builder = new CanvasPathBuilder(creator); float radius = 3; float lineWidth = 20; builder.BeginFigure(0, 0); builder.AddLine(0, radius * 2); builder.EndFigure(CanvasFigureLoop.Open); float y = radius; builder.BeginFigure(0, y); builder.AddArc(new Vector2(lineWidth + radius, y + radius), radius, radius, -(float)Math.PI / 2, (float)Math.PI); y += radius * 2; builder.AddArc(new Vector2(radius, y + radius), radius, radius, -(float)Math.PI / 2, -(float)Math.PI); y += radius * 2; float x = lineWidth * 2 / 3; builder.AddLine(x, y); builder.EndFigure(CanvasFigureLoop.Open); builder.BeginFigure(x - radius, y - radius / 3); builder.AddLine(x, y); builder.AddLine(x - radius, y + radius / 3); builder.EndFigure(CanvasFigureLoop.Open); return(CanvasGeometry.CreatePath(builder)); }
private CanvasPathBuilder CreateForegroundGauge(ICanvasResourceCreator sender) { var center = new Vector2(0, 0); float outerRadius = 50.0f; float innerRadius = outerRadius * 0.7f; float startAngle = (float)StartAngle; float sweepAngle = (float)((Utilities.Clamp(DeliveredLitres, MinimumLitres, PresetLitres) / (PresetLitres - MinimumLitres)) * (StartAngle - EndAngle)); float endAngle = (float)(startAngle - sweepAngle); var pathBuilder = new CanvasPathBuilder(sender); pathBuilder.BeginFigure(GetVector(outerRadius, startAngle)); pathBuilder.AddArc(center, outerRadius, outerRadius, startAngle, -sweepAngle); //var vc = GetVector(innerRadius, endAngle); pathBuilder.AddLine(GetVector(innerRadius, endAngle)); pathBuilder.AddArc(center, innerRadius, innerRadius, endAngle, sweepAngle); pathBuilder.EndFigure(CanvasFigureLoop.Closed); return(pathBuilder); }
private CanvasPathBuilder CreateBorderGauge(ICanvasResourceCreator sender) { var center = new Vector2(0, 0); float outerRadius = 49.0f; float innerRadius = outerRadius * 0.7f; var pathBuilder = new CanvasPathBuilder(sender); float startAngle = (float)StartAngle; float endAngle = (float)EndAngle; float sweepAngle = (float)(StartAngle - EndAngle); pathBuilder.BeginFigure(GetVector(outerRadius, startAngle)); pathBuilder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin); pathBuilder.AddArc(center, outerRadius, outerRadius, startAngle, -sweepAngle); pathBuilder.AddLine(GetVector(innerRadius, endAngle)); pathBuilder.AddArc(center, innerRadius, innerRadius, endAngle, sweepAngle); pathBuilder.EndFigure(CanvasFigureLoop.Closed); return(pathBuilder); }
/// <summary> /// Adds an ellipse figure to the path. /// </summary> /// <param name="pathBuilder">CanvasPathBuilder</param> /// <param name="x">X coordinate of the center location of the ellipse.</param> /// <param name="y">Y coordinate of the center location of the ellipse.</param> /// <param name="radiusX">Radius of the ellipse on the X-axis.</param> /// <param name="radiusY">Radius of the ellipse on the Y-axis.</param> public static void AddEllipseFigure(this CanvasPathBuilder pathBuilder, float x, float y, float radiusX, float radiusY) { // Sanitize the radiusX by taking the absolute value radiusX = Math.Abs(radiusX); // Sanitize the radiusY by taking the absolute value radiusY = Math.Abs(radiusY); try { pathBuilder.BeginFigure(x + radiusX, y); } catch (ArgumentException) { // An ArgumentException will be raised if another figure was already begun( and not ended) // before calling AddEllipseFigure() method. throw new InvalidOperationException("A call to CanvasPathBuilder.AddEllipseFigure occurred, " + "when another figure was already begun. Please call CanvasPathBuilder.EndFigure method, " + "before calling CanvasPathBuilder.AddEllipseFigure, to end the previous figure."); } // First Semi-Ellipse pathBuilder.AddArc(new Vector2(x - radiusX, y), radiusX, radiusY, Scalar.Pi, CanvasSweepDirection.Clockwise, CanvasArcSize.Large); // Second Semi-Ellipse pathBuilder.AddArc(new Vector2(x + radiusX, y), radiusX, radiusY, Scalar.Pi, CanvasSweepDirection.Clockwise, CanvasArcSize.Large); // End Figure pathBuilder.EndFigure(CanvasFigureLoop.Closed); }
private static CanvasGeometry CreateCookieCore(ICanvasResourceCreator resourceCreator, Matrix3x2 oneMatrix, float innerRadius, float sweepAngle) { // start tooth Vector2 startTooth = new Vector2(1, 0); // end tooth Vector2 endTooth = TransformerGeometry.GetRotationVector(sweepAngle); CanvasPathBuilder pathBuilder = new CanvasPathBuilder(resourceCreator); CanvasArcSize canvasArcSize = (sweepAngle < System.Math.PI) ? CanvasArcSize.Large : CanvasArcSize.Small; { // DonutAndCookie // start notch Vector2 startNotch = startTooth * innerRadius; // end notch Vector2 endNotch = endTooth * innerRadius; // start tooth point pathBuilder.BeginFigure(startNotch); // start notch point pathBuilder.AddArc(endNotch, innerRadius, innerRadius, sweepAngle, CanvasSweepDirection.CounterClockwise, canvasArcSize); } // end notch point pathBuilder.AddLine(endTooth); // end tooth point pathBuilder.AddArc(startTooth, 1, 1, sweepAngle, CanvasSweepDirection.Clockwise, canvasArcSize); pathBuilder.EndFigure(CanvasFigureLoop.Closed); return(CanvasGeometry.CreatePath(pathBuilder).Transform(oneMatrix)); }
//Capsule:胶囊 public static CanvasGeometry CreateCapsule(ICanvasResourceCreator rc, Vector2 start, Vector2 end, float radius) { //基本向量 Vector2 vector = end - start; float rotation = 修图.Library.Method.Tanh(vector);//初始角度 //左右角度/向量 double rotationLeft = rotation + Math.PI / 2; double rotationRight = rotation - Math.PI / 2; Vector2 left = new Point(Math.Cos(rotationLeft), Math.Sin(rotationLeft)).ToVector2() * radius; Vector2 right = new Point(Math.Cos(rotationRight), Math.Sin(rotationRight)).ToVector2() * radius; //计算四个位置 Vector2 startLeft = start + left; Vector2 startRight = start + right; Vector2 endLeft = end + left; Vector2 endRight = end + right; //画几何 CanvasPathBuilder pathBuilder = new CanvasPathBuilder(rc); pathBuilder.BeginFigure(startLeft); //左上角 pathBuilder.AddArc(startRight, radius, radius, (float)Math.PI, CanvasSweepDirection.Clockwise, CanvasArcSize.Large); //左下角 pathBuilder.AddLine(endRight); pathBuilder.AddArc(endLeft, radius, radius, (float)Math.PI, CanvasSweepDirection.Clockwise, CanvasArcSize.Large);//右下角 pathBuilder.EndFigure(CanvasFigureLoop.Closed); return(CanvasGeometry.CreatePath(pathBuilder)); }
//Heart:心形 public static CanvasGeometry CreateHeart(ICanvasResourceCreator rc, Vector2 start, Vector2 end) { //基本向量 Vector2 vector = end - start; float rotation = 修图.Library.Method.Tanh(vector);//初始角度 float LengthHalf = vector.Length() / 2; Vector2 center = (end + start) / 2; //正方形中心点 float radius = LengthHalf / (float)Math.Sqrt(2.0d); //圆半径 //左右角度/向量 double rotationLeft = rotation + Math.PI / 2; double rotationRight = rotation - Math.PI / 2; Vector2 left = new Point(Math.Cos(rotationLeft), Math.Sin(rotationLeft)).ToVector2() * LengthHalf + center; //左点 Vector2 right = new Point(Math.Cos(rotationRight), Math.Sin(rotationRight)).ToVector2() * LengthHalf + center; //右点 //画几何 CanvasPathBuilder pathBuilder = new CanvasPathBuilder(rc); pathBuilder.BeginFigure(start); //屁眼 pathBuilder.AddArc(left, radius, radius, (float)Math.PI, CanvasSweepDirection.CounterClockwise, CanvasArcSize.Large); //左下角 pathBuilder.AddLine(end); pathBuilder.AddLine(right); pathBuilder.AddArc(start, radius, radius, (float)Math.PI, CanvasSweepDirection.CounterClockwise, CanvasArcSize.Large);//右下角 pathBuilder.EndFigure(CanvasFigureLoop.Closed); return(CanvasGeometry.CreatePath(pathBuilder)); }
private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args) { var startAngle = (float)(StartAngle - Math.PI / 2); var center = new Vector2((float)(ActualWidth / 2), (float)(ActualHeight / 2)); var radius = center.X > center.Y ? new Vector2(center.Y) : new Vector2(center.X); var startPoint = center + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(startAngle)) * radius; using (var builder = new CanvasPathBuilder(sender)) { double relativeDistance = Distance / radius.X; double relativeSecondDistance = Distance / (radius.X - Thickness / 2); double repairSweepAngle = SweepAngle > relativeDistance ? SweepAngle - relativeDistance : 0; double repairSecondSweepAngle = SweepAngle > relativeSecondDistance / 2 ? SweepAngle - relativeSecondDistance / 2 : 0; builder.BeginFigure(startPoint); builder.AddArc(center, radius.X, radius.Y, (float)(startAngle + relativeDistance / 2), (float)repairSweepAngle); builder.AddArc(center, radius.X - (float)Thickness / 2, (float)(radius.Y - Thickness / 2), (float)(startAngle + SweepAngle - relativeSecondDistance / 2), -(float)repairSecondSweepAngle); builder.EndFigure(CanvasFigureLoop.Closed); /* * builder.BeginFigure(startPoint); * builder.AddArc(center, radius.X, radius.Y, startAngle, (float)repairSweepAngle); * builder.EndFigure(CanvasFigureLoop.Open); */ using (var geometry = CanvasGeometry.CreatePath(builder)) args.DrawingSession.FillGeometry(geometry, Fill.Color); } }
public void AddArc(float xCenter, float yCenter, float radius, float startAngle, float endAngle) { if (pathBuilder == null) { throw new Exception("Path is closed"); } pathBuilder.AddArc(new Vector2(xCenter, yCenter), radius, radius, startAngle, endAngle); }
virtual protected void DrawAlarmLowArc(CanvasControl sender, CanvasDrawEventArgs args, Color alarmColor, double alarmValue) { var ds = args.DrawingSession; float percentValue = (float)((alarmValue - MinValue) / (MaxValue - MinValue)); float range = GaugeEndAngle - GaugeStartAngle; float degrees = GaugeStartAngle + (range * percentValue); float arcSweepAngle = degrees - GaugeStartAngle; float startAngle = (float)(GaugeStartAngle * Math.PI / 180D); float sweepAngle = (float)(arcSweepAngle * Math.PI / 180D); double radian = GaugeStartAngle * Math.PI / 180D; float startX = (float)(Math.Cos(radian) * MiddleCircleRadius) + Center.X; float startY = (float)(Math.Sin(radian) * MiddleCircleRadius) + Center.Y; Vector2 startPoint = new Vector2(startX, startY); using (var builder = new CanvasPathBuilder(sender)) { builder.BeginFigure(startPoint); builder.AddArc(Center, MiddleCircleRadius, MiddleCircleRadius, startAngle, sweepAngle); builder.EndFigure(CanvasFigureLoop.Open); using (var geometry = CanvasGeometry.CreatePath(builder)) { ds.DrawGeometry(geometry, alarmColor, (float)MediumTicLength, arcStrokeStyle); } } }
private void CanvasAnimatedControl_OnDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { for (int i = 0; i <= _ringCount; i++) { var currentOffset = StartOffset + i*(RingPadding + RingStrokeWidth); using (var c = new CanvasPathBuilder(sender)) { c.BeginFigure(currentOffset, 0.0f); c.AddArc(new Vector2(0.0f, 0.0f), currentOffset, currentOffset, 0.0f, (float)(Math.PI * 2)); c.EndFigure(CanvasFigureLoop.Open); using (var g = CanvasGeometry.CreatePath(c)) { var m = _pattern[_animationCounter + (_ringCount - i)]; _brush.Transform = Matrix3x2.CreateRotation((float)(Math.PI * 2 * m), _center); using (args.DrawingSession.CreateLayer(_brush)) { args.DrawingSession.DrawGeometry(g, _center, Color.FromArgb(255, m < 0.5 ? Convert.ToByte(Math.Floor(m * 2 * 255)) : Convert.ToByte(Math.Floor((1.5 - m) * 255)), m < 0.5 ? (byte)128 : Convert.ToByte(Math.Floor(m * 255)), 255), RingStrokeWidth); } } } } _animationCounter++; if (_animationCounter > _pattern.Count - _ringCount - 1) _animationCounter = 0; }
protected override void Render() { var root = Container.GetVisual(); var compositor = Window.Current.Compositor; var canvasPathBuilder = new CanvasPathBuilder(new CanvasDevice()); if (IsStrokeRounded) { canvasPathBuilder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin); } else { canvasPathBuilder.SetSegmentOptions(CanvasFigureSegmentOptions.None); } // Figure if (IsPie) { StartPointX = CenterPointX; StartPointY = CenterPointY; } else { StartPointX = Radius * Math.Cos(StartAngle * Degrees2Radians) + CenterPointX; StartPointY = Radius * Math.Sin(StartAngle * Degrees2Radians) + CenterPointY; } canvasPathBuilder.BeginFigure(new Vector2((float)StartPointX, (float)StartPointY)); canvasPathBuilder.AddArc( new Vector2((float)CenterPointX, (float)CenterPointY), (float)Radius, (float)Radius, (float)(StartAngle * Degrees2Radians), (float)(SweepAngle * Degrees2Radians)); canvasPathBuilder.EndFigure(IsClosed || IsPie ? CanvasFigureLoop.Closed : CanvasFigureLoop.Open); // Path var canvasGeometry = CanvasGeometry.CreatePath(canvasPathBuilder); var compositionPath = new CompositionPath(canvasGeometry); var pathGeometry = compositor.CreatePathGeometry(); pathGeometry.Path = compositionPath; var spriteShape = compositor.CreateSpriteShape(pathGeometry); spriteShape.FillBrush = compositor.CreateColorBrush(Fill); spriteShape.StrokeThickness = (float)StrokeThickness; spriteShape.StrokeBrush = compositor.CreateColorBrush(Stroke); spriteShape.StrokeStartCap = IsStrokeRounded ? CompositionStrokeCap.Round : CompositionStrokeCap.Flat; spriteShape.StrokeEndCap = IsStrokeRounded ? CompositionStrokeCap.Round : CompositionStrokeCap.Flat; // Visual var shapeVisual = compositor.CreateShapeVisual(); shapeVisual.Size = new Vector2((float)Container.ActualWidth, (float)Container.ActualHeight); shapeVisual.Shapes.Add(spriteShape); root.Children.RemoveAll(); root.Children.InsertAtTop(shapeVisual); }
public void VerifySendPathTo() { // // This calls each of the path functions, once, and verfies that it works. // Sink behavior is verified in more detail in the geometry unit tests. // CanvasDevice device = new CanvasDevice(); CanvasPathBuilder pathBuilder = new CanvasPathBuilder(device); pathBuilder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Alternate); pathBuilder.BeginFigure(0, 0); pathBuilder.AddLine(0, 0); pathBuilder.AddQuadraticBezier(new Vector2(), new Vector2()); pathBuilder.AddCubicBezier(new Vector2(), new Vector2(), new Vector2()); // D2D tries to be smart about degenerate arcs and redundant set segment options, and may sometimes actually // surpress them. Therefore, these calls use non-defaults. pathBuilder.AddArc(new Vector2 { X = 100, Y = 100 }, 10, 10, 90, CanvasSweepDirection.Clockwise, CanvasArcSize.Small); pathBuilder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceUnstroked); pathBuilder.EndFigure(CanvasFigureLoop.Closed); CanvasGeometry pathGeometry = CanvasGeometry.CreatePath(pathBuilder); MyGeometryStreamReader myStreamReader = new MyGeometryStreamReader(); pathGeometry.SendPathTo(myStreamReader); myStreamReader.Verify(); }
//Pie:饼图(内半径百分比、开始角度,扫描角度) public static CanvasGeometry CreatePie(ICanvasResourceCreator rc, Vector2 start, Vector2 end, float innerRadius, float sweepAngle) { sweepAngle = (float)Math.PI * 2 - sweepAngle; //基本参数 Vector2 vector = end - start; //基本向量 float radius = vector.Length(); //牙齿边长 float radiusHalf = radius * innerRadius; //切口边长 float startAngle = 修图.Library.Method.Tanh(vector); //起始角度 //计算四个点 Vector2 startVector = new Point(Math.Cos(startAngle), Math.Sin(startAngle)).ToVector2(); //借本向量起始 Vector2 endVector = new Point(Math.Cos(sweepAngle + startAngle), Math.Sin(sweepAngle + startAngle)).ToVector2(); //借本向量终末 Vector2 startVectorTooth = startVector * radius + start; //起始牙齿 Vector2 startVectorNotch = startVector * radiusHalf + start; //起始切口 Vector2 endVectorTooth = endVector * radius + start; //起始牙齿 Vector2 endVectorNotch = endVector * radiusHalf + start; //起始切口 //画几何 CanvasPathBuilder pathBuilder = new CanvasPathBuilder(rc); if (sweepAngle < Math.PI) { pathBuilder.BeginFigure(startVectorNotch); //起始切口点 pathBuilder.AddArc(endVectorNotch, radiusHalf, radiusHalf, sweepAngle, CanvasSweepDirection.CounterClockwise, CanvasArcSize.Large); //终末切口点 pathBuilder.AddLine(endVectorTooth); //终末牙齿点 pathBuilder.AddArc(startVectorTooth, radius, radius, sweepAngle, CanvasSweepDirection.Clockwise, CanvasArcSize.Large); //起始牙齿点 } else { pathBuilder.BeginFigure(startVectorNotch); //起始切口点 pathBuilder.AddArc(endVectorNotch, radiusHalf, radiusHalf, sweepAngle, CanvasSweepDirection.CounterClockwise, CanvasArcSize.Small); //终末切口点 pathBuilder.AddLine(endVectorTooth); //终末牙齿点 pathBuilder.AddArc(startVectorTooth, radius, radius, sweepAngle, CanvasSweepDirection.Clockwise, CanvasArcSize.Small); //起始牙齿点 } pathBuilder.EndFigure(CanvasFigureLoop.Closed); return(CanvasGeometry.CreatePath(pathBuilder)); }
public UIBezierPath(Vector2 center, float radius, float startAngle, float endAngle, bool clockwise) { mBuilder = new CanvasPathBuilder(CanvasDevice.GetSharedDevice()); float sweepAngle = endAngle; //float sa = RadianToDegrees(startAngle); //float ea = RadianToDegrees(endAngle); mBuilder.AddArc(center, radius, radius, startAngle, sweepAngle); }
public CanvasGeometry Arc(ICanvasResourceCreator resourceCreator, float centerX, float centerY, float radius, float startAngle, float endAngle) { var path = new CanvasPathBuilder(resourceCreator); path.BeginFigure(centerX, centerY - radius); path.AddArc(new Vector2(centerX, centerY), radius, radius, startAngle, endAngle); path.EndFigure(CanvasFigureLoop.Open); return(CanvasGeometry.CreatePath(path)); }
static CanvasGeometry CreateTimeSegmentGeometry(CanvasDrawingSession ds, double fractionSecond) { double fractionSecondAngle = 2 * Math.PI * fractionSecond; double angle = fractionSecondAngle % (2 * Math.PI); using (var builder = new CanvasPathBuilder(ds)) { builder.BeginFigure(center, center); builder.AddArc(new Vector2(center), radius, radius, (float)Math.PI * 3 / 2, (float)angle); builder.EndFigure(CanvasFigureLoop.Closed); return CanvasGeometry.CreatePath(builder); } }
public static List <PiePartGeometry> GetPieChart(ICanvasResourceCreator resourceCreator, float[] valueList, ChartTextFormat textFormat, float radius, bool isShowData) { var centerPoint = new Vector2(radius, radius); var geoList = new List <PiePartGeometry>(); var sum = valueList.Sum(); var startAngle = 0f; var percentList = valueList.Select(o => o / sum); foreach (var item in percentList) { var radian = item * 2 * Math.PI; var builder = new CanvasPathBuilder(resourceCreator); builder.BeginFigure(centerPoint); builder.AddArc(centerPoint, radius, radius, startAngle, (float)radian); builder.EndFigure(CanvasFigureLoop.Closed); if (isShowData) { var partCenter = new Point( (radius - textFormat.Thickness.Top) * Math.Cos(startAngle + radian / 2) + centerPoint.X, (radius - textFormat.Thickness.Top) * Math.Sin(startAngle + radian / 2) + centerPoint.Y) .ToVector2(); var textLayout = ChartDrawHelper.CreateCanvasText(resourceCreator, $"{string.Format("{0:F1}", item * 100)}%", textFormat); var textRect = textLayout.DrawBounds; var textPos = new Point(partCenter.X - textRect.Width / 2, partCenter.Y - textRect.Height / 2); var part = new PiePartGeometry { ShapeGeometry = CanvasGeometry.CreatePath(builder), TextGeometry = CanvasGeometry.CreateText(textLayout), DataRect = new Rect(textPos, new Size(textRect.Width, textRect.Height)) }; geoList.Add(part); builder.Dispose(); textLayout.Dispose(); } else { var part = new PiePartGeometry { ShapeGeometry = CanvasGeometry.CreatePath(builder) }; geoList.Add(part); builder.Dispose(); } startAngle += (float)radian; } return(geoList); }
internal virtual void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle) { Vector2 center = new Vector2(); center.X = x + w / 2; center.Y = y + h / 2; if (arcAngle == 360) graphics.DrawEllipse(center, w / 2, h / 2, c); else { CanvasPathBuilder builder = new CanvasPathBuilder(graphics); builder.BeginFigure(center); builder.AddArc(center, w / 2, h / 2, -(float)(2 * Math.PI * startAngle / 360), -(float)(2 * Math.PI * arcAngle / 360)); builder.EndFigure(CanvasFigureLoop.Closed); graphics.DrawGeometry(CanvasGeometry.CreatePath(builder), c); } }
protected void DrawGaugeArc(CanvasControl sender, CanvasDrawingSession ds, float startAngle, float endAngle, Color color, CanvasSweepDirection canvasSweepDirection, CanvasArcSize canvasArcSize) { using (CanvasPathBuilder cp = new CanvasPathBuilder(sender)) { var startPoint = this.Center + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(startAngle)) * this.Radius; var endPoint = this.Center + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(endAngle)) * this.Radius; cp.BeginFigure(startPoint); cp.AddArc(endPoint, this.Radius, this.Radius, 0, canvasSweepDirection, canvasArcSize); cp.EndFigure(CanvasFigureLoop.Open); using (var geometry = CanvasGeometry.CreatePath(cp)) { ds.DrawGeometry(geometry, color, c_arcThickness, this.ArcStrokeStyle); } } }
private static void Render(DependencyObject d, DependencyPropertyChangedEventArgs args) { var arc = (EllipticalArc)d; if (arc.Container.ActualWidth == 0) { return; } var root = arc.Container.GetVisual(); var compositor = Window.Current.Compositor; var canvasPathBuilder = new CanvasPathBuilder(new CanvasDevice()); // Figure canvasPathBuilder.BeginFigure(new Vector2(arc.StartPointX, arc.StartPointY)); canvasPathBuilder.AddArc( new Vector2(arc.EndPointX, arc.EndPointY), arc.RadiusX, arc.RadiusY, (float)(arc.RotationAngle * Math.PI / 180), arc.IsClockwise ? CanvasSweepDirection.Clockwise : CanvasSweepDirection.CounterClockwise, arc.IsLargeArc ? CanvasArcSize.Large : CanvasArcSize.Small); canvasPathBuilder.EndFigure(arc.IsClosed ? CanvasFigureLoop.Closed : CanvasFigureLoop.Open); // Path var canvasGeometry = CanvasGeometry.CreatePath(canvasPathBuilder); var compositionPath = new CompositionPath(canvasGeometry); var pathGeometry = compositor.CreatePathGeometry(); pathGeometry.Path = compositionPath; var spriteShape = compositor.CreateSpriteShape(pathGeometry); spriteShape.FillBrush = compositor.CreateColorBrush(arc.Fill); spriteShape.StrokeThickness = (float)arc.StrokeThickness; spriteShape.StrokeBrush = compositor.CreateColorBrush(arc.Stroke); spriteShape.StrokeStartCap = arc.IsStrokeRounded ? CompositionStrokeCap.Round : CompositionStrokeCap.Flat; spriteShape.StrokeEndCap = arc.IsStrokeRounded ? CompositionStrokeCap.Round : CompositionStrokeCap.Flat; // Visual var shapeVisual = compositor.CreateShapeVisual(); shapeVisual.Size = new Vector2((float)arc.Container.ActualWidth, (float)arc.Container.ActualHeight); shapeVisual.Shapes.Add(spriteShape); root.Children.RemoveAll(); root.Children.InsertAtTop(shapeVisual); }
internal virtual void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle) { Vector2 center = new Vector2(); center.X = x + w / 2; center.Y = y + h / 2; if (arcAngle == 360) { graphics.DrawEllipse(center, w / 2, h / 2, c); } else { CanvasPathBuilder builder = new CanvasPathBuilder(graphics); builder.BeginFigure(center); builder.AddArc(center, w / 2, h / 2, -(float)(2 * Math.PI * startAngle / 360), -(float)(2 * Math.PI * arcAngle / 360)); builder.EndFigure(CanvasFigureLoop.Closed); graphics.DrawGeometry(CanvasGeometry.CreatePath(builder), c); } }
/// <summary> /// Adds the Path Element to the Path. /// </summary> /// <param name="pathBuilder">CanvasPathBuilder object</param> /// <param name="currentPoint">The last active location in the Path before adding /// the Path Element</param> /// <param name="lastElement">The previous PathElement in the Path.</param> /// <returns>The latest location in the Path after adding the Path Element</returns> public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement) { // Calculate coordinates var point = new Vector2(_x, _y); if (IsRelative) { point += currentPoint; } // Execute command pathBuilder.AddArc(point, _radiusX, _radiusY, _angle, _sweepDirection, _arcSize); // Set Last Element lastElement = this; // Return current point return(point); }
public void Draw(object ds, XArc arc, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r) { var a = WpfArc.FromXArc(arc, dx, dy); var _ds = ds as CanvasDrawingSession; double thickness = arc.Style.Thickness / _state.Zoom; var brush = ToColor(arc.Style.Fill); var pen = ToColor(arc.Style.Stroke); var ss = CreateStrokeStyle(arc.Style); CanvasGeometry g; using (var builder = new CanvasPathBuilder(_ds)) { builder.BeginFigure((float)a.Start.X, (float)a.Start.Y); builder.AddArc( new N.Vector2( (float)a.End.X, (float)a.End.Y), (float)a.Radius.Width, (float)a.Radius.Height, 0f, CanvasSweepDirection.Clockwise, a.IsLargeArc ? CanvasArcSize.Large : CanvasArcSize.Small); builder.EndFigure(CanvasFigureLoop.Open); g = CanvasGeometry.CreatePath(builder); } if (arc.IsFilled) { _ds.FillGeometry(g, brush); } if (arc.IsStroked) { _ds.DrawGeometry(g, pen, (float)thickness, ss); } g.Dispose(); ss.Dispose(); }
protected void DrawValueArc(CanvasControl sender, CanvasDrawingSession ds) { this.CreateGaugeArcBrush(sender); using (CanvasPathBuilder cp = new CanvasPathBuilder(sender)) { cp.BeginFigure(this.Center); float startAngle = (float)RadiansFromDegrees(c_startAngle); double endDegrees = this.PercentToStartAngle(this.PercentFull); float endAngle = (float)RadiansFromDegrees(this.PercentToStartAngle(this.PercentFull)); cp.AddArc(this.Center, this.Radius, this.Radius, startAngle, endAngle - startAngle); cp.EndFigure(CanvasFigureLoop.Closed); using (var geometry = CanvasGeometry.CreatePath(cp)) { ds.FillGeometry(geometry, this.GaugeArcBrush); // Colors.Green); } } }
internal virtual void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle) { //using (createAlphaLayer()) //{ Vector2 center = new Vector2(); center.X = x + w / 2; center.Y = y + h / 2; if (arcAngle == 360) { graphics.DrawEllipse(center, w / 2, h / 2, Color.FromArgb((byte)alpha, c.R, c.G, c.B)); } else { CanvasPathBuilder builder = new CanvasPathBuilder(graphics); builder.BeginFigure(center); builder.AddArc(center, w / 2, h / 2, -(float)(2 * Math.PI * startAngle / 360), -(float)(2 * Math.PI * arcAngle / 360)); builder.EndFigure(CanvasFigureLoop.Closed); graphics.DrawGeometry(CanvasGeometry.CreatePath(builder), Color.FromArgb((byte)alpha, c.R, c.G, c.B)); } //} }
/// <summary> /// Adds the Path Element to the Path. /// </summary> /// <param name="pathBuilder">CanvasPathBuilder object</param> /// <param name="currentPoint">The last active location in the Path before adding /// the Path Element</param> /// <param name="lastElement">The previous PathElement in the Path.</param> /// <param name="logger">For logging purpose. To log the set of CanvasPathBuilder /// commands, used for creating the CanvasGeometry, in string format.</param> /// <returns>The latest location in the Path after adding the Path Element</returns> public override Vector2 CreatePath(CanvasPathBuilder pathBuilder, Vector2 currentPoint, ref ICanvasPathElement lastElement, StringBuilder logger) { // Calculate coordinates var point = new Vector2(_x, _y); if (IsRelative) { point += currentPoint; } // Execute command pathBuilder.AddArc(point, _radiusX, _radiusY, _angle, _sweepDirection, _arcSize); // Log command logger?.Append($"{Indent}pathBuilder.AddArc(new Vector2({point.X}, {point.Y}), "); logger?.AppendLine($"{_radiusX}, {_radiusY}, {_angle}, {_sweepDirection}, {_arcSize});"); // Set Last Element lastElement = this; // Return current point return(point); }
static CanvasGeometry CreateTimeSegmentGeometry(CanvasDrawingSession ds, long updateCount, double updatesPerSecond) { double updates = (double)updateCount; double fractionSecond = (updates / updatesPerSecond) % 1.0; double fractionSecondAngle = 2 * Math.PI * fractionSecond; fractionSecondAngle *= -1; // increasing fractionSecond = clockwise = decreasing angle fractionSecondAngle += Math.PI; // we want fractionSecond = 0 to be up (not down) double angle = fractionSecondAngle % (2 * Math.PI); using (var builder = new CanvasPathBuilder(ds)) { builder.BeginFigure(new Vector2(center, center)); builder.AddLine(new Vector2(center, center - radius)); var endArcX = new Vector2(center + (float)Math.Sin(angle) * radius, center + (float)Math.Cos(angle) * radius); var arcSize = angle > 0 ? CanvasArcSize.Small : CanvasArcSize.Large; builder.AddArc(endArcX, radius, radius, 0, CanvasSweepDirection.Clockwise, arcSize); builder.EndFigure(CanvasFigureLoop.Closed); return(CanvasGeometry.CreatePath(builder)); } }
internal static CanvasGeometry GenerateGeometry(CanvasDevice device, Size size, CompositionPathInfo info, Vector2 offset) { // // |--LeftTop----------------------RightTop--| // | | // TopLeft TopRight // | | // | | // | | // | | // | | // | | // BottomLeft BottomRight // | | // |--LeftBottom----------------RightBottom--| // // compute the coordinates of the key points var leftTop = new Vector2(info.LeftTop.Single(), 0); var rightTop = new Vector2((size.Width - info.RightTop).Single(), 0); var topRight = new Vector2(size.Width.Single(), info.TopRight.Single()); var bottomRight = new Vector2(size.Width.Single(), (size.Height - info.BottomRight).Single()); var rightBottom = new Vector2((size.Width - info.RightBottom).Single(), size.Height.Single()); var leftBottom = new Vector2(info.LeftBottom.Single(), size.Height.Single()); var bottomLeft = new Vector2(0, (size.Height - info.BottomLeft).Single()); var topLeft = new Vector2(0, info.TopLeft.Single()); // check keypoints for overlap and resolve by partitioning corners according to // the percentage of each one. // top edge if (leftTop.X > rightTop.X) { var v = ((info.LeftTop) / (info.LeftTop + info.RightTop) * size.Width).Single(); leftTop.X = v; rightTop.X = v; } // right edge if (topRight.Y > bottomRight.Y) { var v = ((info.TopRight) / (info.TopRight + info.BottomRight) * size.Height).Single(); topRight.Y = v; bottomRight.Y = v; } // bottom edge if (leftBottom.X > rightBottom.X) { var v = ((info.LeftBottom) / (info.LeftBottom + info.RightBottom) * size.Width).Single(); rightBottom.X = v; leftBottom.X = v; } // left edge if (topLeft.Y > bottomLeft.Y) { var v = ((info.TopLeft) / (info.TopLeft + info.BottomLeft) * size.Height).Single(); bottomLeft.Y = v; topLeft.Y = v; } // Apply offset leftTop += offset; rightTop += offset; topRight += offset; bottomRight += offset; rightBottom += offset; leftBottom += offset; bottomLeft += offset; topLeft += offset; // create the border geometry var pathBuilder = new CanvasPathBuilder(device); // Begin path pathBuilder.BeginFigure(leftTop); // Top line pathBuilder.AddLine(rightTop); // Upper-right corners var radiusX = size.Width - rightTop.X; var radiusY = (double)topRight.Y; if (!radiusX.IsZero() || !radiusY.IsZero()) { pathBuilder.AddArc(topRight, radiusX.Single(), radiusY.Single(), (Math.PI / 2f).Single(), CanvasSweepDirection.Clockwise, CanvasArcSize.Small); } // Right line pathBuilder.AddLine(bottomRight); // Lower-right corners radiusX = size.Width - rightBottom.X; radiusY = size.Height - bottomRight.Y; if (!radiusX.IsZero() || !radiusY.IsZero()) { pathBuilder.AddArc(rightBottom, radiusX.Single(), radiusY.Single(), (Math.PI / 2f).Single(), CanvasSweepDirection.Clockwise, CanvasArcSize.Small); } // Bottom line pathBuilder.AddLine(leftBottom); // Lower-left corners radiusX = leftBottom.X; radiusY = size.Height - bottomLeft.Y; if (!radiusX.IsZero() || !radiusY.IsZero()) { pathBuilder.AddArc(bottomLeft, radiusX.Single(), radiusY.Single(), (Math.PI / 2f).Single(), CanvasSweepDirection.Clockwise, CanvasArcSize.Small); } // Left line pathBuilder.AddLine(topLeft); // Upper-left corners radiusX = leftTop.X; radiusY = topLeft.Y; if (!radiusX.IsZero() || !radiusY.IsZero()) { pathBuilder.AddArc(leftTop, radiusX.Single(), radiusY.Single(), (Math.PI / 2f).Single(), CanvasSweepDirection.Clockwise, CanvasArcSize.Small); } // End path pathBuilder.EndFigure(CanvasFigureLoop.Closed); return CanvasGeometry.CreatePath(pathBuilder); }
public static CanvasGeometry ToCanvasGeometry(this XPathGeometry pg, CanvasDrawingSession ds) { CanvasGeometry g; using (var builder = new CanvasPathBuilder(ds)) { if (pg.FillRule == XFillRule.EvenOdd) builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Alternate); else builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); foreach (var pf in pg.Figures) { builder.BeginFigure( (float)pf.StartPoint.X, (float)pf.StartPoint.Y, pf.IsFilled ? CanvasFigureFill.Default : CanvasFigureFill.DoesNotAffectFills); foreach (var segment in pf.Segments) { var options = CanvasFigureSegmentOptions.None; if (!segment.IsStroked) options |= CanvasFigureSegmentOptions.ForceUnstroked; if (segment.IsSmoothJoin) options |= CanvasFigureSegmentOptions.ForceRoundLineJoin; builder.SetSegmentOptions(options); if (segment is XArcSegment) { var arcSegment = segment as XArcSegment; builder.AddArc( new N.Vector2( (float)arcSegment.Point.X, (float)arcSegment.Point.Y), (float)(arcSegment.Size.Width / 2.0), (float)(arcSegment.Size.Height / 2.0), (float)arcSegment.RotationAngle, arcSegment.SweepDirection == XSweepDirection.Clockwise ? CanvasSweepDirection.Clockwise : CanvasSweepDirection.CounterClockwise, arcSegment.IsLargeArc ? CanvasArcSize.Large : CanvasArcSize.Small); } else if (segment is XBezierSegment) { var bezierSegment = segment as XBezierSegment; builder.AddCubicBezier( new N.Vector2( (float)bezierSegment.Point1.X, (float)bezierSegment.Point1.Y), new N.Vector2( (float)bezierSegment.Point2.X, (float)bezierSegment.Point2.Y), new N.Vector2( (float)bezierSegment.Point3.X, (float)bezierSegment.Point3.Y)); } else if (segment is XLineSegment) { var lineSegment = segment as XLineSegment; builder.AddLine( new N.Vector2( (float)lineSegment.Point.X, (float)lineSegment.Point.Y)); } else if (segment is XPolyBezierSegment) { var polyBezierSegment = segment as XPolyBezierSegment; if (polyBezierSegment.Points.Count >= 3) { builder.AddCubicBezier( new N.Vector2( (float)polyBezierSegment.Points[0].X, (float)polyBezierSegment.Points[0].Y), new N.Vector2( (float)polyBezierSegment.Points[1].X, (float)polyBezierSegment.Points[1].Y), new N.Vector2( (float)polyBezierSegment.Points[2].X, (float)polyBezierSegment.Points[2].Y)); } if (polyBezierSegment.Points.Count > 3 && polyBezierSegment.Points.Count % 3 == 0) { for (int i = 3; i < polyBezierSegment.Points.Count; i += 3) { builder.AddCubicBezier( new N.Vector2( (float)polyBezierSegment.Points[i].X, (float)polyBezierSegment.Points[i].Y), new N.Vector2( (float)polyBezierSegment.Points[i + 1].X, (float)polyBezierSegment.Points[i + 1].Y), new N.Vector2( (float)polyBezierSegment.Points[i + 2].X, (float)polyBezierSegment.Points[i + 2].Y)); } } } else if (segment is XPolyLineSegment) { var polyLineSegment = segment as XPolyLineSegment; if (polyLineSegment.Points.Count >= 1) { builder.AddLine( new N.Vector2( (float)polyLineSegment.Points[0].X, (float)polyLineSegment.Points[0].Y)); } if (polyLineSegment.Points.Count > 1) { for (int i = 1; i < polyLineSegment.Points.Count; i++) { builder.AddLine( new N.Vector2( (float)polyLineSegment.Points[i].X, (float)polyLineSegment.Points[i].Y)); } } } else if (segment is XPolyQuadraticBezierSegment) { var polyQuadraticSegment = segment as XPolyQuadraticBezierSegment; if (polyQuadraticSegment.Points.Count >= 2) { builder.AddQuadraticBezier( new N.Vector2( (float)polyQuadraticSegment.Points[0].X, (float)polyQuadraticSegment.Points[0].Y), new N.Vector2( (float)polyQuadraticSegment.Points[1].X, (float)polyQuadraticSegment.Points[1].Y)); } if (polyQuadraticSegment.Points.Count > 2 && polyQuadraticSegment.Points.Count % 2 == 0) { for (int i = 3; i < polyQuadraticSegment.Points.Count; i += 3) { builder.AddQuadraticBezier( new N.Vector2( (float)polyQuadraticSegment.Points[i].X, (float)polyQuadraticSegment.Points[i].Y), new N.Vector2( (float)polyQuadraticSegment.Points[i + 1].X, (float)polyQuadraticSegment.Points[i + 1].Y)); } } } else if (segment is XQuadraticBezierSegment) { var qbezierSegment = segment as XQuadraticBezierSegment; builder.AddQuadraticBezier( new N.Vector2( (float)qbezierSegment.Point1.X, (float)qbezierSegment.Point1.Y), new N.Vector2( (float)qbezierSegment.Point2.X, (float)qbezierSegment.Point2.Y)); } else { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); } } builder.EndFigure(pf.IsClosed ? CanvasFigureLoop.Closed : CanvasFigureLoop.Open); } g = CanvasGeometry.CreatePath(builder); } return g; }
//private static Bitmap _textBMP = new Bitmap(2, 2); //private static Graphics _g = Graphics.FromImage(_textBMP); //private static Matrix _identityMatrix = new Matrix(); //private static int _fontSize = RS.getModifierFontSize(); //private static FontStyle _fontStyle = RS.getModifierFontStyle(); //private static String _fontName = RS.getModifierFontName(); //private static int _modifierFontHeight = ShapeUtilities.round(_g.MeasureString("Hj", RS.getLabelFont()).Height); //private static Font _modifierFont = RS.getLabelFont(); /// <summary> /// /// </summary> /// <param name="symbolID"></param> /// <param name="msb"></param> /// <param name="modifiers"></param> /// <param name="attributes"></param> /// <returns></returns> public static ImageInfo ProcessUnitDisplayModifiers(String symbolID, ImageInfo ii, Dictionary<int, String> modifiers, Dictionary<int, String> attributes, Boolean hasTextModifiers, CanvasDevice device) { ImageInfo newii = null; Rect symbolBounds = ShapeUtilities.clone(ii.getSymbolBounds()); Rect imageBounds = ShapeUtilities.clone(ii.getCanvasRenderTarget().GetBounds(device)); Point centerPoint = ShapeUtilities.clone(ii.getAnchorPoint()); TextInfo tiEchelon = null; TextInfo tiAM = null; Rect echelonBounds = Rect.Empty; Rect amBounds = Rect.Empty; Color textColor = Colors.Black; Color textBackgroundColor = Colors.Transparent; int buffer = 0; //ctx = null; int offsetX = 0; int offsetY = 0; int symStd = RS.getSymbologyStandard(); CanvasTextFormat font = RS.getLabelFont(); /*Pen mobilityPen = new Pen(Colors.Black, 2f); mobilityPen.MiterLimit = 2;//*/ try { if(device == null) { device = CanvasDevice.GetSharedDevice(); } if (attributes.ContainsKey(MilStdAttributes.SymbologyStandard)) { symStd = Convert.ToInt16(attributes[MilStdAttributes.SymbologyStandard]); } if (attributes.ContainsKey(MilStdAttributes.TextColor)) { textColor = SymbolUtilities.getColorFromHexString(attributes[MilStdAttributes.TextColor]); } if (attributes.ContainsKey(MilStdAttributes.TextBackgroundColor)) { textBackgroundColor = SymbolUtilities.getColorFromHexString(attributes[MilStdAttributes.TextBackgroundColor]); } #region Build Mobility Modifiers Rect mobilityBounds = Rect.Empty; List<CanvasGeometry> shapes = new List<CanvasGeometry>(); CanvasPathBuilder mobilityPath = null; CanvasPathBuilder mobilityPathFill = null; CanvasGeometry cgMobilityPath = null; CanvasGeometry cgMobilityPathFill = null; if (symbolID[10] == ('M') || symbolID[10] == ('N')) { //Draw Mobility int fifth = (int)((symbolBounds.Width * 0.2) + 0.5f); mobilityPath = new CanvasPathBuilder(device); int x = 0; int y = 0; int centerX = 0; int bottomY = 0; int height = 0; int width = 0; int middleY = 0; int wheelOffset = 2; int wheelSize = fifth;//10; int rrHeight = fifth;//10; int rrArcWidth = (int)((fifth * 1.5) + 0.5f);//16; String mobility = symbolID.Substring(10, 2); x = (int)symbolBounds.Left; y = (int)symbolBounds.Top; height = (int)(symbolBounds.Height); width = (int)(symbolBounds.Width); bottomY = y + height + 2; if (symbolID[10] == ('M')) { bottomY = y + height + 2; //wheelSize = width / 7; //rrHeight = width / 7; //rrArcWidth = width / 7; if (mobility.Equals("MO")) { //line mobilityPath.BeginFigure(x, bottomY); mobilityPath.AddLine(x + width, bottomY); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddLine(x, bottomY, x + width, bottomY); //left circle mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device,new Vector2(x, bottomY + wheelOffset),wheelSize,wheelSize)); //mobilityPath.AddEllipse(x, bottomY + wheelOffset, wheelSize, wheelSize); //right circle mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new System.Numerics.Vector2(x + width - wheelSize, bottomY + wheelOffset), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x + width - wheelSize, bottomY + wheelOffset, wheelSize, wheelSize); } else if (mobility.Equals("MP")) { //line mobilityPath.BeginFigure(x, bottomY); mobilityPath.AddLine(x + width, bottomY); mobilityPath.EndFigure(CanvasFigureLoop.Open); //PathUtilties.AddLine(mobilityPath, x, bottomY, x + width, bottomY); //left circle mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x, bottomY + wheelOffset), wheelSize, wheelSize)); //right circle mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x + width - wheelSize, bottomY + wheelOffset), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x + width - wheelSize, bottomY + wheelOffset, wheelSize, wheelSize); //center wheel mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x + (width / 2) - (wheelSize / 2), bottomY + wheelOffset), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x + (width / 2) - (wheelSize / 2), bottomY + wheelOffset, wheelSize, wheelSize); } else if (mobility.Equals("MQ")) { //round Rect mobilityPath.AddGeometry(CanvasGeometry.CreateRoundedRectangle(device, x, bottomY, width, rrHeight, rrHeight / 2, rrHeight / 2)); //mobilityPath.AddPath(ShapeUtilities.createRoundedRect(new Rect(x, bottomY, width, rrHeight), rrHeight / 2), false); } else if (mobility.Equals("MR")) { //round Rect mobilityPath.AddGeometry(CanvasGeometry.CreateRoundedRectangle(device, x, bottomY, width, rrHeight, rrHeight / 2, rrHeight / 2)); //mobilityPath.AddPath(ShapeUtilities.createRoundedRect(new Rect(x, bottomY, width, rrHeight), wheelSize / 2), false); //left circle mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x - wheelSize - wheelSize, bottomY), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x - wheelSize - wheelSize, bottomY, wheelSize, wheelSize); } else if (mobility.Equals("MS")) { //line mobilityPath.BeginFigure(x + wheelSize, bottomY + (wheelSize / 2)); mobilityPath.AddLine(x + width - wheelSize, bottomY + (wheelSize / 2)); mobilityPath.EndFigure(CanvasFigureLoop.Open); /*mobilityPath.AddLine(x + wheelSize, bottomY + (wheelSize / 2), x + width - wheelSize, bottomY + (wheelSize / 2));//*/ //left circle mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x, bottomY), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x, bottomY, wheelSize, wheelSize); //right circle mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x + width - wheelSize, bottomY), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x + width - wheelSize, bottomY, wheelSize, wheelSize); } else if (mobility.Equals("MT")) { //line mobilityPath.BeginFigure(x, bottomY); mobilityPath.AddLine(x + width, bottomY); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddLine(x, bottomY, x + width, bottomY); //left circle mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x + wheelSize, bottomY + wheelOffset), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x + wheelSize, bottomY + wheelOffset, wheelSize, wheelSize); //left circle2 mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x, bottomY + wheelOffset), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x, bottomY + wheelOffset, wheelSize, wheelSize); //right circle mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x + width - wheelSize, bottomY + wheelOffset), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x + width - wheelSize, bottomY + wheelOffset, wheelSize, wheelSize); //right circle2 mobilityPath.AddGeometry(CanvasGeometry.CreateEllipse(device, new Vector2(x + width - wheelSize - wheelSize, bottomY + wheelOffset), wheelSize, wheelSize)); //mobilityPath.AddEllipse(x + width - wheelSize - wheelSize, bottomY + wheelOffset, wheelSize, wheelSize); } else if (mobility.Equals("MU")) { float halfWidth = (rrArcWidth * 0.5f); mobilityPath.BeginFigure(x, bottomY); mobilityPath.AddLine(x + halfWidth, bottomY + halfWidth); mobilityPath.AddLine(x + width, bottomY + halfWidth); mobilityPath.EndFigure(CanvasFigureLoop.Open); /* mobilityPath.AddLine(x, bottomY, x + halfWidth, bottomY + halfWidth); mobilityPath.AddLine(x + halfWidth, bottomY + halfWidth, x + width, bottomY + halfWidth);//*/ } else if (mobility.Equals("MV")) { mobilityPath.BeginFigure(x, bottomY); mobilityPath.AddCubicBezier(new Vector2(x, bottomY), new Vector2(x - rrHeight, bottomY + rrHeight / 2), new Vector2(x, bottomY + rrHeight)); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddBezier(x, bottomY, x, bottomY, x - rrHeight, bottomY + rrHeight / 2, x, bottomY + rrHeight); mobilityPath.BeginFigure(x, bottomY + rrHeight); mobilityPath.AddLine(x + width, bottomY + rrHeight); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddLine(x, bottomY + rrHeight, x + width, bottomY + rrHeight); mobilityPath.BeginFigure(x + width, bottomY + rrHeight); mobilityPath.AddCubicBezier(new Vector2(x + width, bottomY + rrHeight), new Vector2(x + width + rrHeight, bottomY + rrHeight / 2), new Vector2(x + width, bottomY)); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddBezier(x + width, bottomY + rrHeight, x + width, bottomY + rrHeight, x + width + rrHeight, bottomY + rrHeight / 2, x + width, bottomY); } else if (mobility.Equals("MW")) { centerX = (int)((symbolBounds.X + (symbolBounds.Width / 2)) + 0.5); int angleWidth = rrHeight / 2; mobilityPath.BeginFigure(centerX, bottomY + rrHeight + 2); mobilityPath.AddLine(centerX - angleWidth, bottomY); mobilityPath.AddLine(centerX - angleWidth * 2, bottomY + rrHeight + 2); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddLine(centerX, bottomY + rrHeight + 2, centerX - angleWidth, bottomY); //mobilityPath.AddLine(centerX - angleWidth, bottomY, centerX - angleWidth * 2, bottomY + rrHeight + 2); mobilityPath.BeginFigure(centerX, bottomY + rrHeight + 2); mobilityPath.AddLine(centerX + angleWidth, bottomY); mobilityPath.AddLine(centerX + angleWidth * 2, bottomY + rrHeight + 2); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.StartFigure(); //mobilityPath.AddLine(centerX, bottomY + rrHeight + 2, centerX + angleWidth, bottomY); //mobilityPath.AddLine(centerX + angleWidth, bottomY, centerX + angleWidth * 2, bottomY + rrHeight + 2); } else if (mobility.Equals("MX")) { centerX = (int)((symbolBounds.X + (symbolBounds.Width / 2)) + 0.5); mobilityPath.BeginFigure(x + width, bottomY); mobilityPath.AddLine(x, bottomY); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddLine(x + width, bottomY, x, bottomY); float quarterX = (centerX - x) / 2; ////var quarterY = (((bottomY + rrHeight) - bottomY)/2); mobilityPath.BeginFigure(x, bottomY); mobilityPath.AddCubicBezier(new Vector2(x + quarterX, bottomY + rrHeight), new Vector2(centerX + quarterX, bottomY + rrHeight), new Vector2(x + width, bottomY)); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddBezier(x, bottomY, x + quarterX, bottomY + rrHeight, centerX + quarterX, bottomY + rrHeight, x + width, bottomY); } else if (mobility.Equals("MY")) { float incrementX = width / 7f; x = (int)Math.Floor(symbolBounds.X); float r = incrementX; //mobilityPath.arcTo(oval, sAngle, sAngle, moveTo); mobilityPath.AddArc(new Vector2(x, bottomY), r, r, 180, 180); mobilityPath.AddArc(new Vector2(x + incrementX, bottomY), r, r, 180, -180); mobilityPath.AddArc(new Vector2(x + incrementX * 2, bottomY), r, r, 180, 180); mobilityPath.AddArc(new Vector2(x + incrementX * 3, bottomY), r, r, 180, -180); mobilityPath.AddArc(new Vector2(x + incrementX * 4, bottomY), r, r, 180, 180); mobilityPath.AddArc(new Vector2(x + incrementX * 5, bottomY), r, r, 180, -180); mobilityPath.AddArc(new Vector2(x + incrementX * 6, bottomY), r, r, 180, 180); } } //Draw Towed Array Sonar else if (symbolID[10] == ('N')) { int boxHeight = (int)((rrHeight * 0.8f) + 0.5f); bottomY = y + height + (boxHeight / 7); mobilityPathFill = new CanvasPathBuilder(device); offsetY = ShapeUtilities.round(boxHeight / 6);//1; centerX = (int)((symbolBounds.X + (symbolBounds.Width / 2)) + 0.5); int squareOffset = (int)((boxHeight * 0.5f) + 0.5); middleY = ((boxHeight / 2) + bottomY) + offsetY;//+1 for offset from symbol if (symbolID.Substring(10, 2).Equals("NS")) { //subtract 0.5 becase lines 1 pixel thick get aliased into //a line two pixels wide. //line mobilityPath.BeginFigure(centerX - 1, bottomY - 1); mobilityPath.AddLine(centerX - 1, bottomY + boxHeight + offsetY + 2); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddLine(centerX - 1, bottomY - 1, centerX - 1, bottomY + boxHeight + offsetY + 2); //line mobilityPath.BeginFigure(x, middleY); mobilityPath.AddLine(x + width, middleY); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.StartFigure(); //mobilityPath.AddLine(x, middleY, x + width, middleY); //square mobilityPathFill.AddGeometry(CanvasGeometry.CreateRectangle(device, x - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //mobilityPathFill.AddRect(new Rect(x - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //square mobilityPathFill.AddGeometry(CanvasGeometry.CreateRectangle(device, centerX - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //mobilityPathFill.AddRect(new Rect(centerX - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //square mobilityPathFill.AddGeometry(CanvasGeometry.CreateRectangle(device, x + width - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //mobilityPathFill.AddRect(new Rect(x + width - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); } else if (symbolID.Substring(10, 2).Equals("NL")) { int leftX = x + (centerX - x) / 2, rightX = centerX + (x + width - centerX) / 2; //line vertical left mobilityPath.BeginFigure(leftX, bottomY - 1); mobilityPath.AddLine(leftX, bottomY + offsetY + boxHeight + offsetY + 2); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.AddLine(leftX, bottomY - 1, leftX, bottomY + offsetY + boxHeight + offsetY + 2); //line vertical right mobilityPath.BeginFigure(rightX, bottomY - 1); mobilityPath.AddLine(rightX, bottomY + offsetY + boxHeight + offsetY + 2); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.StartFigure(); //mobilityPath.AddLine(rightX, bottomY - 1, rightX, bottomY + offsetY + boxHeight + offsetY + 2); //line horizontal mobilityPath.BeginFigure(x, middleY); mobilityPath.AddLine(x + width, middleY); mobilityPath.EndFigure(CanvasFigureLoop.Open); //mobilityPath.StartFigure(); //mobilityPath.AddLine(x, middleY, x + width, middleY); //square left mobilityPathFill.AddGeometry(CanvasGeometry.CreateRectangle(device, x - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //mobilityPathFill.AddRect(new Rect(x - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //square middle mobilityPathFill.AddGeometry(CanvasGeometry.CreateRectangle(device, centerX - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //mobilityPathFill.AddRect(new Rect(centerX - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //square right mobilityPathFill.AddGeometry(CanvasGeometry.CreateRectangle(device, x + width - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //mobilityPathFill.AddRect(new Rect(x + width - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //square middle left mobilityPathFill.AddGeometry(CanvasGeometry.CreateRectangle(device, leftX - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //mobilityPathFill.AddRect(new Rect(leftX - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //square middle right mobilityPathFill.AddGeometry(CanvasGeometry.CreateRectangle(device, rightX - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); //mobilityPathFill.AddRect(new Rect(rightX - squareOffset, bottomY + offsetY, boxHeight, boxHeight)); } } //get mobility bounds if (mobilityPath != null) { //build mobility bounds cgMobilityPath = CanvasGeometry.CreatePath(mobilityPath); mobilityBounds = cgMobilityPath.ComputeBounds(); Rect mobilityFillBounds = new Rect(); if (mobilityPathFill != null) { cgMobilityPathFill = CanvasGeometry.CreatePath(mobilityPathFill); mobilityFillBounds = cgMobilityPathFill.ComputeBounds(); } //grow because we use a line thickness of 2. mobilityBounds = new Rect(mobilityBounds.X - 1, mobilityBounds.Y - 1, mobilityBounds.Width+2, mobilityBounds.Height+2); //mobilityBounds.Inflate(1f, 1f); imageBounds = ShapeUtilities.union(imageBounds, mobilityBounds); } } #endregion #region Build Echelon //Draw Echelon String strEchelon = SymbolUtilities.getEchelon(symbolID);//symbolID.substring(11, 12); if (strEchelon != null) { strEchelon = SymbolUtilities.getEchelonText(strEchelon); } if (strEchelon != null && SymbolUtilities.hasInstallationModifier(symbolID) == false && SymbolUtilities.canUnitHaveModifier(symbolID, ModifiersUnits.B_ECHELON)) { if (strEchelon != null) { int outlineOffset = RS.getTextOutlineWidth(); //tiEchelon = new TextInfo(strEchelon, 0, 0, font, _g); tiEchelon = new TextInfo(device, strEchelon); echelonBounds = tiEchelon.getTextBounds(); int y = (int)Math.Round(symbolBounds.Top - echelonBounds.Height); int x = (int)Math.Round(symbolBounds.Left + (symbolBounds.Width / 2) - (echelonBounds.Width / 2)); tiEchelon.setLocation(x, y); echelonBounds = tiEchelon.getTextBounds(); //There will never be lowercase characters in an echelon so trim that fat. //Remove the descent from the bounding box. //tiEchelon.getTextOutlineBounds();//.shiftBR(0,ShapeUtilities.round(-(echelonBounds.Height*0.3))); //make echelon bounds a little more spacious for things like nearby labels and Task Force. //echelonBounds.Inflate(outlineOffset, outlineOffset);// ShapeUtilities.grow(echelonBounds, outlineOffset); //tiEchelon.getTextOutlineBounds(); // RectUtilities.shift(echelonBounds, x, -outlineOffset); //echelonBounds.shift(0,-outlineOffset);// - ShapeUtilities.round(echelonOffset/2)); //tiEchelon.setLocation(x, y - outlineOffset); imageBounds = ShapeUtilities.union(imageBounds, echelonBounds); } } #endregion #region Build Affiliation Modifier String affiliationModifier = null; if (RS.getDrawAffiliationModifierAsLabel() == false) { affiliationModifier = SymbolUtilities.getUnitAffiliationModifier(symbolID, symStd); } if (affiliationModifier != null) { int amOffset = 2; int outlineOffset = RS.getTextOutlineWidth(); tiAM = new TextInfo(device,affiliationModifier); amBounds = tiAM.getTextBounds(); double x, y; if (echelonBounds != Rect.Empty && ((echelonBounds.Left + echelonBounds.Width > symbolBounds.Left + symbolBounds.Width))) { y = (symbolBounds.Top - amOffset); x = echelonBounds.Left + echelonBounds.Width; } else { y = (symbolBounds.Top - amOffset); x = (symbolBounds.Left + symbolBounds.Width); } tiAM.setLocation(x, y); //adjust for outline. amBounds = tiAM.getTextBoundsWithOutline(); tiAM.shift(-outlineOffset, -outlineOffset); imageBounds = ShapeUtilities.union(imageBounds, amBounds); } #endregion #region Build Task Force Rect tfBounds = Rect.Empty; Rect tfRect = Rect.Empty; if (SymbolUtilities.isTaskForce(symbolID)) { if (echelonBounds != Rect.Empty) { tfRect = new Rect(echelonBounds.X, echelonBounds.Y, echelonBounds.Width, symbolBounds.Y - echelonBounds.Y); tfBounds = ShapeUtilities.clone(tfRect); } else { double height = (symbolBounds.Height / 4); double width = (symbolBounds.Width / 3); tfRect = new Rect(symbolBounds.Left + width, symbolBounds.Top - height, width, height); tfBounds = new Rect(tfRect.Left + -1, tfRect.Top - 1, tfRect.Width + 2, tfRect.Height + 2); } imageBounds = ShapeUtilities.union(imageBounds, tfBounds); } #endregion #region Build Feint Dummy Indicator Rect fdiBounds = Rect.Empty; Point fdiTop = new Point();// Point.Empty; Point fdiLeft = new Point(); Point fdiRight = new Point(); if (SymbolUtilities.isFeintDummy(symbolID) || SymbolUtilities.isFeintDummyInstallation(symbolID)) { //create feint indicator /\ fdiLeft = new Point(symbolBounds.Left, symbolBounds.Top); fdiRight = new Point((symbolBounds.Left + symbolBounds.Width), symbolBounds.Top); char affiliation = symbolID[1]; if (affiliation == ('F') || affiliation == ('A') || affiliation == ('D') || affiliation == ('M') || affiliation == ('J') || affiliation == ('K')) { fdiTop = new Point((ShapeUtilities.getCenterX(symbolBounds)), ShapeUtilities.round(symbolBounds.Top - (symbolBounds.Height * .75f))); } else { fdiTop = new Point((ShapeUtilities.getCenterX(symbolBounds)), ShapeUtilities.round(symbolBounds.Top - (symbolBounds.Height * .54f))); } fdiBounds = new Rect(fdiLeft.X, fdiLeft.Y, 1, 1); fdiBounds = ShapeUtilities.union(fdiBounds, fdiTop); fdiBounds = ShapeUtilities.union(fdiBounds, fdiRight); if (echelonBounds != null) { double shiftY = (symbolBounds.Top - echelonBounds.Height - 2); fdiLeft.Y = fdiLeft.Y + shiftY; fdiTop.Y = fdiLeft.Y + shiftY; fdiRight.Y = fdiLeft.Y + shiftY; fdiBounds.Y = fdiLeft.Y + shiftY; /*(fdiLeft.Offset(0, shiftY); fdiTop.Offset(0, shiftY); fdiRight.Offset(0, shiftY); fdiBounds.Offset(0, shiftY);//*/ } imageBounds = ShapeUtilities.union(imageBounds, fdiBounds); } #endregion #region Build Installation Rect instRect = Rect.Empty; Rect instBounds = Rect.Empty; if (SymbolUtilities.hasInstallationModifier(symbolID)) {//the actual installation symbols have the modifier //built in. everything else, we have to draw it. // ////get indicator dimensions//////////////////////////////// int width; int height; char affiliation = SymbolUtilities.getAffiliation(symbolID); if (affiliation == 'F' || affiliation == 'A' || affiliation == 'D' || affiliation == 'M' || affiliation == 'J' || affiliation == 'K') { //4th height, 3rd width height = ShapeUtilities.round(symbolBounds.Height / 4); width = ShapeUtilities.round(symbolBounds.Width / 3); } else if (affiliation == 'H' || affiliation == 'S')//hostile,suspect { //6th height, 3rd width height = ShapeUtilities.round(symbolBounds.Height / 6); width = ShapeUtilities.round(symbolBounds.Width / 3); } else if (affiliation == 'N' || affiliation == 'L')//neutral,exercise neutral { //6th height, 3rd width height = ShapeUtilities.round(symbolBounds.Height / 6); width = ShapeUtilities.round(symbolBounds.Width / 3); } else if (affiliation == 'P' || affiliation == 'U' || affiliation == 'G' || affiliation == 'W') { //6th height, 3rd width height = ShapeUtilities.round(symbolBounds.Height / 6); width = ShapeUtilities.round(symbolBounds.Width / 3); } else { //6th height, 3rd width height = ShapeUtilities.round(symbolBounds.Height / 6); width = ShapeUtilities.round(symbolBounds.Width / 3); } // if(width * 3 < symbolBounds.Width) // width++; //set installation position///////////////////////////////// //set position of indicator if (affiliation == 'F' || affiliation == 'A' || affiliation == 'D' || affiliation == 'M' || affiliation == 'J' || affiliation == 'K' || affiliation == 'N' || affiliation == 'L') { instRect = new Rect((int)(symbolBounds.Left + width), (int)(symbolBounds.Top - height), width, height); } else if (affiliation == 'H' || affiliation == 'S')//hostile,suspect { instRect = new Rect((int)symbolBounds.Left + width, ShapeUtilities.round(symbolBounds.Top - (height * 0.15f)), width, height); } else if (affiliation == 'P' || affiliation == 'U' || affiliation == 'G' || affiliation == 'W') { instRect = new Rect((int)symbolBounds.Left + width, ShapeUtilities.round(symbolBounds.Top - (height * 0.3f)), width, height); } else { instRect = new Rect((int)symbolBounds.Left + width, ShapeUtilities.round(symbolBounds.Top - (height * 0.3f)), width, height); } /*instRect = new SO.Rect(symbolBounds.Left + width, symbolBounds.Top - height, width, height);//*/ //generate installation bounds////////////////////////////// instBounds = new Rect(instRect.Left + -1, instRect.Top - 1, instRect.Width + 2, instRect.Height + 2); imageBounds = ShapeUtilities.union(imageBounds, instBounds); } #endregion #region Build HQ Staff Point pt1HQ = new Point(); Point pt2HQ = new Point(); Rect hqBounds = Rect.Empty; //Draw HQ Staff if (SymbolUtilities.isHQ(symbolID)) { char affiliation = symbolID[1]; //get points for the HQ staff if (affiliation == ('F') || affiliation == ('A') || affiliation == ('D') || affiliation == ('M') || affiliation == ('J') || affiliation == ('K') || affiliation == ('N') || affiliation == ('L')) { pt1HQ = new Point((int)symbolBounds.Left + 1, (int)(symbolBounds.Top + symbolBounds.Height - 1)); pt2HQ = new Point((int)pt1HQ.X, (int)(pt1HQ.Y + symbolBounds.Height)); } else { pt1HQ = new Point((int)symbolBounds.Left + 1, (int)(symbolBounds.Top + (symbolBounds.Height / 2))); pt2HQ = new Point((int)pt1HQ.X, (int)(pt1HQ.Y + symbolBounds.Height)); } //create bounding Rect for HQ staff. hqBounds = new Rect(pt1HQ.X, pt1HQ.Y, 2, pt2HQ.Y - pt1HQ.Y); //adjust the image bounds accordingly. imageBounds.Height = imageBounds.Height + (pt2HQ.Y - imageBounds.Bottom); imageBounds = ShapeUtilities.union(imageBounds, hqBounds); //adjust symbol center centerPoint.X = pt2HQ.X; centerPoint.Y = pt2HQ.Y; } #endregion #region Build DOM Arrow Point[] domPoints = null; Rect domBounds = Rect.Empty; if (modifiers != null && modifiers.ContainsKey(ModifiersUnits.Q_DIRECTION_OF_MOVEMENT)) { String strQ = modifiers[ModifiersUnits.Q_DIRECTION_OF_MOVEMENT]; if (strQ != null && SymbolUtilities.isNumber(strQ)) { float q = (float)Convert.ToDouble(strQ); Boolean isY = (modifiers.ContainsKey(ModifiersUnits.Y_LOCATION)); TextInfo tiY = new TextInfo(device, "Y"); domPoints = createDOMArrowPoints(symbolID, symbolBounds, centerPoint, q, tiY.getTextBounds().Height); domBounds = new Rect(domPoints[0].X, domPoints[0].Y, 1, 1); Point temp = new Point(); for (int i = 1; i < 6; i++) { temp = domPoints[i]; if (temp.X != 0 && temp.Y != 0) { domBounds = ShapeUtilities.union(domBounds, temp); } } domBounds = ShapeUtilities.inflate(domBounds,1, 1); imageBounds = ShapeUtilities.union(imageBounds, domBounds); } } #endregion #region Build Operational Condition Indicator Rect ociBounds = Rect.Empty; int ociOffset = 4; if (mobilityBounds != Rect.Empty) { ociOffset = ShapeUtilities.round(mobilityBounds.Height); } Rect ociShape = processOperationalConditionIndicator(symbolID, symbolBounds, ociOffset); if (ociShape != Rect.Empty) { Rect temp = ShapeUtilities.clone(ociShape); temp = ShapeUtilities.inflate(temp,2, 3); ociBounds = temp; imageBounds = ShapeUtilities.union(imageBounds, ociBounds); } #endregion #region Shift Modifiers if (imageBounds.Left < 0 || imageBounds.Top < 0) { double shiftX = Math.Abs(imageBounds.Left); double shiftY = Math.Abs(imageBounds.Top); if (hqBounds != Rect.Empty) { pt1HQ = ShapeUtilities.offset(pt1HQ,shiftX, shiftY); pt2HQ = ShapeUtilities.offset(pt2HQ, shiftX, shiftY); } if (echelonBounds != Rect.Empty) { tiEchelon.setLocation(tiEchelon.getLocation().X + shiftX, tiEchelon.getLocation().Y + shiftY); } if (amBounds != Rect.Empty) { tiAM.setLocation(tiAM.getLocation().X + shiftX, tiAM.getLocation().Y + shiftY); } if (tfBounds != Rect.Empty) { tfRect = ShapeUtilities.offset(tfRect, shiftX, shiftY); tfBounds = ShapeUtilities.offset(tfBounds,shiftX, shiftY); } if (instBounds != Rect.Empty) { instRect = ShapeUtilities.offset(instRect,shiftX, shiftY); instBounds = ShapeUtilities.offset(instBounds,shiftX, shiftY); } if (fdiBounds != Rect.Empty) { fdiBounds = ShapeUtilities.offset(fdiBounds,shiftX, shiftY); fdiLeft = ShapeUtilities.offset(fdiLeft, shiftX, shiftY); fdiTop = ShapeUtilities.offset(fdiTop, shiftX, shiftY); fdiRight = ShapeUtilities.offset(fdiRight,shiftX, shiftY); } if (ociBounds != Rect.Empty) { ociBounds = ShapeUtilities.offset(ociBounds,shiftX, shiftY); ociShape = ShapeUtilities.offset(ociShape,shiftX, shiftY); } if (domBounds != Rect.Empty) { for (int i = 0; i < 6; i++) { Point temp = domPoints[i]; if (temp.X != 0 && temp.Y != 0) temp = ShapeUtilities.offset(temp,shiftX, shiftY); domPoints[i] = temp; } domBounds = ShapeUtilities.offset(domBounds,shiftX, shiftY); } if (mobilityBounds != Rect.Empty) { Matrix3x2 translation = Matrix3x2.CreateTranslation((float)shiftX, (float)shiftY); //shift mobility points cgMobilityPath.Transform(translation); if(cgMobilityPathFill != null) { cgMobilityPathFill.Transform(translation); } mobilityBounds = ShapeUtilities.offset(mobilityBounds,shiftX, shiftY); } centerPoint = ShapeUtilities.offset(centerPoint,shiftX, shiftY); symbolBounds = ShapeUtilities.offset(symbolBounds, shiftX, shiftY); imageBounds = ShapeUtilities.offset(imageBounds, shiftX, shiftY); } #endregion #region Draw Modifiers CanvasRenderTarget bmp = new CanvasRenderTarget(device, (float)imageBounds.Width, (float)imageBounds.Height, 96); //Bitmap bmp = new Bitmap(imageBounds.Width, imageBounds.Height); //Graphics g = Graphics.FromImage(bmp); //render//////////////////////////////////////////////////////// using (CanvasDrawingSession ds = bmp.CreateDrawingSession()) { ds.Antialiasing = CanvasAntialiasing.Antialiased; ds.TextAntialiasing = CanvasTextAntialiasing.ClearType; //Pen pen = new Pen(Color.Black, 2f); //g.SmoothingMode = SmoothingMode.AntiAlias; if (hqBounds != Rect.Empty) { ds.DrawLine(pt1HQ.ToVector2(), pt2HQ.ToVector2(), Colors.Black, 2f); //g.DrawLine(pen, pt1HQ.X, pt1HQ.Y, pt2HQ.X, pt2HQ.Y); } if (tfBounds != Rect.Empty) { ds.DrawRectangle(tfRect, Colors.Black,2f); //g.DrawRect(pen, tfRect); } if (instBounds != Rect.Empty) { ds.FillRectangle(tfRect,Colors.Black); //g.FillRect(Brushes.Black, instRect); } if (echelonBounds != Rect.Empty) { /*TextInfo[] aTiEchelon = { tiEchelon }; renderText(g, aTiEchelon, textColor, textBackgroundColor);//*/ tiEchelon.drawText(ds, textColor); echelonBounds = Rect.Empty; tiEchelon = null; } if (amBounds != Rect.Empty) { /*TextInfo[] aTiAM = { tiAM }; renderText(g, aTiAM, textColor, textBackgroundColor);//*/ tiAM.drawText(ds, textColor); amBounds = Rect.Empty; tiAM = null; } if (fdiBounds != Rect.Empty) { CanvasStrokeStyle style = new CanvasStrokeStyle(); if (symbolBounds.Width > 19) { style.CustomDashStyle = new float[] { 6f, 4f }; } else { style.CustomDashStyle = new float[] { 5f, 3f }; } style.LineJoin = CanvasLineJoin.Miter; style.MiterLimit = 3; //pen.LineJoin = LineJoin.Miter; //pen.MiterLimit = 3; //pen.Width = 2; //GraphicsPath fdiPath = new GraphicsPath(); //fdiPath.AddLine(fdiLeft.X, fdiLeft.Y, fdiTop.X, fdiTop.Y); //fdiPath.AddLine(fdiTop.X, fdiTop.Y, fdiRight.X, fdiRight.Y); ds.DrawLine(fdiLeft.ToVector2(), fdiTop.ToVector2(), Colors.Black, 2f); //g.DrawPath(pen, fdiPath); fdiBounds = Rect.Empty; } if (mobilityBounds != Rect.Empty) { //ctx.lineCap = "butt"; //ctx.lineJoin = "miter"; if (symbolID[10] == ('N')) { ds.Antialiasing = CanvasAntialiasing.Aliased; //mobilityPaint.setAntiAlias(false); //g.SmoothingMode = SmoothingMode.None; } ds.DrawGeometry(cgMobilityPath, Colors.Black, 2f); // g.DrawPath(mobilityPen, mobilityPath); if (cgMobilityPathFill != null) { ds.FillGeometry(cgMobilityPathFill,Colors.Black); //g.FillPath(Brushes.Black, mobilityPathFill); } mobilityBounds = Rect.Empty; } if (ociBounds != Rect.Empty) { Color statusColor = Colors.Black; char status = symbolID[3]; if (status == ('C'))//Fully Capable { statusColor = Colors.Green; } else if (status == ('D'))//Damage { statusColor = Colors.Yellow; } else if (status == ('X')) { statusColor = Colors.Red; } else if (status == ('F'))//full to capacity(hospital) { statusColor = Colors.Blue; }; ds.FillRectangle(ociBounds, Colors.Black); //g.FillRect(Brushes.Black, ociBounds); ds.FillRectangle(ociShape, statusColor); //g.FillRect(new SolidBrush(statusColor), ociShape); ociBounds = Rect.Empty; ociShape = Rect.Empty; } //draw original icon. //ctx.drawBitmap(ii.getImage(), null, symbolBounds, null); ds.DrawImage(ii.getCanvasRenderTarget(), (float)symbolBounds.X, (float)symbolBounds.Y); //g.DrawImageUnscaled(ii.getBitmap(), symbolBounds.X, symbolBounds.Y); if (domBounds != Rect.Empty) { drawDOMArrow(device, ds, domPoints); domBounds = Rect.Empty; domPoints = null; ; } #endregion } /*GraphicsUnit pixel = GraphicsUnit.Pixel; Rect outline = ShapeUtilities.cloneToRect(bmp.GetBounds(ref pixel)); outline.Width = outline.Width - 1; outline.Height = outline.Height - 1; g.DrawRect(Pens.Red, outline);//*/ newii = new ImageInfo(bmp, centerPoint, symbolBounds,bmp.GetBounds(device)); #region Cleanup if (newii != null) { return newii; } else { return null; } #endregion } catch (Exception exc) { ErrorLogger.LogException("SinglePointRenderer", "ProcessUnitDisplayModifiers", exc); return null; } }
public static CanvasGeometry ToCanvasGeometry(this XPathGeometry pg, CanvasDrawingSession ds) { CanvasGeometry g; using (var builder = new CanvasPathBuilder(ds)) { if (pg.FillRule == XFillRule.EvenOdd) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Alternate); } else { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); } foreach (var pf in pg.Figures) { builder.BeginFigure( (float)pf.StartPoint.X, (float)pf.StartPoint.Y, pf.IsFilled ? CanvasFigureFill.Default : CanvasFigureFill.DoesNotAffectFills); foreach (var segment in pf.Segments) { var options = CanvasFigureSegmentOptions.None; if (!segment.IsStroked) { options |= CanvasFigureSegmentOptions.ForceUnstroked; } if (segment.IsSmoothJoin) { options |= CanvasFigureSegmentOptions.ForceRoundLineJoin; } builder.SetSegmentOptions(options); if (segment is XArcSegment) { var arcSegment = segment as XArcSegment; builder.AddArc( new N.Vector2( (float)arcSegment.Point.X, (float)arcSegment.Point.Y), (float)(arcSegment.Size.Width / 2.0), (float)(arcSegment.Size.Height / 2.0), (float)arcSegment.RotationAngle, arcSegment.SweepDirection == XSweepDirection.Clockwise ? CanvasSweepDirection.Clockwise : CanvasSweepDirection.CounterClockwise, arcSegment.IsLargeArc ? CanvasArcSize.Large : CanvasArcSize.Small); } else if (segment is XBezierSegment) { var bezierSegment = segment as XBezierSegment; builder.AddCubicBezier( new N.Vector2( (float)bezierSegment.Point1.X, (float)bezierSegment.Point1.Y), new N.Vector2( (float)bezierSegment.Point2.X, (float)bezierSegment.Point2.Y), new N.Vector2( (float)bezierSegment.Point3.X, (float)bezierSegment.Point3.Y)); } else if (segment is XLineSegment) { var lineSegment = segment as XLineSegment; builder.AddLine( new N.Vector2( (float)lineSegment.Point.X, (float)lineSegment.Point.Y)); } else if (segment is XPolyBezierSegment) { var polyBezierSegment = segment as XPolyBezierSegment; if (polyBezierSegment.Points.Count >= 3) { builder.AddCubicBezier( new N.Vector2( (float)polyBezierSegment.Points[0].X, (float)polyBezierSegment.Points[0].Y), new N.Vector2( (float)polyBezierSegment.Points[1].X, (float)polyBezierSegment.Points[1].Y), new N.Vector2( (float)polyBezierSegment.Points[2].X, (float)polyBezierSegment.Points[2].Y)); } if (polyBezierSegment.Points.Count > 3 && polyBezierSegment.Points.Count % 3 == 0) { for (int i = 3; i < polyBezierSegment.Points.Count; i += 3) { builder.AddCubicBezier( new N.Vector2( (float)polyBezierSegment.Points[i].X, (float)polyBezierSegment.Points[i].Y), new N.Vector2( (float)polyBezierSegment.Points[i + 1].X, (float)polyBezierSegment.Points[i + 1].Y), new N.Vector2( (float)polyBezierSegment.Points[i + 2].X, (float)polyBezierSegment.Points[i + 2].Y)); } } } else if (segment is XPolyLineSegment) { var polyLineSegment = segment as XPolyLineSegment; if (polyLineSegment.Points.Count >= 1) { builder.AddLine( new N.Vector2( (float)polyLineSegment.Points[0].X, (float)polyLineSegment.Points[0].Y)); } if (polyLineSegment.Points.Count > 1) { for (int i = 1; i < polyLineSegment.Points.Count; i++) { builder.AddLine( new N.Vector2( (float)polyLineSegment.Points[i].X, (float)polyLineSegment.Points[i].Y)); } } } else if (segment is XPolyQuadraticBezierSegment) { var polyQuadraticSegment = segment as XPolyQuadraticBezierSegment; if (polyQuadraticSegment.Points.Count >= 2) { builder.AddQuadraticBezier( new N.Vector2( (float)polyQuadraticSegment.Points[0].X, (float)polyQuadraticSegment.Points[0].Y), new N.Vector2( (float)polyQuadraticSegment.Points[1].X, (float)polyQuadraticSegment.Points[1].Y)); } if (polyQuadraticSegment.Points.Count > 2 && polyQuadraticSegment.Points.Count % 2 == 0) { for (int i = 3; i < polyQuadraticSegment.Points.Count; i += 3) { builder.AddQuadraticBezier( new N.Vector2( (float)polyQuadraticSegment.Points[i].X, (float)polyQuadraticSegment.Points[i].Y), new N.Vector2( (float)polyQuadraticSegment.Points[i + 1].X, (float)polyQuadraticSegment.Points[i + 1].Y)); } } } else if (segment is XQuadraticBezierSegment) { var qbezierSegment = segment as XQuadraticBezierSegment; builder.AddQuadraticBezier( new N.Vector2( (float)qbezierSegment.Point1.X, (float)qbezierSegment.Point1.Y), new N.Vector2( (float)qbezierSegment.Point2.X, (float)qbezierSegment.Point2.Y)); } else { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); } } builder.EndFigure(pf.IsClosed ? CanvasFigureLoop.Closed : CanvasFigureLoop.Open); } g = CanvasGeometry.CreatePath(builder); } return(g); }
public void Draw(object ds, XArc arc, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r) { var a = WpfArc.FromXArc(arc, dx, dy); var _ds = ds as CanvasDrawingSession; double thickness = arc.Style.Thickness / _state.Zoom; var brush = ToColor(arc.Style.Fill); var pen = ToColor(arc.Style.Stroke); var ss = CreateStrokeStyle(arc.Style); CanvasGeometry g; using (var builder = new CanvasPathBuilder(_ds)) { builder.BeginFigure((float)a.Start.X, (float)a.Start.Y); builder.AddArc( new N.Vector2( (float)a.End.X, (float)a.End.Y), (float)a.Radius.Width, (float)a.Radius.Height, 0f, CanvasSweepDirection.Clockwise, a.IsLargeArc ? CanvasArcSize.Large : CanvasArcSize.Small); builder.EndFigure(CanvasFigureLoop.Open); g = CanvasGeometry.CreatePath(builder); } if (arc.IsFilled) { _ds.FillGeometry(g, brush); } if (arc.IsStroked) { _ds.DrawGeometry(g, pen, (float)thickness, ss); } g.Dispose(); ss.Dispose(); }
private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args) { var ds = args.DrawingSession; foreach (var link in Links) { var centerPoint = (link.Node1.Position + link.Node2.Position) / 2; //if (Math.Abs(link.Node1.PositionX - link.Node2.PositionX) > Math.Abs(link.Node1.PositionY - link.Node2.PositionY)) //{ // ds.DrawText(link.Weight.ToString(), centerPoint.X, centerPoint.Y - 10, foregroundColor); //} ds.DrawEllipse((float)Canvas.ActualWidth / 2, (float)Canvas.ActualHeight / 2, 500, 500, foregroundColor); using (var builder = new CanvasPathBuilder(sender)) { builder.BeginFigure(link.Node1.Position); builder.AddArc(link.Node2.Position, arcRadiusX, arcRadiusY, 0, CanvasSweepDirection.Clockwise, CanvasArcSize.Small); builder.EndFigure(CanvasFigureLoop.Open); using (var geometry = CanvasGeometry.CreatePath(builder)) { ds.DrawGeometry(geometry, foregroundColor, strokeWidth); } } } foreach (var node in Nodes) { DrawNode(ds, node); } }
void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args) { var ds = args.DrawingSession; var centerPoint = (arcPoints[0] + arcPoints[1]) / 2; // Draw the end point markers. if (!ThumbnailGenerator.IsDrawingThumbnail) { for (int i = 0; i < 2; i++) { ds.DrawCircle(arcPoints[i], hitTestRadius, (i == activeDrag) ? Colors.White : Colors.Gray); } } switch (CurrentOverload) { case AddArcOverload.AroundEllipse: // Compute positions. var ellipseRadius = (arcPoints[1] - arcPoints[0]) / 2; ellipseRadius.X = Math.Abs(ellipseRadius.X); ellipseRadius.Y = Math.Abs(ellipseRadius.Y); float startAngle = Utils.DegreesToRadians(ArcStartAngle); float sweepAngle = Utils.DegreesToRadians(ArcSweepAngle); var startPoint = centerPoint + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(startAngle)) * ellipseRadius; // Draw the bounding rectangle. if (!ThumbnailGenerator.IsDrawingThumbnail) { ds.DrawRectangle(new Rect(arcPoints[0].ToPoint(), arcPoints[1].ToPoint()), Color.FromArgb(255, 64, 64, 64)); } // Draw the arc. using (var builder = new CanvasPathBuilder(sender)) { builder.BeginFigure(startPoint); builder.AddArc(centerPoint, ellipseRadius.X, ellipseRadius.Y, startAngle, sweepAngle); builder.EndFigure(CanvasFigureLoop.Open); using (var geometry = CanvasGeometry.CreatePath(builder)) { ds.DrawGeometry(geometry, Colors.Yellow, strokeWidth, strokeStyle); } } break; case AddArcOverload.PointToPoint: // Display a warning if this is an invalid arc configuration. bool isRadiusTooSmall = IsArcRadiusTooSmall(); if (isRadiusTooSmall) { ds.DrawText("Radius is less than the\ndistance between the\nstart and end points", centerPoint, Colors.Red, textFormat); } // Draw the arc. using (var builder = new CanvasPathBuilder(sender)) { builder.BeginFigure(arcPoints[0]); builder.AddArc(arcPoints[1], ArcRadiusX, ArcRadiusY, Utils.DegreesToRadians(ArcRotation), ArcSweepDirection, ArcSize); builder.EndFigure(CanvasFigureLoop.Open); using (var geometry = CanvasGeometry.CreatePath(builder)) { ds.DrawGeometry(geometry, isRadiusTooSmall ? Colors.Red : Colors.Yellow, strokeWidth, strokeStyle); } } break; } }
/*public override object Clone() { SVGPath clone = new SVGPath(); clone._gp = (GraphicsPath)_gp.Clone(); clone._ID = _ID; clone._strPath = (String)_strPath.Clone(); return clone; }*/ private void parsePath(CanvasPathBuilder pb, String path) { char[] delimiter = { ' ' }; string[] commands = Regex.Split(path, _regex1); string[] values = null; float[] points = new float[7]; Vector2[] Vector2s = new Vector2[4]; Vector2 lastPoint = new Vector2(0, 0); Vector2 lastControlPoint = new Vector2(0, 0); //Vector2 firstPoint = new Vector2(0, 0); //Vector2 firstPoint = new Vector2(0, 0); try { for (int i = 0; i < commands.Length; i++) { String strCommand = commands[i]; char action = (strCommand != null && strCommand.Length > 0) ? strCommand[0] : ' '; values = strCommand.Split(delimiter); if (action == 'M') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)); points[1] = -(float)Convert.ToDouble(values[1]); lastPoint = new Vector2(points[0], points[1]); //firstPoint = new Vector2(points[0], points[1]); pb.BeginFigure(lastPoint); } else if (action == 'm') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X; points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y; pb.BeginFigure(points[0], points[1]); lastPoint.X = points[0]; lastPoint.Y = points[1]; pb.BeginFigure(lastPoint); } else if (action == 'L')//capital letter is absolute location { points[0] = (float)Convert.ToDouble(values[0].Substring(1)); points[1] = -(float)Convert.ToDouble(values[1]); pb.AddLine(points[0], points[1]); lastPoint.X = points[0]; lastPoint.Y = points[1]; } else if (action == 'l')//lowercase letter is relative location { points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X; points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y; pb.AddLine(points[0], points[1]); lastPoint.X = points[0]; lastPoint.Y = points[1]; } else if (action == 'H') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)); pb.AddLine(points[0], lastPoint.Y); lastPoint.X = points[0]; } else if (action == 'h') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X; pb.AddLine(points[0], lastPoint.Y); lastPoint.X = points[0]; } else if (action == 'V') { points[0] = -(float)Convert.ToDouble(values[0].Substring(1)); pb.AddLine(lastPoint.X, points[0]); lastPoint.Y = points[0]; } else if (action == 'v') { points[0] = -(float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.Y; pb.AddLine(lastPoint.X, points[0]); lastPoint.Y = points[0]; } else if (action == 'C')//cubic bezier, 2 control points { points[0] = (float)Convert.ToDouble(values[0].Substring(1)); points[1] = -(float)Convert.ToDouble(values[1]); points[2] = (float)Convert.ToDouble(values[2]); points[3] = -(float)Convert.ToDouble(values[3]); points[4] = (float)Convert.ToDouble(values[4]); points[5] = -(float)Convert.ToDouble(values[5]); Vector2s[0] = lastPoint; Vector2s[1] = new Vector2(points[0], points[1]); Vector2s[2] = new Vector2(points[2], points[3]); Vector2s[3] = new Vector2(points[4], points[5]); //_gp.AddBezier(Vector2s[0], Vector2s[1], Vector2s[2], Vector2s[3]); pb.AddCubicBezier(Vector2s[1], Vector2s[2], Vector2s[3]); lastPoint = Vector2s[3]; lastControlPoint = Vector2s[2]; } else if (action == 'c') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X; points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y; points[2] = (float)Convert.ToDouble(values[2]) + lastPoint.X; points[3] = -(float)Convert.ToDouble(values[3]) + lastPoint.Y; points[4] = (float)Convert.ToDouble(values[4]) + lastPoint.X; points[5] = -(float)Convert.ToDouble(values[5]) + lastPoint.Y; Vector2s[0] = lastPoint; Vector2s[1] = new Vector2(points[0], points[1]); Vector2s[2] = new Vector2(points[2], points[3]); Vector2s[3] = new Vector2(points[4], points[5]); //_gp.AddBezier(Vector2s[0], Vector2s[1], Vector2s[2], Vector2s[3]); pb.AddCubicBezier(Vector2s[1], Vector2s[2], Vector2s[3]); lastPoint = Vector2s[3]; lastControlPoint = Vector2s[2]; } else if (action == 'S') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)); points[1] = -(float)Convert.ToDouble(values[1]); points[2] = (float)Convert.ToDouble(values[2]); points[3] = -(float)Convert.ToDouble(values[3]); Vector2s[0] = lastPoint; Vector2s[1] = mirrorControlPoint(lastControlPoint, lastPoint); Vector2s[2] = new Vector2(points[0], points[1]); Vector2s[3] = new Vector2(points[2], points[3]); //_gp.AddBezier(Vector2s[0], Vector2s[1], Vector2s[2], Vector2s[3]); pb.AddCubicBezier(Vector2s[1], Vector2s[2], Vector2s[3]); lastPoint = Vector2s[3]; lastControlPoint = Vector2s[2]; } else if (action == 's') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X; points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y; points[2] = (float)Convert.ToDouble(values[2]) + lastPoint.X; points[3] = -(float)Convert.ToDouble(values[3]) + lastPoint.Y; Vector2s[0] = lastPoint; Vector2s[1] = mirrorControlPoint(lastControlPoint, lastPoint); Vector2s[2] = new Vector2(points[0], points[1]); Vector2s[3] = new Vector2(points[2], points[3]); //_gp.AddBezier(Vector2s[0], Vector2s[1], Vector2s[2], Vector2s[3]); pb.AddCubicBezier(Vector2s[1], Vector2s[2], Vector2s[3]); lastPoint = Vector2s[3]; lastControlPoint = Vector2s[2]; } else if (action == 'Q')//quadratic bezier, 1 control point { points[0] = (float)Convert.ToDouble(values[0].Substring(1)); points[1] = -(float)Convert.ToDouble(values[1]); points[2] = (float)Convert.ToDouble(values[2]); points[3] = -(float)Convert.ToDouble(values[3]); //convert quadratic to cubic bezier Vector2 QP0 = lastPoint; Vector2 QP1 = new Vector2(points[0], points[1]); Vector2 QP2 = new Vector2(points[2], points[3]); Vector2 CP0 = QP0; Vector2 CP3 = QP2; //old //Vector2 CP1 = new Vector2((QP0.X + 2.0f * QP1.X) / 3.0f, (QP0.Y + 2.0f * QP1.Y) / 3.0f); //Vector2 CP2 = new Vector2((QP2.X + 2.0f * QP1.X) / 3.0f, (QP2.Y + 2.0f * QP1.Y) / 3.0f); //new Vector2 CP1 = new Vector2(QP0.X + 2.0f / 3.0f * (QP1.X - QP0.X), QP0.Y + 2.0f / 3.0f * (QP1.Y - QP0.Y)); Vector2 CP2 = new Vector2(QP2.X + 2.0f / 3.0f * (QP1.X - QP2.X), QP2.Y + 2.0f / 3.0f * (QP1.Y - QP2.Y)); //_gp.AddBezier(CP0, CP1, CP2, CP3); //pb.AddCubicBezier(CP1, CP2, QP2); pb.AddQuadraticBezier(QP1, QP2); lastPoint = QP2; lastControlPoint = QP1; } else if (action == 'q') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X; points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y; points[2] = (float)Convert.ToDouble(values[2]) + lastPoint.X; points[3] = -(float)Convert.ToDouble(values[3]) + lastPoint.Y; //convert quadratic to cubic bezier Vector2 QP0 = lastPoint; Vector2 QP1 = new Vector2(points[0], points[1]); Vector2 QP2 = new Vector2(points[2], points[3]); Vector2 CP0 = QP0; Vector2 CP3 = QP2; //old //Vector2 CP1 = new Vector2((QP0.X + 2.0f * QP1.X) / 3.0f, (QP0.Y + 2.0f * QP1.Y) / 3.0f); //Vector2 CP2 = new Vector2((QP2.X + 2.0f * QP1.X) / 3.0f, (QP2.Y + 2.0f * QP1.Y) / 3.0f); //new //Vector2 CP1 = new Vector2(QP0.X + 2.0f / 3.0f * (QP1.X - QP0.X), QP0.Y + 2.0f / 3.0f * (QP1.Y - QP0.Y)); //Vector2 CP2 = new Vector2(QP2.X + 2.0f / 3.0f * (QP1.X - QP2.X), QP2.Y + 2.0f / 3.0f * (QP1.Y - QP2.Y)); //_gp.AddBezier(CP0, CP1, CP2, CP3); //pb.AddCubicBezier(CP1, CP2, QP2); pb.AddQuadraticBezier(QP1, QP2); lastPoint = QP2; lastControlPoint = QP1; } else if (action == 'T') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)); points[1] = -(float)Convert.ToDouble(values[1]); //convert quadratic to bezier Vector2 QP0 = lastPoint; Vector2 QP1 = mirrorControlPoint(lastControlPoint, QP0); Vector2 QP2 = new Vector2(points[0], points[1]); Vector2 CP0 = QP0; Vector2 CP3 = QP2; //Vector2 CP1 = new Vector2((QP0.X + 2.0f * QP1.X) / 3.0f, (QP0.Y + 2.0f * QP1.Y) / 3.0f); //Vector2 CP2 = new Vector2((QP2.X + 2.0f * QP1.X) / 3.0f, (QP2.Y + 2.0f * QP1.Y) / 3.0f); //Vector2 CP1 = new Vector2(QP0.X + 2.0f / 3.0f * (QP1.X - QP0.X), QP0.Y + 2.0f / 3.0f * (QP1.Y - QP0.Y)); //Vector2 CP2 = new Vector2(QP2.X + 2.0f / 3.0f * (QP1.X - QP2.X), QP2.Y + 2.0f / 3.0f * (QP1.Y - QP2.Y)); //_gp.AddBezier(CP0, CP1, CP2, CP3); //pb.AddCubicBezier(CP1, CP2, QP2); pb.AddQuadraticBezier(QP1, QP2); lastPoint = QP2; lastControlPoint = QP1; } else if (action == 't') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)) + lastPoint.X; points[1] = -(float)Convert.ToDouble(values[1]) + lastPoint.Y; //convert quadratic to bezier Vector2 QP0 = lastPoint; Vector2 QP1 = mirrorControlPoint(lastControlPoint, QP0); Vector2 QP2 = new Vector2(points[0], points[1]); Vector2 CP0 = QP0; Vector2 CP3 = QP2; //Vector2 CP1 = new Vector2((QP0.X + 2.0f * QP1.X) / 3.0f, (QP0.Y + 2.0f * QP1.Y) / 3.0f); //Vector2 CP2 = new Vector2((QP2.X + 2.0f * QP1.X) / 3.0f, (QP2.Y + 2.0f * QP1.Y) / 3.0f); //Vector2 CP1 = new Vector2(QP0.X + 2.0f / 3.0f * (QP1.X - QP0.X), QP0.Y + 2.0f / 3.0f * (QP1.Y - QP0.Y)); //Vector2 CP2 = new Vector2(QP2.X + 2.0f / 3.0f * (QP1.X - QP2.X), QP2.Y + 2.0f / 3.0f * (QP1.Y - QP2.Y)); //_gp.AddBezier(CP0, CP1, CP2, CP3); //pb.AddCubicBezier(CP1, CP2, QP2); pb.AddQuadraticBezier(QP1, QP2); lastPoint = QP2; lastControlPoint = QP1; } else if (action == 'A') { points[0] = (float)Convert.ToDouble(values[0].Substring(1));//radiusX points[1] = (float)Convert.ToDouble(values[1]);//radiusY points[2] = (float)Convert.ToDouble(values[2]);//angle points[3] = (float)Convert.ToDouble(values[3]);//size points[4] = (float)Convert.ToDouble(values[4]);//sweep points[5] = (float)Convert.ToDouble(values[5]);//endX points[6] = -(float)Convert.ToDouble(values[6]);//endY //SvgArcSize sas = points[3] == 0 ? SvgArcSize.Small : SvgArcSize.Large; //SvgArcSweep sasw = points[4] == 0 ? SvgArcSweep.Negative : SvgArcSweep.Positive; Vector2 endPoint = new Vector2(points[5], points[6]); //SvgArcSegment arc = new SvgArcSegment(lastPoint, points[0], points[1], points[2], sas, sasw, endPoint); //arc.AddToPath(_gp); CanvasArcSize arcSize = CanvasArcSize.Large;//if size = 1, size is large. 0 for small CanvasSweepDirection sweep = CanvasSweepDirection.Clockwise;//if sweep == 1, sweep is clockwise or positive if(points[3]==0.0f) arcSize = CanvasArcSize.Small; if (points[4] == 0.0f) sweep = CanvasSweepDirection.CounterClockwise; pb.AddArc(new Vector2(points[5], points[6]), points[0], points[1], points[2], sweep, arcSize); //AddArcToPath(_gp, lastPoint, points[0], points[1], points[2], (int)points[3], (int)points[4], endPoint); lastPoint.X = points[5]; lastPoint.Y = points[6]; } else if (action == 'a') { points[0] = (float)Convert.ToDouble(values[0].Substring(1)); points[1] = (float)Convert.ToDouble(values[1]); points[2] = (float)Convert.ToDouble(values[2]); points[3] = (float)Convert.ToDouble(values[3]); points[4] = (float)Convert.ToDouble(values[4]); points[5] = (float)Convert.ToDouble(values[5] + lastPoint.X); points[6] = -(float)Convert.ToDouble(values[6] + lastPoint.Y); //SvgArcSize sas = points[3] == 0 ? SvgArcSize.Small : SvgArcSize.Large; //SvgArcSweep sasw = points[4] == 0 ? SvgArcSweep.Negative : SvgArcSweep.Positive; Vector2 endPoint = new Vector2(points[5], points[6]); //SvgArcSegment arc = new SvgArcSegment(lastPoint, points[0], points[1], points[2], sas, sasw, endPoint); //arc.AddToPath(_gp); CanvasArcSize arcSize = CanvasArcSize.Large;//if size = 1, size is large. 0 for small CanvasSweepDirection sweep = CanvasSweepDirection.Clockwise;//if sweep == 1, sweep is clockwise or positive if (points[3] == 0.0f) arcSize = CanvasArcSize.Small; if (points[4] == 0.0f) sweep = CanvasSweepDirection.CounterClockwise; pb.AddArc(new Vector2(points[5], points[6]), points[0], points[1], points[2], sweep, arcSize); //AddArcToPath(_gp, lastPoint, points[0], points[1], points[2], (int)points[3], (int)points[4], endPoint); lastPoint.X = points[5]; lastPoint.Y = points[6]; } else if (action == 'Z' || action == 'z') { pb.EndFigure(CanvasFigureLoop.Closed); } } _cg = CanvasGeometry.CreatePath(pb); } catch (Exception exc) { Debug.WriteLine(exc.Message); Debug.WriteLine(exc.StackTrace); ErrorLogger.LogException("SVGPath", "parsePath", exc); } }
public static void AddCircleFigure(this CanvasPathBuilder builder, Vector2 center, float radius) { builder.BeginFigure(center + Vector2.UnitX * radius); builder.AddArc(center, radius, radius, 0, (float)Math.PI * 2); builder.EndFigure(CanvasFigureLoop.Closed); }
public void AddPathSegment(CanvasPathBuilder canvasPathBuilder, ref bool closed) { canvasPathBuilder.AddArc(_endPoint, _a / 2, _b / 2, _sweepAngle, CanvasSweepDirection.Clockwise, CanvasArcSize.Small); closed = false; }
CanvasGeometry MakeDirectionIcon(ICanvasResourceCreator creator) { var builder = new CanvasPathBuilder(creator); float radius = 3; float lineWidth = 20; builder.BeginFigure(0, 0); builder.AddLine(0, radius * 2); builder.EndFigure(CanvasFigureLoop.Open); float y = radius; builder.BeginFigure(0, y); builder.AddArc(new Vector2(lineWidth + radius, y + radius), radius, radius, -(float)Math.PI/2, (float)Math.PI); y += radius * 2; builder.AddArc(new Vector2(radius, y + radius), radius, radius, -(float)Math.PI/2, -(float)Math.PI); y += radius * 2; float x = lineWidth * 2 / 3; builder.AddLine(x, y); builder.EndFigure(CanvasFigureLoop.Open); builder.BeginFigure(x - radius, y - radius/3); builder.AddLine(x, y); builder.AddLine(x - radius, y + radius/3); builder.EndFigure(CanvasFigureLoop.Open); return CanvasGeometry.CreatePath(builder); }