[racket] how can I get canvas's x and y? when it is scrolled?

From: 김태윤 (kty1104 at gmail.com)
Date: Wed Jun 19 00:47:56 EDT 2013

how can I get image's x and y?

in short, the scrollbar was moved so I can see image's area whose x
and y are from 90, 90 to 290, 290.

at this moment, I move mouse to upper-left corner of the window. and get 0,0.

but I want to get 90,90.

how can I do this?


here my code
 #lang racket/gui
(require racket/draw)

(define f
  (new frame%
       [label "hey"]
       [width 200]
       [height 200]))

(define img (read-bitmap "some_image.png"))
(define img-w (send img get-width))
(define img-h (send img get-height))

(define (pcb c dc)
  (send dc draw-bitmap img 0 0))

(define my_c%
  (class canvas%
    (define/override (on-event e)
      (printf "x: ~a y: ~a \n" (send e get-x) (send e get-y)))

(define c (new my_c%
               [parent f]
               [style (list 'hscroll 'vscroll)]
               [paint-callback pcb]))

(send c init-auto-scrollbars img-w img-h 0 0)

(send f show #t)

Posted on the users mailing list.