9 Creating Your Own Panes

9.2 Receiving input from the user

You now know enough to be able to create new classes of window which can display arbitrary graphics, but to be able to create interactive windows you need to be able to receive events. The CAPI supports this through the use of an input model, which is a mapping of events to the callbacks that should be run when they occur.

When the event callback is called, it gets passed the output-pane and the x and y coordinates of the mouse pointer at the time of the event. A few events also pass additional information as necessary; for example, keyboard events also pass the key that was pressed.

For example, we can create a very simple drawing pane by adding a callback to draw a point whenever the left button is dragged across the pane. This is done as follows:

(contain
 (make-instance
  'output-pane
  :input-model '(((:motion :button-1)
                  gp:draw-point))))

Figure 9.3 An interactive output pane

The input model above seems quite complicated, but it is just a list of event to callback mappings, where each one of these mappings is a list containing an event specification and a callback. An event specification is also a list containing keywords specifying the type of event required.


CAPI User Guide, Liquid Common Lisp Version 5.0 - 2 OCT 1997

Generated with Harlequin WebMaker