Jump to content
Sign in to follow this  
Mason Wheeler

Ellipse does nothing

Recommended Posts

I'm trying to draw a circle on a Tw3Canvas.  First off, there's no Circle method, which kind of surprises me.  But an ellipse should work... right?

 

 
const RADIUS = 12.0; 
begin 
  canvas.Ellipse(FX - RADIUS, FY - RADIUS, FX + RADIUS, FY + RADIUS); 
end; 

 

This ends up drawing nothing at all.  If I change the call to canvas.FillBounds and keep the same params, I get a square, exactly as expected.  The behavior is the same on Firefox and Chrome.

 

Any idea what's going wrong here?

Share this post


Link to post
Share on other sites

The "A Smart Book Demos", "Graphics" project contains demo for painting circles, arcs, and ellipses.

 

 
procedure TPaintForm.PaintCircle; 
begin 
  ClearCanvas; 
  // circle 
  Canvas.StrokeStyle := "#000000"; 
  Canvas.FillStyle := "#FFFF00"; 
  Canvas.BeginPath; 
  Canvas.ArcF(200,200,100,0,PI*2,true); 
  Canvas.ClosePath; 
  Canvas.Stroke; 
  Canvas.Fill; 

  // circle segment 
  Canvas.FillStyle := "#00FFFF"; 
  Canvas.BeginPath; 
  Canvas.ArcF(400,300,50,0,PI,true); 
  Canvas.ClosePath; 
  Canvas.Stroke; 

  // arc 
  Canvas.FillStyle := "#FF00FF"; 
  Canvas.BeginPath; 
  Canvas.ArcF(300,400,50,PI/2,3*PI/2,true); 
  Canvas.Stroke; 

  //ellipse 
  Canvas.FillStyle := "#808080"; 
  Canvas.BeginPath; 
  Canvas.Ellipse(50,350,300,400); 
  Canvas.ClosePath; 
  Canvas.Stroke; 
  Canvas.Fill; 
end; 

Share this post


Link to post
Share on other sites

Thanks.  The Fill call was what I was missing.

 

Also, the codegen for the call is very strange.  It comes out like this:

 

TW3Canvas.Ellipse(Canvas$3,$Check(Self," in TMyObject.Draw [line: 55, column: 18, file: Unit1]").FX-12,$Check(Self," in TMyObject.Draw [line: 55, column: 31, file: Unit1]").FY-12,$Check(Self," in TMyObject.Draw [line: 55, column: 44, file: Unit1]").FX+12,$Check(Self," in TMyObject.Draw [line: 55, column: 57, file: Unit1]").FY+12);

 

I can understand calling Check--there's a compiler option that enables it--but can't it be a little smarter about it than that?

Share this post


Link to post
Share on other sites

The Check() option is really a heavy-handed debugging option, and shouldn't be used in final production code.

 

While in that particular case it could be "optimized", there is no real point as the Check() will still have significant performance impacts in many situations where it couldn't be optimized away.

 

Also as an alternative to TW3Canvas if you want to minimize overhead, you can use the JCanvasRenderingContext2D class directly (you'll lose helpers and utility methods, but that'll be compiled straight to the metal, with only compile-time type checks)

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  

×