Attempting to draw upon a CGLayer upon a NSView
Attempting to draw upon a CGLayer upon a NSView
- Subject: Attempting to draw upon a CGLayer upon a NSView
- From: "Frederick C. Lee" <email@hidden>
- Date: Mon, 6 Mar 2006 21:44:35 -0800
Desired Scenario:
Customize NSView that receives an image and a CGLayer to draw
upon that image.
1) I created a CGLayer context and loaded it into the customize
NSView via an accessor.
2) I load an Image into this view. <-- okay.
3) I can also draw in this view (but not over the image).
Problem: I can't create a layer to draw upon. I tried merely to
dump 'Dark Green'
upon the layer to see if it works. It doesn't.
What am I messing here?
The following is a code snippet from a customized sub-NSView:
...
...
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
bezierPath = [[NSBezierPath bezierPath] retain];
}
return self;
}
- (void) dealloc {
CFRelease(contextRef);
[bezierPath release];
[super dealloc];
}
// ---------------------------------
- (void)setDrawContext:(CGContextRef)inContextRef {
contextRef = (CGContextRef) CFRetain(inContextRef);
}
- (CGContextRef)contextRef {
return contextRef;
}
// ---------------------------------
- (void)setImage:(NSImage *)newImage {
NSImage *temp = [newImage retain];
[_myImage release];
_myImage = temp;
[self setFrameSize:[_myImage size ]];
[self setNeedsDisplay:YES];
}
- (NSImage *)image {
return _myImage;
}
// ---------------------------------
- (void)drawRect:(NSRect)rect {
[super drawRect:rect];
[[NSColor redColor] set];
[bezierPath stroke];
if (nil != [self image])
[[self image] compositeToPoint:([self bounds].origin)
operation:NSCompositeSourceOver];
}
// ---------------------------------
- (void)mouseDown:(NSEvent *)theEvent {
CGContextSaveGState(contextRef);
CGContextSetFillColorWithColor
(contextRef,getRGBOpaqueDarkGreenColor()); <-- doesn't work
CGContextRestoreGState(contextRef);
NSPoint loc = [theEvent locationInWindow];
loc.x -= [self frame].origin.x;
loc.y -= [self frame].origin.y;
[bezierPath moveToPoint:loc];
}
...
...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden