public void PathEllipse(Point center, double radiusX, double radiusY, double fromAngle, double toAngle) { if (fromAngle == toAngle) { return; } if (MathEx.AmostZero(radiusX) && MathEx.AmostZero(radiusY)) { return; } var segmentCount = Math.Max((int)(radiusX + radiusY - 1), 1); if (fromAngle < toAngle) { var unit = (toAngle - fromAngle) / segmentCount; for (int i = 0; i <= segmentCount; i++) { var angle = fromAngle + unit * i; var p = MathEx.EvaluateEllipse(center, radiusX, radiusY, angle); PathLineTo(p); } } else { var unit = (fromAngle - toAngle) / segmentCount; for (int i = 0; i <= segmentCount; i++) { var angle = fromAngle - unit * i; var p = MathEx.EvaluateEllipse(center, radiusX, radiusY, angle); PathLineTo(p); } } }
internal static void DrawArrow(this Cairo.Context g, Point p0, Point p1) { var x0 = p0.X; var y0 = p0.Y; var x1 = p1.X; var y1 = p1.Y; var dx = x1 - x0; var dy = y1 - y0; if (MathEx.AmostZero(dx) && MathEx.AmostZero(dy)) { return; } var n0 = new Vector(-dy, dx); n0.Normalize(); var n1 = new Vector(dy, -dx); n1.Normalize(); var B = new Point(x1, y1); var d = new Vector(x0 - x1, y0 - y1); d.Normalize(); var arrowEnd0 = B + 20 * (d + n0); var arrowEnd1 = B + 20 * (d + n1); g.MoveTo(x1, y1); g.LineTo(new Cairo.PointD(arrowEnd0.X, arrowEnd0.Y)); g.MoveTo(x1, y1); g.LineTo(new Cairo.PointD(arrowEnd1.X, arrowEnd1.Y)); g.MoveTo(x1, y1); }
/// <summary> /// (Fast) adds an arc from angle1 to angle2 to the current path. /// Starts from +x, then clock-wise to +y, -x,-y, then ends at +x. /// </summary> /// <param name="center">the center of the arc</param> /// <param name="radius">the radius of the arc</param> /// <param name="amin">angle1 = amin * 2π * 1/12</param> /// <param name="amax">angle1 = amax * 2π * 1/12</param> public void PathArcFast(Point center, double radius, int amin, int amax) { if (amin > amax) { return; } if (MathEx.AmostZero(radius)) { return; } Path.Capacity = Path.Count + amax - amin + 1; for (int a = amin; a <= amax; a++) { Point c = CirclePoints[a % CirclePoints.Length]; var p = new Point(center.X + c.X * radius, center.Y + c.Y * radius); if (a == amin) { this.PathMoveTo(p); } else { this.PathLineTo(p); } } }
public void AddRectFilledGradient(Point a, Point b, Color topColor, Color bottomColor) { if (MathEx.AmostZero(topColor.A) && MathEx.AmostZero(bottomColor.A)) { return; } this.ShapeMesh.PrimReserve(6, 4); this.PrimRectGradient(a, b, topColor, bottomColor); }
public static void SaveToPng(List <LibTessDotNet.ContourVertex> path) { if (path == null || path.Count <= 1) { return; } using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.Argb32, (int)Form.current.Size.Width, (int)Form.current.Size.Height)) using (Cairo.Context g = new Cairo.Context(surface)) { g.MoveTo(path[0].Position.X, path[0].Position.Y); for (int i = 1; i < path.Count; i++) { var x0 = path[i - 1].Position.X; var y0 = path[i - 1].Position.Y; var x1 = path[i].Position.X; var y1 = path[i].Position.Y; g.LineTo(x1, y1); { // draw index number g.RelMoveTo(5, 5); g.ShowText(i.ToString()); g.MoveTo(x1, y1); // draw arrow var dx = x1 - x0; var dy = y1 - y0; if (MathEx.AmostZero(dx) && MathEx.AmostZero(dy)) { continue; } var n0 = new Vector(-dy, dx); n0.Normalize(); var n1 = new Vector(dy, -dx); n1.Normalize(); var B = new Point(x1, y1); var d = new Vector(x0 - x1, y0 - y1); d.Normalize(); var arrowEnd0 = B + 5 * (d + n0); var arrowEnd1 = B + 5 * (d + n1); g.MoveTo(x1, y1); g.LineTo(new Cairo.PointD(arrowEnd0.X, arrowEnd0.Y)); g.MoveTo(x1, y1); g.LineTo(new Cairo.PointD(arrowEnd1.X, arrowEnd1.Y)); g.MoveTo(x1, y1); } } g.Stroke(); surface.WriteToPng(@"D:\contour_test.png"); } }
private void DrawOutline(StyleRuleSet style, Rect borderBoxRect) { var outlineWidth = style.Get <double>(GUIStyleName.OutlineWidth); if (!MathEx.AmostZero(outlineWidth)) { var outlineColor = style.Get <Color>(GUIStyleName.OutlineColor); if (!MathEx.AmostZero(outlineColor.A)) { this.PathRect(borderBoxRect.TopLeft, borderBoxRect.BottomRight); this.PathStroke(outlineColor, true, outlineWidth); } } }
public static void SaveToPng(List <List <Point> > paths, string filePath) { using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 2000, 2000)) using (Cairo.Context g = new Cairo.Context(surface)) { foreach (var path in paths) { if (path == null || path.Count <= 1) { return; } g.MoveTo(path[0].X, path[0].Y); for (int i = 1; i < path.Count; i++) { var x0 = path[i - 1].X; var y0 = path[i - 1].Y; var x1 = path[i].X; var y1 = path[i].Y; g.LineTo(x1, y1); var dx = x1 - x0; var dy = y1 - y0; if (MathEx.AmostZero(dx) && MathEx.AmostZero(dy)) { continue; } var n0 = new Vector(-dy, dx); n0.Normalize(); var n1 = new Vector(dy, -dx); n1.Normalize(); var B = new Point(x1, y1); var d = new Vector(x0 - x1, y0 - y1); d.Normalize(); var arrowEnd0 = B + 5 * (d + n0); var arrowEnd1 = B + 5 * (d + n1); g.MoveTo(x1, y1); g.LineTo(new Cairo.PointD(arrowEnd0.X, arrowEnd0.Y)); g.MoveTo(x1, y1); g.LineTo(new Cairo.PointD(arrowEnd1.X, arrowEnd1.Y)); g.MoveTo(x1, y1); } g.Stroke(); } surface.WriteToPng(filePath); } }
private static void DrawOutline(DrawingContext dc, StyleRuleSet style, Rect borderBoxRect) { var outlineWidth = style.Get <double>(StylePropertyName.OutlineWidth); if (MathEx.AmostZero(outlineWidth)) { return; } var outlineColor = style.Get <Color>(StylePropertyName.OutlineColor); if (MathEx.AmostZero(outlineColor.A)) { return; } dc.DrawRectangle(null, new Pen(outlineColor, outlineWidth), borderBoxRect); }
private void AddImage(ImagePrimitive primitive, Point a, Point b, Point uv0, Point uv1, Color col) { if (MathEx.AmostZero(col.A)) { return; } if (primitive.Texture == null) { primitive.SendToGPU(); } //add a new draw command DrawCommand cmd = new DrawCommand(); cmd.ClipRect = Rect.Big; cmd.TextureData = primitive.Texture; this.ImageMesh.CommandBuffer.Add(cmd); this.ImageMesh.PrimReserve(6, 4); this.AddImageRect(a, b, uv0, uv1, col); }
private void DrawBorder(StyleRuleSet style, Rect borderBoxRect, Rect paddingBoxRect) { // draw border between border-box and padding-box var borderImageSource = style.BorderImageSource; if (borderImageSource != null) { var rule = style.GetRule <string>(GUIStyleName.BorderImageSource); if (rule.primitive == null) { rule.primitive = new ImagePrimitive(borderImageSource); } Debug.Assert(rule.primitive is ImagePrimitive); this.DrawSlicedImage((ImagePrimitive)rule.primitive, borderBoxRect, style); } else { // Top if (!MathEx.AmostZero(borderBoxRect.Top)) { var borderTopColor = style.Get <Color>(GUIStyleName.BorderTopColor); if (!MathEx.AmostZero(borderTopColor.A)) { this.PathLineTo(paddingBoxRect.TopLeft); this.PathLineTo(borderBoxRect.TopLeft); this.PathLineTo(borderBoxRect.TopRight); this.PathLineTo(paddingBoxRect.TopRight); this.PathFill(borderTopColor); } } // Right if (!MathEx.AmostZero(borderBoxRect.Right)) { var borderRightColor = style.Get <Color>(GUIStyleName.BorderRightColor); if (!MathEx.AmostZero(borderRightColor.A)) { this.PathLineTo(paddingBoxRect.TopRight); this.PathLineTo(borderBoxRect.TopRight); this.PathLineTo(borderBoxRect.BottomRight); this.PathLineTo(paddingBoxRect.BottomRight); this.PathFill(borderRightColor); } } // Bottom if (!MathEx.AmostZero(borderBoxRect.Bottom)) { var borderBottomColor = style.Get <Color>(GUIStyleName.BorderBottomColor); if (!MathEx.AmostZero(borderBottomColor.A)) { this.PathLineTo(paddingBoxRect.BottomRight); this.PathLineTo(borderBoxRect.BottomRight); this.PathLineTo(borderBoxRect.BottomLeft); this.PathLineTo(paddingBoxRect.BottomLeft); this.PathFill(borderBottomColor); } } // Left if (!MathEx.AmostZero(borderBoxRect.Left)) { var borderLeftColor = style.Get <Color>(GUIStyleName.BorderLeftColor); if (!MathEx.AmostZero(borderLeftColor.A)) { this.PathLineTo(paddingBoxRect.BottomLeft); this.PathLineTo(borderBoxRect.BottomLeft); this.PathLineTo(borderBoxRect.TopLeft); this.PathLineTo(paddingBoxRect.TopLeft); this.PathFill(borderLeftColor); } } } }