Cryptomatte: Show Name of Object/Material Under The Cursor.

This change shows the object or material name with the cursor when picking for a cryptomatte node.

Reviewed By: Julian Eisel

Differential Revision: https://developer.blender.org/D10705
This commit is contained in:
Jeroen Bakker 2021-03-17 08:48:05 +01:00
parent f4639276ee
commit 97defd9cd7
Notes: blender-bot 2023-04-04 07:45:26 +02:00
Referenced by commit 9e6c4be731, Fix T88167: Regression: no tooltip for syringe/picker, during picking object
Referenced by issue #88167, Regression: no tooltip for syringe/picker, during picking object
9 changed files with 91 additions and 23 deletions

@ -1 +1 @@
Subproject commit b06e7fe345e4a313eb701692e5d45033131caee1
Subproject commit ef74c1b861a1b05c2483a2c045a6380704167491

@ -1 +1 @@
Subproject commit ef3104dae302dcfb08b21e32d10b548bf304bd29
Subproject commit 6dfba915743b67aff99ddcc19c0807d339a87c96

View File

@ -1289,10 +1289,11 @@ void ntreeCompositCryptomatteSyncFromRemove(bNode *node);
bNodeSocket *ntreeCompositCryptomatteAddSocket(bNodeTree *ntree, bNode *node);
int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node);
void ntreeCompositCryptomatteLayerPrefix(const bNode *node, char *r_prefix, size_t prefix_len);
/* Update the runtime layer names with the cryptomatte layer names of the references
* render layer or image. */
void ntreeCompositCryptomatteUpdateLayerNames(bNode *node);
struct CryptomatteSession *ntreeCompositCryptomatteSession(bNode *node);
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -103,26 +103,41 @@ wmKeyMap *eyedropper_colorband_modal_keymap(wmKeyConfig *keyconf)
*/
/** \name Generic Shared Functions
* \{ */
void eyedropper_draw_cursor_text(const struct bContext *C, const ARegion *region, const char *name)
static void eyedropper_draw_cursor_text_ex(const int x, const int y, const char *name)
{
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
wmWindow *win = CTX_wm_window(C);
int x = win->eventstate->x;
int y = win->eventstate->y;
const float col_fg[4] = {1.0f, 1.0f, 1.0f, 1.0f};
const float col_bg[4] = {0.0f, 0.0f, 0.0f, 0.2f};
UI_fontstyle_draw_simple_backdrop(fstyle, x, y + U.widget_unit, name, col_fg, col_bg);
}
void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name)
{
if (name[0] == '\0') {
return;
}
const int x = window->eventstate->x;
const int y = window->eventstate->y;
eyedropper_draw_cursor_text_ex(x, y, name);
}
void eyedropper_draw_cursor_text_region(const struct bContext *C,
const ARegion *region,
const char *name)
{
wmWindow *win = CTX_wm_window(C);
const int x = win->eventstate->x - region->winrct.xmin;
const int y = win->eventstate->y - region->winrct.ymin;
if ((name[0] == '\0') || (BLI_rcti_isect_pt(&region->winrct, x, y) == false)) {
return;
}
x = x - region->winrct.xmin;
y = y - region->winrct.ymin;
y += U.widget_unit;
UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, col_fg, col_bg);
eyedropper_draw_cursor_text_ex(x, y, name);
}
/**

View File

@ -36,6 +36,7 @@
#include "BLI_string.h"
#include "BKE_context.h"
#include "BKE_cryptomatte.h"
#include "BKE_image.h"
#include "BKE_main.h"
#include "BKE_node.h"
@ -58,6 +59,9 @@
#include "ED_clip.h"
#include "ED_image.h"
#include "ED_node.h"
#include "ED_screen.h"
#include "RE_pipeline.h"
#include "RE_pipeline.h"
@ -78,9 +82,19 @@ typedef struct Eyedropper {
float accum_col[3];
int accum_tot;
void *draw_handle_sample_text;
char sample_text[MAX_NAME];
bNode *crypto_node;
struct CryptomatteSession *cryptomatte_session;
} Eyedropper;
static void eyedropper_draw_cb(const wmWindow *window, void *arg)
{
Eyedropper *eye = arg;
eyedropper_draw_cursor_text_window(window, eye->sample_text);
}
static bool eyedropper_init(bContext *C, wmOperator *op)
{
Eyedropper *eye = MEM_callocN(sizeof(Eyedropper), __func__);
@ -104,6 +118,8 @@ static bool eyedropper_init(bContext *C, wmOperator *op)
RNA_property_float_get_array(&eye->ptr, eye->prop, col);
if (ELEM(eye->ptr.type, &RNA_CompositorNodeCryptomatteV2, &RNA_CompositorNodeCryptomatte)) {
eye->crypto_node = (bNode *)eye->ptr.data;
eye->cryptomatte_session = ntreeCompositCryptomatteSession(eye->crypto_node);
eye->draw_handle_sample_text = WM_draw_cb_activate(CTX_wm_window(C), eyedropper_draw_cb, eye);
}
else {
eye->crypto_node = NULL;
@ -128,12 +144,21 @@ static bool eyedropper_init(bContext *C, wmOperator *op)
static void eyedropper_exit(bContext *C, wmOperator *op)
{
WM_cursor_modal_restore(CTX_wm_window(C));
Eyedropper *eye = op->customdata;
wmWindow *window = CTX_wm_window(C);
WM_cursor_modal_restore(window);
if (op->customdata) {
MEM_freeN(op->customdata);
op->customdata = NULL;
if (eye->draw_handle_sample_text) {
WM_draw_cb_exit(window, eye->draw_handle_sample_text);
eye->draw_handle_sample_text = NULL;
}
if (eye->cryptomatte_session) {
BKE_cryptomatte_free(eye->cryptomatte_session);
eye->cryptomatte_session = NULL;
}
MEM_SAFE_FREE(op->customdata);
}
/* *** eyedropper_color_ helper functions *** */
@ -416,6 +441,20 @@ static void eyedropper_color_sample(bContext *C, Eyedropper *eye, int mx, int my
eyedropper_color_set(C, eye, accum_col);
}
static void eyedropper_color_sample_text_update(bContext *C, Eyedropper *eye, int mx, int my)
{
float col[3];
eye->sample_text[0] = '\0';
if (eye->cryptomatte_session) {
if (eyedropper_cryptomatte_sample_fl(C, eye, mx, my, col)) {
BKE_cryptomatte_find_name(
eye->cryptomatte_session, col[0], eye->sample_text, sizeof(eye->sample_text));
eye->sample_text[sizeof(eye->sample_text) - 1] = '\0';
}
}
}
static void eyedropper_cancel(bContext *C, wmOperator *op)
{
Eyedropper *eye = op->customdata;
@ -462,6 +501,11 @@ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* button is pressed so keep sampling */
eyedropper_color_sample(C, eye, event->x, event->y);
}
if (eye->draw_handle_sample_text) {
eyedropper_color_sample_text_update(C, eye, event->x, event->y);
ED_region_tag_redraw(CTX_wm_region(C));
}
}
return OPERATOR_RUNNING_MODAL;

View File

@ -77,7 +77,7 @@ typedef struct DataDropper {
static void datadropper_draw_cb(const struct bContext *C, ARegion *region, void *arg)
{
DataDropper *ddr = arg;
eyedropper_draw_cursor_text(C, region, ddr->name);
eyedropper_draw_cursor_text_region(C, region, ddr->name);
}
static int datadropper_init(bContext *C, wmOperator *op)

View File

@ -78,7 +78,7 @@ typedef struct DepthDropper {
static void depthdropper_draw_cb(const struct bContext *C, ARegion *region, void *arg)
{
DepthDropper *ddr = arg;
eyedropper_draw_cursor_text(C, region, ddr->name);
eyedropper_draw_cursor_text_region(C, region, ddr->name);
}
static int depthdropper_init(bContext *C, wmOperator *op)

View File

@ -23,9 +23,10 @@
#pragma once
/* interface_eyedropper.c */
void eyedropper_draw_cursor_text(const struct bContext *C,
const struct ARegion *region,
const char *name);
void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name);
void eyedropper_draw_cursor_text_region(const struct bContext *C,
const struct ARegion *region,
const char *name);
uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event);
/* interface_eyedropper_color.c (expose for color-band picker) */

View File

@ -216,6 +216,13 @@ void ntreeCompositCryptomatteLayerPrefix(const bNode *node, char *r_prefix, size
BLI_strncpy(r_prefix, cstr, prefix_len);
}
CryptomatteSession *ntreeCompositCryptomatteSession(bNode *node)
{
blender::bke::cryptomatte::CryptomatteSessionPtr session_ptr = cryptomatte_init_from_node(
*node, 0, true);
return session_ptr.release();
}
static void node_init_cryptomatte(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeCryptomatte *user = static_cast<NodeCryptomatte *>(