• 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: NSTextView subclass redrawing weirdness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextView subclass redrawing weirdness


  • Subject: Re: NSTextView subclass redrawing weirdness
  • From: Antonio Nunes <email@hidden>
  • Date: Sun, 9 Jul 2006 08:46:25 +0100

On 9 Jul 2006, at 02:07, John Cassington wrote:

I have created a subclass of on NSTextView so that I can add a 1 pixel
border around the edge of it. This is working, but it seems to be getting
darker every time i do something that causes a redraw (such as hitting
enter).
[...]
-(void)drawRect:(NSRect)rect {
NSRect wholeRect = [self bounds];
NSRect textRect = NSMakeRect(wholeRect.origin.x +1,wholeRect.origin.y+1,
wholeRect.size.width-2,wholeRect.size.height-2);


   [[NSColor blackColor] set];
   [NSBezierPath setDefaultLineWidth:1];
   [NSBezierPath strokeRect:wholeRect];

   [super drawRect:textRect];
}

Hi John,

The progressive darkening is the result of accumulated anti-aliased drawing. The first time the frame is drawn it isn't the color you specified anyway because of anti-aliasing. Did you notice that? Unless you want gray in which case that is the color you should specify. So you should clear the rect before drawing it again (see NSEraseRect). But you can get the result you want also without using an NSBezierPath. Try this:

-(void)drawRect:(NSRect)rect {
	NSRect wholeRect = [self bounds];
	NSRect textRect = NSInsetRect(wholeRect,1,1);

	[[NSColor blackColor] set];  // or grayColor if that's what you want
	NSFrameRect(wholeRect);

	[super drawRect:textRect];
}

Looks OK to me.

Cheers,
António Nunes

-----------------------------------------
Accepting others as they are
brings a wonderful freedom
to your own mind.

--The Peace Formula
-----------------------------------------




_______________________________________________ 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
References: 
 >NSTextView subclass redrawing weirdness (From: "John Cassington" <email@hidden>)

  • Prev by Date: Determining login privileges
  • Next by Date: Re: Determining login privileges
  • Previous by thread: NSTextView subclass redrawing weirdness
  • Next by thread: crash in [NSAnimation _stopAnimation:]
  • Index(es):
    • Date
    • Thread