[racket] Questions about the Canvas

From: Hillary Ryan (hillary.ryan at yale.edu)
Date: Wed Jun 13 15:16:53 EDT 2012

Hello,

I have been working on a racket GUI recently. So far it's been wonderfully
smooth sailing, especially compared to Java. I had a couple of questions
about the canvas object. Any help would be wonderful.

Many Thanks,
Hillary

Questions:
1)
Why does this work?
(define canvas (new canvas% [parent window] [paint-callback (lambda (canvas
dc) (draw canvas dc))]))

But this doesn't
(define canvas (new canvas% [parent window] [paint-callback  (draw canvas
dc)]))

It seems that in both cases the paint-callback is being set to a 2-arity
procedure. However, in the second case the window doesn't update unless
draw is called from REPL.

2)
I have a bunch (two dozen) of little objects that I would like to be able
to draw on one canvas. At the moment I am passing each object the drawing
context which comes from the canvas, letting the object draw itself and
then moving onto the next object. By this method, if one object changes I
have to redraw the entire canvas. I know in Java you can redraw only part
of the canvas. Is there a standard method in Racket for drawing a bunch of
objects on a canvas efficiently?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120613/1d989a31/attachment.html>

Posted on the users mailing list.