Drawing Text and Graphics

part of Common Lisp Interface Manager (CLIM) by Jason Kantz


  • How is output displayed on a pane?
  • What are some of the basic CLIM drawing functions?


  • Mediums, Sheets, and Streams
  • CLIM Drawing Functions


    A medium is the destination for graphic output in CLIM. Different medium classes correspond to different devices, such as displays and printers, allowing graphics to be rendered in a variety of ways depending on the medium and its drawing options.

    An application pane (AKA an extended-stream-pane) is a kind of medium that can be supplied to drawing functions. For example we can make the word application frame, access it's pane, and then access drawing options that are part of the pane because it is a medium.

    CLIM-USER(8): (setq *word* (make-application-frame 'word))
    #<WORD @ #x4b2478a>
    CLIM-USER(9): (setq pane (get-frame-pane *word* 'document))
    #<APPLICATION-PANE @ #x4b24af2>
    CLIM-USER(10): (medium-foreground pane)
    #<CLIM-UTILS:GRAY-COLOR Black @ #x41432ca>
    CLIM-USER(11): (medium-background pane)
    #<CLIM-UTILS:GRAY-COLOR White @ #x4142792>

    Drawing on Panes

    Within a pane description, the pane option :display-function specifies the function that will draw the output for that pane.

    Below we have modified the word application frame. Notice the slot doc-title was added to store the title of the current document. Also notice a display function for the pane called title was added. The supplied function, display-doc-title, takes two arguments: an application frame and a medium.

    (define-application-frame word		;name
         ()					;superclasses
      ((doc-title				;slots
        :accessor doc-title
        :initarg :doc-title))
       ;; options
        (title				;pane name 
         :application			;pane type
         ;; pane options
         :display-function #'display-doc-title
         :initial-cursor-visibility nil)
        (document				;pane name 
         :application))			;pane type
        (default				;name of the layout
    	(vertically ()			;layout macros
    	  (1/4 title)
    	  (3/4 document)))))
    (defmethod display-doc-title ((frame word) stream)
      (draw-text* stream "Document:" 10 15)
      (if (slot-boundp frame 'doc-title)
          (draw-text* stream (doc-title frame) 20 40)
          (draw-text* stream "Untitled" 20 40)))
    (make-application-frame 'word 
    			:height 300
    			:width 300
    			:doc-title "Microcrock's Business Plan")

    Notice that the origin of the coordinate system of the drawing plane is in the top left corner of the window with positive x extending to the right and positive y extending down toward the bottom of the window.


    "Men are sent into the world with bills of credit, and seldom draw to their full extent."
    -- Horace Walpole
    1. Load the CLIM package within your Lisp, and switch to the CLIM-USER package.
    2. Load word.lisp
    3. Type the following into your Lisp listener:
      (make-application-frame 'word
                              :height 300 :width 400
                              :doc-title "Microcrock's Business Plan")
    4. Close the word application frame that appears.
    5. In word.lisp, remove the slot called doc-title from the word application frame, and add a slot called current-file.
    6. Modify display-doc-title so that it displays the value of current-file instead of doc-title.
    7. Modify the word application frame so the title pane does not have scroll-bars.
    8. Add a display function called #'display-document to the document pane description of the word application frame.
    9. Define display-document to draw each line of current-file onto the document pane. Use the do-file macro provided in word.lisp to iterate over the lines of a the file. To find out the height of a line, use the line-height function provided in word.lisp. Use clim:draw-rectangle* to draw a black line around the all of the text.
    10. After you make your modifications, you should be able to type the following into your lisp listener to see the contents of the word.lisp file within the word application frame.
      (make-application-frame 'word
                              :height 300 :width 400
                              :current-file "word.lisp")

    Next: Formatted Output