Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.45 KB | None | 0 0
  1. procedure TFormNumericTree.DrawTree;
  2. const
  3.    FirstY = 3;
  4.    FirstSeparate = 4;
  5. var
  6.    FirstCircle: TPoint;
  7.    XDelta, YDelta: Byte;
  8. begin
  9.    with pbDrawTree.Canvas do
  10.    begin
  11.       Brush.Color := clWhite;
  12.       FillRect(ClientRect);
  13.       Pen.Width := 3;
  14.    end;
  15.    FirstCircle.X := pbDrawTree.Width div 2 - Radius;
  16.    FirstCircle.Y := FirstY;
  17.    if Head <> nil then
  18.    begin
  19.       if (rbRoot.Checked) or not(rbLeft.Checked or rbRoot.Checked or rbRight.Checked) then
  20.       begin
  21.          with pbDrawTree.Canvas do
  22.          begin
  23.             Pen.Color := clGreen;
  24.             Ellipse(FirstCircle.X, FirstCircle.Y, FirstCircle.X + Diametre,
  25.                FirstCircle.Y + Diametre);
  26.             XDelta := TextWidth(IntToStr(Head^.Key)) div 2;
  27.             YDelta := TextHeight(IntToStr(Head^.Key)) div 2;
  28.             TextOut(FirstCircle.X + Radius - XDelta, FirstCircle.Y + Radius - YDelta,
  29.                IntToStr(Head^.Key));
  30.          end;
  31.       end;
  32.       if (rbLeft.Checked) or not(rbLeft.Checked or rbRoot.Checked or rbRight.Checked) then
  33.          if Head^.Left <> nil then
  34.             DrawElement(Head^.Left, FirstCircle, FirstSeparate, -1);
  35.       if (rbRight.Checked) or not(rbLeft.Checked or rbRoot.Checked or rbRight.Checked) then
  36.          if Head^.Right <> nil then
  37.             DrawElement(Head^.Right, FirstCircle, FirstSeparate, 1);
  38.    end;
  39. end;
  40.  
  41. procedure TFormNumericTree.DrawElement(CurrElement: Adrzv; PrevCircle: TPoint;
  42.    Depth: Byte; Direction: ShortInt);
  43. var
  44.    NewCircle: TPoint;
  45.    XDelta, YDelta: Byte;
  46. begin
  47.    NewCircle.X := PrevCircle.X + Direction * (CountWidth div Depth);
  48.    NewCircle.Y := PrevCircle.Y + Distance;
  49.    with pbDrawTree.Canvas do
  50.    begin
  51.       Pen.Width := 3;
  52.       Pen.Color := clGreen;
  53.       Brush.Style := bsClear;
  54.       Ellipse(NewCircle.X, NewCircle.Y, NewCircle.X + Diametre, NewCircle.Y + Diametre);
  55.       XDelta := TextWidth(IntToStr(CurrElement^.Key)) div 2;
  56.       YDelta := TextHeight(IntToStr(CurrElement^.Key)) div 2;
  57.       TextOut(NewCircle.X + Radius - XDelta, NewCircle.Y + Radius - YDelta,
  58.          IntToStr(CurrElement^.Key));
  59.       Pen.Color := clBlack;
  60.       MoveTo(PrevCircle.X + Radius, PrevCircle.Y + Diametre);
  61.       LineTo(NewCircle.X + Radius, NewCircle.Y);
  62.    end;
  63.    if CurrElement^.Left <> nil then
  64.       DrawElement(CurrElement^.Left, NewCircle, Depth * 2, -1);
  65.    if CurrElement^.Right <> nil then
  66.       DrawElement(CurrElement^.Right, NewCircle, Depth * 2, 1);
  67. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement