• 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: NSView puzzle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSView puzzle (From: DKJ <email@hidden>)

  • Prev by Date: Re: NSView puzzle
  • Next by Date: Strategy for naming support folder
  • Previous by thread: Re: NSView puzzle
  • Next by thread: Inconsistent HTML text size in TextField
  • Index(es):
    • Date
    • Thread