Changes between Version 16 and Version 17 of CocoaBridge


Ignore:
Timestamp:
Oct 17, 2007, 7:23:39 PM (14 years ago)
Author:
rme
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CocoaBridge

    v16 v17  
    8888}}}
    8989
    90 Note that if the view is ever told to redisplay itself, your drawing
     90Getting a little fancier, we can write code to grab
     91an image from the web and draw it in our view.
     92This time we create the NSImage instance using
     93an Objective-C-style idiom.  We could also
     94have written
     95`(make-instance 'ns:ns-image :with-contents-of-url url)`.
     96
     97Note that you still have to release the NSImage instance,
     98no matter how you create it.  (The NSWindow instance
     99created above will be released when the window is
     100closed, so there's no leak there.  But that's a special
     101feature of the NSWindow class.)
     102
     103{{{
     104(defun draw-earth (view)
     105  (let* ((url (#/URLWithString: ns:ns-url "http://nssdc.gsfc.nasa.gov/thumbnail/planetary/earth/apollo17_earth.gif"))
     106         (image (#/initWithContentsOfURL: (#/alloc ns:ns-image) url)))
     107    (with-focused-view view
     108      (ns:with-ns-rect (z 0 0 0 0)
     109         (#/drawAtPoint:fromRect:operation:fraction:
     110          image (ns:make-ns-point 40 40)
     111          z
     112          #$NSCompositeCopy
     113          1.0)))
     114    (#/release image)))
     115}}}
     116
     117Do the actual drawing:
     118{{{
     119(draw-earth *v*)
     120}}}
     121
     122The drawing that we're doing by evaluating forms
     123at the listener can be looked at as "immediate mode"
     124drawing.  This is a fun way to experiment,
     125but if the view is ever told to redisplay itself (e.g., if you minimize and
     126then restore the window), your drawing
    91127will be wiped out. You need to arrange for your drawing routines
    92128to be called from the view's `drawRect:` method in order