Hi,

I'm trying to draw an NSImage (a PNG) in a CALayer. The goal is to create a method that allows me to pass an NSImage as an argument to create a layer-hosting view. I have:


-(id)drawButton: (NSView *)button withImage:(NSImage *)anImage {
...
// image layer
        imageLayer=[CALayer layer];
        [imageLayer drawLayer:imageLayer inContext:ctx];
        imageLayer.masksToBounds=YES;
        [imageLayer addConstraint:[CAConstraint
                                                           
constraintWithAttribute:kCAConstraintMaxY
                                                           
relativeTo:@"superlayer"
                                                           
attribute:kCAConstraintMaxY
                                                           offset:-(height/2)]];
        [imageLayer addConstraint:[CAConstraint
                                                           
constraintWithAttribute:kCAConstraintMidX
                                                           
relativeTo:@"superlayer"
                                                           
attribute:kCAConstraintMidX]];
        
        [titleLayer addSublayer:imageLayer];
        [titleLayer layoutIfNeeded];
...

And I found this snippet in the Core Animation Cookbook:

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
        NSGraphicsContext *nsGraphicsContext;
nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx
                                                                                
                                                   flipped:NO];
        [NSGraphicsContext saveGraphicsState];
        [NSGraphicsContext setCurrentContext:nsGraphicsContext];
        
        // ...Draw content using NS APIs...
        NSRect aRect=NSMakeRect(10.0,10.0,30.0,30.0);
        NSBezierPath *thePath=[NSBezierPath bezierPathWithRect:aRect];
        [[NSColor redColor] set];
        [thePath fill];
        
        [NSGraphicsContext restoreGraphicsState];
}


But I don't know how to get the current CGContextRef for the second parameter.


Thanks in advance.

Brad
_______________________________________________

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