• 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
Custom view, drawRect, clip?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom view, drawRect, clip?


  • Subject: Custom view, drawRect, clip?
  • From: Martin <email@hidden>
  • Date: Mon, 4 Feb 2008 19:45:16 +0100

Hi,

I have a custom view in which I do my drawing in the -(void)drawRect: (NSRect)rect method. For a start, I just want to draw a huge gradient in that view. So I just do:
- (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. If I keep the previous version of drawRect, the result produced is not what I want: since fancyGradient is computed for rect, with rect being smaller that my view's frame, a small gradient is overlayed on top of the big one.

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?

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]?

Thanks,
Martin.


_______________________________________________

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


  • Follow-Ups:
    • Re: Custom view, drawRect, clip?
      • From: "I. Savant" <email@hidden>
  • Prev by Date: NSDrawerOpeningState woes
  • Next by Date: Re: IKImageBrowserView cellSpacing
  • Previous by thread: Re: NSDrawerOpeningState woes
  • Next by thread: Re: Custom view, drawRect, clip?
  • Index(es):
    • Date
    • Thread