Re: Reverse-engineering Apple's two-tinted gradient NSViews
Re: Reverse-engineering Apple's two-tinted gradient NSViews
- Subject: Re: Reverse-engineering Apple's two-tinted gradient NSViews
- From: "email@hidden" <email@hidden>
- Date: Thu, 22 Jan 2009 13:24:00 +0000
On 22 Jan 2009, at 12:57, Sam Krishna wrote:
I think my understanding of NSGradient's use may be off here....
I'm trying to create a custom NSView that uses NSGradient to shade
the view in such a way that it mimics Apple's two-tints NSView. You
can see the color scheme at the bottom left hand corner of Mail and
the NSView at the bottom of Automator (I'm sure there are other
apps, but I can't figure out which ones they are).
Here's the code I'm using for -drawRect:
- (void)drawRect:(NSRect)rect {
// Drawing code here.
NSArray *_colorArray = [NSArray arrayWithObjects:
[NSColor colorWithDeviceRed:0.9843 green:
0.9843 blue:0.9843 alpha:1.0],
[NSColor colorWithDeviceRed:0.9608 green:
0.9608 blue:0.9608 alpha:1.0],
[NSColor colorWithDeviceRed:0.8824 green:
0.8824 blue:0.8824 alpha:1.0],
nil];
NSGradient *_gradient = [[NSGradient alloc]
initWithColors:_colorArray];
[_gradient drawInRect:rect angle:90];
[_gradient release];
}
What is the result of running this code presently?
I use the following code to draw a two tone gradient.
I always draw the entire bounds rather than the rect parameter (which
is only telling you the part of the view that has been invalidated).
There is also an IB framework that implements this view rendering -
perhaps someone else on the list recalls the name.
- (void)drawRect:(NSRect)rect {
rect = [self bounds];
NSGraphicsContext* gc = [NSGraphicsContext currentContext];
[gc setShouldAntialias:NO];
// gradient
NSBezierPath *bgPath = [NSBezierPath bezierPathWithRect:rect];
NSColor *endColor = self.endColor;
NSColor *startColor = self.startColor;
NSGradient *gradient = [[NSGradient alloc]
initWithStartingColor:startColor endingColor:endColor];
[gradient drawInBezierPath:bgPath angle:90.0];
}
Am I using the right NSGradient method? Is it the right angle?
I tried using -drawFromPoint:toPoint:options:, but that didn't work,
either. Any ideas?
Live Playfully,
Sam
-----
If he listens in faith,
finding no fault, a man is free
and will attain the cherished words
of those who act in virtue.
_______________________________________________
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
Jonathan Mitchell
Central Conscious Unit
http://www.mugginsoft.com
_______________________________________________
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