示例#1
0
        protected List <Rectangle> DrawLeaves(List <MerkleNode> leaves)
        {
            List <Rectangle> rects = new List <Rectangle>();
            int i = 0;

            foreach (var leaf in leaves.Cast <DemoMerkleNode>())
            {
                var leafRect = new Rectangle(i * X_OFFSET, LEAF_Y, LEAF_WIDTH, NODE_HEIGHT);
                WebSocketHelpers.DropShape("Box", leaf.Text, leafRect, LEAF_COLOR, leaf.Text);
                rects.Add(leafRect);
                leaf.Tag = leafRect;
                ++i;
            }

            return(rects);
        }
示例#2
0
        protected List <Rectangle> DrawParents(IEnumerable <MerkleNode> parents, int level)
        {
            List <Rectangle> rects = new List <Rectangle>();
            int i  = 0;
            int l0 = level - 1;
            int indent;
            int spacing;
            int width = NODE_WIDTH;

            // Leaves and branches have different widths.
            if (level == 1)
            {
                indent  = LEAF_WIDTH / 2 - 5;
                spacing = LEAF_WIDTH * 2 + 10;
            }
            else if (level == 2)
            {
                indent  = ((int)Math.Pow(2, l0) - 1) * LEAF_WIDTH + LEAF_WIDTH / 2;
                spacing = NODE_WIDTH * (int)Math.Pow(2, level) - NODE_WIDTH / 2 - 13;
            }
            else if (level == 3)
            {
                indent  = ((int)Math.Pow(2, l0) - 1) * LEAF_WIDTH + LEAF_WIDTH / 2 + 10;
                spacing = NODE_WIDTH * (int)Math.Pow(2, level) - NODE_WIDTH / 2 - 75;
            }
            else
            {
                indent  = ((int)Math.Pow(2, l0) - 1) * LEAF_WIDTH + LEAF_WIDTH / 2 - 20;
                spacing = NODE_WIDTH * (int)Math.Pow(2, level) - NODE_WIDTH / 2 - 30;
                width   = NODE_WIDTH * 2;
            }

            Color nodeColor = parents.Count() == 1 ? ROOT_COLOR : NODE_COLOR;

            foreach (var node in parents.Cast <DemoMerkleNode>())
            {
                var nodeRect = new Rectangle(indent + i * spacing, LEAF_Y - (V_OFFSET * level), width, NODE_HEIGHT);
                WebSocketHelpers.DropShape("Box", node.Text, nodeRect, nodeColor, node.Text);
                rects.Add(nodeRect);
                node.Tag = nodeRect;
                ++i;
            }

            return(rects);
        }