Reputation: 297
I am writing a tic-tac-toe game in plt-scheme as my AI course project. The idea for gui is a grid with 9 boxes, each with a canvas, using panes ... When the user click on a canvas, 'X' or 'O' will be drawn accordingly ...
The question is how can I catch mouse click event on canvas? I found out I need to use on-event, but still don't know how? Any clues?
Upvotes: 1
Views: 721
Reputation: 1
I got all mouse and keypad command for uses anywhere here.
(define my-canvas%
(class canvas%
(define/override (on-event event)
(and
(send test reader (list (number->string (send event get-x))
(number->string (send event get-y)) ))
(send test reader (list (send event get-event-type)))))
(define/override (on-char event)
(define pressed (send event get-key-code))
(if (char? pressed) (send test reader (list (make-string 1 pressed))) '()))
(super-new)))
(define tester%
(class object%
(super-new)
(define command '())
(define/public (reader x)
(and (set! command x)
(display x))
)
(define/public (outer)
command)
))
Upvotes: 0
Reputation: 297
Ok, I got it ...
(define canvas-box%
(class canvas%
(define/override (on-event e)
(when (equal? (send e get-event-type) 'left-down) (foobar-callback)))
(super-new)))
Upvotes: 2