Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGShading



The best sample code I found for CGShading was "CalendarView": http://developer.apple.com/samplecode/CalendarView/CalendarView.html

All you really need is the code from "ShadeRect.c" and a drawRect (assuming you are using Cocoa) that looks something like:

// Include the code from ShadeRect.c

- (void) drawRect:(NSRect)rect
{
// Shading only works on 10.3 and above (with opacity, at least) and is rather slow unless
// the machine has Quartz Extreme
if (GetOSVersion() >= MAC_OS_X_VERSION_10_3 && hasQuartzExtreme) // or something similar
{
NSRect frame = [self frame];
CGRect cgRect = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);

#ifdef COLOR_SHADING

// Color shading
CGRGB start = { 0.1959, 0.0854, 0.0954 }; // for example
CGRGB end = { 0, 0, 0 };
ShadeRectColor( &start, &end, &cgRect, (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]);

#else

// Grayscale shading
ShadeRect(1.0, 0.0, &cgRect, (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]);

#endif // COLOR_SHADING
}
}

Perry
_______________________________________________
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.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.