From bf24467e109368d69b1c9576a58433d6f7683e72 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 12 Oct 2023 17:34:51 -0700 Subject: [PATCH 1/4] Fix #101058: Allow Cryptomatte Picking Between Windows Allow the source and target windows to differ when selecting objects using Cryptomatte. But this does not show the name. --- .../interface/eyedroppers/eyedropper_color.cc | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/interface/eyedroppers/eyedropper_color.cc b/source/blender/editors/interface/eyedroppers/eyedropper_color.cc index 11e2961ac94..f1f4ba5fbaa 100644 --- a/source/blender/editors/interface/eyedroppers/eyedropper_color.cc +++ b/source/blender/editors/interface/eyedroppers/eyedropper_color.cc @@ -253,34 +253,42 @@ static bool eyedropper_cryptomatte_sample_fl(bContext *C, return false; } - bScreen *screen = CTX_wm_screen(C); - ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event_xy); + ScrArea *area = nullptr; + + int mval[2]; + wmWindow *win = WM_window_find_under_cursor(CTX_wm_window(C), event_xy, mval); + if (win) { + bScreen *screen = WM_window_get_active_screen(win); + area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mval); + } + if (!area || !ELEM(area->spacetype, SPACE_IMAGE, SPACE_NODE, SPACE_CLIP)) { return false; } - ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, event_xy); + ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mval); + if (!region) { return false; } - int mval[2] = {event_xy[0] - region->winrct.xmin, event_xy[1] - region->winrct.ymin}; + int region_mval[2] = {mval[0] - region->winrct.xmin, mval[1] - region->winrct.ymin}; float fpos[2] = {-1.0f, -1.0}; switch (area->spacetype) { case SPACE_IMAGE: { SpaceImage *sima = static_cast(area->spacedata.first); - ED_space_image_get_position(sima, region, mval, fpos); + ED_space_image_get_position(sima, region, region_mval, fpos); break; } case SPACE_NODE: { Main *bmain = CTX_data_main(C); SpaceNode *snode = static_cast(area->spacedata.first); - ED_space_node_get_position(bmain, snode, region, mval, fpos); + ED_space_node_get_position(bmain, snode, region, region_mval, fpos); break; } case SPACE_CLIP: { SpaceClip *sc = static_cast(area->spacedata.first); - ED_space_clip_get_position(sc, region, mval, fpos); + ED_space_clip_get_position(sc, region, region_mval, fpos); break; } default: { -- 2.30.2 From c3c4d25b052245d5d6ff50e391ddb08ab11e6419 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 13 Oct 2023 12:46:55 -0700 Subject: [PATCH 2/4] Adding a TODO comment. --- .../editors/interface/eyedroppers/eyedropper_color.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/blender/editors/interface/eyedroppers/eyedropper_color.cc b/source/blender/editors/interface/eyedroppers/eyedropper_color.cc index f1f4ba5fbaa..c47631b7484 100644 --- a/source/blender/editors/interface/eyedroppers/eyedropper_color.cc +++ b/source/blender/editors/interface/eyedroppers/eyedropper_color.cc @@ -241,6 +241,13 @@ static bool eyedropper_cryptomatte_sample_image_fl(const bNode *node, return success; } +/* TODO(Harley): Although the following works when the target and source windows differ, it does + * not show the object name at the mouse position in that case. This is because Eyedropper uses a + * drawing callback for this - draw_handle_sample_text - that is per-window. A likely way to + * approach this is to store the cb_win in eyedropper and change the callback when needed. Or + * perhaps change it to a region draw callback: ED_region_draw_cb_activate. There is also a + * cursor API that might work. */ + static bool eyedropper_cryptomatte_sample_fl(bContext *C, Eyedropper *eye, const int event_xy[2], -- 2.30.2 From 41f6b5eb87b8a1c5ff81a229ba031b8ba20a0826 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Sat, 14 Oct 2023 10:29:38 -0700 Subject: [PATCH 3/4] Properly showing the object name now on other windows. --- .../interface/eyedroppers/eyedropper_color.cc | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/source/blender/editors/interface/eyedroppers/eyedropper_color.cc b/source/blender/editors/interface/eyedroppers/eyedropper_color.cc index c47631b7484..d6f198c7363 100644 --- a/source/blender/editors/interface/eyedroppers/eyedropper_color.cc +++ b/source/blender/editors/interface/eyedroppers/eyedropper_color.cc @@ -68,6 +68,8 @@ struct Eyedropper { float accum_col[3]; int accum_tot; + wmWindow *cb_win; + int cb_win_mval[2]; void *draw_handle_sample_text; char sample_text[MAX_NAME]; @@ -78,7 +80,7 @@ struct Eyedropper { static void eyedropper_draw_cb(const wmWindow *window, void *arg) { Eyedropper *eye = static_cast(arg); - eyedropper_draw_cursor_text_window(window, eye->sample_text); + eyedropper_draw_cursor_text_region(eye->cb_win_mval, eye->sample_text); } static bool eyedropper_init(bContext *C, wmOperator *op) @@ -108,7 +110,8 @@ static bool eyedropper_init(bContext *C, wmOperator *op) eye->crypto_node = (bNode *)eye->ptr.data; eye->cryptomatte_session = ntreeCompositCryptomatteSession(CTX_data_scene(C), eye->crypto_node); - eye->draw_handle_sample_text = WM_draw_cb_activate(CTX_wm_window(C), eyedropper_draw_cb, eye); + eye->cb_win = CTX_wm_window(C); + eye->draw_handle_sample_text = WM_draw_cb_activate(eye->cb_win, eyedropper_draw_cb, eye); } if (prop_subtype != PROP_COLOR) { @@ -135,7 +138,7 @@ static void eyedropper_exit(bContext *C, wmOperator *op) WM_cursor_modal_restore(window); if (eye->draw_handle_sample_text) { - WM_draw_cb_exit(window, eye->draw_handle_sample_text); + WM_draw_cb_exit(eye->cb_win, eye->draw_handle_sample_text); eye->draw_handle_sample_text = nullptr; } @@ -241,13 +244,6 @@ static bool eyedropper_cryptomatte_sample_image_fl(const bNode *node, return success; } -/* TODO(Harley): Although the following works when the target and source windows differ, it does - * not show the object name at the mouse position in that case. This is because Eyedropper uses a - * drawing callback for this - draw_handle_sample_text - that is per-window. A likely way to - * approach this is to store the cb_win in eyedropper and change the callback when needed. Or - * perhaps change it to a region draw callback: ED_region_draw_cb_activate. There is also a - * cursor API that might work. */ - static bool eyedropper_cryptomatte_sample_fl(bContext *C, Eyedropper *eye, const int event_xy[2], @@ -269,6 +265,16 @@ static bool eyedropper_cryptomatte_sample_fl(bContext *C, area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mval); } + eye->cb_win_mval[0] = mval[0]; + eye->cb_win_mval[1] = mval[1]; + + if (win && win != eye->cb_win && eye->draw_handle_sample_text) { + WM_draw_cb_exit(eye->cb_win, eye->draw_handle_sample_text); + eye->cb_win = win; + eye->draw_handle_sample_text = WM_draw_cb_activate(eye->cb_win, eyedropper_draw_cb, eye); + ED_region_tag_redraw(CTX_wm_region(C)); + } + if (!area || !ELEM(area->spacetype, SPACE_IMAGE, SPACE_NODE, SPACE_CLIP)) { return false; } @@ -313,6 +319,8 @@ static bool eyedropper_cryptomatte_sample_fl(bContext *C, return false; } + ED_region_tag_redraw(region); + /* TODO(jbakker): Migrate this file to cc and use std::string as return param. */ char prefix[MAX_NAME + 1]; const Scene *scene = CTX_data_scene(C); @@ -506,7 +514,6 @@ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event) if (eye->draw_handle_sample_text) { eyedropper_color_sample_text_update(C, eye, event->xy); - ED_region_tag_redraw(CTX_wm_region(C)); } } -- 2.30.2 From 15fa0ceab1d2225010fe297701ea90ea21129ec6 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Sat, 14 Oct 2023 11:25:49 -0700 Subject: [PATCH 4/4] Unused parameter --- .../blender/editors/interface/eyedroppers/eyedropper_color.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/interface/eyedroppers/eyedropper_color.cc b/source/blender/editors/interface/eyedroppers/eyedropper_color.cc index d6f198c7363..4160fa1d580 100644 --- a/source/blender/editors/interface/eyedroppers/eyedropper_color.cc +++ b/source/blender/editors/interface/eyedroppers/eyedropper_color.cc @@ -77,7 +77,7 @@ struct Eyedropper { CryptomatteSession *cryptomatte_session; }; -static void eyedropper_draw_cb(const wmWindow *window, void *arg) +static void eyedropper_draw_cb(const wmWindow * /*window*/, void *arg) { Eyedropper *eye = static_cast(arg); eyedropper_draw_cursor_text_region(eye->cb_win_mval, eye->sample_text); -- 2.30.2