CanvasGeometry Geometry() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(-46.8400002F, -15F)); builder.AddLine(new Vector2(46.8400002F, -15F)); builder.AddCubicBezier(new Vector2(52.7799988F, -15F), new Vector2(56.5089989F, -14.0719995F), new Vector2(59.7680016F, -12.3290005F)); builder.AddCubicBezier(new Vector2(63.0270004F, -10.5860004F), new Vector2(65.5859985F, -8.02799988F), new Vector2(67.3290024F, -4.76900005F)); builder.AddCubicBezier(new Vector2(69.0719986F, -1.50999999F), new Vector2(70F, 2.22000003F), new Vector2(70F, 8.15999985F)); builder.AddLine(new Vector2(70F, 11.8400002F)); builder.AddCubicBezier(new Vector2(70F, 17.7800007F), new Vector2(69.0719986F, 21.5090008F), new Vector2(67.3290024F, 24.7679996F)); builder.AddCubicBezier(new Vector2(65.5859985F, 28.0270004F), new Vector2(63.0270004F, 30.5860004F), new Vector2(59.7680016F, 32.3289986F)); builder.AddCubicBezier(new Vector2(56.5089989F, 34.0719986F), new Vector2(52.7799988F, 35F), new Vector2(46.8400002F, 35F)); builder.AddLine(new Vector2(-46.8400002F, 35F)); builder.AddCubicBezier(new Vector2(-52.7799988F, 35F), new Vector2(-56.5089989F, 34.0719986F), new Vector2(-59.7680016F, 32.3289986F)); builder.AddCubicBezier(new Vector2(-63.0270004F, 30.5860004F), new Vector2(-65.5859985F, 28.0270004F), new Vector2(-67.3290024F, 24.7679996F)); builder.AddCubicBezier(new Vector2(-69.0719986F, 21.5090008F), new Vector2(-70F, 17.7800007F), new Vector2(-70F, 11.8400002F)); builder.AddLine(new Vector2(-70F, 8.15999985F)); builder.AddCubicBezier(new Vector2(-70F, 2.22000003F), new Vector2(-69.0719986F, -1.50999999F), new Vector2(-67.3290024F, -4.76900005F)); builder.AddCubicBezier(new Vector2(-65.5859985F, -8.02799988F), new Vector2(-63.0270004F, -10.5860004F), new Vector2(-59.7680016F, -12.3290005F)); builder.AddCubicBezier(new Vector2(-56.5089989F, -14.0719995F), new Vector2(-52.7799988F, -15F), new Vector2(-46.8400002F, -15F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
private void SimplePathImperative_Click(object sender, RoutedEventArgs e) { // Same steps as for SimpleShapeImperative_Click to create, size and host a ShapeVisual compositor = Window.Current.Compositor; Windows.UI.Composition.ShapeVisual shape = compositor.CreateShapeVisual(); SetVisualOnElement(shape); // use Win2D's CanvasPathBuilder to create a simple path CanvasPathBuilder pathBuilder = new CanvasPathBuilder(CanvasDevice.GetSharedDevice()); pathBuilder.BeginFigure(1, 1); pathBuilder.AddLine(300, 300); pathBuilder.AddLine(1, 300); pathBuilder.EndFigure(CanvasFigureLoop.Closed); // create a Win2D CanvasGeomtryobject from the path CanvasGeometry triangleGeometry = CanvasGeometry.CreatePath(pathBuilder); // create a CompositionPath from the Win2D geometry CompositionPath trianglePath = new CompositionPath(triangleGeometry); // create a CompositionPathGeometry from the composition path CompositionPathGeometry compositionPathGeometry = compositor.CreatePathGeometry(trianglePath); // create a SpriteShape from the CompositionPathGeometry, give it a gradient fill and add to our ShapeVisual CompositionSpriteShape spriteShape = compositor.CreateSpriteShape(compositionPathGeometry); spriteShape.FillBrush = CreateGradientBrush(); shape.Shapes.Add(spriteShape); }
// use for shape (path) private CanvasPathBuilder DrawPath(CanvasPathBuilder p, List <DrawablePoint> left, List <DrawablePoint> right) { int count = left.Count; for (int i = 0; i < count - 1; ++i) { p.BeginFigure(left[i].X, left[i].Y); p.AddCubicBezier( new Vector2(left[i].OutX, left[i].OutY), new Vector2(left[i + 1].InX, left[i + 1].InY), new Vector2(left[i + 1].X, left[i + 1].Y)); p.AddLine(right[i + 1].X, right[i + 1].Y); p.AddCubicBezier( new Vector2(right[i + 1].InX, right[i + 1].InY), new Vector2(right[i].OutX, right[i].OutY), new Vector2(right[i].X, right[i].Y)); p.AddLine(left[i].X, left[i].Y); p.EndFigure(CanvasFigureLoop.Open); } float r = left[0].GetDistance(right[0]); AddArc(p, (left[0].X + right[0].X) / 2 - r / 2, (left[0].Y + right[0].Y) / 2 - r / 2, r, r); r = left[count - 1].GetDistance(right[count - 1]); AddArc(p, (left[count - 1].X + right[count - 1].X) / 2 - r / 2, (left[count - 1].Y + right[count - 1].Y) / 2 - r / 2, r, r); return(p); }
// - - - Shape tree root for layer: icon // - - ShapeGroup: s CanvasGeometry Geometry_0() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); builder.BeginFigure(new Vector2(42.8370018F, -8.77700043F)); builder.AddCubicBezier(new Vector2(48.230999F, -3.148F), new Vector2(53.9420013F, 0.925999999F), new Vector2(60F, 3.47099996F)); builder.AddCubicBezier(new Vector2(63.2330017F, 4.829F), new Vector2(66.5650024F, 5.75299978F), new Vector2(70F, 6.24499989F)); builder.AddCubicBezier(new Vector2(71.9660034F, 6.52600002F), new Vector2(73.9660034F, 6.66699982F), new Vector2(76F, 6.66699982F)); builder.AddCubicBezier(new Vector2(77.9329987F, 6.66699982F), new Vector2(79.5459976F, 8.09500027F), new Vector2(79.9189987F, 9.99400043F)); builder.AddLine(new Vector2(80F, 10.8330002F)); builder.AddLine(new Vector2(80F, 35.8440018F)); builder.AddCubicBezier(new Vector2(80F, 62.6629982F), new Vector2(66.8700027F, 80.8960037F), new Vector2(41.2649994F, 89.7860031F)); builder.AddCubicBezier(new Vector2(40.4440002F, 90.0709991F), new Vector2(39.5559998F, 90.0709991F), new Vector2(38.7350006F, 89.7860031F)); builder.AddCubicBezier(new Vector2(31.4820004F, 87.2679977F), new Vector2(25.2310009F, 84F), new Vector2(19.9950008F, 80F)); builder.AddCubicBezier(new Vector2(16.1459999F, 77.0599976F), new Vector2(12.8470001F, 73.723999F), new Vector2(10.1020002F, 70F)); builder.AddCubicBezier(new Vector2(3.83500004F, 61.4980011F), new Vector2(0.458999991F, 50.9700012F), new Vector2(0.0439999998F, 38.4970016F)); builder.AddLine(new Vector2(0F, 35.8440018F)); builder.AddLine(new Vector2(0F, 10.8330002F)); builder.AddCubicBezier(new Vector2(0F, 8.53199959F), new Vector2(1.79100001F, 6.66699982F), new Vector2(4F, 6.66699982F)); builder.AddCubicBezier(new Vector2(16.2339993F, 6.66699982F), new Vector2(27.2329998F, 1.57500005F), new Vector2(37.1780014F, -8.77999973F)); builder.AddCubicBezier(new Vector2(38.7410011F, -10.408F), new Vector2(41.276001F, -10.4069996F), new Vector2(42.8370018F, -8.77700043F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
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); } } }
private static CanvasGeometry CreateCapsuleCore(ICanvasResourceCreator resourceCreator, float verticalLength, Vector2 horizontalUnit, Vector2 centerTop, Vector2 centerLeft, Vector2 centerRight, Vector2 centerBottom, Vector2 leftTop, Vector2 rightTop, Vector2 rightBottom, Vector2 leftBottom) { // Horizontal Vector2 horizontal2 = 0.5f * verticalLength * horizontalUnit; Vector2 horizontal448 = horizontal2 * 0.448f; // vector / (1 - 0.552f) // Vertical Vector2 vertical276 = (centerBottom - centerTop) * 0.276f; // vector / 2 * 0.552f // Control Vector2 left2 = centerLeft - vertical276; Vector2 leftTop_Top = leftTop + horizontal2; Vector2 leftTop_Top1 = leftTop + horizontal448; Vector2 rightTop_Top = rightTop - horizontal2; Vector2 rightTop_Top2 = rightTop - horizontal448; Vector2 right1 = centerRight - vertical276; Vector2 right2 = centerRight + vertical276; Vector2 rightBottom_Bottom = rightBottom - horizontal2; Vector2 rightBottom_Bottom1 = rightBottom - horizontal448; Vector2 leftBottom_Bottom = leftBottom + horizontal2; Vector2 leftBottom_Bottom2 = leftBottom + horizontal448; Vector2 left1 = centerLeft + vertical276; // Path CanvasPathBuilder pathBuilder = new CanvasPathBuilder(resourceCreator); { pathBuilder.BeginFigure(centerLeft); pathBuilder.AddCubicBezier(left2, leftTop_Top1, leftTop_Top); pathBuilder.AddLine(rightTop_Top); pathBuilder.AddCubicBezier(rightTop_Top2, right1, centerRight); pathBuilder.AddCubicBezier(right2, rightBottom_Bottom1, rightBottom_Bottom); pathBuilder.AddLine(leftBottom_Bottom); pathBuilder.AddCubicBezier(leftBottom_Bottom2, left1, centerLeft); pathBuilder.EndFigure(CanvasFigureLoop.Closed); } // Geometry return(CanvasGeometry.CreatePath(pathBuilder)); }
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 CreateResources(ICanvasResourceCreator resourceCreator) { DestroyResources(); // define path var pb = new CanvasPathBuilder(resourceCreator); var radiusH = HexUtils.GetRadiusHeight(Radius); pb.BeginFigure(-1 * Radius * HexUtils.COS60, radiusH); pb.AddLine(Radius * HexUtils.COS60, radiusH); pb.AddLine(Radius, 0); pb.AddLine(Radius * HexUtils.COS60, -1 * radiusH); pb.AddLine(-1 * Radius * HexUtils.COS60, -1 * radiusH); pb.AddLine(-1 * Radius, 0); pb.EndFigure(CanvasFigureLoop.Closed); // create and cache _strokeStyle = new CanvasStrokeStyle(); var geo = CanvasGeometry.CreatePath(pb); if (Filled) { _geo = CanvasCachedGeometry.CreateFill(geo); } else { _geo = CanvasCachedGeometry.CreateStroke(geo, Style.StrokeWidth, _strokeStyle); } }
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); } } }
/// <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); }
//Heart:心形 public static CanvasGeometry CreateHeart(ICanvasResourceCreator rc, Vector2 start, Vector2 end) { //基本向量 Vector2 vector = end - start; float rotation = 修图.Library.Method.Tanh(vector);//初始角度 float LengthHalf = vector.Length() / 2; Vector2 center = (end + start) / 2; //正方形中心点 float radius = LengthHalf / (float)Math.Sqrt(2.0d); //圆半径 //左右角度/向量 double rotationLeft = rotation + Math.PI / 2; double rotationRight = rotation - Math.PI / 2; Vector2 left = new Point(Math.Cos(rotationLeft), Math.Sin(rotationLeft)).ToVector2() * LengthHalf + center; //左点 Vector2 right = new Point(Math.Cos(rotationRight), Math.Sin(rotationRight)).ToVector2() * LengthHalf + center; //右点 //画几何 CanvasPathBuilder pathBuilder = new CanvasPathBuilder(rc); pathBuilder.BeginFigure(start); //屁眼 pathBuilder.AddArc(left, radius, radius, (float)Math.PI, CanvasSweepDirection.CounterClockwise, CanvasArcSize.Large); //左下角 pathBuilder.AddLine(end); pathBuilder.AddLine(right); pathBuilder.AddArc(start, radius, radius, (float)Math.PI, CanvasSweepDirection.CounterClockwise, CanvasArcSize.Large);//右下角 pathBuilder.EndFigure(CanvasFigureLoop.Closed); return(CanvasGeometry.CreatePath(pathBuilder)); }
private 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); }
// - - - Masks CanvasGeometry Geometry_1() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(53.6599998F, 85.5F)); builder.AddLine(new Vector2(147.339996F, 85.5F)); builder.AddCubicBezier(new Vector2(153.279999F, 85.5F), new Vector2(157.009003F, 86.4280014F), new Vector2(160.268005F, 88.1709976F)); builder.AddCubicBezier(new Vector2(163.526993F, 89.9140015F), new Vector2(166.085999F, 92.4729996F), new Vector2(167.828995F, 95.7320023F)); builder.AddCubicBezier(new Vector2(169.572006F, 98.9909973F), new Vector2(170.5F, 102.720001F), new Vector2(170.5F, 108.660004F)); builder.AddLine(new Vector2(170.5F, 112.339996F)); builder.AddCubicBezier(new Vector2(170.5F, 118.279999F), new Vector2(169.572006F, 122.009003F), new Vector2(167.828995F, 125.267998F)); builder.AddCubicBezier(new Vector2(166.085999F, 128.526993F), new Vector2(163.526993F, 131.085999F), new Vector2(160.268005F, 132.828995F)); builder.AddCubicBezier(new Vector2(157.009003F, 134.572006F), new Vector2(153.279999F, 135.5F), new Vector2(147.339996F, 135.5F)); builder.AddLine(new Vector2(53.6599998F, 135.5F)); builder.AddCubicBezier(new Vector2(47.7200012F, 135.5F), new Vector2(43.9910011F, 134.572006F), new Vector2(40.7319984F, 132.828995F)); builder.AddCubicBezier(new Vector2(37.4729996F, 131.085999F), new Vector2(34.9140015F, 128.526993F), new Vector2(33.1710014F, 125.267998F)); builder.AddCubicBezier(new Vector2(31.4279995F, 122.009003F), new Vector2(30.5F, 118.279999F), new Vector2(30.5F, 112.339996F)); builder.AddLine(new Vector2(30.5F, 108.660004F)); builder.AddCubicBezier(new Vector2(30.5F, 102.720001F), new Vector2(31.4279995F, 98.9909973F), new Vector2(33.1710014F, 95.7320023F)); builder.AddCubicBezier(new Vector2(34.9140015F, 92.4729996F), new Vector2(37.4729996F, 89.9140015F), new Vector2(40.7319984F, 88.1709976F)); builder.AddCubicBezier(new Vector2(43.9910011F, 86.4280014F), new Vector2(47.7200012F, 85.5F), new Vector2(53.6599998F, 85.5F)); builder.EndFigure(CanvasFigureLoop.Closed); result = CanvasGeometry.CreatePath(builder); } return(result); }
public void DrawCommon(CanvasDrawingSession g) { //save tansform var save = g.Transform; g.FillRectangle(new Rect(P11.X - 2, P11.Y - 2, 4, 4), Pen.Color); using (var pathBuilder = new CanvasPathBuilder(g)) { pathBuilder.BeginFigure(P11); pathBuilder.AddLine(P12); pathBuilder.AddLine(P22); pathBuilder.AddLine(P21); pathBuilder.EndFigure(CanvasFigureLoop.Closed); g.DrawGeometry(CanvasGeometry.CreatePath(pathBuilder), Pen.Color, Pen.Width); } if (IsGlyphVisible) { drawOrthogonalGlyph(g, P11, P12, P21); drawOrthogonalGlyph(g, P12, P11, P22); drawOrthogonalGlyph(g, P21, P11, P22); drawOrthogonalGlyph(g, P22, P21, P12); } drawMeasure(g, P11, P12); drawMeasure(g, P12, P22); drawMeasure(g, P22, P21); drawMeasure(g, P21, P11); //recover transform g.Transform = save; }
public UIBezierPath(Rect rect) { mBuilder = new CanvasPathBuilder(CanvasDevice.GetSharedDevice()); mBuilder.BeginFigure((float)rect.X, (float)rect.Y); mBuilder.AddLine((float)rect.Right, (float)rect.Y); mBuilder.AddLine((float)rect.Right, (float)rect.Bottom); mBuilder.AddLine((float)rect.X, (float)rect.Bottom); }
public void AddLine(float x, float y) { if (pathBuilder == null) { throw new Exception("Path is closed"); } pathBuilder.AddLine(x, y); }
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); } }
//private CanvasGeometry CreatePath() //{ // var pathBuilder = new CanvasPathBuilder(_device); // pathBuilder.BeginFigure(1, 1); // //pathBuilder.AddLine(30, 30); // //pathBuilder.AddLine(1, 30); // pathBuilder.AddLine(30, 1); // pathBuilder.AddLine(30, 30); // pathBuilder.EndFigure(CanvasFigureLoop.Closed); // return CanvasGeometry.CreatePath(pathBuilder); //} private CanvasGeometry CreatePath(Point point1, Point point2, Point point3) { var pathBuilder = new CanvasPathBuilder(_device); pathBuilder.BeginFigure((float)point1.X, (float)point1.Y); pathBuilder.AddLine((float)point2.X, (float)point2.Y); pathBuilder.AddLine((float)point3.X, (float)point3.Y); pathBuilder.EndFigure(CanvasFigureLoop.Closed); return(CanvasGeometry.CreatePath(pathBuilder)); }
private void CreateAnimatedChart1() { var shapeVisual = _compositor.CreateShapeVisual(); shapeVisual.RelativeSizeAdjustment = Vector2.One; var viewBox = _compositor.CreateViewBox(); viewBox.Size = new Vector2(500, 200); viewBox.Stretch = CompositionStretch.Fill; shapeVisual.ViewBox = viewBox; ElementCompositionPreview.SetElementChildVisual(ChartArea1, shapeVisual); var chart = _compositor.CreateSpriteShape(); chart.CenterPoint = viewBox.Size / 2; chart.FillBrush = _compositor.CreateColorBrush(Colors.LightBlue); var chartGeometry = _compositor.CreatePathGeometry(); var builder1 = new CanvasPathBuilder(null); builder1.BeginFigure(new Vector2(0, 200)); builder1.AddLine(new Vector2(0, 100)); builder1.AddCubicBezier(new Vector2(30, 100), new Vector2(60), new Vector2(100, 60)); builder1.AddCubicBezier(new Vector2(140, 60), new Vector2(200, 120), new Vector2(250, 120)); builder1.AddCubicBezier(new Vector2(350, 120), new Vector2(340, 40), new Vector2(380, 40)); builder1.AddCubicBezier(new Vector2(420, 40), new Vector2(400, 120), new Vector2(500, 120)); builder1.AddLine(new Vector2(500, 200)); builder1.EndFigure(CanvasFigureLoop.Closed); var curvedPath = new CompositionPath(CanvasGeometry.CreatePath(builder1)); var builder2 = new CanvasPathBuilder(null); builder2.BeginFigure(new Vector2(0, 200)); builder2.AddLine(new Vector2(0, 100)); builder2.AddCubicBezier(new Vector2(30, 100), new Vector2(60, 100), new Vector2(100, 100)); builder2.AddCubicBezier(new Vector2(140, 100), new Vector2(200, 100), new Vector2(250, 100)); builder2.AddCubicBezier(new Vector2(350, 100), new Vector2(340, 100), new Vector2(380, 100)); builder2.AddCubicBezier(new Vector2(420, 100), new Vector2(400, 100), new Vector2(500, 100)); builder2.AddLine(new Vector2(500, 200)); builder2.EndFigure(CanvasFigureLoop.Closed); var flatPath = new CompositionPath(CanvasGeometry.CreatePath(builder2)); chartGeometry.Path = flatPath; chart.Geometry = chartGeometry; shapeVisual.Shapes.Add(chart); var pathAnimation = _compositor.CreatePathKeyFrameAnimation(); pathAnimation.InsertKeyFrame(1, curvedPath); pathAnimation.Duration = TimeSpan.FromMilliseconds(800); pathAnimation.DelayTime = TimeSpan.FromMilliseconds(2000); chartGeometry.StartAnimation("Path", pathAnimation); }
public void Draw(float f, float f2, float f3, float f4, CanvasDrawingSession canvas, Color paint, float f5, float f6) { var builder = new CanvasPathBuilder(canvas); builder.BeginFigure(f3, f4); builder.AddLine(f, f4); int i = 0; while (true) { float f10 = i; float f11 = N; if (f10 <= f11) { if (i == 0) { float f12 = progress[i]; builder.AddLine(f, (f2 - (radius[i] * (1.0f - f12) + radiusNext[i] * f12)) * f6 + f5 * (1.0f - f6)); } else { float[] fArr = progress; int i2 = i - 1; float f13 = fArr[i2]; float[] fArr2 = radius; float f14 = fArr2[i2] * (1.0f - f13); float[] fArr3 = radiusNext; float f15 = fArr[i]; float f16 = fArr2[i] * (1.0f - f15) + fArr3[i] * f15; float f17 = f3 - f; float f18 = f17 / f11 * i2; float f19 = f17 / f11 * f10; float f20 = f18 + (f19 - f18) / 2.0f; float f21 = (1.0f - f6) * f5; float f22 = (f2 - f16) * f6 + f21; builder.AddCubicBezier(new Vector2(f20, (f2 - (f14 + fArr3[i2] * f13)) * f6 + f21), new Vector2(f20, f22), new Vector2(f19, f22)); if (f10 == N) { builder.AddLine(f3, f4); } } i++; } else { builder.EndFigure(CanvasFigureLoop.Closed); canvas.FillGeometry(CanvasGeometry.CreatePath(builder), paint); return; } } }
CanvasGeometry Geometry_1() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(14.7390003F, -10.2580004F)); builder.AddLine(new Vector2(-5.97599983F, 10.2580004F)); builder.AddLine(new Vector2(-14.7390003F, 1.49399996F)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
CanvasGeometry Geometry_1() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(-30F, 0F)); builder.AddLine(new Vector2(-10F, 20F)); builder.AddLine(new Vector2(30F, -20F)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
CanvasGeometry Geometry_3() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(-5, 0.5F)); builder.AddLine(new Vector2(-2, 3.5F)); builder.AddLine(new Vector2(5, -3.5F)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
CanvasGeometry Geometry() { CanvasGeometry result; using (var builder = new CanvasPathBuilder(null)) { builder.BeginFigure(new Vector2(65, 1.5F)); builder.AddLine(new Vector2(-14, 63)); builder.AddLine(new Vector2(-51.5F, 16)); builder.EndFigure(CanvasFigureLoop.Open); result = CanvasGeometry.CreatePath(builder); } return(result); }
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 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); } } }
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); } }
//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)); }
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; } }
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); }
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 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 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(); }
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); }
/// <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); } } } } } }
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 static CanvasGeometry ToCanvasGeometry(this XPathGeometry pg, CanvasDrawingSession ds) { CanvasGeometry g; using (var builder = new CanvasPathBuilder(ds)) { if (pg.FillRule == XFillRule.EvenOdd) builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Alternate); else builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding); foreach (var pf in pg.Figures) { builder.BeginFigure( (float)pf.StartPoint.X, (float)pf.StartPoint.Y, pf.IsFilled ? CanvasFigureFill.Default : CanvasFigureFill.DoesNotAffectFills); foreach (var segment in pf.Segments) { var options = CanvasFigureSegmentOptions.None; if (!segment.IsStroked) options |= CanvasFigureSegmentOptions.ForceUnstroked; if (segment.IsSmoothJoin) options |= CanvasFigureSegmentOptions.ForceRoundLineJoin; builder.SetSegmentOptions(options); if (segment is XArcSegment) { var arcSegment = segment as XArcSegment; builder.AddArc( new N.Vector2( (float)arcSegment.Point.X, (float)arcSegment.Point.Y), (float)(arcSegment.Size.Width / 2.0), (float)(arcSegment.Size.Height / 2.0), (float)arcSegment.RotationAngle, arcSegment.SweepDirection == XSweepDirection.Clockwise ? CanvasSweepDirection.Clockwise : CanvasSweepDirection.CounterClockwise, arcSegment.IsLargeArc ? CanvasArcSize.Large : CanvasArcSize.Small); } else if (segment is XBezierSegment) { var bezierSegment = segment as XBezierSegment; builder.AddCubicBezier( new N.Vector2( (float)bezierSegment.Point1.X, (float)bezierSegment.Point1.Y), new N.Vector2( (float)bezierSegment.Point2.X, (float)bezierSegment.Point2.Y), new N.Vector2( (float)bezierSegment.Point3.X, (float)bezierSegment.Point3.Y)); } else if (segment is XLineSegment) { var lineSegment = segment as XLineSegment; builder.AddLine( new N.Vector2( (float)lineSegment.Point.X, (float)lineSegment.Point.Y)); } else if (segment is XPolyBezierSegment) { var polyBezierSegment = segment as XPolyBezierSegment; if (polyBezierSegment.Points.Count >= 3) { builder.AddCubicBezier( new N.Vector2( (float)polyBezierSegment.Points[0].X, (float)polyBezierSegment.Points[0].Y), new N.Vector2( (float)polyBezierSegment.Points[1].X, (float)polyBezierSegment.Points[1].Y), new N.Vector2( (float)polyBezierSegment.Points[2].X, (float)polyBezierSegment.Points[2].Y)); } if (polyBezierSegment.Points.Count > 3 && polyBezierSegment.Points.Count % 3 == 0) { for (int i = 3; i < polyBezierSegment.Points.Count; i += 3) { builder.AddCubicBezier( new N.Vector2( (float)polyBezierSegment.Points[i].X, (float)polyBezierSegment.Points[i].Y), new N.Vector2( (float)polyBezierSegment.Points[i + 1].X, (float)polyBezierSegment.Points[i + 1].Y), new N.Vector2( (float)polyBezierSegment.Points[i + 2].X, (float)polyBezierSegment.Points[i + 2].Y)); } } } else if (segment is XPolyLineSegment) { var polyLineSegment = segment as XPolyLineSegment; if (polyLineSegment.Points.Count >= 1) { builder.AddLine( new N.Vector2( (float)polyLineSegment.Points[0].X, (float)polyLineSegment.Points[0].Y)); } if (polyLineSegment.Points.Count > 1) { for (int i = 1; i < polyLineSegment.Points.Count; i++) { builder.AddLine( new N.Vector2( (float)polyLineSegment.Points[i].X, (float)polyLineSegment.Points[i].Y)); } } } else if (segment is XPolyQuadraticBezierSegment) { var polyQuadraticSegment = segment as XPolyQuadraticBezierSegment; if (polyQuadraticSegment.Points.Count >= 2) { builder.AddQuadraticBezier( new N.Vector2( (float)polyQuadraticSegment.Points[0].X, (float)polyQuadraticSegment.Points[0].Y), new N.Vector2( (float)polyQuadraticSegment.Points[1].X, (float)polyQuadraticSegment.Points[1].Y)); } if (polyQuadraticSegment.Points.Count > 2 && polyQuadraticSegment.Points.Count % 2 == 0) { for (int i = 3; i < polyQuadraticSegment.Points.Count; i += 3) { builder.AddQuadraticBezier( new N.Vector2( (float)polyQuadraticSegment.Points[i].X, (float)polyQuadraticSegment.Points[i].Y), new N.Vector2( (float)polyQuadraticSegment.Points[i + 1].X, (float)polyQuadraticSegment.Points[i + 1].Y)); } } } else if (segment is XQuadraticBezierSegment) { var qbezierSegment = segment as XQuadraticBezierSegment; builder.AddQuadraticBezier( new N.Vector2( (float)qbezierSegment.Point1.X, (float)qbezierSegment.Point1.Y), new N.Vector2( (float)qbezierSegment.Point2.X, (float)qbezierSegment.Point2.Y)); } else { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); } } builder.EndFigure(pf.IsClosed ? CanvasFigureLoop.Closed : CanvasFigureLoop.Open); } g = CanvasGeometry.CreatePath(builder); } return g; }
/*public 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); } }
// 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); }
public CanvasPathBuilder Build(ICanvasResourceCreator creator) { var path = new CanvasPathBuilder(creator); path.BeginFigure(_from); path.AddLine(_to); path.EndFigure(CanvasFigureLoop.Open); return path; }
//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 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 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); }
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); } }
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); }
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; }