Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation NSBezierPath (Additions)
- - (void)fillGradientFrom:(NSColor*)inStartColor to:(NSColor*)inEndColor angle:(float)inAngle {
- CIImage* coreimage;
- inStartColor = [inStartColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
- inEndColor = [inEndColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
- CIColor* startColor = [CIColor colorWithRed:[inStartColor redComponent] green:[inStartColor greenComponent] blue:[inStartColor blueComponent] alpha:[inStartColor alphaComponent]];
- CIColor* endColor = [CIColor colorWithRed:[inEndColor redComponent] green:[inEndColor greenComponent] blue:[inEndColor blueComponent] alpha:[inEndColor alphaComponent]];
- CIFilter* filter;
- filter = [CIFilter filterWithName:@"CILinearGradient"];
- [filter setValue:startColor forKey:@"inputColor0"];
- [filter setValue:endColor forKey:@"inputColor1"];
- CIVector* startVector;
- CIVector* endVector;
- startVector = [CIVector vectorWithX:0.0 Y:0.0];
- endVector = [CIVector vectorWithX:0.0 Y:[self bounds].size.height];
- [filter setValue:startVector forKey:@"inputPoint0"];
- [filter setValue:endVector forKey:@"inputPoint1"];
- coreimage = [filter valueForKey:@"outputImage"];
- [[NSGraphicsContext currentContext] saveGraphicsState];
- CIContext* context;
- context = [[NSGraphicsContext currentContext] CIContext];
- [self setClip];
- [context drawImage:coreimage atPoint:CGPointZero fromRect:
- CGRectMake( 0.0, 0.0, [self bounds].size.width, [self bounds].size.height )];
- [[NSGraphicsContext currentContext] restoreGraphicsState];
- }
- @end
- Use:
- NSColor *startColor = [NSColor colorWithCalibratedRed:0xff/255. green:0xff/255. blue:0xff/255. alpha:1.0];
- NSColor *endColor = [NSColor colorWithCalibratedRed:0x99/255. green:0x99/255. blue:0x99/255. alpha:1.0];
- NSBezierPath *path = [NSBezierPath bezierPathWithRect:eventsFrame];
- [path fillGradientFrom:startColor to:endColor angle:0.0];
Add Comment
Please, Sign In to add comment