Re: Miniature view
Re: Miniature view
- Subject: Re: Miniature view
- From: Andrew Hunter <email@hidden>
- Date: Wed, 21 Apr 2004 22:37:34 +0100
On 21 Apr 2004, at 20:33, Pierre Bernard wrote:
Shawn,
Thanks for your reply!
Scaled views of what? What do the views contain?
Actually, they are WebViews. The thumbnails should serve both as
previews and as live progress indictors as web pages are loaded.
Here's one way I used a while ago. subview is the view you want to
scale.
NSCachedImageRep* cache = nil;
NSImage* img = nil;
// Make the ImageRep
cache = [[NSCachedImageRep allocWithZone: [self zone]]
initWithWindow: window
rect: frame];
// Put the subview in the ImageRep
[[cache window] setOpaque: NO];
[[cache window] setBackgroundColor: [NSColor clearColor]];
[[cache window] setContentView: subview];
[[cache window] displayIfNeeded];
// Put the ImageRep in the image
if (img) { [img release]; }
img = [[NSImage allocWithZone: [self zone]] init];
[img addRepresentation: cache];
// img now contains an image of the view that can be drawn scaled if
need be
NSCachedImageRep is basically an off-screen window, and if you add it
as a representation to an NSImage, you can created cached versions of
arbitrary views. Note that drawing scaled NSImages is nowhere near as
fast as Quartz can move windows around with Exposi, but if you just
want to get a scaled representation, this will do the trick. I used
this for doing transition animations, but it obviously has many more
applications.
Note that it's possible to have a window open-but-hidden (sending it an
orderOut: message puts it in this state), where its backing store is
retained, something I discovered after writing this code, but I'm not
sure if the backing store can be turned into anything useful for
scaling without using something undocumented (it'd be good if it could
be, because then you can emulate animations such as the Finder's
open/close folder).
It ought to be possible to pass events to the view cached in this
manner, too. I've been meaning to adapt my class to do this. You can
keep the cached version up to date by calling [[cache window]
displayIfNeeded] regularly.
This isn't the only way to scale a view. In some cases, calling
-[NSView setBounds:] is more appropriate. Quite a lot of the views
built into Cocoa don't seem to like this, though.
Andrew.
--
Andrew Hunter.
http://www.logicalshift.demon.co.uk
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.