Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TFormNumericTree.DrawTree;
- const
- FirstY = 3;
- FirstSeparate = 4;
- var
- FirstCircle: TPoint;
- XDelta, YDelta: Byte;
- begin
- with pbDrawTree.Canvas do
- begin
- Brush.Color := clWhite;
- FillRect(ClientRect);
- Pen.Width := 3;
- end;
- FirstCircle.X := pbDrawTree.Width div 2 - Radius;
- FirstCircle.Y := FirstY;
- if Head <> nil then
- begin
- if (rbRoot.Checked) or not(rbLeft.Checked or rbRoot.Checked or rbRight.Checked) then
- begin
- with pbDrawTree.Canvas do
- begin
- Pen.Color := clGreen;
- Ellipse(FirstCircle.X, FirstCircle.Y, FirstCircle.X + Diametre,
- FirstCircle.Y + Diametre);
- XDelta := TextWidth(IntToStr(Head^.Key)) div 2;
- YDelta := TextHeight(IntToStr(Head^.Key)) div 2;
- TextOut(FirstCircle.X + Radius - XDelta, FirstCircle.Y + Radius - YDelta,
- IntToStr(Head^.Key));
- end;
- end;
- if (rbLeft.Checked) or not(rbLeft.Checked or rbRoot.Checked or rbRight.Checked) then
- if Head^.Left <> nil then
- DrawElement(Head^.Left, FirstCircle, FirstSeparate, -1);
- if (rbRight.Checked) or not(rbLeft.Checked or rbRoot.Checked or rbRight.Checked) then
- if Head^.Right <> nil then
- DrawElement(Head^.Right, FirstCircle, FirstSeparate, 1);
- end;
- end;
- procedure TFormNumericTree.DrawElement(CurrElement: Adrzv; PrevCircle: TPoint;
- Depth: Byte; Direction: ShortInt);
- var
- NewCircle: TPoint;
- XDelta, YDelta: Byte;
- begin
- NewCircle.X := PrevCircle.X + Direction * (CountWidth div Depth);
- NewCircle.Y := PrevCircle.Y + Distance;
- with pbDrawTree.Canvas do
- begin
- Pen.Width := 3;
- Pen.Color := clGreen;
- Brush.Style := bsClear;
- Ellipse(NewCircle.X, NewCircle.Y, NewCircle.X + Diametre, NewCircle.Y + Diametre);
- XDelta := TextWidth(IntToStr(CurrElement^.Key)) div 2;
- YDelta := TextHeight(IntToStr(CurrElement^.Key)) div 2;
- TextOut(NewCircle.X + Radius - XDelta, NewCircle.Y + Radius - YDelta,
- IntToStr(CurrElement^.Key));
- Pen.Color := clBlack;
- MoveTo(PrevCircle.X + Radius, PrevCircle.Y + Diametre);
- LineTo(NewCircle.X + Radius, NewCircle.Y);
- end;
- if CurrElement^.Left <> nil then
- DrawElement(CurrElement^.Left, NewCircle, Depth * 2, -1);
- if CurrElement^.Right <> nil then
- DrawElement(CurrElement^.Right, NewCircle, Depth * 2, 1);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement