public static RectangleF AddWindowsFontOutline(this GraphicsPath graphicsPath, FontOutline outline, float size, PointF origin, bool enableHorizontalCenteringMode) { if (outline is null || outline.Polygons.Length == 0) { return(new RectangleF(origin, SizeF.Empty)); } float horizontalOffset = enableHorizontalCenteringMode ? outline.GlyphMetrics.CalcHorizontalCenteringOffset(outline.EmSquare) : 0; var scaleFactor = size / outline.EmSquare; foreach (var polygon in outline.Polygons) { graphicsPath.StartFigure(); var startPoint = polygon.StartPoint; foreach (var curve in polygon.Curves) { var points = curve.ToGraphicsPathPoint(ref startPoint, horizontalOffset, scaleFactor, origin); if (curve.PrimitiveType == TtPrimitiveTypes.Line) { graphicsPath.AddLines(points); } else if (curve.PrimitiveType == TtPrimitiveTypes.CubicBezierSpline) { graphicsPath.AddBeziers(points); } else if (curve.PrimitiveType == TtPrimitiveTypes.QuadraticBezierSpline) { var curveCount = (points.Length - 1) / 2; var cubicBezierPoints = new PointF[points.Length + curveCount]; for (int i = 0; i < curveCount; i++) { var c0 = points[i * 3 + 0]; var c1 = points[i * 3 + 1]; var c2 = points[i * 3 + 2]; cubicBezierPoints[i * 4 + 0] = c0; cubicBezierPoints[i * 4 + 1] = Add(Mul(c0, 1 / 3f), Mul(c1, 2 / 3f)); cubicBezierPoints[i * 4 + 2] = Add(Mul(c2, 1 / 3f), Mul(c1, 2 / 3f)); cubicBezierPoints[i * 4 + 3] = c2; } graphicsPath.AddBeziers(cubicBezierPoints); } } graphicsPath.CloseFigure(); } return(new RectangleF(origin, new SizeF(outline.EmSquare, outline.EmSquare))); }
private void AddBeziersExample(PaintEventArgs e, Point[] myArray) { // Adds two Bezier curves. //Point[] myArray = // { // new Point(20, 100), // new Point(40, 75), // new Point(60, 125), // new Point(80, 100), // new Point(100, 50), // new Point(120, 150), // new Point(140, 100) // }; // Create the path and add the curves. GraphicsPath myPath = new GraphicsPath(); myPath.AddBeziers(myArray); // Draw the path to the screen. Pen myPen = new Pen(Color.Black, 2); e.Graphics.DrawPath(myPen, myPath); }
/// <summary> /// Here we recalculate the freehand path by smoothing out the lines with Beziers. /// </summary> private void RecalculatePath() { isRecalculated = true; // Dispose the previous path, if we have one if (freehandPath != null) { freehandPath.Dispose(); } freehandPath = new GraphicsPath(); // Here we can put some cleanup... like losing all the uninteresting points. if (capturePoints.Count > 3) { int index = 0; while ((capturePoints.Count - 1) % 3 != 0) { // duplicate points, first at 50% than 25% than 75% capturePoints.Insert((int)(capturePoints.Count*POINT_OFFSET[index]), capturePoints[(int)(capturePoints.Count*POINT_OFFSET[index++])]); } freehandPath.AddBeziers(capturePoints.ToArray()); } // Recalculate the bounds myBounds = Rectangle.Round(freehandPath.GetBounds()); }
public void DrawBeziers (Pen pen, PointF [] points) { GraphicsPath path = new GraphicsPath(); path.AddBeziers(points); DrawPath(pen, path); }
static List<PointF> GetArrowLinePoints(float x1, float y1, float x2, float y2, out float centerX, out float centerY, float extra_thickness = 0) { var widthX = (x2 - x1); var lengthX = Math.Max(60, Math.Abs(widthX / 2)) //+ Math.Max(0, -widthX / 2) ; var lengthY = 0;// Math.Max(-170, Math.Min(-120.0f, widthX - 120.0f)) + 120.0f; if (widthX < 120) lengthX = 60; var yB = ((y1 + y2) / 2) + lengthY;// (y2 + ((y1 - y2) / 2) * 0.75f) + lengthY; var yC = y2 + yB; var xC = (x1 + x2) / 2; var xA = x1 + lengthX; var xB = x2 - lengthX; /* if (widthX >= 120) { xA = xB = xC = x2 - 60; } //*/ var points = new List<PointF> { new PointF(x1, y1), new PointF(xA, y1), new PointF(xB, y2), new PointF(x2 - GraphConstants.ConnectorSize - extra_thickness, y2) }; var t = 1.0f;//Math.Min(1, Math.Max(0, (widthX - 30) / 60.0f)); var yA = (yB * t) + (yC * (1 - t)); if (widthX <= 120) { points.Insert(2, new PointF(xB, yA)); points.Insert(2, new PointF(xC, yA)); points.Insert(2, new PointF(xA, yA)); } //* using (var tempPath = new GraphicsPath()) { tempPath.AddBeziers(points.ToArray()); tempPath.Flatten(); points = tempPath.PathPoints.ToList(); } //*/ var angles = new PointF[points.Count - 1]; var lengths = new float[points.Count - 1]; float totalLength = 0; centerX = 0; centerY = 0; points.Add(points[points.Count - 1]); for (int i = 0; i < points.Count - 2; i++) { var pt1 = points[i]; var pt2 = points[i + 1]; var pt3 = points[i + 2]; var deltaX = (float)((pt2.X - pt1.X) + (pt3.X - pt2.X)); var deltaY = (float)((pt2.Y - pt1.Y) + (pt3.Y - pt2.Y)); var length = (float)Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)); if (length <= 1.0f) { points.RemoveAt(i); i--; continue; } lengths[i] = length; totalLength += length; angles[i].X = deltaX / length; angles[i].Y = deltaY / length; } float midLength = (totalLength / 2.0f);// * 0.75f; float startWidth = extra_thickness + 0.75f; float endWidth = extra_thickness + (GraphConstants.ConnectorSize / 3.5f); float currentLength = 0; var newPoints = new List<PointF>(); newPoints.Add(points[0]); for (int i = 0; i < points.Count - 2; i++) { var angle = angles[i]; var point = points[i + 1]; var length = lengths[i]; var width = (((currentLength * (endWidth - startWidth)) / totalLength) + startWidth); var angleX = angle.X * width; var angleY = angle.Y * width; var newLength = currentLength + length; if (currentLength <= midLength && newLength >= midLength) { var dX = point.X - points[i].X; var dY = point.Y - points[i].Y; var t1 = midLength - currentLength; var l = length; centerX = points[i].X + ((dX * t1) / l); centerY = points[i].Y + ((dY * t1) / l); } var pt1 = new PointF(point.X - angleY, point.Y + angleX); var pt2 = new PointF(point.X + angleY, point.Y - angleX); if (Math.Abs(newPoints[newPoints.Count - 1].X - pt1.X) > 1.0f || Math.Abs(newPoints[newPoints.Count - 1].Y - pt1.Y) > 1.0f) newPoints.Add(pt1); if (Math.Abs(newPoints[0].X - pt2.X) > 1.0f || Math.Abs(newPoints[0].Y - pt2.Y) > 1.0f) newPoints.Insert(0, pt2); currentLength = newLength; } return newPoints; }
public void AddBeziers_SamePointF () { PointF[] points = new PointF [4] { new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f), new PointF (1f, 1f) }; GraphicsPath gp = new GraphicsPath (); gp.AddBeziers (points); // 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.AddBeziers (points); // 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 AddBeziers_3_PointFs () { GraphicsPath gp = new GraphicsPath (); gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) }); }
public void AddBeziers_3_Points () { GraphicsPath gp = new GraphicsPath (); gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) }); }
public void StartClose_AddBeziers () { GraphicsPath path = new GraphicsPath (); path.AddLine (1, 1, 2, 2); path.AddBeziers (new Point[7] { new Point (10, 10), new Point (20, 10), new Point (20, 20), new Point (30, 20), new Point (40, 40), new Point (50, 40), new Point (50, 50) }); 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"); }
public void Draw(Graphics g, System.Drawing.Color color) { switch (kind) { case SymbolStrokes.Disc: using (Brush b = new SolidBrush(color)) g.FillEllipse(b, new RectangleF(points[0].X - radius, points[0].Y - radius, radius * 2, radius * 2)); break; case SymbolStrokes.Circle: try { using (Pen p = new Pen(color, thickness)) g.DrawEllipse(p, new RectangleF(points[0].X - radius, points[0].Y - radius, radius * 2, radius * 2)); } catch (ExternalException) { // Ignore this exeption. Not sure what causes it. } break; case SymbolStrokes.Polyline: using (Pen p = new Pen(color, thickness)) { p.LineJoin = corners; p.StartCap = ends; p.EndCap = ends; g.DrawLines(p, points); } break; case SymbolStrokes.Polygon: using (Pen p = new Pen(color, thickness)) { p.LineJoin = corners; g.DrawPolygon(p, points); } break; case SymbolStrokes.FilledPolygon: using (Brush b = new SolidBrush(color)) g.FillPolygon(b, points); break; case SymbolStrokes.PolyBezier: using (Pen p = new Pen(color, thickness)) { p.StartCap = ends; p.EndCap = ends; g.DrawBeziers(p, points); } break; case SymbolStrokes.FilledPolyBezier: using (Brush b = new SolidBrush(color)) using (GraphicsPath path = new GraphicsPath()) { path.AddBeziers(points); g.FillPath(b, path); } break; default: Debug.Fail("Bad SymbolStroke kind"); break; } }
internal override PointCollection getOutlinePoly() { PointCollection poly = new PointCollection(0); GraphicsPath arrowPath = new GraphicsPath(FillMode.Alternate); // draw the arrow's line if (style == ArrowStyle.Bezier) { arrowPath.AddBeziers(points.getArray()); } else { arrowPath.AddLines(points.getArray()); } System.Drawing.Pen widenPen = new System.Drawing.Pen(Color.Black, 2 * Constants.getMillimeter(flowChart.MeasureUnit)); arrowPath.Widen(widenPen); arrowPath.Flatten(); poly.AddRange(arrowPath.PathPoints); widenPen.Dispose(); arrowPath.Dispose(); return poly; }
/// <summary> /// Updates the arrow's text. /// </summary> private void updateText() { if (textStyle == ArrowTextStyle.Follow) { textLayout = new TextLayout(); PointF[] poly = points.getArray(); if (style == ArrowStyle.Bezier) { GraphicsPath temp = new GraphicsPath(); temp.AddBeziers(poly); temp.Flatten(new Matrix(), 1f); poly = temp.PathPoints; temp.Dispose(); } // Check whether to reverse the arrow points if (poly[0].X > poly[poly.Length - 1].X) { for (int i = 0; i < poly.Length / 2; i++) { PointF t = poly[i]; poly[i] = poly[poly.Length - i - 1]; poly[poly.Length - i - 1] = t; } } Graphics graphics = flowChart.CreateGraphics(); flowChart.setTransforms(graphics); float textHeight = Font.GetHeight(graphics); PointF startPoint = poly[0]; for (int i = 0; i < poly.Length - 1; i++) { // The processed segment PointF p = poly[i]; PointF t = poly[i + 1]; float a = 0; float r = 0; GeoConvert.DekartToPolar(t, p, ref a, ref r); // Find the angle between the segments float angle = 0; // The angle for the last segment remains 0 float a2 = 0; float r2 = 0; if (i < poly.Length - 2) { // The next segment PointF p2 = poly[i + 1]; PointF t2 = poly[i + 2]; GeoConvert.DekartToPolar(p2, t2, ref a2, ref r2); if (a2 < a) a2 += 360; angle = a2 - a; } // Calculate the real length (the start point might have been offset) float rr = 0; float aa = 0; GeoConvert.DekartToPolar(startPoint, t, ref aa, ref rr); PointF d1 = startPoint; PointF d2 = t; PointF d3 = PointF.Empty; PointF d4 = PointF.Empty; float width = 0; if (angle < 180) { // No restrictions GeoConvert.PolarToDekart(d1, a - 90, textHeight, ref d4); GeoConvert.PolarToDekart(d2, a - 90, textHeight, ref d3); width = rr; startPoint = t; } else { GeoConvert.PolarToDekart(d1, a - 90, textHeight, ref d4); float alpha2 = (360 - angle) / 2; float xx = textHeight / (float)Math.Sin(Rad(alpha2)); float xxProj = (float)Math.Sqrt(Math.Pow(xx, 2) - Math.Pow(textHeight, 2)); if (xxProj > rr) { xxProj = rr; xx = (float)Math.Sqrt(Math.Pow(xxProj, 2) + Math.Pow(textHeight, 2)); } GeoConvert.PolarToDekart(d2, a - alpha2, xx, ref d3); GeoConvert.PolarToDekart(d2, a, xxProj, ref d2); width = rr - xxProj; if (xxProj > r2) xxProj = r2; GeoConvert.PolarToDekart(t, a2, xxProj, ref startPoint); } textLayout.Rectangles.Add(new RectangleF(d4.X, d4.Y, width, textHeight)); textLayout.Angles.Add(180 - a); } string tempText = this.text; for (int i = 0; i < textLayout.Rectangles.Count; i++) { RectangleF rect = (RectangleF)textLayout.Rectangles[i]; float angle = (float)textLayout.Angles[i]; int chars = Fit(tempText, rect.Width, Font, graphics); if (chars == 0) { textLayout.Strings.Add(""); continue; } string part = tempText.Substring(0, chars); tempText = tempText.Substring(chars); textLayout.Strings.Add(part); } graphics.Dispose(); } }
public void AddBeziers_PointFArr() { PointF [] points = new PointF [] { new PointF(20.01f, 100.1f), new PointF(40.02f, 75.2f), new PointF(60.03f, 125.3f), new PointF(80.04f, 100.4f), new PointF(100.05f, 50.5f), new PointF(120.06f, 150.6f), new PointF(140.07f, 100.7f)}; path = new GraphicsPath(); path.AddBeziers(points); Assert.AreEqual (7, path.PointCount); PointF [] expectedPoints = new PointF [] { new PointF(20.01f, 100.1f), new PointF(40.02f, 75.2f), new PointF(60.03f, 125.3f), new PointF(80.04f, 100.4f), new PointF(100.05f, 50.5f), new PointF(120.06f, 150.6f), new PointF(140.07f, 100.7f)}; for(int i = 0; i < path.PointCount; i++) { DrawingTest.AssertAlmostEqual(expectedPoints [i], path.PathPoints [i]); } byte [] expectedTypes = new byte [] { (byte) PathPointType.Start, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3}; for (int i=0; i < expectedTypes.Length; i++) { Assert.AreEqual (expectedTypes [i], path.PathTypes [i]); } t.Graphics.DrawPath (p, path); t.Show (); //t.AssertCompare (); }
public void AddBeziers_PointArr() { Point [] points = new Point [] {new Point(20, 100), new Point(40, 75), new Point(60, 125), new Point(80, 100), new Point(100, 50), new Point(120, 150), new Point(140, 100)}; path = new GraphicsPath(); path.AddBeziers(points); Assert.AreEqual (7, path.PointCount); PointF [] expectedPoints = new PointF [] { new PointF(20f, 100f), new PointF(40f, 75f), new PointF(60f, 125f), new PointF(80f, 100f), new PointF(100f, 50f), new PointF(120f, 150f), new PointF(140f, 100f)}; for(int i = 0; i < path.PointCount; i++) { DrawingTest.AssertAlmostEqual(expectedPoints [i], path.PathPoints [i]); } byte [] expectedTypes = new byte [] { (byte) PathPointType.Start, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3}; for (int i=0; i < expectedTypes.Length; i++) { Assert.AreEqual (expectedTypes [i], path.PathTypes [i]); } t.Graphics.DrawPath (p, path); t.Show (); //t.AssertCompare (); }
public override void OnRendererTabPageItem(Graphics gfx, Rectangle tabPageItemRct, string tabPageText, int index, CommonObjects.ButtonState btnState) { Rectangle itemRct = tabPageItemRct; SmoothingMode mode = gfx.SmoothingMode; gfx.SmoothingMode = SmoothingMode.AntiAlias; Bitmap itemBitmap = null; switch (tabPageText.ToUpperInvariant()) { case "SOLUTION &EXPLORER": itemBitmap = Resources.AddToFavoritesHS; break; case "PRO&PERTIES": itemBitmap = Resources.AlignTableCellMiddleLeftJustHS; break; case "&TOOLBOX": itemBitmap = Resources.compareversionsHS; break; case "ERROR &LIST": itemBitmap = Resources.NewWindow; break; case "&OUTPUT": itemBitmap = Resources.XSDSchema_RemoveAllButSelectionFromWorkspaceCmd; break; default: itemBitmap = Resources.AddToFavoritesHS; break; } using (StringFormat format = new StringFormat(StringFormatFlags.LineLimit)) { format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; using (GraphicsPath path = new GraphicsPath()) { bool isSelected = false; Color textColor = DisabledTabPageItemForeColor; switch (btnState) { case CommonObjects.ButtonState.Hover: case CommonObjects.ButtonState.Normal: textColor = TabPageItemForeColor; goto case CommonObjects.ButtonState.Disabled; case CommonObjects.ButtonState.Pressed: isSelected = true; textColor = SelectedTabPageItemForeColor; using (Brush brush = new SolidBrush(BackColor)) gfx.FillRectangle(brush, tabPageItemRct.Left - 1, tabPageItemRct.Top - 1, tabPageItemRct.Width + 1, tabPageItemRct.Height + 1); goto case CommonObjects.ButtonState.Disabled; case CommonObjects.ButtonState.Disabled: int xOffset; if (index == 0) { xOffset = itemRct.Left + 10 + (itemRct.Height / 2); Point[] points = new Point[] { new Point(itemRct.Left, itemRct.Bottom), new Point(itemRct.Left, itemRct.Bottom - 4), new Point(itemRct.Left + 2, itemRct.Bottom - 11), new Point(xOffset, itemRct.Top), }; path.AddBeziers(points); } else if (isSelected) { xOffset = itemRct.Left + (itemRct.Height / 2); Point[] points = new Point[] { new Point(itemRct.Left - 10, itemRct.Bottom), new Point(itemRct.Left - 10, itemRct.Bottom - 4), new Point(itemRct.Left - 8, itemRct.Bottom - 11), new Point(xOffset, itemRct.Top), }; path.AddBeziers(points); } else { xOffset = itemRct.Left + (itemRct.Height / 2); path.AddLine(itemRct.Left, itemRct.Bottom, itemRct.Left, itemRct.Top + (itemRct.Height / 2) - 3); Point[] points = new Point[] { new Point(itemRct.Left, itemRct.Top + (itemRct.Height / 2) - 4), new Point(itemRct.Left, itemRct.Top + (itemRct.Height / 2) - 5), new Point(itemRct.Left + 2, itemRct.Top + 2), new Point(xOffset, itemRct.Top), }; path.AddBeziers(points); } path.AddLine(xOffset + 1, itemRct.Top, itemRct.Right - 5, itemRct.Top); path.AddLine(itemRct.Right - 1, itemRct.Top + 2, itemRct.Right - 1, itemRct.Bottom); path.CloseFigure(); using (LinearGradientBrush brush = new LinearGradientBrush(itemRct, Color.FromArgb(248, 247, 242), isSelected ? Color.White : Color.FromArgb(233, 233, 216), LinearGradientMode.Vertical)) { Blend bl = new Blend(2); bl.Factors = new float[] { 0.4F, 1.0F }; bl.Positions = new float[] { 0.0F, 1.0F }; brush.Blend = bl; gfx.FillPath(brush, path); } using (Pen pen = new Pen(SystemColors.ControlDark)) { gfx.DrawPath(pen, path); if (isSelected) { pen.Color = Color.White; gfx.DrawLine(pen, index == 0 ? itemRct.Left + 1 : itemRct.Left - 9, itemRct.Bottom, itemRct.Right - 2, itemRct.Bottom); } } gfx.DrawImage(itemBitmap, xOffset - 3, itemRct.Top + ItemObjectsDrawingMargin + 1, itemBitmap.Width, itemBitmap.Height); xOffset = ItemObjectsDrawingMargin + itemBitmap.Width; itemRct.X += xOffset; itemRct.Width -= xOffset; using (Font font = new Font(NeoTabPageItemsFont, isSelected ? FontStyle.Bold : FontStyle.Regular)) { itemRct.X += 2; itemRct.Width -= 2; itemRct.Y += 2; itemRct.Height -= 2; if (index == 0) { itemRct.X += 10; itemRct.Width -= 10; } using (Brush brush = new SolidBrush(textColor)) gfx.DrawString(tabPageText, font, brush, itemRct, format); } break; } } } gfx.SmoothingMode = mode; }
public override void OnRendererTabPageItem(Graphics gfx, Rectangle tabPageItemRct, string tabPageText, int index, CommonObjects.ButtonState btnState) { Rectangle itemRct = tabPageItemRct; SmoothingMode mode = gfx.SmoothingMode; gfx.SmoothingMode = SmoothingMode.AntiAlias; using (StringFormat format = new StringFormat(StringFormatFlags.LineLimit)) { format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; using (GraphicsPath path = new GraphicsPath()) { bool isSelected = false; Color textColor = DisabledTabPageItemForeColor; switch (btnState) { case CommonObjects.ButtonState.Hover: case CommonObjects.ButtonState.Normal: textColor = TabPageItemForeColor; goto case CommonObjects.ButtonState.Disabled; case CommonObjects.ButtonState.Pressed: isSelected = true; textColor = SelectedTabPageItemForeColor; using (Brush brush = new SolidBrush(BackColor)) gfx.FillRectangle(brush, tabPageItemRct.Left - 1, tabPageItemRct.Top - 1, tabPageItemRct.Width + 1, tabPageItemRct.Height + 1); goto case CommonObjects.ButtonState.Disabled; case CommonObjects.ButtonState.Disabled: int xOffset; if (index == 0) { xOffset = itemRct.Left + 10 + (itemRct.Height / 2); Point[] points = new Point[] { new Point(itemRct.Left, itemRct.Bottom), new Point(itemRct.Left, itemRct.Bottom - 4), new Point(itemRct.Left + 2, itemRct.Bottom - 11), new Point(xOffset, itemRct.Top), }; path.AddBeziers(points); } else if (isSelected) { xOffset = itemRct.Left + (itemRct.Height / 2); Point[] points = new Point[] { new Point(itemRct.Left - 10, itemRct.Bottom), new Point(itemRct.Left - 10, itemRct.Bottom - 4), new Point(itemRct.Left - 8, itemRct.Bottom - 11), new Point(xOffset, itemRct.Top), }; path.AddBeziers(points); } else { xOffset = itemRct.Left + (itemRct.Height / 2); path.AddLine(itemRct.Left, itemRct.Bottom, itemRct.Left, itemRct.Top + (itemRct.Height / 2) - 3); Point[] points = new Point[] { new Point(itemRct.Left, itemRct.Top + (itemRct.Height / 2) - 4), new Point(itemRct.Left, itemRct.Top + (itemRct.Height / 2) - 5), new Point(itemRct.Left + 2, itemRct.Top + 2), new Point(xOffset, itemRct.Top), }; path.AddBeziers(points); } path.AddLine(xOffset + 1, itemRct.Top, itemRct.Right - 5, itemRct.Top); path.AddLine(itemRct.Right - 1, itemRct.Top + 2, itemRct.Right - 1, itemRct.Bottom); path.CloseFigure(); using (LinearGradientBrush brush = new LinearGradientBrush(itemRct, Color.FromArgb(248, 247, 242), isSelected ? Color.White : Color.FromArgb(233, 233, 216), LinearGradientMode.Vertical)) { Blend bl = new Blend(2); bl.Factors = new float[] { 0.4F, 1.0F }; bl.Positions = new float[] { 0.0F, 1.0F }; brush.Blend = bl; gfx.FillPath(brush, path); } using (Pen pen = new Pen(SystemColors.ControlDark)) { gfx.DrawPath(pen, path); if(isSelected) { pen.Color = Color.White; gfx.DrawLine(pen, index == 0 ? itemRct.Left + 1 : itemRct.Left - 9, itemRct.Bottom, itemRct.Right - 2, itemRct.Bottom); } } using (Font font = new Font(NeoTabPageItemsFont, isSelected ? FontStyle.Bold : FontStyle.Regular)) { itemRct.X += 2; itemRct.Width -= 2; itemRct.Y += 2; itemRct.Height -= 2; if (index == 0) { itemRct.X += 6; itemRct.Width -= 6; } using (Brush brush = new SolidBrush(textColor)) gfx.DrawString(tabPageText, font, brush, itemRct, format); } break; } } } gfx.SmoothingMode = mode; }
//Code to draw path for the line public override void DrawPath() { if (Container == null) return; if (ControlPoints == null) return; //Get the start and end location depending on start shapes etc PointF startLocation = GetOriginLocation(Start,End); PointF endLocation = GetOriginLocation(End,Start); //Add the points to the solution ArrayList points = new ArrayList(); points.Add(startLocation); //Add the control points //If bezier must be 2,5,8 control points etc PointF[] controlPoints; //Set up control points if (CurveType == CurveType.Bezier) { //Must be 2, 5, 8 etc if (mControlPoints.GetUpperBound(0) < 1) throw new CurveException("Bezier must contain at least 2 control points."); int intMax = (((int) (mControlPoints.GetUpperBound(0) - 1) / 3) * 3) + 2; controlPoints = new PointF[intMax]; for (int i = 0; i < intMax; i++ ) { controlPoints[i] = mControlPoints[i]; } } else { controlPoints = mControlPoints; } points.InsertRange(1,controlPoints); //Add the end points points.Add(endLocation); //Draw the path GraphicsPath path = new GraphicsPath(); if (CurveType == CurveType.Bezier) { path.AddBeziers((PointF[]) points.ToArray(typeof(PointF))); } else { path.AddCurve((PointF[]) points.ToArray(typeof(PointF)),Tension); } SetPoints(points); //Calculate path rectangle RectangleF rect = path.GetBounds(); SetRectangle(rect); //Sets the bounding rectangle SetPath(path); //setpath moves the line to 0,0 }
public void Reverse_Beziers () { using (GraphicsPath gp = new GraphicsPath ()) { Point[] beziers = new Point[] { new Point (1,2), new Point (3,4), new Point (5,6), new Point (7,8), new Point (9,10), new Point (11,12), new Point (13,14) }; gp.AddBeziers (beziers); Reverse (gp); } }
public void DrawBeziers(Pen pen, PointF[] points) { using (var path = new GraphicsPath()) { path.AddBeziers(points); DrawPath(pen, path); } }
public void AddBeziers_Point () { GraphicsPath gp = new GraphicsPath (); gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) }); CheckBezier (gp); }
private void AddBeziers2(Graphics g) { // Adds two Bezier curves. PointF[] myArray = { new PointF(20, 100), new PointF(40, 75), new PointF(60, 125), new PointF(80, 100), new PointF(100, 50), new PointF(120, 150), new PointF(140, 100) }; // Create the path and add the curves. GraphicsPath myPath = new GraphicsPath(); myPath.AddBeziers(myArray); // Draw the path to the screen. Pen myPen = new Pen(Color.Black, 2); g.DrawPath(myPen, myPath); }
public void AddBeziers_PointF () { GraphicsPath gp = new GraphicsPath (); gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) }); CheckBezier (gp); }
static private GraphicsPath Beziers () { GraphicsPath path = new GraphicsPath (); path.AddBeziers (new Point[7] { new Point (20, 100), new Point (70, 10), new Point (130, 200), new Point (180, 100), new Point (200, 100), new Point (240, 240), new Point (20, 100) }); return path; }
/// <summary> /// Repaints the form with cool background and stuff /// </summary> /// <param name="graph">The graphics object to paint to, the element will be drawn to 0, 0</param> public override void Paint(Graphics graph) { //Draws Rectangular Shapes if (Shape == ModelShape.Arrow) { _arrowPath = new GraphicsPath(); //Draws the basic shape Pen arrowPen; if (Highlight < 1) arrowPen = new Pen(Color.Cyan, 3F); else arrowPen = new Pen(Color.Black, 3F); //Draws the curved arrow Point[] lineArray = new Point[4]; lineArray[0] = new Point(_startPoint.X, _startPoint.Y); lineArray[1] = new Point(_startPoint.X - ((_startPoint.X - _stopPoint.X) / 3), _startPoint.Y); lineArray[2] = new Point(_stopPoint.X - ((_stopPoint.X - _startPoint.X) / 3), _stopPoint.Y); lineArray[3] = new Point(_stopPoint.X, _stopPoint.Y); graph.DrawBeziers(arrowPen, lineArray); _arrowPath.AddBeziers(lineArray); _arrowPath.Flatten(); //Draws the arrow head Point[] arrowArray = new Point[3]; arrowArray[0] = _stopPoint; arrowArray[1] = new Point(_stopPoint.X - (5 * Math.Sign(_stopPoint.X - _startPoint.X)), _stopPoint.Y - 2); arrowArray[2] = new Point(_stopPoint.X - (5 * Math.Sign(_stopPoint.X - _startPoint.X)), _stopPoint.Y + 2); graph.DrawPolygon(arrowPen, arrowArray); //Garbage collection arrowPen.Dispose(); } }
/// <summary> /// 随机生成贝塞尔曲线 /// </summary> /// <param name="bmp">一个图片的实例</param> /// <param name="lineNum">线条数量</param> /// <returns></returns> public Bitmap DrawRandomBezier(Int32 lineNum) { Bitmap b = new Bitmap(bgWidth, bgHeight); b.MakeTransparent(); Graphics g = Graphics.FromImage(b); g.Clear(Color.Transparent); g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; GraphicsPath gPath1 = new GraphicsPath(); Int32 lineRandNum = random.Next(lineNum); for (int i = 0; i < (lineNum - lineRandNum); i++) { Pen p = new Pen(GetRandomDeepColor()); Point[] point = { new Point(random.Next(1, (b.Width/10)), random.Next(1, (b.Height))), new Point(random.Next((b.Width/10)*2, (b.Width/10)*4), random.Next(1, (b.Height))), new Point(random.Next((b.Width/10)*4, (b.Width/10)*6), random.Next(1, (b.Height))), new Point(random.Next((b.Width/10)*8, b.Width), random.Next(1, (b.Height))) }; gPath1.AddBeziers(point); g.DrawPath(p, gPath1); p.Dispose(); } for (int i = 0; i < lineRandNum; i++) { Pen p = new Pen(GetRandomDeepColor()); Point[] point = { new Point(random.Next(1, b.Width), random.Next(1, b.Height)), new Point(random.Next((b.Width/10)*2, b.Width), random.Next(1, b.Height)), new Point(random.Next((b.Width/10)*4, b.Width), random.Next(1, b.Height)), new Point(random.Next(1, b.Width), random.Next(1, b.Height)) }; gPath1.AddBeziers(point); g.DrawPath(p, gPath1); p.Dispose(); } return b; }
/// <summary> /// Produces DXF output from various type of lines /// </summary> /// <param name="pt">Point array of the line points</param> /// <param name="crLine">Line color</param> /// <param name="LayerName">Name of the layer to place the line</param> /// <param name="dlt">Line type according to DxLineType enum</param> /// <param name="dash">Line dash style</param> /// <param name="LineWidth">Used for bezier curves ( if 8 - points, 16 - controls points )</param> /// <returns>DXF output string</returns> public string Pt2String(PointF[] pt, Color crLine , string LayerName, DxLineType dlt , DashStyle dash , Single LineWidth ) { string sResult = ""; bool IsClosedLine = false; long SegCount = 0; bool FirstOrLast = false; try { // Validating input parameters if ( pt == null ) throw new Exception("Null points array passed"); if ( pt.Length == 0 ) throw new Exception("Empty points array passed"); IsClosedLine = (pt[0] == pt[pt.Length-1]); if (( dlt == DxLineType.ltSingle) || (dlt == DxLineType.ltClosedSingle)) SegCount = pt.Length - 1; else SegCount = pt.Length; // Processing all line points according to its type for ( int i=0; i< SegCount ; i++) { FirstOrLast =((i ==0) || (i == SegCount-1)); switch ( dlt) { case DxLineType.ltSingle: case DxLineType.ltClosedSingle: sResult+=String.Format(provider, "0\nLINE\n 100\nAcDbEntity\n{0:HAN} 8\n{1}\n 6\n{6:DASH_STYLE}\n62\n{0:ACI}\n 100\nAcDbLine\n 10\n{2:U}\n 20\n{3:U}\n 11\n{4:U}\n 21\n{5:U}\n", crLine, LayerName, pt[i].X, pt[i].Y, pt[i+1].X, pt[i+1].Y, dash); break; case DxLineType.ltBezier: sResult+=String.Format(provider, " 0\nVERTEX\n 100\nAcDbEntity\n{0:HAN} 8\n{2}\n 62\n{4:ACI}\n100\nAcDbVertex\n 100\nAcDb2dVertex\n 10\n{0:U}\n 20\n{1:U}\n 70\n{3}\n", pt[i].X, pt[i].Y, LayerName, 16 , crLine, dash); break; case DxLineType.ltVertex: sResult+=String.Format(provider, " 0\nVERTEX\n 100\nAcDbEntity\n{0:HAN} 8\n{2}\n 62\n{4:ACI}\n100\nAcDbVertex\n 100\nAcDb2dVertex\n 10\n{0:U}\n 20\n{1:U}\n 70\n{3}\n", pt[i].X, pt[i].Y, LayerName, LineWidth, crLine); break; case DxLineType.ltPoly: sResult+=String.Format(provider, " 10\n{0:U}\n 20\n{1:U}\n", pt[i].X, pt[i].Y); break; case DxLineType.ltHatch: sResult+=String.Format(provider, " 10\n{0:U}\n 20\n{1:U}\n", pt[i].X, pt[i].Y); break; default: throw new Exception("Line type is not supported"); } } // Post - processing some types of line if (dlt == DxLineType.ltClosedSingle) sResult+=String.Format(provider, "0\nLINE\n 100\nAcDbEntity\n{0:HAN} 8\n{1}\n 6\n{6:DASH_STYLE}\n62\n{0:ACI}\n 100\nAcDbLine\n 10\n{2:U}\n 20\n{3:U}\n 11\n{4:U}\n 21\n{5:U}\n", crLine, LayerName, pt[pt.Length - 1].X, pt[pt.Length - 1].Y, pt[0].X, pt[0].Y, dash); if ( dlt == DxLineType.ltPoly ) sResult = String.Format(provider, "0\nLWPOLYLINE\n 100\nAcDbEntity\n{0:HAN} 8\n{1}\n 6\n{5:DASH_STYLE}\n62\n{0:ACI}\n 100\nAcDbPolyline\n 90\n{2}\n 70\n{4}\n{3}", crLine, LayerName, pt.Length , sResult, IsClosedLine ? "1" : "0", dash); if ( dlt == DxLineType.ltBezier ) { GraphicsPath gr_temp = new GraphicsPath(FillMode.Winding); gr_temp.AddBeziers(pt); gr_temp.Flatten(); PointF[] pts2 = gr_temp.PathData.Points as PointF[]; sResult = String.Format(provider, "0\nPOLYLINE\n{0:HAN} 100\nAcDbEntity\n 8\n{0}\n 6\n{4:DASH_STYLE}\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}", LayerName, crLine, sResult, Pt2String(pts2,crLine,LayerName,DxLineType.ltVertex, dash, 8), dash); gr_temp.Dispose(); } } catch ( Exception ex) { sResult = ""; m_status = ex.Message; Trace.WriteLine(String.Format("{0} error {1}\n","DxfHelper.Pt2String",ex.Message)); } return sResult; }
/// <summary> /// Template to get a fill path. /// </summary> /// <param name="gp">Graphics path to fill with data.</param> /// <param name="pdata">The plot data. Don't use the Range property of the pdata, since it is overriden by the next argument.</param> /// <param name="range">The plot range to use.</param> /// <param name="layer">Graphics layer.</param> /// <param name="fillDirection">Designates a bound to fill to.</param> /// <param name="linePoints">The points that mark the line.</param> /// <param name="connectCircular">If true, a circular connection is drawn.</param> private void FillOneRange_PreprocessedPoints( GraphicsPath gp, Processed2DPlotData pdata, IPlotRange range, IPlotArea layer, CSPlaneID fillDirection, PointF[] linePoints, bool connectCircular, double logicalShiftX, double logicalShiftY ) { if (connectCircular) { gp.AddBeziers(linePoints); gp.CloseFigure(); } else { Logical3D r0 = layer.GetLogical3D(pdata, range.OriginalFirstPoint); r0.RX += logicalShiftX; r0.RY += logicalShiftY; layer.CoordinateSystem.GetIsolineFromPlaneToPoint(gp, fillDirection, r0); gp.AddBeziers(linePoints); Logical3D r1 = layer.GetLogical3D(pdata, range.GetOriginalRowIndexFromPlotPointIndex(range.LowerBound + linePoints.Length - 1)); r1.RX += logicalShiftX; r1.RY += logicalShiftY; layer.CoordinateSystem.GetIsolineFromPointToPlane(gp, r1, fillDirection); layer.CoordinateSystem.GetIsolineOnPlane(gp, fillDirection, r1, r0); gp.CloseFigure(); } }