-
Notifications
You must be signed in to change notification settings - Fork 610
Pass alpha value from the color panel to the embedder. #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ - (void)handleMethodCall:(FLEMethodCall *)call result:(FLEMethodResult)result { | |
if ([call.methodName isEqualToString:@(plugins_color_panel::kShowColorPanelMethod)]) { | ||
if ([call.arguments isKindOfClass:[NSDictionary class]]) { | ||
BOOL showAlpha = | ||
[[call.arguments valueForKey:@(plugins_color_panel::kColorPanelShowAlpha)] boolValue]; | ||
[[call.arguments valueForKey:@(plugins_color_panel::kColorPanelShowAlpha)] boolValue]; | ||
[self showColorPanelWithAlpha:showAlpha]; | ||
} else { | ||
NSLog(@"Malformed call for %@. Expected an NSDictionary but got %@", | ||
|
@@ -112,9 +112,12 @@ - (void)selectedColorDidChange { | |
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't seem to add a review comment above this context line, so arbitrarily adding here: while you are here, please fix the indentation on line 38 (should be indented 4 more). I had a specific comment about this when I approved the previous change (thus the mention of re-running clang-format) but apparently didn't save it so it wasn't part of the approval comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah not sure what happened there. I saw your comment and ran the clang-format. Might've undone the change by mistake. Anyway, it's done now :) |
||
- (NSDictionary *)dictionaryWithColor:(NSColor *)color { | ||
NSMutableDictionary *result = [NSMutableDictionary dictionary]; | ||
result[@(plugins_color_panel::kColorComponentRedKey)] = @(color.redComponent); | ||
result[@(plugins_color_panel::kColorComponentGreenKey)] = @(color.greenComponent); | ||
result[@(plugins_color_panel::kColorComponentBlueKey)] = @(color.blueComponent); | ||
// TODO: Consider being able to pass other type of color space (Gray scale, CMYK, etc). | ||
NSColor *rgbColor = [color colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary now? Is it just to handle asking for the alpha when showing alpha is false (in which case, a conditional would handle it) or are there other cases that are broken? Messing with color space makes me nervous, since it's not clear to me that this is actually going to give the same color the user intended to pick in all configurations. (It may be, but I'm not even close to an expert on color spaces; I just know enough to know that it's easy to get them wrong.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prevents crashes if the NSColor passed in is not an rgb color. I believe this converts the color to the proper color space (generic) for data representation. However, if you want the color to display accurately it should be converted to NSCalibratedRGBColorSpace (https://stackoverflow.com/questions/37307113/swift-why-nscolor-becomes-lighter-when-rendered). #0000FF -> NSColor.NSCalibratedRGBColorSpace -> screen (shows #0000FF) I'm not 100% sure about this next part but I'm assuming: I couldn't find any information online that explains/proves the reverse conversion. Though it should be relatively easy to pull up xcode to double check this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, there was actually a bug. If you choose a color from the Gray scale slider or CYMK, it raises an exception. As @izackp mentions, it prevents the exception, and it corresponds to the calibrated space. Per the genericRGBColorSpace documentation: |
||
result[@(plugins_color_panel::kColorComponentAlphaKey)] = @(rgbColor.alphaComponent); | ||
result[@(plugins_color_panel::kColorComponentRedKey)] = @(rgbColor.redComponent); | ||
result[@(plugins_color_panel::kColorComponentGreenKey)] = @(rgbColor.greenComponent); | ||
result[@(plugins_color_panel::kColorComponentBlueKey)] = @(rgbColor.blueComponent); | ||
return result; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
false
is passed for showing alpha, do both the macOS and Linux implementations send back 255 so that this will behave correctly when it's false?It seems like either:
Either way, channel_constants.h should document it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the slider is not shown, alpha is always 1. Added a comment in channel_constants.h