[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Event handling



>I just wrote a simple program for event handling as follows:
>
>(defclass my-window (window)() )
>
>(defmethod view-click-event-handler
>     ((window my-window) where)
>     (print (point-string where)))
>
>(defun foo()
>     (make-instance 'my-window))
>
>(defun toy()
>     (foo)
>    ;system should wait for events from the user
>     (print "ok"))
>
>(toy)
>
>After running the function toy, the system creates not only a window,
>but also shows the "ok" in the Listener.  My purpose of the program
>is to first create a window, then wait for events from the user, and
>finally print the "ok" in the Listener.  Can anyone fix my problem?
>Thanks in advance.
>
>jipan@gmuvax2.gmu.edu

Everything should be clear if you understand the model of event handling
MCL uses (see the section Events in the docs).

As a very trivial example of events handling for a chess program:

(defmethod view-click-EVENT-HANDLER ; all the handling of events relative
     ((window chess-window) where)  ; to the window has to be done in here
  (multiple-value-bind (h v)
                       (convert-local-coordinates-to-chess-coordinates
where)
    (if (or (< h 0) (> h 7)
            (< v 0) (> v 7))
        (ed-beep)
      (play-the-chess-move window h v))))

If fact, dialog items that you could put on your window, are just more
specialized ways of handling window events.

Hope this makes sense.

Guillaume Cartier
LACIM, Universite du Quebec a Montreal.
Bureau: (514) 987-4290
E-Mail: cartier@math.uqam.ca