CLIM mail archive

[Prev][Next][Index][Thread]

graphically updating an object on the screen...



    Date: Fri, 6 Dec 1991 14:32 EST
    From: Deborah Berman <dberman@cs.washington.edu>

    What is the best way to graphically update an object on the screen?
    For example, we're building a thermometer and need to update the temperature
    at each time interval.  What facilities do CLIM have for this?  Does
    anyone have experience doing something like this?  Sample code to share?

If (AND ONLY IF) the thermometer is guaranteed not to overlap with any
other output in its window, then a simple but efficient choice of
strategy is to hang onto the output record for the thermometer and
explicitly erase it, then redraw it.  Here, for example, is a little
animation of a telephone ringing and picking up.

;;; -*- Mode: LISP; Syntax: Common-Lisp; Base: 10; Package: CLIM-USER -*-

(defvar *phone-body-outline* '(-24 8 24 8 24 0 8 -16 -8 -16 -24 0))
(defvar *phone-handset-on-hook-outline* '(-18 -20 18 -20 20 -19 20 -18 26 -14 30 -18 30 -23
					  20 -26 -20 -26 -30 -23 -30 -18 -26 -14 -20 -18 -20 -19))
(defvar *phone-handset-off-hook-outline* '(6 -45 -20 -19 -21 -17 -20 -16 -21 -10 -27 -10 -30 -13
					   -26 -22 3 -51 12 -55 15 -52 15 -46 9 -45 8 -46))
(defvar *ringing-blivets* '((30 -8 30 -12) (32 -6 32 -14) (34 -4 34 -16)))

(defun draw-phone (stream x y &key id off-hook ringing)
  (with-translation (stream x y)
    (draw-polygon* stream *phone-body-outline* :filled t :ink +light-gray+)
    (draw-polygon* stream *phone-body-outline* :filled nil :closed t)
    (let ((handset-outline (if off-hook
			       *phone-handset-off-hook-outline*
			       *phone-handset-on-hook-outline*)))
      (draw-polygon* stream handset-outline :filled t :ink +light-gray+)
      (draw-polygon* stream handset-outline :filled nil :closed t))
    (when ringing
      (dolist (sx '(1 -1))
	(with-scaling (stream sx 1)
	  (dolist (blivet *ringing-blivets*)
	    (draw-polygon* stream blivet :filled nil :closed nil)))))
    (when id
      (draw-string* stream id 0 12 :align-x :center :align-y :top))))

#||
();;; run this in the CLIM Listener for testing

(defun test (&optional (stream *standard-output*))
  (let ((o-r nil) (off-hook nil) (ringing nil))
    (loop do
      (when o-r
	(erase-output-record o-r stream))
      (setq o-r 
	    (with-new-output-record (stream)
	      (draw-phone stream 100 100 :off-hook off-hook :ringing ringing)))
      (cond (ringing
	     (setq ringing nil off-hook t))
	    (off-hook
	     (setq off-hook nil))
	    (T
	     (setq ringing t)))
      (sleep 1))))

||#

0,,

References:

Main Index | Thread Index