Drawing in a NSView out side of drawRect
Drawing in a NSView out side of drawRect
- Subject: Drawing in a NSView out side of drawRect
- From: "David Alter" <email@hidden>
- Date: Fri, 19 Dec 2008 16:20:00 -0800
I want to draw in a NSView but not when drawRect is called. To do this I
understand that I need to call lockFocus before drawing and unlockFocus
after. The drawing appears to happen but it is not until I deactivate the
window do I see my results. How can I get it to refresh once I have done my
drawing?
To test this out I have sub classed NSView and overloaded mouseDown. I added
the following code.
- (void)mouseDown:(NSEvent *)theEvent ;
{
NSPoint loc = [[self window] mouseLocationOutsideOfEventStream];
loc = [self convertPoint:loc fromView:[[self window] contentView]];
CGContextRef myContext =
(CGContextRef)[[NSGraphicsContext currentContext]graphicsPort];
[self lockFocus];
CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);
CGContextFillRect (myContext, CGRectMake (loc.x, loc.y, 10, 10 ));
[self unlockFocus];
}
This will draw a box for each mouse click, but not until I deactivate my
window.
thanks for the help
-dave
_______________________________________________
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