[plt-scheme] Using a canvas% and its dc<%>

From: Robert Bruce Findler (robby at cs.uchicago.edu)
Date: Sun Mar 2 09:19:14 EST 2003

The canvas does not save the drawing state; instead it calls a callback
each time it needs to be refreshed (and there may even be suprious
refreshes). So, what you need to do is this:

     (define w (instantiate frame% ()
                 [label "Test frame"]))
     (define c (instantiate canvas% ()
                 [parent w]
                 [min-width 500]
                 [min-height 500]
                 [paint-callback (lambda (c d) (pc c d))]))
     (define p (send the-pen-list find-or-create-pen
                     "red" 2 'solid))
     
     (send w show #t)
     (define (pc c d)
       (send d set-pen p)
       (send d draw-ellipse 100 100 200 200))


At Sun, 02 Mar 2003 16:04:04 +0200, Akiva Kleiman wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> Hello,
> 
> I was trying to draw a red circle on a window. Simple task, it seemed.
> So I wrote this little batch of code.
>      (define w (instantiate frame% ()
>                  [label "Test frame"]))
>      (define c (instantiate canvas% ()
>                  [parent w]
>                  [min-width 500]
>                  [min-height 500]))
>      (define d (send c get-dc))
>      (define p (send the-pen-list find-or-create-pen
>                      "red" 2 'solid))
>      
>      (send w show #t)
>      (send d set-pen p)
>      (send d draw-ellipse 100 100 200 200)
> 
> Little window, with a canvas in it, and it draws a red circle, filled with 
> white; less then a second later, though, the entire window is filled with 
> white, and my circle is nowhere to be found.
> What could be the problem?
> 
> 
> Katsmall the Wise
> kela_bit at netvision.net.il
> 
> 



Posted on the users mailing list.