56 begin
57 curx := X + i * rw;
58 cury := Y;
59 bmp.Canvas.Rectangle(curx, cury, curx + rw + 1, cury + rh);
60 bmp.Canvas.TextOut(curx + 5, cury + 3, IntToStr(Node.key[i]));
61
62
63 j := i - (node.n + 1) div 2 - 1; // центрирование
64
65 // лесенкой
66 newx := X + pow(t - 1, H - Level - 1) * (rw + 2) * j;
67 newy := y + 150 + i * (rh + 2);
68 // в линию
69 // newx := X + pow(2*t-1, H - Level - 2) * (rw+2) * j;
70 // newy := y + 150;
71
72 bmp.Canvas.MoveTo(curx, cury + rh);
73 bmp.Canvas.LineTo(newx + rw, newy);
74
75 BTreeDraw(Node.c[i], newx, newy, Level + 1, h);
76 end;
77 newx := X + pow(t-1, H - Level - 1) * (rw + 2) * ((node.n+1) div 2);
78 newy := y + 150 + (node.n + 1) * (rh + 2);
79 // newx := X + pow(2*t-1, H - Level - 1) * (rw+2) * (node.n div 2+1);
80
81 bmp.Canvas.MoveTo(curx + rw, cury + rh);
82 bmp.Canvas.LineTo(newx + rw, newy);
83
84 BTreeDraw(Node.c[Node.n + 1], newx, newy, level + 1, h);
85 end
86 else
87 for i := 1 to Node.n do
88 begin
89 curx := x + i * rw;
90 cury := y;
91 bmp.Canvas.Rectangle(curx, cury, curx + rw + 1, cury + rh);
92 bmp.Canvas.TextOut(curx + 5, cury + 3, IntToStr(Node.key[i]));
93 end;
94 end;
95
96 procedure TfTreePicture.Draw(NumOfKeys: integer);
97 var h: integer;
98 begin
99 H := Floor(ln(NumOfKeys)/ln(t)) + 1;
100 bmp.Width := pow(t-1, H+1)*(rw+2);
101
102 if bmp.Width < Width then bmp.Width := Width + 100;
103
104 bmp.Height := H*200;
105
106 if bmp.Height < Height then bmp.Height := Height+ 100;
107
108 bmp.Canvas.FillRect(bmp.Canvas.ClipRect);
109 BTreeDraw(bt.RootPos, bmp.Width div 2, 10, 0, H);
110 iBTree.Picture.Bitmap.Assign(bmp);
111 sbHoriz.Max := bmp.Width - 1 - iBTree.Width;
112 sbVert.Max := bmp.Height - 1 - iBTree.Height;
113
114 sbHoriz.Position := sbHoriz.Max div 2+60;
115 end;
116
117 procedure TfTreePicture.FormCreate(Sender: TObject);
118 begin
119 bmp := TBitmap.Create;
37