[Openmcl-devel] programmatic file chooser? thanks!
Brent Fulgham
bfulgham at gmail.com
Thu Aug 28 22:17:35 PDT 2008
Just to take the example a bit further, if you are on Leopard you can
even play with rudimentary CoreAnimation:
> (defun make-image-view-window ()
> "Make a window whose content view is an empty NSImageView. Allow
> the user to drag images to that view, and support transfer of images
> to/from the view via the clipboard. Return the NSImageView."
> (ccl::with-autorelease-pool
> (let* ((rect (ns:make-ns-rect 0 0 300 300))
> (w (make-instance 'ns:ns-window
> :with-content-rect rect
> :style-mask (logior #$NSTitledWindowMask
> #$NSClosableWindowMask
> #
> $NSMiniaturizableWindowMask
> #
> $NSResizableWindowMask)
> :backing #$NSBackingStoreBuffered
> :defer t))
> (image-view (make-instance 'ns:ns-image-view)))
> ;; Set the window's title to a constant NSString (#@"...").
> (#/setTitle: w #@"Drag or paste an image here!")
> ;; Make the image view respond to drag-and-drop
> (#/setEditable: image-view t)
> ;; and make it support the clipboard
> (#/setAllowsCutCopyPaste: image-view t)
> ;; Make the image view be the window's "content view".
> (#/setContentView: w (#/autorelease image-view))
> ;; Center and display the window.
> (#/center w)
> (#/orderFront: w nil)
> image-view)))
As before, load an image and tell the view to scale it:
? (defvar *view* (make-image-view-window))
*VIEW*
? (#/image *view*)
#<NS-IMAGE NSImage 0x21eac40 Size={1600, 1280} Reps=(
NSBitmapImageRep 0x21f4e30 Size={1600, 1280}
ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=24 Pixels=1600x1280
Alpha=NO Planar=NO Format=0) (#x21EAC40)>
? (#/setImageScaling: *view* #$NSScaleToFit)
NIL
Define a new NSRect that has a different location (and shape):
? (defvar *nf* (ns:make-ns-rect 100 350 400 400))
*NF*
? *NF*
#<NS-RECT 400 X 400 @ 100,350 [gcable] (#xF2BA750) #x30004213FACD>
Get the View's containing window so we can access its animation proxy:
? (defvar *W* (#/window *view*))
*W*
Now, tell Cocoa to move it around!
? (#/setFrame:display:animate: *w* *nf* #$YES #$YES)
Whee!
-Brent
More information about the Openmcl-devel
mailing list