Esempio n. 1
0
        public static void RenderTree(IRenderContext g, TypeTree tree)
        {
            RenderNode rRoot = RenderNode.ConvertFromNode(tree.root);
            Size       size  = rRoot.GetSize();

            g.DrawBackground(size);
            DrawTree(g, rRoot, rRoot.GetOriginX((int)size.Width), SquareSize);
        }
Esempio n. 2
0
        private static Size DrawTree(IRenderContext g, RenderNode rRoot, int x, int y)
        {
            RenderNode left;
            RenderNode right;
            Size       size;

            foreach (RenderNode n in rRoot.GetAllNodes())
            {
                bool hasChild = false;
                int  nx       = n.x + x;
                int  ny       = n.y + y;

                g.DrawRectangle(nx - SquareSize / 2, ny - SquareSize / 2, SquareSize, SquareSize);
                size = g.MeasureString(n.display);
                g.DrawString(n.display, nx - size.Width / 2, ny - size.Height / 2);

                if (!n.isRoot)
                {
                    g.DrawLine(nx, ny - SquareSize / 2, nx, ny - DefaultDistance / 2);
                }

                left  = n.GetLeft();
                right = n.GetRight();

                if (left != null)
                {
                    g.DrawLine(nx, ny + DefaultDistance / 2, left.x + x, ny + DefaultDistance / 2);
                    hasChild = true;
                }

                if (right != null)
                {
                    g.DrawLine(nx, ny + DefaultDistance / 2, right.x + x, ny + DefaultDistance / 2);
                    hasChild = true;
                }

                if (hasChild)
                {
                    g.DrawLine(nx, ny + SquareSize / 2, nx, ny + DefaultDistance / 2);
                }
            }

            return(rRoot.GetSize());
        }