[racket] Drawing in the Canvas from outside

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Jan 27 12:54:00 EST 2015

Do you want something like this: 

#lang racket/gui

(define frame (new frame% [label ""] [width 700] [height 500]))
(define canvas 
 (new canvas% 
      [parent frame]
      [paint-callback  
       (lambda (c dc)
         (send dc draw-line 1 1 100 100))]))
(send frame show #true)

(define (my-draw) 
  (send (send canvas get-dc) draw-line 100 100 0 200))


-- Matthias



On Jan 27, 2015, at 12:09 PM, Alexandr M wrote:

> Hello,
> 
> How can I draw the line (for example) in the canvas object defined as:
> 
> (define frame (new frame% [label ""] [width 700] [height 500]))
> (define canvas (new canvas% [parent frame]
>   ;;;; - call from outside:  [paint-callback (lambda (c dc) (send dc draw-line 1 1 10 10) )]
>   ))
> 
> by calling a function like
> 
> (define (MyDraw canvas-obj) .... (draw-line 1 1 10 10))
> 
> ?
> 
> -- 
> Best regards,
> Alex
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.