36 - (id)initWithStartingColor:(
CPColor)startingColor endingColor:(
CPColor)endingColor
41 - (id)initWithColors:(CPArray)someColors
43 var count = [someColors count];
48 var distance = 1.0 / (count - 1),
52 for (var i = 0; i < count; i++)
54 [locations addObject:location];
61 - (id)initWithColors:(CPArray)someColors atLocations:(CPArray)someLocations colorSpace:(
CPColorSpace)aColorSpace
63 if (
self = [super
init])
66 cgColors = [someColors arrayByApplyingBlock:function(color)
68 return CGColorCreate(colorSpace, [color components])
77 - (void)drawInRect:(CGRect)rect angle:(
float)angle
82 CGContextClipToRect(ctx, rect);
85 [
self _drawInRect:rect atAngle:angle];
93 - (void)_drawInRect:(CGRect)rect atAngle:(
float)angle
101 angle = ((angle % 360.0) + 360.0) % 360.0;
104 startPoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect));
105 else if (angle < 180.0)
106 startPoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect));
107 else if (angle < 270.0)
108 startPoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect));
110 startPoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect));
124 var radians = PI * angle / 180.0,
125 length = ABS(CGRectGetWidth(rect) * COS(radians)) + ABS(CGRectGetHeight(rect) * SIN(radians));
127 endPoint = CGPointMake(startPoint.x + length * COS(radians),
128 startPoint.y + length * SIN(radians));
130 [
self drawFromPoint:startPoint toPoint:endPoint options:CPGradientDrawsBeforeStartingLocation | CPGradientDrawsAfterEndingLocation];
147 [
self _drawInRect:[aPath
bounds] atAngle:anAngle];
152 - (void)drawFromPoint:(NSPoint)startingPoint toPoint:(NSPoint)endingPoint options:(NSGradientDrawingOptions)options
Used to implement exception handling (creating & raising).
function CGColorSpaceCreateDeviceRGB()
void restoreGraphicsState()
CPGraphicsContext currentContext()
CPGradientDrawsAfterEndingLocation
function CGContextDrawLinearGradient(aContext, aGradient, aStartPoint, anEndPoint, options)
function CGContextRestoreGState(aContext)
CGColorSpace CGColorSpace()
void raise:reason:(CPString aName, [reason] CPString aReason)
id initWithColors:atLocations:colorSpace:(CPArray someColors, [atLocations] CPArray someLocations, [colorSpace] CPColorSpace aColorSpace)
function CGContextSetLineWidth(aContext, aLineWidth)
function CGContextClosePath(aContext)
function CGContextAddPath(aContext, aPath)
id initWithColors:(CPArray someColors)
function CGContextBeginPath(aContext)
CGGradient kCGGradientDrawsBeforeStartLocation
kCGGradientDrawsAfterEndLocation
CPGradientDrawsBeforeStartingLocation
function CGContextSaveGState(aContext)
function CGContextAddRect(aContext, aRect)
function CGGradientCreateWithColors(aColorSpace, colors, locations)