From 20cffaa7fe192dc5d46fb7c8da54a1be676c8da6 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sun, 11 Mar 2012 14:07:17 +0000 Subject: [PATCH] Fix CPGradient angle. --- AppKit/CPGradient.j | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/AppKit/CPGradient.j b/AppKit/CPGradient.j index bab82da0f..76230648c 100644 --- a/AppKit/CPGradient.j +++ b/AppKit/CPGradient.j @@ -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. */ @@ -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); - CGContextRestoreGState(ctx); - //[self drawFromPoint:rect.origin toPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect)) options: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]; + + // TODO kCGGradientDrawsBeforeStartLocation and kCGGradientDrawsAfterEndLocation are not actually supported + // by CGContextDrawLinearGradient yet. + CGContextDrawLinearGradient(ctx, _gradient, startingPoint, endingPoint, options); } @end