• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CALayer graphics context
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: CALayer graphics context
      • From: David Duncan <email@hidden>
References: 
 >CALayer graphics context (From: DKJ <email@hidden>)

  • Prev by Date: Re: NSInMemoryStoreType: Not really "persistent", is it?
  • Next by Date: Re: When does Cocoa fall apart? (Run loops)
  • Previous by thread: CALayer graphics context
  • Next by thread: Re: CALayer graphics context
  • Index(es):
    • Date
    • Thread