See: Event Lists.
See: Ogre.
The Lush interpreter provides a centralized machanism for queuing and
dispatching events. Events are represented by arbitrary non-empty lists.
The event lists discussed in section "Event Lists" are merely the events
generated by the window system.
Function sendevent is the simplest way
to generate an event. Besides the event itself, function
sendevent requires an "event handler", that is to say an
arbitrary non null lisp object. The event handler can be merely used as
a key to identify the target of the event. Yet it is strongly suggested
that the event handler should be a lisp object that recognizes method
handle .
Besides function sendevent , events
can be generated by defining a timer using
create-timer , or by associating an event handler with a
graphic window using function set-event-handler
.
Although events can be polled manually using functions
testevent , checkevent ,
and waitevent , it is often more
practical to let Lush dispatch the events automatically. Lush silently
polls the event queue whenever it is waiting for input on the console.
All available events are dispatched by calling the method
handle of their event handler with the event itself as a
single argument. These automatic call allow the implementation of
asynchronous graphic interfaces, like those implemented by the Ogre
library.
3.17.0.0. (set-event-handler w h)
|
[DX] |
See: Ogre.
Associates the event handler h with
window w . The new event handler for
window w replaces the old one.
Providing the empty list as argument h
simply removes the previous event handler without defining a new one.
Once an event handler has been attached to a window, graphics events
occuring on that window, like mouse or keyboard interaction, are posted
on the lush event queue and dispatched as usual.
3.17.0.1. (create-timer handler delay [interval])
|
[DX] |
See: Timers
See: (new Timer [ delay [
interval ]] [ callback ])
Creates a timer that generates an event (timer
timerid) for handler handler
every interval milliseconds after an
initial delay of delay milliseconds.
Specifying an interval of zero milliseconds creates a one shot timer
that fires only once after delay
milliseconds. This function returns a timer identifier that can be used
with function kill-timer . Section
"Timers" describe a more convenient way to define a timer.
3.17.0.2. (create-timer-absolute handler date)
|
[DX] |
Creates a timer that generates an event (timer
timerid) for handler handler
at the specified date. Dates are real numbers representing a number of
seconds spent since a system dependent date.
3.17.0.3. (kill-timer timerid)
|
[DX] |
See: (create-timer handler
delay [ interval ])
Destroys the timer timerid .
3.17.0.4. (sendevent handler event)
|
[DX] |
Posts and event event with event
handler handler . Argument
event must be a non empty list. Argument
handler must be a non null object. It is customary (but not
mandatory) to make sure that the event handler recognizes method
handle for processing automatically displatched events.
3.17.0.5. (sendevent x y)
|
[DX] |
This obsolete form of sendevent takes two integer arguments and posts
event (sendevent x y) to
the event handler associated with the current window.
3.17.0.6. (testevent [h])
|
[DX] |
Function testevent returns the first
event available for handler h without
removing the event from the queue. When argument
h is omitted, function testevent
implicitely uses the event handler associated with the current window.
Function testevent works differently
when argument h is the empty list. It
returns the event handler associated with the first pending event, or
the empty list if no events are pending.
When no suitable event is pending, function
testevent returns the empty list without waiting.
3.17.0.7. (checkevent [h])
|
[DX] |
Function checkevent returns the first
event available for handler h and
removes it from the queue. When argument h
is omitted, function checkevent
implicitely uses the event handler associated with the current window.
Function checkevent works differently
when argument h is the empty list. It
returns the event handler associated with the first pending event,
without modifying the queue.
When no suitable event is pending, function
checkevent returns the empty list without waiting.
3.17.0.8. (waitevent)
|
[DX] |
Function waitevent first tests the
event queue and returns the event handler associated with the first
pending event. Otherwise function waitevent
waits until an event occurs and returns the associated event handler.
3.17.0.9. (process-pending-events)
|
[DX] |
Function process-pending-events
dispatches all pending events. While there are pending events, function
process-pending-events removes the first event from the
queue, checks whether the associated event handler recognizes method
handle , and, calls method handle
of the event handler object with the event as single argument.
Function process-pending-events
returns when no events are available on the event queue. Function
process-pending-events is implicitely called whenever events
become available while Lush is waiting for user input on the console.
Long Lush programs can call this function from time to time in order to
maintain event driven graphic interface active during the execution of
the program.
3.17.0.10. (==> eventhandler handle event)
|
[MSG] |
See: (process-pending-events)
Method handle of event handler objects
is automatically called when lush dispatches events, either because it
is waiting for user input on the console, or because function
process-pending-events has been called.
3.17.1.0. (new Timer [delay [interval]] [callback])
|
[CLASS] |
Creates a new timer that fires every interval
milliseconds after an initial delay of delay
milliseconds. Specifying an interval of zero milliseconds creates a one
shot timer that fires only once after delay
milliseconds.
A timer event is posted into the lush event queue when the timer fires.
This event is dispatched when lush waits for user input or when function
process-pending-events is called. Dispatching the timer event
causes function callback to be called
with the timer as a single argument.
Example:
? (new timer 1000 (lambda(c) (printf "One second\n"))))))
Timers only post events if the previously posted timer events have been
dispatched timely. This feature prevents the event queue to grow very
large when lush is not able to dispatch the events fast enough.
3.17.1.1. (==> timer set delay [interval])
|
[MSG] |
Sets the timer delay delay and
periodicity interval expressed in
milliseconds. Passing the empty list as argument
delay cancels the timer.
3.17.1.2. (==> timer setcall callback)
|
[MSG] |
Sets the timer callback function to callback
. This function is called whenever lush dispatches events generated by
this timer.