Jump to content
Sign in to follow this  

Port Delphi Canvas Function

Recommended Posts

You can do an ellipse by applying scale to an arc, f.i.:

  Canvas.Scale(1, 0.5); 
  Canvas.ArcF(200, 210, 100, 0, PI*2, false); 
  Canvas.Scale(1, 2); 

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)

Share this post

Link to post
Share on other sites

I've added Ellipse to TW3Canvas for the next release, code looks like:

procedure TW3Canvas.Ellipse(const aRect : TRectF); 
   var dx := aRect.Width; 
   var dy := aRect.Height; 
   var f := if dy<>0 then dx/dy else 1; 
   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); 


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

Share this post

Link to post
Share on other sites

I actually started on a TCanvas wrapper last week to help emulate the old VCL. It will just consume the standard canvas (e.g: FMyCanvas:=TVCLCanvas.Create(Canvas) ). Also thinking about porting over some other canvas types, like CODEF - which is really cool

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this