[plt-scheme] A question about PLT Graphics Toolkit
At Thu, 5 Mar 2009 11:38:01 +0100, Ziboon wrote:
> #lang scheme/gui
> (define f (new frame%
> (label "test") ))
>
>
> (define c (new canvas%
> (parent f)
> (min-width 200)
> (paint-callback (λ (canvas dc)
> (send dc clear)))))
>
>
> (define dc (send c get-dc))
>
> (send dc set-background (make-object color% "red"))
>
> (send dc draw-rectangle 0 0 50 50)
>
> (send f show #t )*
>
> ;--------------------------------------------------
> -------------------------------------
>
> Why set-background work : I see my canvas red; but draw-rectangle doesn't
> work there are no rectangle in my canvas.
>
> I try to delete set-background line but I don't see my rectangle.
>
> so I know if I put *(send dc draw-rectangle 0 0 50 50) *in
> paint-callback it will work .
>
> But i want draw a rectangle not directly in my canvas class.
Images drawn onto a canvas are not persistent. When the canvas is
hidden or shown by the windowing system, then the canvas is re-painted
by calling its paint callback.
Your paint callback always clears the canvas. If you move the
`draw-rectangle' call into the paint callback after the clear, then
you'll see a rectangle.
Here's a revised version of your program:
----------------------------------------
#lang scheme/gui
(define f (new frame%
(label "test")))
(define c (new canvas%
(parent f)
(min-width 200)
(paint-callback
(λ (canvas dc)
(send dc set-background (make-object color% "red"))
(send dc clear)
(send dc draw-rectangle 0 0 50 50)))))
(send f show #t )
----------------------------------------