Re: Custom view, drawRect, clip?
Re: Custom view, drawRect, clip?
- Subject: Re: Custom view, drawRect, clip?
- From: "I. Savant" <email@hidden>
- Date: Mon, 4 Feb 2008 13:54:56 -0500
> - (void)drawRect:(NSRect)rect {
> [fancyGradient drawInRect:rect angle:270.0];
> }
>
> But then, Cocoa needs to refresh some small parts of that view, so it
> calls drawRect: with rect being much smaller than the view's frame.
The Cocoa Drawing Guide explains the reasons for this in great
detail. The short version: Cocoa only asks you to draw what's "dirty".
It's up to you to give your view intelligence enough to deal with
drawing all or part of itself.
> I have one solution for that problem :
> - (void)drawRect:(NSRect)rect {
> rect.origin.y = 0;
> rect.size.height = [self frame].size.height;
> [fancyGradient drawInRect:rect angle:270.0];
> }
>
> My first question is: is it bad to draw outside the initial rect?
Not at all, but there's an easier way:
- (void)drawRect:(NSRect)rect
{
[fancyGradient drawInRect:[self bounds] angle:270.0];
}
> My second question is: should I create the gradient first, then clip
> it, then draw it? Can I clip NSGradient? (If no, do I have to use
> CGGradient and CoreGraphics instead ?)
>
> My third question is: I have the same problem with a NSBezierPath. How
> do I clip it? What does [myPath addClip] do (yes, I've read the doc,
> so my question is: is clipping path of the current graphic context
> automagically set to rect)? What is the difference with [NSBezierPath
> clipRect:rect]?
Again, read the Cocoa Drawing Guide:
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaDrawingGuide/GraphicsContexts/chapter_3_section_3.html#
The above page covers this in detail.
--
I.S.
_______________________________________________
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