Page 1 of 2

Seeking comments regarding canvas syntax

Posted: Fri Oct 26, 2012 3:55 pm
by Ref
************************* WARNING! Content may offend some forum users! *****************************
********************* Users who are 'canvas challenged' need read no further. **************************
I have found the syntax used to deal with canvases somewhat clunky and have come up with a slightly different one.
Was wonder if this might be of interest for future releases of Love.
Currently:

Code: Select all

canvas = love.graphics.newCanvas( width, height )
   love.graphics.setCanvas( canvas )
      love.graphics.draw( image )
      love.graphics.setColor( { 255,  0,  0, 255 } )
         love.graphics.circle( 'line', 45, 45, 20 )
      love.graphics.setColor( { 255, 255, 255, 255 } )
         love.graphics.setFont( gr.newFont( 16 ) )
         love.graphics.print( 'message', 5, 75 )
         love.graphics.rectangle( 'fill', 35, 35, 20, 20 )
      love.graphics.setColor(  {0,  0,  0, 255} )
         love.graphics.print( '2', 40, 35 )
      love.graphics.setCanvas()
if love.draw()

Code: Select all

love.graphics.draw( canvas, 100,100, angle,1,1,45,45 )
Proposed:

Code: Select all

can3 = newCanvas( image )
   can3:Color( 255,  0,  0, 255 )
      can3:circle( 'line', 45, 45, 20 )
   can3:Color( 255, 255, 255, 255 )
      can3:fontsize( 16 )
      can3:text( 'message', 5, 75 )
      can3:box( 'fill', 35, 35, 20, 20 )
   can3:Color(   0,   0,   0, 255 )
      can3:text( '2', 40, 35 )
and in love.draw()

Code: Select all

can3:draw( 100, 100, angle, 1, 1, can3.canvas:getWidth()/2, can3.canvas:getHeight()/2)
Everything is changed behind the scene by requiring the library containing the modifications.
I just find it easier to read code later especially when I didn't use 'canvas' for a name but something more descriptive.
No speed advantage (or penalty) and could be extended to use fake canvases.
Of any merit or better to leave well enough alone?
Your opinion?

Edit: Canvas.lua library updated with more love.graphics features.
Canvas:line() now permits any number of line segments to be handled in one call. Points can be individually listed or put in a table and Canvas:trianglestrip() added.
Other Canvas functions now pass all the usual love.graphics settings straight through.

Re: Seeking comments regarding canvas syntax

Posted: Fri Oct 26, 2012 4:06 pm
by Nixola
What about making available both?

Re: Seeking comments regarding canvas syntax

Posted: Fri Oct 26, 2012 4:30 pm
by Ref
Suppose I could just stick with using my library but thought that for someone just starting out, a simpler default syntax might be helpful.

Re: Seeking comments regarding canvas syntax

Posted: Sat Oct 27, 2012 1:18 pm
by T-Bone
I always use the renderTo function. I find it much easier to use, and the syntax often becomes cleaner, because you can make predefined render functions and just pass them to to renderTo which is nice. And I wouldn't want any syntax to stray too far away from the normal love.draw syntax, that's what we all know and love.

Re: Seeking comments regarding canvas syntax

Posted: Sat Oct 27, 2012 3:18 pm
by Ref
I guess the thing I like most is that an action is always associated with an object:
ball:Color()
ball:line()
ball:circle()
ball:trianglestrip() -- added feature
ball:draw()

Re: Seeking comments regarding canvas syntax

Posted: Sat Oct 27, 2012 4:43 pm
by paritybit
I tend to like object-oriented syntax and feel, but in this case there's something positive to be said for being able to draw to a canvas just like you draw to the screen.

Re: Seeking comments regarding canvas syntax

Posted: Sat Oct 27, 2012 8:12 pm
by rokit boy
can someone add fake canvas? because i dont support them.

Re: Seeking comments regarding canvas syntax

Posted: Sat Oct 27, 2012 8:23 pm
by Roland_Yonaba
rokit boy wrote:can someone add fake canvas? because i dont support them.
Thanks Xgoff!

Re: Seeking comments regarding canvas syntax

Posted: Sat Oct 27, 2012 8:56 pm
by qaisjp
it looks pretty neat, actually.

instead of object:drawc how about object:draw?

Re: Seeking comments regarding canvas syntax

Posted: Sat Oct 27, 2012 9:45 pm
by Ref
qaisjp wrote:it looks pretty neat, actually.

instead of object:drawc how about object:draw?
Done!
Replaced drawi and drawc with a single draw.
Will post after further testing (and if anyone is really interested.)
Thanks for the suggestion!