public DrawBezier ( |
||
pen | ||
pt1 | Point | |
pt2 | Point | |
pt3 | Point | |
pt4 | Point | |
return | void |
public override void Draw(System.Drawing.Graphics g) { g.DrawArc(pen, Shape_Point.X, Shape_Point.Y, Width / 2, Height / 2, StartAngle, SweepAngle); g.DrawArc(pen, (MouseDown_Point.X + MouseUp_Point.X) / 2, Shape_Point.Y, Width / 2, Height / 2, StartAngle, SweepAngle); g.DrawBezier(pen, new Point(Shape_Point.X, Shape_Point.Y + Height / 4), new Point(Shape_Point.X + Width / 10, Shape_Point.Y + Height / 4 * 3), new Point(Shape_Point.X + Width / 10 * 4, Shape_Point.Y + Height), new Point(Width / 2 + Shape_Point.X, Shape_Point.Y + Height)); g.DrawBezier(pen, new Point(Shape_Point.X + Width, Shape_Point.Y + Height / 4), new Point(Shape_Point.X + Width - Width / 10, Shape_Point.Y + Height / 4 * 3), new Point(Shape_Point.X + Width - Width / 10 * 4, Shape_Point.Y + Height), new Point(Width / 2 + Shape_Point.X, Shape_Point.Y + Height)); }
public static void DrawEdge( Graphics g, Edge edge ) { // Line if( edge.IsComplex ) { var old_end_cap = edge.LinePen.EndCap; edge.LinePen.EndCap = System.Drawing.Drawing2D.LineCap.Round; for( int seg_ind = 0; seg_ind < edge.Segments.Length - 1; ++seg_ind ) { var segment = edge.Segments[seg_ind]; if( segment.IsLinear ) g.DrawLine(edge.LinePen, segment.Points[0], segment.Points[1]); else g.DrawBezier(edge.LinePen, segment.Points[0], segment.Points[1], segment.Points[2], segment.Points[3]); } edge.LinePen.EndCap = old_end_cap; var last_segment = edge.Segments[edge.Segments.Length - 1]; if( last_segment.IsLinear ) g.DrawLine(edge.LinePen, last_segment.Points[0], last_segment.Points[1]); else g.DrawBezier(edge.LinePen, last_segment.Points[0], last_segment.Points[1], last_segment.Points[2], last_segment.Points[3]); } else { g.DrawLine(edge.LinePen, edge.StartPosition, edge.EndPosition); } // Label if( edge.LabelText != null ) g.DrawString(edge.LabelText, edge.LabelFont, edge.LabelBrush, edge.LabelPosition.X, edge.LabelPosition.Y); }
private void DrawLineCore(Point from, Point to, float width, Color color, LineStyle lineStyle, Action <Pen> initializePen) { using (var brush = new SolidBrush(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B))) using (var pen = new Pen(brush, width)) { initializePen(pen); switch (lineStyle) { case LineStyle.Clean: m_Graphics.DrawLine(pen, from.ToPointF(), to.ToPointF()); break; case LineStyle.Sketchy: using (AntiAliasedGraphics()) { var bezierCurve = new BezierCurve(from, to); m_Graphics.DrawBezier(pen, from.ToPointF(), bezierCurve.FirstControlPoint.ToPointF(), bezierCurve.SecondControlPoint.ToPointF(), to.ToPointF()); } break; default: break; } } }
public override void Draw(Graphics g) { if (this.lineComponent.IsSelected) { g.DrawLine(ViewFactory.BoundingBoxPen, this.lineComponent.StartPoint.X, this.lineComponent.StartPoint.Y, this.lineComponent.ControlPoint1.X, this.lineComponent.ControlPoint1.Y); g.DrawLine(ViewFactory.BoundingBoxPen, this.lineComponent.EndPoint.X, this.lineComponent.EndPoint.Y, this.lineComponent.ControlPoint2.X, this.lineComponent.ControlPoint2.Y); } if (this.lineComponent.ParentMoving) { g.DrawBezier(ViewFactory.LinePen, this.lineComponent.StartPoint.MakePointF(), this.lineComponent.ControlPoint1.MakePointF(), this.lineComponent.ControlPoint2.MakePointF(), this.lineComponent.EndPoint.MakePointF()); } else { g.DrawLines(ViewFactory.LinePen, this.lineComponent.points.ToArray()); /*DrawPoint(g, new FlowChartPoint(points[points.Count/2].X,points[points.Count/2].Y), GraphicsSettings.LabelPen, GraphicsSettings.EdgeBoxWidth);*/ } DrawArrow(g, this.lineComponent.EndPoint, this.lineComponent.ControlPoint2, ViewFactory.ArrowBrush, ViewFactory.ArrowPen, ViewFactory.ArrowLength); if (this.lineComponent.IsSelected) { DrawPoint(g, this.lineComponent.ControlPoint1, ViewFactory.EdgePen, ViewFactory.EdgeBoxWidth); DrawPoint(g, this.lineComponent.ControlPoint2, ViewFactory.EdgePen, ViewFactory.EdgeBoxWidth); } base.Draw(g); }
public void lines(Graphics g, int[,] A, Point[] P, Pen pen) { for (int i = 0; i < A.GetLength(0); i++) { for (int j = 0; j < A.GetLength(0); j++) { if (A[i,j] == 1) { Point p1 = normDistance(P[i], P[j]); Point p2 = normDistance(P[j], P[i]); g.DrawLine(pen, p1,p2); } if (A[i,i] != 0) { Pen self = new Pen(Color.FromArgb(0,255,255),8); int Xs = P[i].X, Ys = P[i].Y + 20; int Xe = Xs, Ye = Ys; int p1X = Xs - 100; int p1Y = Ys + 50; int p2X = Xs + 100; int p2Y = Ys + 50; g.DrawBezier(self, Xs, Ys, p1X, p1Y, p2X, p2Y, Xe, Ye); } } } }
public static Bitmap GetBitmap(Emgu.CV.Image <Bgr, byte> image) { Emgu.CV.Image <Gray, byte> gray = image.Convert <Gray, byte>(); int [] k = new int[gray.Width]; for (int i = 0; i < gray.Width; i++) { for (int j = 0; j < gray.Height; j++) { if (gray[j, i].Intensity <= 200) { k[i]++; } } } Bitmap image2 = new Bitmap(gray.Width, gray.Height); System.Drawing.Graphics p = System.Drawing.Graphics.FromImage(image2); p.Clear(Color.Black); for (int i = 0; i < k.Length - 3; i++) { PointF p1 = new PointF(i, k[i]); PointF p2 = new PointF(i + 1, k[i + 1]); PointF p3 = new PointF(i + 2, k[i + 2]); PointF p4 = new PointF(i + 3, k[i + 3]); p.DrawBezier(new Pen(Brushes.White), p1, p2, p3, p4); } return(image2); }
private void DrawRealTemperature() { double mult1X, mult1Y, mult2X, mult2Y; mult1X = .17; mult1Y = .67; mult2X = .41; mult2Y = .9; Point start, end, ctrl1, ctrl2; double segX = m_width / m_cntX; double segY = m_height / m_cntY; for (int i = 0; i < m_points.Count - 1; i++) { int height = ((Point)m_points[i]).Y - ((Point)m_points[i + 1]).Y; //int width = ((Point)m_points[i]).X - ((Point)m_points[i + 1]).X; double relativeH = height / segY; double relativeW; if (relativeH > 0) { relativeW = Math.Abs(2 * relativeH); } else { relativeW = Math.Abs(.5 * relativeH); } double width = relativeW * segX; if (((Point)m_points[i + 1]).X - width > 0) { start = new Point(((Point)m_points[i + 1]).X, ((Point)m_points[i]).Y); end = new Point((int)(((Point)m_points[i + 1]).X + width), ((Point)m_points[i + 1]).Y); //start = new Point((int)(((Point)m_points[i + 1]).X - width), ((Point)m_points[i]).Y); //end = new Point(((Point)m_points[i + 1]).X, ((Point)m_points[i + 1]).Y); } else { start = new Point(0, ((Point)m_points[i]).Y); end = new Point((int)width, ((Point)m_points[i + 1]).Y); } ctrl1 = new Point((int)(start.X + width * mult1X), (int)(start.Y - height * mult1Y)); ctrl2 = new Point((int)(start.X + width * mult2X), (int)(start.Y - height * mult2Y)); //Debug.WriteLine("Start"); //Debug.WriteLine(start.ToString()); //Debug.WriteLine(ctrl1.ToString()); //Debug.WriteLine(ctrl2.ToString()); //Debug.WriteLine(end.ToString()); m_graphics.DrawBezier(m_penGreen, PointLocation(start), PointLocation(ctrl1), PointLocation(ctrl2), PointLocation(end)); } }
//mouse has been released private void pictureBoxDrawArea_MouseUp(object sender, MouseEventArgs e) { //capture the second x and y coord x2 = e.X; y2 = e.Y; //create a pen to use System.Drawing.Pen myPen; //set the color to the chosen color myPen = new System.Drawing.Pen(button1.BackColor); //create a graphics thingy from the bm System.Drawing.Graphics test = Graphics.FromImage(bm); //bunch of if elses that should be a case of something , basically what state am i in, do something different if (currentstate == state.DrawLine) { test.DrawLine(myPen, x1, y1, x2, y2); } else if (currentstate == state.DrawRect) { test.DrawRectangle(myPen, new Rectangle(x1, y1, x2, y2)); } else if (currentstate == state.DrawElipse) { test.DrawEllipse(myPen, new Rectangle(x1, y1, x2, y2)); } else if (currentstate == state.DrawCurve) { test.DrawBezier(myPen, new Point(x1, y1), new Point(x1, y1), new Point(x2, y2), new Point(x2, y2)); //dont work } else if (currentstate == state.DrawPoly) { // test.DrawPolygon( } else if (currentstate == state.Pencil) { } else if (currentstate == state.Brush) { } else if (currentstate == state.RectSelect) { } else if (currentstate == state.WriteText) { System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); test.DrawString(writetext, drawFont, drawBrush, x1, y1); } //clean up some stuff myPen.Dispose(); test.Dispose(); //show the new image pictureBoxDrawArea.Image = bm; }
private void button4_Click(object sender, EventArgs e) { //Bezier pictureBox1.Refresh(); Pen redPen = new Pen(Color.Red, 3); g.DrawBezier(redPen, 0, 110, 35, 0, 65, 200, 100, 100); }
public override void OnDraw(System.Drawing.Graphics g) { try { g.DrawBezier(new System.Drawing.Pen(new System.Drawing.SolidBrush(this.Color), width), ptStart, ptControl1, ptControl2, ptEnd); } catch { } }
public override void Paint(System.Drawing.Graphics g) { getVertex(); Point[] p = new Point[4]; for (int i = 0; i < p.Length; ++i) { p[i] = new Point(point.X + vertex[i].X, point.Y + vertex[i].Y); } g.DrawBezier(pen, p[0], p[1], p[2], p[3]); }
public override void DrawGraphics(Graphics destination) { DrawGraphics(); using (var pen = Style.CreatePen()) { destination.DrawBezier(pen, ControlPoints[0], ControlPoints[1], ControlPoints[2], ControlPoints[3]); } EditablegeometryCue.DrawGeometry(destination); }
public static void DrawLeftToRightArrow(Graphics g, int x1, int y1, int x2, int y2) { int startLine = 7; int endLine = 15; int bezierStregth = 10; float arrowLength = 7.0f; float arrowWidth = 3.2f; // Shadow g.DrawLine(ArrowShadowPen,x1+1,y1+1,x1+startLine+2,y1+1); g.DrawLine(ArrowShadowPen,x2-endLine,y2+1,x2+1-8,y2+1); g.DrawBezier(ArrowShadowPen, x1+startLine+1,y1+1, x1+startLine+bezierStregth+1,y1+1, x2-endLine-bezierStregth+1,y2+1, x2-endLine+1,y2+1); // Head shadow PointF[] arrowPointsShadow = { new PointF(x2-5-arrowLength+1,y2-arrowWidth+1), new PointF(x2-5+1,y2+1), new PointF(x2-5-arrowLength+1,y2+arrowWidth+1) }; GraphicsPath arrowPathShadow = new GraphicsPath(); arrowPathShadow.AddPolygon(arrowPointsShadow); g.FillPath(ArrowShadowBrush,arrowPathShadow); // Line g.DrawLine(LeftToRightArrowPen,x1,y1,x1+startLine+1,y1); g.DrawLine(LeftToRightArrowPen,x2-endLine-1,y2,x2-8,y2); g.DrawBezier(LeftToRightArrowPen, x1+startLine,y1, x1+startLine+bezierStregth,y1, x2-endLine-bezierStregth,y2, x2-endLine,y2); // Head PointF[] arrowPoints = { new PointF(x2-5-arrowLength,y2-arrowWidth), new PointF(x2-5,y2), new PointF(x2-5-arrowLength,y2+arrowWidth) }; GraphicsPath arrowPath = new GraphicsPath(); arrowPath.AddPolygon(arrowPoints); g.FillPath(LeftToRightArrowBrush,arrowPath); }
public override void Paint(Graphics graphics) { Point pointN = SupplierViewer.GetOutputLineConnectionPoint(Item); Point pointM = ConsumerViewer.GetInputLineConnectionPoint(Item); Point pointN2 = new Point(pointN.X, pointN.Y - Math.Max((int)((pointN.Y - pointM.Y) / 2), 40)); Point pointM2 = new Point(pointM.X, pointM.Y + Math.Max((int)((pointN.Y - pointM.Y) / 2), 40)); using (Pen pen = new Pen(DataCache.IconAverageColour(Item.Icon), 3f)) { graphics.DrawBezier(pen, pointN, pointN2, pointM2, pointM); } }
/// <summary> /// This method draws a Bezier curve. /// </summary> /// <param name="graphics">It receives the Graphics instance</param> /// <param name="array">An array of (x,y) pairs of coordinates used to draw the curve.</param> public static void Bezier(System.Drawing.Graphics graphics, int[] array) { System.Drawing.Pen pen; pen = GraphicsManager.manager.GetPen(graphics); try { graphics.DrawBezier(pen, array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7]); } catch (System.IndexOutOfRangeException e) { throw new System.IndexOutOfRangeException(e.ToString()); } }
public void DrawBezier(Pen pen, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { if (pen == null) { throw new ArgumentNullException("pen"); } lock (bitmapLock) { TryExpand(0.0d, 0.0d, Math.Max(Math.Max(Math.Max(x1, x2), x3), x4), Math.Max(Math.Max(Math.Max(y1, y2), y3), y4), pen.Width); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) { g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.DrawBezier(pen, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } Texturize(); } }
private void butBezier_Click(object sender, EventArgs e) { g = PictureBox1.CreateGraphics(); float startX = 100.0F; float startY = 100.0F; float controlX1 = 200.0F; float controlY1 = 10.0F; float controlX2 = 350.0F; float controlY2 = 50.0F; float endX = 500.0F; float endY = 100.0F; g.DrawBezier(penRed, startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY); }
private void button3_Click_1(object sender, EventArgs e) { pictureBox1.Refresh(); PointF P1 = new PointF(); PointF P2 = new PointF(); // g.DrawLine(pen1, 0, 0, 50, 300); PointF Pstart = new PointF(0, 0); PointF Pend = new PointF(300, 300); P1.X = (float)Double.Parse(textBox1.Text); P1.Y = (float)Double.Parse(textBox2.Text); P2.X = (float)Double.Parse(textBox3.Text); P2.Y = (float)Double.Parse(textBox4.Text); g.DrawBezier(pen1, Pstart, P1, P2, Pend); }
private static void DrawAxons(this Network network, Graphics graphic) { foreach (Axon axon in network.Axons) { Point source = Translate(network, axon.Source).Add(5); Point target = Translate(network, axon.Target).Add(5); Point s2 = source.Shift(50, 0); Point t2 = target.Shift(-50, 0); Color color = Blend(Color.Gray, Color.Red, axon.Signal); float width = (float)axon.Weight*2; Pen axonpen = new Pen(color, width); graphic.DrawBezier(axonpen, source, s2, t2, target); } }
private void DrawBezier(Graphics g) { // Draw a black Bezier curve. Pen pen = new Pen(Color.Black); pen.Width = 5; pen.DashStyle = DashStyle.Dash; // Specify which type of drawing must occur at the ends of the stroke pen.StartCap = LineCap.RoundAnchor; pen.EndCap = LineCap.ArrowAnchor; g.DrawBezier( pen, new Point(10, 30), new Point(30, 200), new Point(50, -100), new Point(70, 100)); }
public override void Paint(System.Drawing.Graphics graphics) { Point pointN = Parent.ScreenToGraph(Parent.PointToClient(Cursor.Position)); Point pointM = pointN; if (SupplierElement != null) { pointN = SupplierElement.GetOutputLineConnectionPoint(Item); } if (ConsumerElement != null) { pointM = ConsumerElement.GetInputLineConnectionPoint(Item); } Point pointN2 = new Point(pointN.X, pointN.Y - Math.Max((int)((pointN.Y - pointM.Y) / 2), 40)); Point pointM2 = new Point(pointM.X, pointM.Y + Math.Max((int)((pointN.Y - pointM.Y) / 2), 40)); using (Pen pen = new Pen(DataCache.IconAverageColour(Item.Icon), 3f)) { graphics.DrawBezier(pen, pointN, pointN2, pointM2, pointM); } }
/// <summary> /// This method draws a Bezier curve. /// </summary> /// <param name="graphics">It receives the Graphics instance</param> /// <param name="array">An array of (x,y) pairs of coordinates used to draw the curve.</param> public static void Bezier(Graphics graphics, int[] array) { Pen pen = Manager.GetPen(graphics); try { graphics.DrawBezier(pen, array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7]); } catch(IndexOutOfRangeException e) { throw new IndexOutOfRangeException(e.ToString()); } }
private void DrawConnectors(DiagramShapeControlBase parentShape, Graphics g, Pen pen, Brush brush, DiagramLayoutDirection direction, DiagramConnectorType connectorType) { if (parentShape.Expanded) { Point startPoint = new Point(); Point endPoint = new Point(); if (showExpanders) { startPoint.X = parentShape.expander.Left + parentShape.expander.Width / 2; startPoint.Y = parentShape.expander.Top + parentShape.expander.Height / 2; } else { if (direction == DiagramLayoutDirection.Vertical) { startPoint.X = parentShape.Left + parentShape.Width / 2; startPoint.Y = parentShape.Bottom; } else if (direction == DiagramLayoutDirection.Horizontal) { startPoint.Y = parentShape.Top + parentShape.Height / 2; startPoint.X = parentShape.Right; } } foreach (DiagramShapeControlBase shape in parentShape.childShapes) { if (direction == DiagramLayoutDirection.Vertical) { endPoint.Y = shape.Top; endPoint.X = shape.Left + (shape.Width / 2); } else if (direction == DiagramLayoutDirection.Horizontal) { endPoint.Y = shape.Top + (shape.Height / 2); endPoint.X = shape.Left; } switch (connectorType) { case DiagramConnectorType.Standard: g.DrawLine(pen, startPoint, endPoint); break; case DiagramConnectorType.Bezier: Point pt1 = Point.Empty; Point pt2 = Point.Empty; if (direction == DiagramLayoutDirection.Vertical) { pt1 = new Point(startPoint.X, startPoint.Y + 20); pt2 = new Point(endPoint.X, endPoint.Y - 20); } else if (direction == DiagramLayoutDirection.Horizontal) { pt1 = new Point(startPoint.X + 20, startPoint.Y); pt2 = new Point(endPoint.X - 20, endPoint.Y); } g.DrawBezier(pen, startPoint, pt1, pt2, endPoint); break; } // Draw arrows if (drawArrows) { Point anglePoint = new Point(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y); float angle = (float)(Math.Atan2(anglePoint.Y, anglePoint.X) * (180.0 / Math.PI)); if (connectorType == DiagramConnectorType.Bezier) { if (direction == DiagramLayoutDirection.Horizontal) angle *= 0.5f; else angle = 90.0f + (angle - 90.0f) * 0.5f; } g.TranslateTransform(endPoint.X, endPoint.Y); g.RotateTransform(angle); g.FillPath(brush, arrowPath); g.ResetTransform(); } DrawConnectors(shape, g, pen, brush, direction, connectorType); } } }
private void DrawOne(Graphics g, int xmin, int xmax, int ymin, int ymax) { var shape = Shape.Arc; var color = new Color(); var randomValue = RandomProvider.RandomGenerator.NextDouble(); foreach (var probabilitiesOfShape in ProbabilitiesOfShapes) { if (randomValue < probabilitiesOfShape.Probability) { shape = probabilitiesOfShape.Value; break; } } randomValue = RandomProvider.RandomGenerator.NextDouble(); foreach (var colorProbabilityPair in colorsCDFs) { if (randomValue < colorProbabilityPair.probability) { color = colorProbabilityPair.color; break; } } var pen = new Pen(color); var x1 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1); var y1 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1); var x2 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1); var y2 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1); var x3 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1); var y3 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1); var x4 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1); var y4 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1); var w1 = RandomProvider.RandomGenerator.Next(x1, xmax + 1); var h1 = RandomProvider.RandomGenerator.Next(y1, ymax + 1); var angle1 = RandomProvider.RandomGenerator.Next(0, 360); switch (shape) { case Shape.Arc: g.DrawArc(pen, x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360), RandomProvider.RandomGenerator.Next(0, 360)); break; case Shape.Bezier: g.DrawBezier(pen, x1, y1, x2, y2, x3, y3, x4, y4); break; case Shape.ClosedCurve: g.DrawClosedCurve(pen, new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.Curve: g.DrawCurve(pen, new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.Ellipse: g.DrawEllipse(pen, x1, y1, w1, h1); break; case Shape.Line: g.DrawLine(pen, x1, y1, x2, y2); break; case Shape.Lines: g.DrawLines(pen, new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.Pie: g.DrawPie(pen, x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360), RandomProvider.RandomGenerator.Next(0, 360)); break; case Shape.Polygon: g.DrawPolygon(pen, new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.Rectangle: g.DrawRectangle(pen, x1, y1, w1, h1); break; case Shape.String: g.DrawString(EnglishWordsDictionary.GetRandomWord(), new Font("Cambria", RandomProvider.RandomGenerator.Next(1, 50)), new SolidBrush(color), new PointF(x1, y1)); break; case Shape.FillClosedCurve: g.FillClosedCurve(new SolidBrush(color), new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.FillEllipse: g.FillEllipse(new SolidBrush(color), x1, y1, w1, h1); break; case Shape.FillPie: g.FillPie(new SolidBrush(color), x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360), RandomProvider.RandomGenerator.Next(0, 360)); break; case Shape.FillPolygon: g.FillPolygon(new SolidBrush(color), new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.FillRectangle: g.FillRectangle(new SolidBrush(color), x1, y1, w1, h1); break; default: throw new ArgumentOutOfRangeException(); } // g.Save(); }
/// <summary> /// This method draws a Bezier curve. /// </summary> /// <param name="graphics">It receives the Graphics instance</param> /// <param name="array">An array of (x,y) pairs of coordinates used to draw the curve.</param> public static void Bezier(System.Drawing.Graphics graphics, int[] array) { System.Drawing.Pen pen; pen = GraphicsManager.Manager.GetPen(graphics); graphics.DrawBezier(pen, array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7]); }
static public bool DrawGraphicsPath( System.Drawing.Graphics pGraphics, System.Drawing.Drawing2D.GraphicsPath pGraphicsPath, System.Drawing.Color clrPen, float fPenWidth) { if (pGraphics == null || pGraphicsPath == null) { return(false); } System.Drawing.Drawing2D.PathData pathData = pGraphicsPath.PathData; if (pathData.Points.Length <= 0) { return(false); } System.Drawing.Pen pen = new Pen(clrPen, fPenWidth); pen.LineJoin = LineJoin.Round; stBezier bezier = new stBezier(); stStart start = new stStart(); PointF prevPoint = new PointF(); for (int i = 0; i < pathData.Types.Length; ++i) { byte maskedByte = pathData.Types[i]; if (pathData.Types[i] == (byte)PathPointType.PathTypeMask) { maskedByte = (byte)(pathData.Types[i] & 0x3); } switch (maskedByte) { case PathPointType.Start: case PathPointType.Start | PathPointType.PathMarker: start.fPoint = pathData.Points[i]; start.nCount = 1; start.bDrawn = false; bezier.nCount = 0; break; case PathPointType.Line: case PathPointType.Line | PathPointType.PathMarker: pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]); break; case PathPointType.Line | PathPointType.CloseSubpath: case PathPointType.Line | PathPointType.PathMarker | PathPointType.CloseSubpath: pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]); pGraphics.DrawLine(pen, pathData.Points[i], start.fPoint); start.nCount = 0; break; case PathPointType.Bezier: case PathPointType.Bezier | PathPointType.PathMarker: bezier.fPoints[bezier.nCount] = pathData.Points[i]; bezier.nCount++; if (bezier.nCount == 1) { pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]); } if (bezier.nCount >= 4) { pGraphics.DrawBezier(pen, bezier.fPoints[0], bezier.fPoints[1], bezier.fPoints[2], bezier.fPoints[3]); bezier.nCount = 0; } break; case PathPointType.Bezier | PathPointType.CloseSubpath: case PathPointType.Bezier | PathPointType.PathMarker | PathPointType.CloseSubpath: bezier.fPoints[bezier.nCount] = pathData.Points[i]; bezier.nCount++; if (bezier.nCount == 1) { pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]); } if (bezier.nCount >= 4) { pGraphics.DrawBezier(pen, bezier.fPoints[0], bezier.fPoints[1], bezier.fPoints[2], bezier.fPoints[3]); bezier.nCount = 0; if (start.nCount == 1) { pGraphics.DrawLine(pen, pathData.Points[i], start.fPoint); start.nCount = 0; } } else if (start.nCount == 1) { pGraphics.DrawLine(pen, pathData.Points[i], start.fPoint); start.nCount = 0; start.bDrawn = true; } break; default: { //wchar_t buf[200]; //memset(buf,0, sizeof(buf)); //wsprintf(buf,_T("maskedByte: 0x%X\n"), maskedByte); //OutputDebugStringW(buf); } break; } prevPoint = pathData.Points[i]; } return(true); }
public static void DrawBezier(Graphics g, DiagramView view, System.Drawing.Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { if (pen != null) { g.DrawBezier(pen, x1, y1, x2, y2, x3, y3, x4, y4); } }
private void DrawBezier(Graphics graphics, Bezier bezier, Pen pen, Brush brush, bool control) { graphics.DrawBezier(pen, bezier.Point1.ToPointF(), bezier.Point2.ToPointF(), bezier.Point3.ToPointF(), bezier.Point4.ToPointF()); if (control) { graphics.DrawLine(pen, bezier.Point1.ToPointF(), bezier.Point2.ToPointF()); graphics.DrawLine(pen, bezier.Point4.ToPointF(), bezier.Point3.ToPointF()); DrawPoint(graphics, bezier.Point1.X, bezier.Point1.Y, brush); DrawPoint(graphics, bezier.Point2.X, bezier.Point2.Y, brush); DrawPoint(graphics, bezier.Point3.X, bezier.Point3.Y, brush); DrawPoint(graphics, bezier.Point4.X, bezier.Point4.Y, brush); } }
/// <summary> /// Paints the connection on the canvas /// The From part is always the child node while the To part is /// always the parent node. /// Hence; /// - vertical: Parent->Child <=> Top->Bottom /// - horizontal: Parent->Child <=> Left->Right /// </summary> /// <param name="g"></param> public override void Paint(System.Drawing.Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; PointF p1, p2, p3, p4; //intermediate points if (visible) { if (hovered || isSelected) { pen = redPen; } else { pen = currentPen; } switch (site.ConnectionType) { case ConnectionType.Default: switch (site.LayoutDirection) { case TreeDirection.Vertical: p1 = new PointF(from.Left + from.Width / 2, from.Top); p2 = new PointF(to.Left + to.Width / 2, to.Bottom + 5); g.DrawLine(pen, p1, p2); break; case TreeDirection.Horizontal: p1 = new PointF(from.Left, from.Top + from.Height / 2); p2 = new PointF(to.Right + 4, to.Top + to.Height / 2); g.DrawLine(pen, p1, p2); break; } break; case ConnectionType.Traditional: switch (site.LayoutDirection) { case TreeDirection.Vertical: p1 = new PointF(from.Left + from.Width / 2, from.Top - (from.Top - to.Bottom) / 2); p2 = new PointF(to.Left + to.Width / 2, from.Top - (from.Top - to.Bottom) / 2); g.DrawLine(pen, Start, p1); g.DrawLine(pen, p1, p2); g.DrawLine(pen, End, p2); break; case TreeDirection.Horizontal: p1 = new PointF(to.Right + (from.Left - to.Right) / 2, from.Top + from.Height / 2); p2 = new PointF(to.Right + (from.Left - to.Right) / 2, to.Top + to.Height / 2); g.DrawLine(pen, Start, p1); g.DrawLine(pen, p1, p2); g.DrawLine(pen, End, p2); break; } break; case ConnectionType.Bezier: switch (site.LayoutDirection) { case TreeDirection.Vertical: p1 = new PointF(from.Left + from.Width / 2, from.Top); p2 = new PointF(from.Left + from.Width / 2, from.Top - (from.Top - to.Bottom) / 2); p3 = new PointF(to.Left + to.Width / 2, from.Top - (from.Top - to.Bottom) / 2); p4 = new PointF(to.Left + to.Width / 2, to.Bottom); g.DrawBezier(pen, p1, p2, p3, p4); break; case TreeDirection.Horizontal: p1 = new PointF(to.Right, to.Top + to.Height / 2); p2 = new PointF(to.Right + (from.Left - to.Right) / 2, to.Top + to.Height / 2); p3 = new PointF(to.Right + (from.Left - to.Right) / 2, from.Top + from.Height / 2); p4 = new PointF(from.Left, from.Top + from.Height / 2); g.DrawBezier(pen, p1, p2, p3, p4); break; } break; } } }
private void DrawEdge(Edge e, Pen pen, Graphics graphics) { ICurve curve = e.Curve; Curve c = curve as Curve; if (c != null) { foreach (ICurve s in c.Segments) { LineSegment l = s as LineSegment; if (l != null) graphics.DrawLine(pen, MsaglPointToDrawingPoint(l.Start), MsaglPointToDrawingPoint(l.End)); CubicBezierSegment cs = s as CubicBezierSegment; if (cs != null) graphics.DrawBezier(pen, MsaglPointToDrawingPoint(cs.B(0)), MsaglPointToDrawingPoint(cs.B(1)), MsaglPointToDrawingPoint(cs.B(2)), MsaglPointToDrawingPoint(cs.B(3))); } if (e.ArrowheadAtSource) DrawArrow(e, pen, graphics, e.Curve.Start, e.EdgeGeometry.SourceArrowhead.TipPosition); if (e.ArrowheadAtTarget) DrawArrow(e, pen, graphics, e.Curve.End, e.EdgeGeometry.TargetArrowhead.TipPosition); } else { var l=curve as LineSegment; if (l != null) graphics.DrawLine(pen, MsaglPointToDrawingPoint(l.Start), MsaglPointToDrawingPoint(l.End)); } }
/// <summary> /// Zeichnet das LineSegment mit dem Stift pen auf die Zeichenfläche g /// </summary> /// <param name="g">Zeichenfläche auf die gemalt werden soll</param> /// <param name="pen">zu benutzender Stift</param> public void Draw(Graphics g, Pen pen) { g.DrawBezier(pen, _p0, _p1, _p2, _p3); }
private void DrawChildren(Graphics g, IList<INative> children) { foreach (var child in children) { if (child is IPin) { var pin = child as IPin; var color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00); Brush brush = new SolidBrush(color); double x = pin.Point.X - 4.0; double y = pin.Point.Y - 4.0; double width = 8.0; double height = 8.0; g.FillEllipse( brush, (float)x, (float)y, (float)width, (float)height); brush.Dispose(); } else if (child is ILine) { var line = child as ILine; Pen pen = new Pen( ToNativeColor(line.Stroke), (float)line.StrokeThickness); g.DrawLine( pen, (float)line.Point1.X, (float)line.Point1.Y, (float)line.Point2.X, (float)line.Point2.Y); pen.Dispose(); } else if (child is IBezier) { var bezier = child as IBezier; Pen pen = new Pen( ToNativeColor(bezier.Stroke), (float)bezier.StrokeThickness); g.DrawBezier( pen, (float)bezier.Start.X, (float)bezier.Start.Y, (float)bezier.Point1.X, (float)bezier.Point1.Y, (float)bezier.Point2.X, (float)bezier.Point2.Y, (float)bezier.Point3.X, (float)bezier.Point3.Y); pen.Dispose(); } else if (child is IQuadraticBezier) { var quadraticBezier = child as IQuadraticBezier; Pen pen = new Pen( ToNativeColor(quadraticBezier.Stroke), (float)quadraticBezier.StrokeThickness); double x1 = quadraticBezier.Start.X; double y1 = quadraticBezier.Start.Y; double x2 = quadraticBezier.Start.X + (2.0 * (quadraticBezier.Point1.X - quadraticBezier.Start.X)) / 3.0; double y2 = quadraticBezier.Start.Y + (2.0 * (quadraticBezier.Point1.Y - quadraticBezier.Start.Y)) / 3.0; double x3 = x2 + (quadraticBezier.Point2.X - quadraticBezier.Start.X) / 3.0; double y3 = y2 + (quadraticBezier.Point2.Y - quadraticBezier.Start.Y) / 3.0; double x4 = quadraticBezier.Point2.X; double y4 = quadraticBezier.Point2.Y; g.DrawBezier( pen, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); pen.Dispose(); } else if (child is IArc) { var arc = child as IArc; double x = Math.Min(arc.Point1.X, arc.Point2.X); double y = Math.Min(arc.Point1.Y, arc.Point2.Y); double width = Math.Abs(arc.Point2.X - arc.Point1.X); double height = Math.Abs(arc.Point2.Y - arc.Point1.Y); if (width > 0.0 && height > 0.0) { Pen pen = new Pen( ToNativeColor(arc.Stroke), (float)arc.StrokeThickness); g.DrawArc( pen, (float)x, (float)y, (float)width, (float)height, (float)arc.StartAngle, (float)arc.SweepAngle); pen.Dispose(); } } else if (child is IRectangle) { var rectangle = child as IRectangle; Pen pen = new Pen( ToNativeColor(rectangle.Stroke), (float)rectangle.StrokeThickness); double x = Math.Min(rectangle.Point1.X, rectangle.Point2.X); double y = Math.Min(rectangle.Point1.Y, rectangle.Point2.Y); double width = Math.Abs(rectangle.Point2.X - rectangle.Point1.X); double height = Math.Abs(rectangle.Point2.Y - rectangle.Point1.Y); g.DrawRectangle( pen, (float)x, (float)y, (float)width, (float)height); pen.Dispose(); } else if (child is IEllipse) { var ellipse = child as IEllipse; Pen pen = new Pen( ToNativeColor(ellipse.Stroke), (float)ellipse.StrokeThickness); double x = Math.Min(ellipse.Point1.X, ellipse.Point2.X); double y = Math.Min(ellipse.Point1.Y, ellipse.Point2.Y); double width = Math.Abs(ellipse.Point2.X - ellipse.Point1.X); double height = Math.Abs(ellipse.Point2.Y - ellipse.Point1.Y); g.DrawEllipse( pen, (float)x, (float)y, (float)width, (float)height); pen.Dispose(); } else if (child is IText) { var text = child as IText; Brush brush = new SolidBrush(ToNativeColor(text.Foreground)); Font font = new Font("Calibri", (float)(text.Size * 72 / 96)); double x = Math.Min(text.Point1.X, text.Point2.X); double y = Math.Min(text.Point1.Y, text.Point2.Y); double width = Math.Abs(text.Point2.X - text.Point1.X); double height = Math.Abs(text.Point2.Y - text.Point1.Y); g.DrawString( text.Text, font, brush, new RectangleF( (float)x, (float)y, (float)width, (float)height), new StringFormat() { Alignment = (StringAlignment)text.HorizontalAlignment, LineAlignment = (StringAlignment)text.VerticalAlignment }); brush.Dispose(); font.Dispose(); } else if (child is IBlock) { var block = child as IBlock; DrawChildren(g, block.Children); } } }
/** Draw a flat symbol. * @param ynote The pixel location of the top of the accidental's note. */ public void DrawFlat(Graphics g, Pen pen, int ynote) { int x = SheetMusic.LineSpace/4; /* Draw the vertical line */ pen.Width = 1; g.DrawLine(pen, x, ynote - SheetMusic.NoteHeight - SheetMusic.NoteHeight/2, x, ynote + SheetMusic.NoteHeight); /* Draw 3 bezier curves. * All 3 curves start and stop at the same points. * Each subsequent curve bulges more and more towards * the topright corner, making the curve look thicker * towards the top-right. */ g.DrawBezier(pen, x, ynote + SheetMusic.LineSpace/4, x + SheetMusic.LineSpace/2, ynote - SheetMusic.LineSpace/2, x + SheetMusic.LineSpace, ynote + SheetMusic.LineSpace/3, x, ynote + SheetMusic.LineSpace + SheetMusic.LineWidth + 1); g.DrawBezier(pen, x, ynote + SheetMusic.LineSpace/4, x + SheetMusic.LineSpace/2, ynote - SheetMusic.LineSpace/2, x + SheetMusic.LineSpace + SheetMusic.LineSpace/4, ynote + SheetMusic.LineSpace/3 - SheetMusic.LineSpace/4, x, ynote + SheetMusic.LineSpace + SheetMusic.LineWidth + 1); g.DrawBezier(pen, x, ynote + SheetMusic.LineSpace/4, x + SheetMusic.LineSpace/2, ynote - SheetMusic.LineSpace/2, x + SheetMusic.LineSpace + SheetMusic.LineSpace/2, ynote + SheetMusic.LineSpace/3 - SheetMusic.LineSpace/2, x, ynote + SheetMusic.LineSpace + SheetMusic.LineWidth + 1); }
private Graph.LaneInfo DrawPenLoop(Graphics wa, int top, int lane, int mid, Graph.LaneInfo laneInfo, Brush brushLineColor, bool drawBorder) { for (int i = drawBorder ? 0 : 2; i < 3; i++) { Pen penLine; if (i == 0) { penLine = new Pen(new SolidBrush(Color.White), LANE_LINE_WIDTH + 2); } else if (i == 1) { penLine = new Pen(new SolidBrush(Color.Black), LANE_LINE_WIDTH + 1); } else { penLine = new Pen(brushLineColor, LANE_LINE_WIDTH); } if (laneInfo.ConnectLane == lane) { wa.DrawLine ( penLine, new Point(mid, top - 1), new Point(mid, top + rowHeight + 2) ); } else { wa.DrawBezier ( penLine, new Point(mid, top - 1), new Point(mid, top + rowHeight + 2), new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top - 1), new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top + rowHeight + 2) ); } } return laneInfo; }
public void DrawPath(Graphics g) { //if (mBaseMovement != null) // mBaseMovement.DrawPath(g); if (mBaseMovement != null) mBaseMovement.DrawPath(g); PointF anchor = GetAnchorPoint(); try { Matrix mx = new Matrix(); mx.RotateAt(-mMoveRotation, new PointF(anchor.X, anchor.Y)); g.Transform = mx; Pen pen = new Pen(Color.White); pen.DashPattern = new float[] { 6.0f, 8.0f }; pen.DashStyle = DashStyle.Custom; switch (mType) { case MovementType.VerticalCycle: g.DrawLine(pen, anchor.X, anchor.Y - GetYRadius(), anchor.X, anchor.Y + GetYRadius()); break; case MovementType.HorizontalCycle: g.DrawLine(pen, anchor.X - GetXRadius(), anchor.Y, anchor.X + GetXRadius(), anchor.Y); break; case MovementType.Circle: case MovementType.RotateAroundCircle: g.DrawEllipse(pen, anchor.X - GetXRadius(), anchor.Y - GetYRadius(), GetXRadius() * 2, GetYRadius() * 2); break; case MovementType.HorizontalInfinity: g.DrawBezier(pen, anchor.X, anchor.Y, anchor.X - (GetXRadius() * 1.35f), anchor.Y - (GetYRadius() * 1.8f), anchor.X - (GetXRadius() * 1.35f), anchor.Y + (GetYRadius() * 1.8f), anchor.X, anchor.Y); g.DrawBezier(pen, anchor.X, anchor.Y, anchor.X + (GetXRadius() * 1.35f), anchor.Y - (GetYRadius() * 1.8f), anchor.X + (GetXRadius() * 1.35f), anchor.Y + (GetYRadius() * 1.8f), anchor.X, anchor.Y); break; case MovementType.VericalInfinity: g.DrawBezier(pen, anchor.X, anchor.Y, anchor.X - GetXRadius(), anchor.Y - GetYRadius(), anchor.X + GetXRadius(), anchor.Y - GetYRadius(), anchor.X, anchor.Y); g.DrawBezier(pen, anchor.X, anchor.Y, anchor.X - GetXRadius(), anchor.Y + GetYRadius(), anchor.X + GetXRadius(), anchor.Y + GetYRadius(), anchor.X, anchor.Y); break; case MovementType.VerticalArc: g.DrawArc(pen, anchor.X - GetXRadius(), anchor.Y - GetYRadius(), GetXRadius() * 2, GetYRadius() * 2, -90.0f, 180.0f); break; case MovementType.HorizontalArc: g.DrawArc(pen, anchor.X - GetXRadius(), anchor.Y - GetYRadius(), GetXRadius() * 2, GetYRadius() * 2, 180.0f, 180.0f); break; case MovementType.HorizontalWrap: if (mReverse) { g.DrawLine(pen, anchor.X, anchor.Y, anchor.X - GetXRadius(), anchor.Y); } else { g.DrawLine(pen, anchor.X, anchor.Y, anchor.X + GetXRadius(), anchor.Y); } break; case MovementType.VerticalWrap: if (mReverse) { g.DrawLine(pen, anchor.X, anchor.Y, anchor.X, anchor.Y + GetYRadius()); } else { g.DrawLine(pen, anchor.X, anchor.Y, anchor.X, anchor.Y - GetYRadius()); } break; } } catch { } finally { g.Transform = new Matrix(); } }
private void dibujarVehiculo(Graphics grafico, Vehiculo vehiculo) { //El punto es el centro del vehiculo int xInicio = (int)vehiculo.X; int yInicio = (int)vehiculo.Y; int largo = vehiculo.Largo; int ancho = 12; //Coordenada del inicio del dibujo int x = xInicio-(ancho/2); int y = yInicio-largo; Random a = new Random (vehiculo.Id); Color colorVehiculo = Color.White; if (vehiculo.Tipo == Vehiculo.AUTOPERSONAL) { colorVehiculo = Color.FromArgb(a.Next(20, 105),a.Next(30, 160),125); } else if (vehiculo.Tipo == Vehiculo.CAMION) { colorVehiculo = Color.FromArgb(a.Next(0, 120),a.Next(0, 50),0); } else if (vehiculo.Tipo == Vehiculo.TRASPORTEPUBLICO) { colorVehiculo = Color.FromArgb(a.Next(230, 255),a.Next(50, 200),0); } if(Modificar.eliminarVehiculos && Modificar.estaSobre(vehiculo)) { colorVehiculo = Configuracion.COLORRESALTAR; } Color interDerecho = Color.Gray; Color interIzquierdo = Color.Gray; Color freno = Color.Gray; if (vehiculo.Intermitente == Vehiculo.INTERMITENTE_DERECHA) interDerecho = Color.Yellow; else if (vehiculo.Intermitente == Vehiculo.INTERMITENTE_IZQUIERDA) interIzquierdo = Color.Yellow; if (vehiculo.LuzFreno) freno = Color.Red; if (Configuracion.mostrarBezier) { Bezier b = vehiculo.Conductor.Bezier; if (b != null) grafico.DrawBezier (new Pen (colorVehiculo), b.X1, b.Y1, b.X2, b.Y2, b.X3, b.Y3, b.X4, b.Y4); } //Rota el vehiculo con el angulo de giro Matrix m = new Matrix (); m.Translate (Configuracion.origenX,Configuracion.origenY); m.Scale (Configuracion.tamañoMapa,Configuracion.tamañoMapa); m.RotateAt ((int)vehiculo.Angulo, new PointF (xInicio, yInicio)); grafico.Transform = m; grafico.FillRectangle (new SolidBrush (colorVehiculo), x, y, ancho, largo); grafico.FillRectangle (new SolidBrush (interIzquierdo), x, y+largo-2, 2, 2); grafico.FillRectangle (new SolidBrush (freno), x+4, y+largo-2, 4, 2); grafico.FillRectangle (new SolidBrush (interDerecho), x+10, y+largo-2, 2, 2); //grafico.FillRectangle (new SolidBrush (Color.Green), x+ancho/2, y+largo, 4, 4); //grafico.FillRectangle (new SolidBrush (Color.YellowGreen), x+ancho/2-4, y+largo, 4, 4); if (Configuracion.mostrarRadioPercepcion) { grafico.DrawEllipse (new Pen (colorVehiculo), xInicio - Configuracion.radioPercepcionVehiculo, yInicio-(largo/2) - Configuracion.radioPercepcionVehiculo, Configuracion.radioPercepcionVehiculo * 2, Configuracion.radioPercepcionVehiculo * 2); grafico.DrawEllipse (new Pen (colorVehiculo), xInicio - Configuracion.radioPercepcionSeñaletica, yInicio-(largo/2) - Configuracion.radioPercepcionSeñaletica, Configuracion.radioPercepcionSeñaletica * 2, Configuracion.radioPercepcionSeñaletica * 2); } this.dibujarID (grafico, vehiculo.Id, Elemento.VERTICAL, x+3, y); grafico.ResetTransform (); //Se reestablecen los ajustes del mapa grafico.TranslateTransform (Configuracion.origenX,Configuracion.origenY); grafico.ScaleTransform (Configuracion.tamañoMapa,Configuracion.tamañoMapa); }
public override void DrawToGraphics(Graphics graphics) { Pen pen = Pens.Black; switch (this.CurrentState) { case ItemState.Free: pen = new Pen(ColorDefinition.GetColorWhenFree()); break; case ItemState.Hover: pen = new Pen(ColorDefinition.GetColorWhenHover()); break; case ItemState.Selected: pen = new Pen(ColorDefinition.GetColorWhenSelected()); break; default: break; } // switch List<PointF> tempNails = new List<PointF>(); tempNails.Add(this.GetStartingPoint()); foreach (NailItem nail in this.Nails) tempNails.Add(nail.Center()); tempNails.Add(this.GetEndPoint()); float R = NailItem.R; if (this.CurrentState == ItemState.Free) R = NailItem.R + 5; PointF[] points = new PointF[3]; PointF firstNail = PointF.Empty; firstNail = tempNails[0]; for (int i = 0; i < tempNails.Count - 1; i++) { points[1] = tempNails[i + 1]; points[0] = GraphUltility.FindPointByDistance(points[1], firstNail, R); graphics.DrawLine(pen, firstNail, points[0]); if (i + 2 < tempNails.Count) { points[2] = GraphUltility.FindPointByDistance(points[1], tempNails[i + 2], R); firstNail = points[2]; //Make the intersection curved if (this.CurrentState == ItemState.Free) graphics.DrawBezier(pen, points[0], points[1], points[1], points[2]); } } DrawRouteWithBigArrow(graphics, pen, firstNail, tempNails[tempNails.Count - 1]); Label.Value = _weight; Label.CurrentState = this.CurrentState; Label.DrawToGraphics(graphics); }
public void Render(System.Drawing.Graphics g, WorldTransform t) { if (rndf != null && DrawingUtility.DrawRndf) { foreach (Segment segment in rndf.Segments.Values) { foreach (Way way in segment.Ways.Values) { foreach (Lane lane in way.Lanes.Values) { foreach (LanePartition lanePartition in lane.LanePartitions) { // Draw Line representing the Lane Partition w/ added WayColor if it is wanted if (DrawingUtility.DrawLanePartitions) { if (way.WayID.WayNumber == 1) { DrawingUtility.DrawControlLine(lanePartition.InitialWaypoint.Position, lanePartition.FinalWaypoint.Position, DrawingUtility.LanePartitionWay1Color, g, t); } else { DrawingUtility.DrawControlLine(lanePartition.InitialWaypoint.Position, lanePartition.FinalWaypoint.Position, DrawingUtility.LanePartitionWay2Color, g, t); } } foreach (UserPartition userPartition in lanePartition.UserPartitions) { // Draw Line representing the User Partition w/ added WayColor if it is wanted if (DrawingUtility.DrawUserPartitions) { if (way.WayID.WayNumber == 1) { DrawingUtility.DrawControlLine(userPartition.InitialWaypoint.Position, userPartition.FinalWaypoint.Position, DrawingUtility.UserPartitionWay1Color, g, t); } else { DrawingUtility.DrawControlLine(userPartition.InitialWaypoint.Position, userPartition.FinalWaypoint.Position, DrawingUtility.UserPartitionWay2Color, g, t); } } // Draw Final User Waypoints if User Waypoints and if wanted if (DrawingUtility.DrawUserWaypoints) { if (userPartition.FinalWaypoint is UserWaypoint) { Color c = DrawingUtility.GetWaypointColor(userPartition.FinalWaypoint); if (DrawingUtility.DrawUserWaypointText) { DrawingUtility.DrawControlPoint(userPartition.FinalWaypoint.Position, c, userPartition.FinalWaypoint.ToString(), ContentAlignment.MiddleCenter, ControlPointStyle.SmallCircle, g, t); } else { DrawingUtility.DrawControlPoint(userPartition.FinalWaypoint.Position, c, null, ContentAlignment.BottomCenter, ControlPointStyle.SmallCircle, g, t); } } } } } // draw splines if (DrawingUtility.DisplayLaneSplines) { List <Coordinates> waypointLocations = new List <Coordinates>(); foreach (RndfWayPoint waypoint in lane.Waypoints.Values) { waypointLocations.Add(waypoint.Position); } // get spline List <CubicBezier> c2Spline = RndfTools.SplineC2FromPoints(waypointLocations); float nomPixelWidth = 2.0f; float penWidth = nomPixelWidth / t.Scale; Pen pen = new Pen(Color.FromArgb(100, Color.DarkSeaGreen), penWidth); foreach (CubicBezier cb in c2Spline) { g.DrawBezier(pen, DrawingUtility.ToPointF(cb.P0), DrawingUtility.ToPointF(cb.P1), DrawingUtility.ToPointF(cb.P2), DrawingUtility.ToPointF(cb.P3)); } } if (DrawingUtility.DrawRndfWaypoints) { foreach (RndfWayPoint rndfWayPoint in lane.Waypoints.Values) { if (DrawingUtility.DrawRndfWaypointText) { DrawingUtility.DrawControlPoint(rndfWayPoint.Position, DrawingUtility.GetWaypointColor(rndfWayPoint), rndfWayPoint.WaypointID.ToString(), ContentAlignment.BottomCenter, ControlPointStyle.SmallCircle, g, t); } else { DrawingUtility.DrawControlPoint(rndfWayPoint.Position, DrawingUtility.GetWaypointColor(rndfWayPoint), null, ContentAlignment.BottomCenter, ControlPointStyle.SmallCircle, g, t); } if (DrawingUtility.DisplayRndfGoals && rndfWayPoint.IsCheckpoint) { DrawingUtility.DrawControlPoint(rndfWayPoint.Position, DrawingUtility.GetWaypointColor(rndfWayPoint), rndfWayPoint.CheckpointNumber.ToString(), ContentAlignment.TopCenter, ControlPointStyle.SmallCircle, g, t); } } } } } } if (DrawingUtility.DrawInterconnects) { foreach (Interconnect interconnect in rndf.Interconnects.Values) { DrawingUtility.DrawControlLine(interconnect.InitialWaypoint.Position, interconnect.FinalWaypoint.Position, DrawingUtility.InterconnectColor, g, t); } } if (DrawingUtility.DisplayIntersectionSplines) { foreach (Interconnect interconnect in rndf.Interconnects.Values) { try { Coordinates d0 = interconnect.InitialWaypoint.Position - interconnect.InitialWaypoint.PreviousLanePartition.InitialWaypoint.Position; Coordinates p0 = interconnect.InitialWaypoint.Position; Coordinates dn = interconnect.FinalWaypoint.NextLanePartition.FinalWaypoint.Position - interconnect.FinalWaypoint.Position; Coordinates pn = interconnect.FinalWaypoint.Position; List <Coordinates> coords = new List <Coordinates>(); coords.Add(p0); if (interconnect.UserPartitions != null) { for (int i = 1; i < interconnect.UserPartitions.Count; i++) { coords.Add(interconnect.UserPartitions[i].InitialWaypoint.Position); } } coords.Add(pn); List <CubicBezier> c2Spline = RndfTools.SplineC2FromSegmentAndDerivatives(coords, d0, dn); float nomPixelWidth = 2.0f; float penWidth = nomPixelWidth / t.Scale; Pen pen = new Pen(Color.FromArgb(100, Color.DarkSeaGreen), penWidth); foreach (CubicBezier cb in c2Spline) { g.DrawBezier(pen, DrawingUtility.ToPointF(cb.P0), DrawingUtility.ToPointF(cb.P1), DrawingUtility.ToPointF(cb.P2), DrawingUtility.ToPointF(cb.P3)); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } if (DrawingUtility.DisplayIntersectionBounds && rndf.intersections != null) { foreach (Intersection intersection in rndf.intersections.Values) { if (intersection.Perimeter != null) { foreach (BoundaryLine boundary in intersection.Perimeter) { DrawingUtility.DrawColoredControlLine(DrawingUtility.IntersectionAreaColor, boundary.p1, boundary.p2, g, t); } } } } } }
/// <summary> /// Draws the edges connecting the nodes. /// </summary> /// <param name="graphics">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> /// <param name="edgePen">The pen used for normal connectors.</param> /// <param name="edgePenReadOnly">The pen used for read-only connectors.</param> public virtual void DrawEdges(Graphics graphics, NodeViewData nvd, Pen edgePen, Pen edgePenReadOnly) { RectangleF boundingBox= nvd.BoundingBox; // calculate an offset so we cannot see the end or beginning of the rendered edge float edgePenHalfWidth= edgePen.Width *0.5f; foreach(NodeViewData node in nvd.Children) { RectangleF nodeBoundingBox= node.BoundingBox; // calculate the centre between both nodes and of the edge float middle= boundingBox.Right + (nodeBoundingBox.Left - boundingBox.Right) *0.5f; // end at the middle of the other node float nodeHeight= nodeBoundingBox.Top + nodeBoundingBox.Height *0.5f; // find the correct connector for this node for(int i= 0; i <_subItems.Count; ++i) { SubItemConnector conn= _subItems[i] as SubItemConnector; if(conn !=null && conn.Child ==node.Node) { // get the bounding box of the event RectangleF subitemBoundingBox= GetSubItemBoundingBox(boundingBox, i); // start at the middle of the connector float connectorHeight= subitemBoundingBox.Top + subitemBoundingBox.Height *0.5f; graphics.DrawBezier(conn.Connector.IsReadOnly ? edgePenReadOnly : edgePen, boundingBox.Right - edgePenHalfWidth, connectorHeight, middle, connectorHeight, middle, nodeHeight, nodeBoundingBox.Left + edgePenHalfWidth, nodeHeight); break; } } } }
private bool DrawItem(Graphics wa, Graph.ILaneRow row) { if (row == null || row.NodeLane == -1) { return false; } // Clip to the area we're drawing in, but draw 1 pixel past so // that the top/bottom of the line segment's anti-aliasing isn't // visible in the final rendering. int top = wa.RenderingOrigin.Y + _rowHeight / 2; var laneRect = new Rectangle(0, top, (int)wa.ClipBounds.Width, _rowHeight); Region oldClip = wa.Clip; var newClip = new Region(laneRect); newClip.Intersect(oldClip); wa.Clip = newClip; // wa.Clear(Color.Transparent); //Getting RevisionGraphDrawStyle results in call to AppSettings. This is not very cheap, cache. revisionGraphDrawStyleCache = RevisionGraphDrawStyle; //for (int r = 0; r < 2; r++) for (int lane = 0; lane < row.Count; lane++) { int mid = wa.RenderingOrigin.X + (int)((lane + 0.5) * _laneWidth); for (int item = 0; item < row.LaneInfoCount(lane); item++) { if (item > 2) { } Graph.LaneInfo laneInfo = row[lane, item]; bool highLight = (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && laneInfo.Junctions.Any(j => j.IsRelative)) || (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.HighlightSelected && laneInfo.Junctions.Any(j => j.HighLight)) || (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.Normal); List<Color> curColors = GetJunctionColors(laneInfo.Junctions); // Create the brush for drawing the line Brush brushLineColor = null; Pen brushLineColorPen = null; try { bool drawBorder = highLight && AppSettings.BranchBorders; //hide border for "non-relatives" if (curColors.Count == 1 || !AppSettings.StripedBranchChange) { if (curColors[0] != _nonRelativeColor) { brushLineColor = new SolidBrush(curColors[0]); } else if (curColors.Count > 1 && curColors[1] != _nonRelativeColor) { brushLineColor = new SolidBrush(curColors[1]); } else { drawBorder = false; brushLineColor = new SolidBrush(_nonRelativeColor); } } else { Color lastRealColor = curColors.LastOrDefault(c => c != _nonRelativeColor); if (lastRealColor.IsEmpty) { brushLineColor = new SolidBrush(_nonRelativeColor); drawBorder = false; } else { brushLineColor = new HatchBrush(HatchStyle.DarkDownwardDiagonal, curColors[0], lastRealColor); } } // Precalculate line endpoints bool singleLane = laneInfo.ConnectLane == lane; int x0 = mid; int y0 = top - 1; int x1 = singleLane ? x0 : mid + (laneInfo.ConnectLane - lane) * _laneWidth; int y1 = top + _rowHeight; Point p0 = new Point(x0, y0); Point p1 = new Point(x1, y1); // Precalculate curve control points when needed Point c0, c1; if (singleLane) { c0 = c1 = Point.Empty; } else { // Controls the curvature of cross-lane lines (0 = straight line, 1 = 90 degree turns) const float severity = 0.5f; c0 = new Point(x0, (int)(y0 * (1.0f - severity) + y1 * severity)); c1 = new Point(x1, (int)(y1 * (1.0f - severity) + y0 * severity)); } for (int i = drawBorder ? 0 : 2; i < 3; i++) { Pen penLine = null; if (i == 0) { penLine = _whiteBorderPen; } else if (i == 1) { penLine = _blackBorderPen; } else { if (brushLineColorPen == null) brushLineColorPen = new Pen(brushLineColor, _laneLineWidth); penLine = brushLineColorPen; } if (laneInfo.ConnectLane == lane) { wa.DrawLine ( penLine, new Point(mid, top - 1), new Point(mid, top + _rowHeight + 2) ); } else { wa.DrawBezier ( penLine, new Point(mid, top - 1), new Point(mid, top + _rowHeight + 2), new Point(mid + (laneInfo.ConnectLane - lane) * _laneWidth, top - 1), new Point(mid + (laneInfo.ConnectLane - lane) * _laneWidth, top + _rowHeight + 2) ); } } } finally { if (brushLineColorPen != null) ((IDisposable)brushLineColorPen).Dispose(); if (brushLineColor != null) ((IDisposable)brushLineColor).Dispose(); } } } // Reset the clip region wa.Clip = oldClip; { // Draw node var nodeRect = new Rectangle ( wa.RenderingOrigin.X + (_laneWidth - _nodeDimension) / 2 + row.NodeLane * _laneWidth, wa.RenderingOrigin.Y + (_rowHeight - _nodeDimension) / 2, _nodeDimension, _nodeDimension ); Brush nodeBrush; List<Color> nodeColors = GetJunctionColors(row.Node.Ancestors); bool highlight = (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && row.Node.Ancestors.Any(j => j.IsRelative)) || (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.HighlightSelected && row.Node.Ancestors.Any(j => j.HighLight)) || (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.Normal); bool drawBorder = AppSettings.BranchBorders && highlight; if (nodeColors.Count == 1) { nodeBrush = new SolidBrush(highlight ? nodeColors[0] : _nonRelativeColor); if (nodeColors[0] == _nonRelativeColor) drawBorder = false; } else { nodeBrush = new LinearGradientBrush(nodeRect, nodeColors[0], nodeColors[1], LinearGradientMode.Horizontal); if (nodeColors.All(c => c == _nonRelativeColor)) drawBorder = false; } if (_filterMode == FilterType.Highlight && row.Node.IsFiltered) { Rectangle highlightRect = nodeRect; highlightRect.Inflate(2, 3); wa.FillRectangle(Brushes.Yellow, highlightRect); wa.DrawRectangle(Pens.Black, highlightRect); } if (row.Node.Data == null) { wa.FillEllipse(Brushes.White, nodeRect); using (var pen = new Pen(Color.Red, 2)) { wa.DrawEllipse(pen, nodeRect); } } else if (row.Node.IsActive) { wa.FillRectangle(nodeBrush, nodeRect); nodeRect.Inflate(1, 1); using (var pen = new Pen(Color.Black, 3)) wa.DrawRectangle(pen, nodeRect); } else if (row.Node.IsSpecial) { wa.FillRectangle(nodeBrush, nodeRect); if (drawBorder) { wa.DrawRectangle(Pens.Black, nodeRect); } } else { wa.FillEllipse(nodeBrush, nodeRect); if (drawBorder) { wa.DrawEllipse(Pens.Black, nodeRect); } } } return true; }
private void Render(Graphics g) { Size csize = this.ClientSize; int w = (int)csize.Width; int h = (int)csize.Height; frmclk.Start(); // start frame timer. switch (m_sampleDrawing) { case SampleDrawings.FillSolidRects: { for (int i = 0; i < m_rects.Count; i++) { m_brush1.Color = m_colors[i]; g.FillRectangle(m_brush1, m_rects[i]); } } break; case SampleDrawings.Draw_Rects: { Pen p = new Pen(Color.Red); for (int i = 0; i < m_rects.Count; i++) { p.Color = m_colors[i]; g.DrawRectangle(p, m_rects[i]); } p.Dispose(); } break; case SampleDrawings.DrawRandomLines1: { Pen p = new Pen(Color.Red); for (int i = 0; i < m_lines.Count; i++) { p.Color = m_colors[i]; Line line = m_lines[i]; g.DrawLine(p, line.P1, line.P2); } p.Dispose(); } break; case SampleDrawings.DrawRandomLines2: { Pen p = new Pen(Color.Red, 2.0f); for (int i = 0; i < m_lines.Count; i++) { p.Color = m_colors[i]; Line line = m_lines[i]; g.DrawLine(p, line.P1, line.P2); } p.Dispose(); } break; case SampleDrawings.DrawBeziers: { int c = 0; Pen p = new Pen(Color.White, 2.0f); //Pen p = new Pen(Color.White); foreach (Bezier bz in m_beziers) { p.Color = m_colors[c++]; g.DrawBezier(p, bz.P1, bz.P2, bz.P3, bz.P4); } p.Dispose(); } break; case SampleDrawings.DrawText: { RectangleF layoutrect = new RectangleF(); layoutrect.Size = g.MeasureString(m_drawInfo, m_info); for (int i = 0; i < m_texts.Count; i++) { m_brush1.Color = m_colors[i]; layoutrect.Location = m_texts[i]; g.DrawString(m_drawInfo , m_info, m_brush1, layoutrect, m_strFormat); } } break; case SampleDrawings.DrawBitmaps: { Random rnd = new Random(7533); RectangleF bmpRect = new RectangleF(); bmpRect.Size = m_bmp.Size; for (int i = 0; i < 20; i++) { bmpRect.Location = new PointF(rnd.Next(w), rnd.Next(h)); g.DrawImage(m_bmp, bmpRect); } } break; default: break; } m_frameCount++; m_cumulativeTime += (float)frmclk.Elapsed; // compute fps and tpf every 10 frames. if (m_frameCount > 10) { m_fps = m_frameCount / m_cumulativeTime; m_cumulativeTime = 0; m_frameCount = 0; UpdateInfo(); } }
public virtual void DrawConnections(Graphics g, Color outlineColor, NodePort selectedPort) { if (g == null) { throw new ArgumentNullException("g"); } for (Int32 i = 0; i < InputsLength; i++) { if (GetInput(i).Connection != null) { Color color = Color.Black; if (Object.ReferenceEquals(GetInput(i), selectedPort)) { color = outlineColor; } NodeBase currentNode = GetInput(i).Connection.Node; Int32 connectionIndex = 0; for (Int32 j = 0; j < currentNode.OutputsLength; j++) { if (Object.ReferenceEquals(currentNode.GetOutput(j), GetInput(i).Connection)) { connectionIndex = j; break; } } /* Calculate extreme points. */ Point output = new Point( currentNode.BodyRectangle.X + currentNode.BodyRectangle.Width , currentNode.BodyRectangle.Y + connectionIndex * currentNode.HeaderRectangle.Height + currentNode.HeaderRectangle.Height / 2 + 1 ); Point input = new Point( BodyRectangle.X , BodyRectangle.Y + i * HeaderRectangle.Height + HeaderRectangle.Height / 2 + 1 ); /* Draw connection shadow and the connection itself. */ g.DrawBezier( _connectionPen , input , new Point(input.X - 26, input.Y + 4) , new Point(output.X + 34, output.Y + 4) , output ); using (SolidBrush sb = new SolidBrush(color)) using (Pen pen = new Pen(sb, 2f)) { g.DrawBezier(pen, input, new Point(input.X - 30, input.Y), new Point(output.X + 30, output.Y), output); g.FillPolygon(sb, new Point[] { new Point(input.X - 5, input.Y - 5), input, new Point(input.X - 5, input.Y + 5) }); } } } }
private void DrawSelectedString(Graphics g) { // highlight the selected cells g.DrawImage(texSelected, new Point(0,0)); // draw the wiring if (cellPoints.Length > 1) { g.DrawLines(new Pen(Color.FromArgb(80, Color.Black), 3.0f), cellPoints); g.DrawLines(new Pen(Color.LightYellow, 1.0f), cellPoints); } // draw the bypass diode arcs int ndiodes = CellString.BypassDiodes.Count; for (int i = 0; i < ndiodes; i++) { ArraySpec.BypassDiode diode = CellString.BypassDiodes[i]; PointF pA = junctionPoints[diode.CellIxs.First]; PointF pB = junctionPoints[diode.CellIxs.Second + 1]; float perpX = (pB.Y - pA.Y) * 0.2f; float perpY = (pA.X - pB.X) * 0.2f; PointF pMidA = new PointF( pA.X * 0.7f + pB.X * 0.3f + perpX, pA.Y * 0.7f + pB.Y * 0.3f + perpY); PointF pMidB = new PointF( pA.X * 0.3f + pB.X * 0.7f + perpX, pA.Y * 0.3f + pB.Y * 0.7f + perpY); g.DrawBezier(new Pen(Color.FromArgb(200, Color.Black), 5f), pA, pMidA, pMidB, pB); g.DrawBezier(new Pen(Color.Red, 3f), pA, pMidA, pMidB, pB); } // draw the bypass diode endpoints foreach(int i in bypassJunctions){ DrawJunction(g, junctionPoints[i], Brushes.Red); } }
public void Draw(Graphics g) { if (Start.IsEmpty == false) { g.FillRectangle(Brushes.Blue, Start.X - 4, Start.Y - 4, 8, 8); } if (End.IsEmpty == false) { g.FillRectangle(Brushes.Blue, End.X - 4, End.Y - 4, 8, 8); } if (CP1.IsEmpty == false) { g.FillEllipse(Brushes.Orange, CP1.X - 4, CP1.Y - 4, 8, 8); } if (CP2.IsEmpty == false) { g.FillEllipse(Brushes.Orange, CP2.X - 4, CP2.Y - 4, 8, 8); } using (Pen dashed = new Pen(Brushes.Violet, 1.5f)) { dashed.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; if (Start.IsEmpty == false && CP1.IsEmpty == false) { g.DrawLine(dashed, Start, CP1); } if (CP1.IsEmpty == false && CP2.IsEmpty == false) { g.DrawLine(dashed, CP1, CP2); } if (CP2.IsEmpty == false && End.IsEmpty == false) { g.DrawLine(dashed, CP2, End); } } if (Start.IsEmpty == false && CP1.IsEmpty == false && CP2.IsEmpty == false && End.IsEmpty == false) { g.DrawBezier(Pens.Magenta, Start, CP1, CP2, End); } if (_pointSelected.IsEmpty == false) { using (Pen pen = new Pen(Color.Violet, 3f)) { if (IsStartSelected(_pointSelected, _curveSelected) == true) { g.DrawRectangle(pen, _curveSelected.Start.X - 8, _curveSelected.Start.Y - 8, 16, 16); } if (IsCP1Selected(_pointSelected, _curveSelected) == true) { g.DrawEllipse(pen, _curveSelected.CP1.X - 8, _curveSelected.CP1.Y - 8, 16, 16); } if (IsCP2Selected(_pointSelected, _curveSelected) == true) { g.DrawEllipse(pen, _curveSelected.CP2.X - 8, _curveSelected.CP2.Y - 8, 16, 16); } if (IsEndSelected(_pointSelected, _curveSelected) == true) { g.DrawRectangle(pen, _curveSelected.End.X - 8, _curveSelected.End.Y - 8, 16, 16); } } } }
// end drawGraph private bool DrawItem(Graphics wa, Graph.ILaneRow row) { if (row == null || row.NodeLane == -1) { return false; } // Clip to the area we're drawing in, but draw 1 pixel past so // that the top/bottom of the line segment's anti-aliasing isn't // visible in the final rendering. int top = wa.RenderingOrigin.Y + rowHeight / 2; var laneRect = new Rectangle(0, top, Width, rowHeight); Region oldClip = wa.Clip; var newClip = new Region(laneRect); newClip.Intersect(oldClip); wa.Clip = newClip; wa.Clear(Color.Transparent); //for (int r = 0; r < 2; r++) for (int lane = 0; lane < row.Count; lane++) { int mid = wa.RenderingOrigin.X + (int)((lane + 0.5) * LANE_WIDTH); for (int item = 0; item < row.LaneInfoCount(lane); item++) { Graph.LaneInfo laneInfo = row[lane, item]; bool highLight = (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && laneInfo.Junctions.Any(j => j.IsRelative)) || (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.HighlightSelected && laneInfo.Junctions.Any(j => j.HighLight)) || (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.Normal); List<Color> curColors = GetJunctionColors(laneInfo.Junctions); // Create the brush for drawing the line Brush brushLineColor = null; Pen brushLineColorPen = null; try { bool drawBorder = Settings.BranchBorders && highLight; //hide border for "non-relatives" if (curColors.Count == 1 || !Settings.StripedBranchChange) { if (curColors[0] != nonRelativeColor) { brushLineColor = new SolidBrush(curColors[0]); } else if (curColors.Count > 1 && curColors[1] != nonRelativeColor) { brushLineColor = new SolidBrush(curColors[1]); } else { drawBorder = false; brushLineColor = new SolidBrush(nonRelativeColor); } } else { Color lastRealColor = curColors.LastOrDefault(c => c != nonRelativeColor); if (lastRealColor.IsEmpty) { brushLineColor = new SolidBrush(nonRelativeColor); drawBorder = false; } else { brushLineColor = new HatchBrush(HatchStyle.DarkDownwardDiagonal, curColors[0], lastRealColor); } } for (int i = drawBorder ? 0 : 2; i < 3; i++) { Pen penLine = null; if (i == 0) { penLine = whiteBorderPen; } else if (i == 1) { penLine = blackBorderPen; } else { if (brushLineColorPen == null) brushLineColorPen = new Pen(brushLineColor, LANE_LINE_WIDTH); penLine = brushLineColorPen; } if (laneInfo.ConnectLane == lane) { wa.DrawLine ( penLine, new Point(mid, top - 1), new Point(mid, top + rowHeight + 2) ); } else { wa.DrawBezier ( penLine, new Point(mid, top - 1), new Point(mid, top + rowHeight + 2), new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top - 1), new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top + rowHeight + 2) ); } } } finally { if (brushLineColorPen != null) ((IDisposable)brushLineColorPen).Dispose(); if (brushLineColor != null) ((IDisposable)brushLineColor).Dispose(); } } } // Reset the clip region wa.Clip = oldClip; { // Draw node var nodeRect = new Rectangle ( wa.RenderingOrigin.X + (LANE_WIDTH - NODE_DIMENSION) / 2 + row.NodeLane * LANE_WIDTH, wa.RenderingOrigin.Y + (rowHeight - NODE_DIMENSION) / 2, NODE_DIMENSION, NODE_DIMENSION ); Brush nodeBrush; List<Color> nodeColors = GetJunctionColors(row.Node.Ancestors); bool highlight = (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && row.Node.Ancestors.Any(j => j.IsRelative)) || (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.HighlightSelected && row.Node.Ancestors.Any(j => j.HighLight)) || (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.Normal); bool drawBorder = Settings.BranchBorders && highlight; if (nodeColors.Count == 1) { nodeBrush = new SolidBrush(highlight ? nodeColors[0] : nonRelativeColor); if (nodeColors[0] == nonRelativeColor) drawBorder = false; } else { nodeBrush = new LinearGradientBrush(nodeRect, nodeColors[0], nodeColors[1], LinearGradientMode.Horizontal); if (nodeColors.All(c => c == nonRelativeColor)) drawBorder = false; } if (filterMode == FilterType.Highlight && row.Node.IsFiltered) { Rectangle highlightRect = nodeRect; highlightRect.Inflate(2, 3); wa.FillRectangle(Brushes.Yellow, highlightRect); wa.DrawRectangle(Pens.Black, highlightRect); } if (row.Node.Data == null) { wa.FillEllipse(Brushes.White, nodeRect); using (var pen = new Pen(Color.Red, 2)) { wa.DrawEllipse(pen, nodeRect); } } else if (row.Node.IsActive) { wa.FillRectangle(nodeBrush, nodeRect); nodeRect.Inflate(1, 1); using (var pen = new Pen(Color.Black, 3)) wa.DrawRectangle(pen, nodeRect); } else if (row.Node.IsSpecial) { wa.FillRectangle(nodeBrush, nodeRect); if (drawBorder) { wa.DrawRectangle(Pens.Black, nodeRect); } } else { wa.FillEllipse(nodeBrush, nodeRect); if (drawBorder) { wa.DrawEllipse(Pens.Black, nodeRect); } } } return true; }
/// <summary> /// Draws lines between boxes /// </summary> /// <param name="a">First node (From)</param> /// <param name="b">Second Node (To)</param> /// <param name="whichKid">The number of the child node being connected to.</param> /// <param name="kidCount">Number of kids being connected to from the first node.</param> private void joinNodes(Node a, Node b, int whichKid, int kidCount) { PointF[] points = null; float dx, dy, x1, y1, x2, y2; Node temp; Options.ElementOptions eo; eo = Options.OptionsData.whichOption(b); // the second node determines the line style if ((treeOrientation == DrawTree.treeOrientationType.bottom_up) | (treeOrientation == DrawTree.treeOrientationType.top_down)) { if (a.y > b.y) // swap { temp = b; b = a; a = temp; } } else { if (a.x > b.x) // swap { temp = b; b = a; a = temp; } } // Create pen. Pen pen = new Pen(Color.Black, 1); // calc offset if (treeOrientation == DrawTree.treeOrientationType.top_down) { temp = a; } else { temp = b; } // bool distributeX = false; float gap; float xdif = 0; if (opts.Distributed) { gap = temp.width / (float)(kidCount + 1); if (treeOrientation == DrawTree.treeOrientationType.top_down) { xdif = gap * (float)(whichKid + 1) - temp.width / 2; } else { xdif = -(gap * (float)(whichKid + 1) - temp.width / 2); } } if ((treeOrientation == DrawTree.treeOrientationType.bottom_up) | (treeOrientation == DrawTree.treeOrientationType.top_down)) { dx = (b.x + b.width / 2) - (a.x + a.width / 2); // x difference dy = (b.y - a.y - a.height) / 2F; // y difference x1 = a.x + a.width / 2F + offsetX; // right side of top box y1 = a.y + a.height + this.offsetY; // bottom of the box x2 = b.x + (b.width / 2.0F) + this.offsetX; // middle of the bottom box y2 = b.y + this.offsetY; // top of bottom box if (opts.Distributed) { if (treeOrientation == DrawTree.treeOrientationType.top_down) { x1 += xdif; dx -= xdif; } else { x2 -= xdif; dx = x2 - x1; } } } else { x1 = a.x + a.width + offsetX; // halfway in x-axis for the top box y1 = a.y + a.height / 2 + this.offsetY; // bottom of the box x2 = b.x + this.offsetX; // left of right box y2 = b.y + b.height / 2F + this.offsetY; // top of bottom box dx = (x2 - x1) / 2; // x difference dy = y2 - y1; // y difference } // Create array of points that define lines to draw. if ((treeOrientation == DrawTree.treeOrientationType.bottom_up) | (treeOrientation == DrawTree.treeOrientationType.top_down)) { if (join == joinType.dogleg || join == joinType.curve) { if (dx == 0F) // If there is no horizontal movement, just draw one line { PointF[] p1 = { new PointF(x1, y1), new PointF(x2, y2) }; points = p1; } else { PointF[] p1 = { new PointF(x1, y1), new PointF(x1, y1 + dy), new PointF(x1 + dx, y1 + dy), new PointF(x2, y2) }; points = p1; } } else if (join == joinType.direct) // joinType.direct - i.e. a straight line { PointF[] p1 = { new PointF(x1, y1), new PointF(x2, y2) }; points = p1; } else if (join == joinType.curve) { } // do nothing else { System.Diagnostics.Debug.Assert(false, "Unknown join type"); } } else // left to right { if (join == joinType.dogleg || join == joinType.curve) { if (dy == 0F) // If there is no vertical movement, just draw one line { PointF[] p1 = { new PointF(x1, y1), new PointF(x2, y2) }; points = p1; } else { PointF[] p1 = { new PointF(x1, y1), new PointF(x1 + dx, y1), new PointF(x1 + dx, y1 + dy), new PointF(x2, y2) }; points = p1; } } else if (join == joinType.direct) // joinType.direct - i.e. a straight line { PointF[] p1 = { new PointF(x1, y1), new PointF(x2, y2) }; points = p1; } else if (join == joinType.curve) { PointF[] p1 = { new PointF(x1, y1), new PointF(x1, y1 + dy), new PointF(x1 + dx, y1 + dy), new PointF(x2, y2) }; points = p1; } else { System.Diagnostics.Debug.Assert(false, "Unknown join type"); } } pen.DashStyle = eo.lineStyle; // add arrow if required if (arrows != arrowType.none) { AdjustableArrowCap myArrow = new AdjustableArrowCap(4, 6, true); if (arrows == arrowType.start | arrows == arrowType.both) { pen.CustomStartCap = myArrow; } if (arrows == arrowType.end | arrows == arrowType.both) { pen.CustomEndCap = myArrow; } } //Draw lines to screen. if (join == joinType.curve) { graphics.DrawBezier(pen, x1, y1, x1, y1 + dy, x1 + dx, y1 + dy, x2, y2); } else { graphics.DrawLines(pen, points); } if (marker != markerType.none) { drawElementMarker(b, join, x2, y2, pen, new SolidBrush(Color.BlueViolet)); } }
// end DrawGraph private bool DrawItem(Graphics wa, Graph.LaneRow row) { if (row == null || row.NodeLane == -1) { return false; } // Clip to the area we're drawing in, but draw 1 pixel past so // that the top/bottom of the line segment's anti-aliasing isn't // visible in the final rendering. int top = wa.RenderingOrigin.Y + _rowHeight / 2; var laneRect = new Rectangle(0, top, Width, _rowHeight); Region oldClip = wa.Clip; var newClip = new Region(laneRect); newClip.Intersect(oldClip); wa.Clip = newClip; wa.Clear(Color.Transparent); for (int r = 0; r < 2; r++) for (int lane = 0; lane < row.Count; lane++) { int mid = wa.RenderingOrigin.X + (int)((lane + 0.5) * LaneWidth); for (int item = 0; item < row.LaneInfoCount(lane); item++) { Graph.LaneInfo laneInfo = row[lane, item]; //Draw all non-relative items first, them draw //all relative items on top if (laneInfo.Junctions.FirstOrDefault() != null) if (laneInfo.Junctions.First().IsRelative == (r == 0)) continue; List<Color> curColors = GetJunctionColors(laneInfo.Junctions); // Create the brush for drawing the line Brush brushLineColor; bool drawBorder = BranchBorders; //hide border for "non-relatives" if (curColors.Count == 1 || !StripedBranchChange) { if (curColors[0] != _nonRelativeColor) { brushLineColor = new SolidBrush(curColors[0]); } else if (curColors.Count > 1 && curColors[1] != _nonRelativeColor) { brushLineColor = new SolidBrush(curColors[1]); } else { drawBorder = false; brushLineColor = new SolidBrush(_nonRelativeColor); } } else { brushLineColor = new HatchBrush(HatchStyle.DarkDownwardDiagonal, curColors[0], curColors[1]); if (curColors[0] == _nonRelativeColor && curColors[1] == _nonRelativeColor) drawBorder = false; } for (int i = drawBorder ? 0 : 2; i < 3; i++) { Pen penLine; if (i == 0) { penLine = new Pen(new SolidBrush(Color.White), LaneLineWidth + 2); } else if (i == 1) { penLine = new Pen(new SolidBrush(Color.Black), LaneLineWidth + 1); } else { penLine = new Pen(brushLineColor, LaneLineWidth); } if (laneInfo.ConnectLane == lane) { wa.DrawLine ( penLine, new Point(mid, top - 1), new Point(mid, top + _rowHeight + 2) ); } else { wa.DrawBezier ( penLine, new Point(mid, top - 1), new Point(mid, top + _rowHeight + 2), new Point(mid + (laneInfo.ConnectLane - lane) * LaneWidth, top - 1), new Point(mid + (laneInfo.ConnectLane - lane) * LaneWidth, top + _rowHeight + 2) ); } } } } // Reset the clip region wa.Clip = oldClip; { // Draw node var nodeRect = new Rectangle ( wa.RenderingOrigin.X + (LaneWidth - NodeDimensions) / 2 + row.NodeLane * LaneWidth, wa.RenderingOrigin.Y + (_rowHeight - NodeDimensions) / 2, NodeDimensions, NodeDimensions ); Brush nodeBrush; bool drawBorder = BranchBorders; List<Color> nodeColors = GetJunctionColors(row.Node.Ancestors); if (nodeColors.Count == 1) { nodeBrush = new SolidBrush(nodeColors[0]); if (nodeColors[0] == _nonRelativeColor) drawBorder = false; } else { nodeBrush = new LinearGradientBrush(nodeRect, nodeColors[0], nodeColors[1], LinearGradientMode.Horizontal); if (nodeColors[0] == _nonRelativeColor && nodeColors[1] == Color.LightGray) drawBorder = false; } if (_filterMode == FilterType.Highlight && row.Node.IsFiltered) { Rectangle highlightRect = nodeRect; highlightRect.Inflate(2, 3); wa.FillRectangle(Brushes.Yellow, highlightRect); wa.DrawRectangle(new Pen(Brushes.Black), highlightRect); } if (row.Node.Data == null) { wa.FillEllipse(Brushes.White, nodeRect); wa.DrawEllipse(new Pen(Color.Red, 2), nodeRect); } else if (row.Node.IsActive) { wa.FillRectangle(nodeBrush, nodeRect); nodeRect.Inflate(1, 1); wa.DrawRectangle(new Pen(Color.Black, 3), nodeRect); } else if (row.Node.IsSpecial) { wa.FillRectangle(nodeBrush, nodeRect); if (drawBorder) { wa.DrawRectangle(new Pen(Color.Black, 1), nodeRect); } } else { wa.FillEllipse(nodeBrush, nodeRect); if (drawBorder) { wa.DrawEllipse(new Pen(Color.Black, 1), nodeRect); } } } return true; }
private void btnBezier_Click(object sender, EventArgs e) { g = pictureBox1.CreateGraphics(); g.DrawBezier(penGreen, 100, 100, 200, 10, 350, 50, 500, 100);; }
private void RenderRelativePath(VehicleState vs, Path transPath, Graphics g, WorldTransform t, bool isArbiterPath) { if((isArbiterPath && DrawingUtility.DrawArbiterLanePath) || (!isArbiterPath && DrawingUtility.DrawOperationalLanePath)) { // compute the rotation matrix to add in our vehicles rotation /*Matrix3 rotMatrix = new Matrix3( Math.Cos(vs.heading.ArcTan), -Math.Sin(vs.heading.ArcTan), 0, Math.Sin(vs.heading.ArcTan), Math.Cos(vs.heading.ArcTan), 0, 0, 0, 1); // compute the translation matrix to move our vehicle's location Matrix3 transMatrix = new Matrix3( 1, 0, vs.xyPosition.X, 0, 1, vs.xyPosition.Y, 0, 0, 1); // compute the combined transformation matrix Matrix3 m = rotMatrix * transMatrix; // clone, transform and add each segment to our path transPath.Transform(m);*/ float nomPixelWidth = 2.0f; float penWidth = nomPixelWidth / t.Scale; Pen arbiterPen = new Pen(Color.FromArgb(100, DrawingUtility.ArbiterLanePath), penWidth); Pen operationalPen = new Pen(Color.FromArgb(100, DrawingUtility.OperationalLanePath), penWidth); // display path foreach (IPathSegment ps in transPath) { if (ps is BezierPathSegment) { BezierPathSegment seg = (BezierPathSegment)ps; CubicBezier cb = seg.cb; if (isArbiterPath) { g.DrawBezier(arbiterPen, DrawingUtility.ToPointF(cb.P0), DrawingUtility.ToPointF(cb.P1), DrawingUtility.ToPointF(cb.P2), DrawingUtility.ToPointF(cb.P3)); } else { g.DrawBezier(operationalPen, DrawingUtility.ToPointF(cb.P0), DrawingUtility.ToPointF(cb.P1), DrawingUtility.ToPointF(cb.P2), DrawingUtility.ToPointF(cb.P3)); } } } } }
private void button4_Click(object sender, EventArgs e) { g.DrawBezier(pen1, new Point(100, 100), new Point(200, 10), new Point(350, 50), new Point(500, 100)); }