Re: CALayer graphics context
Re: CALayer graphics context
- Subject: Re: CALayer graphics context
- From: Patrick Mau <email@hidden>
- Date: Wed, 22 Oct 2008 17:00:40 +0200
Hi dkj
A CALayer itself is not associated with a context. The NSView owns the
graphics context.
The context you are looking for is passed to the "drawLayer:inContext"
message.
Simply set a delegate of your layer and send 'setNeedsDisplay' once to
setup
your content. Here's an example:
- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
NSString *imgName = [[NSBundle mainBundle]
pathForImageResource:@"Rocks"];
NSImage *img = [[[NSImage alloc] initWithContentsOfFile:imgName]
autorelease];
NSGraphicsContext *gc = [NSGraphicsContext
graphicsContextWithGraphicsPort:ctx flipped:NO];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:gc];
[img drawInRect:NSRectFromCGRect(layer.bounds)
fromRect:NSMakeRect(0.0, 0.0, [img size].width, [img size].height)
operation:NSCompositeCopy
fraction:1.0];
[NSGraphicsContext restoreGraphicsState];
}
Best Regards,
Patrick
On 22.10.2008, at 16:53, DKJ wrote:
Is there a quick way to get a CGContextRef for a CALayer? I don't
see anything obvious in the documentation for the CALayer class.
dkj
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden