1 CAPI Reference Entries

define-command

Macro

Summary

Thedefine-command macro defines an alias for a mouse or keyboard gesture that can be used in the input model of an output pane.

Syntax

define-command name gesture &key translator host

Description

The macrodefine-command defines an alias for a mouse or keyboard gesture that can then be used inoutput-pane's input models. The name is the name of the alias and the gesture is one of the gestures accepted byoutput-pane. The translator is a function that gets passed the arguments that would be passed to the callback, and returns a list of arguments to be passed to the callback along with the output-pane (which will be the first argument). The host indicates which platforms this gesture should apply for (it defaults to all platforms).

For a full description of the gesture syntax, see output-pane.

Examples

Firstly, here is an example of defining a command which maps onto a gesture.

(defun gesture-callback (output-pane x y)
  (capi:display-message 
   "Pressed ~S at (~S,~S)"
   output-pane x y))

(capi:define-command :select (:button-1 :press)) (capi:contain (make-instance 'capi:output-pane :input-model '((:select gesture-callback))))

Here is a more complicated example demonstrating the use of the translator to affect the arguments passed to a callback.

(capi:define-command
  :select-object (:button-1 :press)
  :translator #'(lambda (output-pane x y)
                  (let ((object
                        (capi:pinboard-object-at-position
                                        output-pane x y)))
                                  (when object
                                    (list object)))))

(defun object-select-callback (output-pane &optional object) (when object (capi:display-message "Pressed on ~S in ~S" object output-pane)))

(setq pinboard (capi:contain (make-instance 'capi:pinboard-layout :input-model '((:select-object object-select-callback)))))

(make-instance 'capi:item-pinboard-object :text "Press Me!" :parent pinboard :x 10 :y 20)

(make-instance 'capi:line-pinboard-object :parent pinboard :x 20 :y 50 :width 100 :height 100)

Example File

capi/output-panes/commands.lisp

See Also

output-pane
invoke-command
invoke-untranslated-command


CAPI Reference Manual, Liquid Common Lisp Version 5.0 - 3 OCT 1997

Generated with Harlequin WebMaker