Drawing split view into NSImage
Drawing split view into NSImage
- Subject: Drawing split view into NSImage
- From: 정다운 <email@hidden>
- Date: Thu, 13 May 2004 15:46:44 +0900 (JST)
Hi,
I'm trying to draw an NSSplitView into a focused NSImage. The
NSSplitView contains two panes A and B (A is above B), and each pane
contains NSTextFields. But the result is the splitview divider draws in
the right place, but the contents of panes A and B are switched so B is
above A. See <
http://dwj.freeshell.org/blog/img/AGNodeView.jpg> for
what I mean.
I am doing this for very large images (~2500px^2) because
dataWithPDFInsideRect: becomes too slow.
Here is code:
- (void)myDraw
{
[image setFlipped: [self isFlipped]];
[image lockFocus];
[self drawSubviewsInImage:image];
[image unlockFocus];
}
- (void)drawSubviewsInImage:(NSImage *)image
{
NSEnumerator *e = [[self subviews] objectEnumerator];
NSView *child;
while ( child = [e nextObject] ) {
NSImage *subviewImage = [[NSImage alloc] initWithSize:[child
bounds].size];
[subviewImage setFlipped: [child isFlipped]];
[subviewImage lockFocus];
[self drawSubviewsInImage:subviewImage];
[subviewImage unlockFocus];
[NSGraphicsContext saveGraphicsState];
if ([self isFlipped]) {
// Flip text inside splitview
NSAffineTransform *flip = [NSAffineTransform transform];
[flip scaleXBy:1.0 yBy:-1.0];
[flip translateXBy:0 yBy:-[self bounds].size.height];
[flip concat];
}
// Paste subviewImage onto image
[subviewImage drawAtPoint:[child frame].origin fromRect:[child
bounds] operation:NSCompositeSourceOver fraction:1.0];
// Clean up
[NSGraphicsContext restoreGraphicsState];
[subviewImage release];
}
}
The last affine transform seems to be needed to unflip text but I don't
quite know why or what transform I should be using. Any help is
appreciated!
Cheers,
DW
________________________________________________________________________________
CV4k 50MB, 4u @L;s ?k7. 0m9N>x4B - >_HD! 8^@O (
http://mail.yahoo.co.kr)
CV=E0n, C_C50n, 0!?d, OST, FK<[, 9BAw:q5p?@ - >_HD! :qF.9Z=: (
http://kr.music.yahoo.com)
CV=E H^4kFy A$:8, :'<R8., D38/EM, 9.@Z8^<<Av - >_HD! 8p9Y@O (
http://kr.mobile.yahoo.com)
_______________________________________________
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.