Re: NSView Background
Re: NSView Background
- Subject: Re: NSView Background
- From: Shawn Erickson <email@hidden>
- Date: Wed, 7 Jan 2004 09:28:23 -0800
On Jan 7, 2004, at 6:03 AM, Nicko van Someren wrote:
On 7 Jan 2004, at 13:49, lbland wrote:
On Jan 6, 2004, at 8:17 PM, Matt Gemmell wrote:
You can create a subclass of NSView and in its drawRect: method, use
code something like this:
[[NSColor blackColor] set];
NSRectFill(rect);
/* where rect is the NSRect passed to the drawRect: method. */
ouch!
try this instead:
[[NSColor blackColor] set];
NSRectFill([self bounds]);
because /* where rect is the NSRect passed to the drawRect: method.
*/ can be anything.
Will the rectangle that is passed to a view's drawRect: method ever
extend outside the bounds of the view? I thought it was already
clipped to be within the view. If it is then you're better off using
the first code since the later code will usually be trying to (a)
paint a strict subset and (b) only paint where it's not going to be
clipped anyway.
Actually if on panther or later the "best way" to do the above is as
follows (written in Mail.app)...
@interface MYView : NSView
@end
@implementation MYView
- (void)drawRect:(NSRect)rect {
const NSRect *rects;
int index, count;
[[NSColor blackColor] set];
[self getRectsBeingDrawn:&rects count:&count];
for (index = 0; index < numRects; index++) {
NSRectFill(rects[index]);
}
}
- (BOOL) isOpaque {
return YES:
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.