rendered paste bodyprocedure TTree.AuxCalc(ANode: PNode);
begin
if ANode = FRoot then begin
ANode^.FY := 0;
end;
if ANode^.FLeft <> nil then begin
ANode^.FLeft^.FY := ANode^.FY + VSpace + 2 * NodeSize;
AuxCalc(ANode^.FLeft);
end;
if ANode^.FRight <> nil then begin
ANode^.FRight^.FY := ANode^.FY + VSpace + 2 * NodeSize;
AuxCalc(ANode^.FRight);
end;
if (ANode^.FLeft = nil) and (ANode^.FRight = nil) then begin
ANode^.FHeight := 2 * NodeSize;
ANode^.FWidth := 2 * NodeSize;
end
else begin
if (ANode^.FLeft <> nil) and (ANode^.FRight = nil) then begin
ANode^.FHeight := ANode^.FLeft^.FHeight + VSpace + 2 * NodeSize;
ANode^.FWidth := ANode^.FLeft^.FWidth + HSpace;
end
else begin
if (ANode^.FLeft = nil) and (ANode^.FRight <> nil) then begin
ANode^.FHeight := ANode^.FRight^.FHeight + VSpace + 2 * NodeSize;
ANode^.FWidth := ANode^.FRight^.FWidth + HSpace;
end
else begin
ANode^.FHeight := Max(ANode^.FLeft^.FHeight, ANode^.FRight^.FHeight) +
VSpace + 2 * NodeSize;
ANode^.FWidth := ANode^.FLeft^.FWidth + ANode^.FRight^.FWidth + HSpace;
end;
end;
case FRootPositionStyle of
0: begin
ANode^.FX := ANode^.FWidth div 2;
end;
1: begin
end
else begin
end;
end;
end;
end;
procedure TTree.DrawTree(ANode: PNode; AX, AY: Integer; ACanvas: TCanvas);
{ pre: AX, AY are absolute coordinates of upper left-hand corner of
the bounding box;
ANode points to a binary search tree with up-to-date layout info
post: ANode has been drawn on the canvas according to its layout info }
var
HRect: TRect;
begin
if ANode^.FLeft <> nil then begin
ACanvas.MoveTo(ANode^.FX + NodeSize, ANode^.FY + NodeSize);
ACanvas.LineTo(ANode^.FLeft^.FX + NodeSize, ANode^.FLeft^.FY);
DrawTree(ANode^.FLeft, 0, 0, ACanvas);
end;
if ANode^.FRight <> nil then begin
ACanvas.MoveTo(ANode^.FX + NodeSize, ANode^.FY + NodeSize);
ACanvas.LineTo(ANode^.FRight^.FX + NodeSize, ANode^.FRight^.FY);
DrawTree(ANode^.FRight, 0, 0, ACanvas);
end;
if FDrawEmptyTrees = True then begin
end;
if FDrawBoundingBoxes = True then begin
if ANode^.FWidth <> 2 * NodeSize then begin
ACanvas.Brush.Color := clWhite;
ACanvas.Pen.Color := clBlack;
HRect.Left := 0;
HRect.Right := ANode^.FWidth - 1;
HRect.Top := ANode^.FY;
HRect.Bottom := ANode^.FY + ANode^.FHeight;
ACanvas.MoveTo(HRect.Left, HRect.Top);
ACanvas.LineTo(HRect.Right, HRect.Top);
ACanvas.LineTo(HRect.Right, HRect.Bottom);
ACanvas.LineTo(HRect.Left, HRect.Bottom);
ACanvas.LineTo(HRect.Left, HRect.Top);
end;
end;
ACanvas.Pen.Color := clBlack;
ACanvas.Brush.Color := clYellow;
HRect.Left := ANode^.FX + 1;
HRect.Right := ANode^.FX + 2 * NodeSize - 1;
HRect.Top := ANode^.FY + 1;
HRect.Bottom := ANode^.FY + 2 * NodeSize - 1;
ACanvas.Rectangle(HRect.Left - 1, HRect.Top - 1, HRect.Right + 1, HRect.Bottom + 1);
ACanvas.TextRect(HRect, ANode^.FX + 1, ANode^.FY + 1, IntToStr(ANode^.FValue));
end;