11.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 creates a new subclass of drawn-pinboard-object that displays an ellipse.

(defun draw-ellipse-pane (gp pane
                             x y
                             width height)
  (with-geometry pane
    (let ((x-radius
           (1- (floor %width% 2)))
           (1- (floor %height% 2))))
       (1+ (+ %x% x-radius))
       (1+ (+ %y% y-radius))
       x-radius y-radius
       :filled t
       (if (> x-radius y-radius) 
(defclass ellipse-pane
   :display-callback 'draw-ellipse-pane
   :visible-min-width 50
   :visible-min-height 50))
 (make-instance 'ellipse-pane)
 :best-width 200
 :best-height 100)

Figure 11.7 An ellipse-pane class

The with-geometry macro is used to set the size and position, or geometry, of the ellipse drawn by the draw-ellipse-pane function. The fill color depends on the radii of the ellipse - try resizing the window to see this. See the LispWorks CAPI Reference Manual for more details of drawn-pinboard-object .

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.

  (loop for i below 9
        (make-instance 'ellipse-pane))
  :columns 3)
 :best-width 300
 :best-height 400)

Figure 11.8 Nine ellipse-pane instances in a layout


LispWorks CAPI User Guide (Windows version) - 17 Mar 2008