Re: +[NSColor highlightColor] returns white instead of actual color
Re: +[NSColor highlightColor] returns white instead of actual color
- Subject: Re: +[NSColor highlightColor] returns white instead of actual color
- From: Ken Ferry <email@hidden>
- Date: Sun, 1 Feb 2009 14:30:16 -0800
Hi jerry,
My memory is that this is the alternateSelectedControlColor. I'm not
at a mac right now, so I cannot verify.
-Ken
On Feb 1, 2009, at 6:46 AM, Jerry Krinock <email@hidden> wrote:
Sorry, there's more to this....
+[NSColor selectedTextBackgroundColor] definitely gives a color
based on System Preferences > Appearance > Highlight Color (for
selected text). However, the color actually used in NSTableView is
darker than this.
For example, I set the color in System Preferences to RGB = {255, 0,
255}, but when I use DigitalColor Meter.app on a highlighted cell in
a "stock" NSTableView, I measure {204, 0, 204}. Now, 204=51*4 and
255=51*5. So it looks like someone in the NSTextFieldCell
Department decided to reduce the brightness by 20%, because, of
course, if someone set their "highlight" (sic) color to all white,
the white text drawn on it by NSTextFieldCell would be invisible.
So, I was able to match the "stock" NSTextFieldCell using a little
brightness-tweaking method that I had lying around. Is this 20%
reduction in brightness documented anywhere? I even searched Human
Interface Guldelines for "highlight" but didn't find any mention of
this.
Interestingly, in NSTextViews (TextEdit docs, this message in
Mail.app), the text is drawn in black instead of white, and the 20%
reduction is not applied. And then, Xcode's editor ignores my
System Preferences and uses black on orange, like it or not. Seems
like we need some User Interface Police here.
***************************************************
color = [NSColor selectedTextBackgroundColor] ;
color = [color colorTweakBrightness:-.20] ;
***************************************************
#import <Cocoa/Cocoa.h>
@interface NSColor (Tweak)
/*!
@brief Returns a copy of the receiver, but with the
brightness altered by a given tweak factor.
@details If tweak > 0, the brightness is altered by
blending the receiver with +tweak fraction of pure white.
If tweak < 0, the brightness is altered by
blending the receiver with -tweak fraction of pure black.
if tweak = 0, the returned color will be an identical copy of
the receiver.
@param tweak The factor by which to tweak the brightness.
A value greater than +1.0 is clipped to +1.0.
A value less than -1.0 is clipped to -1.0.
@result A tweaked, autoreleased copy of the receiver
*/
- (NSColor*)colorTweakBrightness:(float)tweak ;
@end
***************************************************
#import "NSColor+Tweak.h"
@implementation NSColor (Tweak)
- (NSColor*)colorTweakBrightness:(float)tweak {
SEL blendColorSelector = (tweak > 0) ? @selector(whiteColor) :
@selector (blackColor) ;
NSColor* blendColor = [NSColor
performSelector:blendColorSelector] ;
float blend = fabs(tweak) ;
blend = MIN(blend, 1.0) ;
return [self blendedColorWithFraction:(CGFloat)blend
ofColor:blendColor] ;
}
@end
_______________________________________________
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
_______________________________________________
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