2016-10-26 21:14:02 +00:00
|
|
|
#import "GBColorCell.h"
|
|
|
|
|
|
|
|
static inline double scale_channel(uint8_t x)
|
|
|
|
{
|
2022-02-13 14:58:44 +00:00
|
|
|
x &= 0x1F;
|
2016-10-26 21:14:02 +00:00
|
|
|
return x / 31.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@implementation GBColorCell
|
|
|
|
{
|
|
|
|
NSInteger _integerValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setObjectValue:(id)objectValue
|
|
|
|
{
|
|
|
|
_integerValue = [objectValue integerValue];
|
2020-06-09 22:10:11 +00:00
|
|
|
uint8_t r = _integerValue & 0x1F,
|
|
|
|
g = (_integerValue >> 5) & 0x1F,
|
|
|
|
b = (_integerValue >> 10) & 0x1F;
|
|
|
|
super.objectValue = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"$%04x", (uint16_t)(_integerValue & 0x7FFF)] attributes:@{
|
2021-10-26 22:43:36 +00:00
|
|
|
NSForegroundColorAttributeName: r * 3 + g * 4 + b * 2 > 120? [NSColor blackColor] : [NSColor whiteColor],
|
|
|
|
NSFontAttributeName: [NSFont userFixedPitchFontOfSize:12]
|
2020-06-09 22:10:11 +00:00
|
|
|
}];
|
2016-10-26 21:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)integerValue
|
|
|
|
{
|
|
|
|
return _integerValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)intValue
|
|
|
|
{
|
|
|
|
return (int)_integerValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSColor *) backgroundColor
|
|
|
|
{
|
2021-10-26 22:43:36 +00:00
|
|
|
/* Todo: color correction */
|
2016-10-26 21:14:02 +00:00
|
|
|
uint16_t color = self.integerValue;
|
|
|
|
return [NSColor colorWithRed:scale_channel(color) green:scale_channel(color >> 5) blue:scale_channel(color >> 10) alpha:1.0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)drawsBackground
|
|
|
|
{
|
2021-10-23 10:36:58 +00:00
|
|
|
return true;
|
2016-10-26 21:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|