[plt-scheme] Problem to make background on a table game

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Mar 24 11:09:56 EDT 2008

At Sun, 23 Mar 2008 12:12:58 -0700 (PDT), Tiago wrote:
> Hi Scheme's users !
> 
> I started scheme this year and i would make a video poker for fun but
> the bakcground is always white :s !!!
> how can i change that ?
> 
> I try to use (make-background-region x y w h paint-callback)
> 
> but in paint-callback i use my canvas with the background and his dc
> but i have
> 
> reference to undefined identifier: dc
> 
> Little part o my code :
> 
> (define image-fond (make-object bitmap% "images/background.jpg"
> 'jpeg))
> 
> (define canvas
>   (new canvas% (parent t)
>        (paint-callback
>         (lambda (canvas dc)
>           (send dc clear)
>           (send dc draw-bitmap image-fond 0 0)))))
> 
> (define w (send t table-width))
> (define h (send t table-height))
> 
> (make-background-region 0 0 w h (canvas dc)))

I'm not clear on what you're trying to do, but in the expression

  (canvas dc)

`dc' is indeed undefined. If it were defined, you'd be applying
`canvas' as a function to the result of `dc', but `canvas' is an
object.

I think that problem you don't want to create a new canvas, and instead
you want

   (make-background-region 0 0 w h 
                           (lambda (dc x y w h)
                             (send dc draw-bitmap image-fond)))

and then you want to install the region into a table created by
`make-table.

To set the background to green before drawing the image, create the
region something like this:

   (make-background-region 
    0 0 w h 
    (lambda (dc x y w h)
      (let ([brush (send dc get-brush)])
        (send dc set-brush "green" 'solid)
        (send dc fill-rectangle x y w h)
        (send dc set-brush old-brush))
      (send dc draw-bitmap image-fond)))


Matthew



Posted on the users mailing list.