Re: Drawing white text with black shadow?
Re: Drawing white text with black shadow?
- Subject: Re: Drawing white text with black shadow?
- From: David Remahl <email@hidden>
- Date: Tue, 28 May 2002 09:54:17 +0200
>
On the Finder's desktop, file names are drawn white with a dark shadow.
>
>
Is there an easy way to do this?
>
>
-steve
There is a very simple, though unsupported, way of doing that. In fact,
shadowed drawing is part of the graphics state.
To draw shadow, you need to define a few functions that are left out of the
headers (because they're private):
// For drop shadow support. Be aware that this API
// may change/go away in future OSXes.
extern void *CGSReadObjectFromCString(char*);
extern char *CGSUniqueCString(char*);
extern void *CGSSetGStateAttribute(void*,char*,void*);
extern void *CGSReleaseGenericObj(void*);
When you are focused on the view/image you want to target, set the graphics
state like this:
void *r27 = NULL, *r29 = NULL;
[NSGraphicsContext saveGraphicsState];
r27 = CGSReadObjectFromCString((void*)[[NSString stringWithFormat:@"{ Style
= Shadow; Height = %f; Radius = %f; Azimuth = %f; Ka = %f; }", shadowHeight,
shadowRadius, shadowAzimuth, shadowOpacity] cString]);
r29 = [[NSGraphicsContext currentContext] graphicsPort];
CGSSetGStateAttribute(r29, CGSUniqueCString("Style"), r27);
// Do any drawing here
[NSGraphicsContext restoreGraphicsState];
CGSReleaseGenericObj(r27);
ShadowHeight, shadowRadius, shadowAzimuth and shadowOpacity are variables
that you can vary to get different effects.
Be aware that this is unsupported from Apple and may go away in any release.
You should probably do weak linking and check for the presence of the
functions before calling them, and make very sure that r27 is created OK,
etc.
/ Sincerely, David Remahl
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.