;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; compare-drawings.lisp ;; ;; c) Lee Spector, 1999 ;; lspector@hampshire.edu ;; ;; version 1.19990405 (n.yyyymmdd) #| A simple graphics window utility for Macintosh Common Lisp, created to allow for the comparison of two drawings. To use: - evaluate or load this file - set *which-drawing* to indicate which drawing to draw to - call draw-color-rectangle to paint colored rectangles - call draw-color-oval to paint colored ovals - call draw-color-line to paint colored lines - call wait-for-drawing-choice to wait for the user to select one of the drawings. |# (require :quickdraw) ;; quickdraw must be loaded (defvar *draw-window-1* nil "One of the windows in which drawing will occur.") (defvar *draw-window-2* nil "One of the windows in which drawing will occur.") (defvar *drawing-choice-dialog* nil) (defvar *which-drawing* 1) (defvar *chosen-drawing* nil) (defun close-draw-windows () (window-close *draw-window-1*) (window-close *draw-window-2*) (window-close *drawing-choice-dialog*)) (defun init-draw-windows (&optional (xsize 250) (ysize 250)) (unless (and *draw-window-1* (wptr *draw-window-1*)) ; window doesn't exist (setq *draw-window-1* (make-instance 'window :window-title "Drawing 1" :view-size (make-point xsize ysize) :view-position (make-point 50 50) :window-type :document :color-p t))) (unless (and *draw-window-2* (wptr *draw-window-2*)) ; window doesn't exist (setq *draw-window-2* (make-instance 'window :window-title "Drawing 2" :view-size (make-point xsize ysize) :view-position (make-point (+ 70 xsize) 50) :window-type :document :color-p t))) (unless (and *drawing-choice-dialog* (wptr *drawing-choice-dialog*)) (setq *drawing-choice-dialog* (MAKE-INSTANCE 'COLOR-DIALOG :WINDOW-TYPE :TOOL :WINDOW-TITLE "Preference?" :VIEW-POSITION (make-point xsize (+ ysize 80)) :VIEW-SIZE #@(123 57) :VIEW-FONT '("Charcoal" 12 :SRCOR :PLAIN (:COLOR-INDEX 0)) :VIEW-SUBVIEWS (LIST (MAKE-DIALOG-ITEM 'BUTTON-DIALOG-ITEM #@(7 6) #@(49 43) "1" #'(LAMBDA (ITEM) ITEM (setq *chosen-drawing* 1)) :DEFAULT-BUTTON NIL) (MAKE-DIALOG-ITEM 'BUTTON-DIALOG-ITEM #@(62 6) #@(49 43) "2" #'(LAMBDA (ITEM) ITEM (setq *chosen-drawing* 2)) :DEFAULT-BUTTON NIL))))) (clear-drawings) (event-dispatch)) (defun draw-color-rectangle (x y xsize ysize red green blue) "Paints a color rectangle in the drawing window. Red, green, and blue should each be integers in the range 0-65535." (let ((w (if (= *which-drawing* 1) *draw-window-1* *draw-window-2*))) (with-focused-view w (with-fore-color (make-color red green blue) (paint-rect w x y (+ x xsize) (+ y ysize)))))) (defun draw-color-oval (x y xsize ysize red green blue) "Paints a color oval in the drawing window. Red, green, and blue should each be integers in the range 0-65535." (let ((w (if (= *which-drawing* 1) *draw-window-1* *draw-window-2*))) (with-focused-view w (with-fore-color (make-color red green blue) (paint-oval w x y (+ x xsize) (+ y ysize)))))) (defun draw-color-line (x1 y1 x2 y2 red green blue) "Paints a color line from to in the drawing window. Red, green, and blue should each be integers in the range 0-65535." (let ((w (if (= *which-drawing* 1) *draw-window-1* *draw-window-2*))) (with-focused-view w (with-fore-color (make-color red green blue) (move-to w x1 y1) (line-to w x2 y2))))) (defun clear-drawings () "Clears the drawing windows by painting them white." (setq *which-drawing* 1) (let ((size (view-size *draw-window-1*))) (draw-color-rectangle 0 ;; starts at upper corner 0 (point-h size) ;; covers whole window (point-v size) 65535 ;; R, G, B all max 65535 65535)) (setq *which-drawing* 2) (let ((size (view-size *draw-window-2*))) (draw-color-rectangle 0 ;; starts at upper corner 0 (point-h size) ;; covers whole window (point-v size) 65535 ;; R, G, B all max 65535 65535))) (defun show-drawing2 () "Brings the drawing window to the front." (window-select *draw-window-1*) (window-select *draw-window-2*) (event-dispatch)) (defun wait-for-drawing-choice () (setq *chosen-drawing* nil) (do () ((numberp *chosen-drawing*) *chosen-drawing*) (event-dispatch))) #| ;; Examples (init-draw-windows 300 300) (setq *Which-Drawing* 1) (draw-color-rectangle 0 0 20 20 65535 0 0) (draw-color-rectangle 40 30 50 50 0 65535 0) (draw-color-rectangle 20 90 150 150 0 0 65535) (draw-color-rectangle 10 250 180 100 0 65535 65535) (setq *Which-Drawing* 2) (draw-color-oval 0 0 20 20 65535 0 0) (draw-color-oval 40 30 50 50 0 65535 0) (draw-color-oval 20 90 150 150 0 0 65535) (draw-color-oval 10 250 180 100 0 65535 65535) (wait-for-drawing-choice) |#