On Fri, Jul 25, 2008 at 10:16 AM, Keith Duncan <[EMAIL PROTECTED]> wrote:
> Here's the code:
>
> //  Created by Sean Patrick O'Brien on 4/1/08.
> //  Copyright 2008 MolokoCacao. All rights reserved.
> - (void)fillWithInnerShadow:(NSShadow *)shadow {
>        [NSGraphicsContext saveGraphicsState];
>
>        NSShadow *shadowCopy = [shadow copy];
>
>        NSSize offset = shadowCopy.shadowOffset;
>        CGFloat radius = shadowCopy.shadowBlurRadius;
>
>        NSRect bounds = NSInsetRect(self.bounds, -(ABS(offset.width) +
> radius), -(ABS(offset.height) + radius));
>
>        offset.height += bounds.size.height;
>        shadowCopy.shadowOffset = offset;
>
>        NSAffineTransform *transform = [NSAffineTransform transform];
>        [transform translateXBy:0 yBy:([[NSGraphicsContext currentContext]
> isFlipped] ? 1 : -1) * bounds.size.height];
>
>        NSBezierPath *drawingPath = [NSBezierPath bezierPathWithRect:bounds];
>        [drawingPath setWindingRule:NSEvenOddWindingRule];
>
>        [drawingPath appendBezierPath:self];
>        [drawingPath transformUsingAffineTransform:transform];
>
>        [self addClip];
>        [shadowCopy set];
>
>        [[NSColor blackColor] set];
>        [drawingPath fill];
>
>        [shadowCopy release];
>
>        [NSGraphicsContext restoreGraphicsState];
> }

Since this code doesn't use the shadow for all drawing, it makes
little sense to use the shadow set in the drawing context, since you
have a bunch of drawing that won't use it. Passing the shadow in makes
perfect sense to me.

I don't recommend it, but you *could* refactor this code to use the
currently set shadow. The non-shadowed code can push the graphics
context state, set a no-effect shadow, draw, then pop the state to get
back to the old shadow.

Mike
_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to