Jump to content


Photo

Ellipse does nothing


  • Please log in to reply
5 replies to this topic

#1 Mason Wheeler

Mason Wheeler
  • Members
  • 39 posts

Posted 09 March 2014 - 04:02 AM

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?
  • MiltonOi likes this

#2 gabr42

gabr42

    Boss

  • Administrators
  • 192 posts

Posted 09 March 2014 - 04:22 PM

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; 


#3 Mason Wheeler

Mason Wheeler
  • Members
  • 39 posts

Posted 10 March 2014 - 12:12 AM

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?

#4 gabr42

gabr42

    Boss

  • Administrators
  • 192 posts

Posted 10 March 2014 - 12:19 PM

While I do agree that the codegen could be smarter, this is not currently the focus of the development team. In the short term, those Check(s) will probably stay as they are now.

#5 Eric

Eric
  • Moderators
  • 96 posts

Posted 10 March 2014 - 12:36 PM

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)

#6 Mason Wheeler

Mason Wheeler
  • Members
  • 39 posts

Posted 10 March 2014 - 11:03 PM

I understand that it's not meant to be used in production code.  That was never my intention.  My complaint is that it really gets in the way of debugging!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users