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
:visible-min-width 50
:visible-min-height 50))
(contain
(make-instance 'ellipse-pane))
Figure 9.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. See the LispWorks 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