# Port Delphi Canvas Function

3 replies to this topic

### #1 ielite

ielite
• Members
• 704 posts

Posted 02 February 2013 - 12:44 AM

How to port Delphi Canvas function to SMS?

Ellipse(X1,Y1,X2,Y2);

Example:

Ellipse(x-r,y-r,x+r,y+r);

Thanks

Shane

### #2 Eric

Eric
• Moderators
• 96 posts

Posted 02 February 2013 - 08:48 AM

You can do an ellipse by applying scale to an arc, f.i.:
```   Canvas.Scale(1, 0.5);
Canvas.BeginPath;
Canvas.ArcF(200, 210, 100, 0, PI*2, false);
Canvas.Scale(1, 2);
Canvas.Stroke;
```

The second scale call restores the previous scale, and has to be done before the Stroke, otherwise the scale will also get applied to the stroke thickness.

Arc takes center coordinates followed by radius, so the scale ratio would be Abs((Y2-Y1)/(X2-X1)) if I'm not mistaken (and its inverse for the second scale call)

### #3 Eric

Eric
• Moderators
• 96 posts

Posted 02 February 2013 - 07:32 PM

I've added Ellipse to TW3Canvas for the next release, code looks like:
``` procedure TW3Canvas.Ellipse(const aRect : TRectF);
begin
var dx := aRect.Width;
var dy := aRect.Height;
var f := if dy<>0 then dx/dy else 1;
FDC.beginPath();
FDC.scale(f, 1);
FDC.arc((aRect.Right+aRect.Left)*0.5, (aRect.Top+aRect.Bottom)*0.5,
dy*0.5, 0, 2*PI, false);
FDC.scale(1/f, 1);
FDC.stroke();
end;
```

That's starting from the bounding rect, if you start from center + x/y radius, things can be further simplified.

Cipher Diaz