[plt-scheme] mouse event
> Can you give me some examples of mouse event in a canvas (return pos x
> and y when you click the canvas).
> Thank you.
Ziighou,
Below is an example you can paste into a DrScheme window. There's an
example from which this is derived in the MrEd manual:
http://download.plt-scheme.org/doc/204/html/mred/mred-Z-H-3.html#node_chap_2
(define *frame* (instantiate frame% ()
(label "Foo")
(width 100)
(height 100)))
(define my-canvas%
(class canvas% ; The base class is canvas%
;; Declare overrides:
(override on-event)
;; Define overriding method to handle mouse events
(define on-event (lambda (event)
(if (send event button-down? 'any)
(display (list (send event get-x)
(send event get-y))))))
;; Call the superclass initialization (and pass on all init args)
(super-instantiate ())))
;; Make a canvas that handles events in the frame
(instantiate my-canvas% (*frame*))
(send *frame* show #t)