You can override on-paint to draw from a bitmap and then draw into the bitmap.
The canvas DC is access directly to the OS-provided drawing context and you add what you need as you see fit. Robby On Tuesday, June 2, 2015, John Smith <rashreportl...@gmail.com> wrote: > Matthias, > > The code you provided worked, but this whole discussion was started to > get the code *out* of the body of a function. > > Is there a way I could run your solution with > (send (send canvas get-dc) draw-rectangle 30 20 10 40) > running in the top level? > > -Luke > > On Tue, Jun 2, 2015 at 3:43 PM, Matthias Felleisen <matth...@ccs.neu.edu > <javascript:_e(%7B%7D,'cvml','matth...@ccs.neu.edu');>> wrote: > >> >> You want to override on-paint: >> >> #lang racket >> >> (require racket/gui/base) >> >> (define frame >> (new frame% >> [label "Example"] >> [width 300] >> [height 300])) >> >> (define canvas >> ;; classes are first-class >> http://www.ccs.neu.edu/home/matthias/Tmp/Class/programming-with-class/ >> (new (class canvas% >> (super-new [parent frame]) >> [define/override (on-paint) >> (send (send canvas get-dc) draw-rectangle 30 20 10 40)]))) >> >> (send frame show #t) >> >> >> >> >> On Jun 2, 2015, at 3:31 PM, "Alexander D. Knauth" <alexan...@knauth.org >> <javascript:_e(%7B%7D,'cvml','alexan...@knauth.org');>> wrote: >> >> > I have never worked with a canvas% before (I have worked with a lot of >> other racket gui stuff), so I have no idea what’s going on, but watch what >> happens with this: >> > #lang racket >> > (require racket/gui/base) >> > (define frame (new frame% >> > [label "Example"] >> > [width 300] >> > [height 300])) >> > (define canvas >> > (new canvas% [parent frame])) >> > (define dc (send canvas get-dc)) >> > (send frame show #t) >> > (sleep 1) >> > (send dc draw-rectangle 30 20 10 40) >> > >> > And even better, with this: >> > #lang racket >> > (require racket/gui/base) >> > (define frame (new frame% >> > [label "Example"] >> > [width 300] >> > [height 300])) >> > (define canvas >> > (new canvas% [parent frame])) >> > (define dc (send canvas get-dc)) >> > (send frame show #t) >> > (sleep 1) >> > (send dc draw-rectangle 30 20 10 40) >> > (sleep 2) >> > >> > >> > On Jun 2, 2015, at 3:17 PM, John Smith <rashreportl...@gmail.com >> <javascript:_e(%7B%7D,'cvml','rashreportl...@gmail.com');>> wrote: >> > >> >> Alexis, >> >> Thank you for the speedy answer. >> >> I think I correctly implemented what you described. See attached. >> >> In the new code, no error is thrown but the rectangle is not drawn. >> >> Reorderings of displaying the window and drawing the rectangle appear >> to have no effect. >> >> The only way I can get anything to show up is if I enter it in the >> REPL once the code is executed. >> >> >> >> Any idea what might be causing this? >> >> >> >> -Luke >> >> >> >> -- >> >> 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 racket-users+unsubscr...@googlegroups.com >> <javascript:_e(%7B%7D,'cvml','racket-users%2bunsubscr...@googlegroups.com');> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> >> <graphics-3.rkt> >> > >> > >> > -- >> > 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 racket-users+unsubscr...@googlegroups.com >> <javascript:_e(%7B%7D,'cvml','racket-users%2bunsubscr...@googlegroups.com');> >> . >> > 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 racket-users+unsubscr...@googlegroups.com > <javascript:_e(%7B%7D,'cvml','racket-users%2bunsubscr...@googlegroups.com');> > . > 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.