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

Strange color behavior (again)



On Tue Jul 13 14:20:19 1993 osiris@cs.utexas.edu writes
about problems using (pen-pattern) with color windows
which has remained unanswered.

Here is the code that exhibits the problem. It draws a grey line
with a pen (5,5) pixels and then draws a wierdly patterned line
the same thickness in blue.

(require 'quickdraw)
(setf xxx (make-instance 'window :color-p T))
(with-focused-view xxx
  (with-fore-color (make-color 0 40000 40000)
    (pen-normal xxx)
    (let ((old-pat (pen-pattern xxx)))
      (set-pen-pattern xxx *gray-pattern*)
      (set-pen-size  xxx (make-point 5 5))
      (move-to xxx 0 30)
      (line-to xxx 200 30)
      (set-pen-pattern xxx old-pat)
      (move-to xxx 0 50)
      (line-to xxx 200 50)
      (dispose-record old-pat))))

First, disposing the record (old-pat) does not seem like a very good idea.
Use the rlet construction if you want to create temporary records that
disappear when the block terminates.

The problem arises since color windows have a :cWindowRecord
associated with them rather than a :windowRecord.
 
If you want to change the pen for both color and b&w windows,
use the pen-state rather than pen-pattern to control the pen attributes.

Here is the corrected code for with-focused-view which uses traps
directly:
 
(with-focused-view xxx
  (with-fore-color (make-color 0 40000 40000)
    (pen-normal xxx)
    (rlet ((pen-state :penState))
      (require-trap #_GetPenState pen-state)
      (require-trap #_PenPat *gray-pattern*)
      (require-trap  #_PenSize :long (make-point 5 5))
      (move-to xxx 0 30)
      (line-to xxx 200 30)
      (require-trap #_SetPenState pen-state)
      (require-trap  #_PenSize :long (make-point 5 5))
      (move-to xxx 0 50)
      (line-to xxx 200 50))))


You'd be better off rewriting the code with the with-pen-state macro.
The macro allows you to change the pensize, the pen pattern, pix pattern (color)
location, and/or mode.

Mark

Here's the way it will look:
(with-focused-view xxx
  (with-fore-color (make-color 0 40000 40000)
    (pen-normal xxx)
    (with-pen-state (:pnsize #@(5 5) :pnPat *gray-pattern*)
      (move-to xxx 0 30)
      (line-to xxx 200 30))
    
    (with-pen-state (:pnsize #@(5 5))
      (move-to xxx 0 50)
      (line-to xxx 200 50))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; code from oodles-of-utils:Brutal-utils:QuickDraw-u.lisp
;;
;; Copyright  1992 Northwestern University Institute for the Learning Sciences
;; All Rights Reserved
;;
;; author: Michael S. Engber
;;
;; utilities for quickdraw
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defmacro with-pen-state ((&key pnLoc pnSize pnMode pnPat pnPixPat) &body
body)
    (let ((state (gensym)))
      `(rlet ((,state :PenState))
         (require-trap #_GetPenState ,state)
         (unwind-protect
           (progn
             ,@(when pnLoc    `((require-trap #_MoveTo (point-h ,pnLoc) (point-v
,pnLoc))))
             ,@(when pnSize   `((require-trap #_PenSize (point-h ,pnSize)
(point-v ,pnSize))))
             ,@(when pnMode   `((require-trap #_PenMode ,pnMode)))
             ,@(when pnPat    `((require-trap #_PenPat ,pnPat)))
             ,@(when pnPixPat `((require-trap #_PenPixPat ,pnPixPat)))
             ,@body)
           (require-trap #_SetPenState ,state)))))
;; end of code
 
 


(this code available by anonymous ftp from cambridge.apple.com in
the pub/MCL2/contrib directory.