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


To work with resources you need to read the chapter on them in Inside

The usual procedure is to save your graphic as a PICT resource (from
Canvas or MacDraw), use the OpenResFile trap to make the PICTs
available, use the GetResource, GetIndResource, or GetNamedResource
trap to get a mac handle to the pict, then do DRAW-PICTURE, etc. using
the handle.

I posted a 1.3.2 file called resources.lisp that has lisp-level
routines for handling resources. I think there have been other
postings of PICT-specific things like pict dialog items and reading
PICT files.

I haven't converted resources.lisp to 2.0b1 but its improved trap
interface makes trap hacking much easier (thanks to the Apple team).
Here is simple code to open, close, and maintain resource files:

? (defvar *open-resource-files* ())
? (let* ((file-name (choose-file-dialog))
         (result (with-pstrs ((str (namestring file-name)))
                   (#_openResFile str))))
    (if (minusp result)
      (warn "Error (~S) opening ~S." result file-name)
      (push result *open-resource-files*)))

? (let ((refnum (first *open-resource-files*)))
    (setf *open-resource-files* (delete refnum *open-resource-files*))
    (#_closeResFile refnum))
? *open-resource-files*

Here is code that draws all PICTs in the front window's upperleft hand
corner. (I don't think you need to call #_DisposHandle on each
resource, and I think you should call #_LoadResource in case the
resource has been purged. Can someone correct me on this?).

(dotimes (index (#_CountResources "PICT"))
    (draw-picture (first (windows)) (#_GetIndResource "PICT" index))
    (sleep 1))