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

Re: pen-pattern for CWindowRecord



wilcox@cmns.think.com writes:
  I have a macro called with-pen-pattern which temporarily sets a new
  pattern.  It works fine for WindowRecords but not for CWindowRecords.
  That's because the function pen-pattern assumes a WindowRecord.

The following code from oodles-of-utils package in the file
brutal-utils/QuickDraw-u.lisp may do what you want.  I've used
it for color windows:
(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)))))


The following code from the same source file supports both color
and ordinary grafports:

  (defmacro with-back-pix-pat (pix-pat &body body)
    (let ((fn (gensym))
          (data_p (gensym)))
      `(flet ((,fn ()
                (if (zerop (href ,pix-pat PixPat.patType))
                  (with-dereferenced-handles ((,data_p (href ,pix-pat PixPat.patData)))
                    (require-trap #_BackPat ,data_p))
                  (require-trap #_BackPixPat ,pix-pat))
                ,@body))
         (declare (dynamic-extent #',fn))
         (call-with-back-pat-saved #',fn))))

The expression (zerop (href ,pix-pat PixPat.patType)) distinguishes between
grafports and cgrafports as wilcox suggests in his message.