public virtual void Paint(GraphicsLayer.IGraphics g, int width, int height) { var bounds = ComputeBounds(g, width, height); if (!string.IsNullOrEmpty(_label)) { if (Color.Equals(default(GraphicsLayer.ARGB))) { if (IsUniversal) { g.FillEllipse(UniversalVertexFillBrushColor, bounds); } } else { g.FillEllipse(Color, bounds); } g.DrawEllipse(_IsSelected ? BoundarySelectedPenColor : BoundaryPenColor, bounds, _IsSelected ? BoundarySelectedPenWidth : 1); g.DrawString(_label, LabelFont, LabelBrushColor, bounds); } else { if (Color.Equals(default(GraphicsLayer.ARGB))) { g.FillEllipse(IsUniversal ? UniversalVertexFillBrushColor : DefaultFillBrushColor, bounds); } else { g.FillEllipse(Color, bounds); } g.DrawEllipse(_IsSelected ? BoundarySelectedPenColor : BoundaryPenColor, bounds, _IsSelected ? BoundarySelectedPenWidth : 1); } }
public virtual void Paint(GraphicsLayer.IGraphics g, int width, int height) { var bounds = ComputeBounds(g, width, height); if (!string.IsNullOrEmpty(_label)) { if (Color.Equals(default(GraphicsLayer.ARGB))) { if (IsUniversal) { g.FillEllipse(UniversalVertexFillBrushColor, bounds); } } else { g.FillEllipse(Color, bounds); } g.DrawEllipse(_IsSelected ? BoundarySelectedPenColor : BoundaryPenColor, bounds, _IsSelected ? BoundarySelectedPenWidth : 1); g.DrawString(_label, LabelFont, LabelBrushColor, bounds); } else { if (Color.Equals(default(GraphicsLayer.ARGB))) { g.FillEllipse(IsUniversal ? UniversalVertexFillBrushColor : DefaultFillBrushColor, bounds); } else { g.FillEllipse(Color, bounds); } g.DrawEllipse(_IsSelected ? BoundarySelectedPenColor : BoundaryPenColor, bounds, _IsSelected ? BoundarySelectedPenWidth : 1); } if (_showIndex) { var cx = (bounds.Left + bounds.Right) / 2; var cy = (bounds.Bottom + bounds.Top) / 2; var r = Math.Max(bounds.Width, bounds.Height) / 2 + 5; var bb = new GraphicsLayer.Box(cx + r * Math.Cos(IndexAngle) - 5, cy + r * Math.Sin(IndexAngle) - 5, 10, 10); g.DrawString(ParentIndex.ToString(), IndexFont, IndexBrushColor, bb); } }
public void Paint(GraphicsLayer.IGraphics g, int width, int height) { if (_V1 == _V2) { // Draw self loop. } else { var maxRadius1 = Math.Max(_V1.LocalBounds.Width, _V1.LocalBounds.Height) / 2; var maxRadius2 = Math.Max(_V2.LocalBounds.Width, _V2.LocalBounds.Height) / 2; var cos = (_V2.X - _V1.X) / Math.Sqrt((_V2.X - _V1.X) * (_V2.X - _V1.X) + (_V2.Y - _V1.Y) * (_V2.Y - _V1.Y)); cos = Math.Min(Math.Max(cos, -1), 1); var sin = (_V2.Y - _V1.Y) / Math.Sqrt((_V2.X - _V1.X) * (_V2.X - _V1.X) + (_V2.Y - _V1.Y) * (_V2.Y - _V1.Y)); sin = Math.Min(Math.Max(sin, -1), 1); var angle = Math.Acos(cos); if (_V1.Y > _V2.Y) { angle = -angle; } if (double.IsNaN(angle)) { return; } var angleStep = Math.PI / 2.0 / _Multiplicity; var evenModifier = (_Multiplicity % 2 == 0) ? 0.5 : 0; GraphicsLayer.Box topStart = new GraphicsLayer.Box(0, 0); GraphicsLayer.Box topFinish = new GraphicsLayer.Box(0, 0); var first = true; for (int i = -(_Multiplicity - 1) / 2; i < Math.Ceiling((_Multiplicity + 1) / 2.0); i++) { var startAngle = angle + angleStep * (i - evenModifier); var finishAngle = angle - angleStep * (i - evenModifier); var start = LocalToGlobal(_V1.Location + Utility.PolarToRectangular(maxRadius1 + 0.01, startAngle), width, height); var finish = LocalToGlobal(_V2.Location - Utility.PolarToRectangular(maxRadius2 + 0.01, finishAngle), width, height); if (first) { first = false; topStart = start; topFinish = finish; } g.DrawLine(_penColor, start, finish, _thickness); } if (_Orientation != Orientations.None) { var points = new GraphicsLayer.Box[3]; if (_Orientation == Orientations.Forward) { var sweep = _V2.Location - Utility.PolarToRectangular(maxRadius2 + 0.025f, angle); points[0] = LocalToGlobal(Utility.RotateAroundPoint(sweep, _V2.Location, Math.PI / 180.0 * 10.0), width, height); points[1] = LocalToGlobal(_V2.Location - Utility.PolarToRectangular(maxRadius2 + 0.005f, angle), width, height); points[2] = LocalToGlobal(Utility.RotateAroundPoint(sweep, _V2.Location, -Math.PI / 180.0 * 10.0), width, height); } else if (_Orientation == Orientations.Backward) { var sweep = _V1.Location + Utility.PolarToRectangular(maxRadius1 + 0.025f, angle); points[0] = LocalToGlobal(Utility.RotateAroundPoint(sweep, _V1.Location, Math.PI / 180.0 * 10.0), width, height); points[1] = LocalToGlobal(_V1.Location + Utility.PolarToRectangular(maxRadius1 + 0.005f, angle), width, height); points[2] = LocalToGlobal(Utility.RotateAroundPoint(sweep, _V1.Location, -Math.PI / 180.0 * 10.0), width, height); } g.FillPolygon(new GraphicsLayer.ARGB(0, 0, 0), points); } var label = Label; if (!string.IsNullOrEmpty(label)) { var box = g.MeasureString(label, LabelFont); var bounds = new GraphicsLayer.Box(topStart.X + (topFinish.X - topStart.X) / 2 - box.Width / 2 - 0.75 * box.Width * sin, topStart.Y + (topFinish.Y - topStart.Y) / 2 - box.Height / 2 + 0.75 * box.Height * cos, box.Width, box.Height); g.DrawString(label, LabelFont, LabelBrushColor, bounds); } if (_showIndex) { var bounds = new GraphicsLayer.Box(topStart.X + (topFinish.X - topStart.X) / 2, topStart.Y + (topFinish.Y - topStart.Y) / 2, 10, 10); var cx = (bounds.Left + bounds.Right) / 2; var cy = (bounds.Bottom + bounds.Top) / 2; var r = Math.Max(bounds.Width, bounds.Height) / 2 + 5; var bb = new GraphicsLayer.Box(cx + r * Math.Cos(IndexAngle) - 5, cy + r * Math.Sin(IndexAngle) - 5, 10, 10); g.DrawString(ParentIndex.ToString(), IndexFont, IndexBrushColor, bb); } } }