示例#1
0
        public Bitmap Draw(OrientedGraph graph, int scroll, int selectedID, int[] selectedEdge)
        {
            btm = new Bitmap(500, 800);
            gr  = Graphics.FromImage(btm);

            for (int i = 0; i < graph.CountNodes(); i++)
            {
                Pen pen;
                if (i == selectedID)
                {
                    pen = new Pen(Color.Red, 3);
                }
                else
                {
                    pen = new Pen(Color.Black, 3);
                }

                switch (graph.GetNodeType(i))
                {
                case 1:
                {
                    gr.DrawRectangle(pen, 200 + graph.GetNodeShift(i) * 100, 25 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll, 100, 100);
                    break;
                }

                case 2:
                {
                    Point[] p = new Point[4];
                    p[0] = new Point(200 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[1] = new Point(250 + graph.GetNodeShift(i) * 100, 50 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[2] = new Point(300 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[3] = new Point(250 + graph.GetNodeShift(i) * 100, 100 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    gr.DrawPolygon(pen, p);
                    break;
                }

                case 3:
                {
                    gr.DrawEllipse(pen, 200 + graph.GetNodeShift(i) * 100, 50 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll, 100, 50);
                    break;
                }

                case 5:
                {
                    Point[] p = new Point[4];
                    p[0] = new Point(200 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[1] = new Point(250 + graph.GetNodeShift(i) * 100, 50 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[2] = new Point(300 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    p[3] = new Point(250 + graph.GetNodeShift(i) * 100, 100 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    gr.DrawPolygon(pen, p);
                    break;
                }
                }
                for (int j = 0; j < graph.GetAdj()[i].Count; j++)
                {
                    if (selectedEdge[0] == i && selectedEdge[1] == graph.GetAdj()[i][j])
                    {
                        pen = Pens.Red;
                    }
                    else
                    {
                        pen = Pens.Black;
                    }
                    Point p1 = new Point(250 + graph.GetNodeShift(i) * 100, 75 + DIST_BETWEEN_BLOCKS * i - SCROLL_SCALE * scroll);
                    Point p2 = new Point(250 + graph.GetNodeShift(graph.GetAdj()[i][j]) * 100, 75 + DIST_BETWEEN_BLOCKS * graph.GetAdj()[i][j] - SCROLL_SCALE * scroll);
                    Drawline(pen, graph.GetNodeType(i), graph.GetNodeType(graph.GetAdj()[i][j]), p1, p2);
                }
            }

            return(btm);
        }
 public Flowchart(string name)
 {
     this.name = name;
     graph     = new OrientedGraph();
     blocks    = new List <IBlock>();
 }