Example #1
0
            /// <summary>
            /// Draw the node on a panel surface.
            /// </summary>
            /// <param name="surface">Surface to draw on.</param>
            internal void Draw(DrawingSurface2D surface)
            {
                if (this.Position.Width > 0)
                {
                    // Fill colors in bands from left to right
                    double offset = 0;
                    foreach (Tuple <double, Color> band in this.FillColors)
                    {
                        if (band.Item1 <= 0)
                        {
                            continue;
                        }

                        Color c     = band.Item2;
                        var   brush = new SolidBrush(c);

                        Point2D left = new Point2D(this.Position.Corner1.X + offset * this.Position.Width, this.Position.Corner1.Y);
                        offset += band.Item1;
                        Point2D right = new Point2D(this.Position.Corner1.X + offset * this.Position.Width, this.Position.Corner2.Y);
                        surface.FillRectangle(brush, new Rectangle2D(left, right));
                    }

                    Font font = new Font("Arial", 12, FontStyle.Regular);
                    // let's shrink the position for the text to leave some border

                    if (this.Label != null)
                    {
                        const double borderFraction = 8; // reserve 1/8 of the rectangle for border
                        Rectangle2D  box            = new Rectangle2D(
                            this.Position.Corner1.Translate(this.Position.Width / borderFraction, this.Position.Height / borderFraction),
                            this.Position.Corner2.Translate(-this.Position.Width / borderFraction, -this.Position.Height / borderFraction));
                        surface.DrawTextInRectangle(this.Label, Brushes.Black, font, box);
                    }
                }

                Pen pen = this.Selected ? thickBlackPen : blackPen;

                switch (this.Shape)
                {
                default:
                case NodeShape.Box:
                    surface.DrawRectangle(this.Position, pen);
                    break;

                case NodeShape.Ellipse:
                    surface.DrawEllipse(this.LineColor, this.Position, pen, false);
                    break;

                case NodeShape.Invhouse:
                {
                    Point2D[] points = new Point2D[5];
                    points[0] = new Point2D(this.Position.Corner1.X, this.Position.Corner1.Y + this.Position.Height / 3);
                    points[1] = new Point2D(this.Position.Corner1.X, this.Position.Corner2.Y - this.Position.Height / 8);
                    points[2] = new Point2D(this.Position.Corner2.X, this.Position.Corner2.Y - this.Position.Height / 8);
                    points[3] = new Point2D(this.Position.Corner2.X, this.Position.Corner1.Y + this.Position.Height / 3);
                    points[4] = new Point2D(this.Position.Corner1.X + this.Position.Width / 2, this.Position.Corner1.Y);
                    surface.DrawPolygon(this.LineColor, points, pen, false);
                    break;
                }
                }
            }
Example #2
0
            /// <summary>
            /// Draw the node on a panel surface.
            /// </summary>
            /// <param name="surface">Surface to draw on.</param>
            internal void Draw(DrawingSurface2D surface)
            {
                if (this.Position.Width > 0)
                {
                    // Fill colors in bands from left to right
                    double offset = 0;
                    foreach (Tuple<double, Color> band in this.FillColors)
                    {
                        if (band.Item1 <= 0)
                            continue;

                        Color c = band.Item2;
                        var brush = new SolidBrush(c);

                        Point2D left = new Point2D(this.Position.Corner1.X + offset * this.Position.Width, this.Position.Corner1.Y);
                        offset += band.Item1;
                        Point2D right = new Point2D(this.Position.Corner1.X + offset * this.Position.Width, this.Position.Corner2.Y);
                        surface.FillRectangle(brush, new Rectangle2D(left, right));
                    }

                    Font font = new Font("Arial", 12, FontStyle.Regular);
                    // let's shrink the position for the text to leave some border

                    if (this.Label != null)
                    {
                        const double borderFraction = 8; // reserve 1/8 of the rectangle for border
                        Rectangle2D box = new Rectangle2D(
                            this.Position.Corner1.Translate(this.Position.Width / borderFraction, this.Position.Height / borderFraction),
                            this.Position.Corner2.Translate(-this.Position.Width / borderFraction, -this.Position.Height / borderFraction));
                        surface.DrawTextInRectangle(this.Label, Brushes.Black, font, box);
                    }
                }

                Pen pen = this.Selected ? thickBlackPen : blackPen;
                switch (this.Shape)
                {
                    default:
                    case NodeShape.Box:
                        surface.DrawRectangle(this.Position, pen);
                        break;
                    case NodeShape.Ellipse:
                        surface.DrawEllipse(this.LineColor, this.Position, pen, false);
                        break;
                    case NodeShape.Invhouse:
                        {
                            Point2D[] points = new Point2D[5];
                            points[0] = new Point2D(this.Position.Corner1.X, this.Position.Corner1.Y + this.Position.Height / 3);
                            points[1] = new Point2D(this.Position.Corner1.X, this.Position.Corner2.Y - this.Position.Height / 8);
                            points[2] = new Point2D(this.Position.Corner2.X, this.Position.Corner2.Y - this.Position.Height / 8);
                            points[3] = new Point2D(this.Position.Corner2.X, this.Position.Corner1.Y + this.Position.Height / 3);
                            points[4] = new Point2D(this.Position.Corner1.X + this.Position.Width / 2, this.Position.Corner1.Y);
                            surface.DrawPolygon(this.LineColor, points, pen, false);
                            break;
                        }
                }
            }