9.3 Creating graphical objects

9.3.2 An example pinboard object

To create your own pinboard objects, the class drawn-pinboard-object is provided, which is a pinboard-object that accepts a display-callback to display itself. The following example uses this class to create a new class of pinboard-object that displays an ellipse.

(defun draw-ellipse-pane (gp pane
                          x y
                          width height)
  (with-geometry pane
    (let ((x-radius
           (floor %width% 2))
          (y-radius
           (floor %height% 2)))
      (gp:draw-ellipse 
       gp
       (+ %x% x-radius)
       (+ %y% y-radius)
       x-radius y-radius))))

(defclass ellipse-pane (drawn-pinboard-object) () (:default-initargs :display-callback 'draw-ellipse-pane :min-width 50 :min-height 50))

(contain (make-instance 'ellipse-pane))

Figure 9.7 An ellipse-pane class

Thewith-geometry macro is used to set the size and position, or geometry, of the ellipse drawn by thedraw-ellipse-pane function. See the CAPI Reference Manual for more details.

Now that you have a new ellipse-pane class, you can create instances of them and place them inside layouts. For instance, the example below creates nine ellipse panes and place them in a three by three grid.

(contain
 (make-instance
  'grid-layout
  :description
  (loop for i below 9
        collect
        (make-instance 'ellipse-pane))
  :columns 3))

Figure 9.8 Nine ellipse-pane classes in a layout


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

Generated with Harlequin WebMaker