Re: how to clip inside a path
Re: how to clip inside a path
- Subject: Re: how to clip inside a path
- From: Corbin Dunn <email@hidden>
- Date: Mon, 29 Oct 2012 16:04:28 -0700
On Oct 29, 2012, at 3:47 PM, Graham Cox <email@hidden> wrote:
> I have the following method in a category on NSBezierPath, which seems to be what you want, and works in the same way as -addClip:
>
>
> - (void) addInverseClip
Please don't add generic category names to standard appkit classes (like NSBezierPath). This could easily conflict with potential names we add in the future. Either don't use a category, or use a unique prefix for your method names.
corbin
> // this is similar to -addClip, except that it excludes the area bounded by the path instead of includes it. It works by combining this path
> // with the existing clip area using the E/O winding rule, then setting the result as the clip area. This should be called between
> // calls to save and restore the gstate, as for addClip.
>
> CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
> CGRect cbbox = CGContextGetClipBoundingBox( context );
>
> NSBezierPath* cp = [NSBezierPath bezierPathWithRect:*(NSRect*)&cbbox];
> [cp appendBezierPath:self];
> [cp setWindingRule:NSEvenOddWindingRule];
> [cp addClip];
> }
>
>
>
> --Graham
>
>
>
>
> On 30/10/2012, at 12:22 AM, Roland King <email@hidden> wrote:
>
>> I have a graphics context and a path and I want to clip everything inside the path, ie not display it, and leave everything outside the path displayed. The path is simple and doesn't cross itself, for sake of example it may as well be a circle. If I start with a clip-free GC and set that circle as a clipping path, I'll get the opposite, everything in the circle will show, how do I do the other way around? Does it work if I set a path at the bound rect of the GC plus my shape in the middle? That would seem to have two crossings to get into the shape, one at the bounds of the rect, one as you cross the shape, which should mean everything inside the shape is 'outside' but does a path at the very extremities of the GC, or even outside it, count as 'crossed'?
>>
>> The more I think about it, the more clipping sounds hard to implement
>
> _______________________________________________
>
> 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
_______________________________________________
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