private void RenderData(CanvasDrawingSession ds, double width, double height) { if (data.Count == 0) { return; } float thickness = 1; float w = (float)width * data.Count / 300; float xs = w / data.Count; float x0 = (float)width - w; using (var cpb = new CanvasPathBuilder(ds)) { cpb.BeginFigure(new Vector2((float)(axis[0] * width), (float)(height * (1 - data[0])))); for (int i = 1; i < data.Count; i++) { //cpb.AddLine(new Vector2(i*xs + x0, (float)(height * (1 - data[i])))); cpb.AddLine(new Vector2((float)(axis[i] * width), (float)(height * (1 - data[i])))); } if (renderArea) { cpb.AddLine(new Vector2(data.Count * xs + x0, (float)height)); cpb.AddLine(new Vector2(x0, (float)height)); cpb.EndFigure(CanvasFigureLoop.Closed); ds.FillGeometry(CanvasGeometry.CreatePath(cpb), color); } else { cpb.EndFigure(CanvasFigureLoop.Open); ds.DrawGeometry(CanvasGeometry.CreatePath(cpb), color, thickness); } } }
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 void RenderData(CanvasDrawEventArgs args, Color color, float thickness) { using (var cpb = new CanvasPathBuilder(args.DrawingSession)) { cpb.BeginFigure(new Vector2(0, (float)(canvas.ActualHeight * (1 - _data[0])))); for (int i = 1; i < _data.Count; i++) { cpb.AddLine(new Vector2(i, (float)(canvas.ActualHeight * (1 - _data[i])))); } if (ShowDataAsAreaCheckBox.IsChecked == true) { cpb.AddLine(new Vector2(_data.Count, (float)canvas.ActualHeight)); cpb.AddLine(new Vector2(0, (float)canvas.ActualHeight)); cpb.EndFigure(CanvasFigureLoop.Closed); args.DrawingSession.FillGeometry(CanvasGeometry.CreatePath(cpb), Colors.LightGreen); } else { cpb.EndFigure(CanvasFigureLoop.Open); args.DrawingSession.DrawGeometry(CanvasGeometry.CreatePath(cpb), color, thickness); } } }
public void RenderData(CanvasControl canvas, CanvasDrawEventArgs args, Color color, float thickness, List <double> data, bool renderArea) { using (var cpb = new CanvasPathBuilder(args.DrawingSession)) { cpb.BeginFigure(new Vector2(0, (float)(canvas.ActualHeight * (1 - data[0])))); for (int i = 1; i < data.Count; i++) { cpb.AddLine(new Vector2(i, (float)(canvas.ActualHeight * (1 - data[i])))); } if (renderArea) { cpb.AddLine(new Vector2(data.Count, (float)canvas.ActualHeight)); cpb.AddLine(new Vector2(0, (float)canvas.ActualHeight)); cpb.EndFigure(CanvasFigureLoop.Closed); args.DrawingSession.FillGeometry(CanvasGeometry.CreatePath(cpb), Colors.LightGreen); } else { cpb.EndFigure(CanvasFigureLoop.Open); args.DrawingSession.DrawGeometry(CanvasGeometry.CreatePath(cpb), color, thickness); } } }
public override CanvasGeometry GetGeometry(ICanvasResourceCreator iCreator, bool isMoving) { pixelManager.BeginUsing(); bool figureEnded = true; int i = -1, addToI, pixelPointsCount = pixelManager.Points.Count; float pixelWidth = ViewArgs.PixelSize.ActualWidth; Vector2 curPoint; CanvasPathBuilder cpb = new CanvasPathBuilder(iCreator); addToI = isMoving ? 1 + movingSkipPoints : 1; do { i++; if (i == pixelPointsCount) { pixelManager.EndUsing(); return(null); } curPoint = pixelManager.Points[i]; } while (curPoint.X < 0 || float.IsNaN(curPoint.Y)); while (curPoint.X < pixelWidth && i < pixelPointsCount) { curPoint = pixelManager.Points[i]; if (figureEnded) { if (!float.IsNaN(curPoint.Y)) { cpb.BeginFigure(curPoint); figureEnded = false; } } else if (!float.IsNaN(curPoint.Y)) { cpb.AddLine(curPoint); } else { cpb.EndFigure(CanvasFigureLoop.Open); figureEnded = true; } i += addToI; } pixelManager.EndUsing(); if (!figureEnded) { cpb.EndFigure(CanvasFigureLoop.Open); } return(CanvasGeometry.CreatePath(cpb)); }
public void EndFigure(bool close) { if (pathBuilder == null) { throw new Exception("Path is closed"); } pathBuilder.EndFigure(close ? CanvasFigureLoop.Closed : CanvasFigureLoop.Open); }
public void Draw(CanvasDrawingSession graphics) { CanvasDevice device = CanvasDevice.GetSharedDevice(); var builder = new CanvasPathBuilder(device); var originalW = _arrowHead.X - _arrowTail.X; var originalH = _arrowHead.Y - _arrowTail.Y; var originalL = Math.Sqrt(originalW * originalW + originalH * originalH); var newL = originalL - Math.Min(20, originalL / 2); var newW = originalW * newL / originalL; var newH = originalH * newL / originalL; var newX = _arrowTail.X + (float)newW; var newY = _arrowTail.Y + (float)newH; var normalK = -originalW / originalH; var cosA = 1 / (float)Math.Sqrt(1 + normalK * normalK); var step = 20 * cosA; var x1 = newX - step; var y1 = normalK * (x1 - newX) + newY; var arrowLeftSholder = new Vector2(x1, y1); var x2 = newX + step; var y2 = normalK * (x2 - newX) + newY; var arrowRightSholder = new Vector2(x2, y2); builder.BeginFigure(_arrowTail); builder.AddLine(_arrowHead); builder.EndFigure(CanvasFigureLoop.Open); builder.BeginFigure(arrowLeftSholder); builder.AddLine(_arrowHead); builder.AddLine(arrowRightSholder); builder.EndFigure(CanvasFigureLoop.Open); var arrow = CanvasGeometry.CreatePath(builder); graphics.DrawGeometry(arrow, drawingColor, drawingSize, new CanvasStrokeStyle { TransformBehavior = CanvasStrokeTransformBehavior.Fixed, StartCap = CanvasCapStyle.Triangle, EndCap = CanvasCapStyle.Triangle, LineJoin = CanvasLineJoin.Miter }); }
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; }
/// <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); }
public CanvasGeometry GetGeometry(CanvasDevice device) { var fill = FillType == PathFillType.Winding ? CanvasFilledRegionDetermination.Winding : CanvasFilledRegionDetermination.Alternate; // FillRule = path.FillType == PathFillType.EvenOdd ? FillRule.EvenOdd : FillRule.Nonzero, var canvasPathBuilder = new CanvasPathBuilder(device); canvasPathBuilder.SetFilledRegionDetermination(fill); var closed = true; for (var i = 0; i < Contours.Count; i++) { Contours[i].AddPathSegment(canvasPathBuilder, ref closed); } if (!closed) { canvasPathBuilder.EndFigure(CanvasFigureLoop.Open); } return(CanvasGeometry.CreatePath(canvasPathBuilder)); }
/// <summary> /// Adds a Rectangle to the Path. /// </summary> /// <param name="pathBuilder">CanvasPathBuilder</param> /// <param name="x">X offset of the TopLeft corner of the Rectangle</param> /// <param name="y">Y offset of the TopLeft corner of the Rectangle</param> /// <param name="width">Width of the Rectangle</param> /// <param name="height">Height of the Rectangle</param> public static void AddRectangleFigure(this CanvasPathBuilder pathBuilder, float x, float y, float width, float height) { // Sanitize the width by taking the absolute value width = Math.Abs(width); // Sanitize the height by taking the absolute value height = Math.Abs(height); try { pathBuilder.BeginFigure(x, y); } catch (ArgumentException) { // An ArgumentException will be raised if another figure was already begun( and not ended) // before calling AddPolygonFigure() method. throw new InvalidOperationException("A call to CanvasPathBuilder.AddRectangleFigure occurred, " + "when another figure was already begun. Please call CanvasPathBuilder.EndFigure method, " + "before calling CanvasPathBuilder.AddRectangleFigure, to end the previous figure."); } // Top Side pathBuilder.AddLine(x + width, y); // Right Side pathBuilder.AddLine(x + width, y + height); // Bottom Side pathBuilder.AddLine(x, y + height); // Left Side pathBuilder.AddLine(x, y); // End the Figure pathBuilder.EndFigure(CanvasFigureLoop.Closed); }
// - - - Shape tree root for layer: icon // - - ShapeGroup: Group 2 CanvasGeometry Geometry_0() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(60F, -15F)); builder.AddCubicBezier(new Vector2(60F, -48.137001F), new Vector2(33.137001F, -75F), new Vector2(0F, -75F)); builder.AddCubicBezier(new Vector2(-33.137001F, -75F), new Vector2(-60F, -48.137001F), new Vector2(-60F, -15F)); builder.AddLine(new Vector2(-60F, 30F)); builder.AddLine(new Vector2(-65.9449997F, 37.4309998F)); builder.AddCubicBezier(new Vector2(-69.6750031F, 42.0950012F), new Vector2(-68.9189987F, 48.8989983F), new Vector2(-64.2549973F, 52.6300011F)); builder.AddCubicBezier(new Vector2(-62.7210007F, 53.8569984F), new Vector2(-60.8889999F, 54.6380005F), new Vector2(-58.9609985F, 54.901001F)); builder.AddLine(new Vector2(-57.5F, 55F)); builder.AddLine(new Vector2(57.4790001F, 55F)); builder.AddCubicBezier(new Vector2(63.4539986F, 55F), new Vector2(68.2969971F, 50.1559982F), new Vector2(68.2969971F, 44.1809998F)); builder.AddCubicBezier(new Vector2(68.2969971F, 41.7280006F), new Vector2(67.4639969F, 39.348999F), new Vector2(65.9329987F, 37.4319992F)); builder.AddLine(new Vector2(60F, 30F)); builder.AddLine(new Vector2(60F, -15F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
public static CanvasRenderTarget CreateFromSharedDevice(ICanvasResourceCreator resourceCreator, double width, double height) { var device = CanvasDevice.GetSharedDevice(); var target = new CanvasRenderTarget(device, (float)width, (float)height, 96); using (var session = target.CreateDrawingSession()) { session.Clear(Colors.Transparent); var pathBuilder = new CanvasPathBuilder(session); pathBuilder.BeginFigure(170, 90, CanvasFigureFill.Default); pathBuilder.AddCubicBezier(new Vector2(130, 100), new Vector2(130, 150), new Vector2(230, 150)); pathBuilder.AddCubicBezier(new Vector2(250, 180), new Vector2(320, 180), new Vector2(340, 150)); pathBuilder.AddCubicBezier(new Vector2(420, 150), new Vector2(420, 120), new Vector2(390, 100)); pathBuilder.AddCubicBezier(new Vector2(430, 40), new Vector2(370, 30), new Vector2(340, 50)); pathBuilder.AddCubicBezier(new Vector2(320, 5), new Vector2(250, 20), new Vector2(250, 50)); pathBuilder.AddCubicBezier(new Vector2(200, 5), new Vector2(150, 20), new Vector2(170, 80)); pathBuilder.EndFigure(CanvasFigureLoop.Closed); var cloudFigure = CanvasGeometry.CreatePath(pathBuilder); session.FillGeometry(cloudFigure, Color.FromArgb((byte)(255 * 0.7), 0, 255, 0)); var strokeColor = new CanvasSolidColorBrush(session, Color.FromArgb(255, 0, 0, 0)); session.DrawGeometry(cloudFigure, strokeColor, 12); session.FillCircle(500, 20, 20, Colors.White); } return(target); }
private CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, GeometryType type) { switch (type) { case GeometryType.Rectangle: return(CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 300, 350)); case GeometryType.RoundedRectangle: return(CanvasGeometry.CreateRoundedRectangle(resourceCreator, 80, 80, 400, 400, 100, 100)); case GeometryType.Ellipse: return(CanvasGeometry.CreateEllipse(resourceCreator, 275, 275, 225, 275)); case GeometryType.Star: { return(Utils.CreateStarGeometry(resourceCreator, 250, new Vector2(250, 250))); } case GeometryType.Group: { CanvasGeometry geo0 = CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 100, 100); CanvasGeometry geo1 = CanvasGeometry.CreateRoundedRectangle(resourceCreator, 300, 100, 100, 100, 50, 50); CanvasPathBuilder pathBuilder = new CanvasPathBuilder(resourceCreator); pathBuilder.BeginFigure(200, 200); pathBuilder.AddLine(500, 200); pathBuilder.AddLine(200, 350); pathBuilder.EndFigure(CanvasFigureLoop.Closed); CanvasGeometry geo2 = CanvasGeometry.CreatePath(pathBuilder); return(CanvasGeometry.CreateGroup(resourceCreator, new CanvasGeometry[] { geo0, geo1, geo2 })); } } System.Diagnostics.Debug.Assert(false); return(null); }
private void toMask_Tapped(object sender, TappedRoutedEventArgs e) { if (App.Setting.PenVectorList.Count > 1) { CanvasPathBuilder VirtualBuilder = new CanvasPathBuilder(App.Model.VirtualControl); VirtualBuilder.BeginFigure(App.Setting.PenVectorList[0].Vect); CanvasPathBuilder AnimatedBuilder = new CanvasPathBuilder(App.Model.AnimatedControl); AnimatedBuilder.BeginFigure(App.Setting.PenVectorList[0].Vect); for (int i = 0; i < App.Setting.PenVectorList.Count - 1; i++)//0 to 9 { Vector2 vl = App.Setting.PenVectorList[i].Left; Vector2 v1r = App.Setting.PenVectorList[i + 1].Right; Vector2 v1 = App.Setting.PenVectorList[i + 1].Vect; VirtualBuilder.AddCubicBezier(vl, v1r, v1); AnimatedBuilder.AddCubicBezier(vl, v1r, v1); } VirtualBuilder.EndFigure(CanvasFigureLoop.Closed); AnimatedBuilder.EndFigure(CanvasFigureLoop.Closed); //几何图形 CanvasGeometry VirtualGeometry = CanvasGeometry.CreatePath(VirtualBuilder); CanvasGeometry AnimatedGeometry = CanvasGeometry.CreatePath(AnimatedBuilder); //几何 App.Mask(VirtualGeometry, AnimatedGeometry, App.Model.MaskMode); //改变选区与套索 App.Model.isReStroke = true; //重新设置描边 App.Judge(); //判断选区,改变是否动画与选区矩形 } flyout.Hide(); }
//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)); }
private void toStroke_Tapped(object sender, TappedRoutedEventArgs e) { if (App.Setting.PenVectorList.Count > 1) { CanvasPathBuilder VirtualBuilder = new CanvasPathBuilder(App.Model.VirtualControl); VirtualBuilder.BeginFigure(App.Setting.PenVectorList[0].Vect); for (int i = 0; i < App.Setting.PenVectorList.Count - 1; i++)//0 to 9 { Vector2 vl = App.Setting.PenVectorList[i].Left; Vector2 v1r = App.Setting.PenVectorList[i + 1].Right; Vector2 v1 = App.Setting.PenVectorList[i + 1].Vect; VirtualBuilder.AddCubicBezier(vl, v1r, v1); } VirtualBuilder.EndFigure(CanvasFigureLoop.Closed); using (var ds = App.Model.CurrentRenderTarget.CreateDrawingSession()) { ds.DrawGeometry(CanvasGeometry.CreatePath(VirtualBuilder), App.Model.PenColor, App.Setting.PenWidth, App.Setting.PenStrokeStyle); } App.Model.Layers[App.Model.Index].SetWriteableBitmap(App.Model.VirtualControl); //刷新缩略图 App.Model.isReRender = true; //重新渲染 App.Model.Refresh++; //画布刷新 } flyout.Hide(); }
private void OnSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e) { var length = (float)Math.Min(e.NewSize.Width, e.NewSize.Height) * 0.95; var centerX = (float)e.NewSize.Width / 2; var centerY = (float)e.NewSize.Height / 2; var points = new List <Vector2>(); var r = length / 2; var r2 = r * 1.06; var r3 = r * 0.951; int index = 0; int segments = 100; for (int i = 0; i < segments; i += 2) { var x = r * Math.Cos(i * 2 * Math.PI / segments) + centerX; var y = r * Math.Sin(i * 2 * Math.PI / segments) + centerY; points.Add(new Vector2((float)x, (float)y)); var currentR = index++ % 2 == 0 ? r2 : r3; x = currentR * Math.Cos((i + 1) * 2 * Math.PI / segments) + centerX; y = currentR * Math.Sin((i + 1) * 2 * Math.PI / segments) + centerY; points.Add(new Vector2((float)x, (float)y)); } points.Add(points[0]); CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(points[0]); for (int i = 0; i < points.Count - 2; i += 2) { var currentPoint = points[i]; var centerPoint = points[i + 1]; var nextPoint = points[i + 2]; builder.AddCubicBezier(currentPoint, centerPoint, nextPoint); } builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } var compositor = Window.Current.Compositor; var path = new CompositionPath(result); var line3 = compositor.CreatePathGeometry(); line3.Path = path; var shape3 = compositor.CreateSpriteShape(line3); shape3.FillBrush = compositor.CreateColorBrush(Colors.Red); var visual = compositor.CreateShapeVisual(); visual.Shapes.Add(shape3); visual.Size = e.NewSize.ToVector2(); ElementCompositionPreview.SetElementChildVisual(this, visual); }
//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)); }
// - - - - Shape tree root for layer: icon // - - - ShapeGroup: Group 2 // - - Path 1 CanvasGeometry Geometry_1() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(-80F, -44.9970016F)); builder.AddCubicBezier(new Vector2(-80.0019989F, -58.8050003F), new Vector2(-68.8079987F, -70F), new Vector2(-55F, -70F)); builder.AddLine(new Vector2(-28.3600006F, -70F)); builder.AddCubicBezier(new Vector2(-25.1149998F, -70F), new Vector2(-21.9570007F, -68.947998F), new Vector2(-19.3610001F, -67.0009995F)); builder.AddLine(new Vector2(-3.35800004F, -55F)); builder.AddLine(new Vector2(44.9560013F, -55F)); builder.AddCubicBezier(new Vector2(58.7630005F, -55F), new Vector2(69.9560013F, -43.9070015F), new Vector2(69.9560013F, -30.1000004F)); builder.AddLine(new Vector2(70F, -30F)); builder.AddLine(new Vector2(-41.7639999F, -29.9790001F)); builder.AddCubicBezier(new Vector2(-48.9420013F, -29.9790001F), new Vector2(-55F, -25.3400002F), new Vector2(-56.4869995F, -17.8490009F)); builder.AddLine(new Vector2(-72.2580032F, 63.0509987F)); builder.AddCubicBezier(new Vector2(-77.0199966F, 58.5F), new Vector2(-79.9869995F, 52.0849991F), new Vector2(-79.987999F, 44.9780006F)); builder.AddLine(new Vector2(-80F, -44.9970016F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
CanvasGeometry Geometry_1() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(21.4139996F, 59.112999F)); builder.AddCubicBezier(new Vector2(22.4300003F, 49.0349998F), new Vector2(25.007F, 39.894001F), new Vector2(29.1480007F, 31.691F)); builder.AddCubicBezier(new Vector2(33.2890015F, 23.4880009F), new Vector2(38.875F, 15.8319998F), new Vector2(45.9059982F, 8.72299957F)); builder.AddCubicBezier(new Vector2(52.3899994F, 2.16000009F), new Vector2(57.3699989F, -5.0079999F), new Vector2(60.8470001F, -12.7810001F)); builder.AddCubicBezier(new Vector2(64.3239975F, -20.5540009F), new Vector2(66.0619965F, -29.0900002F), new Vector2(66.0619965F, -38.387001F)); builder.AddCubicBezier(new Vector2(66.0619965F, -47.6839981F), new Vector2(64.2850037F, -56.4339981F), new Vector2(60.7299995F, -64.637001F)); builder.AddCubicBezier(new Vector2(57.1749992F, -72.8399963F), new Vector2(52.3510017F, -79.987999F), new Vector2(46.257F, -86.0820007F)); builder.AddCubicBezier(new Vector2(40.1629982F, -92.1760025F), new Vector2(33.0149994F, -97), new Vector2(24.8120003F, -100.555F)); builder.AddCubicBezier(new Vector2(16.6089993F, -104.110001F), new Vector2(7.85900021F, -105.887001F), new Vector2(-1.43799996F, -105.887001F)); builder.AddCubicBezier(new Vector2(-10.7349997F, -105.887001F), new Vector2(-19.4850006F, -104.110001F), new Vector2(-27.6879997F, -100.555F)); builder.AddCubicBezier(new Vector2(-35.8909988F, -97), new Vector2(-43.0390015F, -92.1760025F), new Vector2(-49.1329994F, -86.0820007F)); builder.AddCubicBezier(new Vector2(-55.2270012F, -79.987999F), new Vector2(-60.0509987F, -72.8399963F), new Vector2(-63.605999F, -64.637001F)); builder.AddCubicBezier(new Vector2(-67.1610031F, -56.4339981F), new Vector2(-68.9380035F, -47.6839981F), new Vector2(-68.9380035F, -38.387001F)); builder.AddCubicBezier(new Vector2(-68.9380035F, -29.0900002F), new Vector2(-67.1999969F, -20.5540009F), new Vector2(-63.7229996F, -12.7810001F)); builder.AddCubicBezier(new Vector2(-60.2459984F, -5.0079999F), new Vector2(-55.2659988F, 2.16000009F), new Vector2(-48.7820015F, 8.72299957F)); builder.AddCubicBezier(new Vector2(-41.7509995F, 15.8319998F), new Vector2(-36.1650009F, 23.4880009F), new Vector2(-32.0239983F, 31.691F)); builder.AddCubicBezier(new Vector2(-27.8829994F, 39.894001F), new Vector2(-25.3059998F, 49.0349998F), new Vector2(-24.2900009F, 59.112999F)); builder.AddLine(new Vector2(21.4139996F, 59.112999F)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
CanvasGeometry Geometry_2() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(-11, -4.5F)); builder.AddLine(new Vector2(-11, -5.26000023F)); builder.AddCubicBezier(new Vector2(-11, -6.32000017F), new Vector2(-10.5799999F, -7.34000015F), new Vector2(-9.82999992F, -8.09000015F)); builder.AddLine(new Vector2(-7.59000015F, -10.3299999F)); builder.AddCubicBezier(new Vector2(-6.84000015F, -11.0799999F), new Vector2(-5.82000017F, -11.5F), new Vector2(-4.76000023F, -11.5F)); builder.AddLine(new Vector2(4.76000023F, -11.5F)); builder.AddCubicBezier(new Vector2(5.82000017F, -11.5F), new Vector2(6.84000015F, -11.0799999F), new Vector2(7.59000015F, -10.3299999F)); builder.AddLine(new Vector2(9.82999992F, -8.09000015F)); builder.AddCubicBezier(new Vector2(10.5799999F, -7.34000015F), new Vector2(11, -6.32000017F), new Vector2(11, -5.26000023F)); builder.AddLine(new Vector2(11, 8.5F)); builder.AddCubicBezier(new Vector2(11, 10.1599998F), new Vector2(9.65999985F, 11.5F), new Vector2(8, 11.5F)); builder.AddLine(new Vector2(-8, 11.5F)); builder.AddCubicBezier(new Vector2(-9.65999985F, 11.5F), new Vector2(-11, 10.1599998F), new Vector2(-11, 8.5F)); builder.AddLine(new Vector2(-11, -4.5F)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
private void DrawDryInk_CustomGeometryMethod(CanvasDrawingSession ds, IReadOnlyList <InkStroke> strokes) { // // This shows off the fact that apps can use the custom drying path // to render dry ink using Win2D, and not necessarily // rely on the built-in rendering in CanvasDrawingSession.DrawInk. // foreach (var stroke in strokes) { var color = stroke.DrawingAttributes.Color; var inkPoints = stroke.GetInkPoints(); if (inkPoints.Count > 0) { CanvasPathBuilder pathBuilder = new CanvasPathBuilder(canvasControl); pathBuilder.BeginFigure(inkPoints[0].Position.ToVector2()); for (int i = 1; i < inkPoints.Count; i++) { pathBuilder.AddLine(inkPoints[i].Position.ToVector2()); ds.DrawCircle(inkPoints[i].Position.ToVector2(), 3, color); } pathBuilder.EndFigure(CanvasFigureLoop.Open); CanvasGeometry geometry = CanvasGeometry.CreatePath(pathBuilder); ds.DrawGeometry(geometry, color); } } }
private void DrawSelectionLasso(CanvasControl sender, CanvasDrawingSession ds) { if (selectionPolylinePoints == null) { return; } if (selectionPolylinePoints.Count == 0) { return; } CanvasPathBuilder selectionLasso = new CanvasPathBuilder(canvasControl); selectionLasso.BeginFigure(selectionPolylinePoints[0].ToVector2()); for (int i = 1; i < selectionPolylinePoints.Count; ++i) { selectionLasso.AddLine(selectionPolylinePoints[i].ToVector2()); } selectionLasso.EndFigure(CanvasFigureLoop.Open); CanvasGeometry pathGeometry = CanvasGeometry.CreatePath(selectionLasso); ds.DrawGeometry(pathGeometry, Colors.Magenta, 5.0f); }
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 static CanvasBitmap RenderFromShape(CanvasAnimatedControl canvas, float width, float height, Shape shape, float thickness = 2, bool filled = false) { var renderTarget = new CanvasRenderTarget(canvas, width * SCALE_FACTOR, height * SCALE_FACTOR); var pathBuilder = new CanvasPathBuilder(canvas.Device); pathBuilder.BeginFigure(shape.Points.First() * SCALE_FACTOR); foreach (Vector2 point in shape.Points.Skip(1)) { pathBuilder.AddLine(point * SCALE_FACTOR); } pathBuilder.EndFigure(shape.Closed ? CanvasFigureLoop.Closed : CanvasFigureLoop.Open); using (var ds = renderTarget.CreateDrawingSession()) { if (filled) { ds.FillGeometry(CanvasGeometry.CreatePath(pathBuilder), Colors.White); } else { ds.DrawGeometry(CanvasGeometry.CreatePath(pathBuilder), Colors.White, thickness * SCALE_FACTOR); } } return(renderTarget); }
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(); }
public void drawGrid(double s, CanvasDrawingSession ds) { CanvasPathBuilder pathBuilder = new CanvasPathBuilder(ds); for (float x0 = 0.5f; x0 < 8.5f; x0 += 1) { pathBuilder.BeginFigure(0, x0); for (float y0 = 0.5f; y0 < 8.5; y0 += 0.5f) { var a = Math.Atan2(y0, x0) * 2 / 3; var r = Math.Sqrt(x0 * x0 + y0 * y0); var x = r * Math.Sin(a); var y = r * Math.Cos(a); pathBuilder.AddLine((float)x, (float)y); } pathBuilder.EndFigure(CanvasFigureLoop.Open); } // rotate and reflect the result var onep = CanvasGeometry.CreatePath(pathBuilder); for (int a = 0; a < 6; a++) { var m = Matrix3x2.Identity * Matrix.CreateRotation(Math.PI / 6 + a * Math.PI / 3); ds.DrawGeometry(onep.Transform(m), Colors.DarkGray, 1 / (float)s); m = m * Matrix.CreateScale(1, -1); ds.DrawGeometry(onep.Transform(m), Colors.DarkGray, 1 / (float)s); } }
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); }
// - - - - Shape tree root for layer: icon // - - - ShapeGroup: Group 2 // - - Path 3+Path 2+Path 1.PathGeometry CanvasGeometry Geometry_3() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(-78.8949966F, -49.3380013F)); builder.AddCubicBezier(new Vector2(-80F, -44.7340012F), new Vector2(-80F, -39.1559982F), new Vector2(-80F, -28F)); builder.AddLine(new Vector2(-80F, 28F)); builder.AddCubicBezier(new Vector2(-80F, 39.1559982F), new Vector2(-80F, 44.7340012F), new Vector2(-78.8949966F, 49.3380013F)); builder.AddCubicBezier(new Vector2(-75.3840027F, 63.9640007F), new Vector2(-63.9640007F, 75.3830032F), new Vector2(-49.3380013F, 78.8949966F)); builder.AddCubicBezier(new Vector2(-44.7340012F, 80F), new Vector2(-39.1559982F, 80F), new Vector2(-28F, 80F)); builder.AddLine(new Vector2(10F, 80F)); builder.AddLine(new Vector2(10.0179996F, 39.0730019F)); builder.AddCubicBezier(new Vector2(-7.0710001F, 42.2659988F), new Vector2(-25.3899994F, 37.2089996F), new Vector2(-38.5509987F, 23.9319992F)); builder.AddCubicBezier(new Vector2(-40.4949989F, 21.9710007F), new Vector2(-40.480999F, 18.8050003F), new Vector2(-38.5200005F, 16.8610001F)); builder.AddCubicBezier(new Vector2(-36.5589981F, 14.9169998F), new Vector2(-33.3930016F, 14.9309998F), new Vector2(-31.4489994F, 16.8920002F)); builder.AddCubicBezier(new Vector2(-19.8419991F, 28.6009998F), new Vector2(-3.31800008F, 32.4729996F), new Vector2(11.5319996F, 28.4540005F)); builder.AddCubicBezier(new Vector2(11.9099998F, 27.3059998F), new Vector2(12.3579998F, 26.2329998F), new Vector2(12.8760004F, 25.2380009F)); builder.AddCubicBezier(new Vector2(17.2849998F, 16.0990009F), new Vector2(25.2479992F, 10.7620001F), new Vector2(35.894001F, 10.0710001F)); builder.AddLine(new Vector2(37.7879982F, 10.0089998F)); builder.AddLine(new Vector2(80F, 10F)); builder.AddLine(new Vector2(80F, -28F)); builder.AddCubicBezier(new Vector2(80F, -39.1559982F), new Vector2(80F, -44.7340012F), new Vector2(78.8949966F, -49.3380013F)); builder.AddCubicBezier(new Vector2(75.3830032F, -63.9640007F), new Vector2(63.9640007F, -75.3840027F), new Vector2(49.3380013F, -78.8949966F)); builder.AddCubicBezier(new Vector2(44.7340012F, -80F), new Vector2(39.1559982F, -80F), new Vector2(28F, -80F)); builder.AddLine(new Vector2(-28F, -80F)); builder.AddCubicBezier(new Vector2(-39.1559982F, -80F), new Vector2(-44.7340012F, -80F), new Vector2(-49.3380013F, -78.8949966F)); builder.AddCubicBezier(new Vector2(-63.9640007F, -75.3840027F), new Vector2(-75.3840027F, -63.9640007F), new Vector2(-78.8949966F, -49.3380013F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
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); } }
public void Draw(ICanvasAnimatedControl sender, CanvasDrawingSession drawingSession) { if (currentThunder == null) { return; } // 保护原先画布的混合模式 var previousBlend = drawingSession.Blend; drawingSession.Blend = blendState; var builder = new CanvasPathBuilder(sender); builder.BeginFigure(0, 0); for (int i = 0; i < currentThunder.LifeLong; i++) { builder.AddLine(currentThunder.Path[i].X, currentThunder.Path[i].Y); } builder.EndFigure(CanvasFigureLoop.Open); builder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin); // Draw the particle. var path = CanvasGeometry.CreatePath(builder); var NormalizeLifeTime = currentThunder.TimeSinceStart / currentThunder.Duration; byte opacity = (byte)((NormalizeLifeTime - 1) * (NormalizeLifeTime - 1) * 255); CanvasCommandList cl = new CanvasCommandList(sender); using (CanvasDrawingSession clds = cl.CreateDrawingSession()) { clds.DrawGeometry(path, currentThunder.Position, Color.FromArgb((byte)(0.75f * opacity), 255, 255, 255), 6 * currentThunder.Luminace); } var lightAmount = 20.6f * currentThunder.Luminace * (NormalizeLifeTime - 1) * (NormalizeLifeTime - 1); blur.Source = cl; blur.BlurAmount = lightAmount; drawingSession.DrawImage(blur); drawingSession.DrawGeometry(path, currentThunder.Position, Color.FromArgb(opacity, 255, 240, 180), 2 * currentThunder.Luminace); drawingSession.Blend = previousBlend; if (NormalizeLifeTime > 1) { currentThunder = null; } }
private void DrawDryInk_CustomGeometryMethod(CanvasDrawingSession ds, IReadOnlyList<InkStroke> strokes) { // // This shows off the fact that apps can use the custom drying path // to render dry ink using Win2D, and not necessarily // rely on the built-in rendering in CanvasDrawingSession.DrawInk. // foreach (var stroke in strokes) { var color = stroke.DrawingAttributes.Color; var inkPoints = stroke.GetInkPoints(); if (inkPoints.Count > 0) { CanvasPathBuilder pathBuilder = new CanvasPathBuilder(canvasControl); pathBuilder.BeginFigure(inkPoints[0].Position.ToVector2()); for (int i = 1; i < inkPoints.Count; i++) { pathBuilder.AddLine(inkPoints[i].Position.ToVector2()); ds.DrawCircle(inkPoints[i].Position.ToVector2(), 3, color); } pathBuilder.EndFigure(CanvasFigureLoop.Open); CanvasGeometry geometry = CanvasGeometry.CreatePath(pathBuilder); ds.DrawGeometry(geometry, color); } } }
private CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, GeometryType type) { switch (type) { case GeometryType.Rectangle: return CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 300, 350); case GeometryType.RoundedRectangle: return CanvasGeometry.CreateRoundedRectangle(resourceCreator, 80, 80, 400, 400, 100, 100); case GeometryType.Ellipse: return CanvasGeometry.CreateEllipse(resourceCreator, 275, 275, 225, 275); case GeometryType.Star: { return Utils.CreateStarGeometry(resourceCreator, 250, new Vector2(250, 250)); } case GeometryType.Group: { CanvasGeometry geo0 = CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 100, 100); CanvasGeometry geo1 = CanvasGeometry.CreateRoundedRectangle(resourceCreator, 300, 100, 100, 100, 50, 50); CanvasPathBuilder pathBuilder = new CanvasPathBuilder(resourceCreator); pathBuilder.BeginFigure(200, 200); pathBuilder.AddLine(500, 200); pathBuilder.AddLine(200, 350); pathBuilder.EndFigure(CanvasFigureLoop.Closed); CanvasGeometry geo2 = CanvasGeometry.CreatePath(pathBuilder); return CanvasGeometry.CreateGroup(resourceCreator, new CanvasGeometry[] { geo0, geo1, geo2 }); } } System.Diagnostics.Debug.Assert(false); 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; }
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); }
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(); }
public void Draw(object ds, XQBezier qbezier, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r) { var _ds = ds as CanvasDrawingSession; double thickness = qbezier.Style.Thickness / _state.Zoom; var brush = ToColor(qbezier.Style.Fill); var pen = ToColor(qbezier.Style.Stroke); var ss = CreateStrokeStyle(qbezier.Style); CanvasGeometry g; using (var builder = new CanvasPathBuilder(_ds)) { builder.BeginFigure((float)qbezier.Point1.X, (float)qbezier.Point1.Y); builder.AddQuadraticBezier( new N.Vector2( (float)qbezier.Point2.X, (float)qbezier.Point2.Y), new N.Vector2( (float)qbezier.Point3.X, (float)qbezier.Point3.Y)); builder.EndFigure(CanvasFigureLoop.Open); g = CanvasGeometry.CreatePath(builder); } if (qbezier.IsFilled) { _ds.FillGeometry(g, brush); } if (qbezier.IsStroked) { _ds.DrawGeometry(g, pen, (float)thickness, ss); } g.Dispose(); ss.Dispose(); }
void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args) { CanvasTextFormat centeredTextFormat = new CanvasTextFormat(); centeredTextFormat.HorizontalAlignment = CanvasHorizontalAlignment.Center; centeredTextFormat.VerticalAlignment = CanvasVerticalAlignment.Center; centeredTextFormat.FontSize = 30; if (photoCanvasBitmap != null) { CanvasRenderTarget tempRenderTarget = new CanvasRenderTarget(sender, photoCanvasBitmap.Size); using (CanvasDrawingSession ds = tempRenderTarget.CreateDrawingSession()) { // Begin by drawing the captured photo into the temporary render target ds.DrawImage(photoCanvasBitmap, new System.Numerics.Vector2(0, 0)); foreach (Face face in lastCapturedFaces) { Rect faceRect = new Rect(face.FaceRectangle.Left, face.FaceRectangle.Top, face.FaceRectangle.Width, face.FaceRectangle.Height); ds.DrawRectangle(faceRect, Colors.Red); CanvasPathBuilder pathBuilder = new CanvasPathBuilder(sender); Vector2 startingPoint = new Vector2((float)(faceRect.Left + faceRect.Width / 2), (float)faceRect.Top); pathBuilder.BeginFigure(startingPoint); pathBuilder.AddLine(startingPoint - new Vector2(Math.Max(70.0f, (float)faceRect.Width / 2), 10)); pathBuilder.AddLine(startingPoint - new Vector2(Math.Max(70.0f, (float)faceRect.Width / 2), 50)); pathBuilder.AddLine(startingPoint + new Vector2(Math.Max(70.0f, (float)faceRect.Width / 2), - 50)); pathBuilder.AddLine(startingPoint + new Vector2(Math.Max(70.0f, (float)faceRect.Width / 2), - 10)); pathBuilder.EndFigure(CanvasFigureLoop.Closed); // Draw the speech bubble above the face CanvasGeometry geometry = CanvasGeometry.CreatePath(pathBuilder); ds.FillGeometry(geometry, Colors.Yellow); // Draw the person's age and gender above the face String descString = face.Attributes.Gender.ToString() + ", " + face.Attributes.Age.ToString(); ds.DrawText(descString, startingPoint - new Vector2(0, 30), Colors.Orange, centeredTextFormat); } } // End by drawing the rendertarget into the center of the screen double imageScale = Math.Min(sender.RenderSize.Width / photoCanvasBitmap.Size.Width, sender.RenderSize.Height / tempRenderTarget.Size.Height); double newWidth = imageScale * tempRenderTarget.Size.Width; double newHeight = imageScale * tempRenderTarget.Size.Height; Rect targetRect = new Rect((sender.RenderSize.Width - newWidth) / 2, (sender.RenderSize.Height - newHeight) / 2, newWidth, newHeight); args.DrawingSession.DrawImage(tempRenderTarget, targetRect); } else { args.DrawingSession.DrawText("Processing...", (float)(sender.Size.Width / 2), (float)(sender.Size.Height / 2), Colors.White, centeredTextFormat); } }
void Redraw(CanvasControl canvas, CanvasDrawEventArgs args) { for (int y = -2; y <= (int)Math.Ceiling(canvas.ActualHeight / TileSize.Height * 2) + 1; ++y) { for (int x = -2; x <= (int)Math.Ceiling(canvas.ActualWidth / TileSize.Width) + 1; ++x) { Vector2 onscreenTile = new Vector2(0.0f, 0.0f); var path = new CanvasPathBuilder(canvas); if (TileShape == MapTileShape.Square) { onscreenTile.X = (float)Math.Floor((double)(x + (y / 2))); onscreenTile.Y = (float)Math.Floor((double)(-x + (y / 2) + (y % 2))); var tileRect = new Rect(onscreenTile.X, onscreenTile.Y, 1, 1); path.BeginFigure( MapToScreen( new Vector2((float)tileRect.Left, (float)tileRect.Top))); path.AddLine( MapToScreen( new Vector2((float)tileRect.Right, (float)tileRect.Top))); path.AddLine( MapToScreen( new Vector2((float)tileRect.Right, (float)tileRect.Bottom))); path.AddLine( MapToScreen( new Vector2((float)tileRect.Left, (float)tileRect.Bottom))); path.EndFigure(CanvasFigureLoop.Closed); } else if (TileShape == MapTileShape.Hexagon) { onscreenTile.X = (float)x; onscreenTile.Y = (float)y; var topLeft = MapToScreen(onscreenTile); var bottomRight = new Vector2( (float)(topLeft.X + TileSize.Width), (float)(topLeft.Y + TileSize.Height)); #if HORIZONTAL_HEXAGONS path.BeginFigure(new Vector2( topLeft.X + 0.25f * (float)TileSize.Width, topLeft.Y)); path.AddLine(new Vector2( bottomRight.X - 0.25f * (float)TileSize.Width, topLeft.Y)); path.AddLine(new Vector2( bottomRight.X, topLeft.Y + 0.5f * (float)TileSize.Height)); path.AddLine(new Vector2( bottomRight.X - 0.25f * (float)TileSize.Width, bottomRight.Y)); path.AddLine(new Vector2( topLeft.X + 0.25f * (float)TileSize.Width, bottomRight.Y)); path.AddLine(new Vector2( topLeft.X, topLeft.Y + 0.5f * (float)TileSize.Height)); #else path.BeginFigure(new Vector2( topLeft.X + 0.5f * (float)TileSize.Width, topLeft.Y)); path.AddLine(new Vector2( bottomRight.X, topLeft.Y + 0.25f * (float)TileSize.Height)); path.AddLine(new Vector2( bottomRight.X, bottomRight.Y - 0.25f * (float)TileSize.Height)); path.AddLine(new Vector2( bottomRight.X - 0.5f * (float)TileSize.Width, bottomRight.Y)); path.AddLine(new Vector2( topLeft.X, bottomRight.Y - 0.25f * (float)TileSize.Height)); path.AddLine(new Vector2( topLeft.X, topLeft.Y + 0.25f * (float)TileSize.Height)); #endif path.EndFigure(CanvasFigureLoop.Closed); } var tile = onscreenTile + TileOffset; var geometry = CanvasGeometry.CreatePath(path); if (tile == HighlightedTile) { args.DrawingSession.FillGeometry(geometry, Colors.CornflowerBlue); args.DrawingSession.DrawGeometry(geometry, Color.FromArgb(255, 40, 40, 40)); } else { args.DrawingSession.FillGeometry(geometry, Colors.White); args.DrawingSession.DrawGeometry(geometry, Colors.Black); } } } }
private void OnIOGraphDraw(CanvasControl sender, CanvasDrawEventArgs args) { var ds = args.DrawingSession; var mostRecentBytesRead = imageStream == null ? 0 : imageStream.GetBytesRead(); bytesRead.Add(mostRecentBytesRead); // Flash the control red when there's some IO if (mostRecentBytesRead != 0) flash = 1; else flash *= 0.95f; ds.Clear(new Vector4(flash, 0, 0, 1)); ds.DrawText("Bytes read", new Rect(0, 0, sender.ActualWidth, sender.ActualHeight), Colors.DarkRed, new CanvasTextFormat() { VerticalAlignment = CanvasVerticalAlignment.Center, HorizontalAlignment = CanvasHorizontalAlignment.Left, FontSize = 12 }); int maxBytesRead = bytesRead.Max(); maxBytesRead = Math.Max(1, maxBytesRead); int displayCount = 120; // Draw a moving vertical tick to allow us to see that the graph is // updating even if nothing is being read. drawCount = (drawCount + 1) % displayCount; var vx = (1.0f - (float)drawCount / (float)displayCount) * (float)sender.ActualWidth; ds.DrawLine(vx, (float)sender.ActualHeight - 5, vx, (float)sender.ActualHeight, Colors.Gray); // Draw the graph if (bytesRead.Count > 2) { var p = new CanvasPathBuilder(sender); for (int i = 0; i < Math.Min(displayCount, bytesRead.Count); ++i) { var x = ((float)i / (float)displayCount) * (float)sender.ActualWidth; var y = (float)sender.ActualHeight - ((float)bytesRead[i] / (float)maxBytesRead) * (float)sender.ActualHeight; if (i == 0) p.BeginFigure(x, y); else p.AddLine(x, y); } p.EndFigure(CanvasFigureLoop.Open); using (var g = CanvasGeometry.CreatePath(p)) { ds.DrawGeometry(g, Colors.White, 3, new CanvasStrokeStyle() { LineJoin = CanvasLineJoin.Round }); } int toRemove = bytesRead.Count - displayCount; if (toRemove > 0) bytesRead.RemoveRange(0, toRemove); } sender.Invalidate(); }
public CanvasPathBuilder Build(ICanvasResourceCreator creator) { var path = new CanvasPathBuilder(creator); path.BeginFigure(_from); path.AddLine(_to); path.EndFigure(CanvasFigureLoop.Open); return path; }
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); }
/// <summary> /// Creates the geometry for the placeholder /// </summary> /// <param name="progress">Progress percentage</param> /// <returns>CanvasGeometry</returns> private CanvasGeometry GetPlaceHolderGeometry(int progress = -1) { using (var pathBuilder = new CanvasPathBuilder(_generator.Device)) using (var pathBuilder2 = new CanvasPathBuilder(_generator.Device)) { pathBuilder.BeginFigure(33.690f, 18.000f); pathBuilder.AddLine(30.082f, 22.793f); pathBuilder.AddLine(39.174f, 39.616f); pathBuilder.AddLine(28.297f, 25.166f); pathBuilder.AddLine(17.250f, 10.490f); pathBuilder.AddLine(3.750f, 27.596f); pathBuilder.AddLine(3.750f, 3.750f); pathBuilder.AddLine(44.250f, 3.750f); pathBuilder.AddLine(44.250f, 30.523f); pathBuilder.AddLine(33.690f, 18.000f); pathBuilder.EndFigure(CanvasFigureLoop.Closed); pathBuilder2.BeginFigure(0.000f, 0.000f); pathBuilder2.AddLine(0.000f, 32.348f); pathBuilder2.AddLine(0.000f, 48.000f); pathBuilder2.AddLine(0.000f, 48.000f); pathBuilder2.AddLine(48.000f, 48.000f); pathBuilder2.AddLine(48.000f, 48.000f); pathBuilder2.AddLine(48.000f, 34.971f); pathBuilder2.AddLine(48.000f, 0.000f); pathBuilder2.AddLine(0.000f, 0.000f); pathBuilder2.EndFigure(CanvasFigureLoop.Closed); using (var geom1 = CanvasGeometry.CreatePath(pathBuilder)) using (var geom2 = CanvasGeometry.CreatePath(pathBuilder2)) { var geom3 = geom2.CombineWith(geom1, Matrix3x2.Identity, CanvasGeometryCombine.Exclude); if ((progress < 0) || (progress >= 100)) { // No need to display the progress return geom3; } else { // Create the progress geometry using (var geom4 = CanvasGeometry.CreateRectangle(_generator.Device, 2, 40, 44, 6)) { var geom5 = geom3.CombineWith(geom4, Matrix3x2.Identity, CanvasGeometryCombine.Exclude); var width = progress * 0.40f; using (var geom6 = CanvasGeometry.CreateRectangle(_generator.Device, 4, 42, width, 2)) { return geom5.CombineWith(geom6, Matrix3x2.Identity, CanvasGeometryCombine.Union); } } } } } }
private static void drawDOMArrow(ICanvasResourceCreator device, CanvasDrawingSession ds, Point[] domPoints) { // Pen pen = new Pen(Color.Black, 3f); //pen.MiterLimit = 3; CanvasPathBuilder domPath = new CanvasPathBuilder(device); CanvasPathBuilder domArrow = new CanvasPathBuilder(device); if (domPoints[1].X == 0 && domPoints[1].Y == 0) { domPath.BeginFigure(domPoints[0].ToVector2()); domPath.AddLine(domPoints[2].ToVector2()); domPath.EndFigure(CanvasFigureLoop.Open); } else { domPath.BeginFigure(domPoints[0].ToVector2()); domPath.AddLine(domPoints[1].ToVector2()); domPath.AddLine(domPoints[2].ToVector2()); domPath.EndFigure(CanvasFigureLoop.Open); } domArrow.BeginFigure(domPoints[3].ToVector2()); domArrow.AddLine(domPoints[4].ToVector2()); domArrow.AddLine(domPoints[5].ToVector2()); domArrow.EndFigure(CanvasFigureLoop.Closed); CanvasGeometry cgPath = CanvasGeometry.CreatePath(domPath); CanvasGeometry cgArrow = CanvasGeometry.CreatePath(domArrow); ds.DrawGeometry(cgPath, Colors.Black,3f); ds.FillGeometry(cgArrow, Colors.Black); }
// changes the drawing points in graph to be actual graph geometry item which can be used for drawing private CanvasGeometry getDrawChartGeometry(CanvasDevice device, List<DataPoint> offsetList) { if (offsetList == null || offsetList.Count <= 0) { return null; } CanvasPathBuilder pathBuilder = new CanvasPathBuilder(device); //start with first point pathBuilder.BeginFigure((float)offsetList[0].OffsetX, (float)offsetList[0].OffsetY); for (int i = 0; i < offsetList.Count; i++) { // add line to the next point in the offset list pathBuilder.AddLine((float)offsetList[i].OffsetX, (float)offsetList[i].OffsetY); } //end it with open loop, we are not closed geometry object but just a chart-graph pathBuilder.EndFigure(CanvasFigureLoop.Open); return CanvasGeometry.CreatePath(pathBuilder); }
CanvasGeometry MakeConvexGeometry() { if (currentPointsInContact.Count == 0) return null; var hull = ConvexHull.Create(currentPointsInContact.Values.Select(x => x.ToVector2())); // Figure out where the center is var hullCenter = Vector2.Zero; foreach (var p in hull) { hullCenter += p; } hullCenter /= hull.Count; // Build the geometry, made up of arcs around the hull using (var builder = new CanvasPathBuilder(device)) { builder.BeginFigure(hull[0]); for (int i = 1; i <= hull.Count; ++i) { // // i-2 --- i-1 --- i --- i+1 // a --- b --- c --- d // // The bezier is between i-1 and i. We need to figure out the control points // that make this smooth. var a = hull[(i + hull.Count - 2) % hull.Count]; var b = hull[(i + hull.Count - 1) % hull.Count]; var c = hull[i % hull.Count]; var d = hull[(i + 1) % hull.Count]; var ab = Vector2.Normalize(b - a); var bc = Vector2.Normalize(c - b); var cp1 = b + Vector2.Normalize(ab + bc) * (c - b).Length() * 0.5f; var cd = Vector2.Normalize(d - c); var cp2 = c - Vector2.Normalize(bc + cd) * (c - b).Length() * 0.5f; builder.AddCubicBezier(cp1, cp2, c); } builder.EndFigure(CanvasFigureLoop.Closed); return CanvasGeometry.CreatePath(builder); } }
private static CanvasGeometry CreateHeart(ICanvasResourceCreator resourceCreator, float scale, Vector2 center) { center = center - new Vector2(center.X / 2, center.Y / 2); CanvasPathBuilder pathBuilder = new CanvasPathBuilder(resourceCreator); var begin = new Vector2(0.47f, 0.34f) * scale + center; pathBuilder.BeginFigure(begin); pathBuilder.AddCubicBezier(new Vector2(0.66f, 0.19f) * scale + center, new Vector2(0.88f, 0.30f) * scale + center, new Vector2(0.88f, 0.48f) * scale + center); pathBuilder.AddCubicBezier(new Vector2(0.88f, 0.66f) * scale + center, new Vector2(0.49f, 1) * scale + center, new Vector2(0.49f, 1)* scale + center); pathBuilder.AddCubicBezier(new Vector2(0.49f, 1) * scale + center, new Vector2(0, 0.66f) * scale + center, new Vector2(0, 0.48f) * scale + center); pathBuilder.AddCubicBezier(new Vector2(0, 0.30f) * scale + center, new Vector2(0.33f, 0.19f) * scale + center, begin); pathBuilder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin); pathBuilder.EndFigure(CanvasFigureLoop.Closed); var geometry = CanvasGeometry.CreatePath(pathBuilder); return geometry; }
//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; } }
private void DrawSelectionLasso(CanvasControl sender, CanvasDrawingSession ds) { if (selectionPolylinePoints == null) return; if (selectionPolylinePoints.Count == 0) return; CanvasPathBuilder selectionLasso = new CanvasPathBuilder(canvasControl); selectionLasso.BeginFigure(selectionPolylinePoints[0].ToVector2()); for (int i = 1; i < selectionPolylinePoints.Count; ++i) { selectionLasso.AddLine(selectionPolylinePoints[i].ToVector2()); } selectionLasso.EndFigure(CanvasFigureLoop.Open); CanvasGeometry pathGeometry = CanvasGeometry.CreatePath(selectionLasso); ds.DrawGeometry(pathGeometry, Colors.Magenta, 5.0f); }
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); } }
private CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, GeometryType type) { switch (type) { case GeometryType.Rectangle: return CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 300, 350); case GeometryType.RoundedRectangle: return CanvasGeometry.CreateRoundedRectangle(resourceCreator, 80, 80, 400, 400, 100, 100); case GeometryType.Ellipse: return CanvasGeometry.CreateEllipse(resourceCreator, 275, 275, 225, 275); case GeometryType.Star: return Utils.CreateStarGeometry(resourceCreator, 250, new Vector2(250, 250)); case GeometryType.Text: { var textFormat = new CanvasTextFormat { FontFamily = "Comic Sans MS", FontSize = 400, }; var textLayout = new CanvasTextLayout(resourceCreator, "2D", textFormat, 1000, 1000); return CanvasGeometry.CreateText(textLayout); } case GeometryType.Group: { CanvasGeometry geo0 = CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 100, 100); CanvasGeometry geo1 = CanvasGeometry.CreateRoundedRectangle(resourceCreator, 300, 100, 100, 100, 50, 50); CanvasPathBuilder pathBuilder = new CanvasPathBuilder(resourceCreator); pathBuilder.BeginFigure(200, 200); pathBuilder.AddLine(500, 200); pathBuilder.AddLine(200, 350); pathBuilder.EndFigure(CanvasFigureLoop.Closed); CanvasGeometry geo2 = CanvasGeometry.CreatePath(pathBuilder); return CanvasGeometry.CreateGroup(resourceCreator, new CanvasGeometry[] { geo0, geo1, geo2 }); } } System.Diagnostics.Debug.Assert(false); return null; }
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; } }
/// <summary> /// Draws a raindrop on canvas at the current position. /// </summary> public void Draw(RainyDay rainyday, CanvasDrawingSession context) { float orgR = r; r = 0.95f * r; if (r < 3) { clipGeo = CanvasGeometry.CreateCircle(context, new Vector2(x, y), r); } else if (colliding != null || yspeed > 2) { if (colliding != null) { var collider = colliding; r = 1.001f * (r > collider.r ? r : collider.r); x += (collider.x - x); colliding = null; } float yr = 1 + 0.1f * yspeed; using (CanvasPathBuilder path = new CanvasPathBuilder(context)) { path.BeginFigure(x - r / yr, y); path.AddCubicBezier(new Vector2(x - r, y - r * 2), new Vector2(x + r, y - r * 2), new Vector2(x + r / yr, y)); path.AddCubicBezier(new Vector2(x + r, y + yr * r), new Vector2(x - r, y + yr * r), new Vector2(x - r / yr, y)); path.EndFigure(CanvasFigureLoop.Closed); clipGeo = CanvasGeometry.CreatePath(path); } } else { clipGeo = CanvasGeometry.CreateCircle(context, new Vector2(x, y), 0.9f * r); } r = orgR; if (rainyday.Reflection != null) { using (context.CreateLayer(1, clipGeo)) { rainyday.Reflection(context, this); } } if (clipGeo != null) { clipGeo.Dispose(); } }
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); } }
void DrawBezier(CanvasDrawingSession drawingSession, Vector2 start, Vector2 ctrl0, Vector2 ctrl1, Vector2 end) { CanvasPathBuilder pathBuilder = new CanvasPathBuilder(canvasControl); pathBuilder.BeginFigure(start); pathBuilder.AddCubicBezier(ctrl0, ctrl1, end); pathBuilder.EndFigure(CanvasFigureLoop.Open); CanvasGeometry geometry = CanvasGeometry.CreatePath(pathBuilder); drawingSession.DrawGeometry(geometry, Colors.White, 5.0f); }
/*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); } }
CanvasGeometry MakeDirectionIcon() { var builder = new CanvasPathBuilder(Device); float arrowHeadSize = 15; int lineCount = 4; var verticalLineTop = new Vector2(0, 0); var lineHeight = new Vector2(0, 20); var lineWidth = new Vector2(lineHeight.Y * lineCount, 0); var verticalLineBottom = verticalLineTop + lineHeight * lineCount; var arrowHeadWidth = new Vector2(arrowHeadSize / 2, 0); var arrowHeadHeight = new Vector2(0, arrowHeadSize / 2); // This is what we're drawing: // // |-------> // |-------> // |-------> // V // A single stroke draws the first horizontal line and the vertical line: // // |------- // | // | // // builder.BeginFigure(verticalLineTop + lineWidth); builder.AddLine(verticalLineTop); builder.AddLine(verticalLineBottom); builder.EndFigure(CanvasFigureLoop.Open); // // Now draw the bottom arrow // builder.BeginFigure(verticalLineBottom - arrowHeadWidth - arrowHeadHeight); builder.AddLine(verticalLineBottom); builder.AddLine(verticalLineBottom + arrowHeadWidth - arrowHeadHeight); builder.EndFigure(CanvasFigureLoop.Open); // // Now the horizontal lines and arrows // for (int i = 0; i < lineCount; ++i) { var left = verticalLineTop + lineHeight * i; var right = left + lineWidth; // The first line we drew already, so we don't need to draw it again if (i != 0) { // Draw the horizontal line builder.BeginFigure(left); builder.AddLine(right); builder.EndFigure(CanvasFigureLoop.Open); } // Draw the arrow at the end of the line builder.BeginFigure(right - arrowHeadWidth - arrowHeadHeight); builder.AddLine(right); builder.AddLine(right - arrowHeadWidth + arrowHeadHeight); builder.EndFigure(CanvasFigureLoop.Open); } return CanvasGeometry.CreatePath(builder); }