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

Re: color icons



; 
; I am having trouble getting color icons (cicn resources) to appear.  I am
; using the icon-dialog-item code (Apple, 1989) which works fine with black
; and white icons (icon resources).

I use cicn's literally all the time, with no problems. I've never
actually tried using cicn's with the icon-dialog-item, I just defined
my own cicn-dialog item. When loading the resource, there's a trap
specifically for loading cicn's. It's called #_getcicon.  I use the
folllowing function to return a mac handle to the resource:

(defun load-color-icon (id)
  "Load a color icon with the id number id from the current resource
file. Should be called within a with-open-resource-file form if the 
icon is not in the MCL image."
    (let ((icon-hdl (#_getCicon id)))
      (if (%null-ptr-p icon-hdl)
        (error "no icon resource with id ~s." id)
        icon-hdl)))

And here's my cicn-dialog-item code (btw, this also happens to center
the icon in the view - the actual drawing is just done with
#_plotcicon). Hope it helps!

;
; Daniel
;

-Adam

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; thing:	cicn-dialog-item-mixin
;;		cicn-dialog-item
;; author:	Adam Alpern <ala@neural.hampshire.edu>
;; synopsis:	Provides a class to be mixed-in with dialog-items, or 
;;		other views that draws a color icon (resource type cicn) 
;;		centered in the item.

(defclass cicn-dialog-item-mixin ()
  ((icon :initarg :icon :initform nil :accessor icon)
   (icon-size :initarg :icon-size :initform #@(32 32) 
              :accessor icon-size)
   (offset :initarg :offset :initform #@(0 0) :accessor offset))
  (:Default-initargs :view-size #@(32 32)))

(defmethod calculate-icon-offset ((view cicn-dialog-item-mixin))
  (let* ((off (subtract-points (view-size view)
                               (icon-size view)))
         (off-h (point-h off))
         (off-v (point-v off))
         (offset (make-point (truncate (/ off-h 2))
                             (truncate (/ off-v 2)))))
    offset))

(defmethod (setf icon) :after (icon (view cicn-dialog-item-mixin))
  "Invalidates item so that the new icon is drawn."
  (declare (ignore icon))
  (setf (offset view) (calculate-icon-offset view))
  (invalidate-view view t))

(defmethod initialize-instance :after ((view cicn-dialog-item-mixin)
				       &rest args)
  (declare (ignore args))
  (setf (offset view) (calculate-icon-offset view)))

(defmethod set-view-size :after ((view cicn-dialog-item-mixin) h
				 &optional v)
  (declare (ignore h v))
  (setf (offset view) (calculate-icon-offset view)))

(defmethod view-draw-contents :after ((view cicn-dialog-item-mixin))
  (when (icon view)
    (with-focused-view view
      (rlet ((r :rect 
                :topleft (offset view) 
                :bottomright (add-points (offset view) 
					 (icon-size view))))
        (#_hlock (icon view))
        (#_plotCicon r (icon view))
        (#_hunlock (icon view))
        ))))

(defclass cicn-dialog-item (cicn-dialog-item-mixin dialog-item) ())


-- 
Adam Alpern, Hampshire College             WWW: http://hampshire.edu/~adaF92/
ala@neural.hampshire.edu