Re: Obtaining the NSGraphicsContext for custom NSView
Re: Obtaining the NSGraphicsContext for custom NSView
- Subject: Re: Obtaining the NSGraphicsContext for custom NSView
- From: Serge Meynard <email@hidden>
- Date: Mon, 14 Mar 2005 14:12:45 -0500
I've already got the appropriate coordinates for my view. The problem
is that the method to draw the graphic takes those coordinates and
applies them to the main window instead of the view, that is (I think)
it's drawing in the window's context, not the view's, because if I
hard-code the coordinates to draw at the appropriate coordinates
(using the window's coordinate system), the graphic is drawn under the
custom view and is not visible.
Here's the code I'm using.
- (void)drawPlayHeadAtX:(float)xCoord
Y:(float)yCoord
{
// Graphic will always be drawn at y = 8 of the custom view.
NSPoint mouseLoc = NSMakePoint(xCoord, 8.0f);
NSLog (@"mouseLoc: %f, %f", mouseLoc.x, mouseLoc.y);
[playHead dissolveToPoint:mouseLoc
fraction:1.0f];
[self setNeedsDisplay:YES];
}
Try locking the focus on your view before you draw, since you're not
inside a drawRect: method:
{
// Graphic will always be drawn at y = 8 of the custom view.
NSPoint mouseLoc = NSMakePoint(xCoord, 8.0f);
[self lockFocus];
[playHead dissolveToPoint:mouseLoc fraction:1.0f];
[self unlockFocus];
[self setNeedsDisplay:YES];
}
Or better yet, use the mouseDown method to set up a local variable, and
do the drawing of the playhead inside the drawRect: method. It's easier
to figure out display problems when all the drawing code is in the same
place.
_______________________________________________
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