All Manuals > Common Lisp Interface Manager 2.0 User's Guide > Chapter 2 Drawing Graphics > 2.6 Drawing with LispWorks Graphics Ports

NextPrevUpTopContentsIndex

2.6.2 API for Drawing with Graphics Ports

with-gp-drawing-to-sheet[Macro]	

Arguments: (gp-port sheet &key x y width height background) &body body

perform-gp-drawing[Function]	

Arguments: sheet gp-drawing-func &key x y width height background

Summary: Binds gp-port to a graphics port, executes the body , and then copies the drawing on the port to the screen. x and y specify the position in the sheet to which the contents of the port are copied. They both default to 0. width and height specify the dimensions of the port. width defaults to the width of the sheet minus x , and height defaults to the height of the sheet minus y . background specifies the background of the port. It is a graphics port color specification, rather than a CLIM ink. See "The Color System" chapter in the CAPI User Guide and Reference Manual for details. Note that named colors can be specified by keywords like :red , :green and so on. background defaults to :white . with-gp-drawing-to-sheet creates the port using width and height and background , binds gp-port to it and evaluates the body . When the body finishes, it copies the contents to the sheet at the position specified by x and y . perform-gp-drawing is equivalent to:

(with-gp-drawing-to-sheet
 (gp-port sheet :x x :y y 
	:width width :height height
	:background background)
 (funcall gp-drawing-func gp-port))

In general, body should contain calls to graphics ports drawing functions like gp:draw-string , with the port argument gp-port .

Drawings into the port can exceed the dimensions. Any drawing beyond width and height is ignored.

The coping completely overwrites the contents of the sheet in the rectangle specified by x , y , width and height .

perform-gp-drawing is especially convenient when drawing something that also needs to be printed, because gp-drawing-func can also be used to do the drawing to a capi:printer-port .

In this example draw-some-strings draws a string with fonts in different sizes using gp:draw-string . This is purely a graphics ports function, without any relation to CLIM, and can be used to draw into a capi:output-pane , or to a capi:printer-port :

(defun draw-some-strings(port)
  (dotimes (x 10)
    (let ((font 
           (gp:find-best-font
            port 
            (gp:make-font-description :size (+ 6 (* x 3))))))
      (gp:draw-string port "A string " 30 (+ 40 (* x 30))
                      :font font))))

In this example we use draw-some-strings to draw into a CLIM stream (using *standard-output* here). Note that only the first few strings are visible, because we restrict the drawing to 100x100. The background is yellow and we also draw a pink circle under the strings:

(clim:with-gp-drawing-to-sheet (port *standard-output*
                                     :x 0 :y 100
                                     :width 100 :height 100
                                     :background :yellow)
  (gp:draw-circle port 50 50  50 :foreground :pink :filled t)
  (draw-some-strings port))

In this example perform-gp-drawing draws into a CLIM stream (again using *standard-output* ). The drawing is offset by 100 in the x direction, but fills the full height:

(clim:perform-gp-drawing *standard-output*
                         'draw-some-strings
                         :x 100)

This form sends the same drawing to a printer specified by my-printer :

(capi:with-print-job (printer-port :printer my-printer)
  (draw-some-strings printer-port))

See also draw-gp-pixmap-to-sheet , draw-gp-image-to-sheet and perform-gp-drawing .

draw-gp-pixmap-to-sheet[Function]	

Arguments: sheet pixmap &key to-x to-y to-width to-height from-x from-y

Summary: Draws a graphics ports pixmap to the sheet . That is, it copies the contents of the pixmap to the sheet .

from-x and from-y specify the origin in the pixmap for the copying. They both default to 0.

to-x , to-y , to-width and to-height specify a rectangle in the sheet into which the drawing occurs. to-x and to-y both default to 0. to-width defaults to the width of the pixmap minus from-x , and to-height defaults to the height of the pixmap minus from-y .

pixmap must be a "compatible pixmap", which means it was made with :drawing-mode :compatible , or is owned by a port that was itself made with :drawing-mode :compatible .

See also draw-gp-image-to-sheet , with-gp-drawing-to-sheet and perform-gp-drawing .

draw-gp-image-to-sheet[Function]	

Arguments: sheet image &key to-x to-y to-width to-height from-x from-y from-width from-height

Summary: Draws a graphics ports image to the sheet .

from-x , from-y , from-width and from-height specify a rectangle in the image to draw.

from-x and from-y both default to 0. from-width defaults to the width of the image minus from-x , and from-height defaults to the height of the image minus from-y .

to-x , to-y , to-width and to-height specify a rectangle in the sheet into which the drawing occurs. to-x and to-y both default to 0. to-width and to-height default to from-width and from-height respectively.

If from-width ( from-height ) is not equal to to-width ( to-height ), the image is scaled horizontally by to-width / from-width (vertically by to-height / from-height ).

Note that image must be a BMP image, which means that you cannot draw JPG or PNG images. If you need to draw these formats, draw to a pixmap and use draw-gp-pixmap-to-sheet with the pixmap.

See also draw-gp-pixmap-to-sheet , with-gp-drawing-to-sheet and perform-gp-drawing .


Common Lisp Interface Manager 2.0 User's Guide - 3 Mar 2015

NextPrevUpTopContentsIndex