Re: NSView puzzle
Re: NSView puzzle
- Subject: Re: NSView puzzle
- From: Graham Cox <email@hidden>
- Date: Fri, 10 Oct 2008 10:05:54 +1100
On 10 Oct 2008, at 7:17 am, DKJ wrote:
- (void)mouseDown:(NSEvent *)ev {
click = [self convertPoint:[ev locationInWindow] fromView:nil];
[self display];
}
Don't call [self display]. Instead, call [self setNeedsDisplay:YES];
While the above will work, it's not the recommended way to update the
view.
- (void)drawRect:(NSRect)rect {
NSImage *board = [[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"chessboard"
ofType:@"tiff"]];
[board drawInRect:[self bounds]
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:0.5];
*** [str drawAtPoint:click withAttributes:dict];
}
This is leaking the 'board' image every time you draw it. You need to
move the loading of the board image elsewhere - the -initWithFrame:
method would probably be a good place - then you can redraw the same
object in -drawRect:
hth,
Graham
_______________________________________________
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