본문 바로가기
Application/Delphi Lecture

How do I create a rounded rect

by 현이빈이 2008. 8. 13.
반응형
function CreateRoundRectangle(rectangle: TGPRect;
  radius: integer): TGPGraphicsPath;
var
  path : TGPGraphicsPath;
  l, t, w, h, d : integer;
begin
  path := TGPGraphicsPath.Create;
  l := rectangle.X;
  t := rectangle.y;
  w := rectangle.Width;
  h := rectangle.Height;
  d := radius shl 1; // divide by 2

  // the lines beween the arcs are automatically added by the path
  path.AddArc(l, t, d, d, 180, 90); // topleft
  path.AddArc(l + w - d, t, d, d, 270, 90); // topright
  path.AddArc(l + w - d, t + h - d, d, d, 0, 90); // bottomright
  path.AddArc(l, t + h - d, d, d, 90, 90); // bottomleft
  path.CloseFigure();
  result := path;
end;
반응형