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 (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 arch...@mail-archive.com

Reply via email to