• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CILinearGradient drawing backwards in 10.5
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CILinearGradient drawing backwards in 10.5


  • Subject: CILinearGradient drawing backwards in 10.5
  • From: Michael Watson <email@hidden>
  • Date: Thu, 1 Nov 2007 13:25:02 -0400

As of Leopard, when I attempt to draw a linear gradient (CILinearGradient) via any kind of context--an NSImage, an NSView drawing itself (flipped or not), etc--the gradient start and end colours are backwards. That is, if I start the gradient at black and end it at white, it will appear on-screen as though I started at white and ended at black. In Tiger, I did not have this problem.

I draw the gradient inside of an NSBezierPath category:

- (void)fillUsingLinearGradientWithStartColour:(NSColor *)startColour startVector:(NSPoint)startVector endColour:(NSColor *)endColour endVector:(NSPoint)endVector
{
NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
NSRect pathBounds;
CIColor *ciStartColour;
CIColor *ciEndColour;
CIVector *ciStartVector;
CIVector *ciEndVector;
CIFilter *gradientFilter;
CIImage *gradientImage;
CIContext *ciGraphicsContext;

pathBounds = [self bounds];

// convert colour space of NSColors
// core image expects calibrated RGB colours
startColour = [startColour colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
endColour = [endColour colorUsingColorSpaceName:NSCalibratedRGBColorSpace];

// convert NSColors to CIColors
ciStartColour = [CIColor colorWithRed:[startColour redComponent] green:[startColour greenComponent] blue:[startColour blueComponent] alpha:[startColour alphaComponent]];
ciEndColour = [CIColor colorWithRed:[endColour redComponent] green: [endColour greenComponent] blue:[endColour blueComponent] alpha: [endColour alphaComponent]];

// create CIVectors from the NSPoints
ciStartVector = [CIVector vectorWithX:startVector.x Y:startVector.y];
ciEndVector = [CIVector vectorWithX:endVector.x Y:endVector.y];

// create and configure the gradient filter
gradientFilter = [CIFilter filterWithName:@"CILinearGradient"];
[gradientFilter setDefaults];
[gradientFilter setValue:ciStartColour forKey:@"inputColor0"];
[gradientFilter setValue:ciStartVector forKey:@"inputPoint0"];
[gradientFilter setValue:ciEndColour forKey:@"inputColor1"];
[gradientFilter setValue:ciEndVector forKey:@"inputPoint1"];

// extract the CIImage from the filter pipeline
gradientImage = [gradientFilter valueForKey:@"outputImage"];

// save the current graphics state and push a new drawing context onto the stack
[currentContext saveGraphicsState];

// obtain the current graphics context
ciGraphicsContext = [currentContext CIContext];

// clip the context to the bezier path
[self addClip];

// draw into the current graphics context
[ciGraphicsContext drawImage:gradientImage atPoint:CGPointMake (pathBounds.origin.x, pathBounds.origin.y) fromRect:CGRectMake (pathBounds.origin.x, pathBounds.origin.y, pathBounds.size.width, pathBounds.size.height)];

// restore previous graphics state
[currentContext restoreGraphicsState];
}


What am I doing incorrectly that just happens to work in Tiger, but not in Leopard? If I'm drawing an image that an NSView renders, or using this code with an NSView that's drawing itself, it doesn't seem to make a difference if the view is flipped or not. The gradient is always "backwards".



--
mikey-san



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: CILinearGradient drawing backwards in 10.5
      • From: Wade Tregaskis <email@hidden>
  • Prev by Date: Core Animation: Layer vs NSTextView
  • Next by Date: Re: Error (1000) creating CGSWindow
  • Previous by thread: Re: Core Animation: Layer vs NSTextView
  • Next by thread: Re: CILinearGradient drawing backwards in 10.5
  • Index(es):
    • Date
    • Thread