On 06/05/2009, at 4:47 AM, McLaughlin, Michael P. wrote:

In a custom NSBezierView, I fill the view with a background color then set a clip path that will eventually be drawn as a map. I do this so that I can color-code the map (in a complicated way) without "going outside the lines".

If I then draw the map, external boundaries are drawn as half-width lines
because the clip path divides them in half lengthwise.

I cannot just double the line width because there are internal map
boundaries as well so I would like to *remove* the clip path totally.

If I write

[[NSBezierPath new] setClip];

this works perfectly except that I get an error in the Console window which
I would rather avoid.

Is there a recommended way to remove a clip path?

Note: Setting the clip path to a dummy path outside the view does not work
because then the map will not be drawn at all.

Thanks for any tips.


The clip path is part of the graphics state of the context, so to remove a clip path you set you have to save the state prior to setting the clip, then restore it afterwards:

[NSGraphicsContext saveGraphicsState];
[myPath addClip];

// draw stuff

[NSGraphicsContext restoreGraphicsState]; // undoes the -addClip


Note that also, in general when drawing in a view, you should use - addClip rather than -setClip, because the view has already set a clipping path to constrain drawing within its visible frame. Using - addClip takes this into account, -setClip doesn't which would mean you could draw right over the edge of the view.

--Graham




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to