• 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: Attempting to draw upon a CGLayer upon a NSView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Attempting to draw upon a CGLayer upon a NSView


  • Subject: Re: Attempting to draw upon a CGLayer upon a NSView
  • From: "Frederick C. Lee" <email@hidden>
  • Date: Fri, 10 Mar 2006 20:25:21 -0800

Thanks for replying.

I'm still having a problem connecting the CGLayer to the GUI for human interaction.

1) I've created the CGLayer (via context) within the subView's initWithFrame; and created the Layer's Context:

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];

if (self) {
bezierPath = [[NSBezierPath bezierPath] retain];
CGSize layerSize = CGSizeMake(frame.size.width, frame.size.height);
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
layer = CGLayerCreateWithContext(context, layerSize, NULL);


if (layer != NULL) {
// Get the context corresonding to the layer.
drawingLayerContext = CGLayerGetContext(layer);
}
}
return self;
}
...
==========
2) Making the Drawing Layer Context the 'current' context.
Note: *** I'm having trouble converting Quartz context --> Cocoa context: ***


- (void)mouseDown:(NSEvent *)theEvent {
// Need to make the drawing Context current:
[NSGraphicsContext setCurrentContext:(NSGraphicsContext *) drawingLayerContext]; <-- problem.
...
[bezierPath moveToPoint:loc];
}


The result here:
2006-03-10 ... -[NSCFType isDrawingToScreen]: selector not recognized [self = 0x3bb110]
2006-03-10 ... No current point for line


============
3) Attempting to draw an overlay (I'm assuming 'drawingLayerContext' is the current context):


- (void)mouseDragged:(NSEvent *)theEvent {
   ...
    [bezierPath lineToPoint:loc];
    [self setNeedsDisplay:YES];
}

============
3a) Thinking of resetting context to the image-layer here:

- (void)mouseUp:(NSEvent *)theEvent {
    NSLog(@"{mouseUp}");
}

============
4) Render the Drawing:
- (void)drawRect:(NSRect)rect {
    [super drawRect:rect];

// Base Layer here
if (nil != [self image]) {
// Draw the Map image to the screen
[[self image] compositeToPoint:([self bounds].origin) operation:NSCompositeSourceOver];
}


   // Drawing Layer Here.
    [[NSColor redColor] set];
    [bezierPath stroke];

    CGContextDrawLayerAtPoint(drawingLayerContext, CGPointZero, layer);

}

I tried doing the [NSGraphicsContext saveGraphicsState] & [NSGraphicsContext restoreGraphicsState]
in the mouseDown()/mouseDragged() but they froze the display.


Am I on the right tack?
How do I convert Quartz context to Cocoa Context?


Ric.



On Mar 7, 2006, at 5:38 PM, Scott Thompson wrote:

First of all, you never create a CGLayer. You would have to create it using CGLayerCreateWithContext. After creating the layer, you could draw into it in the mouseDown routine if you wanted to by getting it's CGContext (CGLayerGetContext) and making that the current context using the methods of NSGraphicsContext.

Then in your drawRect routine you would draw the image and then draw the layer using CGContextDrawLayerAtPoint.

_______________________________________________ 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
References: 
 >Attempting to draw upon a CGLayer upon a NSView (From: "Frederick C. Lee" <email@hidden>)
 >Re: Attempting to draw upon a CGLayer upon a NSView (From: Scott Thompson <email@hidden>)

  • Prev by Date: NSPredicate and NSMetadataQuery
  • Next by Date: NSTextFieldCell and vertical alignment
  • Previous by thread: Re: Attempting to draw upon a CGLayer upon a NSView
  • Next by thread: Re: Attempting to draw upon a CGLayer upon a NSView
  • Index(es):
    • Date
    • Thread