Skip to content

Commit

Permalink
Fix CPGradient angle.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljungberg committed Mar 11, 2012
1 parent ebeb104 commit 20cffaa
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions AppKit/CPGradient.j
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

CPGradientDrawsBeforeStartingLocation = kCGGradientDrawsBeforeStartLocation;
CPGradientDrawsAfterEndingLocation = kCGGradientDrawsAfterEndLocation;

/*!
A class for drawing linear and radial gradients with a convenient API.
*/
Expand Down Expand Up @@ -51,11 +54,20 @@
var ctx = [[CPGraphicsContext currentContext] graphicsPort];

CGContextSaveGState(ctx);
CGContextClipToRect(ctx, rect);
CGContextAddRect(ctx, rect);
CGContextDrawLinearGradient(ctx, _gradient, rect.origin, CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect)), 0);

[self drawFromPoint:rect.origin toPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect)) options:CPGradientDrawsBeforeStartingLocation | CPGradientDrawsAfterEndingLocation];
CGContextRestoreGState(ctx);
}

- (void)drawFromPoint:(NSPoint)startingPoint toPoint:(NSPoint)endingPoint options:(NSGradientDrawingOptions)options
{
var ctx = [[CPGraphicsContext currentContext] graphicsPort];

//[self drawFromPoint:rect.origin toPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect)) options:0];
// TODO kCGGradientDrawsBeforeStartLocation and kCGGradientDrawsAfterEndLocation are not actually supported
// by CGContextDrawLinearGradient yet.
CGContextDrawLinearGradient(ctx, _gradient, startingPoint, endingPoint, options);
}

@end

0 comments on commit 20cffaa

Please sign in to comment.