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

A question regarding small icons....

Has anyone out there written code for handling small icons in MACL?

I am using the Resource utilities provided by Matthew Cornell.

Here is my code, loosely based on icon-dialog-items from the Examples
folder in MACL 1.3.2.  The file Palette.rsrc is just a small resource
file with a few ICON's and one SICN with 17 icons.  I need to figure
out how to draw just one, and then I think I can figure out the
indexing on the other icons.

By the way, I thank everyone for all the informative responses
I have received regarding macros.  I am sifting through them and
will provide a global contribution, plus my specific use of them.
If my use is lisp style-wise inappropriate, feel free to flame.

Thanks for your help.  Pretty soon I hope my team and I will be making
some contributions to the MACL community.

  -- Luke

(in-package :ccl)
(require 'quickdraw)
(export '(*sicn-dialog-item*)
(export '(open-resource-file
(eval-when (eval compile)
  (require 'traps))

; trying to get this version to work with small icons
(defobfun (plot-sicn *window*) (sicn point)
  (declare (object-variable wptr my-refnum))
  (unless (or (typep sicn 'fixnum)
              (pointerp sicn))
    (error "~s is not a valid icon (not a resource-id or pointer"))
   (let* ((my-refnum (open-resource-file "SODA;PlanDraw:Palette.rsrc"))
          (the-sicn-handle (when (plusp my-refnum)
                             (get-resource "SICN" sicn))))
     (format t "the-sicn-handle is ~a~%" the-sicn-handle)
     (format t "The size of the resource is ~a~%" (size-resource the-sicn-handle))
     (cond (the-sicn-handle
            (with-dereferenced-handles ((the-sicn-pointer the-sicn-handle))
              (rlet ((the-dest-rect :rect
                                    :topleft point
                                    :bottomright (add-points point #@(16 16)))
                     (the-source-rect :rect
                                      :topleft #@(0 0)
                                      :bottomright #@(16 16))
                     (the-source-bits :bitmap
                                      :baseAddr the-sicn-pointer
                                      :rowBytes 2
                                      :bounds the-source-rect))
                (dotimes (index 32)
                  (format t "|~x" (%get-byte the-sicn-pointer index)))
                (copy-bits the-source-bits
                           (rref wptr window.port.portBits)
            (format t "ERROR: the-sicn-handle is nil!"))))
   (close-resource-file "SODA;PlanDraw:Palette.rsrc")))

; this version works correctly with large icons
(defobfun (plot-sicn *window*) (sicn point)
  (declare (object-variable wptr my-refnum))
  (format t "The point ~a~%" (point-string point))
  (unless (or (typep sicn 'fixnum)
              (pointerp sicn))
    (error "~s is not a valid icon (not a resource-id or pointer"))
   (let* ((my-refnum (open-resource-file "SODA;PlanDraw:Palette.rsrc"))
          (the-sicn-handle (when (plusp my-refnum)
                             (get-resource "ICON" sicn))))
     (cond (the-sicn-handle
            (with-port wptr
              (rlet ((r :rect
                        :topleft point
                        :bottomright (add-points point #@(16 16))))
                     (_ploticon :ptr r :ptr the-sicn-handle))))
            (format t "ERROR: the-sicn-handle is nil!"))))
   (close-resource-file "SODA;PlanDraw:Palette.rsrc")))


(defobject *sicn-dialog-item* *dialog-item*)

(defobfun (exist *sicn-dialog-item*) (init-list)
  (have 'my-sicn (getf init-list :sicn 128))
   (init-list-default init-list :dialog-item-size #@(16 16))))

(defobfun (dialog-item-draw *sicn-dialog-item*) ()
  (declare (object-variable my-sicn my-dialog))
  (let* ((sicn my-sicn)                      ;rebind some instance variables
         (pos (dialog-item-position)))       ; to lexical variables so they can be passed to another object.
    (ask my-dialog (plot-sicn sicn pos))))   ;ask the owning dialog window
                                             ;to plot the sicn.

(defobfun (dialog-item-click-event-handler *sicn-dialog-item*) (where)
  (declare (object-variable my-dialog wptr)
           (ignore where))
  (let* ((pos (dialog-item-position))        ;position of the item
         (mtop (point-v pos))                ;the four rectangle
         (mleft (point-h pos))               ;  coordinates of the
         (mbottom (+ mtop 16))               ;  item
         (mright (+ mleft 16))               ;
         (inverted-p nil)                    ;used to track whether the sicn
                                             ;  is inverted. will only be true
                                             ;  when the mouse is over the sicn
         (item (self)))                      ;the sicn object.
    (ask my-dialog                           ;the dialog does all the tracking.
      (with-port wptr                        ;draw in the dialog's grafport.
        (rlet ((temp-rect :rect              ;temporarily allocate a rectangle
                          :top mtop          ;
                          :left mleft        ;
                          :bottom mbottom    ;
                          :right mright))    ;
          (without-interrupts                ;
           (_inverrect :ptr temp-rect)       ;initially invert the sicn.
           (setq inverted-p t)               ;
             (loop                           ;loop until the button is released
               (unless (mouse-down-p)        ;
                 (when inverted-p            ;if button released with mouse
                                             ;  over the sicn, run the action
                   (ask item (dialog-item-action)))
                 (return-from dialog-item-click-event-handler))
               (if (logbitp 8 (_PtInRect     ;
                               :long (window-mouse-position)
                               :ptr temp-rect
                               :word))       ;is mouse over the sicn's rect?
                   (unless inverted-p        ;yes, make sure it's inverted.
                     (_inverrect :ptr temp-rect)
                     (setq inverted-p t))    ;
                   (when inverted-p          ;no, make sure it's not inverted.
                     (_inverrect :ptr temp-rect)
                     (setq inverted-p nil))))))))))

(defobfun (dialog-item-action *sicn-dialog-item*) ()

(provide 'sicn-dialog-items)
(pushnew :sicn-dialog-items *features*)

(provide 'resources)
(pushnew :resources *features*)

(oneof *DIALOG*
       :WINDOW-POSITION #@(68 72)
       :WINDOW-SIZE #@(300 150)
       (list (oneof *sicn-dialog-item*
                    :sicn 128
                    :dialog-item-action '(progn
                                           (print "please note")