You could draw into a bitmap and then have on-paint draw that bitmap, too.

Robby

On Fri, Sep 16, 2016 at 2:53 AM, Jens Axel Søgaard
<[email protected]> wrote:
> As Alex writes the operating system (the system GUI) might erase parts of a
> window at
> any time. Therefore you need to do all your drawing from within on-paint.
>
> http://stackoverflow.com/q/16084690/23567
>
> /Jens Axel
>
>
> 2016-09-16 7:09 GMT+02:00 Alex Harsanyi <[email protected]>:
>>
>> According to the documentation for the canvas<%> interface you cannot rely
>> on the canvas not being cleared
>> (http://docs.racket-lang.org/gui/canvas___.html?q=canvas%3C%25%3E):
>>
>> Even when the canvas’s style suppresses explicit clearing of the canvas, a
>> canvas may be erased by the windowing system due to window-moving and
>> -resizing operations. For a transparent canvas, “erased” means that the
>> canvas’s parent window shows through.
>>
>> I suspect the window system clears the canvas when the frame is resized.
>>
>> Alex.
>>
>>
>> On Friday, September 16, 2016 at 9:06:01 AM UTC+8, David K. Storrs wrote:
>> > How do I draw into a canvas and have the results persist past the next
>> > call to paint-callback?
>> >
>> >
>> > Given the code below I was expecting to see:
>> >
>> > 1) A window opens with a diagonal green line on it
>> >
>> > 2) A vertical blue line appears, crossing with the green line
>> >
>> > 3) The window goes fullscreen, still showing the green and blue lines
>> >
>> >
>> >
>> > Instead what I get is:
>> >
>> > 1) A window appears with vertical blue line
>> >
>> > 2) The blue line disappears and is replaced by a diagonal green line
>> >
>> > 3) The window goes fullscreen.  Only the green line is shown.
>> >
>> >
>> > I'm guessing that what's happening is that the window opens, completes
>> > going through the script (and therefore calling the section of code that
>> > displays the blue line), then the on-paint event is triggered and erases 
>> > the
>> > canvas's dc before calling the paint callback.
>> >
>> >
>> > I tried removing the paint-callback on the theory that the default one
>> > probably just told the dc to render its content.  That made no change 
>> > except
>> > that (unsurprisingly) the green line is not painted -- the blue line is, 
>> > but
>> > promptly disappears.
>> >
>> >
>> > Assuming I'm right about what's going on, how do I draw into a dc and
>> > have the changes persist?
>> >
>> >
>> >
>> > #lang racket
>> > (require racket/gui)
>> >
>> >
>> > (define-values (w h) (get-display-size))
>> > (displayln (format "Display size (pixels): ~a x ~a" w h))  ;; 1440 x 877
>> > (define frame (new frame%
>> >                    (label "Example")
>> >                    (width w)
>> >                    (height h)
>> >                    ))
>> > (define canvas
>> >   (new canvas%
>> >        (parent frame)
>> >        (style '(border hscroll vscroll resize-corner))
>> >        (paint-callback (lambda (canvas dc)
>> >                          (send dc set-pen (send the-pen-list
>> > find-or-create-pen "green" 1 'solid))
>> >                          (send dc draw-line 0 0 1430 867)
>> >        ))))
>> >
>> > (define dc (send canvas get-dc))
>> >
>> > (send frame show #t)
>> > (send dc set-pen (send the-pen-list find-or-create-pen "blue" 1 'solid))
>> > (send dc draw-line 700 0 700 877)
>> > (send frame fullscreen #t)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> --
> Jens Axel Søgaard
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to