public AddBezier ( Point pt1, Point pt2, Point pt3, Point pt4 ) : void | ||
pt1 | Point | |
pt2 | Point | |
pt3 | Point | |
pt4 | Point | |
Результат | void |
/// <summary> /// Gets the tab path. /// </summary> /// <param name="index">The index.</param> /// <returns>GraphicsPath.</returns> private GraphicsPath GetTabPath(int index) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.Reset(); Rectangle rect = this.GetTabRect(index); switch (Alignment) { case TabAlignment.Top: break; case TabAlignment.Bottom: break; case TabAlignment.Left: break; case TabAlignment.Right: break; } int PaddingTop = 10; Point P_LeftTop = new Point(rect.Left + 7, rect.Top + PaddingTop); Point P_LeftBottom = new Point(rect.Left + 1, rect.Bottom); Point P_RightTop = new Point(rect.Right - 7, rect.Top + PaddingTop); Point P_RightBottom = new Point(rect.Right - 1, rect.Bottom); Point P_Control1 = new Point(rect.Left + 3, rect.Top + PaddingTop); Point P_Control2 = new Point(rect.Left + 2, rect.Bottom - rect.Height / 2); Point P_Control3 = new Point(rect.Right - 3, rect.Top + PaddingTop); Point P_Control4 = new Point(rect.Right - 2, rect.Bottom - rect.Height / 2); //path.AddLine(rect.Left + 15, rect.Top, rect.Left + 2, rect.Bottom + 1); //path.AddLine(rect.Left + 15, rect.Top, rect.Right - 15, rect.Top); //path.AddLine(rect.Right - 15, rect.Top, rect.Right - 2, rect.Bottom + 1); //path.AddLine(rect.Right - 2, rect.Bottom, rect.Left + 2, rect.Bottom); path.AddBezier(P_LeftTop, P_Control1, P_Control2, P_LeftBottom); path.AddLine(P_LeftBottom, P_RightBottom); path.AddBezier(P_RightBottom, P_Control4, P_Control3, P_RightTop); //path.AddBezier(P_RightTop, P_Control3, P_Control4, P_RightBottom); path.AddLine(P_RightTop, P_LeftTop); //int diameter = 2 * 10; //path.AddArc(new Rectangle(new Point(rect.Left + 5, rect.Top), new Size(diameter, diameter)), 180, 60); //path.AddArc(new Rectangle(new Point(rect.Right - 15 - diameter, rect.Top - diameter), new Size(diameter, diameter)), 0, 60); path.CloseFigure(); //return GetRoundedRectPath(rect, 15); return(path); }
public static GraphicsPath RoundRect(RectangleF r, float r1, float r2, float r3, float r4) { float x = r.X, y = r.Y, w = r.Width, h = r.Height; GraphicsPath rr = new GraphicsPath(); rr.AddBezier(x, y + r1, x, y, x + r1, y, x + r1, y); rr.AddLine(x + r1, y, x + w - r2, y); rr.AddBezier(x + w - r2, y, x + w, y, x + w, y + r2, x + w, y + r2); rr.AddLine(x + w, y + r2, x + w, y + h - r3); rr.AddBezier(x + w, y + h - r3, x + w, y + h, x + w - r3, y + h, x + w - r3, y + h); rr.AddLine(x + w - r3, y + h, x + r4, y + h); rr.AddBezier(x + r4, y + h, x, y + h, x, y + h - r4, x, y + h - r4); rr.AddLine(x, y + h - r4, x, y + r1); return rr; }
private static void AddSegmentToPath(ICurve seg, ref System.Drawing.Drawing2D.GraphicsPath p) { const float radiansToDegrees = (float)(180.0 / Math.PI); LineSegment line = seg as LineSegment; if (line != null) { p.AddLine(PointF(line.Start), PointF(line.End)); } else { CubicBezierSegment cb = seg as CubicBezierSegment; if (cb != null) { p.AddBezier(PointF(cb.B(0)), PointF(cb.B(1)), PointF(cb.B(2)), PointF(cb.B(3))); } else { Ellipse ellipse = seg as Ellipse; if (ellipse != null) { p.AddArc((float)(ellipse.Center.X - ellipse.AxisA.Length), (float)(ellipse.Center.Y - ellipse.AxisB.Length), (float)(2 * ellipse.AxisA.Length), (float)(2 * ellipse.AxisB.Length), (float)(ellipse.ParStart * radiansToDegrees), (float)((ellipse.ParEnd - ellipse.ParStart) * radiansToDegrees)); } } } }
public static GraphicsPath RoundRect(Rectangle rect, float r1, float r2, float r3, float r4) { int x = rect.X; int y = rect.Y; int width = rect.Width; int height = rect.Height; GraphicsPath path = new GraphicsPath(); path.AddBezier((float) x, y + r1, (float) x, (float) y, x + r1, (float) y, x + r1, (float) y); path.AddLine(x + r1, (float) y, (x + width) - r2, (float) y); path.AddBezier((x + width) - r2, (float) y, (float) (x + width), (float) y, (float) (x + width), y + r2, (float) (x + width), y + r2); path.AddLine((float) (x + width), y + r2, (float) (x + width), (y + height) - r3); path.AddBezier((float) (x + width), (y + height) - r3, (float) (x + width), (float) (y + height), (x + width) - r3, (float) (y + height), (x + width) - r3, (float) (y + height)); path.AddLine((x + width) - r3, (float) (y + height), x + r4, (float) (y + height)); path.AddBezier(x + r4, (float) (y + height), (float) x, (float) (y + height), (float) x, (y + height) - r4, (float) x, (y + height) - r4); path.AddLine((float) x, (y + height) - r4, (float) x, y + r1); return path; }
public static GraphicsPath CreateRoundRect(RectangleF r, float r1, float r2, float r3, float r4) { float x = r.X; float y = r.Y; float width = r.Width; float height = r.Height; GraphicsPath path = new GraphicsPath(); path.AddBezier(x, y + r1, x, y, x + r1, y, x + r1, y); path.AddLine(x + r1, y, (x + width) - r2, y); path.AddBezier((x + width) - r2, y, x + width, y, x + width, y + r2, x + width, y + r2); path.AddLine((float) (x + width), (float) (y + r2), (float) (x + width), (float) ((y + height) - r3)); path.AddBezier((float) (x + width), (float) ((y + height) - r3), (float) (x + width), (float) (y + height), (float) ((x + width) - r3), (float) (y + height), (float) ((x + width) - r3), (float) (y + height)); path.AddLine((float) ((x + width) - r3), (float) (y + height), (float) (x + r4), (float) (y + height)); path.AddBezier(x + r4, y + height, x, y + height, x, (y + height) - r4, x, (y + height) - r4); path.AddLine(x, (y + height) - r4, x, y + r1); return path; }
public override RectangleF ReturnBounds() { GraphicsPath path = new GraphicsPath(); path.AddBezier(pointOne, pointTwo, pointTree, pointFour); path.Transform(this.TMatrix.TransformationMatrix); return path.GetBounds(); }
/// <summary> /// делает скругленные углы прямоугольнику rect с радиусом скругления cornerRad /// </summary> /// <param name="rect"></param> прямоугольник /// <param name="cornerRad"></param> радиус скругления /// <returns></returns> public static GraphicsPath GetBarShape(RectangleF rect, float cornerRad) { float rad = cornerRad; float x = rect.X; float y = rect.Y; float width = rect.Width; float height = rect.Height; GraphicsPath path = new GraphicsPath(); path.AddBezier(x, y + rad, x, y, x + rad, y, x + rad, y); path.AddLine(x + rad, y, (x + width) - rad, y); path.AddBezier((x + width) - rad, y, x + width, y, x + width, y + rad, x + width, y + rad); path.AddLine((x + width), (y + rad), (x + width), ((y + height) - rad)); path.AddBezier((x + width), ((y + height) - rad), (x + width), (y + height), ((x + width) - rad), (y + height), ((x + width) - rad), (y + height)); path.AddLine(((x + width) - rad), (y + height), (x + rad), (y + height)); path.AddBezier(x + rad, y + height, x, y + height, x, (y + height) - rad, x, (y + height) - rad); path.AddLine(x, (y + height) - rad, x, y + rad); return path; }
/// <summary> /// Bygger og returnerer en et rektangel, med eventuelle avrundede hjørner /// </summary> /// <param name="x">Startpunktets x-koordinat</param> /// <param name="y">Startpunktet y-koordinat</param> /// <param name="width">Bredden på rektangelet</param> /// <param name="height">Høyden på rektangelet</param> /// <param name="leftTopRadius">Avrundingsverdi for hjørne oppe til venstre</param> /// <param name="rightTopRadius">Avrundingsverdi for hjørne oppe til høyre</param> /// <param name="rightBottomRadius">Avrundingsverdi for hjørne nede til høyre</param> /// <param name="leftBottomRadius">Avrundingsverdi for hjørne nede til venstre</param> /// <returns>Et GraphicsPath-objekt som representerer rektangelet</returns> public static GraphicsPath Rectangle(int x, int y, int width, int height, int leftTopRadius, int rightTopRadius, int rightBottomRadius, int leftBottomRadius) { GraphicsPath p = new GraphicsPath(); //Punkter for øvre venstre hjørne Point leftTopStart = new Point(x, y + leftTopRadius); Point leftTopStop = new Point(x + leftTopRadius, y); Point topLeftControlPoint = new Point(x, y); //Punkter for øvre høyre hjørne Point rightTopStart = new Point(x + width- rightTopRadius, y); Point rightTopStop = new Point(x + width, y + rightTopRadius); Point topRightControlPoint = new Point(x + width, y); //Punkter for nedre høyre hjørne Point rightBottomStart = new Point(x + width, y + height - rightBottomRadius); Point rightBottomStop = new Point(x + width - rightBottomRadius, y + height); Point bottomRightControlPoint = new Point(x + width, y + height); //Punkter for nedre venstre hjørne Point leftBottomStart = new Point(x + leftBottomRadius, y + height); Point leftBottomStop = new Point(x, y + height - leftBottomRadius); Point bottomLeftControlPoint = new Point(x, y + height); p.StartFigure(); p.AddBezier(leftTopStart, topLeftControlPoint, topLeftControlPoint, leftTopStop); //Top left corner p.AddLine(x + leftTopRadius, y, x + width - rightTopRadius, y); //Top edge p.AddBezier(rightTopStart, topRightControlPoint, topRightControlPoint, rightTopStop); //Top right corner p.AddLine(x + width, y + rightTopRadius, x + width, y + height - rightBottomRadius); //Right edge p.AddBezier(rightBottomStart, bottomRightControlPoint, bottomRightControlPoint, rightBottomStop); // Bottom right corner p.AddLine(x + width - rightBottomRadius, y + height, x + leftBottomRadius, y + height); //Bottom edge p.AddBezier(leftBottomStart, bottomLeftControlPoint, bottomLeftControlPoint, leftBottomStop); // Bottom right corner p.CloseFigure(); return p; }
public virtual void NextSubpath_Int_Int_Bool() { GraphicsPath path = new GraphicsPath (); path.AddLine (new Point (100, 100), new Point (400, 100)); path.AddLine (new Point (400, 200), new Point (10, 100)); path.StartFigure (); path.SetMarkers (); path.AddBezier( 10, 10, 50, 250, 100, 5, 200, 280); path.CloseFigure (); path.StartFigure (); path.SetMarkers (); path.AddRectangle (new Rectangle (10, 20, 300, 400)); path.StartFigure (); path.SetMarkers (); path.AddLine (new Point (400, 400), new Point (400, 10)); GraphicsPathIterator iterator = new GraphicsPathIterator (path); int start; int end; bool isClosed; int count = iterator.NextSubpath (out start, out end, out isClosed); Assert.AreEqual (4, count); Assert.AreEqual (0, start); Assert.AreEqual (3, end); Assert.IsFalse (isClosed); count = iterator.NextSubpath (out start, out end, out isClosed); Assert.AreEqual (4, count); Assert.AreEqual (4, start); Assert.AreEqual (7, end); Assert.IsTrue (isClosed); count = iterator.NextSubpath (out start, out end, out isClosed); Assert.AreEqual (4, count); Assert.AreEqual (8, start); Assert.AreEqual (11, end); Assert.IsTrue (isClosed); count = iterator.NextSubpath (out start, out end, out isClosed); Assert.AreEqual (2, count); Assert.AreEqual (12, start); Assert.AreEqual (13, end); Assert.IsFalse (isClosed); count = iterator.NextSubpath (out start, out end, out isClosed); Assert.AreEqual (0, count); Assert.AreEqual (0, start); Assert.AreEqual (0, end); Assert.IsTrue (isClosed); }
/// <summary> /// Adds a quadratic bezier curve to the end of the line. /// </summary> /// <param name="control">The control point of the curve.</param> /// <param name="to">The end point of the curve.</param> /// <returns>This <see cref="IGraphicsPath" />.</returns> public IGraphicsPath AddQuadraticBezier(Vector2 control, Vector2 to) { Vector2 @from = _lastPoint.ToVector2(); PointF end = to.ToPointF(); _pathGeometry?.AddBezier( _lastPoint, (@from + (2f / 3f * (control - @from))).ToPointF(), (to + (2f / 3f * (control - to))).ToPointF(), end); _lastPoint = end; return(this); }
public override void DrawYourSelf(Graphics graphics) { GraphicsPath path = new GraphicsPath(); path.AddBezier(pointOne, pointTwo, pointTree, pointFour); path.Transform(this.TMatrix.TransformationMatrix); Pen pen = new Pen(this.BorderColor, this.BorderWidth); graphics.DrawPath(pen, path); if (this.Selected) { this.selectionUnit = new CoveringRectangle(Rectangle.Round(ReturnBounds())); this.selectionUnit.DrawYourSelf(graphics); } }
private System.Drawing.Drawing2D.GraphicsPath CreateGlarePath(System.Drawing.Rectangle bounds, int radius) { System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); if (radius == 0) { graphicsPath.AddLine(bounds.X, bounds.Y, bounds.Right - 1, bounds.Y); graphicsPath.AddLine(bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Bottom - 1); } else { graphicsPath.AddLine(bounds.X + radius, bounds.Y, bounds.Right - radius - 1, bounds.Y); graphicsPath.AddArc(bounds.Right - radius - 1, bounds.Y, radius, radius, 270.0F, 90.0F); graphicsPath.AddLine(bounds.Right - 1, bounds.Y + radius, bounds.Right - 1, bounds.Bottom - radius); } graphicsPath.AddBezier(bounds.Right - 1, bounds.Bottom - 1, bounds.Right, bounds.Y + (bounds.Height / 2), bounds.X + (bounds.Width / 2), bounds.Y, bounds.X, bounds.Y); graphicsPath.CloseAllFigures(); return(graphicsPath); }
public void CurveTo(CurveTo curveTo) { float x3 = (float)curveTo.X3; float y3 = (float)curveTo.Y3; _path.AddBezier( _currentPoint.X, _currentPoint.Y, (float)curveTo.X1, (float)curveTo.Y1, (float)curveTo.X2, (float)curveTo.Y2, x3, y3); _currentPoint.X = x3; _currentPoint.Y = y3; }
private void AnimateFrame(Rectangle box, Graphics g, ref int marqueeX) { if (box == null || g == null || box.Width <= 1) { return; } g.SmoothingMode = SmoothingMode.AntiAlias; //g.Clip = new Region(box); g.FillRectangle(new SolidBrush(color1), box); int h = box.Height; int hm = (int)((float)h / 2f); using (GraphicsPath gp = new GraphicsPath()) { Point MidLeft = new Point(0, hm); Point MidRight = new Point(h * 2, hm); int currentX = box.Right + animateX; // Increment currentX to animate int left = currentX - (h * 2); if (left < box.Left) { left = box.Left; } while (currentX > box.Left) { left = currentX - (h * 2); MidLeft = new Point(left, hm); MidRight = new Point(currentX, hm); int crestX = currentX - h; gp.AddBezier(MidRight, new Point(crestX, 0), new Point(crestX, h), MidLeft); currentX -= h * 2; } gp.AddLine(MidLeft, new Point(box.Left, box.Bottom)); // left side gp.AddLine(new Point(box.Left, box.Bottom), new Point(box.Right, box.Bottom)); // bottom gp.AddLine(new Point(box.Right, box.Bottom), new Point(box.Right, hm)); // right side g.FillPath(new SolidBrush(color2), gp); } g.SmoothingMode = SmoothingMode.Default; if (isAnimated && ++animateX > (box.Height * 2)) { animateX = 1; } }
internal static GraphicsPath CreateGraphicsPath(ICurve iCurve) { GraphicsPath graphicsPath = new GraphicsPath(); if (iCurve == null) return null; Curve c = iCurve as Curve; if (c != null) { foreach (ICurve seg in c.Segments) { CubicBezierSegment cubic = seg as CubicBezierSegment; if (cubic != null) graphicsPath.AddBezier(PointF(cubic.B(0)), PointF(cubic.B(1)), PointF(cubic.B(2)), PointF(cubic.B(3))); else { LineSegment ls = seg as LineSegment; if (ls != null) graphicsPath.AddLine(PointF(ls.Start), PointF(ls.End)); else { Ellipse el = seg as Ellipse; if (el != null) { graphicsPath.AddArc((float)(el.Center.X - el.AxisA.X), (float)(el.Center.Y - el.AxisB.Y), (float)(el.AxisA.X * 2), Math.Abs((float)el.AxisB.Y * 2), EllipseStartAngle(el), EllipseSweepAngle(el)); } } } } } else { var ls = iCurve as LineSegment; if (ls != null) graphicsPath.AddLine(PointF(ls.Start), PointF(ls.End)); } return graphicsPath; }
public static GraphicsPath Deshret() { GraphicsPath gp = new GraphicsPath(); PointF[] tempA = deshretData[0x00]; PointF p1, p2, p3, p4 = tempA[0x00]; int j = 0x01; for(int i = 0x00; i < 0x0b; i++) { p1 = p4; p2 = tempA[j++]; p3 = tempA[j++]; p4 = tempA[j++]; gp.AddBezier(p1,p2,p3,p4); } p1 = p4; p4 = tempA[j++]; gp.AddLine(p1,p4); for(int i = 0x00; i < 0x07; i++) { p1 = p4; p2 = tempA[j++]; p3 = tempA[j++]; p4 = tempA[j++]; gp.AddBezier(p1,p2,p3,p4); } gp.CloseFigure(); tempA = deshretData[0x01]; p4 = tempA[0x00]; j = 0x01; for(int i = 0x00; i < 0x14; i++) { p1 = p4; p2 = tempA[j++]; p3 = tempA[j++]; p4 = tempA[j++]; gp.AddBezier(p1,p2,p3,p4); } gp.AddLine(p4,tempA[j++]); gp.CloseFigure(); return gp; }
public GraphicsPath SyntaxToPath(string PathSyntax) { List<string> t = Tokenize(PathSyntax); if (t.Count < 2) return new GraphicsPath(); GraphicsPath p = new GraphicsPath(); int i = 0; if (t[0] == "F1") { p.FillMode = FillMode.Winding; i++; } else if (t[0] == "F0") { p.FillMode = FillMode.Alternate; i++; } PointF last_point = new PointF(0, 0); for (; i < t.Count; i++) { switch (t[i]) { // doesn't handle a lot of short-cuts yet. Doesn't support Hh or Vv case "M": p.StartFigure(); last_point = GetPointStr(t[i + 1], t[i + 2]); i += 2; break; case "m": p.StartFigure(); last_point = GetPointStrOff(t[i + 1], t[i + 2], last_point); i += 2; break; case "L": p.AddLine(last_point, GetPointStr(t[i + 1], t[i + 2])); last_point = p.GetLastPoint(); i += 2; break; case "l": p.AddLine(last_point, GetPointStrOff(t[i + 1], t[i + 2], last_point)); last_point = p.GetLastPoint(); i += 2; break; case "C": p.AddBezier(last_point, GetPointStr(t[i + 1], t[i + 2]), GetPointStr(t[i + 3], t[i + 4]), GetPointStr(t[i + 5], t[i + 6])); last_point = p.GetLastPoint(); i += 6; break; case "Z": case "z": p.CloseFigure(); break; default: throw new Exception("Unsupported symbol: " + t[i]); } } p.CloseAllFigures(); return p; }
/// <summary> /// Paints the shape on the canvas /// </summary> /// <param name="g"></param> /// public override void Paint(System.Drawing.Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle toggleNode = Rectangle.Empty; //the [+] [-] Point[] pts = new Point[12] { new Point(rectangle.X,rectangle.Y), //0 new Point(rectangle.X+bshift,rectangle.Y), //1 new Point(rectangle.Right-bshift,rectangle.Y), //2 new Point(rectangle.Right,rectangle.Y), //3 new Point(rectangle.Right,rectangle.Y+bshift), //4 new Point(rectangle.Right,rectangle.Bottom-bshift), //5 new Point(rectangle.Right,rectangle.Bottom), //6 new Point(rectangle.Right-bshift,rectangle.Bottom), //7 new Point(rectangle.X+bshift,rectangle.Bottom), //8 new Point(rectangle.X,rectangle.Bottom), //9 new Point(rectangle.X,rectangle.Bottom - bshift), //10 new Point(rectangle.X,rectangle.Y+bshift), //11 }; path = new GraphicsPath(); path.AddBezier(pts[11],pts[0],pts[0],pts[1]); path.AddLine(pts[1],pts[2]); path.AddBezier(pts[2],pts[3],pts[3],pts[4]); path.AddLine(pts[4],pts[5]); path.AddBezier(pts[5],pts[6],pts[6],pts[7]); path.AddLine(pts[7],pts[8]); path.AddBezier(pts[8],pts[9],pts[9],pts[10]); path.AddLine(pts[10],pts[11]); path.CloseFigure(); region = new Region(path); shapeBrush = new LinearGradientBrush(rectangle,this.shapeColor,Color.WhiteSmoke,0f); // start Draw Shadow shadow = region.Clone(); shadow.Translate(5, 5); //add the amount of children if (childNodes.Count > 0) { plus = " [" + childNodes.Count + "]"; } else { plus = ""; } g.FillRegion(new SolidBrush(Color.Gainsboro), shadow); //g.DrawPath(new Pen(Color.Gainsboro,1), shadow); //End Draw Shadow g.FillRegion(shapeBrush, region); if (hovered || isSelected) pen = thickPen; else pen = blackPen; g.DrawPath(pen, path); if (text != string.Empty) { //g.DrawString(text + plus,font,Brushes.Black, rectangle.X+5,rectangle.Y+5); g.DrawString(text,font,Brushes.Black, rectangle.X+5,rectangle.Y+5); } //draw the [+] expansion shape if (childNodes.Count > 0) { switch(site.LayoutDirection) { case TreeDirection.Vertical: toggleNode = new Rectangle(Left + this.Width/2 - 5, Bottom, 10, 10); break; case TreeDirection.Horizontal: toggleNode = new Rectangle(Right , Top +Height/2-5 , 10, 10); break; } //Draw [ ] g.FillRectangle(new SolidBrush(Color.White), toggleNode); g.DrawRectangle(blackPen, toggleNode); //Draw - g.DrawLine(blackPen, (toggleNode.X + 2), (toggleNode.Y + (toggleNode.Height / 2)), (toggleNode.X + (toggleNode.Width - 2)), (toggleNode.Y + (toggleNode.Height / 2)) ); if (!this.Expanded) { //Draw | g.DrawLine(blackPen, (toggleNode.X + (toggleNode.Width /2)), (toggleNode.Y + 2), (toggleNode.X + (toggleNode.Width /2)), (toggleNode.Y + (toggleNode.Height - 2))); } } }
public static GraphicsPath CreatePath(SvgPathElement element) { GraphicsPath gp = new GraphicsPath(); SvgPointF initPoint = new SvgPointF(0, 0); SvgPointF lastPoint = new SvgPointF(0, 0); ISvgPathSeg segment = null; SvgPathSegMoveto pathMoveTo = null; SvgPathSegLineto pathLineTo = null; SvgPathSegCurveto pathCurveTo = null; SvgPathSegArc pathArc = null; ISvgPathSegList segments = element.PathSegList; int nElems = segments.NumberOfItems; for (int i = 0; i < nElems; i++) { segment = segments.GetItem(i); if (DynamicCast.Cast(segment, out pathMoveTo)) { //SvgPathSegMoveto seg = (SvgPathSegMoveto)segment; gp.StartFigure(); lastPoint = initPoint = pathMoveTo.AbsXY; } else if (DynamicCast.Cast(segment, out pathLineTo)) { //SvgPathSegLineto seg = (SvgPathSegLineto)segment; SvgPointF p = pathLineTo.AbsXY; gp.AddLine(lastPoint.X, lastPoint.Y, p.X, p.Y); lastPoint = p; } else if (DynamicCast.Cast(segment, out pathCurveTo)) { // SvgPathSegCurveto seg = (SvgPathSegCurveto)segment; SvgPointF xy = pathCurveTo.AbsXY; SvgPointF x1y1 = pathCurveTo.CubicX1Y1; SvgPointF x2y2 = pathCurveTo.CubicX2Y2; gp.AddBezier(lastPoint.X, lastPoint.Y, x1y1.X, x1y1.Y, x2y2.X, x2y2.Y, xy.X, xy.Y); lastPoint = xy; } else if (DynamicCast.Cast(segment, out pathArc)) { //SvgPathSegArc seg = (SvgPathSegArc)segment; SvgPointF p = pathArc.AbsXY; if (lastPoint.Equals(p)) { // If the endpoints (x, y) and (x0, y0) are identical, then this // is equivalent to omitting the elliptical arc segment entirely. } else if (pathArc.R1 == 0 || pathArc.R2 == 0) { // Ensure radii are valid gp.AddLine(lastPoint.X, lastPoint.Y, p.X, p.Y); } else { CalculatedArcValues calcValues = pathArc.GetCalculatedArcValues(); GraphicsPath gp2 = new GraphicsPath(); gp2.StartFigure(); gp2.AddArc((float)(calcValues.Cx - calcValues.CorrRx), (float)(calcValues.Cy - calcValues.CorrRy), (float)calcValues.CorrRx * 2, (float)calcValues.CorrRy * 2, (float)calcValues.AngleStart, (float)calcValues.AngleExtent); Matrix matrix = new Matrix(); matrix.Translate(-(float)calcValues.Cx, -(float)calcValues.Cy); gp2.Transform(matrix); matrix = new Matrix(); matrix.Rotate((float)pathArc.Angle); gp2.Transform(matrix); matrix = new Matrix(); matrix.Translate((float)calcValues.Cx, (float)calcValues.Cy); gp2.Transform(matrix); gp.AddPath(gp2, true); } lastPoint = p; } else if (segment is SvgPathSegClosePath) { gp.CloseFigure(); lastPoint = initPoint; } } string fillRule = element.GetPropertyValue("fill-rule"); if (fillRule == "evenodd") gp.FillMode = FillMode.Alternate; else gp.FillMode = FillMode.Winding; return gp; }
public void AddBezier_Float () { GraphicsPath gp = new GraphicsPath (); gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f); CheckBezier (gp); }
public void AddBezier_SamePointF () { GraphicsPath gp = new GraphicsPath (); gp.AddBezier (new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f)); // all points are present Assert.AreEqual (4, gp.PointCount, "1-PointCount"); Assert.AreEqual (0, gp.PathTypes [0], "1-PathTypes[0]"); Assert.AreEqual (3, gp.PathTypes [1], "1-PathTypes[1]"); Assert.AreEqual (3, gp.PathTypes [2], "1-PathTypes[2]"); Assert.AreEqual (3, gp.PathTypes [3], "1-PathTypes[3]"); gp.AddBezier (new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f)); // the first point (move to) can be compressed (i.e. removed) Assert.AreEqual (7, gp.PointCount, "2-PointCount"); Assert.AreEqual (3, gp.PathTypes [4], "2-PathTypes[4]"); Assert.AreEqual (3, gp.PathTypes [5], "2-PathTypes[5]"); Assert.AreEqual (3, gp.PathTypes [6], "2-PathTypes[6]"); }
public void AddBezier_PointF () { GraphicsPath gp = new GraphicsPath (); gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f)); CheckBezier (gp); }
public void AddBezier_Int () { GraphicsPath gp = new GraphicsPath (); gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4); CheckBezier (gp); }
public void AddBezier(PointF start, PointF control1, PointF control2, PointF end) { Control.AddBezier(start.ToSD(), control1.ToSD(), control2.ToSD(), end.ToSD()); }
public static D2D.GraphicsPath ToGraphicsPath(this PathGeometryViewModel pg, Func <double, float> scale) { var gp = new D2D.GraphicsPath { FillMode = pg.FillRule == FillRule.EvenOdd ? D2D.FillMode.Alternate : D2D.FillMode.Winding }; foreach (var pf in pg.Figures) { var startPoint = pf.StartPoint; foreach (var segment in pf.Segments) { if (segment is ArcSegmentViewModel arcSegment) { // TODO: Convert WPF/SVG elliptical arc segment format to GDI+ bezier curves. startPoint = arcSegment.Point; } else if (segment is CubicBezierSegmentViewModel cubicBezierSegment) { gp.AddBezier( scale(startPoint.X), scale(startPoint.Y), scale(cubicBezierSegment.Point1.X), scale(cubicBezierSegment.Point1.Y), scale(cubicBezierSegment.Point2.X), scale(cubicBezierSegment.Point2.Y), scale(cubicBezierSegment.Point3.X), scale(cubicBezierSegment.Point3.Y)); startPoint = cubicBezierSegment.Point3; } else if (segment is LineSegmentViewModel lineSegment) { gp.AddLine( scale(startPoint.X), scale(startPoint.Y), scale(lineSegment.Point.X), scale(lineSegment.Point.Y)); startPoint = lineSegment.Point; } else if (segment is QuadraticBezierSegmentViewModel quadraticBezierSegment) { var p1 = startPoint; var p2 = quadraticBezierSegment.Point1; var p3 = quadraticBezierSegment.Point2; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1), scale(y1), scale(x2), scale(y2), scale(x3), scale(y3), scale(x4), scale(y4)); startPoint = quadraticBezierSegment.Point2; } else { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); } } if (pf.IsClosed) { gp.CloseFigure(); } else { gp.StartFigure(); } } return(gp); }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="qbezier"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, XQBezier qbezier, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r) { var _gfx = gfx as Graphics; Brush brush = ToSolidBrush(qbezier.Style.Fill); Pen pen = ToPen(qbezier.Style, _scaleToPage); double x1 = qbezier.Point1.X; double y1 = qbezier.Point1.Y; double x2 = qbezier.Point1.X + (2.0 * (qbezier.Point2.X - qbezier.Point1.X)) / 3.0; double y2 = qbezier.Point1.Y + (2.0 * (qbezier.Point2.Y - qbezier.Point1.Y)) / 3.0; double x3 = x2 + (qbezier.Point3.X - qbezier.Point1.X) / 3.0; double y3 = y2 + (qbezier.Point3.Y - qbezier.Point1.Y) / 3.0; double x4 = qbezier.Point3.X; double y4 = qbezier.Point3.Y; if (qbezier.IsFilled) { var path = new GraphicsPath(); path.AddBezier( _scaleToPage(x1 + dx), _scaleToPage(y1 + dy), _scaleToPage(x2 + dx), _scaleToPage(y2 + dy), _scaleToPage(x3 + dx), _scaleToPage(y3 + dy), _scaleToPage(x4 + dx), _scaleToPage(y4 + dy)); _gfx.FillPath(brush, path); } if (qbezier.IsStroked) { _gfx.DrawBezier( pen, _scaleToPage(x1 + dx), _scaleToPage(y1 + dy), _scaleToPage(x2 + dx), _scaleToPage(y2 + dy), _scaleToPage(x3 + dx), _scaleToPage(y3 + dy), _scaleToPage(x4 + dx), _scaleToPage(y4 + dy)); } brush.Dispose(); pen.Dispose(); }
/// <summary> /// Produces DXF output for Flowchart shape /// </summary> /// <param name="rect">Bounding Rectangle</param> /// <param name="ShapeStyle">Flowchart shape style</param> /// <param name="st">ElementTemplate reference if shape is complex null otherwise</param> /// <param name="crLine">Line color</param> /// <param name="RA">Rotation angle</param> /// <param name="dash">DashStyle</param> /// <param name="LineWidth">Line width ( not used)</param> /// <param name="Offset">Offset if it's necessary</param> /// <param name="WCS2UCS">if true conversion for world-coordinate to user-coordinate is required</param> /// <param name="gr">GraphicsPath to be assigned</param> /// <param name="result">>DXF output string</param> /// <returns>true if successfull otherwise false</returns> public bool Shape2Str( RectangleF rect, BoxStyle ShapeStyle, ElementTemplate[] st, Color crLine, float RA, DashStyle dash, Single LineWidth, float Offset, bool WCS2UCS, ref GraphicsPath gr, ref string result ) { float X = 0, Y = 0, X1 = 0, Y1 = 0, X2 = 0, Y2 = 0, X3 = 0, Y3 = 0; bool DisableStringOutput = false; PointF[] pts = null; bool bOk = false; string PathPart = ""; GraphicsPath gr_temp = new GraphicsPath(FillMode.Winding); try { if ( gr == null ) throw new Exception("Empty Graphics Path reference passed"); DisableStringOutput = ( result == null ); // Detecting box's style switch (ShapeStyle) { case BoxStyle.Rectangle: gr.AddRectangle(rect); break; case BoxStyle.Ellipse: gr.AddEllipse(rect.X,rect.Y,rect.Width, rect.Height); break; case BoxStyle.RoundedRectangle: gr = Utilities.getRoundRect(rect.X, rect.Y, rect.Width, rect.Height,10); break; case BoxStyle.Delay: gr.AddRectangle(rect); break; case BoxStyle.Rhombus: pts = new PointF[4] {new PointF((rect.Left + rect.Right) / 2, rect.Top - Offset), new PointF(Math.Max(rect.Right, rect.Left) + Offset, (rect.Top + rect.Bottom) / 2), new PointF((rect.Left + rect.Right) / 2, Math.Max(rect.Bottom, rect.Top) + Offset), new PointF(rect.Left - Offset,(rect.Top + rect.Bottom) / 2)}; gr.AddPolygon(pts); break; case BoxStyle.Shape: // if shape is complex then processing all its elements if (st == null) throw new Exception("Empty shape reference in the complex shape"); foreach (ElementTemplate et in st ) { switch ( et.getClassId()) { case 28: // If shape element is arc ArcTemplate at = et as ArcTemplate; double rx = 0, ry = 0 , cx = 0, cy = 0; rx = rect.Width * (at.Bounds.Width/200); ry = rect.Height * (at.Bounds.Height/200); cx = rect.X + rect.Width*(at.Bounds.X/100) + rx; cy = rect.Y + rect.Height*(at.Bounds.Y/100) + ry; gr.AddArc((float) (cx - rx), (float) ( cy - ry) , (float) rx*2, (float) ry*2, at.StartAngle ,at.SweepAngle); float StartAngle = 180 + at.StartAngle + (360 - at.SweepAngle) - RA, EndAngle = StartAngle + at.SweepAngle; if ( rx != ry ) { float iAngleC = 0; double majorx = 0, majory = 0; if (at.StartAngle<0) iAngleC = 360 - Math.Abs(at.StartAngle); else iAngleC = at.StartAngle; majorx = (rx < ry) ? 0 : rx; majory = (rx < ry) ? ry : 0; if (( iAngleC >=0 ) && (iAngleC<90)) { majorx*=-1; majory*=-1; } else if (( iAngleC >=90 ) && (iAngleC<180)) { } else if (( iAngleC >=180 ) && (iAngleC<270)) { majorx*=-1; majory*=-1; } else if (( iAngleC >=270 ) && (iAngleC<=360)) { } StartAngle = at.StartAngle + RA; EndAngle = StartAngle + at.SweepAngle; if ((at.SweepAngle>=270) && (at.SweepAngle<360)) { if ( ry > rx ) { StartAngle = at.StartAngle + RA + 90 + ( 360 - at.SweepAngle); EndAngle = at.StartAngle + RA + 90; } } else if (at.SweepAngle>=180) { if (ry>rx) { StartAngle-=90; EndAngle-=90; } } PathPart = String.Format(provider, " 0\nELLIPSE\n 100\nAcDbEntity\n{0:HAN} 8\n{5}\n 62\n{6:ACI}\n 100\nAcDbEllipse\n 10\n{0:U}\n 20\n{1:U}\n 11\n{7:U}\n 21\n{8:U}\n 40\n{9:U}\n 41\n{3:U}\n 42\n{4:U}\n", cx, m_FlowChart.DocExtents.Height - cy,0, (StartAngle*Math.PI)/180 , (EndAngle*Math.PI)/180, SHAPE_LAYER, crLine, majorx , majory , (rx < ry) ? rx/ry : ry/rx); } else { PathPart = String.Format(provider, " 0\nARC\n 100\nAcDbEntity\n{0:HAN} 8\n{5}\n 62\n{6:ACI}\n 100\nAcDbCircle\n 10\n{0:U}\n 20\n{1:U}\n 40\n{2:U}\n 100\nAcDbArc\n 50\n{3}\n 51\n{4}\n", cx, m_FlowChart.DocExtents.Height - cy,rx, StartAngle , EndAngle, SHAPE_LAYER, crLine); } break; case 29: // If shape element is bezier curve BezierTemplate bt = et as BezierTemplate; X = rect.X + rect.Width * (bt.Coordinates[0]/100); Y = rect.Y + rect.Height* (bt.Coordinates[1]/100); X1 = rect.X + rect.Width * (bt.Coordinates[2]/100); Y1 = rect.Y + rect.Height* (bt.Coordinates[3]/100); X2 = rect.X + rect.Width * (bt.Coordinates[4]/100); Y2 = rect.Y + rect.Height* (bt.Coordinates[5]/100); X3 = rect.X + rect.Width * (bt.Coordinates[6]/100); Y3 = rect.Y + rect.Height* (bt.Coordinates[7]/100); gr_temp.Reset(); gr_temp.AddBezier(X,Y,X1,Y1,X2,Y2,X3,Y3); gr.AddBezier(X,Y,X1,Y1,X2,Y2,X3,Y3); // Applying rotation if it's necessary pts = RotatePoints(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), gr_temp); gr_temp.Flatten(); PointF[] pts2 = gr_temp.PathData.Points.Clone() as PointF[]; PathPart = String.Format(provider, "0\nPOLYLINE\n{0:HAN} 100\nAcDbEntity\n8\n{0}\n 62\n{1:ACI}\n 100\nAcDb2dPolyline\n 66\n1\n 70\n4\n 75\n6\n{2}{3}0\nSEQEND\n 100\nAcDbEntity\n{0:HAN}", SHAPE_LAYER, crLine, Pt2String(pts,crLine,SHAPE_LAYER,DxLineType.ltVertex, dash, 16), Pt2String(pts2,crLine,SHAPE_LAYER,DxLineType.ltVertex, dash, 8)); break; case 30: // If shape element is line LineTemplate lt = et as LineTemplate; X1 = rect.X + rect.Width * (lt.Coordinates[0]/100); Y1 = rect.Y + rect.Height* (lt.Coordinates[1]/100); X2 = rect.X + rect.Width * (lt.Coordinates[2]/100); Y2 = rect.Y + rect.Height* (lt.Coordinates[3]/100); gr_temp.Reset(); gr_temp.AddLine(X1,Y1,X2,Y2); gr.AddLine(X1,Y1,X2,Y2); // Applying rotation if it's necessary pts = RotatePoints(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), gr_temp); PathPart = Pt2String(pts, crLine,SHAPE_LAYER,DxLineType.ltSingle,DashStyle.Solid, 1); break; } result+=PathPart; } break; default: gr.AddRectangle(rect); break; } // Converting shapes coordinates from UCS to WSC TranslateCoords(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), WCS2UCS, ref gr); gr.Flatten(); // If string output is required producing DXF string if (!DisableStringOutput) { if ( result=="" ) { pts = gr.PathPoints.Clone() as PointF[]; result = Pt2String(pts, crLine, SHAPE_LAYER, DxLineType.ltClosedSingle, dash, LineWidth); } } bOk = true; } catch ( Exception ex) { Trace.WriteLine(String.Format("{0} error {1}\n","Box2Str",ex.Message)); bOk = false; } return bOk; }
static void AddSegmentToPath(ICurve seg, ref GraphicsPath p) { const float radiansToDegrees = (float) (180.0/Math.PI); var line = seg as LineSegment; if (line != null) p.AddLine(PointF(line.Start), PointF(line.End)); else { var cb = seg as CubicBezierSegment; if (cb != null) p.AddBezier(PointF(cb.B(0)), PointF(cb.B(1)), PointF(cb.B(2)), PointF(cb.B(3))); else { var ellipse = seg as Ellipse; if (ellipse != null) p.AddArc((float) (ellipse.Center.X - ellipse.AxisA.Length), (float) (ellipse.Center.Y - ellipse.AxisB.Length), (float) (2*ellipse.AxisA.Length), (float) (2*ellipse.AxisB.Length), (float) (ellipse.ParStart*radiansToDegrees), (float) ((ellipse.ParEnd - ellipse.ParStart)*radiansToDegrees)); } } }
private GraphicsPath BuildMenuIconShape( ref Rectangle rcMenuIcon) { GraphicsPath XMenuIconPath = new GraphicsPath(); switch (m_xTitleBar.TitleBarType) { case XTitleBar.XTitleBarType.Rounded: XMenuIconPath.AddArc( rcMenuIcon.Left, rcMenuIcon.Top, rcMenuIcon.Height, rcMenuIcon.Height, 90, 180); XMenuIconPath.AddLine( rcMenuIcon.Left + rcMenuIcon.Height / 2, rcMenuIcon.Top, rcMenuIcon.Right, rcMenuIcon.Top ); XMenuIconPath.AddBezier( new Point(rcMenuIcon.Right, rcMenuIcon.Top), new Point(rcMenuIcon.Right - 10, rcMenuIcon.Bottom / 2 - 5), new Point(rcMenuIcon.Right - 12, rcMenuIcon.Bottom / 2 + 5), new Point(rcMenuIcon.Right, rcMenuIcon.Bottom) ); XMenuIconPath.AddLine( rcMenuIcon.Right, rcMenuIcon.Bottom, rcMenuIcon.Left + rcMenuIcon.Height / 2, rcMenuIcon.Bottom ); break; case XTitleBar.XTitleBarType.Angular: XMenuIconPath.AddArc( rcMenuIcon.Left, rcMenuIcon.Top, rcMenuIcon.Height, rcMenuIcon.Height, 90, 180); XMenuIconPath.AddLine( rcMenuIcon.Left + rcMenuIcon.Height / 2, rcMenuIcon.Top, rcMenuIcon.Right + 18, rcMenuIcon.Top ); XMenuIconPath.AddLine( rcMenuIcon.Right + 18, rcMenuIcon.Top, rcMenuIcon.Right - 5, rcMenuIcon.Bottom ); XMenuIconPath.AddLine( rcMenuIcon.Right - 5, rcMenuIcon.Bottom, rcMenuIcon.Left + rcMenuIcon.Height / 2, rcMenuIcon.Bottom ); break; case XTitleBar.XTitleBarType.Rectangular: XMenuIconPath.AddArc( rcMenuIcon.Left, rcMenuIcon.Top, rcMenuIcon.Height, rcMenuIcon.Height, 90, 180); XMenuIconPath.AddLine( rcMenuIcon.Left + rcMenuIcon.Height / 2, rcMenuIcon.Top, rcMenuIcon.Right, rcMenuIcon.Top ); XMenuIconPath.AddLine( rcMenuIcon.Right, rcMenuIcon.Top, rcMenuIcon.Right, rcMenuIcon.Bottom ); XMenuIconPath.AddLine( rcMenuIcon.Right, rcMenuIcon.Bottom, rcMenuIcon.Left + rcMenuIcon.Height / 2, rcMenuIcon.Bottom ); break; } return XMenuIconPath; }
/// <summary> /// /// </summary> /// <param name="pg"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="scale"></param> /// <returns></returns> public static D2D.GraphicsPath ToGraphicsPath(this IPathGeometry pg, double dx, double dy, Func <double, float> scale) { var gp = new D2D.GraphicsPath { FillMode = pg.FillRule == FillRule.EvenOdd ? D2D.FillMode.Alternate : D2D.FillMode.Winding }; foreach (var pf in pg.Figures) { var startPoint = pf.StartPoint; foreach (var segment in pf.Segments) { if (segment is IArcSegment arcSegment) { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); // TODO: Convert WPF/SVG elliptical arc segment format to GDI+ bezier curves. //startPoint = arcSegment.Point; } else if (segment is ICubicBezierSegment cubicBezierSegment) { gp.AddBezier( scale(startPoint.X + dx), scale(startPoint.Y + dy), scale(cubicBezierSegment.Point1.X + dx), scale(cubicBezierSegment.Point1.Y + dy), scale(cubicBezierSegment.Point2.X + dx), scale(cubicBezierSegment.Point2.Y + dy), scale(cubicBezierSegment.Point3.X + dx), scale(cubicBezierSegment.Point3.Y + dy)); startPoint = cubicBezierSegment.Point3; } else if (segment is ILineSegment lineSegment) { gp.AddLine( scale(startPoint.X + dx), scale(startPoint.Y + dy), scale(lineSegment.Point.X + dx), scale(lineSegment.Point.Y + dy)); startPoint = lineSegment.Point; } else if (segment is IPolyCubicBezierSegment polyCubicBezierSegment) { if (polyCubicBezierSegment.Points.Length >= 3) { gp.AddBezier( scale(startPoint.X + dx), scale(startPoint.Y + dy), scale(polyCubicBezierSegment.Points[0].X + dx), scale(polyCubicBezierSegment.Points[0].Y + dy), scale(polyCubicBezierSegment.Points[1].X + dx), scale(polyCubicBezierSegment.Points[1].Y + dy), scale(polyCubicBezierSegment.Points[2].X + dx), scale(polyCubicBezierSegment.Points[2].Y + dy)); } if (polyCubicBezierSegment.Points.Length > 3 && polyCubicBezierSegment.Points.Length % 3 == 0) { for (int i = 3; i < polyCubicBezierSegment.Points.Length; i += 3) { gp.AddBezier( scale(polyCubicBezierSegment.Points[i - 1].X + dx), scale(polyCubicBezierSegment.Points[i - 1].Y + dy), scale(polyCubicBezierSegment.Points[i].X + dx), scale(polyCubicBezierSegment.Points[i].Y + dy), scale(polyCubicBezierSegment.Points[i + 1].X + dx), scale(polyCubicBezierSegment.Points[i + 1].Y + dy), scale(polyCubicBezierSegment.Points[i + 2].X + dx), scale(polyCubicBezierSegment.Points[i + 2].Y + dy)); } } startPoint = polyCubicBezierSegment.Points.Last(); } else if (segment is IPolyLineSegment polyLineSegment) { if (polyLineSegment.Points.Length >= 1) { gp.AddLine( scale(startPoint.X + dx), scale(startPoint.Y + dy), scale(polyLineSegment.Points[0].X + dx), scale(polyLineSegment.Points[0].Y + dy)); } if (polyLineSegment.Points.Length > 1) { for (int i = 1; i < polyLineSegment.Points.Length; i++) { gp.AddLine( scale(polyLineSegment.Points[i - 1].X + dx), scale(polyLineSegment.Points[i - 1].Y + dy), scale(polyLineSegment.Points[i].X + dx), scale(polyLineSegment.Points[i].Y + dy)); } } startPoint = polyLineSegment.Points.Last(); } else if (segment is IPolyQuadraticBezierSegment polyQuadraticSegment) { if (polyQuadraticSegment.Points.Length >= 2) { var p1 = startPoint; var p2 = polyQuadraticSegment.Points[0]; var p3 = polyQuadraticSegment.Points[1]; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1 + dx), scale(y1 + dy), scale(x2 + dx), scale(y2 + dy), scale(x3 + dx), scale(y3 + dy), scale(x4 + dx), scale(y4 + dy)); } if (polyQuadraticSegment.Points.Length > 2 && polyQuadraticSegment.Points.Length % 2 == 0) { for (int i = 3; i < polyQuadraticSegment.Points.Length; i += 3) { var p1 = polyQuadraticSegment.Points[i - 1]; var p2 = polyQuadraticSegment.Points[i]; var p3 = polyQuadraticSegment.Points[i + 1]; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1 + dx), scale(y1 + dy), scale(x2 + dx), scale(y2 + dy), scale(x3 + dx), scale(y3 + dy), scale(x4 + dx), scale(y4 + dy)); } } startPoint = polyQuadraticSegment.Points.Last(); } else if (segment is IQuadraticBezierSegment quadraticBezierSegment) { var p1 = startPoint; var p2 = quadraticBezierSegment.Point1; var p3 = quadraticBezierSegment.Point2; double x1 = p1.X; double y1 = p1.Y; double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0; double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0; double x3 = x2 + (p3.X - p1.X) / 3.0; double y3 = y2 + (p3.Y - p1.Y) / 3.0; double x4 = p3.X; double y4 = p3.Y; gp.AddBezier( scale(x1 + dx), scale(y1 + dy), scale(x2 + dx), scale(y2 + dy), scale(x3 + dx), scale(y3 + dy), scale(x4 + dx), scale(y4 + dy)); startPoint = quadraticBezierSegment.Point2; } else { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); } } if (pf.IsClosed) { gp.CloseFigure(); } else { gp.StartFigure(); } } return(gp); }
public override void AddToPath(GraphicsPath graphicsPath) { if (this.Start == this.End) { return; } if (this.RadiusX == 0.0f && this.RadiusY == 0.0f) { graphicsPath.AddLine(this.Start, this.End); return; } double sinPhi = Math.Sin(this.Angle * SvgArcSegment.RadiansPerDegree); double cosPhi = Math.Cos(this.Angle * SvgArcSegment.RadiansPerDegree); double x1dash = cosPhi * (this.Start.X - this.End.X) / 2.0 + sinPhi * (this.Start.Y - this.End.Y) / 2.0; double y1dash = -sinPhi * (this.Start.X - this.End.X) / 2.0 + cosPhi * (this.Start.Y - this.End.Y) / 2.0; double root; double numerator = this.RadiusX * this.RadiusX * this.RadiusY * this.RadiusY - this.RadiusX * this.RadiusX * y1dash * y1dash - this.RadiusY * this.RadiusY * x1dash * x1dash; float rx = this.RadiusX; float ry = this.RadiusY; if (numerator < 0.0) { float s = (float)Math.Sqrt(1.0 - numerator / (this.RadiusX * this.RadiusX * this.RadiusY * this.RadiusY)); rx *= s; ry *= s; root = 0.0; } else { root = ((this.Size == SvgArcSize.Large && this.Sweep == SvgArcSweep.Positive) || (this.Size == SvgArcSize.Small && this.Sweep == SvgArcSweep.Negative) ? -1.0 : 1.0) * Math.Sqrt(numerator / (this.RadiusX * this.RadiusX * y1dash * y1dash + this.RadiusY * this.RadiusY * x1dash * x1dash)); } double cxdash = root * rx * y1dash / ry; double cydash = -root * ry * x1dash / rx; double cx = cosPhi * cxdash - sinPhi * cydash + (this.Start.X + this.End.X) / 2.0; double cy = sinPhi * cxdash + cosPhi * cydash + (this.Start.Y + this.End.Y) / 2.0; double theta1 = SvgArcSegment.CalculateVectorAngle(1.0, 0.0, (x1dash - cxdash) / rx, (y1dash - cydash) / ry); double dtheta = SvgArcSegment.CalculateVectorAngle((x1dash - cxdash) / rx, (y1dash - cydash) / ry, (-x1dash - cxdash) / rx, (-y1dash - cydash) / ry); if (this.Sweep == SvgArcSweep.Negative && dtheta > 0) { dtheta -= 2.0 * Math.PI; } else if (this.Sweep == SvgArcSweep.Positive && dtheta < 0) { dtheta += 2.0 * Math.PI; } int segments = (int)Math.Ceiling((double)Math.Abs(dtheta / (Math.PI / 2.0))); double delta = dtheta / segments; double t = 8.0 / 3.0 * Math.Sin(delta / 4.0) * Math.Sin(delta / 4.0) / Math.Sin(delta / 2.0); double startX = this.Start.X; double startY = this.Start.Y; for (int i = 0; i < segments; ++i) { double cosTheta1 = Math.Cos(theta1); double sinTheta1 = Math.Sin(theta1); double theta2 = theta1 + delta; double cosTheta2 = Math.Cos(theta2); double sinTheta2 = Math.Sin(theta2); double endpointX = cosPhi * rx * cosTheta2 - sinPhi * ry * sinTheta2 + cx; double endpointY = sinPhi * rx * cosTheta2 + cosPhi * ry * sinTheta2 + cy; double dx1 = t * (-cosPhi * rx * sinTheta1 - sinPhi * ry * cosTheta1); double dy1 = t * (-sinPhi * rx * sinTheta1 + cosPhi * ry * cosTheta1); double dxe = t * (cosPhi * rx * sinTheta2 + sinPhi * ry * cosTheta2); double dye = t * (sinPhi * rx * sinTheta2 - cosPhi * ry * cosTheta2); graphicsPath.AddBezier((float)startX, (float)startY, (float)(startX + dx1), (float)(startY + dy1), (float)(endpointX + dxe), (float)(endpointY + dye), (float)endpointX, (float)endpointY); theta1 = theta2; startX = (float)endpointX; startY = (float)endpointY; } }
public void Reverse_Subpath_Marker_2 () { using (GraphicsPath gp = new GraphicsPath ()) { gp.AddLine (0, 1, 2, 3); gp.SetMarkers (); gp.StartFigure (); gp.AddLine (20, 21, 22, 23); gp.AddBezier (5, 6, 7, 8, 9, 10, 11, 12); PointF[] bp = gp.PathPoints; byte[] expected = new byte[] { 0, 3, 3, 3, 1, 33, 0, 1 }; gp.Reverse (); PointF[] ap = gp.PathPoints; byte[] at = gp.PathTypes; int count = gp.PointCount; Assert.AreEqual (bp.Length, count, "PointCount"); for (int i = 0; i < count; i++) { Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ()); Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ()); } } }
static public void PolyDraw( System.Drawing.Drawing2D.GraphicsPath pPath, POINT[] lppt, byte[] lpbTypes, int cCount) { int nIndex; POINT pptLastMoveTo = new POINT(); POINT pptPrev = new POINT(); bool bLastMoveToNull = true; // for each of the points we have... for (nIndex = 0; nIndex < cCount; nIndex++) { switch (lpbTypes[nIndex]) { case PT_MOVETO: if (bLastMoveToNull == false && nIndex > 0) { pPath.CloseFigure(); } pptLastMoveTo = lppt[nIndex]; bLastMoveToNull = false; pptPrev = lppt[nIndex]; break; case PT_LINETO | PT_CLOSEFIGURE: pPath.AddLine(pptPrev.X, pptPrev.Y, lppt[nIndex].X, lppt[nIndex].Y); pptPrev = lppt[nIndex]; if (bLastMoveToNull == false) { pPath.CloseFigure(); pptPrev = pptLastMoveTo; } bLastMoveToNull = true; break; case PT_LINETO: pPath.AddLine(pptPrev.X, pptPrev.Y, lppt[nIndex].X, lppt[nIndex].Y); pptPrev = lppt[nIndex]; break; case PT_BEZIERTO | PT_CLOSEFIGURE: //ASSERT(nIndex + 2 <= cCount); pPath.AddBezier( pptPrev.X, pptPrev.Y, lppt[nIndex].X, lppt[nIndex].Y, lppt[nIndex + 1].X, lppt[nIndex + 1].Y, lppt[nIndex + 2].X, lppt[nIndex + 2].Y); nIndex += 2; pptPrev = lppt[nIndex]; if (bLastMoveToNull == false) { pPath.CloseFigure(); pptPrev = pptLastMoveTo; } bLastMoveToNull = true; break; case PT_BEZIERTO: //ASSERT(nIndex + 2 <= cCount); pPath.AddBezier( pptPrev.X, pptPrev.Y, lppt[nIndex].X, lppt[nIndex].Y, lppt[nIndex + 1].X, lppt[nIndex + 1].Y, lppt[nIndex + 2].X, lppt[nIndex + 2].Y); nIndex += 2; pptPrev = lppt[nIndex]; break; } } // If the figure was never closed and should be, // close it now. if (bLastMoveToNull == false && nIndex > 1) { pPath.AddLine(pptPrev.X, pptPrev.Y, pptLastMoveTo.X, pptLastMoveTo.Y); //pPath->CloseFigure(); } }
public void StartClose_AddBezier () { GraphicsPath path = new GraphicsPath (); path.AddLine (1, 1, 2, 2); path.AddBezier (10, 10, 100, 100, 20, 20, 200, 200); path.AddLine (10, 10, 20, 20); byte[] types = path.PathTypes; // check first types Assert.AreEqual (0, types[0], "start/Line"); Assert.AreEqual (1, types[2], "start/Bezier"); // check last types Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier"); Assert.AreEqual (1, types[path.PointCount - 1], "end/Line"); }
/// <summary> /// Draw a "between items" line at the given co-ordinates /// </summary> /// <param name="g"></param> /// <param name="x1"></param> /// <param name="y1"></param> /// <param name="x2"></param> /// <param name="y2"></param> protected virtual void DrawBetweenLine(Graphics g, int x1, int y1, int x2, int y2) { using (Brush b = new SolidBrush(this.FeedbackColor)) { int x = x1; int y = y1; using (GraphicsPath gp = new GraphicsPath()) { gp.AddLine( x, y + 5, x, y - 5); gp.AddBezier( x, y - 6, x + 3, y - 2, x + 6, y - 1, x + 11, y); gp.AddBezier( x + 11, y, x + 6, y + 1, x + 3, y + 2, x, y + 6); gp.CloseFigure(); g.FillPath(b, gp); } x = x2; y = y2; using (GraphicsPath gp = new GraphicsPath()) { gp.AddLine( x, y + 6, x, y - 6); gp.AddBezier( x, y - 7, x - 3, y - 2, x - 6, y - 1, x - 11, y); gp.AddBezier( x - 11, y, x - 6, y + 1, x - 3, y + 2, x, y + 7); gp.CloseFigure(); g.FillPath(b, gp); } } using (Pen p = new Pen(this.FeedbackColor, 3.0f)) { g.DrawLine(p, x1, y1, x2, y2); } }
public void Reverse_Bezier () { using (GraphicsPath gp = new GraphicsPath ()) { gp.AddBezier (1, 2, 3, 4, 5, 6, 7, 8); Reverse (gp); } }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="bezier"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, XBezier bezier, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r) { var _gfx = gfx as Graphics; Brush brush = ToSolidBrush(bezier.Style.Fill); Pen pen = ToPen(bezier.Style, _scaleToPage); if (bezier.IsFilled) { var path = new GraphicsPath(); path.AddBezier( _scaleToPage(bezier.Point1.X), _scaleToPage(bezier.Point1.Y), _scaleToPage(bezier.Point2.X), _scaleToPage(bezier.Point2.Y), _scaleToPage(bezier.Point3.X), _scaleToPage(bezier.Point3.Y), _scaleToPage(bezier.Point4.X), _scaleToPage(bezier.Point4.Y)); _gfx.FillPath(brush, path); } if (bezier.IsStroked) { _gfx.DrawBezier( pen, _scaleToPage(bezier.Point1.X), _scaleToPage(bezier.Point1.Y), _scaleToPage(bezier.Point2.X), _scaleToPage(bezier.Point2.Y), _scaleToPage(bezier.Point3.X), _scaleToPage(bezier.Point3.Y), _scaleToPage(bezier.Point4.X), _scaleToPage(bezier.Point4.Y)); } brush.Dispose(); pen.Dispose(); }
public void AddBezier_Point () { GraphicsPath gp = new GraphicsPath (); gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4)); CheckBezier (gp); }
public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null) { using (var path = new GraphicsPath ()) { var bb = new BoundingBoxBuilder (); var position = Point.Zero; foreach (var op in ops) { var mt = op as MoveTo; if (mt != null) { var p = mt.Point; position = p; bb.Add (p); continue; } var lt = op as LineTo; if (lt != null) { var p = lt.Point; path.AddLine (Conversions.GetPointF (position), Conversions.GetPointF (p)); position = p; bb.Add (p); continue; } var at = op as ArcTo; if (at != null) { var p = at.Point; path.AddLine (Conversions.GetPointF (position), Conversions.GetPointF (p)); position = p; bb.Add (p); continue; } var ct = op as CurveTo; if (ct != null) { var p = ct.Point; var c1 = ct.Control1; var c2 = ct.Control2; path.AddBezier (Conversions.GetPointF (position), Conversions.GetPointF (c1), Conversions.GetPointF (c2), Conversions.GetPointF (p)); position = p; bb.Add (p); bb.Add (c1); bb.Add (c2); continue; } var cp = op as ClosePath; if (cp != null) { path.CloseFigure (); continue; } throw new NotSupportedException ("Path Op " + op); } var frame = bb.BoundingBox; if (brush != null) { graphics.FillPath (brush.GetBrush (frame), path); } if (pen != null) { var r = Conversions.GetRectangleF (frame); graphics.DrawPath (pen.GetPen (), path); } } }
/// <summary> /// Paints the shape of the person object in the plex. Here you can let your imagination go. /// </summary> /// <param name="g">The graphics canvas onto which to paint</param> public override void Paint(Graphics g) { if (RecalculateSize) { SizeF s = g.MeasureString(Text, Font); Rectangle = new RectangleF(Rectangle.X, Rectangle.Y, s.Width, Math.Max(s.Height + 10, Rectangle.Height)); RecalculateSize = false; //very important! } /* * apath = new GraphicsPath(); * PointF[] pts = new PointF[3]{new PointF(Rectangle.X,Rectangle.Y), new PointF(Rectangle.Right,Rectangle.Top), new PointF(Rectangle.X + Rectangle.Width/2,Rectangle.Bottom)}; * apath.AddClosedCurve(pts); * mRegion = new Region(apath); * g.FillRegion(Brushes.Red,mRegion); * */ apath = new GraphicsPath(); PointF[] pts = new PointF[10] { new PointF(Rectangle.X, Rectangle.Y), new PointF(Rectangle.X, Rectangle.Y + 20), new PointF(Rectangle.Right, Rectangle.Y + 20), new PointF(Rectangle.Right, Rectangle.Y), new PointF(Rectangle.X, Rectangle.Bottom), new PointF(Rectangle.X, Rectangle.Bottom + 20), new PointF(Rectangle.Right, Rectangle.Bottom + 20), new PointF(Rectangle.Right, Rectangle.Bottom), new PointF(Rectangle.X, Rectangle.Y - 20), new PointF(Rectangle.Right, Rectangle.Y - 20) }; Brush br = new LinearGradientBrush(pts[0], pts[3], this.ShapeColor, Color.WhiteSmoke); apath.AddBezier(pts[0], pts[1], pts[2], pts[3]); apath.AddLine(pts[4], pts[0]); apath.AddLine(pts[7], pts[3]); apath.AddBezier(pts[4], pts[5], pts[6], pts[7]); mRegion = new Region(apath); g.FillRegion(br, mRegion); apath = new GraphicsPath(); apath.AddBezier(pts[0], pts[8], pts[9], pts[3]); apath.AddBezier(pts[0], pts[1], pts[2], pts[3]); mRegion = new Region(apath); g.FillRegion(this.BackgroundBrush, mRegion); if (ShowLabel) { StringFormat sf = new StringFormat(); sf.Alignment = stringAlignment; switch (stringAlignment) { case StringAlignment.Center: g.DrawString(Text, Font, TextBrush, Rectangle.X + (Rectangle.Width / 2), Rectangle.Y + 3, sf); break; case StringAlignment.Far: g.DrawString(Text, Font, TextBrush, Rectangle.X + Rectangle.Width - 1, Rectangle.Y + 3, sf); break; case StringAlignment.Near: g.DrawString(Text, Font, TextBrush, Rectangle.X + 1, Rectangle.Y + 3, sf); break; } } base.Paint(g); }