On Oct 23, 2008, at 9:11 PM, Ken Ferry wrote:
Last, you might be interested in -[NSView cacheDisplayInRect:toBitmapImageRep:] as an alternate way of accomplishing the end goal. Take a gander at the 10.4 AppKit release notes, that have an explanatory section on this method. Search for "NSView Drawing Redirection API" at <http://developer.apple.com/releasenotes/Cocoa/AppKitOlderNotes.html >.

OK, I thought this was what I wanted, but I seem to be having a problem that I don't fully understand.

I have 2 views, "viewToReflect", and "reflectionView" (which shows the reflection of viewToReflect), both subclasses of NSView. In each class, I have an outlet to the other. In reflectionView, I have an NSBitmapImageRep* ("reflectedImage") member.

When viewToReflect gets redrawn, I tell reflectionView that it needs to update itself:

[reflectionView setNeedsDisplay];

In reflectionView's -drawRect:, I create the NSBitmapImageRep instance and I initialize it as those release notes state:

reflectedImage = [viewToReflect bitmapImageRepForCachingDisplayInRect: [viewToReflect bounds]]; NSGraphicsContext *bitmapGraphicsContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:reflectedImage];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:bitmapGraphicsContext];
[[NSColor clearColor] set];
NSRectFill(NSMakeRect(0, 0, [reflectedImage size].width, [reflectedImage size].height));
[NSGraphicsContext restoreGraphicsState];

and then I call

[viewToReflect cacheDisplayInRect:[viewToReflect bounds] toBitmapImageRep:reflectedImage];

This causes a recursion cycle to start; upon calling this cacheDisplayInRect:... method, I ended up being put back at the top of reflectionView's -drawRect:, even though it's viewToReflect that should be getting redrawn. I assumed I would go back through the viewToReflect's -drawRect, but that is not happening (I have a breakpoint there, and it's not getting hit after this call, while the reflectionView's -drawRect: breakpoint IS getting hit). Here's a stack trace snippet:

...repeat lines 15-19 ad infinitum (as long as I keep continuing)
#15 0x0002a8b8 in -[CardReflectionView drawRect:] at CardReflectionView.m:29 #16 0x903e2eb2 in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inContext:topView:] #17 0x903e324a in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inContext:topView:]
#18 0x903e27db in -[NSView displayRectIgnoringOpacity:inContext:]
#19 0x90489c0c in -[NSView cacheDisplayInRect:toBitmapImageRep:]
#20 0x0002a8b8 in -[CardReflectionView drawRect:] at CardReflectionView.m:29 #21 0x903e2eb2 in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inContext:topView:] #22 0x903e324a in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inContext:topView:]
#23 0x903e27db in -[NSView displayRectIgnoringOpacity:inContext:]
#24 0x90489c0c in -[NSView cacheDisplayInRect:toBitmapImageRep:]
#25 0x0002a8b8 in -[CardReflectionView drawRect:] at CardReflectionView.m:29
#26 0x90399984 in -[NSView _drawRect:clip:]

cacheDisplayInRect:... sure seemed like what I want to do, and going over it again (and again, and again...) it sure seems logical, but obviously I'm missing something rather important. Anyone care to point what exactly what that might be to me?

Thanks!
randy
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to