* * *

Author Topic: What are the last 4 parameters of the Canvas.Arc procedure  (Read 276 times)

bobonwhidbey

  • Full Member
  • ***
  • Posts: 193
What are the last 4 parameters of the Canvas.Arc procedure
« on: April 21, 2017, 06:22:41 pm »
I'm trying to draw arcs on the canvas. I got this from online Delphi help but didn't understand it.

Use Arc to draw an elliptically curved line with the current Pen. The arc traverses the perimeter of an ellipse that is bounded by the points (X1,Y1) and (X2,Y2). The arc is drawn following the perimeter of the ellipse, counterclockwise, from the starting point to the ending point. The starting point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X3,Y3). The ending point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X4, Y4).

I think the first 4 parameters are straight forward...starting and ending points. What are the next 4 parameters?  I've experimented a lot but this monkey on the keyboard hasn't figured out how to set these parameters.

For example, how would I get a sweep around the NW corner? In particular, I'm trying to provide some 3D shading for a RoundRect(ARect, 25,25);


Code: Pascal  [Select]
  1.  
  2. R := GetClientRect;   { Gets the boundaries of the current window }
  3. z := 25;
  4. Arc(R.Left + z, R.Top, R.Left, R.Top + z, z,z,0,0);  // Top    
Win10 64-bit
Lazarus 1.7
FPC 3.0.0

wp

  • Hero Member
  • *****
  • Posts: 3450
Re: What are the last 4 parameters of the Canvas.Arc procedure
« Reply #1 on: April 21, 2017, 07:01:41 pm »
Maybe you want to try this code. It draws the four corners of a rounded rect by using these 4 last parameters. Note that the corresponding start and end points, denoted P1 and P2 in my code, must be ordered in counterclickwise direction:

Code: Pascal  [Select]
  1. procedure TForm1.PaintBox2Paint(Sender: TObject);
  2. var
  3.   C, P1, P2: TPoint;
  4.   rx, ry: Integer;
  5. begin
  6.   rx := 80;
  7.   ry := 50;
  8.  
  9.   // left top corner
  10.   C := Point(100, 100);
  11.   P1 := Point(C.X, C.Y-ry);
  12.   P2 := Point(C.X-rx, C.Y);
  13.   Paintbox2.Canvas.Arc(C.X-rx, C.Y-ry, C.x+rx, C.y+ry, P1.X, P1.Y, P2.X,P2.Y);
  14.   Paintbox2.Canvas.TextOut(P1.X, P1.Y, 'start');
  15.   Paintbox2.Canvas.TextOut(P2.X, P2.Y, 'end');
  16.  
  17.   // right top corner
  18.   C := Point(300, 100);
  19.   P1 := Point(C.X+rx, C.Y);
  20.   P2 := Point(C.X, C.Y-ry);
  21.   Paintbox2.Canvas.Arc(C.X-rx, C.Y-ry, C.x+rx, C.y+ry, P1.X, P1.Y, P2.X,P2.Y);
  22.   Paintbox2.Canvas.TextOut(P1.X, P1.Y, 'start');
  23.   Paintbox2.Canvas.TextOut(P2.X, P2.Y, 'end');
  24.  
  25.   // bottom right corner
  26.   C := Point(300, 200);
  27.   P1 := Point(C.X, C.Y+ry);
  28.   P2 := Point(C.X+rx, C.Y);
  29.   Paintbox2.Canvas.Arc(C.X-rx, C.Y-ry, C.x+rx, C.y+ry, P1.X, P1.Y, P2.X,P2.Y);
  30.   Paintbox2.Canvas.TextOut(P1.X, P1.Y, 'start');
  31.   Paintbox2.Canvas.TextOut(P2.X, P2.Y, 'end');
  32.  
  33.   // bottom left corner
  34.   C := Point(100, 200);
  35.   P1 := Point(C.X-rx, C.Y);
  36.   P2 := Point(C.X, C.Y+ry);
  37.   Paintbox2.Canvas.Arc(C.X-rx, C.Y-ry, C.x+rx, C.y+ry, P1.X, P1.Y, P2.X,P2.Y);
  38.   Paintbox2.Canvas.TextOut(P1.X, P1.Y, 'start');
  39.   Paintbox2.Canvas.TextOut(P2.X, P2.Y, 'end');
  40. end;

Just add a TPaintbox to the form to test this code.
Lazarus trunk / fpc 3.0.0 / Win32

bobonwhidbey

  • Full Member
  • ***
  • Posts: 193
Re: What are the last 4 parameters of the Canvas.Arc procedure
« Reply #2 on: April 21, 2017, 11:09:33 pm »
Thank you WP, that's just what I needed.
Win10 64-bit
Lazarus 1.7
FPC 3.0.0

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus