12.5 Drawing Functions

  • 12.5.1 Basic Drawing Functions
  • 12.5.2 Compound Drawing Functions
  • Each drawing function takes keyword arguments allowing any drawing option or suboption to be supplied separately in the call to the function. In some implementations of CLIM, the drawing functions may ignore drawing options that are irrelevant to that function; in other implementations, an error may be signalled. See Chapter 10 for a more complete discussion of the drawing options. An error will be signalled if any drawing function is called on a sheet that is mute for output. [annotate]

    While the functions in this section are specified to be called on mediums, they can also be called on sheets and streams. CLIM implementations will typically implement the method on a medium, and write a "trampoline" on the various sheet and stream classes that trampolines to the medium. [annotate]

    Implementation note: The drawing functions are all specified as ordinary functions, not as generic functions. This is intended to ease the task of writing compile-time optimizations that avoid keyword argument taking, check for such things as constant drawing options, and so forth. If you need to specialize any of the drawing methods, use define-graphics-method. [annotate]

    Each drawing function comes in two forms, a "structured" version and a "spread" version. The structured version passes points, whereas the spread version passes coordinates. See Section 2.3 for more information on this. [annotate]

    Any drawing functions may create an output record that corresponds to the figure being drawn. See Chapter 15 for a complete discussion of output recording. During output recording, none of these functions capture any arguments that are points, point sequences, coordinate sequences, or text strings. Line styles, text styles, transformations, and clipping regions may be captured. [annotate]

    Note that the CLIM specification does not specify more complex shapes such as cubic splines and Bézier curves. These are suitable candidates for extensions to CLIM. [annotate]

    Note: Quadratic and Cubic Beziers seem notably lacking in 2020. [edit]-- Matt 2020-01-30 19:12Z
     

    12.5.1 Basic Drawing Functions

    draw-point  medium point &key ink clipping-region transformation line-style line-thickness line-unit [Function]
    draw-point*  medium x y &key ink clipping-region transformation line-style line-thickness line-unit [Function]
              

    These functions (structured and spread arguments, respectively) draw a single point on the medium medium at the point point (or the position (x,y)). [annotate]

    The unit and thickness components of the current line style (see Chapter 10) affect the drawing of the point by controlling the size on the display device of the "blob" that is used to render the point. [annotate]

    [annotate]

    draw-points  medium points &key ink clipping-region transformation line-style line-thickness line-unit [Function]
    draw-points*  medium position-seq &key ink clipping-region transformation line-style line-thickness line-unit [Function]
              

    These functions (structured and spread arguments, respectively) draw a set of points on the medium medium. points is a sequence of point objects; position-seq is a sequence of coordinate pairs, which are real numbers. It is an error if position-seq does not contain an even number of elements. [annotate]

    Ignoring the drawing options, these functions exist as equivalents to [annotate]

    (map nil #`(lambda (point) (draw-point medium point)) points)
    

    and [annotate]

    (do ((i 0 (+ i 2)))
        ((= i (length position-seq)))
      (draw-point* medium (elt position-seq i) (elt position-seq (+ i 1))))
    

    for convenience and efficiency. [annotate]

    [annotate]

    draw-line  medium point1 point2 &key ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
    draw-line*  medium x1 y1 x2 y2 &key ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
              

    These functions (structured and spread arguments, respectively) draw a line segment on the medium medium from the point point1 to point2 (or from the position (x1,y1) to (x2,y2)). [annotate]

    The current line style (see Chapter 10) affects the drawing of the line in the obvious way, except that the joint shape has no effect. Dashed lines start dashing at point1. [annotate]

    [annotate]

    draw-lines  medium points &key ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
    draw-lines*  medium position-seq &key ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
              

    These functions (structured and spread arguments, respectively) draw a set of disconnected line segments. points is a sequence of point objects; position-seq is a sequence of coordinate pairs. It is an error if position-seq does not contain an even number of elements. [annotate]

    Ignoring the drawing options, these functions are equivalent to [annotate]

    (do ((i 0 (+ i 2)))
        ((= i (length points)))
      (draw-line medium (elt points i) (elt points (1+ i))))
    

    and [annotate]

    (do ((i 0 (+ i 4)))
        ((= i (length position-seq)))
      (draw-line* medium (elt position-seq i)       (elt position-seq (+ i 1))
                         (elt position-seq (+ i 2)) (elt position-seq (+ i 3))))
    

    [annotate]

    draw-polygon  medium point-seq &key (filled t) (closed t) ink clipping-region transformation line-style line-thickness line-unit line-dashes line-joint-shape line-cap-shape [Function]
    draw-polygon*  medium coord-seq &key (filled t) (closed t) ink clipping-region transformation line-style line-thickness line-unit line-dashes line-joint-shape line-cap-shape [Function]
              

    Draws a polygon or polyline on the medium medium. When filled is false, this draws a set of connected lines, otherwise it draws a filled polygon. If closed is true (the default) and filled is false, it ensures that a segment is drawn that connects the ending point of the last segment to the starting point of the first segment. The current line style (see Chapter 10) affects the drawing of unfilled polygons in the obvious way. The cap shape affects only the "open" vertices in the case when closed is false. Dashed lines start dashing at the starting point of the first segment, and may or may not continue dashing across vertices, depending on the window system. [annotate]

    point-seq is a sequence of point objects; coord-seq is a sequence of coordinate pairs. It is an error if coord-seq does not contain an even number of elements. [annotate]

    If filled is true, a closed polygon is drawn and filled in. In this case, closed is assumed to be true as well. [annotate]

    [annotate]

    draw-rectangle  medium point1 point2 &key (filled t) ink clipping-region transformation line-style line-thickness line-unit line-dashes line-joint-shape [Function]
              

    [annotate]

    draw-rectangle*  medium x1 y1 x2 y2 &key (filled t) ink clipping-region transformation line-style line-thickness line-unit line-dashes line-joint-shape [Function]
              

    Draws either a filled or unfilled rectangle on the medium medium that has its sides aligned with the coordinate axes of the native coordinate system. One corner of the rectangle is at the position (x1,y1) and the opposite corner is at (x2,y2). The arguments x1, y1, x2, and y1 are real numbers that are canonicalized in the same way as for make-bounding-rectangle. filled is as for draw-polygon*. [annotate]

    The current line style (see Chapter 10) affects the drawing of unfilled rectangles in the obvious way, except that the cap shape has no effect. [annotate]

    [annotate]

    draw-rectangles  medium points &key ink clipping-region transformation line-style line-thickness line-unit line-dashes line-joint-shape [Function]
    draw-rectangles*  medium position-seq &key ink clipping-region transformation line-style line-thickness line-unit line-dashes line-joint-shape [Function]
              

    These functions (structured and spread arguments, respectively) draw a set of rectangles. points is a sequence of point objects; position-seq is a sequence of coordinate pairs. It is an error if position-seq does not contain an even number of elements. [annotate]

    Ignoring the drawing options, these functions are equivalent to [annotate]

    (do ((i 0 (+ i 2)))
        ((= i (length points)))
      (draw-rectangle medium (elt points i) (elt points (1+ i))))
    

    and [annotate]

    (do ((i 0 (+ i 4)))
        ((= i (length position-seq)))
      (draw-rectangle* medium (elt position-seq i)       (elt position-seq (+ i 1))
                              (elt position-seq (+ i 2)) (elt position-seq (+ i 3))))
    

    [annotate]

    draw-ellipse  medium center-pt radius-1-dx radius-1-dy radius-2-dx radius-2-dy &key (filled t) start-angle end-angle ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
    draw-ellipse*  medium center-x center-y radius-1-dx radius-1-dy radius-2-dx radius-2-dy &key (filled t) start-angle end-angle ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
              

    These functions (structured and spread arguments, respectively) draw an ellipse (when filled is true, the default) or an elliptical arc (when filled is false) on the medium medium. The center of the ellipse is the point center-pt (or the position (center-x,center-y)). [annotate]

    Two vectors, (radius-1-dx,radius-1-dy) and (radius-2-dx,radius-2-dy) specify the bounding parallelogram of the ellipse as explained in Chapter 3. All of the radii are real numbers. If the two vectors are collinear, the ellipse is not well-defined and the ellipse-not-well-defined error will be signalled. The special case of an ellipse with its major axes aligned with the coordinate axes can be obtained by setting both radius-1-dy and radius-2-dx to 0. [annotate]

    start-angle and end-angle are real numbers that specify an arc rather than a complete ellipse. Angles are measured with respect to the positive x axis. The elliptical arc runs positively (counter-clockwise) from start-angle to end-angle. The default for start-angle is 0; the default for end-angle is 2π. [annotate]

    In the case of a "filled arc" (that is when filled is true and start-angle or end-angle are supplied and are not 0 and 2π), the figure drawn is the "pie slice" area swept out by a line from the center of the ellipse to a point on the boundary as the boundary point moves from start-angle to end-angle. [annotate]

    When drawing unfilled ellipses, the current line style (see Chapter 10) affects the drawing in the obvious way, except that the joint shape has no effect. Dashed elliptical arcs start "dashing" at start-angle. [annotate]

    [annotate]

    draw-circle  medium center-pt radius &key (filled t) start-angle end-angle ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
    draw-circle*  medium center-x center-y radius &key (filled t) start-angle end-angle ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
              

    These functions (structured and spread arguments, respectively) draw a circle (when filled is true, the default) or a circular arc (when filled is false) on the medium medium. The center of the circle is center-pt or (center-x,center-y) and the radius is radius. These are just special cases of draw-ellipse and draw-ellipse*. filled is as for draw-ellipse*. [annotate]

    start-angle and end-angle allow the specification of an arc rather than a complete circle in the same manner as that of the ellipse functions, above. [annotate]

    The "filled arc" behavior is the same as that of an ellipse, above. [annotate]

    [annotate]

    draw-text  medium string-or-char point &key text-style (start 0) end (align-x :left) (align-y :baseline) toward-point transform-glyphs ink clipping-region transformation text-style text-family text-face text-size [Function]
    draw-text*  medium string-or-char x y &key text-style (start 0) end (align-x :left) (align-y :baseline) toward-x toward-y transform-glyphs ink clipping-region transformation text-style text-family text-face text-size [Function]
              

    The text specified by string-or-char is drawn on the medium medium starting at the position specified by the point point (or the position (x,y)). The exact definition of "starting at" is dependent on align-x and align-y. align-x is one of :left, :center, or :right. align-y is one of :baseline, :top, :center, or :bottom. align-x defaults to :left and align-y defaults to :baseline; with these defaults, the first glyph is drawn with its left edge and its baseline at point. [annotate]

    text-style defaults to nil, meaning that the text will be drawn using the current text style of the medium. [annotate]

    start and end specify the start and end of the string, in the case where string-or-char is a string. If start is supplied, it must be an integer that is less than the length of the string. If end is supplied, it must be an integer that is less than the length of the string, but greater than or equal to start. [annotate]

    Normally, glyphs are drawn from left to right no matter what transformation is in effect. toward-x or toward-y (derived from toward-point in the case of draw-text) can be used to change the direction from one glyph to the next one. For example, if toward-x is less than the x position of point, then the glyphs will be drawn from right to left. If toward-y is greater than the y position of point, then the glyphs' baselines will be positioned one above another. More precisely, the reference point in each glyph lies on a line from point to toward-point, and the spacing of each glyph is determined by packing rectangles along that line, where each rectangle is "char-width" wide and "char-height" high. [annotate]

    If transform-glyphs is true, then each glyph is transformed as an image before it is drawn. That is, if a rotation transformation is in effect, then each glyph will be rotated individually. If transform-glyphs is not supplied, then the individual glyphs are not subject to the current transformation. It is permissible for CLIM implementations to ignore transform-glyphs if it is too expensive to implement. [annotate]

    [annotate]

    12.5.2 Compound Drawing Functions

    CLIM also provides a few compound drawing functions. The compound drawing functions could be composed by a programmer from the basic drawing functions, but are provided by CLIM because they are commonly used. [annotate]

    draw-arrow  medium point-1 point-2 &key ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape to-head from-head head-length head-width [Function]
    draw-arrow*  medium x1 y1 x2 y2 &key ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape from-head to-head head-length head-width [Function]
              

    These functions (structured and spread arguments, respectively) draw a line segment on the medium medium from the point point1 to point2 (or from the position (x1,y1) to (x2,y2)). If to-head is true (the default), then the "to" end of the line is capped by an arrowhead. If from-head is true (the default is false), then the "from" end of the line is capped by an arrowhead. The arrowhead has length head-length (default 10) and width head-width (default 5). [annotate]

    The current line style (see Chapter 10) affects the drawing of the line portion of the arrow in the obvious way, except that the joint shape has no effect. Dashed arrows start dashing at point1. [annotate]

    [annotate]

    draw-oval  medium center-pt x-radius y-radius &key (filled t) ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
    draw-oval*  medium center-x center-y x-radius y-radius &key (filled t) ink clipping-region transformation line-style line-thickness line-unit line-dashes line-cap-shape [Function]
              

    These functions (structured and spread arguments, respectively) draw a filled or unfilled oval (that is, a "race-track" shape) on the medium medium. The oval is centered on center-pt (or (center-x,center-y)). If x-radius or y-radius is 0, then a circle is drawn with the specified non-zero radius. Other, a figure is drawn that results from drawing a rectangle with dimension x-radius by y-radius, and the replacing the two short sides with a semicircular arc of the appropriate size. [annotate]

    [annotate]