/// <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 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> /// 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; } } }
public static 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 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); } } } } } }