UI: Support canceling Eyedropper color picking operations
Have `eyedropper_color_sample_fl` return success, in case platform sampling starts but is canceled (Async return on MacOS). Removes any chance of returning black color on failures. Pull Request: https://projects.blender.org/blender/blender/pulls/133124
This commit is contained in:
committed by
Harley Acheson
parent
4e683c4bd6
commit
96babd5e9f
@@ -891,6 +891,7 @@ GHOST_TSuccess GHOST_SystemCocoa::getPixelAtCursor(float r_color[3]) const
|
||||
@autoreleasepool {
|
||||
NSColorSampler *sampler = [[NSColorSampler alloc] init];
|
||||
__block BOOL selectCompleted = NO;
|
||||
__block BOOL samplingSucceeded = NO;
|
||||
|
||||
[sampler showSamplerWithSelectionHandler:^(NSColor *selectedColor) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)),
|
||||
@@ -904,6 +905,7 @@ GHOST_TSuccess GHOST_SystemCocoa::getPixelAtCursor(float r_color[3]) const
|
||||
r_color[1] = [rgbColor greenComponent];
|
||||
r_color[2] = [rgbColor blueComponent];
|
||||
}
|
||||
samplingSucceeded = YES;
|
||||
}
|
||||
selectCompleted = YES;
|
||||
});
|
||||
@@ -913,8 +915,9 @@ GHOST_TSuccess GHOST_SystemCocoa::getPixelAtCursor(float r_color[3]) const
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
|
||||
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
|
||||
}
|
||||
|
||||
return samplingSucceeded ? GHOST_kSuccess : GHOST_kFailure;
|
||||
}
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_SystemCocoa::setMouseCursorPosition(int32_t x, int32_t y)
|
||||
|
||||
@@ -430,7 +430,7 @@ static bool eyedropper_cryptomatte_sample_fl(bContext *C,
|
||||
return false;
|
||||
}
|
||||
|
||||
void eyedropper_color_sample_fl(bContext *C,
|
||||
bool eyedropper_color_sample_fl(bContext *C,
|
||||
Eyedropper *eye,
|
||||
const int event_xy[2],
|
||||
float r_col[3])
|
||||
@@ -454,20 +454,20 @@ void eyedropper_color_sample_fl(bContext *C,
|
||||
if (area->spacetype == SPACE_IMAGE) {
|
||||
SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
|
||||
if (ED_space_image_color_sample(sima, region, mval, r_col, nullptr)) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (area->spacetype == SPACE_NODE) {
|
||||
SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
|
||||
Main *bmain = CTX_data_main(C);
|
||||
if (ED_space_node_color_sample(bmain, snode, region, mval, r_col)) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (area->spacetype == SPACE_CLIP) {
|
||||
SpaceClip *sc = static_cast<SpaceClip *>(area->spacedata.first);
|
||||
if (ED_space_clip_color_sample(sc, region, mval, r_col)) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (eye != nullptr && area->spacetype == SPACE_VIEW3D) {
|
||||
@@ -479,30 +479,33 @@ void eyedropper_color_sample_fl(bContext *C,
|
||||
eye->viewport_session->init(region);
|
||||
}
|
||||
if (eye->viewport_session->sample(mval, r_col)) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Other areas within a Blender window. */
|
||||
if (win) {
|
||||
/* Other areas within a Blender window. */
|
||||
if (!WM_window_pixels_read_sample(C, win, event_xy_win, r_col)) {
|
||||
WM_window_pixels_read_sample_from_offscreen(C, win, event_xy_win, r_col);
|
||||
}
|
||||
const char *display_device = CTX_data_scene(C)->display_settings.display_device;
|
||||
ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
|
||||
IMB_colormanagement_display_to_scene_linear_v3(r_col, display);
|
||||
return true;
|
||||
}
|
||||
else if ((WM_capabilities_flag() & WM_CAPABILITY_DESKTOP_SAMPLE) &&
|
||||
WM_desktop_cursor_sample_read(r_col))
|
||||
{
|
||||
/* Outside of the Blender window if we support it. */
|
||||
IMB_colormanagement_srgb_to_scene_linear_v3(r_col, r_col);
|
||||
}
|
||||
else {
|
||||
zero_v3(r_col);
|
||||
|
||||
/* Outside the Blender window if we support it. */
|
||||
if ((WM_capabilities_flag() & WM_CAPABILITY_DESKTOP_SAMPLE)) {
|
||||
if (WM_desktop_cursor_sample_read(r_col)) {
|
||||
IMB_colormanagement_srgb_to_scene_linear_v3(r_col, r_col);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
zero_v3(r_col);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* sets the sample color RGB, maintaining A */
|
||||
@@ -538,7 +541,9 @@ static void eyedropper_color_sample(bContext *C, Eyedropper *eye, const int even
|
||||
}
|
||||
}
|
||||
else {
|
||||
eyedropper_color_sample_fl(C, eye, event_xy, col);
|
||||
if (!eyedropper_color_sample_fl(C, eye, event_xy, col)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!eye->crypto_node) {
|
||||
|
||||
@@ -48,7 +48,7 @@ void eyedropper_win_area_find(const bContext *C,
|
||||
* \note Exposed by 'eyedropper_intern.hh' for use with color band picking.
|
||||
*/
|
||||
struct Eyedropper;
|
||||
void eyedropper_color_sample_fl(bContext *C,
|
||||
bool eyedropper_color_sample_fl(bContext *C,
|
||||
struct Eyedropper *eye,
|
||||
const int event_xy[2],
|
||||
float r_col[3]);
|
||||
|
||||
Reference in New Issue
Block a user