• 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
[SOLVED] Is there a fast NSShadow alternative?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Is there a fast NSShadow alternative?


  • Subject: [SOLVED] Is there a fast NSShadow alternative?
  • From: "Alan Smith" <email@hidden>
  • Date: Wed, 11 Jul 2007 16:55:23 -0400

I have come up with a way to create an inner glow for a NSBezierPath,
it's not very pretty and doesn't work perfectly for all shapes but it
will do for now.

Here is the code:

[NSGraphicsContext saveGraphicsState];

NSBezierPath *shadowPath = [NSBezierPath bezierPathWithRect: rect];
NSAffineTransform *transform = [NSAffineTransform transform];
NSShadow *shadow = [[NSShadow alloc] init];

[shadow setShadowBlurRadius: 105.0];
[shadow setShadowColor: [NSColor greenColor]];
[shadow set];

float lineWidth = 50.0;
NSRect pathBounds = [shadowPath bounds];
NSSize pathSize = pathBounds.size;
NSSize scaledSize = NSMakeSize(pathSize.width + lineWidth,
pathSize.height + lineWidth);
NSPoint pathOrigin = pathBounds.origin;
NSPoint pathOffsetOrigin = NSMakePoint(pathOrigin.x - lineWidth / 2.0,
pathOrigin.y - lineWidth / 2.0);

[transform scaleSize: pathSize toSize: scaledSize];
[transform translatePoint: pathOrigin toPoint: pathOffsetOrigin];

[shadowPath addClip];
[shadowPath setLineWidth: lineWidth];
[shadowPath transformUsingAffineTransform: transform];

[[shadow shadowColor] set];
[shadowPath stroke];

[NSGraphicsContext restoreGraphicsState];

Have fun, Alan

--
// Quotes from Alan Smith -------------------------
"You don't forget, you just don't remember."
"Maturity resides in the mind."
"Silence is the Universe's greatest gift."
"When the World realizes that personal beliefs are not something to
argue or fight over, it shall evolve."
_______________________________________________

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


References: 
 >Is there a fast NSShadow alternative? (From: "Alan Smith" <email@hidden>)
 >Re: Is there a fast NSShadow alternative? (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Re: Setting up a UI where changes are only applied when OK clicked?
  • Next by Date: Re: Setting up a UI where changes are only applied when OK clicked?
  • Previous by thread: Re: Is there a fast NSShadow alternative?
  • Next by thread: Re: Is there a fast NSShadow alternative?
  • Index(es):
    • Date
    • Thread