12.7 Graphics Protocols

  • 12.7.1 General Behavior of Drawing Functions
  • 12.7.2 Medium-specific Drawing Functions
  • 12.7.3 Other Medium-specific Output Functions
  • Every medium must implement methods for the various graphical drawing generic functions. Furthermore, every sheet that supports the standard output protocol must implement these methods as well; often, the sheet methods will trampoline to the methods on the sheet's medium. All of these generic functions take the same arguments as the non-generic spread function equivalents, except the arguments that are keyword arguments in the non-generic functions are positional arguments in the generic functions. [annotate]

    Every medium must implement methods for the various graphical drawing generic functions. All of these generic functions take as (specialized) arguments the medium, followed by the drawing function-specific arguments, followed by the ink, line style (or text style), and clipping region. [annotate]

    The drawing function-specific arguments will either be x and y positions, or a sequence of x and y positions. These positions will be in medium coordinates, and must be transformed by applying the medium's device transformation in order to produce device coordinates. Note that the user transformation will have already been applied to the positions when the medium-specific drawing function is called. However, the medium-specific drawing function will still need to apply the device transformation to the positions in order to draw the graphics in the appopriate place on the host window. [annotate]

    The ink, line style, text style, and clipping regions arguments are not part of the medium-specific drawing functions. They must be extracted from the medium object. Each medium-specific method will decode the ink, line (or text) style, and clipping region in a port-specific way and communicate it to the underlying port. [annotate]

    12.7.1 General Behavior of Drawing Functions

    Using draw-line* as an example, calling any of the drawing functions specified above results in the following series of function calls on a non-output recording sheet: [annotate]

    Note: It is very convenient to choose draw-line* as an example, because it doesn't expose some of the problems of the other drawing functions. For instance, draw-rectangle* may be called with a non-rectilinear transformation, which makes it necessary to call medium-draw-polygon* instead of medium-draw-rectangle*. Another problem is with draw-text* when :transform-glyphs is t. [edit]-- Robert Strandh 2007-08-23 09:49Z
     

    12.7.2 Medium-specific Drawing Functions

    All mediums and all sheets that support the standard output protocol must implement methods for the following generic functions. [annotate]

    The method for each of these drawing functions on the most specific, implementation-dependent medium class will transform the coordinates by the device transformation of the medium's sheet, extract the medium's port-specific "drawable", and then invoke a port-specific drawing function (such as xlib:draw-line) to do the actual drawing. [annotate]

    Note: This use of "device transformation" is incoherent with some other parts of the spec. Elsewhere, "device transformation" means the composition of the "user transformation" (a.k.a the "medium transformation") and the "native transformation" of the sheet. [edit]-- Robert Strandh 2007-08-23 10:00Z
     

    An :around on basic-medium for each of the drawing functions will have already transformed the user coordinates to medium coordinates before the most specific, implementation-dependent method is called. [annotate]

    Implementation note: CLIM implementations should provide "trampoline" methods on sheets that support the standard output protocol that simply call the same generic function on the medium. Sheets that support output recording will require extra mechanism before delegating to the medium in order to implement such functionality as creating output records and handling scrolling. [annotate]

    medium-draw-point*  medium x y [Generic Function]
              

    Draws a point on the medium medium. [annotate]

    [annotate]

    medium-draw-points*  medium coord-seq [Generic Function]
              

    Draws a set of points on the medium medium. coord-seq is a sequence of coordinate pairs, which are real numbers. It is an error if coord-seq does not contain an even number of elements. [annotate]

    [annotate]

    medium-draw-line*  medium x1 y1 x2 y2 [Generic Function]
              

    Draws a line on the medium medium. The line is drawn from (x1,y1) to (x2,y2). [annotate]

    [annotate]

    medium-draw-lines*  stream position-seq [Generic Function]
              

    Draws a set of disconnected lines on the medium medium. coord-seq is a sequence of coordinate pairs, which are real numbers. Each successive pair of coordinate pairs is taken as the start and end position of each line. It is an error if coord-seq does not contain an even number of elements. [annotate]

    [annotate]

    medium-draw-polygon*  medium coord-seq closed [Generic Function]
              

    Draws a polygon or polyline on the medium medium. coord-seq is a sequence of coordinate pairs, which are real numbers. It is an error if coord-seq does not contain an even number of elements. Each successive coordinate pair is taken as the position of one vertex of the polygon. [annotate]

    [annotate]

    Note: We have an extra :filled argument. [edit]-- Gilbert Baumann 2005-03-06 15:03Z
     

    medium-draw-rectangle*  medium x1 y1 x2 y2 [Generic Function]
              

    Draws a rectangle on the medium medium. The corners of the rectangle are at (x1,y1) and (x2,y2). [annotate]

    [annotate]

    Note: filled? [edit]-- Gilbert Baumann 2005-03-06 15:03Z
     

    medium-draw-rectangles*  medium coord-seq [Generic Function]
              

    Draws a set of rectangles on the medium medium. coord-seq is a sequence of coordinate pairs, which are real numbers. It is an error if coord-seq does not contain an even number of elements. Each successive pair of coordinate pairs is taken as the upper-left and lower-right corner of the rectangle. [annotate]

    [annotate]

    Note: filled? [edit]-- Gilbert Baumann 2005-03-06 15:04Z
     

    medium-draw-ellipse*  medium center-x center-y radius-1-dx radius-1-dy radius-2-dx radius-2-dy start-angle end-angle [Generic Function]
              

    Draws an ellipse or elliptical arc on the medium medium. The center of the ellipse is at (x,y), and the radii are specified by the two vectors (radius-1-dx,radius-1-dy) and (radius-2-dx,radius-2-dy). [annotate]

    start-angle and end-angle are real numbers that specify an arc rather than a complete ellipse. Note that the medium and device transformations must be applied to the angles as well. [annotate]

    [annotate]

    Note: filled? [edit]-- Gilbert Baumann 2005-03-06 15:05Z
     

    medium-draw-text*  medium text x y (start 0) end (align-x :left) (align-y :baseline) toward-x toward-y transform-glyphs [Generic Function]
              

    Draws a character or a string on the medium medium. The text is drawn starting at (x,y), and towards (toward-x,toward-y). In Some implementations of CLIM, medium-draw-text* may call either medium-draw-string* or medium-draw-character* in order to draw the text. [annotate]

    Note: There is no medium-draw-string* and no medium-draw-character* in this spec. Are these supposed to be lower level primitives? [edit]-- Gilbert Baumann 2003-06-02 05:50Z
     

    [annotate]

    12.7.3 Other Medium-specific Output Functions

    medium-finish-output  medium [Generic Function]
              

    Ensures that all the output sent to medium has reached its destination, and only then return false. This is used by finish-output. [annotate]

    [annotate]

    medium-force-output  medium [Generic Function]
              

    Like medium-finish-output, except that it may return false without waiting for the output to complete. This is used by force-output. [annotate]

    [annotate]

    medium-clear-area  medium left top right bottom [Generic Function]
              

    Clears an area on the medium medium by filling the rectangle whose edges are at left, top, right, and bottom with the medium's background ink. left, top, right, and bottom are in thed medium's coordinate system. [annotate]

    The default method on basic-medium simply uses draw-rectangle* to clear the area. Some host window systems has special functions that are faster than draw-rectangle*. [annotate]

    [annotate]

    Note:

    It is worth noting, that unlike medium-draw-rectangle*, medium-clear-area is expected to do a "source" operation not "over" from the composition point of view. Having that in mind the default method should /always/ use a solid ink, i.e:

    (draw-rectangle* medium left top right bottom :ink (compose-over +background-ink+ +black+))

    [edit]-- Daniel Kochmanski 2022-03-17 09:21Z
     

    medium-beep  medium [Generic Function]
              

    Causes an audible sound to be played on the medium. The default method does nothing. [annotate]

    [annotate]