[plt-scheme] Problems with double buffering

From: Katsmall the Wise (kela_bit at netvision.net.il)
Date: Sat Mar 8 14:38:01 EST 2003

I have the following macros define-public-draw-procs, define-draw-proc 
and class drawing-canvas% defined:

(define-macro define-draw-proc
  (lambda (name)
    `(define (,name . args)
       (set! the-log (cons (cons ',name args)
                           the-log))
       (on-paint))))

(define-macro define-public-draw-procs
  (lambda names
    (append `(begin)
            (map (lambda (name)
                   `(define-draw-proc ,name))
                 names)
            (map (lambda (name)
                   `(public ,name))
                 names)
       `((void)))))

(define drawing-canvas%
  (class canvas%
    (inherit get-dc)
    (inherit get-width)
    (inherit get-height)
    (define first-time? #t)
    (define bmp '---)
    (define bmp-dc '---)
    (define (do-first-time)
      (set! bmp (make-object bitmap% (get-width) (get-height) #f))
      (set! bmp-dc (instantiate bitmap-dc% ()))
      (send bmp-dc set-bitmap bmp)
      (set! first-time? #f))
    (define the-log empty)
    (define-public-draw-procs draw-arc
                              draw-bitmap
                              draw-bitmap-section
                              draw-ellipse
                              draw-line
                              draw-lines
                              draw-point
                              draw-polygon
                              draw-rectangle
                              draw-rounded-rectangle
                              draw-spline
                              draw-text
                              set-pen
                              set-brush)
    (define (get-log)
      the-log)
    (define (set-log! v)
      (set! the-log v)
      (on-paint))
    (define (clear-log!)
      (set! the-log empty)
      (on-paint))
    (public get-log set-log! clear-log!)
    (define/override (on-paint)
      (if first-time? (do-first-time))
      (send bmp-dc clear)
      (set! the-log (draw-on-dc bmp-dc the-log))
      (send (get-dc) draw-bitmap bmp 0 0)
      (void))
    (super-instantiate ())))

This works just fine with
    (define/override (on-paint)
      (send (get-dc) clear)
      (set! the-log (draw-on-dc (get-dc) the-log))
      (void))
But here, it shows an empty canvas%...
Now, what can be the problem?
Is my draw-bitmap syntax wrong?
Robby suggested a solution, but it's quite complicated, I'm trying to 
find a simple solution that doesn't use modules, semaphores and the 
likes (because I have *no* idea how to use them). He said he wasn't sure 
about the organization of my code, so I put the class declaration 
here... That's about it.

Katsmall the Wise
kela_bit at netvision.net.il
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20030308/ac5893ce/attachment.html>

Posted on the users mailing list.