[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Is it possible to have a persistent canvas background color ?
I tried to assign a permanent background color to a canvas
calling (send (get-dc) set-background back-color)
during class initialization :
(define MainForm (make-object frame% "My program" #f ))
(define MyCanvas (class canvas% (aframe)
(inherit get-dc)
(override (on-paint (lambda () (do-paint (get-dc)))))
(sequence (super-init aframe)
(send (get-dc) set-background back-color))))
(define the-canvas (make-object MyCanvas MainForm))
I wanted to avoid to set a background color and to call clear in the paint
procedure, since (it seems to me) the canvas is automatically cleared
upon entry to the paint procedure, using a (default ? ) white color.
This is my paint code:
(define (do-paint dc )
(let*-values (((width height) (send MainForm get-client-size))
((x) (quotient (- width board-size-x) 2 ))
((y) (quotient (- height board-size-y) 2)))
(set! left-margin x
(set! top-margin y)
(send dc set-background back-color) ; !!!!
(send dc clear) ; !!!!
(paint-board dc board)))
I wanted to remove the lines marked with !!!!!
I see that with the two lines above the canvas is cleared two times: one
automatically, and a second time by my code.
The problem is that if I remove such lines, sometimes, resizing or
uncovering the frame, the background is painted with the usual dully gray
color.
Any suggestion ?
Maurizio