Use skia color helpers

This commit is contained in:
Kevin Sawicki 2017-02-27 12:05:44 -08:00
parent eff49ad19c
commit b16d649819

View file

@ -459,10 +459,8 @@ bool ScopedDisableResize::disable_resize_ = false;
- (void)colorPickerAction:(id)sender { - (void)colorPickerAction:(id)sender {
NSString* item_id = ((NSColorPickerTouchBarItem *)sender).identifier; NSString* item_id = ((NSColorPickerTouchBarItem *)sender).identifier;
NSColor* color = ((NSColorPickerTouchBarItem *)sender).color; NSColor* color = ((NSColorPickerTouchBarItem *)sender).color;
NSString* colorHexString = [NSString stringWithFormat:@"#%02X%02X%02X", std::string hex_color = atom::ToRGBHex(skia::NSDeviceColorToSkColor(color));
(int) (color.redComponent * 0xFF), (int) (color.greenComponent * 0xFF), shell_->NotifyTouchBarItemInteraction("color_picker", { std::string([item_id UTF8String]), hex_color });
(int) (color.blueComponent * 0xFF)];
shell_->NotifyTouchBarItemInteraction("color_picker", { std::string([item_id UTF8String]), std::string([colorHexString UTF8String]) });
} }
- (void)sliderAction:(id)sender { - (void)sliderAction:(id)sender {
@ -481,25 +479,8 @@ bool ScopedDisableResize::disable_resize_ = false;
} }
- (NSColor*)colorFromHexColorString:(NSString*)inColorString { - (NSColor*)colorFromHexColorString:(NSString*)inColorString {
NSColor* result = nil; SkColor color = atom::ParseHexColor([inColorString UTF8String]);
unsigned colorCode = 0; return skia::SkColorToCalibratedNSColor(color);
unsigned char redByte, greenByte, blueByte;
if (nil != inColorString)
{
NSScanner* scanner = [NSScanner scannerWithString:inColorString];
(void) [scanner scanHexInt:&colorCode]; // ignore error
}
redByte = (unsigned char)(colorCode >> 16);
greenByte = (unsigned char)(colorCode >> 8);
blueByte = (unsigned char)(colorCode); // masks off high bits
result = [NSColor
colorWithCalibratedRed:(CGFloat)redByte / 0xff
green:(CGFloat)greenByte / 0xff
blue:(CGFloat)blueByte / 0xff
alpha:1.0];
return result;
} }
- (NSButton*)makeButtonForDict:(mate::PersistentDictionary)dict withLabel:(std::string)label { - (NSButton*)makeButtonForDict:(mate::PersistentDictionary)dict withLabel:(std::string)label {