diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/editors/space_node | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/editors/space_node')
-rw-r--r-- | source/blender/editors/space_node/CMakeLists.txt | 74 | ||||
-rw-r--r-- | source/blender/editors/space_node/drawnode.c | 5731 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_add.c | 806 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_buttons.c | 290 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_draw.c | 2757 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 3954 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_gizmo.c | 769 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_group.c | 1720 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_intern.h | 127 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_ops.c | 279 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_relationships.c | 3145 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_select.c | 1670 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_templates.c | 1327 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_toolbar.c | 33 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_view.c | 894 | ||||
-rw-r--r-- | source/blender/editors/space_node/space_node.c | 1558 |
16 files changed, 12864 insertions, 12270 deletions
diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt index 5e2437c99ca..df1b7c03aab 100644 --- a/source/blender/editors/space_node/CMakeLists.txt +++ b/source/blender/editors/space_node/CMakeLists.txt @@ -16,59 +16,59 @@ # ***** END GPL LICENSE BLOCK ***** set(INC - ../include - ../../blenfont - ../../blenkernel - ../../blenlib - ../../blentranslation - ../../depsgraph - ../../imbuf - ../../gpu - ../../makesdna - ../../makesrna - ../../nodes - ../../render/extern/include - ../../windowmanager - ../../compositor - ../../../../intern/guardedalloc - ../../../../intern/glew-mx + ../include + ../../blenfont + ../../blenkernel + ../../blenlib + ../../blentranslation + ../../depsgraph + ../../imbuf + ../../gpu + ../../makesdna + ../../makesrna + ../../nodes + ../../render/extern/include + ../../windowmanager + ../../compositor + ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS - ${GLEW_INCLUDE_PATH} + ${GLEW_INCLUDE_PATH} ) set(SRC - drawnode.c - node_add.c - node_buttons.c - node_draw.c - node_edit.c - node_gizmo.c - node_group.c - node_ops.c - node_relationships.c - node_select.c - node_templates.c - node_toolbar.c - node_view.c - space_node.c + drawnode.c + node_add.c + node_buttons.c + node_draw.c + node_edit.c + node_gizmo.c + node_group.c + node_ops.c + node_relationships.c + node_select.c + node_templates.c + node_toolbar.c + node_view.c + space_node.c - node_intern.h + node_intern.h ) set(LIB - bf_blenkernel - bf_blenlib - bf_editor_screen + bf_blenkernel + bf_blenlib + bf_editor_screen ) if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) + add_definitions(-DWITH_INTERNATIONAL) endif() if(WITH_COMPOSITOR) - add_definitions(-DWITH_COMPOSITOR) + add_definitions(-DWITH_COMPOSITOR) endif() add_definitions(${GL_DEFINITIONS}) diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index be26f67b936..7072f34ee4d 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -65,93 +65,95 @@ #include "IMB_colormanagement.h" #include "IMB_imbuf_types.h" -#include "node_intern.h" /* own include */ +#include "node_intern.h" /* own include */ #include "NOD_composite.h" #include "NOD_shader.h" #include "NOD_texture.h" - /* ****************** SOCKET BUTTON DRAW FUNCTIONS ***************** */ -static void node_socket_button_label(bContext *UNUSED(C), uiLayout *layout, PointerRNA *UNUSED(ptr), PointerRNA *UNUSED(node_ptr), +static void node_socket_button_label(bContext *UNUSED(C), + uiLayout *layout, + PointerRNA *UNUSED(ptr), + PointerRNA *UNUSED(node_ptr), const char *text) { - uiItemL(layout, text, 0); + uiItemL(layout, text, 0); } /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */ static void node_buts_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - bNode *node = ptr->data; - /* first output stores value */ - bNodeSocket *output = node->outputs.first; - PointerRNA sockptr; - RNA_pointer_create(ptr->id.data, &RNA_NodeSocket, output, &sockptr); + bNode *node = ptr->data; + /* first output stores value */ + bNodeSocket *output = node->outputs.first; + PointerRNA sockptr; + RNA_pointer_create(ptr->id.data, &RNA_NodeSocket, output, &sockptr); - uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE); + uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE); } static void node_buts_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - bNode *node = ptr->data; - /* first output stores value */ - bNodeSocket *output = node->outputs.first; - PointerRNA sockptr; - uiLayout *col; - RNA_pointer_create(ptr->id.data, &RNA_NodeSocket, output, &sockptr); + bNode *node = ptr->data; + /* first output stores value */ + bNodeSocket *output = node->outputs.first; + PointerRNA sockptr; + uiLayout *col; + RNA_pointer_create(ptr->id.data, &RNA_NodeSocket, output, &sockptr); - col = uiLayoutColumn(layout, false); - uiTemplateColorPicker(col, &sockptr, "default_value", 1, 0, 0, 0); - uiItemR(col, &sockptr, "default_value", UI_ITEM_R_SLIDER, "", ICON_NONE); + col = uiLayoutColumn(layout, false); + uiTemplateColorPicker(col, &sockptr, "default_value", 1, 0, 0, 0); + uiItemR(col, &sockptr, "default_value", UI_ITEM_R_SLIDER, "", ICON_NONE); } static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row, *col; + uiLayout *row, *col; - bNodeTree *ntree = (bNodeTree *)ptr->id.data; + bNodeTree *ntree = (bNodeTree *)ptr->id.data; - col = uiLayoutColumn(layout, false); - row = uiLayoutRow(col, true); - uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE); - if (ELEM(ntree->type, NTREE_COMPOSIT, NTREE_TEXTURE)) { - uiItemR(row, ptr, "use_alpha", 0, "", ICON_IMAGE_RGB_ALPHA); - } + col = uiLayoutColumn(layout, false); + row = uiLayoutRow(col, true); + uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE); + if (ELEM(ntree->type, NTREE_COMPOSIT, NTREE_TEXTURE)) { + uiItemR(row, ptr, "use_alpha", 0, "", ICON_IMAGE_RGB_ALPHA); + } - uiItemR(col, ptr, "use_clamp", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "use_clamp", 0, NULL, ICON_NONE); } static void node_buts_time(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row; + uiLayout *row; #if 0 - /* XXX no context access here .. */ - bNode *node = ptr->data; - CurveMapping *cumap = node->storage; - - if (cumap) { - cumap->flag |= CUMA_DRAW_CFRA; - if (node->custom1 < node->custom2) - cumap->sample[0] = (float)(CFRA - node->custom1) / (float)(node->custom2 - node->custom1); - } + /* XXX no context access here .. */ + bNode *node = ptr->data; + CurveMapping *cumap = node->storage; + + if (cumap) { + cumap->flag |= CUMA_DRAW_CFRA; + if (node->custom1 < node->custom2) + cumap->sample[0] = (float)(CFRA - node->custom1) / (float)(node->custom2 - node->custom1); + } #endif - uiTemplateCurveMapping(layout, ptr, "curve", 's', false, false, false, false); + uiTemplateCurveMapping(layout, ptr, "curve", 's', false, false, false, false); - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "frame_start", 0, IFACE_("Sta"), ICON_NONE); - uiItemR(row, ptr, "frame_end", 0, IFACE_("End"), ICON_NONE); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "frame_start", 0, IFACE_("Sta"), ICON_NONE); + uiItemR(row, ptr, "frame_end", 0, IFACE_("End"), ICON_NONE); } static void node_buts_colorramp(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiTemplateColorRamp(layout, ptr, "color_ramp", 0); + uiTemplateColorRamp(layout, ptr, "color_ramp", 0); } static void node_buts_curvevec(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiTemplateCurveMapping(layout, ptr, "mapping", 'v', false, false, false, false); + uiTemplateCurveMapping(layout, ptr, "mapping", 'v', false, false, false, false); } #define SAMPLE_FLT_ISNONE FLT_MAX @@ -159,133 +161,128 @@ static void node_buts_curvevec(uiLayout *layout, bContext *UNUSED(C), PointerRNA static float _sample_col[4] = {SAMPLE_FLT_ISNONE}; void ED_node_sample_set(const float col[4]) { - if (col) { - copy_v4_v4(_sample_col, col); - } - else { - copy_v4_fl(_sample_col, SAMPLE_FLT_ISNONE); - } + if (col) { + copy_v4_v4(_sample_col, col); + } + else { + copy_v4_fl(_sample_col, SAMPLE_FLT_ISNONE); + } } static void node_buts_curvecol(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - bNode *node = ptr->data; - CurveMapping *cumap = node->storage; + bNode *node = ptr->data; + CurveMapping *cumap = node->storage; - if (_sample_col[0] != SAMPLE_FLT_ISNONE) { - cumap->flag |= CUMA_DRAW_SAMPLE; - copy_v3_v3(cumap->sample, _sample_col); - } - else { - cumap->flag &= ~CUMA_DRAW_SAMPLE; - } + if (_sample_col[0] != SAMPLE_FLT_ISNONE) { + cumap->flag |= CUMA_DRAW_SAMPLE; + copy_v3_v3(cumap->sample, _sample_col); + } + else { + cumap->flag &= ~CUMA_DRAW_SAMPLE; + } - uiTemplateCurveMapping(layout, ptr, "mapping", 'c', false, false, false, true); + uiTemplateCurveMapping(layout, ptr, "mapping", 'c', false, false, false, true); } static void node_buts_normal(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - bNode *node = ptr->data; - /* first output stores normal */ - bNodeSocket *output = node->outputs.first; - PointerRNA sockptr; - RNA_pointer_create(ptr->id.data, &RNA_NodeSocket, output, &sockptr); + bNode *node = ptr->data; + /* first output stores normal */ + bNodeSocket *output = node->outputs.first; + PointerRNA sockptr; + RNA_pointer_create(ptr->id.data, &RNA_NodeSocket, output, &sockptr); - uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE); + uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE); } #if 0 /* not used in 2.5x yet */ static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v) { - Main *bmain = CTX_data_main(C); - bNodeTree *ntree = ntree_v; - bNode *node = node_v; - Tex *tex; + Main *bmain = CTX_data_main(C); + bNodeTree *ntree = ntree_v; + bNode *node = node_v; + Tex *tex; - if (node->menunr < 1) return; + if (node->menunr < 1) return; - if (node->id) { - id_us_min(node->id); - node->id = NULL; - } - tex = BLI_findlink(&bmain->tex, node->menunr - 1); + if (node->id) { + id_us_min(node->id); + node->id = NULL; + } + tex = BLI_findlink(&bmain->tex, node->menunr - 1); - node->id = &tex->id; - id_us_plus(node->id); - BLI_strncpy(node->name, node->id->name + 2, sizeof(node->name)); + node->id = &tex->id; + id_us_plus(node->id); + BLI_strncpy(node->name, node->id->name + 2, sizeof(node->name)); - nodeSetActive(ntree, node); + nodeSetActive(ntree, node); - if (ntree->type == NTREE_TEXTURE) - ntreeTexCheckCyclics(ntree); + if (ntree->type == NTREE_TEXTURE) + ntreeTexCheckCyclics(ntree); - // allqueue(REDRAWBUTSSHADING, 0); - // allqueue(REDRAWNODE, 0); - NodeTagChanged(ntree, node); + // allqueue(REDRAWBUTSSHADING, 0); + // allqueue(REDRAWNODE, 0); + NodeTagChanged(ntree, node); - node->menunr = 0; + node->menunr = 0; } #endif static void node_buts_texture(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - bNode *node = ptr->data; + bNode *node = ptr->data; - short multi = ( - node->id && - ((Tex *)node->id)->use_nodes && - (node->type != CMP_NODE_TEXTURE) && - (node->type != TEX_NODE_TEXTURE) - ); + short multi = (node->id && ((Tex *)node->id)->use_nodes && (node->type != CMP_NODE_TEXTURE) && + (node->type != TEX_NODE_TEXTURE)); - uiItemR(layout, ptr, "texture", 0, "", ICON_NONE); + uiItemR(layout, ptr, "texture", 0, "", ICON_NONE); - if (multi) { - /* Number Drawing not optimal here, better have a list*/ - uiItemR(layout, ptr, "node_output", 0, "", ICON_NONE); - } + if (multi) { + /* Number Drawing not optimal here, better have a list*/ + uiItemR(layout, ptr, "node_output", 0, "", ICON_NONE); + } } static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "operation", 0, "", ICON_NONE); - uiItemR(layout, ptr, "use_clamp", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "operation", 0, "", ICON_NONE); + uiItemR(layout, ptr, "use_clamp", 0, NULL, ICON_NONE); } static int node_resize_area_default(bNode *node, int x, int y) { - if (node->flag & NODE_HIDDEN) { - rctf totr = node->totr; - /* right part of node */ - totr.xmin = node->totr.xmax - 20.0f; - if (BLI_rctf_isect_pt(&totr, x, y)) { - return NODE_RESIZE_RIGHT; - } - else { - return 0; - } - } - else { - const float size = NODE_RESIZE_MARGIN; - rctf totr = node->totr; - int dir = 0; - - if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax) { - dir |= NODE_RESIZE_RIGHT; - } - if (x >= totr.xmin && x < totr.xmin + size && y >= totr.ymin && y < totr.ymax) { - dir |= NODE_RESIZE_LEFT; - } - return dir; - } + if (node->flag & NODE_HIDDEN) { + rctf totr = node->totr; + /* right part of node */ + totr.xmin = node->totr.xmax - 20.0f; + if (BLI_rctf_isect_pt(&totr, x, y)) { + return NODE_RESIZE_RIGHT; + } + else { + return 0; + } + } + else { + const float size = NODE_RESIZE_MARGIN; + rctf totr = node->totr; + int dir = 0; + + if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax) { + dir |= NODE_RESIZE_RIGHT; + } + if (x >= totr.xmin && x < totr.xmin + size && y >= totr.ymin && y < totr.ymax) { + dir |= NODE_RESIZE_LEFT; + } + return dir; + } } /* ****************** BUTTON CALLBACKS FOR COMMON NODES ***************** */ - static void node_draw_buttons_group(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiTemplateIDBrowse(layout, C, ptr, "node_tree", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL); + uiTemplateIDBrowse(layout, C, ptr, "node_tree", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL); } /* XXX Does a bounding box update by iterating over all children. @@ -294,318 +291,336 @@ static void node_draw_buttons_group(uiLayout *layout, bContext *C, PointerRNA *p */ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree, bNode *node) { - const float margin = 1.5f * U.widget_unit; - NodeFrame *data = (NodeFrame *)node->storage; - bool bbinit; - bNode *tnode; - rctf rect, noderect; - float xmax, ymax; - - /* init rect from current frame size */ - node_to_view(node, node->offsetx, node->offsety, &rect.xmin, &rect.ymax); - node_to_view(node, node->offsetx + node->width, node->offsety - node->height, &rect.xmax, &rect.ymin); - - /* frame can be resized manually only if shrinking is disabled or no children are attached */ - data->flag |= NODE_FRAME_RESIZEABLE; - /* for shrinking bbox, initialize the rect from first child node */ - bbinit = (data->flag & NODE_FRAME_SHRINK); - /* fit bounding box to all children */ - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { - if (tnode->parent != node) { - continue; - } - - /* add margin to node rect */ - noderect = tnode->totr; - noderect.xmin -= margin; - noderect.xmax += margin; - noderect.ymin -= margin; - noderect.ymax += margin; - - /* first child initializes frame */ - if (bbinit) { - bbinit = 0; - rect = noderect; - data->flag &= ~NODE_FRAME_RESIZEABLE; - } - else { - BLI_rctf_union(&rect, &noderect); - } - } - - /* now adjust the frame size from view-space bounding box */ - node_from_view(node, rect.xmin, rect.ymax, &node->offsetx, &node->offsety); - node_from_view(node, rect.xmax, rect.ymin, &xmax, &ymax); - node->width = xmax - node->offsetx; - node->height = -ymax + node->offsety; - - node->totr = rect; + const float margin = 1.5f * U.widget_unit; + NodeFrame *data = (NodeFrame *)node->storage; + bool bbinit; + bNode *tnode; + rctf rect, noderect; + float xmax, ymax; + + /* init rect from current frame size */ + node_to_view(node, node->offsetx, node->offsety, &rect.xmin, &rect.ymax); + node_to_view( + node, node->offsetx + node->width, node->offsety - node->height, &rect.xmax, &rect.ymin); + + /* frame can be resized manually only if shrinking is disabled or no children are attached */ + data->flag |= NODE_FRAME_RESIZEABLE; + /* for shrinking bbox, initialize the rect from first child node */ + bbinit = (data->flag & NODE_FRAME_SHRINK); + /* fit bounding box to all children */ + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { + if (tnode->parent != node) { + continue; + } + + /* add margin to node rect */ + noderect = tnode->totr; + noderect.xmin -= margin; + noderect.xmax += margin; + noderect.ymin -= margin; + noderect.ymax += margin; + + /* first child initializes frame */ + if (bbinit) { + bbinit = 0; + rect = noderect; + data->flag &= ~NODE_FRAME_RESIZEABLE; + } + else { + BLI_rctf_union(&rect, &noderect); + } + } + + /* now adjust the frame size from view-space bounding box */ + node_from_view(node, rect.xmin, rect.ymax, &node->offsetx, &node->offsety); + node_from_view(node, rect.xmax, rect.ymin, &xmax, &ymax); + node->width = xmax - node->offsetx; + node->height = -ymax + node->offsety; + + node->totr = rect; } static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float aspect) { - /* XXX font id is crap design */ - const int fontid = UI_style_get()->widgetlabel.uifont_id; - NodeFrame *data = (NodeFrame *)node->storage; - rctf *rct = &node->totr; - int color_id = node_get_colorid(node); - char label[MAX_NAME]; - /* XXX a bit hacky, should use separate align values for x and y */ - float width, ascender; - float x, y; - const int font_size = data->label_size / aspect; - const float margin = (float)(NODE_DY / 4); - int label_height; - unsigned char color[3]; - - nodeLabel(ntree, node, label, sizeof(label)); - - BLF_enable(fontid, BLF_ASPECT); - BLF_aspect(fontid, aspect, aspect, 1.0f); - /* clamp otherwise it can suck up a LOT of memory */ - BLF_size(fontid, MIN2(24, font_size), U.dpi); - - /* title color */ - UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color); - BLF_color3ubv(fontid, color); - - width = BLF_width(fontid, label, sizeof(label)); - ascender = BLF_ascender(fontid); - label_height = ((margin / aspect) + (ascender * aspect)); - - /* 'x' doesn't need aspect correction */ - x = BLI_rctf_cent_x(rct) - (0.5f * width); - y = rct->ymax - label_height; - - BLF_position(fontid, x, y, 0); - BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX); - - /* draw text body */ - if (node->id) { - Text *text = (Text *)node->id; - TextLine *line; - const int line_height_max = BLF_height_max(fontid); - const float line_spacing = (line_height_max * aspect); - const float line_width = (BLI_rctf_size_x(rct) - margin) / aspect; - int y_min; - - /* 'x' doesn't need aspect correction */ - x = rct->xmin + margin; - y = rct->ymax - (label_height + line_spacing); - /* early exit */ - y_min = y + ((margin * 2) - (y - rct->ymin)); - - BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP); - BLF_clipping( - fontid, - rct->xmin, - /* round to avoid clipping half-way through a line */ - y - (floorf(((y - rct->ymin) - (margin * 2)) / line_spacing) * line_spacing), - rct->xmin + line_width, - rct->ymax); - - BLF_wordwrap(fontid, line_width); - - for (line = text->lines.first; line; line = line->next) { - struct ResultBLF info; - if (line->line[0]) { - BLF_position(fontid, x, y, 0); - BLF_draw_ex(fontid, line->line, line->len, &info); - y -= line_spacing * info.lines; - } - else { - y -= line_spacing; - } - if (y < y_min) { - break; - } - } - - BLF_disable(fontid, BLF_CLIPPING | BLF_WORD_WRAP); - } - - BLF_disable(fontid, BLF_ASPECT); -} - -static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode, - bNodeTree *ntree, bNode *node, bNodeInstanceKey UNUSED(key)) -{ - rctf *rct = &node->totr; - int color_id = node_get_colorid(node); - float color[4]; - float alpha; - - /* skip if out of view */ - if (BLI_rctf_isect(&node->totr, &ar->v2d.cur, NULL) == false) { - UI_block_end(C, node->block); - node->block = NULL; - return; - } - - UI_GetThemeColor4fv(TH_NODE_FRAME, color); - alpha = color[3]; - - /* shadow */ - node_draw_shadow(snode, node, BASIS_RAD, alpha); - - /* body */ - if (node->flag & NODE_CUSTOM_COLOR) { - rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], alpha); - } - else { - UI_GetThemeColor4fv(TH_NODE_FRAME, color); - } - - UI_draw_roundbox_corner_set(UI_CNR_ALL); - UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color); - - /* outline active and selected emphasis */ - if (node->flag & SELECT) { - if (node->flag & NODE_ACTIVE) { - UI_GetThemeColorShadeAlpha4fv(TH_ACTIVE, 0, -40, color); - } - else { - UI_GetThemeColorShadeAlpha4fv(TH_SELECT, 0, -40, color); - } - - UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color); - } - - /* label */ - node_draw_frame_label(ntree, node, snode->aspect); - - UI_ThemeClearColor(color_id); - - UI_block_end(C, node->block); - UI_block_draw(C, node->block); - node->block = NULL; + /* XXX font id is crap design */ + const int fontid = UI_style_get()->widgetlabel.uifont_id; + NodeFrame *data = (NodeFrame *)node->storage; + rctf *rct = &node->totr; + int color_id = node_get_colorid(node); + char label[MAX_NAME]; + /* XXX a bit hacky, should use separate align values for x and y */ + float width, ascender; + float x, y; + const int font_size = data->label_size / aspect; + const float margin = (float)(NODE_DY / 4); + int label_height; + unsigned char color[3]; + + nodeLabel(ntree, node, label, sizeof(label)); + + BLF_enable(fontid, BLF_ASPECT); + BLF_aspect(fontid, aspect, aspect, 1.0f); + /* clamp otherwise it can suck up a LOT of memory */ + BLF_size(fontid, MIN2(24, font_size), U.dpi); + + /* title color */ + UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color); + BLF_color3ubv(fontid, color); + + width = BLF_width(fontid, label, sizeof(label)); + ascender = BLF_ascender(fontid); + label_height = ((margin / aspect) + (ascender * aspect)); + + /* 'x' doesn't need aspect correction */ + x = BLI_rctf_cent_x(rct) - (0.5f * width); + y = rct->ymax - label_height; + + BLF_position(fontid, x, y, 0); + BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX); + + /* draw text body */ + if (node->id) { + Text *text = (Text *)node->id; + TextLine *line; + const int line_height_max = BLF_height_max(fontid); + const float line_spacing = (line_height_max * aspect); + const float line_width = (BLI_rctf_size_x(rct) - margin) / aspect; + int y_min; + + /* 'x' doesn't need aspect correction */ + x = rct->xmin + margin; + y = rct->ymax - (label_height + line_spacing); + /* early exit */ + y_min = y + ((margin * 2) - (y - rct->ymin)); + + BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP); + BLF_clipping(fontid, + rct->xmin, + /* round to avoid clipping half-way through a line */ + y - (floorf(((y - rct->ymin) - (margin * 2)) / line_spacing) * line_spacing), + rct->xmin + line_width, + rct->ymax); + + BLF_wordwrap(fontid, line_width); + + for (line = text->lines.first; line; line = line->next) { + struct ResultBLF info; + if (line->line[0]) { + BLF_position(fontid, x, y, 0); + BLF_draw_ex(fontid, line->line, line->len, &info); + y -= line_spacing * info.lines; + } + else { + y -= line_spacing; + } + if (y < y_min) { + break; + } + } + + BLF_disable(fontid, BLF_CLIPPING | BLF_WORD_WRAP); + } + + BLF_disable(fontid, BLF_ASPECT); +} + +static void node_draw_frame(const bContext *C, + ARegion *ar, + SpaceNode *snode, + bNodeTree *ntree, + bNode *node, + bNodeInstanceKey UNUSED(key)) +{ + rctf *rct = &node->totr; + int color_id = node_get_colorid(node); + float color[4]; + float alpha; + + /* skip if out of view */ + if (BLI_rctf_isect(&node->totr, &ar->v2d.cur, NULL) == false) { + UI_block_end(C, node->block); + node->block = NULL; + return; + } + + UI_GetThemeColor4fv(TH_NODE_FRAME, color); + alpha = color[3]; + + /* shadow */ + node_draw_shadow(snode, node, BASIS_RAD, alpha); + + /* body */ + if (node->flag & NODE_CUSTOM_COLOR) { + rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], alpha); + } + else { + UI_GetThemeColor4fv(TH_NODE_FRAME, color); + } + + UI_draw_roundbox_corner_set(UI_CNR_ALL); + UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color); + + /* outline active and selected emphasis */ + if (node->flag & SELECT) { + if (node->flag & NODE_ACTIVE) { + UI_GetThemeColorShadeAlpha4fv(TH_ACTIVE, 0, -40, color); + } + else { + UI_GetThemeColorShadeAlpha4fv(TH_SELECT, 0, -40, color); + } + + UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color); + } + + /* label */ + node_draw_frame_label(ntree, node, snode->aspect); + + UI_ThemeClearColor(color_id); + + UI_block_end(C, node->block); + UI_block_draw(C, node->block); + node->block = NULL; } static int node_resize_area_frame(bNode *node, int x, int y) { - const float size = 10.0f; - NodeFrame *data = (NodeFrame *)node->storage; - rctf totr = node->totr; - int dir = 0; + const float size = 10.0f; + NodeFrame *data = (NodeFrame *)node->storage; + rctf totr = node->totr; + int dir = 0; - /* shrinking frame size is determined by child nodes */ - if (!(data->flag & NODE_FRAME_RESIZEABLE)) { - return 0; - } + /* shrinking frame size is determined by child nodes */ + if (!(data->flag & NODE_FRAME_RESIZEABLE)) { + return 0; + } - if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax) { - dir |= NODE_RESIZE_RIGHT; - } - if (x >= totr.xmin && x < totr.xmin + size && y >= totr.ymin && y < totr.ymax) { - dir |= NODE_RESIZE_LEFT; - } - if (x >= totr.xmin && x < totr.xmax && y >= totr.ymax - size && y < totr.ymax) { - dir |= NODE_RESIZE_TOP; - } - if (x >= totr.xmin && x < totr.xmax && y >= totr.ymin && y < totr.ymin + size) { - dir |= NODE_RESIZE_BOTTOM; - } + if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax) { + dir |= NODE_RESIZE_RIGHT; + } + if (x >= totr.xmin && x < totr.xmin + size && y >= totr.ymin && y < totr.ymax) { + dir |= NODE_RESIZE_LEFT; + } + if (x >= totr.xmin && x < totr.xmax && y >= totr.ymax - size && y < totr.ymax) { + dir |= NODE_RESIZE_TOP; + } + if (x >= totr.xmin && x < totr.xmax && y >= totr.ymin && y < totr.ymin + size) { + dir |= NODE_RESIZE_BOTTOM; + } - return dir; + return dir; } static void node_buts_frame_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "label_size", 0, IFACE_("Label Size"), ICON_NONE); - uiItemR(layout, ptr, "shrink", 0, IFACE_("Shrink"), ICON_NONE); - uiItemR(layout, ptr, "text", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "label_size", 0, IFACE_("Label Size"), ICON_NONE); + uiItemR(layout, ptr, "shrink", 0, IFACE_("Shrink"), ICON_NONE); + uiItemR(layout, ptr, "text", 0, NULL, ICON_NONE); } +#define NODE_REROUTE_SIZE 8.0f -#define NODE_REROUTE_SIZE 8.0f - -static void node_draw_reroute_prepare(const bContext *UNUSED(C), bNodeTree *UNUSED(ntree), bNode *node) +static void node_draw_reroute_prepare(const bContext *UNUSED(C), + bNodeTree *UNUSED(ntree), + bNode *node) { - bNodeSocket *nsock; - float locx, locy; - float size = NODE_REROUTE_SIZE; + bNodeSocket *nsock; + float locx, locy; + float size = NODE_REROUTE_SIZE; - /* get "global" coords */ - node_to_view(node, 0.0f, 0.0f, &locx, &locy); + /* get "global" coords */ + node_to_view(node, 0.0f, 0.0f, &locx, &locy); - /* reroute node has exactly one input and one output, both in the same place */ - nsock = node->outputs.first; - nsock->locx = locx; - nsock->locy = locy; + /* reroute node has exactly one input and one output, both in the same place */ + nsock = node->outputs.first; + nsock->locx = locx; + nsock->locy = locy; - nsock = node->inputs.first; - nsock->locx = locx; - nsock->locy = locy; + nsock = node->inputs.first; + nsock->locx = locx; + nsock->locy = locy; - node->width = size * 2; - node->totr.xmin = locx - size; - node->totr.xmax = locx + size; - node->totr.ymax = locy + size; - node->totr.ymin = locy - size; + node->width = size * 2; + node->totr.xmin = locx - size; + node->totr.xmax = locx + size; + node->totr.ymax = locy + size; + node->totr.ymin = locy - size; } -static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED(snode), - bNodeTree *ntree, bNode *node, bNodeInstanceKey UNUSED(key)) +static void node_draw_reroute(const bContext *C, + ARegion *ar, + SpaceNode *UNUSED(snode), + bNodeTree *ntree, + bNode *node, + bNodeInstanceKey UNUSED(key)) { - char showname[128]; /* 128 used below */ - rctf *rct = &node->totr; + char showname[128]; /* 128 used below */ + rctf *rct = &node->totr; - /* skip if out of view */ - if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax || - node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax) - { - UI_block_end(C, node->block); - node->block = NULL; - return; - } + /* skip if out of view */ + if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax || + node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax) { + UI_block_end(C, node->block); + node->block = NULL; + return; + } - /* XXX only kept for debugging - * selection state is indicated by socket outline below! - */ + /* XXX only kept for debugging + * selection state is indicated by socket outline below! + */ #if 0 - float size = NODE_REROUTE_SIZE; - - /* body */ - float debug_color[4]; - UI_draw_roundbox_corner_set(UI_CNR_ALL); - UI_GetThemeColor4fv(TH_NODE, debug_color); - UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size, debug_color); - - /* outline active and selected emphasis */ - if (node->flag & SELECT) { - GPU_blend(true); - GPU_line_smooth(true); - /* using different shades of TH_TEXT_HI for the empasis, like triangle */ - if (node->flag & NODE_ACTIVE) { - UI_GetThemeColorShadeAlpha4fv(TH_TEXT_HI, 0, -40, debug_color); - } - else { - UI_GetThemeColorShadeAlpha4fv(TH_TEXT_HI, -20, -120, debug_color); - } - UI_draw_roundbox_4fv(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size, debug_color); - - GPU_line_smooth(false); - GPU_blend(false); - } + float size = NODE_REROUTE_SIZE; + + /* body */ + float debug_color[4]; + UI_draw_roundbox_corner_set(UI_CNR_ALL); + UI_GetThemeColor4fv(TH_NODE, debug_color); + UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size, debug_color); + + /* outline active and selected emphasis */ + if (node->flag & SELECT) { + GPU_blend(true); + GPU_line_smooth(true); + /* using different shades of TH_TEXT_HI for the empasis, like triangle */ + if (node->flag & NODE_ACTIVE) { + UI_GetThemeColorShadeAlpha4fv(TH_TEXT_HI, 0, -40, debug_color); + } + else { + UI_GetThemeColorShadeAlpha4fv(TH_TEXT_HI, -20, -120, debug_color); + } + UI_draw_roundbox_4fv(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size, debug_color); + + GPU_line_smooth(false); + GPU_blend(false); + } #endif - if (node->label[0] != '\0') { - /* draw title (node label) */ - BLI_strncpy(showname, node->label, sizeof(showname)); - uiDefBut(node->block, UI_BTYPE_LABEL, 0, showname, - (int)(rct->xmin - NODE_DYS), (int)(rct->ymax), - (short)512, (short)NODE_DY, - NULL, 0, 0, 0, 0, NULL); - } - - /* only draw input socket. as they all are placed on the same position. - * highlight also if node itself is selected, since we don't display the node body separately! - */ - node_draw_sockets(&ar->v2d, C, ntree, node, false, node->flag & SELECT); - - UI_block_end(C, node->block); - UI_block_draw(C, node->block); - node->block = NULL; + if (node->label[0] != '\0') { + /* draw title (node label) */ + BLI_strncpy(showname, node->label, sizeof(showname)); + uiDefBut(node->block, + UI_BTYPE_LABEL, + 0, + showname, + (int)(rct->xmin - NODE_DYS), + (int)(rct->ymax), + (short)512, + (short)NODE_DY, + NULL, + 0, + 0, + 0, + 0, + NULL); + } + + /* only draw input socket. as they all are placed on the same position. + * highlight also if node itself is selected, since we don't display the node body separately! + */ + node_draw_sockets(&ar->v2d, C, ntree, node, false, node->flag & SELECT); + + UI_block_end(C, node->block); + UI_block_draw(C, node->block); + node->block = NULL; } /* Special tweak area for reroute node. @@ -613,3175 +628,3353 @@ static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED( */ static int node_tweak_area_reroute(bNode *node, int x, int y) { - /* square of tweak radius */ - const float tweak_radius_sq = SQUARE(24); + /* square of tweak radius */ + const float tweak_radius_sq = SQUARE(24); - bNodeSocket *sock = node->inputs.first; - float dx = sock->locx - x; - float dy = sock->locy - y; - return (dx * dx + dy * dy <= tweak_radius_sq); + bNodeSocket *sock = node->inputs.first; + float dx = sock->locx - x; + float dy = sock->locy - y; + return (dx * dx + dy * dy <= tweak_radius_sq); } static void node_common_set_butfunc(bNodeType *ntype) { - switch (ntype->type) { - case NODE_GROUP: - ntype->draw_buttons = node_draw_buttons_group; - break; - case NODE_FRAME: - ntype->draw_nodetype = node_draw_frame; - ntype->draw_nodetype_prepare = node_draw_frame_prepare; - ntype->draw_buttons_ex = node_buts_frame_ex; - ntype->resize_area_func = node_resize_area_frame; - break; - case NODE_REROUTE: - ntype->draw_nodetype = node_draw_reroute; - ntype->draw_nodetype_prepare = node_draw_reroute_prepare; - ntype->tweak_area_func = node_tweak_area_reroute; - break; - } + switch (ntype->type) { + case NODE_GROUP: + ntype->draw_buttons = node_draw_buttons_group; + break; + case NODE_FRAME: + ntype->draw_nodetype = node_draw_frame; + ntype->draw_nodetype_prepare = node_draw_frame_prepare; + ntype->draw_buttons_ex = node_buts_frame_ex; + ntype->resize_area_func = node_resize_area_frame; + break; + case NODE_REROUTE: + ntype->draw_nodetype = node_draw_reroute; + ntype->draw_nodetype_prepare = node_draw_reroute_prepare; + ntype->tweak_area_func = node_tweak_area_reroute; + break; + } } /* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */ -static void node_buts_image_user(uiLayout *layout, bContext *C, PointerRNA *ptr, - PointerRNA *imaptr, PointerRNA *iuserptr, +static void node_buts_image_user(uiLayout *layout, + bContext *C, + PointerRNA *ptr, + PointerRNA *imaptr, + PointerRNA *iuserptr, bool compositor) { - uiLayout *col; - int source; + uiLayout *col; + int source; - if (!imaptr->data) { - return; - } + if (!imaptr->data) { + return; + } - col = uiLayoutColumn(layout, false); + col = uiLayoutColumn(layout, false); - uiItemR(col, imaptr, "source", 0, "", ICON_NONE); + uiItemR(col, imaptr, "source", 0, "", ICON_NONE); - source = RNA_enum_get(imaptr, "source"); + source = RNA_enum_get(imaptr, "source"); - if (source == IMA_SRC_SEQUENCE) { - /* don't use iuser->framenr directly - * because it may not be updated if auto-refresh is off */ - Scene *scene = CTX_data_scene(C); - ImageUser *iuser = iuserptr->data; - /* Image *ima = imaptr->data; */ /* UNUSED */ + if (source == IMA_SRC_SEQUENCE) { + /* don't use iuser->framenr directly + * because it may not be updated if auto-refresh is off */ + Scene *scene = CTX_data_scene(C); + ImageUser *iuser = iuserptr->data; + /* Image *ima = imaptr->data; */ /* UNUSED */ - char numstr[32]; - const int framenr = BKE_image_user_frame_get(iuser, CFRA, NULL); - BLI_snprintf(numstr, sizeof(numstr), IFACE_("Frame: %d"), framenr); - uiItemL(layout, numstr, ICON_NONE); - } + char numstr[32]; + const int framenr = BKE_image_user_frame_get(iuser, CFRA, NULL); + BLI_snprintf(numstr, sizeof(numstr), IFACE_("Frame: %d"), framenr); + uiItemL(layout, numstr, ICON_NONE); + } - if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) { - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "use_auto_refresh", 0, NULL, ICON_NONE); - } + if (ELEM(source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) { + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "frame_duration", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "frame_start", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "frame_offset", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "use_cyclic", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "use_auto_refresh", 0, NULL, ICON_NONE); + } - if (compositor && - RNA_enum_get(imaptr, "type") == IMA_TYPE_MULTILAYER && - RNA_boolean_get(ptr, "has_layers")) - { - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE); - } + if (compositor && RNA_enum_get(imaptr, "type") == IMA_TYPE_MULTILAYER && + RNA_boolean_get(ptr, "has_layers")) { + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE); + } } static void node_shader_buts_mapping(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row, *col, *sub; + uiLayout *row, *col, *sub; - uiItemR(layout, ptr, "vector_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemR(layout, ptr, "vector_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(layout, false); + row = uiLayoutRow(layout, false); - col = uiLayoutColumn(row, true); - uiItemL(col, IFACE_("Location:"), ICON_NONE); - uiItemR(col, ptr, "translation", 0, "", ICON_NONE); + col = uiLayoutColumn(row, true); + uiItemL(col, IFACE_("Location:"), ICON_NONE); + uiItemR(col, ptr, "translation", 0, "", ICON_NONE); - col = uiLayoutColumn(row, true); - uiItemL(col, IFACE_("Rotation:"), ICON_NONE); - uiItemR(col, ptr, "rotation", 0, "", ICON_NONE); + col = uiLayoutColumn(row, true); + uiItemL(col, IFACE_("Rotation:"), ICON_NONE); + uiItemR(col, ptr, "rotation", 0, "", ICON_NONE); - col = uiLayoutColumn(row, true); - uiItemL(col, IFACE_("Scale:"), ICON_NONE); - uiItemR(col, ptr, "scale", 0, "", ICON_NONE); + col = uiLayoutColumn(row, true); + uiItemL(col, IFACE_("Scale:"), ICON_NONE); + uiItemR(col, ptr, "scale", 0, "", ICON_NONE); - row = uiLayoutRow(layout, false); + row = uiLayoutRow(layout, false); - col = uiLayoutColumn(row, true); - uiItemR(col, ptr, "use_min", 0, IFACE_("Min"), ICON_NONE); - sub = uiLayoutColumn(col, true); - uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min")); - uiItemR(sub, ptr, "min", 0, "", ICON_NONE); + col = uiLayoutColumn(row, true); + uiItemR(col, ptr, "use_min", 0, IFACE_("Min"), ICON_NONE); + sub = uiLayoutColumn(col, true); + uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min")); + uiItemR(sub, ptr, "min", 0, "", ICON_NONE); - col = uiLayoutColumn(row, true); - uiItemR(col, ptr, "use_max", 0, IFACE_("Max"), ICON_NONE); - sub = uiLayoutColumn(col, true); - uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max")); - uiItemR(sub, ptr, "max", 0, "", ICON_NONE); + col = uiLayoutColumn(row, true); + uiItemR(col, ptr, "use_max", 0, IFACE_("Max"), ICON_NONE); + sub = uiLayoutColumn(col, true); + uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max")); + uiItemR(sub, ptr, "max", 0, "", ICON_NONE); } static void node_shader_buts_vect_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "operation", 0, "", ICON_NONE); + uiItemR(layout, ptr, "operation", 0, "", ICON_NONE); } static void node_shader_buts_vect_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "vector_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - uiItemR(layout, ptr, "convert_from", 0, "", ICON_NONE); - uiItemR(layout, ptr, "convert_to", 0, "", ICON_NONE); + uiItemR(layout, ptr, "vector_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemR(layout, ptr, "convert_from", 0, "", ICON_NONE); + uiItemR(layout, ptr, "convert_to", 0, "", ICON_NONE); } static void node_shader_buts_attribute(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "attribute_name", 0, IFACE_("Name"), ICON_NONE); + uiItemR(layout, ptr, "attribute_name", 0, IFACE_("Name"), ICON_NONE); } static void node_shader_buts_wireframe(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "use_pixel_size", 0, NULL, 0); + uiItemR(layout, ptr, "use_pixel_size", 0, NULL, 0); } static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA *ptr) { - PointerRNA imaptr = RNA_pointer_get(ptr, "image"); - PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); + PointerRNA imaptr = RNA_pointer_get(ptr, "image"); + PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); - uiLayoutSetContextPointer(layout, "image_user", &iuserptr); - uiTemplateID(layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE); - uiItemR(layout, ptr, "interpolation", 0, "", ICON_NONE); - uiItemR(layout, ptr, "projection", 0, "", ICON_NONE); + uiLayoutSetContextPointer(layout, "image_user", &iuserptr); + uiTemplateID(layout, + C, + ptr, + "image", + "IMAGE_OT_new", + "IMAGE_OT_open", + NULL, + UI_TEMPLATE_ID_FILTER_ALL, + false); + uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE); + uiItemR(layout, ptr, "interpolation", 0, "", ICON_NONE); + uiItemR(layout, ptr, "projection", 0, "", ICON_NONE); - if (RNA_enum_get(ptr, "projection") == SHD_PROJ_BOX) { - uiItemR(layout, ptr, "projection_blend", 0, "Blend", ICON_NONE); - } + if (RNA_enum_get(ptr, "projection") == SHD_PROJ_BOX) { + uiItemR(layout, ptr, "projection_blend", 0, "Blend", ICON_NONE); + } - uiItemR(layout, ptr, "extension", 0, "", ICON_NONE); + uiItemR(layout, ptr, "extension", 0, "", ICON_NONE); - /* note: image user properties used directly here, unlike compositor image node, - * which redefines them in the node struct RNA to get proper updates. - */ - node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false); + /* note: image user properties used directly here, unlike compositor image node, + * which redefines them in the node struct RNA to get proper updates. + */ + node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false); } static void node_shader_buts_tex_image_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) { - PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); - uiTemplateImage(layout, C, ptr, "image", &iuserptr, 0, 0); + PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); + uiTemplateImage(layout, C, ptr, "image", &iuserptr, 0, 0); } static void node_shader_buts_tex_environment(uiLayout *layout, bContext *C, PointerRNA *ptr) { - PointerRNA imaptr = RNA_pointer_get(ptr, "image"); - PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); + PointerRNA imaptr = RNA_pointer_get(ptr, "image"); + PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); - uiLayoutSetContextPointer(layout, "image_user", &iuserptr); - uiTemplateID( - layout, C, ptr, "image", - "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiLayoutSetContextPointer(layout, "image_user", &iuserptr); + uiTemplateID(layout, + C, + ptr, + "image", + "IMAGE_OT_new", + "IMAGE_OT_open", + NULL, + UI_TEMPLATE_ID_FILTER_ALL, + false); - node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false); + node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false); - uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE); - uiItemR(layout, ptr, "interpolation", 0, "", ICON_NONE); - uiItemR(layout, ptr, "projection", 0, "", ICON_NONE); + uiItemR(layout, ptr, "color_space", 0, "", ICON_NONE); + uiItemR(layout, ptr, "interpolation", 0, "", ICON_NONE); + uiItemR(layout, ptr, "projection", 0, "", ICON_NONE); } static void node_shader_buts_tex_environment_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) { - PointerRNA imaptr = RNA_pointer_get(ptr, "image"); - PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); - Image *ima = imaptr.data; - - uiLayoutSetContextPointer(layout, "image_user", &iuserptr); - uiTemplateID( - layout, C, ptr, "image", - "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - - if (!ima) { - return; - } - - uiItemR(layout, &imaptr, "source", 0, IFACE_("Source"), ICON_NONE); - - if (!(ELEM(ima->source, IMA_SRC_GENERATED, IMA_SRC_VIEWER))) { - uiLayout *row = uiLayoutRow(layout, true); - const bool is_packed = BKE_image_has_packedfile(ima); - - if (is_packed) { - uiItemO(row, "", ICON_PACKAGE, "image.unpack"); - } - else { - uiItemO(row, "", ICON_UGLYPACKAGE, "image.pack"); - } - - row = uiLayoutRow(row, true); - uiLayoutSetEnabled(row, !is_packed); - uiItemR(row, &imaptr, "filepath", 0, "", ICON_NONE); - uiItemO(row, "", ICON_FILE_REFRESH, "image.reload"); - } - - /* multilayer? */ - if (ima->type == IMA_TYPE_MULTILAYER && ima->rr) { - uiTemplateImageLayers(layout, C, ima, iuserptr.data); - } - else if (ima->source != IMA_SRC_GENERATED) { - uiTemplateImageInfo(layout, C, ima, iuserptr.data); - } - - uiItemR(layout, ptr, "color_space", 0, IFACE_("Color Space"), ICON_NONE); - uiItemR(layout, ptr, "interpolation", 0, IFACE_("Interpolation"), ICON_NONE); - uiItemR(layout, ptr, "projection", 0, IFACE_("Projection"), ICON_NONE); + PointerRNA imaptr = RNA_pointer_get(ptr, "image"); + PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user"); + Image *ima = imaptr.data; + + uiLayoutSetContextPointer(layout, "image_user", &iuserptr); + uiTemplateID(layout, + C, + ptr, + "image", + "IMAGE_OT_new", + "IMAGE_OT_open", + NULL, + UI_TEMPLATE_ID_FILTER_ALL, + false); + + if (!ima) { + return; + } + + uiItemR(layout, &imaptr, "source", 0, IFACE_("Source"), ICON_NONE); + + if (!(ELEM(ima->source, IMA_SRC_GENERATED, IMA_SRC_VIEWER))) { + uiLayout *row = uiLayoutRow(layout, true); + const bool is_packed = BKE_image_has_packedfile(ima); + + if (is_packed) { + uiItemO(row, "", ICON_PACKAGE, "image.unpack"); + } + else { + uiItemO(row, "", ICON_UGLYPACKAGE, "image.pack"); + } + + row = uiLayoutRow(row, true); + uiLayoutSetEnabled(row, !is_packed); + uiItemR(row, &imaptr, "filepath", 0, "", ICON_NONE); + uiItemO(row, "", ICON_FILE_REFRESH, "image.reload"); + } + + /* multilayer? */ + if (ima->type == IMA_TYPE_MULTILAYER && ima->rr) { + uiTemplateImageLayers(layout, C, ima, iuserptr.data); + } + else if (ima->source != IMA_SRC_GENERATED) { + uiTemplateImageInfo(layout, C, ima, iuserptr.data); + } + + uiItemR(layout, ptr, "color_space", 0, IFACE_("Color Space"), ICON_NONE); + uiItemR(layout, ptr, "interpolation", 0, IFACE_("Interpolation"), ICON_NONE); + uiItemR(layout, ptr, "projection", 0, IFACE_("Projection"), ICON_NONE); } static void node_shader_buts_tex_sky(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "sky_type", 0, "", ICON_NONE); - uiItemR(layout, ptr, "sun_direction", 0, "", ICON_NONE); - uiItemR(layout, ptr, "turbidity", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "sky_type", 0, "", ICON_NONE); + uiItemR(layout, ptr, "sun_direction", 0, "", ICON_NONE); + uiItemR(layout, ptr, "turbidity", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "sky_type") == SHD_SKY_NEW) { - uiItemR(layout, ptr, "ground_albedo", 0, NULL, ICON_NONE); - } + if (RNA_enum_get(ptr, "sky_type") == SHD_SKY_NEW) { + uiItemR(layout, ptr, "ground_albedo", 0, NULL, ICON_NONE); + } } static void node_shader_buts_tex_gradient(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "gradient_type", 0, "", ICON_NONE); + uiItemR(layout, ptr, "gradient_type", 0, "", ICON_NONE); } static void node_shader_buts_tex_magic(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "turbulence_depth", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "turbulence_depth", 0, NULL, ICON_NONE); } static void node_shader_buts_tex_brick(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "offset", UI_ITEM_R_SLIDER, IFACE_("Offset"), ICON_NONE); - uiItemR(col, ptr, "offset_frequency", 0, IFACE_("Frequency"), ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "offset", UI_ITEM_R_SLIDER, IFACE_("Offset"), ICON_NONE); + uiItemR(col, ptr, "offset_frequency", 0, IFACE_("Frequency"), ICON_NONE); - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "squash", 0, IFACE_("Squash"), ICON_NONE); - uiItemR(col, ptr, "squash_frequency", 0, IFACE_("Frequency"), ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "squash", 0, IFACE_("Squash"), ICON_NONE); + uiItemR(col, ptr, "squash_frequency", 0, IFACE_("Frequency"), ICON_NONE); } static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "wave_type", 0, "", ICON_NONE); - uiItemR(layout, ptr, "wave_profile", 0, "", ICON_NONE); + uiItemR(layout, ptr, "wave_type", 0, "", ICON_NONE); + uiItemR(layout, ptr, "wave_profile", 0, "", ICON_NONE); } static void node_shader_buts_tex_musgrave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "musgrave_type", 0, "", ICON_NONE); + uiItemR(layout, ptr, "musgrave_type", 0, "", ICON_NONE); } static void node_shader_buts_tex_voronoi(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "coloring", 0, "", ICON_NONE); - uiItemR(layout, ptr, "distance", 0, "", ICON_NONE); - uiItemR(layout, ptr, "feature", 0, "", ICON_NONE); -} - -static void node_shader_buts_tex_pointdensity(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) -{ - bNode *node = ptr->data; - NodeShaderTexPointDensity *shader_point_density = node->storage; - Object *ob = (Object *)node->id; - PointerRNA ob_ptr, obdata_ptr; - - RNA_id_pointer_create((ID *)ob, &ob_ptr); - RNA_id_pointer_create(ob ? (ID *)ob->data : NULL, &obdata_ptr); - - uiItemR(layout, ptr, "point_source", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - uiItemR(layout, ptr, "object", 0, NULL, ICON_NONE); - - if (node->id && shader_point_density->point_source == SHD_POINTDENSITY_SOURCE_PSYS) { - PointerRNA dataptr; - RNA_id_pointer_create((ID *)node->id, &dataptr); - uiItemPointerR(layout, ptr, "particle_system", &dataptr, "particle_systems", NULL, ICON_NONE); - } - - uiItemR(layout, ptr, "space", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "radius", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "interpolation", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "resolution", 0, NULL, ICON_NONE); - if (shader_point_density->point_source == SHD_POINTDENSITY_SOURCE_PSYS) { - uiItemR(layout, ptr, "particle_color_source", 0, NULL, ICON_NONE); - } - else { - uiItemR(layout, ptr, "vertex_color_source", 0, NULL, ICON_NONE); - if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTWEIGHT) { - if (ob_ptr.data) { - uiItemPointerR(layout, ptr, "vertex_attribute_name", &ob_ptr, "vertex_groups", "", ICON_NONE); - } - } - if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTCOL) { - if (obdata_ptr.data) { - uiItemPointerR(layout, ptr, "vertex_attribute_name", &obdata_ptr, "vertex_colors", "", ICON_NONE); - } - } - } + uiItemR(layout, ptr, "coloring", 0, "", ICON_NONE); + uiItemR(layout, ptr, "distance", 0, "", ICON_NONE); + uiItemR(layout, ptr, "feature", 0, "", ICON_NONE); +} + +static void node_shader_buts_tex_pointdensity(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) +{ + bNode *node = ptr->data; + NodeShaderTexPointDensity *shader_point_density = node->storage; + Object *ob = (Object *)node->id; + PointerRNA ob_ptr, obdata_ptr; + + RNA_id_pointer_create((ID *)ob, &ob_ptr); + RNA_id_pointer_create(ob ? (ID *)ob->data : NULL, &obdata_ptr); + + uiItemR(layout, ptr, "point_source", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemR(layout, ptr, "object", 0, NULL, ICON_NONE); + + if (node->id && shader_point_density->point_source == SHD_POINTDENSITY_SOURCE_PSYS) { + PointerRNA dataptr; + RNA_id_pointer_create((ID *)node->id, &dataptr); + uiItemPointerR(layout, ptr, "particle_system", &dataptr, "particle_systems", NULL, ICON_NONE); + } + + uiItemR(layout, ptr, "space", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "radius", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "interpolation", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "resolution", 0, NULL, ICON_NONE); + if (shader_point_density->point_source == SHD_POINTDENSITY_SOURCE_PSYS) { + uiItemR(layout, ptr, "particle_color_source", 0, NULL, ICON_NONE); + } + else { + uiItemR(layout, ptr, "vertex_color_source", 0, NULL, ICON_NONE); + if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTWEIGHT) { + if (ob_ptr.data) { + uiItemPointerR( + layout, ptr, "vertex_attribute_name", &ob_ptr, "vertex_groups", "", ICON_NONE); + } + } + if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTCOL) { + if (obdata_ptr.data) { + uiItemPointerR( + layout, ptr, "vertex_attribute_name", &obdata_ptr, "vertex_colors", "", ICON_NONE); + } + } + } } static void node_shader_buts_tex_coord(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "object", 0, NULL, 0); - uiItemR(layout, ptr, "from_instancer", 0, NULL, 0); + uiItemR(layout, ptr, "object", 0, NULL, 0); + uiItemR(layout, ptr, "from_instancer", 0, NULL, 0); } static void node_shader_buts_bump(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "invert", 0, NULL, 0); + uiItemR(layout, ptr, "invert", 0, NULL, 0); } static void node_shader_buts_uvmap(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiItemR(layout, ptr, "from_instancer", 0, NULL, 0); + uiItemR(layout, ptr, "from_instancer", 0, NULL, 0); - if (!RNA_boolean_get(ptr, "from_instancer")) { - PointerRNA obptr = CTX_data_pointer_get(C, "active_object"); + if (!RNA_boolean_get(ptr, "from_instancer")) { + PointerRNA obptr = CTX_data_pointer_get(C, "active_object"); - if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) { - PointerRNA dataptr = RNA_pointer_get(&obptr, "data"); - uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE); - } - } + if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) { + PointerRNA dataptr = RNA_pointer_get(&obptr, "data"); + uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE); + } + } } static void node_shader_buts_uvalongstroke(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "use_tips", 0, NULL, 0); + uiItemR(layout, ptr, "use_tips", 0, NULL, 0); } static void node_shader_buts_normal_map(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiItemR(layout, ptr, "space", 0, "", 0); + uiItemR(layout, ptr, "space", 0, "", 0); - if (RNA_enum_get(ptr, "space") == SHD_SPACE_TANGENT) { - PointerRNA obptr = CTX_data_pointer_get(C, "active_object"); + if (RNA_enum_get(ptr, "space") == SHD_SPACE_TANGENT) { + PointerRNA obptr = CTX_data_pointer_get(C, "active_object"); - if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) { - PointerRNA dataptr = RNA_pointer_get(&obptr, "data"); - uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE); - } - else { - uiItemR(layout, ptr, "uv_map", 0, "", 0); - } - } + if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) { + PointerRNA dataptr = RNA_pointer_get(&obptr, "data"); + uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE); + } + else { + uiItemR(layout, ptr, "uv_map", 0, "", 0); + } + } } static void node_shader_buts_displacement(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "space", 0, "", 0); + uiItemR(layout, ptr, "space", 0, "", 0); } static void node_shader_buts_tangent(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiLayout *split, *row; + uiLayout *split, *row; - split = uiLayoutSplit(layout, 0.0f, false); + split = uiLayoutSplit(layout, 0.0f, false); - uiItemR(split, ptr, "direction_type", 0, "", 0); + uiItemR(split, ptr, "direction_type", 0, "", 0); - row = uiLayoutRow(split, false); + row = uiLayoutRow(split, false); - if (RNA_enum_get(ptr, "direction_type") == SHD_TANGENT_UVMAP) { - PointerRNA obptr = CTX_data_pointer_get(C, "active_object"); + if (RNA_enum_get(ptr, "direction_type") == SHD_TANGENT_UVMAP) { + PointerRNA obptr = CTX_data_pointer_get(C, "active_object"); - if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) { - PointerRNA dataptr = RNA_pointer_get(&obptr, "data"); - uiItemPointerR(row, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE); - } - else { - uiItemR(row, ptr, "uv_map", 0, "", 0); - } - } - else { - uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, 0); - } + if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) { + PointerRNA dataptr = RNA_pointer_get(&obptr, "data"); + uiItemPointerR(row, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE); + } + else { + uiItemR(row, ptr, "uv_map", 0, "", 0); + } + } + else { + uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, 0); + } } static void node_shader_buts_glossy(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE); + uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE); } static void node_shader_buts_principled(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE); - uiItemR(layout, ptr, "subsurface_method", 0, "", ICON_NONE); + uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE); + uiItemR(layout, ptr, "subsurface_method", 0, "", ICON_NONE); } static void node_shader_buts_anisotropic(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE); + uiItemR(layout, ptr, "distribution", 0, "", ICON_NONE); } static void node_shader_buts_subsurface(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "falloff", 0, "", ICON_NONE); + uiItemR(layout, ptr, "falloff", 0, "", ICON_NONE); } - static void node_shader_buts_toon(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "component", 0, "", ICON_NONE); + uiItemR(layout, ptr, "component", 0, "", ICON_NONE); } static void node_shader_buts_hair(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "component", 0, "", ICON_NONE); + uiItemR(layout, ptr, "component", 0, "", ICON_NONE); } -static void node_shader_buts_principled_hair(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void node_shader_buts_principled_hair(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { - uiItemR(layout, ptr, "parametrization", 0, "", ICON_NONE); + uiItemR(layout, ptr, "parametrization", 0, "", ICON_NONE); } static void node_shader_buts_ies(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row; + uiLayout *row; - row = uiLayoutRow(layout, false); - uiItemR(row, ptr, "mode", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + row = uiLayoutRow(layout, false); + uiItemR(row, ptr, "mode", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(layout, true); + row = uiLayoutRow(layout, true); - if (RNA_enum_get(ptr, "mode") == NODE_IES_INTERNAL) { - uiItemR(row, ptr, "ies", 0, "", ICON_NONE); - } - else { - uiItemR(row, ptr, "filepath", 0, "", ICON_NONE); - } + if (RNA_enum_get(ptr, "mode") == NODE_IES_INTERNAL) { + uiItemR(row, ptr, "ies", 0, "", ICON_NONE); + } + else { + uiItemR(row, ptr, "filepath", 0, "", ICON_NONE); + } } static void node_shader_buts_script(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row; + uiLayout *row; - row = uiLayoutRow(layout, false); - uiItemR(row, ptr, "mode", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + row = uiLayoutRow(layout, false); + uiItemR(row, ptr, "mode", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(layout, true); + row = uiLayoutRow(layout, true); - if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_INTERNAL) { - uiItemR(row, ptr, "script", 0, "", ICON_NONE); - } - else { - uiItemR(row, ptr, "filepath", 0, "", ICON_NONE); - } + if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_INTERNAL) { + uiItemR(row, ptr, "script", 0, "", ICON_NONE); + } + else { + uiItemR(row, ptr, "filepath", 0, "", ICON_NONE); + } - uiItemO(row, "", ICON_FILE_REFRESH, "node.shader_script_update"); + uiItemO(row, "", ICON_FILE_REFRESH, "node.shader_script_update"); } static void node_shader_buts_script_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiItemS(layout); + uiItemS(layout); - node_shader_buts_script(layout, C, ptr); + node_shader_buts_script(layout, C, ptr); -#if 0 /* not implemented yet */ - if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_EXTERNAL) - uiItemR(layout, ptr, "use_auto_update", 0, NULL, ICON_NONE); +#if 0 /* not implemented yet */ + if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_EXTERNAL) + uiItemR(layout, ptr, "use_auto_update", 0, NULL, ICON_NONE); #endif } static void node_buts_output_shader(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "target", 0, "", ICON_NONE); + uiItemR(layout, ptr, "target", 0, "", ICON_NONE); } static void node_buts_output_linestyle(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row, *col; + uiLayout *row, *col; - col = uiLayoutColumn(layout, false); - row = uiLayoutRow(col, true); - uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE); - uiItemR(col, ptr, "use_clamp", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + row = uiLayoutRow(col, true); + uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE); + uiItemR(col, ptr, "use_clamp", 0, NULL, ICON_NONE); } static void node_shader_buts_bevel(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "samples", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "samples", 0, NULL, ICON_NONE); } -static void node_shader_buts_ambient_occlusion(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void node_shader_buts_ambient_occlusion(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { - uiItemR(layout, ptr, "samples", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "inside", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "only_local", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "samples", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "inside", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "only_local", 0, NULL, ICON_NONE); } /* only once called */ static void node_shader_set_butfunc(bNodeType *ntype) { - switch (ntype->type) { - case SH_NODE_NORMAL: - ntype->draw_buttons = node_buts_normal; - break; - case SH_NODE_CURVE_VEC: - ntype->draw_buttons = node_buts_curvevec; - break; - case SH_NODE_CURVE_RGB: - ntype->draw_buttons = node_buts_curvecol; - break; - case SH_NODE_MAPPING: - ntype->draw_buttons = node_shader_buts_mapping; - break; - case SH_NODE_VALUE: - ntype->draw_buttons = node_buts_value; - break; - case SH_NODE_RGB: - ntype->draw_buttons = node_buts_rgb; - break; - case SH_NODE_MIX_RGB: - ntype->draw_buttons = node_buts_mix_rgb; - break; - case SH_NODE_VALTORGB: - ntype->draw_buttons = node_buts_colorramp; - break; - case SH_NODE_MATH: - ntype->draw_buttons = node_buts_math; - break; - case SH_NODE_VECT_MATH: - ntype->draw_buttons = node_shader_buts_vect_math; - break; - case SH_NODE_VECT_TRANSFORM: - ntype->draw_buttons = node_shader_buts_vect_transform; - break; - case SH_NODE_ATTRIBUTE: - ntype->draw_buttons = node_shader_buts_attribute; - break; - case SH_NODE_WIREFRAME: - ntype->draw_buttons = node_shader_buts_wireframe; - break; - case SH_NODE_TEX_SKY: - ntype->draw_buttons = node_shader_buts_tex_sky; - break; - case SH_NODE_TEX_IMAGE: - ntype->draw_buttons = node_shader_buts_tex_image; - ntype->draw_buttons_ex = node_shader_buts_tex_image_ex; - break; - case SH_NODE_TEX_ENVIRONMENT: - ntype->draw_buttons = node_shader_buts_tex_environment; - ntype->draw_buttons_ex = node_shader_buts_tex_environment_ex; - break; - case SH_NODE_TEX_GRADIENT: - ntype->draw_buttons = node_shader_buts_tex_gradient; - break; - case SH_NODE_TEX_MAGIC: - ntype->draw_buttons = node_shader_buts_tex_magic; - break; - case SH_NODE_TEX_BRICK: - ntype->draw_buttons = node_shader_buts_tex_brick; - break; - case SH_NODE_TEX_WAVE: - ntype->draw_buttons = node_shader_buts_tex_wave; - break; - case SH_NODE_TEX_MUSGRAVE: - ntype->draw_buttons = node_shader_buts_tex_musgrave; - break; - case SH_NODE_TEX_VORONOI: - ntype->draw_buttons = node_shader_buts_tex_voronoi; - break; - case SH_NODE_TEX_POINTDENSITY: - ntype->draw_buttons = node_shader_buts_tex_pointdensity; - break; - case SH_NODE_TEX_COORD: - ntype->draw_buttons = node_shader_buts_tex_coord; - break; - case SH_NODE_BUMP: - ntype->draw_buttons = node_shader_buts_bump; - break; - case SH_NODE_NORMAL_MAP: - ntype->draw_buttons = node_shader_buts_normal_map; - break; - case SH_NODE_DISPLACEMENT: - case SH_NODE_VECTOR_DISPLACEMENT: - ntype->draw_buttons = node_shader_buts_displacement; - break; - case SH_NODE_TANGENT: - ntype->draw_buttons = node_shader_buts_tangent; - break; - case SH_NODE_BSDF_GLOSSY: - case SH_NODE_BSDF_GLASS: - case SH_NODE_BSDF_REFRACTION: - ntype->draw_buttons = node_shader_buts_glossy; - break; - case SH_NODE_BSDF_PRINCIPLED: - ntype->draw_buttons = node_shader_buts_principled; - break; - case SH_NODE_BSDF_ANISOTROPIC: - ntype->draw_buttons = node_shader_buts_anisotropic; - break; - case SH_NODE_SUBSURFACE_SCATTERING: - ntype->draw_buttons = node_shader_buts_subsurface; - break; - case SH_NODE_BSDF_TOON: - ntype->draw_buttons = node_shader_buts_toon; - break; - case SH_NODE_BSDF_HAIR: - ntype->draw_buttons = node_shader_buts_hair; - break; - case SH_NODE_BSDF_HAIR_PRINCIPLED: - ntype->draw_buttons = node_shader_buts_principled_hair; - break; - case SH_NODE_SCRIPT: - ntype->draw_buttons = node_shader_buts_script; - ntype->draw_buttons_ex = node_shader_buts_script_ex; - break; - case SH_NODE_UVMAP: - ntype->draw_buttons = node_shader_buts_uvmap; - break; - case SH_NODE_UVALONGSTROKE: - ntype->draw_buttons = node_shader_buts_uvalongstroke; - break; - case SH_NODE_OUTPUT_MATERIAL: - case SH_NODE_OUTPUT_LIGHT: - case SH_NODE_OUTPUT_WORLD: - ntype->draw_buttons = node_buts_output_shader; - break; - case SH_NODE_OUTPUT_LINESTYLE: - ntype->draw_buttons = node_buts_output_linestyle; - break; - case SH_NODE_TEX_IES: - ntype->draw_buttons = node_shader_buts_ies; - break; - case SH_NODE_BEVEL: - ntype->draw_buttons = node_shader_buts_bevel; - break; - case SH_NODE_AMBIENT_OCCLUSION: - ntype->draw_buttons = node_shader_buts_ambient_occlusion; - break; - } + switch (ntype->type) { + case SH_NODE_NORMAL: + ntype->draw_buttons = node_buts_normal; + break; + case SH_NODE_CURVE_VEC: + ntype->draw_buttons = node_buts_curvevec; + break; + case SH_NODE_CURVE_RGB: + ntype->draw_buttons = node_buts_curvecol; + break; + case SH_NODE_MAPPING: + ntype->draw_buttons = node_shader_buts_mapping; + break; + case SH_NODE_VALUE: + ntype->draw_buttons = node_buts_value; + break; + case SH_NODE_RGB: + ntype->draw_buttons = node_buts_rgb; + break; + case SH_NODE_MIX_RGB: + ntype->draw_buttons = node_buts_mix_rgb; + break; + case SH_NODE_VALTORGB: + ntype->draw_buttons = node_buts_colorramp; + break; + case SH_NODE_MATH: + ntype->draw_buttons = node_buts_math; + break; + case SH_NODE_VECT_MATH: + ntype->draw_buttons = node_shader_buts_vect_math; + break; + case SH_NODE_VECT_TRANSFORM: + ntype->draw_buttons = node_shader_buts_vect_transform; + break; + case SH_NODE_ATTRIBUTE: + ntype->draw_buttons = node_shader_buts_attribute; + break; + case SH_NODE_WIREFRAME: + ntype->draw_buttons = node_shader_buts_wireframe; + break; + case SH_NODE_TEX_SKY: + ntype->draw_buttons = node_shader_buts_tex_sky; + break; + case SH_NODE_TEX_IMAGE: + ntype->draw_buttons = node_shader_buts_tex_image; + ntype->draw_buttons_ex = node_shader_buts_tex_image_ex; + break; + case SH_NODE_TEX_ENVIRONMENT: + ntype->draw_buttons = node_shader_buts_tex_environment; + ntype->draw_buttons_ex = node_shader_buts_tex_environment_ex; + break; + case SH_NODE_TEX_GRADIENT: + ntype->draw_buttons = node_shader_buts_tex_gradient; + break; + case SH_NODE_TEX_MAGIC: + ntype->draw_buttons = node_shader_buts_tex_magic; + break; + case SH_NODE_TEX_BRICK: + ntype->draw_buttons = node_shader_buts_tex_brick; + break; + case SH_NODE_TEX_WAVE: + ntype->draw_buttons = node_shader_buts_tex_wave; + break; + case SH_NODE_TEX_MUSGRAVE: + ntype->draw_buttons = node_shader_buts_tex_musgrave; + break; + case SH_NODE_TEX_VORONOI: + ntype->draw_buttons = node_shader_buts_tex_voronoi; + break; + case SH_NODE_TEX_POINTDENSITY: + ntype->draw_buttons = node_shader_buts_tex_pointdensity; + break; + case SH_NODE_TEX_COORD: + ntype->draw_buttons = node_shader_buts_tex_coord; + break; + case SH_NODE_BUMP: + ntype->draw_buttons = node_shader_buts_bump; + break; + case SH_NODE_NORMAL_MAP: + ntype->draw_buttons = node_shader_buts_normal_map; + break; + case SH_NODE_DISPLACEMENT: + case SH_NODE_VECTOR_DISPLACEMENT: + ntype->draw_buttons = node_shader_buts_displacement; + break; + case SH_NODE_TANGENT: + ntype->draw_buttons = node_shader_buts_tangent; + break; + case SH_NODE_BSDF_GLOSSY: + case SH_NODE_BSDF_GLASS: + case SH_NODE_BSDF_REFRACTION: + ntype->draw_buttons = node_shader_buts_glossy; + break; + case SH_NODE_BSDF_PRINCIPLED: + ntype->draw_buttons = node_shader_buts_principled; + break; + case SH_NODE_BSDF_ANISOTROPIC: + ntype->draw_buttons = node_shader_buts_anisotropic; + break; + case SH_NODE_SUBSURFACE_SCATTERING: + ntype->draw_buttons = node_shader_buts_subsurface; + break; + case SH_NODE_BSDF_TOON: + ntype->draw_buttons = node_shader_buts_toon; + break; + case SH_NODE_BSDF_HAIR: + ntype->draw_buttons = node_shader_buts_hair; + break; + case SH_NODE_BSDF_HAIR_PRINCIPLED: + ntype->draw_buttons = node_shader_buts_principled_hair; + break; + case SH_NODE_SCRIPT: + ntype->draw_buttons = node_shader_buts_script; + ntype->draw_buttons_ex = node_shader_buts_script_ex; + break; + case SH_NODE_UVMAP: + ntype->draw_buttons = node_shader_buts_uvmap; + break; + case SH_NODE_UVALONGSTROKE: + ntype->draw_buttons = node_shader_buts_uvalongstroke; + break; + case SH_NODE_OUTPUT_MATERIAL: + case SH_NODE_OUTPUT_LIGHT: + case SH_NODE_OUTPUT_WORLD: + ntype->draw_buttons = node_buts_output_shader; + break; + case SH_NODE_OUTPUT_LINESTYLE: + ntype->draw_buttons = node_buts_output_linestyle; + break; + case SH_NODE_TEX_IES: + ntype->draw_buttons = node_shader_buts_ies; + break; + case SH_NODE_BEVEL: + ntype->draw_buttons = node_shader_buts_bevel; + break; + case SH_NODE_AMBIENT_OCCLUSION: + ntype->draw_buttons = node_shader_buts_ambient_occlusion; + break; + } } /* ****************** BUTTON CALLBACKS FOR COMPOSITE NODES ***************** */ -static void node_buts_image_views(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr, - PointerRNA *imaptr) +static void node_buts_image_views(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr, + PointerRNA *imaptr) { - uiLayout *col; + uiLayout *col; - if (!imaptr->data) { - return; - } + if (!imaptr->data) { + return; + } - col = uiLayoutColumn(layout, false); + col = uiLayoutColumn(layout, false); - if (RNA_boolean_get(ptr, "has_views")) { - if (RNA_enum_get(ptr, "view") == 0) { - uiItemR(col, ptr, "view", 0, NULL, ICON_CAMERA_STEREO); - } - else { - uiItemR(col, ptr, "view", 0, NULL, ICON_SCENE); - } - } + if (RNA_boolean_get(ptr, "has_views")) { + if (RNA_enum_get(ptr, "view") == 0) { + uiItemR(col, ptr, "view", 0, NULL, ICON_CAMERA_STEREO); + } + else { + uiItemR(col, ptr, "view", 0, NULL, ICON_SCENE); + } + } } static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - PointerRNA imaptr, iuserptr; + bNode *node = ptr->data; + PointerRNA imaptr, iuserptr; - RNA_pointer_create((ID *)ptr->id.data, &RNA_ImageUser, node->storage, &iuserptr); - uiLayoutSetContextPointer(layout, "image_user", &iuserptr); - uiTemplateID( - layout, C, ptr, "image", - "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (!node->id) { - return; - } + RNA_pointer_create((ID *)ptr->id.data, &RNA_ImageUser, node->storage, &iuserptr); + uiLayoutSetContextPointer(layout, "image_user", &iuserptr); + uiTemplateID(layout, + C, + ptr, + "image", + "IMAGE_OT_new", + "IMAGE_OT_open", + NULL, + UI_TEMPLATE_ID_FILTER_ALL, + false); + if (!node->id) { + return; + } - imaptr = RNA_pointer_get(ptr, "image"); + imaptr = RNA_pointer_get(ptr, "image"); - node_buts_image_user(layout, C, ptr, &imaptr, &iuserptr, true); + node_buts_image_user(layout, C, ptr, &imaptr, &iuserptr, true); - node_buts_image_views(layout, C, ptr, &imaptr); + node_buts_image_views(layout, C, ptr, &imaptr); } static void node_composit_buts_image_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - PointerRNA iuserptr; + bNode *node = ptr->data; + PointerRNA iuserptr; - RNA_pointer_create((ID *)ptr->id.data, &RNA_ImageUser, node->storage, &iuserptr); - uiLayoutSetContextPointer(layout, "image_user", &iuserptr); - uiTemplateImage(layout, C, ptr, "image", &iuserptr, 0, 1); + RNA_pointer_create((ID *)ptr->id.data, &RNA_ImageUser, node->storage, &iuserptr); + uiLayoutSetContextPointer(layout, "image_user", &iuserptr); + uiTemplateImage(layout, C, ptr, "image", &iuserptr, 0, 1); } static void node_composit_buts_viewlayers(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - uiLayout *col, *row; - PointerRNA op_ptr; - PointerRNA scn_ptr; - PropertyRNA *prop; - const char *layer_name; - char scene_name[MAX_ID_NAME - 2]; + bNode *node = ptr->data; + uiLayout *col, *row; + PointerRNA op_ptr; + PointerRNA scn_ptr; + PropertyRNA *prop; + const char *layer_name; + char scene_name[MAX_ID_NAME - 2]; - uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (!node->id) { - return; - } + if (!node->id) { + return; + } - col = uiLayoutColumn(layout, false); - row = uiLayoutRow(col, true); - uiItemR(row, ptr, "layer", 0, "", ICON_NONE); + col = uiLayoutColumn(layout, false); + row = uiLayoutRow(col, true); + uiItemR(row, ptr, "layer", 0, "", ICON_NONE); - prop = RNA_struct_find_property(ptr, "layer"); - if (!(RNA_property_enum_identifier(C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name))) { - return; - } + prop = RNA_struct_find_property(ptr, "layer"); + if (!(RNA_property_enum_identifier( + C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name))) { + return; + } - scn_ptr = RNA_pointer_get(ptr, "scene"); - RNA_string_get(&scn_ptr, "name", scene_name); + scn_ptr = RNA_pointer_get(ptr, "scene"); + RNA_string_get(&scn_ptr, "name", scene_name); - uiItemFullO(row, "RENDER_OT_render", "", ICON_RENDER_STILL, NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); - RNA_string_set(&op_ptr, "layer", layer_name); - RNA_string_set(&op_ptr, "scene", scene_name); + uiItemFullO( + row, "RENDER_OT_render", "", ICON_RENDER_STILL, NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); + RNA_string_set(&op_ptr, "layer", layer_name); + RNA_string_set(&op_ptr, "scene", scene_name); } - static void node_composit_buts_blur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col, *row; - int reference; - int filter; - - col = uiLayoutColumn(layout, false); - filter = RNA_enum_get(ptr, "filter_type"); - reference = RNA_boolean_get(ptr, "use_variable_size"); - - uiItemR(col, ptr, "filter_type", 0, "", ICON_NONE); - if (filter != R_FILTER_FAST_GAUSS) { - uiItemR(col, ptr, "use_variable_size", 0, NULL, ICON_NONE); - if (!reference) { - uiItemR(col, ptr, "use_bokeh", 0, NULL, ICON_NONE); - } - uiItemR(col, ptr, "use_gamma_correction", 0, NULL, ICON_NONE); - } - - uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE); - - if (RNA_boolean_get(ptr, "use_relative")) { - uiItemL(col, IFACE_("Aspect Correction"), ICON_NONE); - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "factor_x", 0, IFACE_("X"), ICON_NONE); - uiItemR(col, ptr, "factor_y", 0, IFACE_("Y"), ICON_NONE); - } - else { - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "size_x", 0, IFACE_("X"), ICON_NONE); - uiItemR(col, ptr, "size_y", 0, IFACE_("Y"), ICON_NONE); - } - uiItemR(col, ptr, "use_extended_bounds", 0, NULL, ICON_NONE); + uiLayout *col, *row; + int reference; + int filter; + + col = uiLayoutColumn(layout, false); + filter = RNA_enum_get(ptr, "filter_type"); + reference = RNA_boolean_get(ptr, "use_variable_size"); + + uiItemR(col, ptr, "filter_type", 0, "", ICON_NONE); + if (filter != R_FILTER_FAST_GAUSS) { + uiItemR(col, ptr, "use_variable_size", 0, NULL, ICON_NONE); + if (!reference) { + uiItemR(col, ptr, "use_bokeh", 0, NULL, ICON_NONE); + } + uiItemR(col, ptr, "use_gamma_correction", 0, NULL, ICON_NONE); + } + + uiItemR(col, ptr, "use_relative", 0, NULL, ICON_NONE); + + if (RNA_boolean_get(ptr, "use_relative")) { + uiItemL(col, IFACE_("Aspect Correction"), ICON_NONE); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "aspect_correction", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "factor_x", 0, IFACE_("X"), ICON_NONE); + uiItemR(col, ptr, "factor_y", 0, IFACE_("Y"), ICON_NONE); + } + else { + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "size_x", 0, IFACE_("X"), ICON_NONE); + uiItemR(col, ptr, "size_y", 0, IFACE_("Y"), ICON_NONE); + } + uiItemR(col, ptr, "use_extended_bounds", 0, NULL, ICON_NONE); } static void node_composit_buts_dblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "use_wrap", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_wrap", 0, NULL, ICON_NONE); - col = uiLayoutColumn(layout, true); - uiItemL(col, IFACE_("Center:"), ICON_NONE); - uiItemR(col, ptr, "center_x", 0, IFACE_("X"), ICON_NONE); - uiItemR(col, ptr, "center_y", 0, IFACE_("Y"), ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemL(col, IFACE_("Center:"), ICON_NONE); + uiItemR(col, ptr, "center_x", 0, IFACE_("X"), ICON_NONE); + uiItemR(col, ptr, "center_y", 0, IFACE_("Y"), ICON_NONE); - uiItemS(layout); + uiItemS(layout); - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "distance", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "distance", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE); - uiItemS(layout); + uiItemS(layout); - uiItemR(layout, ptr, "spin", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "zoom", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "spin", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "zoom", 0, NULL, ICON_NONE); } -static void node_composit_buts_bilateralblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void node_composit_buts_bilateralblur(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "sigma_color", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "sigma_space", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "sigma_color", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "sigma_space", 0, NULL, ICON_NONE); } static void node_composit_buts_defocus(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiLayout *sub, *col; + uiLayout *sub, *col; - col = uiLayoutColumn(layout, false); - uiItemL(col, IFACE_("Bokeh Type:"), ICON_NONE); - uiItemR(col, ptr, "bokeh", 0, "", ICON_NONE); - uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemL(col, IFACE_("Bokeh Type:"), ICON_NONE); + uiItemR(col, ptr, "bokeh", 0, "", ICON_NONE); + uiItemR(col, ptr, "angle", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "use_gamma_correction", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_gamma_correction", 0, NULL, ICON_NONE); - col = uiLayoutColumn(layout, false); - uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_zbuffer") == true); - uiItemR(col, ptr, "f_stop", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_zbuffer") == true); + uiItemR(col, ptr, "f_stop", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE); - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "use_preview", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "use_preview", 0, NULL, ICON_NONE); - uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "use_zbuffer", 0, NULL, ICON_NONE); - sub = uiLayoutColumn(col, false); - uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_zbuffer") == false); - uiItemR(sub, ptr, "z_scale", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "use_zbuffer", 0, NULL, ICON_NONE); + sub = uiLayoutColumn(col, false); + uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_zbuffer") == false); + uiItemR(sub, ptr, "z_scale", 0, NULL, ICON_NONE); } /* qdn: glare node */ static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "glare_type", 0, "", ICON_NONE); - uiItemR(layout, ptr, "quality", 0, "", ICON_NONE); + uiItemR(layout, ptr, "glare_type", 0, "", ICON_NONE); + uiItemR(layout, ptr, "quality", 0, "", ICON_NONE); - if (RNA_enum_get(ptr, "glare_type") != 1) { - uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE); + if (RNA_enum_get(ptr, "glare_type") != 1) { + uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "glare_type") != 0) { - uiItemR(layout, ptr, "color_modulation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - } - } + if (RNA_enum_get(ptr, "glare_type") != 0) { + uiItemR(layout, ptr, "color_modulation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + } + } - uiItemR(layout, ptr, "mix", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "mix", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "glare_type") == 2) { - uiItemR(layout, ptr, "streaks", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "angle_offset", 0, NULL, ICON_NONE); - } - if (RNA_enum_get(ptr, "glare_type") == 0 || RNA_enum_get(ptr, "glare_type") == 2) { - uiItemR(layout, ptr, "fade", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + if (RNA_enum_get(ptr, "glare_type") == 2) { + uiItemR(layout, ptr, "streaks", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "angle_offset", 0, NULL, ICON_NONE); + } + if (RNA_enum_get(ptr, "glare_type") == 0 || RNA_enum_get(ptr, "glare_type") == 2) { + uiItemR(layout, ptr, "fade", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "glare_type") == 0) { - uiItemR(layout, ptr, "use_rotate_45", 0, NULL, ICON_NONE); - } - } - if (RNA_enum_get(ptr, "glare_type") == 1) { - uiItemR(layout, ptr, "size", 0, NULL, ICON_NONE); - } + if (RNA_enum_get(ptr, "glare_type") == 0) { + uiItemR(layout, ptr, "use_rotate_45", 0, NULL, ICON_NONE); + } + } + if (RNA_enum_get(ptr, "glare_type") == 1) { + uiItemR(layout, ptr, "size", 0, NULL, ICON_NONE); + } } static void node_composit_buts_tonemap(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "tonemap_type", 0, "", ICON_NONE); - if (RNA_enum_get(ptr, "tonemap_type") == 0) { - uiItemR(col, ptr, "key", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "gamma", 0, NULL, ICON_NONE); - } - else { - uiItemR(col, ptr, "intensity", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "adaptation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "correction", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - } + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "tonemap_type", 0, "", ICON_NONE); + if (RNA_enum_get(ptr, "tonemap_type") == 0) { + uiItemR(col, ptr, "key", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "gamma", 0, NULL, ICON_NONE); + } + else { + uiItemR(col, ptr, "intensity", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "adaptation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "correction", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + } } static void node_composit_buts_lensdist(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "use_projector", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "use_projector", 0, NULL, ICON_NONE); - col = uiLayoutColumn(col, false); - uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_projector") == false); - uiItemR(col, ptr, "use_jitter", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "use_fit", 0, NULL, ICON_NONE); + col = uiLayoutColumn(col, false); + uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_projector") == false); + uiItemR(col, ptr, "use_jitter", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "use_fit", 0, NULL, ICON_NONE); } static void node_composit_buts_vecblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "samples", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "factor", 0, IFACE_("Blur"), ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "samples", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "factor", 0, IFACE_("Blur"), ICON_NONE); - col = uiLayoutColumn(layout, true); - uiItemL(col, IFACE_("Speed:"), ICON_NONE); - uiItemR(col, ptr, "speed_min", 0, IFACE_("Min"), ICON_NONE); - uiItemR(col, ptr, "speed_max", 0, IFACE_("Max"), ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemL(col, IFACE_("Speed:"), ICON_NONE); + uiItemR(col, ptr, "speed_min", 0, IFACE_("Min"), ICON_NONE); + uiItemR(col, ptr, "speed_max", 0, IFACE_("Max"), ICON_NONE); - uiItemR(layout, ptr, "use_curved", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_curved", 0, NULL, ICON_NONE); } static void node_composit_buts_filter(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); + uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); } static void node_composit_buts_flip(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "axis", 0, "", ICON_NONE); + uiItemR(layout, ptr, "axis", 0, "", ICON_NONE); } static void node_composit_buts_crop(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - uiItemR(layout, ptr, "use_crop_size", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "relative", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_crop_size", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "relative", 0, NULL, ICON_NONE); - col = uiLayoutColumn(layout, true); - if (RNA_boolean_get(ptr, "relative")) { - uiItemR(col, ptr, "rel_min_x", 0, IFACE_("Left"), ICON_NONE); - uiItemR(col, ptr, "rel_max_x", 0, IFACE_("Right"), ICON_NONE); - uiItemR(col, ptr, "rel_min_y", 0, IFACE_("Up"), ICON_NONE); - uiItemR(col, ptr, "rel_max_y", 0, IFACE_("Down"), ICON_NONE); - } - else { - uiItemR(col, ptr, "min_x", 0, IFACE_("Left"), ICON_NONE); - uiItemR(col, ptr, "max_x", 0, IFACE_("Right"), ICON_NONE); - uiItemR(col, ptr, "min_y", 0, IFACE_("Up"), ICON_NONE); - uiItemR(col, ptr, "max_y", 0, IFACE_("Down"), ICON_NONE); - } + col = uiLayoutColumn(layout, true); + if (RNA_boolean_get(ptr, "relative")) { + uiItemR(col, ptr, "rel_min_x", 0, IFACE_("Left"), ICON_NONE); + uiItemR(col, ptr, "rel_max_x", 0, IFACE_("Right"), ICON_NONE); + uiItemR(col, ptr, "rel_min_y", 0, IFACE_("Up"), ICON_NONE); + uiItemR(col, ptr, "rel_max_y", 0, IFACE_("Down"), ICON_NONE); + } + else { + uiItemR(col, ptr, "min_x", 0, IFACE_("Left"), ICON_NONE); + uiItemR(col, ptr, "max_x", 0, IFACE_("Right"), ICON_NONE); + uiItemR(col, ptr, "min_y", 0, IFACE_("Up"), ICON_NONE); + uiItemR(col, ptr, "max_y", 0, IFACE_("Down"), ICON_NONE); + } } static void node_composit_buts_splitviewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row, *col; + uiLayout *row, *col; - col = uiLayoutColumn(layout, false); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE); } -static void node_composit_buts_double_edge_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void node_composit_buts_double_edge_mask(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, false); + col = uiLayoutColumn(layout, false); - uiItemL(col, IFACE_("Inner Edge:"), ICON_NONE); - uiItemR(col, ptr, "inner_mode", 0, "", ICON_NONE); - uiItemL(col, IFACE_("Buffer Edge:"), ICON_NONE); - uiItemR(col, ptr, "edge_mode", 0, "", ICON_NONE); + uiItemL(col, IFACE_("Inner Edge:"), ICON_NONE); + uiItemR(col, ptr, "inner_mode", 0, "", ICON_NONE); + uiItemL(col, IFACE_("Buffer Edge:"), ICON_NONE); + uiItemR(col, ptr, "edge_mode", 0, "", ICON_NONE); } static void node_composit_buts_map_range(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "use_clamp", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "use_clamp", 0, NULL, ICON_NONE); } static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *sub, *col; + uiLayout *sub, *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "size", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "offset", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "size", 0, NULL, ICON_NONE); - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "use_min", 0, NULL, ICON_NONE); - sub = uiLayoutColumn(col, false); - uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min")); - uiItemR(sub, ptr, "min", 0, "", ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "use_min", 0, NULL, ICON_NONE); + sub = uiLayoutColumn(col, false); + uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_min")); + uiItemR(sub, ptr, "min", 0, "", ICON_NONE); - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "use_max", 0, NULL, ICON_NONE); - sub = uiLayoutColumn(col, false); - uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max")); - uiItemR(sub, ptr, "max", 0, "", ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "use_max", 0, NULL, ICON_NONE); + sub = uiLayoutColumn(col, false); + uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_max")); + uiItemR(sub, ptr, "max", 0, "", ICON_NONE); } static void node_composit_buts_alphaover(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "use_premultiply", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "premul", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "use_premultiply", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "premul", 0, NULL, ICON_NONE); } static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "use_alpha", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "use_antialias_z", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "use_alpha", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "use_antialias_z", 0, NULL, ICON_NONE); } static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE); - switch (RNA_enum_get(ptr, "mode")) { - case CMP_NODE_DILATEERODE_DISTANCE_THRESH: - uiItemR(layout, ptr, "edge", 0, NULL, ICON_NONE); - break; - case CMP_NODE_DILATEERODE_DISTANCE_FEATHER: - uiItemR(layout, ptr, "falloff", 0, NULL, ICON_NONE); - break; - } + uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE); + switch (RNA_enum_get(ptr, "mode")) { + case CMP_NODE_DILATEERODE_DISTANCE_THRESH: + uiItemR(layout, ptr, "edge", 0, NULL, ICON_NONE); + break; + case CMP_NODE_DILATEERODE_DISTANCE_FEATHER: + uiItemR(layout, ptr, "falloff", 0, NULL, ICON_NONE); + break; + } } static void node_composit_buts_inpaint(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE); } static void node_composit_buts_despeckle(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "threshold_neighbor", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "threshold_neighbor", 0, NULL, ICON_NONE); } static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE); } -static void node_composit_buts_distance_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void node_composit_buts_distance_matte(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { - uiLayout *col, *row; + uiLayout *col, *row; - col = uiLayoutColumn(layout, true); + col = uiLayoutColumn(layout, true); - uiItemL(layout, IFACE_("Color Space:"), ICON_NONE); - row = uiLayoutRow(layout, false); - uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemL(layout, IFACE_("Color Space:"), ICON_NONE); + row = uiLayoutRow(layout, false); + uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "tolerance", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "falloff", UI_ITEM_R_SLIDER, NULL, ICON_NONE); } static void node_composit_buts_color_spill(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row, *col; + uiLayout *row, *col; - uiItemL(layout, IFACE_("Despill Channel:"), ICON_NONE); - row = uiLayoutRow(layout, false); - uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemL(layout, IFACE_("Despill Channel:"), ICON_NONE); + row = uiLayoutRow(layout, false); + uiItemR(row, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "limit_method") == 0) { - uiItemL(col, IFACE_("Limiting Channel:"), ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - } + if (RNA_enum_get(ptr, "limit_method") == 0) { + uiItemL(col, IFACE_("Limiting Channel:"), ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + } - uiItemR(col, ptr, "ratio", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "use_unspill", 0, NULL, ICON_NONE); - if (RNA_boolean_get(ptr, "use_unspill") == true) { - uiItemR(col, ptr, "unspill_red", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "unspill_green", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "unspill_blue", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - } + uiItemR(col, ptr, "ratio", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "use_unspill", 0, NULL, ICON_NONE); + if (RNA_boolean_get(ptr, "use_unspill") == true) { + uiItemR(col, ptr, "unspill_red", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "unspill_green", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "unspill_blue", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + } } static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "tolerance", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "tolerance", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "threshold", 0, NULL, ICON_NONE); - col = uiLayoutColumn(layout, true); - /*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); Removed for now */ - uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - /*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, ICON_NONE); Removed for now*/ + col = uiLayoutColumn(layout, true); + /*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); Removed for now */ + uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + /*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, ICON_NONE); Removed for now*/ } static void node_composit_buts_color_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE); } -static void node_composit_buts_channel_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void node_composit_buts_channel_matte(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { - uiLayout *col, *row; + uiLayout *col, *row; - uiItemL(layout, IFACE_("Color Space:"), ICON_NONE); - row = uiLayoutRow(layout, false); - uiItemR(row, ptr, "color_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemL(layout, IFACE_("Color Space:"), ICON_NONE); + row = uiLayoutRow(layout, false); + uiItemR(row, ptr, "color_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - col = uiLayoutColumn(layout, false); - uiItemL(col, IFACE_("Key Channel:"), ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "matte_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemL(col, IFACE_("Key Channel:"), ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "matte_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - col = uiLayoutColumn(layout, false); + col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "limit_method") == 0) { - uiItemL(col, IFACE_("Limiting Channel:"), ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - } + uiItemR(col, ptr, "limit_method", 0, NULL, ICON_NONE); + if (RNA_enum_get(ptr, "limit_method") == 0) { + uiItemL(col, IFACE_("Limiting Channel:"), ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "limit_channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + } - uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE); } static void node_composit_buts_luma_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "limit_max", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(col, ptr, "limit_min", UI_ITEM_R_SLIDER, NULL, ICON_NONE); } static void node_composit_buts_map_uv(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "alpha", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "alpha", 0, NULL, ICON_NONE); } static void node_composit_buts_id_mask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "index", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "use_antialiasing", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "index", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_antialiasing", 0, NULL, ICON_NONE); } static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - PointerRNA imfptr = RNA_pointer_get(ptr, "format"); - const bool multilayer = RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER; + PointerRNA imfptr = RNA_pointer_get(ptr, "format"); + const bool multilayer = RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER; - if (multilayer) { - uiItemL(layout, IFACE_("Path:"), ICON_NONE); - } - else { - uiItemL(layout, IFACE_("Base Path:"), ICON_NONE); - } - uiItemR(layout, ptr, "base_path", 0, "", ICON_NONE); + if (multilayer) { + uiItemL(layout, IFACE_("Path:"), ICON_NONE); + } + else { + uiItemL(layout, IFACE_("Base Path:"), ICON_NONE); + } + uiItemR(layout, ptr, "base_path", 0, "", ICON_NONE); } static void node_composit_buts_file_output_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) { - Scene *scene = CTX_data_scene(C); - PointerRNA imfptr = RNA_pointer_get(ptr, "format"); - PointerRNA active_input_ptr, op_ptr; - wmOperatorType *ot; - uiLayout *row, *col; - int active_index; - const bool multilayer = RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER; - const bool is_multiview = (scene->r.scemode & R_MULTIVIEW) != 0; - - node_composit_buts_file_output(layout, C, ptr); - uiTemplateImageSettings(layout, &imfptr, false); - - /* disable stereo output for multilayer, too much work for something that no one will use */ - /* if someone asks for that we can implement it */ - if (is_multiview) { - uiTemplateImageFormatViews(layout, &imfptr, NULL); - } - - uiItemS(layout); - - uiItemO(layout, IFACE_("Add Input"), ICON_ADD, "NODE_OT_output_file_add_socket"); - - row = uiLayoutRow(layout, false); - col = uiLayoutColumn(row, true); - - active_index = RNA_int_get(ptr, "active_input_index"); - /* using different collection properties if multilayer format is enabled */ - if (multilayer) { - uiTemplateList(col, C, "UI_UL_list", "file_output_node", ptr, "layer_slots", ptr, "active_input_index", - NULL, 0, 0, 0, 0, false, false); - RNA_property_collection_lookup_int(ptr, RNA_struct_find_property(ptr, "layer_slots"), - active_index, &active_input_ptr); - } - else { - uiTemplateList(col, C, "UI_UL_list", "file_output_node", ptr, "file_slots", ptr, "active_input_index", - NULL, 0, 0, 0, 0, false, false); - RNA_property_collection_lookup_int(ptr, RNA_struct_find_property(ptr, "file_slots"), - active_index, &active_input_ptr); - } - /* XXX collection lookup does not return the ID part of the pointer, - * setting this manually here */ - active_input_ptr.id.data = ptr->id.data; - - col = uiLayoutColumn(row, true); - ot = WM_operatortype_find("NODE_OT_output_file_move_active_socket", false); - uiItemFullO_ptr(col, ot, "", ICON_TRIA_UP, NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); - RNA_enum_set(&op_ptr, "direction", 1); - uiItemFullO_ptr(col, ot, "", ICON_TRIA_DOWN, NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); - RNA_enum_set(&op_ptr, "direction", 2); - - if (active_input_ptr.data) { - if (multilayer) { - col = uiLayoutColumn(layout, true); - - uiItemL(col, IFACE_("Layer:"), ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &active_input_ptr, "name", 0, "", ICON_NONE); - uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "", - ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY, NULL); - } - else { - col = uiLayoutColumn(layout, true); - - uiItemL(col, IFACE_("File Subpath:"), ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &active_input_ptr, "path", 0, "", ICON_NONE); - uiItemFullO(row, "NODE_OT_output_file_remove_active_socket", "", - ICON_X, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_R_ICON_ONLY, NULL); - - /* format details for individual files */ - imfptr = RNA_pointer_get(&active_input_ptr, "format"); - - col = uiLayoutColumn(layout, true); - uiItemL(col, IFACE_("Format:"), ICON_NONE); - uiItemR(col, &active_input_ptr, "use_node_format", 0, NULL, ICON_NONE); - - col = uiLayoutColumn(layout, false); - uiLayoutSetActive(col, RNA_boolean_get(&active_input_ptr, "use_node_format") == false); - uiTemplateImageSettings(col, &imfptr, false); - - if (is_multiview) { - uiTemplateImageFormatViews(layout, &imfptr, NULL); - } - } - } + Scene *scene = CTX_data_scene(C); + PointerRNA imfptr = RNA_pointer_get(ptr, "format"); + PointerRNA active_input_ptr, op_ptr; + wmOperatorType *ot; + uiLayout *row, *col; + int active_index; + const bool multilayer = RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER; + const bool is_multiview = (scene->r.scemode & R_MULTIVIEW) != 0; + + node_composit_buts_file_output(layout, C, ptr); + uiTemplateImageSettings(layout, &imfptr, false); + + /* disable stereo output for multilayer, too much work for something that no one will use */ + /* if someone asks for that we can implement it */ + if (is_multiview) { + uiTemplateImageFormatViews(layout, &imfptr, NULL); + } + + uiItemS(layout); + + uiItemO(layout, IFACE_("Add Input"), ICON_ADD, "NODE_OT_output_file_add_socket"); + + row = uiLayoutRow(layout, false); + col = uiLayoutColumn(row, true); + + active_index = RNA_int_get(ptr, "active_input_index"); + /* using different collection properties if multilayer format is enabled */ + if (multilayer) { + uiTemplateList(col, + C, + "UI_UL_list", + "file_output_node", + ptr, + "layer_slots", + ptr, + "active_input_index", + NULL, + 0, + 0, + 0, + 0, + false, + false); + RNA_property_collection_lookup_int( + ptr, RNA_struct_find_property(ptr, "layer_slots"), active_index, &active_input_ptr); + } + else { + uiTemplateList(col, + C, + "UI_UL_list", + "file_output_node", + ptr, + "file_slots", + ptr, + "active_input_index", + NULL, + 0, + 0, + 0, + 0, + false, + false); + RNA_property_collection_lookup_int( + ptr, RNA_struct_find_property(ptr, "file_slots"), active_index, &active_input_ptr); + } + /* XXX collection lookup does not return the ID part of the pointer, + * setting this manually here */ + active_input_ptr.id.data = ptr->id.data; + + col = uiLayoutColumn(row, true); + ot = WM_operatortype_find("NODE_OT_output_file_move_active_socket", false); + uiItemFullO_ptr(col, ot, "", ICON_TRIA_UP, NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); + RNA_enum_set(&op_ptr, "direction", 1); + uiItemFullO_ptr(col, ot, "", ICON_TRIA_DOWN, NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr); + RNA_enum_set(&op_ptr, "direction", 2); + + if (active_input_ptr.data) { + if (multilayer) { + col = uiLayoutColumn(layout, true); + + uiItemL(col, IFACE_("Layer:"), ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &active_input_ptr, "name", 0, "", ICON_NONE); + uiItemFullO(row, + "NODE_OT_output_file_remove_active_socket", + "", + ICON_X, + NULL, + WM_OP_EXEC_DEFAULT, + UI_ITEM_R_ICON_ONLY, + NULL); + } + else { + col = uiLayoutColumn(layout, true); + + uiItemL(col, IFACE_("File Subpath:"), ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &active_input_ptr, "path", 0, "", ICON_NONE); + uiItemFullO(row, + "NODE_OT_output_file_remove_active_socket", + "", + ICON_X, + NULL, + WM_OP_EXEC_DEFAULT, + UI_ITEM_R_ICON_ONLY, + NULL); + + /* format details for individual files */ + imfptr = RNA_pointer_get(&active_input_ptr, "format"); + + col = uiLayoutColumn(layout, true); + uiItemL(col, IFACE_("Format:"), ICON_NONE); + uiItemR(col, &active_input_ptr, "use_node_format", 0, NULL, ICON_NONE); + + col = uiLayoutColumn(layout, false); + uiLayoutSetActive(col, RNA_boolean_get(&active_input_ptr, "use_node_format") == false); + uiTemplateImageSettings(col, &imfptr, false); + + if (is_multiview) { + uiTemplateImageFormatViews(layout, &imfptr, NULL); + } + } + } } static void node_composit_buts_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "space", 0, "", ICON_NONE); + uiItemR(layout, ptr, "space", 0, "", ICON_NONE); - if (RNA_enum_get(ptr, "space") == CMP_SCALE_RENDERPERCENT) { - uiLayout *row; - uiItemR(layout, ptr, "frame_method", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "offset_x", 0, "X", ICON_NONE); - uiItemR(row, ptr, "offset_y", 0, "Y", ICON_NONE); - } + if (RNA_enum_get(ptr, "space") == CMP_SCALE_RENDERPERCENT) { + uiLayout *row; + uiItemR(layout, ptr, "frame_method", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "offset_x", 0, "X", ICON_NONE); + uiItemR(row, ptr, "offset_y", 0, "Y", ICON_NONE); + } } static void node_composit_buts_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); + uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); } static void node_composit_buts_invert(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "invert_rgb", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "invert_alpha", 0, NULL, ICON_NONE); + col = uiLayoutColumn(layout, false); + uiItemR(col, ptr, "invert_rgb", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "invert_alpha", 0, NULL, ICON_NONE); } static void node_composit_buts_premulkey(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE); + uiItemR(layout, ptr, "mapping", 0, "", ICON_NONE); } static void node_composit_buts_view_levels(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemR(layout, ptr, "channel", UI_ITEM_R_EXPAND, NULL, ICON_NONE); } static void node_composit_buts_colorbalance(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *split, *col, *row; + uiLayout *split, *col, *row; - uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "correction_method") == 0) { + if (RNA_enum_get(ptr, "correction_method") == 0) { - split = uiLayoutSplit(layout, 0.0f, false); - col = uiLayoutColumn(split, false); - uiTemplateColorPicker(col, ptr, "lift", 1, 1, 0, 1); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "lift", 0, NULL, ICON_NONE); + split = uiLayoutSplit(layout, 0.0f, false); + col = uiLayoutColumn(split, false); + uiTemplateColorPicker(col, ptr, "lift", 1, 1, 0, 1); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "lift", 0, NULL, ICON_NONE); - col = uiLayoutColumn(split, false); - uiTemplateColorPicker(col, ptr, "gamma", 1, 1, 1, 1); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "gamma", 0, NULL, ICON_NONE); + col = uiLayoutColumn(split, false); + uiTemplateColorPicker(col, ptr, "gamma", 1, 1, 1, 1); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "gamma", 0, NULL, ICON_NONE); - col = uiLayoutColumn(split, false); - uiTemplateColorPicker(col, ptr, "gain", 1, 1, 1, 1); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "gain", 0, NULL, ICON_NONE); + col = uiLayoutColumn(split, false); + uiTemplateColorPicker(col, ptr, "gain", 1, 1, 1, 1); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "gain", 0, NULL, ICON_NONE); + } + else { - } - else { + split = uiLayoutSplit(layout, 0.0f, false); + col = uiLayoutColumn(split, false); + uiTemplateColorPicker(col, ptr, "offset", 1, 1, 0, 1); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "offset", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "offset_basis", 0, NULL, ICON_NONE); - split = uiLayoutSplit(layout, 0.0f, false); - col = uiLayoutColumn(split, false); - uiTemplateColorPicker(col, ptr, "offset", 1, 1, 0, 1); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "offset", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "offset_basis", 0, NULL, ICON_NONE); - - col = uiLayoutColumn(split, false); - uiTemplateColorPicker(col, ptr, "power", 1, 1, 0, 1); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "power", 0, NULL, ICON_NONE); - - col = uiLayoutColumn(split, false); - uiTemplateColorPicker(col, ptr, "slope", 1, 1, 0, 1); - row = uiLayoutRow(col, false); - uiItemR(row, ptr, "slope", 0, NULL, ICON_NONE); - } + col = uiLayoutColumn(split, false); + uiTemplateColorPicker(col, ptr, "power", 1, 1, 0, 1); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "power", 0, NULL, ICON_NONE); + col = uiLayoutColumn(split, false); + uiTemplateColorPicker(col, ptr, "slope", 1, 1, 0, 1); + row = uiLayoutRow(col, false); + uiItemR(row, ptr, "slope", 0, NULL, ICON_NONE); + } } -static void node_composit_buts_colorbalance_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void node_composit_buts_colorbalance_ex(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { - uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "correction_method", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "correction_method") == 0) { + if (RNA_enum_get(ptr, "correction_method") == 0) { - uiTemplateColorPicker(layout, ptr, "lift", 1, 1, 0, 1); - uiItemR(layout, ptr, "lift", 0, NULL, ICON_NONE); + uiTemplateColorPicker(layout, ptr, "lift", 1, 1, 0, 1); + uiItemR(layout, ptr, "lift", 0, NULL, ICON_NONE); - uiTemplateColorPicker(layout, ptr, "gamma", 1, 1, 1, 1); - uiItemR(layout, ptr, "gamma", 0, NULL, ICON_NONE); + uiTemplateColorPicker(layout, ptr, "gamma", 1, 1, 1, 1); + uiItemR(layout, ptr, "gamma", 0, NULL, ICON_NONE); - uiTemplateColorPicker(layout, ptr, "gain", 1, 1, 1, 1); - uiItemR(layout, ptr, "gain", 0, NULL, ICON_NONE); - } - else { - uiTemplateColorPicker(layout, ptr, "offset", 1, 1, 0, 1); - uiItemR(layout, ptr, "offset", 0, NULL, ICON_NONE); + uiTemplateColorPicker(layout, ptr, "gain", 1, 1, 1, 1); + uiItemR(layout, ptr, "gain", 0, NULL, ICON_NONE); + } + else { + uiTemplateColorPicker(layout, ptr, "offset", 1, 1, 0, 1); + uiItemR(layout, ptr, "offset", 0, NULL, ICON_NONE); - uiTemplateColorPicker(layout, ptr, "power", 1, 1, 0, 1); - uiItemR(layout, ptr, "power", 0, NULL, ICON_NONE); + uiTemplateColorPicker(layout, ptr, "power", 1, 1, 0, 1); + uiItemR(layout, ptr, "power", 0, NULL, ICON_NONE); - uiTemplateColorPicker(layout, ptr, "slope", 1, 1, 0, 1); - uiItemR(layout, ptr, "slope", 0, NULL, ICON_NONE); - } + uiTemplateColorPicker(layout, ptr, "slope", 1, 1, 0, 1); + uiItemR(layout, ptr, "slope", 0, NULL, ICON_NONE); + } } - static void node_composit_buts_huecorrect(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - bNode *node = ptr->data; - CurveMapping *cumap = node->storage; + bNode *node = ptr->data; + CurveMapping *cumap = node->storage; - if (_sample_col[0] != SAMPLE_FLT_ISNONE) { - cumap->flag |= CUMA_DRAW_SAMPLE; - copy_v3_v3(cumap->sample, _sample_col); - } - else { - cumap->flag &= ~CUMA_DRAW_SAMPLE; - } + if (_sample_col[0] != SAMPLE_FLT_ISNONE) { + cumap->flag |= CUMA_DRAW_SAMPLE; + copy_v3_v3(cumap->sample, _sample_col); + } + else { + cumap->flag &= ~CUMA_DRAW_SAMPLE; + } - uiTemplateCurveMapping(layout, ptr, "mapping", 'h', false, false, false, false); + uiTemplateCurveMapping(layout, ptr, "mapping", 'h', false, false, false, false); } static void node_composit_buts_ycc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "mode", 0, "", ICON_NONE); + uiItemR(layout, ptr, "mode", 0, "", ICON_NONE); } static void node_composit_buts_movieclip(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID( + layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); } static void node_composit_buts_movieclip_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - PointerRNA clipptr; + bNode *node = ptr->data; + PointerRNA clipptr; - uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID( + layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (!node->id) { - return; - } + if (!node->id) { + return; + } - clipptr = RNA_pointer_get(ptr, "clip"); + clipptr = RNA_pointer_get(ptr, "clip"); - uiTemplateColorspaceSettings(layout, &clipptr, "colorspace_settings"); + uiTemplateColorspaceSettings(layout, &clipptr, "colorspace_settings"); } static void node_composit_buts_stabilize2d(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; + bNode *node = ptr->data; - uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID( + layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (!node->id) { - return; - } + if (!node->id) { + return; + } - uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); - uiItemR(layout, ptr, "invert", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); + uiItemR(layout, ptr, "invert", 0, NULL, ICON_NONE); } static void node_composit_buts_translate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "use_relative", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "wrap_axis", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_relative", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "wrap_axis", 0, NULL, ICON_NONE); } static void node_composit_buts_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); + uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); } static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - - uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - - if (!node->id) { - return; - } - - uiItemR(layout, ptr, "distortion_type", 0, "", ICON_NONE); -} - -static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) -{ - uiLayout *row; - - row = uiLayoutRow(layout, false); - uiItemR(row, ptr, "red", 0, NULL, ICON_NONE); - uiItemR(row, ptr, "green", 0, NULL, ICON_NONE); - uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE); - - row = uiLayoutRow(layout, false); - uiItemL(row, "", ICON_NONE); - uiItemL(row, IFACE_("Saturation"), ICON_NONE); - uiItemL(row, IFACE_("Contrast"), ICON_NONE); - uiItemL(row, IFACE_("Gamma"), ICON_NONE); - uiItemL(row, IFACE_("Gain"), ICON_NONE); - uiItemL(row, IFACE_("Lift"), ICON_NONE); - - row = uiLayoutRow(layout, false); - uiItemL(row, IFACE_("Master"), ICON_NONE); - uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); - - row = uiLayoutRow(layout, false); - uiItemL(row, IFACE_("Highlights"), ICON_NONE); - uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); - - row = uiLayoutRow(layout, false); - uiItemL(row, IFACE_("Midtones"), ICON_NONE); - uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); - - row = uiLayoutRow(layout, false); - uiItemL(row, IFACE_("Shadows"), ICON_NONE); - uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, "", ICON_NONE); - uiItemR(row, ptr, "shadows_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); - - row = uiLayoutRow(layout, false); - uiItemR(row, ptr, "midtones_start", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "midtones_end", UI_ITEM_R_SLIDER, NULL, ICON_NONE); -} - -static void node_composit_buts_colorcorrection_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) -{ - uiLayout *row; - - row = uiLayoutRow(layout, false); - uiItemR(row, ptr, "red", 0, NULL, ICON_NONE); - uiItemR(row, ptr, "green", 0, NULL, ICON_NONE); - uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE); - row = layout; - uiItemL(row, IFACE_("Saturation"), ICON_NONE); - uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - - uiItemL(row, IFACE_("Contrast"), ICON_NONE); - uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - - uiItemL(row, IFACE_("Gamma"), ICON_NONE); - uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - - uiItemL(row, IFACE_("Gain"), ICON_NONE); - uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - - uiItemL(row, IFACE_("Lift"), ICON_NONE); - uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "shadows_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - - row = uiLayoutRow(layout, false); - uiItemR(row, ptr, "midtones_start", 0, NULL, ICON_NONE); - uiItemR(row, ptr, "midtones_end", 0, NULL, ICON_NONE); + bNode *node = ptr->data; + + uiTemplateID( + layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + + if (!node->id) { + return; + } + + uiItemR(layout, ptr, "distortion_type", 0, "", ICON_NONE); +} + +static void node_composit_buts_colorcorrection(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) +{ + uiLayout *row; + + row = uiLayoutRow(layout, false); + uiItemR(row, ptr, "red", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "green", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE); + + row = uiLayoutRow(layout, false); + uiItemL(row, "", ICON_NONE); + uiItemL(row, IFACE_("Saturation"), ICON_NONE); + uiItemL(row, IFACE_("Contrast"), ICON_NONE); + uiItemL(row, IFACE_("Gamma"), ICON_NONE); + uiItemL(row, IFACE_("Gain"), ICON_NONE); + uiItemL(row, IFACE_("Lift"), ICON_NONE); + + row = uiLayoutRow(layout, false); + uiItemL(row, IFACE_("Master"), ICON_NONE); + uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); + + row = uiLayoutRow(layout, false); + uiItemL(row, IFACE_("Highlights"), ICON_NONE); + uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); + + row = uiLayoutRow(layout, false); + uiItemL(row, IFACE_("Midtones"), ICON_NONE); + uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); + + row = uiLayoutRow(layout, false); + uiItemL(row, IFACE_("Shadows"), ICON_NONE); + uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, "", ICON_NONE); + uiItemR(row, ptr, "shadows_lift", UI_ITEM_R_SLIDER, "", ICON_NONE); + + row = uiLayoutRow(layout, false); + uiItemR(row, ptr, "midtones_start", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "midtones_end", UI_ITEM_R_SLIDER, NULL, ICON_NONE); +} + +static void node_composit_buts_colorcorrection_ex(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) +{ + uiLayout *row; + + row = uiLayoutRow(layout, false); + uiItemR(row, ptr, "red", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "green", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "blue", 0, NULL, ICON_NONE); + row = layout; + uiItemL(row, IFACE_("Saturation"), ICON_NONE); + uiItemR(row, ptr, "master_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "highlights_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "midtones_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "shadows_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + + uiItemL(row, IFACE_("Contrast"), ICON_NONE); + uiItemR(row, ptr, "master_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "highlights_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "midtones_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "shadows_contrast", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + + uiItemL(row, IFACE_("Gamma"), ICON_NONE); + uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "highlights_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "midtones_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + + uiItemL(row, IFACE_("Gain"), ICON_NONE); + uiItemR(row, ptr, "master_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "highlights_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + + uiItemL(row, IFACE_("Lift"), ICON_NONE); + uiItemR(row, ptr, "master_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "highlights_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "shadows_lift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + + row = uiLayoutRow(layout, false); + uiItemR(row, ptr, "midtones_start", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "midtones_end", 0, NULL, ICON_NONE); } static void node_composit_buts_switch(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "check", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "check", 0, NULL, ICON_NONE); } -static void node_composit_buts_switch_view_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *UNUSED(ptr)) +static void node_composit_buts_switch_view_ex(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *UNUSED(ptr)) { - uiItemFullO( - layout, "NODE_OT_switch_view_update", - "Update Views", ICON_FILE_REFRESH, NULL, WM_OP_INVOKE_DEFAULT, 0, NULL); + uiItemFullO(layout, + "NODE_OT_switch_view_update", + "Update Views", + ICON_FILE_REFRESH, + NULL, + WM_OP_INVOKE_DEFAULT, + 0, + NULL); } static void node_composit_buts_boxmask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row; + uiLayout *row; - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "x", 0, NULL, ICON_NONE); - uiItemR(row, ptr, "y", 0, NULL, ICON_NONE); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "x", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "y", 0, NULL, ICON_NONE); - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "width", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "height", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "width", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "height", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE); } static void node_composit_buts_bokehimage(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "flaps", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "angle", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "rounding", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(layout, ptr, "catadioptric", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(layout, ptr, "shift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(layout, ptr, "flaps", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "angle", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "rounding", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(layout, ptr, "catadioptric", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(layout, ptr, "shift", UI_ITEM_R_SLIDER, NULL, ICON_NONE); } static void node_composit_buts_bokehblur(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "use_variable_size", 0, NULL, ICON_NONE); - // uiItemR(layout, ptr, "f_stop", 0, NULL, ICON_NONE); // UNUSED - uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "use_extended_bounds", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_variable_size", 0, NULL, ICON_NONE); + // uiItemR(layout, ptr, "f_stop", 0, NULL, ICON_NONE); // UNUSED + uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_extended_bounds", 0, NULL, ICON_NONE); } -static void node_composit_backdrop_viewer(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y) +static void node_composit_backdrop_viewer( + SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y) { -// node_composit_backdrop_canvas(snode, backdrop, node, x, y); - if (node->custom1 == 0) { - const float backdropWidth = backdrop->x; - const float backdropHeight = backdrop->y; - const float cx = x + snode->zoom * backdropWidth * node->custom3; - const float cy = y + snode->zoom * backdropHeight * node->custom4; - const float cross_size = 12 * U.pixelsize; + // node_composit_backdrop_canvas(snode, backdrop, node, x, y); + if (node->custom1 == 0) { + const float backdropWidth = backdrop->x; + const float backdropHeight = backdrop->y; + const float cx = x + snode->zoom * backdropWidth * node->custom3; + const float cy = y + snode->zoom * backdropHeight * node->custom4; + const float cross_size = 12 * U.pixelsize; - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformColor3f(1.0f, 1.0f, 1.0f); + immUniformColor3f(1.0f, 1.0f, 1.0f); - immBegin(GPU_PRIM_LINES, 4); - immVertex2f(pos, cx - cross_size, cy - cross_size); - immVertex2f(pos, cx + cross_size, cy + cross_size); - immVertex2f(pos, cx + cross_size, cy - cross_size); - immVertex2f(pos, cx - cross_size, cy + cross_size); - immEnd(); + immBegin(GPU_PRIM_LINES, 4); + immVertex2f(pos, cx - cross_size, cy - cross_size); + immVertex2f(pos, cx + cross_size, cy + cross_size); + immVertex2f(pos, cx + cross_size, cy - cross_size); + immVertex2f(pos, cx - cross_size, cy + cross_size); + immEnd(); - immUnbindProgram(); - } + immUnbindProgram(); + } } -static void node_composit_backdrop_boxmask(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y) +static void node_composit_backdrop_boxmask( + SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y) { - NodeBoxMask *boxmask = node->storage; - const float backdropWidth = backdrop->x; - const float backdropHeight = backdrop->y; - const float aspect = backdropWidth / backdropHeight; - const float rad = -boxmask->rotation; - const float cosine = cosf(rad); - const float sine = sinf(rad); - const float halveBoxWidth = backdropWidth * (boxmask->width / 2.0f); - const float halveBoxHeight = backdropHeight * (boxmask->height / 2.0f) * aspect; + NodeBoxMask *boxmask = node->storage; + const float backdropWidth = backdrop->x; + const float backdropHeight = backdrop->y; + const float aspect = backdropWidth / backdropHeight; + const float rad = -boxmask->rotation; + const float cosine = cosf(rad); + const float sine = sinf(rad); + const float halveBoxWidth = backdropWidth * (boxmask->width / 2.0f); + const float halveBoxHeight = backdropHeight * (boxmask->height / 2.0f) * aspect; - float cx, cy, x1, x2, x3, x4; - float y1, y2, y3, y4; + float cx, cy, x1, x2, x3, x4; + float y1, y2, y3, y4; - cx = x + snode->zoom * backdropWidth * boxmask->x; - cy = y + snode->zoom * backdropHeight * boxmask->y; + cx = x + snode->zoom * backdropWidth * boxmask->x; + cy = y + snode->zoom * backdropHeight * boxmask->y; - x1 = cx - (cosine * halveBoxWidth + sine * halveBoxHeight) * snode->zoom; - x2 = cx - (cosine * -halveBoxWidth + sine * halveBoxHeight) * snode->zoom; - x3 = cx - (cosine * -halveBoxWidth + sine * -halveBoxHeight) * snode->zoom; - x4 = cx - (cosine * halveBoxWidth + sine * -halveBoxHeight) * snode->zoom; - y1 = cy - (-sine * halveBoxWidth + cosine * halveBoxHeight) * snode->zoom; - y2 = cy - (-sine * -halveBoxWidth + cosine * halveBoxHeight) * snode->zoom; - y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom; - y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom; + x1 = cx - (cosine * halveBoxWidth + sine * halveBoxHeight) * snode->zoom; + x2 = cx - (cosine * -halveBoxWidth + sine * halveBoxHeight) * snode->zoom; + x3 = cx - (cosine * -halveBoxWidth + sine * -halveBoxHeight) * snode->zoom; + x4 = cx - (cosine * halveBoxWidth + sine * -halveBoxHeight) * snode->zoom; + y1 = cy - (-sine * halveBoxWidth + cosine * halveBoxHeight) * snode->zoom; + y2 = cy - (-sine * -halveBoxWidth + cosine * halveBoxHeight) * snode->zoom; + y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom; + y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom; - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformColor3f(1.0f, 1.0f, 1.0f); + immUniformColor3f(1.0f, 1.0f, 1.0f); - immBegin(GPU_PRIM_LINE_LOOP, 4); - immVertex2f(pos, x1, y1); - immVertex2f(pos, x2, y2); - immVertex2f(pos, x3, y3); - immVertex2f(pos, x4, y4); - immEnd(); + immBegin(GPU_PRIM_LINE_LOOP, 4); + immVertex2f(pos, x1, y1); + immVertex2f(pos, x2, y2); + immVertex2f(pos, x3, y3); + immVertex2f(pos, x4, y4); + immEnd(); - immUnbindProgram(); + immUnbindProgram(); } -static void node_composit_backdrop_ellipsemask(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y) +static void node_composit_backdrop_ellipsemask( + SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y) { - NodeEllipseMask *ellipsemask = node->storage; - const float backdropWidth = backdrop->x; - const float backdropHeight = backdrop->y; - const float aspect = backdropWidth / backdropHeight; - const float rad = -ellipsemask->rotation; - const float cosine = cosf(rad); - const float sine = sinf(rad); - const float halveBoxWidth = backdropWidth * (ellipsemask->width / 2.0f); - const float halveBoxHeight = backdropHeight * (ellipsemask->height / 2.0f) * aspect; + NodeEllipseMask *ellipsemask = node->storage; + const float backdropWidth = backdrop->x; + const float backdropHeight = backdrop->y; + const float aspect = backdropWidth / backdropHeight; + const float rad = -ellipsemask->rotation; + const float cosine = cosf(rad); + const float sine = sinf(rad); + const float halveBoxWidth = backdropWidth * (ellipsemask->width / 2.0f); + const float halveBoxHeight = backdropHeight * (ellipsemask->height / 2.0f) * aspect; - float cx, cy, x1, x2, x3, x4; - float y1, y2, y3, y4; + float cx, cy, x1, x2, x3, x4; + float y1, y2, y3, y4; - cx = x + snode->zoom * backdropWidth * ellipsemask->x; - cy = y + snode->zoom * backdropHeight * ellipsemask->y; + cx = x + snode->zoom * backdropWidth * ellipsemask->x; + cy = y + snode->zoom * backdropHeight * ellipsemask->y; - x1 = cx - (cosine * halveBoxWidth + sine * halveBoxHeight) * snode->zoom; - x2 = cx - (cosine * -halveBoxWidth + sine * halveBoxHeight) * snode->zoom; - x3 = cx - (cosine * -halveBoxWidth + sine * -halveBoxHeight) * snode->zoom; - x4 = cx - (cosine * halveBoxWidth + sine * -halveBoxHeight) * snode->zoom; - y1 = cy - (-sine * halveBoxWidth + cosine * halveBoxHeight) * snode->zoom; - y2 = cy - (-sine * -halveBoxWidth + cosine * halveBoxHeight) * snode->zoom; - y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom; - y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom; + x1 = cx - (cosine * halveBoxWidth + sine * halveBoxHeight) * snode->zoom; + x2 = cx - (cosine * -halveBoxWidth + sine * halveBoxHeight) * snode->zoom; + x3 = cx - (cosine * -halveBoxWidth + sine * -halveBoxHeight) * snode->zoom; + x4 = cx - (cosine * halveBoxWidth + sine * -halveBoxHeight) * snode->zoom; + y1 = cy - (-sine * halveBoxWidth + cosine * halveBoxHeight) * snode->zoom; + y2 = cy - (-sine * -halveBoxWidth + cosine * halveBoxHeight) * snode->zoom; + y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom; + y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom; - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformColor3f(1.0f, 1.0f, 1.0f); + immUniformColor3f(1.0f, 1.0f, 1.0f); - immBegin(GPU_PRIM_LINE_LOOP, 4); - immVertex2f(pos, x1, y1); - immVertex2f(pos, x2, y2); - immVertex2f(pos, x3, y3); - immVertex2f(pos, x4, y4); - immEnd(); + immBegin(GPU_PRIM_LINE_LOOP, 4); + immVertex2f(pos, x1, y1); + immVertex2f(pos, x2, y2); + immVertex2f(pos, x3, y3); + immVertex2f(pos, x4, y4); + immEnd(); - immUnbindProgram(); + immUnbindProgram(); } static void node_composit_buts_ellipsemask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *row; - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "x", 0, NULL, ICON_NONE); - uiItemR(row, ptr, "y", 0, NULL, ICON_NONE); - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "width", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(row, ptr, "height", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiLayout *row; + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "x", 0, NULL, ICON_NONE); + uiItemR(row, ptr, "y", 0, NULL, ICON_NONE); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "width", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(row, ptr, "height", UI_ITEM_R_SLIDER, NULL, ICON_NONE); - uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "rotation", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE); } static void node_composit_buts_composite(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "use_alpha", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_alpha", 0, NULL, ICON_NONE); } static void node_composit_buts_viewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "use_alpha", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_alpha", 0, NULL, ICON_NONE); } static void node_composit_buts_viewer_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - uiItemR(layout, ptr, "use_alpha", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "tile_order", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "tile_order") == 0) { - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "center_x", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "center_y", 0, NULL, ICON_NONE); - } + uiItemR(layout, ptr, "use_alpha", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "tile_order", 0, NULL, ICON_NONE); + if (RNA_enum_get(ptr, "tile_order") == 0) { + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "center_x", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "center_y", 0, NULL, ICON_NONE); + } } static void node_composit_buts_mask(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; + bNode *node = ptr->data; - uiTemplateID(layout, C, ptr, "mask", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - uiItemR(layout, ptr, "use_feather", 0, NULL, ICON_NONE); + uiTemplateID(layout, C, ptr, "mask", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiItemR(layout, ptr, "use_feather", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "size_source", 0, "", ICON_NONE); + uiItemR(layout, ptr, "size_source", 0, "", ICON_NONE); - if (node->custom1 & (CMP_NODEFLAG_MASK_FIXED | CMP_NODEFLAG_MASK_FIXED_SCENE)) { - uiItemR(layout, ptr, "size_x", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "size_y", 0, NULL, ICON_NONE); - } + if (node->custom1 & (CMP_NODEFLAG_MASK_FIXED | CMP_NODEFLAG_MASK_FIXED_SCENE)) { + uiItemR(layout, ptr, "size_x", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "size_y", 0, NULL, ICON_NONE); + } - uiItemR(layout, ptr, "use_motion_blur", 0, NULL, ICON_NONE); - if (node->custom1 & CMP_NODEFLAG_MASK_MOTION_BLUR) { - uiItemR(layout, ptr, "motion_blur_samples", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "motion_blur_shutter", 0, NULL, ICON_NONE); - } + uiItemR(layout, ptr, "use_motion_blur", 0, NULL, ICON_NONE); + if (node->custom1 & CMP_NODEFLAG_MASK_MOTION_BLUR) { + uiItemR(layout, ptr, "motion_blur_samples", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "motion_blur_shutter", 0, NULL, ICON_NONE); + } } static void node_composit_buts_keyingscreen(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; + bNode *node = ptr->data; - uiTemplateID(layout, C, ptr, "clip", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID(layout, C, ptr, "clip", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (node->id) { - MovieClip *clip = (MovieClip *) node->id; - uiLayout *col; - PointerRNA tracking_ptr; + if (node->id) { + MovieClip *clip = (MovieClip *)node->id; + uiLayout *col; + PointerRNA tracking_ptr; - RNA_pointer_create(&clip->id, &RNA_MovieTracking, &clip->tracking, &tracking_ptr); + RNA_pointer_create(&clip->id, &RNA_MovieTracking, &clip->tracking, &tracking_ptr); - col = uiLayoutColumn(layout, true); - uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA); - } + col = uiLayoutColumn(layout, true); + uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA); + } } static void node_composit_buts_keying(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - /* bNode *node = ptr->data; */ /* UNUSED */ + /* bNode *node = ptr->data; */ /* UNUSED */ - uiItemR(layout, ptr, "blur_pre", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "screen_balance", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "despill_factor", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "despill_balance", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "edge_kernel_radius", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "edge_kernel_tolerance", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "clip_black", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "clip_white", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "dilate_distance", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "feather_falloff", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "feather_distance", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "blur_post", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "blur_pre", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "screen_balance", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "despill_factor", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "despill_balance", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "edge_kernel_radius", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "edge_kernel_tolerance", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "clip_black", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "clip_white", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "dilate_distance", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "feather_falloff", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "feather_distance", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "blur_post", 0, NULL, ICON_NONE); } static void node_composit_buts_trackpos(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; + bNode *node = ptr->data; - uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID( + layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (node->id) { - MovieClip *clip = (MovieClip *) node->id; - MovieTracking *tracking = &clip->tracking; - MovieTrackingObject *object; - uiLayout *col; - PointerRNA tracking_ptr; - NodeTrackPosData *data = node->storage; + if (node->id) { + MovieClip *clip = (MovieClip *)node->id; + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *object; + uiLayout *col; + PointerRNA tracking_ptr; + NodeTrackPosData *data = node->storage; - RNA_pointer_create(&clip->id, &RNA_MovieTracking, tracking, &tracking_ptr); + RNA_pointer_create(&clip->id, &RNA_MovieTracking, tracking, &tracking_ptr); - col = uiLayoutColumn(layout, false); - uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA); + col = uiLayoutColumn(layout, false); + uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA); - object = BKE_tracking_object_get_named(tracking, data->tracking_object); - if (object) { - PointerRNA object_ptr; + object = BKE_tracking_object_get_named(tracking, data->tracking_object); + if (object) { + PointerRNA object_ptr; - RNA_pointer_create(&clip->id, &RNA_MovieTrackingObject, object, &object_ptr); + RNA_pointer_create(&clip->id, &RNA_MovieTrackingObject, object, &object_ptr); - uiItemPointerR(col, ptr, "track_name", &object_ptr, "tracks", "", ICON_ANIM_DATA); - } - else { - uiItemR(layout, ptr, "track_name", 0, "", ICON_ANIM_DATA); - } + uiItemPointerR(col, ptr, "track_name", &object_ptr, "tracks", "", ICON_ANIM_DATA); + } + else { + uiItemR(layout, ptr, "track_name", 0, "", ICON_ANIM_DATA); + } - uiItemR(layout, ptr, "position", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "position", 0, NULL, ICON_NONE); - if (ELEM(node->custom1, CMP_TRACKPOS_RELATIVE_FRAME, CMP_TRACKPOS_ABSOLUTE_FRAME)) { - uiItemR(layout, ptr, "frame_relative", 0, NULL, ICON_NONE); - } - } + if (ELEM(node->custom1, CMP_TRACKPOS_RELATIVE_FRAME, CMP_TRACKPOS_ABSOLUTE_FRAME)) { + uiItemR(layout, ptr, "frame_relative", 0, NULL, ICON_NONE); + } + } } static void node_composit_buts_planetrackdeform(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - NodePlaneTrackDeformData *data = node->storage; + bNode *node = ptr->data; + NodePlaneTrackDeformData *data = node->storage; - uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID( + layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (node->id) { - MovieClip *clip = (MovieClip *) node->id; - MovieTracking *tracking = &clip->tracking; - MovieTrackingObject *object; - uiLayout *col; - PointerRNA tracking_ptr; + if (node->id) { + MovieClip *clip = (MovieClip *)node->id; + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *object; + uiLayout *col; + PointerRNA tracking_ptr; - RNA_pointer_create(&clip->id, &RNA_MovieTracking, tracking, &tracking_ptr); + RNA_pointer_create(&clip->id, &RNA_MovieTracking, tracking, &tracking_ptr); - col = uiLayoutColumn(layout, false); - uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA); + col = uiLayoutColumn(layout, false); + uiItemPointerR(col, ptr, "tracking_object", &tracking_ptr, "objects", "", ICON_OBJECT_DATA); - object = BKE_tracking_object_get_named(tracking, data->tracking_object); - if (object) { - PointerRNA object_ptr; + object = BKE_tracking_object_get_named(tracking, data->tracking_object); + if (object) { + PointerRNA object_ptr; - RNA_pointer_create(&clip->id, &RNA_MovieTrackingObject, object, &object_ptr); + RNA_pointer_create(&clip->id, &RNA_MovieTrackingObject, object, &object_ptr); - uiItemPointerR(col, ptr, "plane_track_name", &object_ptr, "plane_tracks", "", ICON_ANIM_DATA); - } - else { - uiItemR(layout, ptr, "plane_track_name", 0, "", ICON_ANIM_DATA); - } - } + uiItemPointerR( + col, ptr, "plane_track_name", &object_ptr, "plane_tracks", "", ICON_ANIM_DATA); + } + else { + uiItemR(layout, ptr, "plane_track_name", 0, "", ICON_ANIM_DATA); + } + } - uiItemR(layout, ptr, "use_motion_blur", 0, NULL, ICON_NONE); - if (data->flag & CMP_NODEFLAG_PLANETRACKDEFORM_MOTION_BLUR) { - uiItemR(layout, ptr, "motion_blur_samples", 0, NULL, ICON_NONE); - uiItemR(layout, ptr, "motion_blur_shutter", 0, NULL, ICON_NONE); - } + uiItemR(layout, ptr, "use_motion_blur", 0, NULL, ICON_NONE); + if (data->flag & CMP_NODEFLAG_PLANETRACKDEFORM_MOTION_BLUR) { + uiItemR(layout, ptr, "motion_blur_samples", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "motion_blur_shutter", 0, NULL, ICON_NONE); + } } -static void node_composit_buts_cornerpin(uiLayout *UNUSED(layout), bContext *UNUSED(C), PointerRNA *UNUSED(ptr)) +static void node_composit_buts_cornerpin(uiLayout *UNUSED(layout), + bContext *UNUSED(C), + PointerRNA *UNUSED(ptr)) { } static void node_composit_buts_sunbeams(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "source", UI_ITEM_R_EXPAND, "", ICON_NONE); - uiItemR(layout, ptr, "ray_length", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + uiItemR(layout, ptr, "source", UI_ITEM_R_EXPAND, "", ICON_NONE); + uiItemR(layout, ptr, "ray_length", UI_ITEM_R_SLIDER, NULL, ICON_NONE); } static void node_composit_buts_cryptomatte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col = uiLayoutColumn(layout, true); + uiLayout *col = uiLayoutColumn(layout, true); - uiItemL(col, IFACE_("Matte Objects:"), ICON_NONE); + uiItemL(col, IFACE_("Matte Objects:"), ICON_NONE); - uiLayout *row = uiLayoutRow(col, true); - uiTemplateCryptoPicker(row, ptr, "add"); - uiTemplateCryptoPicker(row, ptr, "remove"); + uiLayout *row = uiLayoutRow(col, true); + uiTemplateCryptoPicker(row, ptr, "add"); + uiTemplateCryptoPicker(row, ptr, "remove"); - uiItemR(col, ptr, "matte_id", 0, "", ICON_NONE); + uiItemR(col, ptr, "matte_id", 0, "", ICON_NONE); } -static void node_composit_buts_cryptomatte_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *UNUSED(ptr)) +static void node_composit_buts_cryptomatte_ex(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *UNUSED(ptr)) { - uiItemO(layout, IFACE_("Add Crypto Layer"), ICON_ADD, "NODE_OT_cryptomatte_layer_add"); - uiItemO(layout, IFACE_("Remove Crypto Layer"), ICON_REMOVE, "NODE_OT_cryptomatte_layer_remove"); + uiItemO(layout, IFACE_("Add Crypto Layer"), ICON_ADD, "NODE_OT_cryptomatte_layer_add"); + uiItemO(layout, IFACE_("Remove Crypto Layer"), ICON_REMOVE, "NODE_OT_cryptomatte_layer_remove"); } -static void node_composit_buts_brightcontrast(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void node_composit_buts_brightcontrast(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { - uiItemR(layout, ptr, "use_premultiply", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_premultiply", 0, NULL, ICON_NONE); } /* only once called */ static void node_composit_set_butfunc(bNodeType *ntype) { - switch (ntype->type) { - case CMP_NODE_IMAGE: - ntype->draw_buttons = node_composit_buts_image; - ntype->draw_buttons_ex = node_composit_buts_image_ex; - break; - case CMP_NODE_R_LAYERS: - ntype->draw_buttons = node_composit_buts_viewlayers; - break; - case CMP_NODE_NORMAL: - ntype->draw_buttons = node_buts_normal; - break; - case CMP_NODE_CURVE_VEC: - ntype->draw_buttons = node_buts_curvevec; - break; - case CMP_NODE_CURVE_RGB: - ntype->draw_buttons = node_buts_curvecol; - break; - case CMP_NODE_VALUE: - ntype->draw_buttons = node_buts_value; - break; - case CMP_NODE_RGB: - ntype->draw_buttons = node_buts_rgb; - break; - case CMP_NODE_FLIP: - ntype->draw_buttons = node_composit_buts_flip; - break; - case CMP_NODE_SPLITVIEWER: - ntype->draw_buttons = node_composit_buts_splitviewer; - break; - case CMP_NODE_MIX_RGB: - ntype->draw_buttons = node_buts_mix_rgb; - break; - case CMP_NODE_VALTORGB: - ntype->draw_buttons = node_buts_colorramp; - break; - case CMP_NODE_CROP: - ntype->draw_buttons = node_composit_buts_crop; - break; - case CMP_NODE_BLUR: - ntype->draw_buttons = node_composit_buts_blur; - break; - case CMP_NODE_DBLUR: - ntype->draw_buttons = node_composit_buts_dblur; - break; - case CMP_NODE_BILATERALBLUR: - ntype->draw_buttons = node_composit_buts_bilateralblur; - break; - case CMP_NODE_DEFOCUS: - ntype->draw_buttons = node_composit_buts_defocus; - break; - case CMP_NODE_GLARE: - ntype->draw_buttons = node_composit_buts_glare; - break; - case CMP_NODE_TONEMAP: - ntype->draw_buttons = node_composit_buts_tonemap; - break; - case CMP_NODE_LENSDIST: - ntype->draw_buttons = node_composit_buts_lensdist; - break; - case CMP_NODE_VECBLUR: - ntype->draw_buttons = node_composit_buts_vecblur; - break; - case CMP_NODE_FILTER: - ntype->draw_buttons = node_composit_buts_filter; - break; - case CMP_NODE_MAP_VALUE: - ntype->draw_buttons = node_composit_buts_map_value; - break; - case CMP_NODE_MAP_RANGE: - ntype->draw_buttons = node_composit_buts_map_range; - break; - case CMP_NODE_TIME: - ntype->draw_buttons = node_buts_time; - break; - case CMP_NODE_ALPHAOVER: - ntype->draw_buttons = node_composit_buts_alphaover; - break; - case CMP_NODE_TEXTURE: - ntype->draw_buttons = node_buts_texture; - break; - case CMP_NODE_DILATEERODE: - ntype->draw_buttons = node_composit_buts_dilateerode; - break; - case CMP_NODE_INPAINT: - ntype->draw_buttons = node_composit_buts_inpaint; - break; - case CMP_NODE_DESPECKLE: - ntype->draw_buttons = node_composit_buts_despeckle; - break; - case CMP_NODE_OUTPUT_FILE: - ntype->draw_buttons = node_composit_buts_file_output; - ntype->draw_buttons_ex = node_composit_buts_file_output_ex; - break; - case CMP_NODE_DIFF_MATTE: - ntype->draw_buttons = node_composit_buts_diff_matte; - break; - case CMP_NODE_DIST_MATTE: - ntype->draw_buttons = node_composit_buts_distance_matte; - break; - case CMP_NODE_COLOR_SPILL: - ntype->draw_buttons = node_composit_buts_color_spill; - break; - case CMP_NODE_CHROMA_MATTE: - ntype->draw_buttons = node_composit_buts_chroma_matte; - break; - case CMP_NODE_COLOR_MATTE: - ntype->draw_buttons = node_composit_buts_color_matte; - break; - case CMP_NODE_SCALE: - ntype->draw_buttons = node_composit_buts_scale; - break; - case CMP_NODE_ROTATE: - ntype->draw_buttons = node_composit_buts_rotate; - break; - case CMP_NODE_CHANNEL_MATTE: - ntype->draw_buttons = node_composit_buts_channel_matte; - break; - case CMP_NODE_LUMA_MATTE: - ntype->draw_buttons = node_composit_buts_luma_matte; - break; - case CMP_NODE_MAP_UV: - ntype->draw_buttons = node_composit_buts_map_uv; - break; - case CMP_NODE_ID_MASK: - ntype->draw_buttons = node_composit_buts_id_mask; - break; - case CMP_NODE_DOUBLEEDGEMASK: - ntype->draw_buttons = node_composit_buts_double_edge_mask; - break; - case CMP_NODE_MATH: - ntype->draw_buttons = node_buts_math; - break; - case CMP_NODE_INVERT: - ntype->draw_buttons = node_composit_buts_invert; - break; - case CMP_NODE_PREMULKEY: - ntype->draw_buttons = node_composit_buts_premulkey; - break; - case CMP_NODE_VIEW_LEVELS: - ntype->draw_buttons = node_composit_buts_view_levels; - break; - case CMP_NODE_COLORBALANCE: - ntype->draw_buttons = node_composit_buts_colorbalance; - ntype->draw_buttons_ex = node_composit_buts_colorbalance_ex; - break; - case CMP_NODE_HUECORRECT: - ntype->draw_buttons = node_composit_buts_huecorrect; - break; - case CMP_NODE_ZCOMBINE: - ntype->draw_buttons = node_composit_buts_zcombine; - break; - case CMP_NODE_COMBYCCA: - case CMP_NODE_SEPYCCA: - ntype->draw_buttons = node_composit_buts_ycc; - break; - case CMP_NODE_MOVIECLIP: - ntype->draw_buttons = node_composit_buts_movieclip; - ntype->draw_buttons_ex = node_composit_buts_movieclip_ex; - break; - case CMP_NODE_STABILIZE2D: - ntype->draw_buttons = node_composit_buts_stabilize2d; - break; - case CMP_NODE_TRANSFORM: - ntype->draw_buttons = node_composit_buts_transform; - break; - case CMP_NODE_TRANSLATE: - ntype->draw_buttons = node_composit_buts_translate; - break; - case CMP_NODE_MOVIEDISTORTION: - ntype->draw_buttons = node_composit_buts_moviedistortion; - break; - case CMP_NODE_COLORCORRECTION: - ntype->draw_buttons = node_composit_buts_colorcorrection; - ntype->draw_buttons_ex = node_composit_buts_colorcorrection_ex; - break; - case CMP_NODE_SWITCH: - ntype->draw_buttons = node_composit_buts_switch; - break; - case CMP_NODE_SWITCH_VIEW: - ntype->draw_buttons_ex = node_composit_buts_switch_view_ex; - break; - case CMP_NODE_MASK_BOX: - ntype->draw_buttons = node_composit_buts_boxmask; - ntype->draw_backdrop = node_composit_backdrop_boxmask; - break; - case CMP_NODE_MASK_ELLIPSE: - ntype->draw_buttons = node_composit_buts_ellipsemask; - ntype->draw_backdrop = node_composit_backdrop_ellipsemask; - break; - case CMP_NODE_BOKEHIMAGE: - ntype->draw_buttons = node_composit_buts_bokehimage; - break; - case CMP_NODE_BOKEHBLUR: - ntype->draw_buttons = node_composit_buts_bokehblur; - break; - case CMP_NODE_VIEWER: - ntype->draw_buttons = node_composit_buts_viewer; - ntype->draw_buttons_ex = node_composit_buts_viewer_ex; - ntype->draw_backdrop = node_composit_backdrop_viewer; - break; - case CMP_NODE_COMPOSITE: - ntype->draw_buttons = node_composit_buts_composite; - break; - case CMP_NODE_MASK: - ntype->draw_buttons = node_composit_buts_mask; - break; - case CMP_NODE_KEYINGSCREEN: - ntype->draw_buttons = node_composit_buts_keyingscreen; - break; - case CMP_NODE_KEYING: - ntype->draw_buttons = node_composit_buts_keying; - break; - case CMP_NODE_TRACKPOS: - ntype->draw_buttons = node_composit_buts_trackpos; - break; - case CMP_NODE_PLANETRACKDEFORM: - ntype->draw_buttons = node_composit_buts_planetrackdeform; - break; - case CMP_NODE_CORNERPIN: - ntype->draw_buttons = node_composit_buts_cornerpin; - break; - case CMP_NODE_SUNBEAMS: - ntype->draw_buttons = node_composit_buts_sunbeams; - break; - case CMP_NODE_CRYPTOMATTE: - ntype->draw_buttons = node_composit_buts_cryptomatte; - ntype->draw_buttons_ex = node_composit_buts_cryptomatte_ex; - break; - case CMP_NODE_BRIGHTCONTRAST: - ntype->draw_buttons = node_composit_buts_brightcontrast; - } + switch (ntype->type) { + case CMP_NODE_IMAGE: + ntype->draw_buttons = node_composit_buts_image; + ntype->draw_buttons_ex = node_composit_buts_image_ex; + break; + case CMP_NODE_R_LAYERS: + ntype->draw_buttons = node_composit_buts_viewlayers; + break; + case CMP_NODE_NORMAL: + ntype->draw_buttons = node_buts_normal; + break; + case CMP_NODE_CURVE_VEC: + ntype->draw_buttons = node_buts_curvevec; + break; + case CMP_NODE_CURVE_RGB: + ntype->draw_buttons = node_buts_curvecol; + break; + case CMP_NODE_VALUE: + ntype->draw_buttons = node_buts_value; + break; + case CMP_NODE_RGB: + ntype->draw_buttons = node_buts_rgb; + break; + case CMP_NODE_FLIP: + ntype->draw_buttons = node_composit_buts_flip; + break; + case CMP_NODE_SPLITVIEWER: + ntype->draw_buttons = node_composit_buts_splitviewer; + break; + case CMP_NODE_MIX_RGB: + ntype->draw_buttons = node_buts_mix_rgb; + break; + case CMP_NODE_VALTORGB: + ntype->draw_buttons = node_buts_colorramp; + break; + case CMP_NODE_CROP: + ntype->draw_buttons = node_composit_buts_crop; + break; + case CMP_NODE_BLUR: + ntype->draw_buttons = node_composit_buts_blur; + break; + case CMP_NODE_DBLUR: + ntype->draw_buttons = node_composit_buts_dblur; + break; + case CMP_NODE_BILATERALBLUR: + ntype->draw_buttons = node_composit_buts_bilateralblur; + break; + case CMP_NODE_DEFOCUS: + ntype->draw_buttons = node_composit_buts_defocus; + break; + case CMP_NODE_GLARE: + ntype->draw_buttons = node_composit_buts_glare; + break; + case CMP_NODE_TONEMAP: + ntype->draw_buttons = node_composit_buts_tonemap; + break; + case CMP_NODE_LENSDIST: + ntype->draw_buttons = node_composit_buts_lensdist; + break; + case CMP_NODE_VECBLUR: + ntype->draw_buttons = node_composit_buts_vecblur; + break; + case CMP_NODE_FILTER: + ntype->draw_buttons = node_composit_buts_filter; + break; + case CMP_NODE_MAP_VALUE: + ntype->draw_buttons = node_composit_buts_map_value; + break; + case CMP_NODE_MAP_RANGE: + ntype->draw_buttons = node_composit_buts_map_range; + break; + case CMP_NODE_TIME: + ntype->draw_buttons = node_buts_time; + break; + case CMP_NODE_ALPHAOVER: + ntype->draw_buttons = node_composit_buts_alphaover; + break; + case CMP_NODE_TEXTURE: + ntype->draw_buttons = node_buts_texture; + break; + case CMP_NODE_DILATEERODE: + ntype->draw_buttons = node_composit_buts_dilateerode; + break; + case CMP_NODE_INPAINT: + ntype->draw_buttons = node_composit_buts_inpaint; + break; + case CMP_NODE_DESPECKLE: + ntype->draw_buttons = node_composit_buts_despeckle; + break; + case CMP_NODE_OUTPUT_FILE: + ntype->draw_buttons = node_composit_buts_file_output; + ntype->draw_buttons_ex = node_composit_buts_file_output_ex; + break; + case CMP_NODE_DIFF_MATTE: + ntype->draw_buttons = node_composit_buts_diff_matte; + break; + case CMP_NODE_DIST_MATTE: + ntype->draw_buttons = node_composit_buts_distance_matte; + break; + case CMP_NODE_COLOR_SPILL: + ntype->draw_buttons = node_composit_buts_color_spill; + break; + case CMP_NODE_CHROMA_MATTE: + ntype->draw_buttons = node_composit_buts_chroma_matte; + break; + case CMP_NODE_COLOR_MATTE: + ntype->draw_buttons = node_composit_buts_color_matte; + break; + case CMP_NODE_SCALE: + ntype->draw_buttons = node_composit_buts_scale; + break; + case CMP_NODE_ROTATE: + ntype->draw_buttons = node_composit_buts_rotate; + break; + case CMP_NODE_CHANNEL_MATTE: + ntype->draw_buttons = node_composit_buts_channel_matte; + break; + case CMP_NODE_LUMA_MATTE: + ntype->draw_buttons = node_composit_buts_luma_matte; + break; + case CMP_NODE_MAP_UV: + ntype->draw_buttons = node_composit_buts_map_uv; + break; + case CMP_NODE_ID_MASK: + ntype->draw_buttons = node_composit_buts_id_mask; + break; + case CMP_NODE_DOUBLEEDGEMASK: + ntype->draw_buttons = node_composit_buts_double_edge_mask; + break; + case CMP_NODE_MATH: + ntype->draw_buttons = node_buts_math; + break; + case CMP_NODE_INVERT: + ntype->draw_buttons = node_composit_buts_invert; + break; + case CMP_NODE_PREMULKEY: + ntype->draw_buttons = node_composit_buts_premulkey; + break; + case CMP_NODE_VIEW_LEVELS: + ntype->draw_buttons = node_composit_buts_view_levels; + break; + case CMP_NODE_COLORBALANCE: + ntype->draw_buttons = node_composit_buts_colorbalance; + ntype->draw_buttons_ex = node_composit_buts_colorbalance_ex; + break; + case CMP_NODE_HUECORRECT: + ntype->draw_buttons = node_composit_buts_huecorrect; + break; + case CMP_NODE_ZCOMBINE: + ntype->draw_buttons = node_composit_buts_zcombine; + break; + case CMP_NODE_COMBYCCA: + case CMP_NODE_SEPYCCA: + ntype->draw_buttons = node_composit_buts_ycc; + break; + case CMP_NODE_MOVIECLIP: + ntype->draw_buttons = node_composit_buts_movieclip; + ntype->draw_buttons_ex = node_composit_buts_movieclip_ex; + break; + case CMP_NODE_STABILIZE2D: + ntype->draw_buttons = node_composit_buts_stabilize2d; + break; + case CMP_NODE_TRANSFORM: + ntype->draw_buttons = node_composit_buts_transform; + break; + case CMP_NODE_TRANSLATE: + ntype->draw_buttons = node_composit_buts_translate; + break; + case CMP_NODE_MOVIEDISTORTION: + ntype->draw_buttons = node_composit_buts_moviedistortion; + break; + case CMP_NODE_COLORCORRECTION: + ntype->draw_buttons = node_composit_buts_colorcorrection; + ntype->draw_buttons_ex = node_composit_buts_colorcorrection_ex; + break; + case CMP_NODE_SWITCH: + ntype->draw_buttons = node_composit_buts_switch; + break; + case CMP_NODE_SWITCH_VIEW: + ntype->draw_buttons_ex = node_composit_buts_switch_view_ex; + break; + case CMP_NODE_MASK_BOX: + ntype->draw_buttons = node_composit_buts_boxmask; + ntype->draw_backdrop = node_composit_backdrop_boxmask; + break; + case CMP_NODE_MASK_ELLIPSE: + ntype->draw_buttons = node_composit_buts_ellipsemask; + ntype->draw_backdrop = node_composit_backdrop_ellipsemask; + break; + case CMP_NODE_BOKEHIMAGE: + ntype->draw_buttons = node_composit_buts_bokehimage; + break; + case CMP_NODE_BOKEHBLUR: + ntype->draw_buttons = node_composit_buts_bokehblur; + break; + case CMP_NODE_VIEWER: + ntype->draw_buttons = node_composit_buts_viewer; + ntype->draw_buttons_ex = node_composit_buts_viewer_ex; + ntype->draw_backdrop = node_composit_backdrop_viewer; + break; + case CMP_NODE_COMPOSITE: + ntype->draw_buttons = node_composit_buts_composite; + break; + case CMP_NODE_MASK: + ntype->draw_buttons = node_composit_buts_mask; + break; + case CMP_NODE_KEYINGSCREEN: + ntype->draw_buttons = node_composit_buts_keyingscreen; + break; + case CMP_NODE_KEYING: + ntype->draw_buttons = node_composit_buts_keying; + break; + case CMP_NODE_TRACKPOS: + ntype->draw_buttons = node_composit_buts_trackpos; + break; + case CMP_NODE_PLANETRACKDEFORM: + ntype->draw_buttons = node_composit_buts_planetrackdeform; + break; + case CMP_NODE_CORNERPIN: + ntype->draw_buttons = node_composit_buts_cornerpin; + break; + case CMP_NODE_SUNBEAMS: + ntype->draw_buttons = node_composit_buts_sunbeams; + break; + case CMP_NODE_CRYPTOMATTE: + ntype->draw_buttons = node_composit_buts_cryptomatte; + ntype->draw_buttons_ex = node_composit_buts_cryptomatte_ex; + break; + case CMP_NODE_BRIGHTCONTRAST: + ntype->draw_buttons = node_composit_buts_brightcontrast; + } } /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */ static void node_texture_buts_bricks(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiLayout *col; + uiLayout *col; - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "offset", UI_ITEM_R_SLIDER, IFACE_("Offset"), ICON_NONE); - uiItemR(col, ptr, "offset_frequency", 0, IFACE_("Frequency"), ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "offset", UI_ITEM_R_SLIDER, IFACE_("Offset"), ICON_NONE); + uiItemR(col, ptr, "offset_frequency", 0, IFACE_("Frequency"), ICON_NONE); - col = uiLayoutColumn(layout, true); - uiItemR(col, ptr, "squash", 0, IFACE_("Squash"), ICON_NONE); - uiItemR(col, ptr, "squash_frequency", 0, IFACE_("Frequency"), ICON_NONE); + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "squash", 0, IFACE_("Squash"), ICON_NONE); + uiItemR(col, ptr, "squash_frequency", 0, IFACE_("Frequency"), ICON_NONE); } static void node_texture_buts_proc(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - PointerRNA tex_ptr; - bNode *node = ptr->data; - ID *id = ptr->id.data; - Tex *tex = (Tex *)node->storage; - uiLayout *col, *row; - - RNA_pointer_create(id, &RNA_Texture, tex, &tex_ptr); - - col = uiLayoutColumn(layout, false); - - switch (tex->type) { - case TEX_BLEND: - uiItemR(col, &tex_ptr, "progression", 0, "", ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "use_flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - break; - - case TEX_MARBLE: - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "marble_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "noise_basis", 0, "", ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - break; - - case TEX_MAGIC: - uiItemR(col, &tex_ptr, "noise_depth", 0, NULL, ICON_NONE); - break; - - case TEX_STUCCI: - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "stucci_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); - break; - - case TEX_WOOD: - uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); - uiItemR(col, &tex_ptr, "wood_type", 0, "", ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(col, false); - uiLayoutSetActive(row, !(ELEM(tex->stype, TEX_BAND, TEX_RING))); - uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - break; - - case TEX_CLOUDS: - uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "cloud_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, IFACE_("Depth"), ICON_NONE); - break; - - case TEX_DISTNOISE: - uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); - uiItemR(col, &tex_ptr, "noise_distortion", 0, "", ICON_NONE); - break; - - case TEX_MUSGRAVE: - uiItemR(col, &tex_ptr, "musgrave_type", 0, "", ICON_NONE); - uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); - break; - case TEX_VORONOI: - uiItemR(col, &tex_ptr, "distance_metric", 0, "", ICON_NONE); - if (tex->vn_distm == TEX_MINKOVSKY) { - uiItemR(col, &tex_ptr, "minkovsky_exponent", 0, NULL, ICON_NONE); - } - uiItemR(col, &tex_ptr, "color_mode", 0, "", ICON_NONE); - break; - } + PointerRNA tex_ptr; + bNode *node = ptr->data; + ID *id = ptr->id.data; + Tex *tex = (Tex *)node->storage; + uiLayout *col, *row; + + RNA_pointer_create(id, &RNA_Texture, tex, &tex_ptr); + + col = uiLayoutColumn(layout, false); + + switch (tex->type) { + case TEX_BLEND: + uiItemR(col, &tex_ptr, "progression", 0, "", ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "use_flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + break; + + case TEX_MARBLE: + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "marble_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "noise_basis", 0, "", ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + break; + + case TEX_MAGIC: + uiItemR(col, &tex_ptr, "noise_depth", 0, NULL, ICON_NONE); + break; + + case TEX_STUCCI: + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "stucci_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); + break; + + case TEX_WOOD: + uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); + uiItemR(col, &tex_ptr, "wood_type", 0, "", ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "noise_basis_2", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + row = uiLayoutRow(col, false); + uiLayoutSetActive(row, !(ELEM(tex->stype, TEX_BAND, TEX_RING))); + uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + break; + + case TEX_CLOUDS: + uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "cloud_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + row = uiLayoutRow(col, false); + uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, IFACE_("Depth"), ICON_NONE); + break; + + case TEX_DISTNOISE: + uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); + uiItemR(col, &tex_ptr, "noise_distortion", 0, "", ICON_NONE); + break; + + case TEX_MUSGRAVE: + uiItemR(col, &tex_ptr, "musgrave_type", 0, "", ICON_NONE); + uiItemR(col, &tex_ptr, "noise_basis", 0, "", ICON_NONE); + break; + case TEX_VORONOI: + uiItemR(col, &tex_ptr, "distance_metric", 0, "", ICON_NONE); + if (tex->vn_distm == TEX_MINKOVSKY) { + uiItemR(col, &tex_ptr, "minkovsky_exponent", 0, NULL, ICON_NONE); + } + uiItemR(col, &tex_ptr, "color_mode", 0, "", ICON_NONE); + break; + } } static void node_texture_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiTemplateID(layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID(layout, + C, + ptr, + "image", + "IMAGE_OT_new", + "IMAGE_OT_open", + NULL, + UI_TEMPLATE_ID_FILTER_ALL, + false); } static void node_texture_buts_image_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node = ptr->data; - PointerRNA iuserptr; + bNode *node = ptr->data; + PointerRNA iuserptr; - RNA_pointer_create((ID *)ptr->id.data, &RNA_ImageUser, node->storage, &iuserptr); - uiTemplateImage(layout, C, ptr, "image", &iuserptr, 0, 0); + RNA_pointer_create((ID *)ptr->id.data, &RNA_ImageUser, node->storage, &iuserptr); + uiTemplateImage(layout, C, ptr, "image", &iuserptr, 0, 0); } static void node_texture_buts_output(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { - uiItemR(layout, ptr, "filepath", 0, "", ICON_NONE); + uiItemR(layout, ptr, "filepath", 0, "", ICON_NONE); } /* only once called */ static void node_texture_set_butfunc(bNodeType *ntype) { - if (ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX) { - ntype->draw_buttons = node_texture_buts_proc; - } - else { - switch (ntype->type) { + if (ntype->type >= TEX_NODE_PROC && ntype->type < TEX_NODE_PROC_MAX) { + ntype->draw_buttons = node_texture_buts_proc; + } + else { + switch (ntype->type) { - case TEX_NODE_MATH: - ntype->draw_buttons = node_buts_math; - break; + case TEX_NODE_MATH: + ntype->draw_buttons = node_buts_math; + break; - case TEX_NODE_MIX_RGB: - ntype->draw_buttons = node_buts_mix_rgb; - break; + case TEX_NODE_MIX_RGB: + ntype->draw_buttons = node_buts_mix_rgb; + break; - case TEX_NODE_VALTORGB: - ntype->draw_buttons = node_buts_colorramp; - break; + case TEX_NODE_VALTORGB: + ntype->draw_buttons = node_buts_colorramp; + break; - case TEX_NODE_CURVE_RGB: - ntype->draw_buttons = node_buts_curvecol; - break; + case TEX_NODE_CURVE_RGB: + ntype->draw_buttons = node_buts_curvecol; + break; - case TEX_NODE_CURVE_TIME: - ntype->draw_buttons = node_buts_time; - break; + case TEX_NODE_CURVE_TIME: + ntype->draw_buttons = node_buts_time; + break; - case TEX_NODE_TEXTURE: - ntype->draw_buttons = node_buts_texture; - break; + case TEX_NODE_TEXTURE: + ntype->draw_buttons = node_buts_texture; + break; - case TEX_NODE_BRICKS: - ntype->draw_buttons = node_texture_buts_bricks; - break; + case TEX_NODE_BRICKS: + ntype->draw_buttons = node_texture_buts_bricks; + break; - case TEX_NODE_IMAGE: - ntype->draw_buttons = node_texture_buts_image; - ntype->draw_buttons_ex = node_texture_buts_image_ex; - break; + case TEX_NODE_IMAGE: + ntype->draw_buttons = node_texture_buts_image; + ntype->draw_buttons_ex = node_texture_buts_image_ex; + break; - case TEX_NODE_OUTPUT: - ntype->draw_buttons = node_texture_buts_output; - break; - } - } + case TEX_NODE_OUTPUT: + ntype->draw_buttons = node_texture_buts_output; + break; + } + } } /* ****** init draw callbacks for all tree types, only called in usiblender.c, once ************ */ static void node_property_update_default(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr) { - bNodeTree *ntree = ptr->id.data; - bNode *node = ptr->data; - ED_node_tag_update_nodetree(bmain, ntree, node); + bNodeTree *ntree = ptr->id.data; + bNode *node = ptr->data; + ED_node_tag_update_nodetree(bmain, ntree, node); } static void node_socket_template_properties_update(bNodeType *ntype, bNodeSocketTemplate *stemp) { - StructRNA *srna = ntype->ext.srna; - PropertyRNA *prop = RNA_struct_type_find_property(srna, stemp->identifier); + StructRNA *srna = ntype->ext.srna; + PropertyRNA *prop = RNA_struct_type_find_property(srna, stemp->identifier); - if (prop) { - RNA_def_property_update_runtime(prop, node_property_update_default); - } + if (prop) { + RNA_def_property_update_runtime(prop, node_property_update_default); + } } static void node_template_properties_update(bNodeType *ntype) { - bNodeSocketTemplate *stemp; + bNodeSocketTemplate *stemp; - if (ntype->inputs) { - for (stemp = ntype->inputs; stemp->type >= 0; ++stemp) { - node_socket_template_properties_update(ntype, stemp); - } - } - if (ntype->outputs) { - for (stemp = ntype->outputs; stemp->type >= 0; ++stemp) { - node_socket_template_properties_update(ntype, stemp); - } - } + if (ntype->inputs) { + for (stemp = ntype->inputs; stemp->type >= 0; ++stemp) { + node_socket_template_properties_update(ntype, stemp); + } + } + if (ntype->outputs) { + for (stemp = ntype->outputs; stemp->type >= 0; ++stemp) { + node_socket_template_properties_update(ntype, stemp); + } + } } -static void node_socket_undefined_draw(bContext *UNUSED(C), uiLayout *layout, PointerRNA *UNUSED(ptr), PointerRNA *UNUSED(node_ptr), +static void node_socket_undefined_draw(bContext *UNUSED(C), + uiLayout *layout, + PointerRNA *UNUSED(ptr), + PointerRNA *UNUSED(node_ptr), const char *UNUSED(text)) { - uiItemL(layout, IFACE_("Undefined Socket Type"), ICON_ERROR); + uiItemL(layout, IFACE_("Undefined Socket Type"), ICON_ERROR); } -static void node_socket_undefined_draw_color(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PointerRNA *UNUSED(node_ptr), float *r_color) +static void node_socket_undefined_draw_color(bContext *UNUSED(C), + PointerRNA *UNUSED(ptr), + PointerRNA *UNUSED(node_ptr), + float *r_color) { - r_color[0] = 1.0f; - r_color[1] = 0.0f; - r_color[2] = 0.0f; - r_color[3] = 1.0f; + r_color[0] = 1.0f; + r_color[1] = 0.0f; + r_color[2] = 0.0f; + r_color[3] = 1.0f; } -static void node_socket_undefined_interface_draw(bContext *UNUSED(C), uiLayout *layout, PointerRNA *UNUSED(ptr)) +static void node_socket_undefined_interface_draw(bContext *UNUSED(C), + uiLayout *layout, + PointerRNA *UNUSED(ptr)) { - uiItemL(layout, IFACE_("Undefined Socket Type"), ICON_ERROR); + uiItemL(layout, IFACE_("Undefined Socket Type"), ICON_ERROR); } -static void node_socket_undefined_interface_draw_color(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), float *r_color) +static void node_socket_undefined_interface_draw_color(bContext *UNUSED(C), + PointerRNA *UNUSED(ptr), + float *r_color) { - r_color[0] = 1.0f; - r_color[1] = 0.0f; - r_color[2] = 0.0f; - r_color[3] = 1.0f; + r_color[0] = 1.0f; + r_color[1] = 0.0f; + r_color[2] = 0.0f; + r_color[3] = 1.0f; } void ED_node_init_butfuncs(void) { - /* Fallback types for undefined tree, nodes, sockets - * Defined in blenkernel, but not registered in type hashes. - */ - - /* default ui functions */ - NodeTypeUndefined.draw_nodetype = node_draw_default; - NodeTypeUndefined.draw_nodetype_prepare = node_update_default; - NodeTypeUndefined.select_area_func = node_select_area_default; - NodeTypeUndefined.tweak_area_func = node_tweak_area_default; - NodeTypeUndefined.draw_buttons = NULL; - NodeTypeUndefined.draw_buttons_ex = NULL; - NodeTypeUndefined.resize_area_func = node_resize_area_default; - - NodeSocketTypeUndefined.draw = node_socket_undefined_draw; - NodeSocketTypeUndefined.draw_color = node_socket_undefined_draw_color; - NodeSocketTypeUndefined.interface_draw = node_socket_undefined_interface_draw; - NodeSocketTypeUndefined.interface_draw_color = node_socket_undefined_interface_draw_color; - - /* node type ui functions */ - NODE_TYPES_BEGIN(ntype) { - /* default ui functions */ - ntype->draw_nodetype = node_draw_default; - ntype->draw_nodetype_prepare = node_update_default; - ntype->select_area_func = node_select_area_default; - ntype->tweak_area_func = node_tweak_area_default; - ntype->draw_buttons = NULL; - ntype->draw_buttons_ex = NULL; - ntype->resize_area_func = node_resize_area_default; - - node_common_set_butfunc(ntype); - - node_composit_set_butfunc(ntype); - node_shader_set_butfunc(ntype); - node_texture_set_butfunc(ntype); - - /* define update callbacks for socket properties */ - node_template_properties_update(ntype); - } NODE_TYPES_END; - - /* tree type icons */ - ntreeType_Composite->ui_icon = ICON_NODE_COMPOSITING; - ntreeType_Shader->ui_icon = ICON_NODE_MATERIAL; - ntreeType_Texture->ui_icon = ICON_NODE_TEXTURE; + /* Fallback types for undefined tree, nodes, sockets + * Defined in blenkernel, but not registered in type hashes. + */ + + /* default ui functions */ + NodeTypeUndefined.draw_nodetype = node_draw_default; + NodeTypeUndefined.draw_nodetype_prepare = node_update_default; + NodeTypeUndefined.select_area_func = node_select_area_default; + NodeTypeUndefined.tweak_area_func = node_tweak_area_default; + NodeTypeUndefined.draw_buttons = NULL; + NodeTypeUndefined.draw_buttons_ex = NULL; + NodeTypeUndefined.resize_area_func = node_resize_area_default; + + NodeSocketTypeUndefined.draw = node_socket_undefined_draw; + NodeSocketTypeUndefined.draw_color = node_socket_undefined_draw_color; + NodeSocketTypeUndefined.interface_draw = node_socket_undefined_interface_draw; + NodeSocketTypeUndefined.interface_draw_color = node_socket_undefined_interface_draw_color; + + /* node type ui functions */ + NODE_TYPES_BEGIN (ntype) { + /* default ui functions */ + ntype->draw_nodetype = node_draw_default; + ntype->draw_nodetype_prepare = node_update_default; + ntype->select_area_func = node_select_area_default; + ntype->tweak_area_func = node_tweak_area_default; + ntype->draw_buttons = NULL; + ntype->draw_buttons_ex = NULL; + ntype->resize_area_func = node_resize_area_default; + + node_common_set_butfunc(ntype); + + node_composit_set_butfunc(ntype); + node_shader_set_butfunc(ntype); + node_texture_set_butfunc(ntype); + + /* define update callbacks for socket properties */ + node_template_properties_update(ntype); + } + NODE_TYPES_END; + + /* tree type icons */ + ntreeType_Composite->ui_icon = ICON_NODE_COMPOSITING; + ntreeType_Shader->ui_icon = ICON_NODE_MATERIAL; + ntreeType_Texture->ui_icon = ICON_NODE_TEXTURE; } void ED_init_custom_node_type(bNodeType *ntype) { - /* default ui functions */ - ntype->draw_nodetype = node_draw_default; - ntype->draw_nodetype_prepare = node_update_default; - ntype->resize_area_func = node_resize_area_default; - ntype->select_area_func = node_select_area_default; - ntype->tweak_area_func = node_tweak_area_default; + /* default ui functions */ + ntype->draw_nodetype = node_draw_default; + ntype->draw_nodetype_prepare = node_update_default; + ntype->resize_area_func = node_resize_area_default; + ntype->select_area_func = node_select_area_default; + ntype->tweak_area_func = node_tweak_area_default; } void ED_init_custom_node_socket_type(bNodeSocketType *stype) { - /* default ui functions */ - stype->draw = node_socket_button_label; + /* default ui functions */ + stype->draw = node_socket_button_label; } /* maps standard socket integer type to a color */ static const float std_node_socket_colors[][4] = { - {0.63, 0.63, 0.63, 1.0}, /* SOCK_FLOAT */ - {0.39, 0.39, 0.78, 1.0}, /* SOCK_VECTOR */ - {0.78, 0.78, 0.16, 1.0}, /* SOCK_RGBA */ - {0.39, 0.78, 0.39, 1.0}, /* SOCK_SHADER */ - {0.70, 0.65, 0.19, 1.0}, /* SOCK_BOOLEAN */ - {0.0, 0.0, 0.0, 1.0}, /*__SOCK_MESH (deprecated) */ - {0.06, 0.52, 0.15, 1.0}, /* SOCK_INT */ - {0.39, 0.39, 0.39, 1.0}, /* SOCK_STRING */ + {0.63, 0.63, 0.63, 1.0}, /* SOCK_FLOAT */ + {0.39, 0.39, 0.78, 1.0}, /* SOCK_VECTOR */ + {0.78, 0.78, 0.16, 1.0}, /* SOCK_RGBA */ + {0.39, 0.78, 0.39, 1.0}, /* SOCK_SHADER */ + {0.70, 0.65, 0.19, 1.0}, /* SOCK_BOOLEAN */ + {0.0, 0.0, 0.0, 1.0}, /*__SOCK_MESH (deprecated) */ + {0.06, 0.52, 0.15, 1.0}, /* SOCK_INT */ + {0.39, 0.39, 0.39, 1.0}, /* SOCK_STRING */ }; /* common color callbacks for standard types */ -static void std_node_socket_draw_color(bContext *UNUSED(C), PointerRNA *ptr, PointerRNA *UNUSED(node_ptr), float *r_color) +static void std_node_socket_draw_color(bContext *UNUSED(C), + PointerRNA *ptr, + PointerRNA *UNUSED(node_ptr), + float *r_color) { - bNodeSocket *sock = ptr->data; - int type = sock->typeinfo->type; - copy_v4_v4(r_color, std_node_socket_colors[type]); + bNodeSocket *sock = ptr->data; + int type = sock->typeinfo->type; + copy_v4_v4(r_color, std_node_socket_colors[type]); } -static void std_node_socket_interface_draw_color(bContext *UNUSED(C), PointerRNA *ptr, float *r_color) +static void std_node_socket_interface_draw_color(bContext *UNUSED(C), + PointerRNA *ptr, + float *r_color) { - bNodeSocket *sock = ptr->data; - int type = sock->typeinfo->type; - copy_v4_v4(r_color, std_node_socket_colors[type]); + bNodeSocket *sock = ptr->data; + int type = sock->typeinfo->type; + copy_v4_v4(r_color, std_node_socket_colors[type]); } /* draw function for file output node sockets, * displays only sub-path and format, no value button */ -static void node_file_output_socket_draw(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr) -{ - bNodeTree *ntree = ptr->id.data; - bNodeSocket *sock = ptr->data; - uiLayout *row; - PointerRNA inputptr, imfptr; - int imtype; - - row = uiLayoutRow(layout, false); - - imfptr = RNA_pointer_get(node_ptr, "format"); - imtype = RNA_enum_get(&imfptr, "file_format"); - - if (imtype == R_IMF_IMTYPE_MULTILAYER) { - NodeImageMultiFileSocket *input = sock->storage; - RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotLayer, input, &inputptr); - - uiItemL(row, input->layer, ICON_NONE); - } - else { - NodeImageMultiFileSocket *input = sock->storage; - PropertyRNA *imtype_prop; - const char *imtype_name; - uiBlock *block; - RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotFile, input, &inputptr); - - uiItemL(row, input->path, ICON_NONE); - - if (!RNA_boolean_get(&inputptr, "use_node_format")) { - imfptr = RNA_pointer_get(&inputptr, "format"); - } - - imtype_prop = RNA_struct_find_property(&imfptr, "file_format"); - RNA_property_enum_name((bContext *)C, &imfptr, imtype_prop, - RNA_property_enum_get(&imfptr, imtype_prop), &imtype_name); - block = uiLayoutGetBlock(row); - UI_block_emboss_set(block, UI_EMBOSS_PULLDOWN); - uiItemL(row, imtype_name, ICON_NONE); - UI_block_emboss_set(block, UI_EMBOSS_NONE); - } -} - -static void std_node_socket_draw(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, const char *text) -{ - bNode *node = node_ptr->data; - bNodeSocket *sock = ptr->data; - int type = sock->typeinfo->type; - /*int subtype = sock->typeinfo->subtype;*/ - - /* XXX not nice, eventually give this node its own socket type ... */ - if (node->type == CMP_NODE_OUTPUT_FILE) { - node_file_output_socket_draw(C, layout, ptr, node_ptr); - return; - } - - if ((sock->in_out == SOCK_OUT) || (sock->flag & SOCK_IN_USE) || (sock->flag & SOCK_HIDE_VALUE)) { - node_socket_button_label(C, layout, ptr, node_ptr, text); - return; - } - - switch (type) { - case SOCK_FLOAT: - case SOCK_INT: - case SOCK_BOOLEAN: - uiItemR(layout, ptr, "default_value", 0, text, 0); - break; - case SOCK_VECTOR: - uiTemplateComponentMenu(layout, ptr, "default_value", text); - break; - case SOCK_RGBA: - case SOCK_STRING: - { - uiLayout *row = uiLayoutSplit(layout, 0.5f, false); - uiItemL(row, text, 0); - uiItemR(row, ptr, "default_value", 0, "", 0); - break; - } - default: - node_socket_button_label(C, layout, ptr, node_ptr, text); - break; - } +static void node_file_output_socket_draw(bContext *C, + uiLayout *layout, + PointerRNA *ptr, + PointerRNA *node_ptr) +{ + bNodeTree *ntree = ptr->id.data; + bNodeSocket *sock = ptr->data; + uiLayout *row; + PointerRNA inputptr, imfptr; + int imtype; + + row = uiLayoutRow(layout, false); + + imfptr = RNA_pointer_get(node_ptr, "format"); + imtype = RNA_enum_get(&imfptr, "file_format"); + + if (imtype == R_IMF_IMTYPE_MULTILAYER) { + NodeImageMultiFileSocket *input = sock->storage; + RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotLayer, input, &inputptr); + + uiItemL(row, input->layer, ICON_NONE); + } + else { + NodeImageMultiFileSocket *input = sock->storage; + PropertyRNA *imtype_prop; + const char *imtype_name; + uiBlock *block; + RNA_pointer_create(&ntree->id, &RNA_NodeOutputFileSlotFile, input, &inputptr); + + uiItemL(row, input->path, ICON_NONE); + + if (!RNA_boolean_get(&inputptr, "use_node_format")) { + imfptr = RNA_pointer_get(&inputptr, "format"); + } + + imtype_prop = RNA_struct_find_property(&imfptr, "file_format"); + RNA_property_enum_name((bContext *)C, + &imfptr, + imtype_prop, + RNA_property_enum_get(&imfptr, imtype_prop), + &imtype_name); + block = uiLayoutGetBlock(row); + UI_block_emboss_set(block, UI_EMBOSS_PULLDOWN); + uiItemL(row, imtype_name, ICON_NONE); + UI_block_emboss_set(block, UI_EMBOSS_NONE); + } +} + +static void std_node_socket_draw( + bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, const char *text) +{ + bNode *node = node_ptr->data; + bNodeSocket *sock = ptr->data; + int type = sock->typeinfo->type; + /*int subtype = sock->typeinfo->subtype;*/ + + /* XXX not nice, eventually give this node its own socket type ... */ + if (node->type == CMP_NODE_OUTPUT_FILE) { + node_file_output_socket_draw(C, layout, ptr, node_ptr); + return; + } + + if ((sock->in_out == SOCK_OUT) || (sock->flag & SOCK_IN_USE) || (sock->flag & SOCK_HIDE_VALUE)) { + node_socket_button_label(C, layout, ptr, node_ptr, text); + return; + } + + switch (type) { + case SOCK_FLOAT: + case SOCK_INT: + case SOCK_BOOLEAN: + uiItemR(layout, ptr, "default_value", 0, text, 0); + break; + case SOCK_VECTOR: + uiTemplateComponentMenu(layout, ptr, "default_value", text); + break; + case SOCK_RGBA: + case SOCK_STRING: { + uiLayout *row = uiLayoutSplit(layout, 0.5f, false); + uiItemL(row, text, 0); + uiItemR(row, ptr, "default_value", 0, "", 0); + break; + } + default: + node_socket_button_label(C, layout, ptr, node_ptr, text); + break; + } } static void std_node_socket_interface_draw(bContext *UNUSED(C), uiLayout *layout, PointerRNA *ptr) { - bNodeSocket *sock = ptr->data; - int type = sock->typeinfo->type; - /*int subtype = sock->typeinfo->subtype;*/ - - switch (type) { - case SOCK_FLOAT: - { - uiLayout *row; - uiItemR(layout, ptr, "default_value", 0, NULL, 0); - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "min_value", 0, IFACE_("Min"), 0); - uiItemR(row, ptr, "max_value", 0, IFACE_("Max"), 0); - break; - } - case SOCK_INT: - { - uiLayout *row; - uiItemR(layout, ptr, "default_value", 0, NULL, 0); - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "min_value", 0, IFACE_("Min"), 0); - uiItemR(row, ptr, "max_value", 0, IFACE_("Max"), 0); - break; - } - case SOCK_VECTOR: - { - uiLayout *row; - uiItemR(layout, ptr, "default_value", UI_ITEM_R_EXPAND, NULL, 0); - row = uiLayoutRow(layout, true); - uiItemR(row, ptr, "min_value", 0, IFACE_("Min"), 0); - uiItemR(row, ptr, "max_value", 0, IFACE_("Max"), 0); - break; - } - case SOCK_BOOLEAN: - case SOCK_RGBA: - case SOCK_STRING: - { - uiItemR(layout, ptr, "default_value", 0, NULL, 0); - break; - } - } + bNodeSocket *sock = ptr->data; + int type = sock->typeinfo->type; + /*int subtype = sock->typeinfo->subtype;*/ + + switch (type) { + case SOCK_FLOAT: { + uiLayout *row; + uiItemR(layout, ptr, "default_value", 0, NULL, 0); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "min_value", 0, IFACE_("Min"), 0); + uiItemR(row, ptr, "max_value", 0, IFACE_("Max"), 0); + break; + } + case SOCK_INT: { + uiLayout *row; + uiItemR(layout, ptr, "default_value", 0, NULL, 0); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "min_value", 0, IFACE_("Min"), 0); + uiItemR(row, ptr, "max_value", 0, IFACE_("Max"), 0); + break; + } + case SOCK_VECTOR: { + uiLayout *row; + uiItemR(layout, ptr, "default_value", UI_ITEM_R_EXPAND, NULL, 0); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "min_value", 0, IFACE_("Min"), 0); + uiItemR(row, ptr, "max_value", 0, IFACE_("Max"), 0); + break; + } + case SOCK_BOOLEAN: + case SOCK_RGBA: + case SOCK_STRING: { + uiItemR(layout, ptr, "default_value", 0, NULL, 0); + break; + } + } } void ED_init_standard_node_socket_type(bNodeSocketType *stype) { - stype->draw = std_node_socket_draw; - stype->draw_color = std_node_socket_draw_color; - stype->interface_draw = std_node_socket_interface_draw; - stype->interface_draw_color = std_node_socket_interface_draw_color; + stype->draw = std_node_socket_draw; + stype->draw_color = std_node_socket_draw_color; + stype->interface_draw = std_node_socket_interface_draw; + stype->interface_draw_color = std_node_socket_interface_draw_color; } -static void node_socket_virtual_draw_color(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PointerRNA *UNUSED(node_ptr), float *r_color) +static void node_socket_virtual_draw_color(bContext *UNUSED(C), + PointerRNA *UNUSED(ptr), + PointerRNA *UNUSED(node_ptr), + float *r_color) { - /* alpha = 0, empty circle */ - zero_v4(r_color); + /* alpha = 0, empty circle */ + zero_v4(r_color); } void ED_init_node_socket_type_virtual(bNodeSocketType *stype) { - stype->draw = node_socket_button_label; - stype->draw_color = node_socket_virtual_draw_color; + stype->draw = node_socket_button_label; + stype->draw_color = node_socket_virtual_draw_color; } /* ************** Generic drawing ************** */ -void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeInstanceKey parent_key) -{ - Main *bmain = CTX_data_main(C); - bNodeInstanceKey active_viewer_key = (snode->nodetree ? snode->nodetree->active_viewer_key : NODE_INSTANCE_KEY_NONE); - float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - Image *ima; - void *lock; - ImBuf *ibuf; - - if (!(snode->flag & SNODE_BACKDRAW) || !ED_node_is_compositor(snode)) { - return; - } - - if (parent_key.value != active_viewer_key.value) { - return; - } - - ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - if (ibuf) { - float x, y; - - GPU_matrix_push_projection(); - GPU_matrix_push(); - - /* somehow the offset has to be calculated inverse */ - wmOrtho2_region_pixelspace(ar); - - x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof; - y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof; - - if (ibuf->rect || ibuf->rect_float) { - unsigned char *display_buffer = NULL; - void *cache_handle = NULL; - - if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B | SNODE_SHOW_ALPHA)) { - - display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); - - if (snode->flag & SNODE_SHOW_R) { - shuffle[0] = 1.0f; - } - else if (snode->flag & SNODE_SHOW_G) { - shuffle[1] = 1.0f; - } - else if (snode->flag & SNODE_SHOW_B) { - shuffle[2] = 1.0f; - } - else { - shuffle[3] = 1.0f; - } - - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); - GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform_ensure(state.shader, "shuffle"), 4, 1, shuffle); - - immDrawPixelsTex(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, - display_buffer, snode->zoom, snode->zoom, NULL); - - GPU_shader_unbind(); - } - else if (snode->flag & SNODE_USE_ALPHA) { - GPU_blend(true); - GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); - - glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom); - - GPU_blend(false); - } - else { - glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom); - } - - if (cache_handle) { - IMB_display_buffer_release(cache_handle); - } - } - - /** \note draw selected info on backdrop */ - if (snode->edittree) { - bNode *node = snode->edittree->nodes.first; - rctf *viewer_border = &snode->nodetree->viewer_border; - while (node) { - if (node->flag & NODE_SELECT) { - if (node->typeinfo->draw_backdrop) { - node->typeinfo->draw_backdrop(snode, ibuf, node, x, y); - } - } - node = node->next; - } - - if ((snode->nodetree->flag & NTREE_VIEWER_BORDER) && - viewer_border->xmin < viewer_border->xmax && - viewer_border->ymin < viewer_border->ymax) - { - rcti pixel_border; - BLI_rcti_init(&pixel_border, - x + snode->zoom * viewer_border->xmin * ibuf->x, - x + snode->zoom * viewer_border->xmax * ibuf->x, - y + snode->zoom * viewer_border->ymin * ibuf->y, - y + snode->zoom * viewer_border->ymax * ibuf->y); - - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformThemeColor(TH_ACTIVE); - - immDrawBorderCorners(pos, &pixel_border, 1.0f, 1.0f); - - immUnbindProgram(); - } - } - - GPU_matrix_pop_projection(); - GPU_matrix_pop(); - } - - BKE_image_release_ibuf(ima, ibuf, lock); +void draw_nodespace_back_pix(const bContext *C, + ARegion *ar, + SpaceNode *snode, + bNodeInstanceKey parent_key) +{ + Main *bmain = CTX_data_main(C); + bNodeInstanceKey active_viewer_key = (snode->nodetree ? snode->nodetree->active_viewer_key : + NODE_INSTANCE_KEY_NONE); + float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + Image *ima; + void *lock; + ImBuf *ibuf; + + if (!(snode->flag & SNODE_BACKDRAW) || !ED_node_is_compositor(snode)) { + return; + } + + if (parent_key.value != active_viewer_key.value) { + return; + } + + ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + if (ibuf) { + float x, y; + + GPU_matrix_push_projection(); + GPU_matrix_push(); + + /* somehow the offset has to be calculated inverse */ + wmOrtho2_region_pixelspace(ar); + + x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof; + y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof; + + if (ibuf->rect || ibuf->rect_float) { + unsigned char *display_buffer = NULL; + void *cache_handle = NULL; + + if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B | SNODE_SHOW_ALPHA)) { + + display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); + + if (snode->flag & SNODE_SHOW_R) { + shuffle[0] = 1.0f; + } + else if (snode->flag & SNODE_SHOW_G) { + shuffle[1] = 1.0f; + } + else if (snode->flag & SNODE_SHOW_B) { + shuffle[2] = 1.0f; + } + else { + shuffle[3] = 1.0f; + } + + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); + GPU_shader_uniform_vector( + state.shader, GPU_shader_get_uniform_ensure(state.shader, "shuffle"), 4, 1, shuffle); + + immDrawPixelsTex(&state, + x, + y, + ibuf->x, + ibuf->y, + GL_RGBA, + GL_UNSIGNED_BYTE, + GL_NEAREST, + display_buffer, + snode->zoom, + snode->zoom, + NULL); + + GPU_shader_unbind(); + } + else if (snode->flag & SNODE_USE_ALPHA) { + GPU_blend(true); + GPU_blend_set_func_separate( + GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + + glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom); + + GPU_blend(false); + } + else { + glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom); + } + + if (cache_handle) { + IMB_display_buffer_release(cache_handle); + } + } + + /** \note draw selected info on backdrop */ + if (snode->edittree) { + bNode *node = snode->edittree->nodes.first; + rctf *viewer_border = &snode->nodetree->viewer_border; + while (node) { + if (node->flag & NODE_SELECT) { + if (node->typeinfo->draw_backdrop) { + node->typeinfo->draw_backdrop(snode, ibuf, node, x, y); + } + } + node = node->next; + } + + if ((snode->nodetree->flag & NTREE_VIEWER_BORDER) && + viewer_border->xmin < viewer_border->xmax && viewer_border->ymin < viewer_border->ymax) { + rcti pixel_border; + BLI_rcti_init(&pixel_border, + x + snode->zoom * viewer_border->xmin * ibuf->x, + x + snode->zoom * viewer_border->xmax * ibuf->x, + y + snode->zoom * viewer_border->ymin * ibuf->y, + y + snode->zoom * viewer_border->ymax * ibuf->y); + + uint pos = GPU_vertformat_attr_add( + immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformThemeColor(TH_ACTIVE); + + immDrawBorderCorners(pos, &pixel_border, 1.0f, 1.0f); + + immUnbindProgram(); + } + } + + GPU_matrix_pop_projection(); + GPU_matrix_pop(); + } + + BKE_image_release_ibuf(ima, ibuf, lock); } /* return quadratic beziers points for a given nodelink and clip if v2d is not NULL. */ -static bool node_link_bezier_handles(View2D *v2d, SpaceNode *snode, bNodeLink *link, float vec[4][2]) -{ - float dist; - float deltax, deltay; - float cursor[2] = {0.0f, 0.0f}; - int toreroute, fromreroute; - - /* this function can be called with snode null (via cut_links_intersect) */ - /* XXX map snode->cursor back to view space */ - if (snode) { - cursor[0] = snode->cursor[0] * UI_DPI_FAC; - cursor[1] = snode->cursor[1] * UI_DPI_FAC; - } - - /* in v0 and v3 we put begin/end points */ - if (link->fromsock) { - vec[0][0] = link->fromsock->locx; - vec[0][1] = link->fromsock->locy; - fromreroute = (link->fromnode && link->fromnode->type == NODE_REROUTE); - } - else { - if (snode == NULL) { - return 0; - } - copy_v2_v2(vec[0], cursor); - fromreroute = 0; - } - if (link->tosock) { - vec[3][0] = link->tosock->locx; - vec[3][1] = link->tosock->locy; - toreroute = (link->tonode && link->tonode->type == NODE_REROUTE); - } - else { - if (snode == NULL) { - return 0; - } - copy_v2_v2(vec[3], cursor); - toreroute = 0; - } - - /* may be called outside of drawing (so pass spacetype) */ - int curving = UI_GetThemeValueType(TH_NODE_CURVING, SPACE_NODE); - - if (curving == 0) { - /* Straight line: align all points. */ - mid_v2_v2v2(vec[1], vec[0], vec[3]); - mid_v2_v2v2(vec[2], vec[1], vec[3]); - return 1; - } - - dist = curving * 0.10f * fabsf(vec[0][0] - vec[3][0]); - deltax = vec[3][0] - vec[0][0]; - deltay = vec[3][1] - vec[0][1]; - /* check direction later, for top sockets */ - if (fromreroute) { - if (ABS(deltax) > ABS(deltay)) { - vec[1][1] = vec[0][1]; - vec[1][0] = vec[0][0] + (deltax > 0 ? dist : -dist); - } - else { - vec[1][0] = vec[0][0]; - vec[1][1] = vec[0][1] + (deltay > 0 ? dist : -dist); - } - } - else { - vec[1][0] = vec[0][0] + dist; - vec[1][1] = vec[0][1]; - } - if (toreroute) { - if (ABS(deltax) > ABS(deltay)) { - vec[2][1] = vec[3][1]; - vec[2][0] = vec[3][0] + (deltax > 0 ? -dist : dist); - } - else { - vec[2][0] = vec[3][0]; - vec[2][1] = vec[3][1] + (deltay > 0 ? -dist : dist); - } - - } - else { - vec[2][0] = vec[3][0] - dist; - vec[2][1] = vec[3][1]; - } - - if (v2d && min_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax) { - return 0; /* clipped */ - } - else if (v2d && max_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin) { - return 0; /* clipped */ - } - - return 1; +static bool node_link_bezier_handles(View2D *v2d, + SpaceNode *snode, + bNodeLink *link, + float vec[4][2]) +{ + float dist; + float deltax, deltay; + float cursor[2] = {0.0f, 0.0f}; + int toreroute, fromreroute; + + /* this function can be called with snode null (via cut_links_intersect) */ + /* XXX map snode->cursor back to view space */ + if (snode) { + cursor[0] = snode->cursor[0] * UI_DPI_FAC; + cursor[1] = snode->cursor[1] * UI_DPI_FAC; + } + + /* in v0 and v3 we put begin/end points */ + if (link->fromsock) { + vec[0][0] = link->fromsock->locx; + vec[0][1] = link->fromsock->locy; + fromreroute = (link->fromnode && link->fromnode->type == NODE_REROUTE); + } + else { + if (snode == NULL) { + return 0; + } + copy_v2_v2(vec[0], cursor); + fromreroute = 0; + } + if (link->tosock) { + vec[3][0] = link->tosock->locx; + vec[3][1] = link->tosock->locy; + toreroute = (link->tonode && link->tonode->type == NODE_REROUTE); + } + else { + if (snode == NULL) { + return 0; + } + copy_v2_v2(vec[3], cursor); + toreroute = 0; + } + + /* may be called outside of drawing (so pass spacetype) */ + int curving = UI_GetThemeValueType(TH_NODE_CURVING, SPACE_NODE); + + if (curving == 0) { + /* Straight line: align all points. */ + mid_v2_v2v2(vec[1], vec[0], vec[3]); + mid_v2_v2v2(vec[2], vec[1], vec[3]); + return 1; + } + + dist = curving * 0.10f * fabsf(vec[0][0] - vec[3][0]); + deltax = vec[3][0] - vec[0][0]; + deltay = vec[3][1] - vec[0][1]; + /* check direction later, for top sockets */ + if (fromreroute) { + if (ABS(deltax) > ABS(deltay)) { + vec[1][1] = vec[0][1]; + vec[1][0] = vec[0][0] + (deltax > 0 ? dist : -dist); + } + else { + vec[1][0] = vec[0][0]; + vec[1][1] = vec[0][1] + (deltay > 0 ? dist : -dist); + } + } + else { + vec[1][0] = vec[0][0] + dist; + vec[1][1] = vec[0][1]; + } + if (toreroute) { + if (ABS(deltax) > ABS(deltay)) { + vec[2][1] = vec[3][1]; + vec[2][0] = vec[3][0] + (deltax > 0 ? -dist : dist); + } + else { + vec[2][0] = vec[3][0]; + vec[2][1] = vec[3][1] + (deltay > 0 ? -dist : dist); + } + } + else { + vec[2][0] = vec[3][0] - dist; + vec[2][1] = vec[3][1]; + } + + if (v2d && min_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax) { + return 0; /* clipped */ + } + else if (v2d && max_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin) { + return 0; /* clipped */ + } + + return 1; } /* if v2d not NULL, it clips and returns 0 if not visible */ -bool node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol) +bool node_link_bezier_points( + View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol) { - float vec[4][2]; + float vec[4][2]; - if (node_link_bezier_handles(v2d, snode, link, vec)) { - /* always do all three, to prevent data hanging around */ - BKE_curve_forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], - coord_array[0] + 0, resol, sizeof(float) * 2); - BKE_curve_forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], - coord_array[0] + 1, resol, sizeof(float) * 2); + if (node_link_bezier_handles(v2d, snode, link, vec)) { + /* always do all three, to prevent data hanging around */ + BKE_curve_forward_diff_bezier( + vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0] + 0, resol, sizeof(float) * 2); + BKE_curve_forward_diff_bezier( + vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0] + 1, resol, sizeof(float) * 2); - return 1; - } - return 0; + return 1; + } + return 0; } #define NODELINK_GROUP_SIZE 256 -#define LINK_RESOL 24 -#define LINK_WIDTH (2.5f * UI_DPI_FAC) -#define ARROW_SIZE (7 * UI_DPI_FAC) +#define LINK_RESOL 24 +#define LINK_WIDTH (2.5f * UI_DPI_FAC) +#define ARROW_SIZE (7 * UI_DPI_FAC) static float arrow_verts[3][2] = {{-1.0f, 1.0f}, {0.0f, 0.0f}, {-1.0f, -1.0f}}; static float arrow_expand_axis[3][2] = {{0.7071f, 0.7071f}, {M_SQRT2, 0.0f}, {0.7071f, -0.7071f}}; static struct { - GPUBatch *batch; /* for batching line together */ - GPUBatch *batch_single; /* for single line */ - GPUVertBuf *inst_vbo; - unsigned int p0_id, p1_id, p2_id, p3_id; - unsigned int colid_id; - GPUVertBufRaw p0_step, p1_step, p2_step, p3_step; - GPUVertBufRaw colid_step; - unsigned int count; - bool enabled; + GPUBatch *batch; /* for batching line together */ + GPUBatch *batch_single; /* for single line */ + GPUVertBuf *inst_vbo; + unsigned int p0_id, p1_id, p2_id, p3_id; + unsigned int colid_id; + GPUVertBufRaw p0_step, p1_step, p2_step, p3_step; + GPUVertBufRaw colid_step; + unsigned int count; + bool enabled; } g_batch_link = {0}; static void nodelink_batch_reset(void) { - GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p0_id, &g_batch_link.p0_step); - GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p1_id, &g_batch_link.p1_step); - GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p2_id, &g_batch_link.p2_step); - GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p3_id, &g_batch_link.p3_step); - GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.colid_id, &g_batch_link.colid_step); - g_batch_link.count = 0; + GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p0_id, &g_batch_link.p0_step); + GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p1_id, &g_batch_link.p1_step); + GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p2_id, &g_batch_link.p2_step); + GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p3_id, &g_batch_link.p3_step); + GPU_vertbuf_attr_get_raw_data( + g_batch_link.inst_vbo, g_batch_link.colid_id, &g_batch_link.colid_step); + g_batch_link.count = 0; } -static void set_nodelink_vertex( - GPUVertBuf *vbo, - unsigned int uv_id, unsigned int pos_id, unsigned int exp_id, unsigned int v, - const unsigned char uv[2], const float pos[2], const float exp[2]) +static void set_nodelink_vertex(GPUVertBuf *vbo, + unsigned int uv_id, + unsigned int pos_id, + unsigned int exp_id, + unsigned int v, + const unsigned char uv[2], + const float pos[2], + const float exp[2]) { - GPU_vertbuf_attr_set(vbo, uv_id, v, uv); - GPU_vertbuf_attr_set(vbo, pos_id, v, pos); - GPU_vertbuf_attr_set(vbo, exp_id, v, exp); + GPU_vertbuf_attr_set(vbo, uv_id, v, uv); + GPU_vertbuf_attr_set(vbo, pos_id, v, pos); + GPU_vertbuf_attr_set(vbo, exp_id, v, exp); } static void nodelink_batch_init(void) { - GPUVertFormat format = {0}; - uint uv_id = GPU_vertformat_attr_add(&format, "uv", GPU_COMP_U8, 2, GPU_FETCH_INT_TO_FLOAT_UNIT); - uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - uint expand_id = GPU_vertformat_attr_add(&format, "expand", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - GPUVertBuf *vbo = GPU_vertbuf_create_with_format_ex(&format, GPU_USAGE_STATIC); - int vcount = LINK_RESOL * 2; /* curve */ - vcount += 2; /* restart strip */ - vcount += 3 * 2; /* arrow */ - vcount *= 2; /* shadow */ - vcount += 2; /* restart strip */ - GPU_vertbuf_data_alloc(vbo, vcount); - int v = 0; - - for (int k = 0; k < 2; ++k) { - unsigned char uv[2] = {0, 0}; - float pos[2] = {0.0f, 0.0f}; - float exp[2] = {0.0f, 1.0f}; - - /* restart */ - if (k == 1) { - set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); - } - - /* curve strip */ - for (int i = 0; i < LINK_RESOL; ++i) { - uv[0] = 255 * (i / (float)(LINK_RESOL - 1)); - uv[1] = 0; - set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); - uv[1] = 255; - set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); - } - /* restart */ - set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); - - uv[0] = 127; - uv[1] = 0; - copy_v2_v2(pos, arrow_verts[0]); - copy_v2_v2(exp, arrow_expand_axis[0]); - set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); - /* arrow */ - for (int i = 0; i < 3; ++i) { - uv[1] = 0; - copy_v2_v2(pos, arrow_verts[i]); - copy_v2_v2(exp, arrow_expand_axis[i]); - set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); - - uv[1] = 255; - set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); - } - - /* restart */ - if (k == 0) { - set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); - } - } - - g_batch_link.batch = GPU_batch_create_ex(GPU_PRIM_TRI_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO); - gpu_batch_presets_register(g_batch_link.batch); - - g_batch_link.batch_single = GPU_batch_create_ex(GPU_PRIM_TRI_STRIP, vbo, NULL, 0); - gpu_batch_presets_register(g_batch_link.batch_single); - - /* Instances data */ - GPUVertFormat format_inst = {0}; - g_batch_link.p0_id = GPU_vertformat_attr_add(&format_inst, "P0", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - g_batch_link.p1_id = GPU_vertformat_attr_add(&format_inst, "P1", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - g_batch_link.p2_id = GPU_vertformat_attr_add(&format_inst, "P2", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - g_batch_link.p3_id = GPU_vertformat_attr_add(&format_inst, "P3", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - g_batch_link.colid_id = GPU_vertformat_attr_add(&format_inst, "colid_doarrow", GPU_COMP_U8, 4, GPU_FETCH_INT); - g_batch_link.inst_vbo = GPU_vertbuf_create_with_format_ex(&format_inst, GPU_USAGE_STREAM); - /* Alloc max count but only draw the range we need. */ - GPU_vertbuf_data_alloc(g_batch_link.inst_vbo, NODELINK_GROUP_SIZE); - - GPU_batch_instbuf_set(g_batch_link.batch, g_batch_link.inst_vbo, true); - - nodelink_batch_reset(); + GPUVertFormat format = {0}; + uint uv_id = GPU_vertformat_attr_add(&format, "uv", GPU_COMP_U8, 2, GPU_FETCH_INT_TO_FLOAT_UNIT); + uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + uint expand_id = GPU_vertformat_attr_add(&format, "expand", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + GPUVertBuf *vbo = GPU_vertbuf_create_with_format_ex(&format, GPU_USAGE_STATIC); + int vcount = LINK_RESOL * 2; /* curve */ + vcount += 2; /* restart strip */ + vcount += 3 * 2; /* arrow */ + vcount *= 2; /* shadow */ + vcount += 2; /* restart strip */ + GPU_vertbuf_data_alloc(vbo, vcount); + int v = 0; + + for (int k = 0; k < 2; ++k) { + unsigned char uv[2] = {0, 0}; + float pos[2] = {0.0f, 0.0f}; + float exp[2] = {0.0f, 1.0f}; + + /* restart */ + if (k == 1) { + set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); + } + + /* curve strip */ + for (int i = 0; i < LINK_RESOL; ++i) { + uv[0] = 255 * (i / (float)(LINK_RESOL - 1)); + uv[1] = 0; + set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); + uv[1] = 255; + set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); + } + /* restart */ + set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); + + uv[0] = 127; + uv[1] = 0; + copy_v2_v2(pos, arrow_verts[0]); + copy_v2_v2(exp, arrow_expand_axis[0]); + set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); + /* arrow */ + for (int i = 0; i < 3; ++i) { + uv[1] = 0; + copy_v2_v2(pos, arrow_verts[i]); + copy_v2_v2(exp, arrow_expand_axis[i]); + set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); + + uv[1] = 255; + set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); + } + + /* restart */ + if (k == 0) { + set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp); + } + } + + g_batch_link.batch = GPU_batch_create_ex(GPU_PRIM_TRI_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO); + gpu_batch_presets_register(g_batch_link.batch); + + g_batch_link.batch_single = GPU_batch_create_ex(GPU_PRIM_TRI_STRIP, vbo, NULL, 0); + gpu_batch_presets_register(g_batch_link.batch_single); + + /* Instances data */ + GPUVertFormat format_inst = {0}; + g_batch_link.p0_id = GPU_vertformat_attr_add( + &format_inst, "P0", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + g_batch_link.p1_id = GPU_vertformat_attr_add( + &format_inst, "P1", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + g_batch_link.p2_id = GPU_vertformat_attr_add( + &format_inst, "P2", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + g_batch_link.p3_id = GPU_vertformat_attr_add( + &format_inst, "P3", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + g_batch_link.colid_id = GPU_vertformat_attr_add( + &format_inst, "colid_doarrow", GPU_COMP_U8, 4, GPU_FETCH_INT); + g_batch_link.inst_vbo = GPU_vertbuf_create_with_format_ex(&format_inst, GPU_USAGE_STREAM); + /* Alloc max count but only draw the range we need. */ + GPU_vertbuf_data_alloc(g_batch_link.inst_vbo, NODELINK_GROUP_SIZE); + + GPU_batch_instbuf_set(g_batch_link.batch, g_batch_link.inst_vbo, true); + + nodelink_batch_reset(); } static char nodelink_get_color_id(int th_col) { - switch (th_col) { - case TH_WIRE: return 1; - case TH_WIRE_INNER: return 2; - case TH_ACTIVE: return 3; - case TH_EDGE_SELECT: return 4; - case TH_REDALERT: return 5; - } - return 0; + switch (th_col) { + case TH_WIRE: + return 1; + case TH_WIRE_INNER: + return 2; + case TH_ACTIVE: + return 3; + case TH_EDGE_SELECT: + return 4; + case TH_REDALERT: + return 5; + } + return 0; } static void nodelink_batch_draw(SpaceNode *snode) { - if (g_batch_link.count == 0) { - return; - } + if (g_batch_link.count == 0) { + return; + } - GPU_blend(true); + GPU_blend(true); - float colors[6][4] = {{0.0f}}; - UI_GetThemeColor4fv(TH_WIRE_INNER, colors[nodelink_get_color_id(TH_WIRE_INNER)]); - UI_GetThemeColor4fv(TH_WIRE, colors[nodelink_get_color_id(TH_WIRE)]); - UI_GetThemeColor4fv(TH_ACTIVE, colors[nodelink_get_color_id(TH_ACTIVE)]); - UI_GetThemeColor4fv(TH_EDGE_SELECT, colors[nodelink_get_color_id(TH_EDGE_SELECT)]); - UI_GetThemeColor4fv(TH_REDALERT, colors[nodelink_get_color_id(TH_REDALERT)]); + float colors[6][4] = {{0.0f}}; + UI_GetThemeColor4fv(TH_WIRE_INNER, colors[nodelink_get_color_id(TH_WIRE_INNER)]); + UI_GetThemeColor4fv(TH_WIRE, colors[nodelink_get_color_id(TH_WIRE)]); + UI_GetThemeColor4fv(TH_ACTIVE, colors[nodelink_get_color_id(TH_ACTIVE)]); + UI_GetThemeColor4fv(TH_EDGE_SELECT, colors[nodelink_get_color_id(TH_EDGE_SELECT)]); + UI_GetThemeColor4fv(TH_REDALERT, colors[nodelink_get_color_id(TH_REDALERT)]); - GPU_vertbuf_data_len_set(g_batch_link.inst_vbo, g_batch_link.count); - GPU_vertbuf_use(g_batch_link.inst_vbo); /* force update. */ + GPU_vertbuf_data_len_set(g_batch_link.inst_vbo, g_batch_link.count); + GPU_vertbuf_use(g_batch_link.inst_vbo); /* force update. */ - GPU_batch_program_set_builtin(g_batch_link.batch, GPU_SHADER_2D_NODELINK_INST); - GPU_batch_uniform_4fv_array(g_batch_link.batch, "colors", 6, (float *)colors); - GPU_batch_uniform_1f(g_batch_link.batch, "expandSize", snode->aspect * LINK_WIDTH); - GPU_batch_uniform_1f(g_batch_link.batch, "arrowSize", ARROW_SIZE); - GPU_batch_draw(g_batch_link.batch); + GPU_batch_program_set_builtin(g_batch_link.batch, GPU_SHADER_2D_NODELINK_INST); + GPU_batch_uniform_4fv_array(g_batch_link.batch, "colors", 6, (float *)colors); + GPU_batch_uniform_1f(g_batch_link.batch, "expandSize", snode->aspect * LINK_WIDTH); + GPU_batch_uniform_1f(g_batch_link.batch, "arrowSize", ARROW_SIZE); + GPU_batch_draw(g_batch_link.batch); - nodelink_batch_reset(); + nodelink_batch_reset(); - GPU_blend(false); + GPU_blend(false); } void nodelink_batch_start(SpaceNode *UNUSED(snode)) { - g_batch_link.enabled = true; + g_batch_link.enabled = true; } void nodelink_batch_end(SpaceNode *snode) { - nodelink_batch_draw(snode); - g_batch_link.enabled = false; -} - -static void nodelink_batch_add_link( - SpaceNode *snode, - const float p0[2], const float p1[2], const float p2[2], const float p3[2], - int th_col1, int th_col2, int th_col3, bool drawarrow) -{ - /* Only allow these colors. If more is needed, you need to modify the shader accordingly. */ - BLI_assert(ELEM(th_col1, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT)); - BLI_assert(ELEM(th_col2, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT)); - BLI_assert(ELEM(th_col3, TH_WIRE, -1)); - - g_batch_link.count++; - copy_v2_v2(GPU_vertbuf_raw_step(&g_batch_link.p0_step), p0); - copy_v2_v2(GPU_vertbuf_raw_step(&g_batch_link.p1_step), p1); - copy_v2_v2(GPU_vertbuf_raw_step(&g_batch_link.p2_step), p2); - copy_v2_v2(GPU_vertbuf_raw_step(&g_batch_link.p3_step), p3); - char *colid = GPU_vertbuf_raw_step(&g_batch_link.colid_step); - colid[0] = nodelink_get_color_id(th_col1); - colid[1] = nodelink_get_color_id(th_col2); - colid[2] = nodelink_get_color_id(th_col3); - colid[3] = drawarrow; - - if (g_batch_link.count == NODELINK_GROUP_SIZE) { - nodelink_batch_draw(snode); - } + nodelink_batch_draw(snode); + g_batch_link.enabled = false; +} + +static void nodelink_batch_add_link(SpaceNode *snode, + const float p0[2], + const float p1[2], + const float p2[2], + const float p3[2], + int th_col1, + int th_col2, + int th_col3, + bool drawarrow) +{ + /* Only allow these colors. If more is needed, you need to modify the shader accordingly. */ + BLI_assert(ELEM(th_col1, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT)); + BLI_assert(ELEM(th_col2, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT)); + BLI_assert(ELEM(th_col3, TH_WIRE, -1)); + + g_batch_link.count++; + copy_v2_v2(GPU_vertbuf_raw_step(&g_batch_link.p0_step), p0); + copy_v2_v2(GPU_vertbuf_raw_step(&g_batch_link.p1_step), p1); + copy_v2_v2(GPU_vertbuf_raw_step(&g_batch_link.p2_step), p2); + copy_v2_v2(GPU_vertbuf_raw_step(&g_batch_link.p3_step), p3); + char *colid = GPU_vertbuf_raw_step(&g_batch_link.colid_step); + colid[0] = nodelink_get_color_id(th_col1); + colid[1] = nodelink_get_color_id(th_col2); + colid[2] = nodelink_get_color_id(th_col3); + colid[3] = drawarrow; + + if (g_batch_link.count == NODELINK_GROUP_SIZE) { + nodelink_batch_draw(snode); + } } /* don't do shadows if th_col3 is -1. */ -void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, - int th_col1, int th_col2, int th_col3) -{ - float vec[4][2]; - - if (node_link_bezier_handles(v2d, snode, link, vec)) { - int drawarrow = ((link->tonode && (link->tonode->type == NODE_REROUTE)) && - (link->fromnode && (link->fromnode->type == NODE_REROUTE))); - - if (g_batch_link.batch == NULL) { - nodelink_batch_init(); - } - - if (g_batch_link.enabled) { - /* Add link to batch. */ - nodelink_batch_add_link(snode, vec[0], vec[1], vec[2], vec[3], th_col1, th_col2, th_col3, drawarrow); - } - else { - /* Draw single link. */ - float colors[3][4] = {{0.0f}}; - if (th_col3 != -1) { - UI_GetThemeColor4fv(th_col3, colors[0]); - } - UI_GetThemeColor4fv(th_col1, colors[1]); - UI_GetThemeColor4fv(th_col2, colors[2]); - - GPUBatch *batch = g_batch_link.batch_single; - GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_NODELINK); - GPU_batch_uniform_2fv_array(batch, "bezierPts", 4, (float *)vec); - GPU_batch_uniform_4fv_array(batch, "colors", 3, (float *)colors); - GPU_batch_uniform_1f(batch, "expandSize", snode->aspect * LINK_WIDTH); - GPU_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE); - GPU_batch_uniform_1i(batch, "doArrow", drawarrow); - GPU_batch_draw(batch); - } - } +void node_draw_link_bezier( + View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int th_col2, int th_col3) +{ + float vec[4][2]; + + if (node_link_bezier_handles(v2d, snode, link, vec)) { + int drawarrow = ((link->tonode && (link->tonode->type == NODE_REROUTE)) && + (link->fromnode && (link->fromnode->type == NODE_REROUTE))); + + if (g_batch_link.batch == NULL) { + nodelink_batch_init(); + } + + if (g_batch_link.enabled) { + /* Add link to batch. */ + nodelink_batch_add_link( + snode, vec[0], vec[1], vec[2], vec[3], th_col1, th_col2, th_col3, drawarrow); + } + else { + /* Draw single link. */ + float colors[3][4] = {{0.0f}}; + if (th_col3 != -1) { + UI_GetThemeColor4fv(th_col3, colors[0]); + } + UI_GetThemeColor4fv(th_col1, colors[1]); + UI_GetThemeColor4fv(th_col2, colors[2]); + + GPUBatch *batch = g_batch_link.batch_single; + GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_NODELINK); + GPU_batch_uniform_2fv_array(batch, "bezierPts", 4, (float *)vec); + GPU_batch_uniform_4fv_array(batch, "colors", 3, (float *)colors); + GPU_batch_uniform_1f(batch, "expandSize", snode->aspect * LINK_WIDTH); + GPU_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE); + GPU_batch_uniform_1i(batch, "doArrow", drawarrow); + GPU_batch_draw(batch); + } + } } /* note; this is used for fake links in groups too */ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) { - int th_col1 = TH_WIRE_INNER, th_col2 = TH_WIRE_INNER, th_col3 = TH_WIRE; - - if (link->fromsock == NULL && link->tosock == NULL) { - return; - } - - /* new connection */ - if (!link->fromsock || !link->tosock) { - th_col1 = th_col2 = TH_ACTIVE; - } - else { - /* going to give issues once... */ - if (link->tosock->flag & SOCK_UNAVAIL) { - return; - } - if (link->fromsock->flag & SOCK_UNAVAIL) { - return; - } - - if (link->flag & NODE_LINK_VALID) { - /* special indicated link, on drop-node */ - if (link->flag & NODE_LINKFLAG_HILITE) { - th_col1 = th_col2 = TH_ACTIVE; - } - else { - /* regular link */ - if (link->fromnode && link->fromnode->flag & SELECT) { - th_col1 = TH_EDGE_SELECT; - } - if (link->tonode && link->tonode->flag & SELECT) { - th_col2 = TH_EDGE_SELECT; - } - } - } - else { - th_col1 = th_col2 = TH_REDALERT; - // th_col3 = -1; /* no shadow */ - } - } - - node_draw_link_bezier(v2d, snode, link, th_col1, th_col2, th_col3); -// node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); -} - -void ED_node_draw_snap(View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned pos) -{ - immBegin(GPU_PRIM_LINES, 4); - - if (border & (NODE_LEFT | NODE_RIGHT)) { - immVertex2f(pos, cent[0], v2d->cur.ymin); - immVertex2f(pos, cent[0], v2d->cur.ymax); - } - else { - immVertex2f(pos, cent[0], cent[1] - size); - immVertex2f(pos, cent[0], cent[1] + size); - } - - if (border & (NODE_TOP | NODE_BOTTOM)) { - immVertex2f(pos, v2d->cur.xmin, cent[1]); - immVertex2f(pos, v2d->cur.xmax, cent[1]); - } - else { - immVertex2f(pos, cent[0] - size, cent[1]); - immVertex2f(pos, cent[0] + size, cent[1]); - } - - immEnd(); + int th_col1 = TH_WIRE_INNER, th_col2 = TH_WIRE_INNER, th_col3 = TH_WIRE; + + if (link->fromsock == NULL && link->tosock == NULL) { + return; + } + + /* new connection */ + if (!link->fromsock || !link->tosock) { + th_col1 = th_col2 = TH_ACTIVE; + } + else { + /* going to give issues once... */ + if (link->tosock->flag & SOCK_UNAVAIL) { + return; + } + if (link->fromsock->flag & SOCK_UNAVAIL) { + return; + } + + if (link->flag & NODE_LINK_VALID) { + /* special indicated link, on drop-node */ + if (link->flag & NODE_LINKFLAG_HILITE) { + th_col1 = th_col2 = TH_ACTIVE; + } + else { + /* regular link */ + if (link->fromnode && link->fromnode->flag & SELECT) { + th_col1 = TH_EDGE_SELECT; + } + if (link->tonode && link->tonode->flag & SELECT) { + th_col2 = TH_EDGE_SELECT; + } + } + } + else { + th_col1 = th_col2 = TH_REDALERT; + // th_col3 = -1; /* no shadow */ + } + } + + node_draw_link_bezier(v2d, snode, link, th_col1, th_col2, th_col3); + // node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); +} + +void ED_node_draw_snap( + View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned pos) +{ + immBegin(GPU_PRIM_LINES, 4); + + if (border & (NODE_LEFT | NODE_RIGHT)) { + immVertex2f(pos, cent[0], v2d->cur.ymin); + immVertex2f(pos, cent[0], v2d->cur.ymax); + } + else { + immVertex2f(pos, cent[0], cent[1] - size); + immVertex2f(pos, cent[0], cent[1] + size); + } + + if (border & (NODE_TOP | NODE_BOTTOM)) { + immVertex2f(pos, v2d->cur.xmin, cent[1]); + immVertex2f(pos, v2d->cur.xmax, cent[1]); + } + else { + immVertex2f(pos, cent[0] - size, cent[1]); + immVertex2f(pos, cent[0] + size, cent[1]); + } + + immEnd(); } diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c index 814496cf59e..8d754087855 100644 --- a/source/blender/editors/space_node/node_add.c +++ b/source/blender/editors/space_node/node_add.c @@ -39,7 +39,7 @@ #include "BKE_scene.h" #include "BKE_texture.h" -#include "ED_node.h" /* own include */ +#include "ED_node.h" /* own include */ #include "ED_screen.h" #include "ED_render.h" @@ -52,487 +52,509 @@ #include "UI_view2d.h" -#include "node_intern.h" /* own include */ +#include "node_intern.h" /* own include */ /* XXX Does some additional initialization on top of nodeAddNode * Can be used with both custom and static nodes, if idname==NULL the static int type will be used instead. */ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx, float locy) { - SpaceNode *snode = CTX_wm_space_node(C); - Main *bmain = CTX_data_main(C); - bNode *node = NULL; + SpaceNode *snode = CTX_wm_space_node(C); + Main *bmain = CTX_data_main(C); + bNode *node = NULL; - node_deselect_all(snode); + node_deselect_all(snode); - if (idname) { - node = nodeAddNode(C, snode->edittree, idname); - } - else { - node = nodeAddStaticNode(C, snode->edittree, type); - } - BLI_assert(node && node->typeinfo); + if (idname) { + node = nodeAddNode(C, snode->edittree, idname); + } + else { + node = nodeAddStaticNode(C, snode->edittree, type); + } + BLI_assert(node && node->typeinfo); - /* Position mouse in node header. */ - node->locx = locx - NODE_DY * 1.5f / UI_DPI_FAC; - node->locy = locy + NODE_DY * 0.5f / UI_DPI_FAC; + /* Position mouse in node header. */ + node->locx = locx - NODE_DY * 1.5f / UI_DPI_FAC; + node->locy = locy + NODE_DY * 0.5f / UI_DPI_FAC; - nodeSetSelected(node, true); + nodeSetSelected(node, true); - ntreeUpdateTree(bmain, snode->edittree); - ED_node_set_active(bmain, snode->edittree, node); + ntreeUpdateTree(bmain, snode->edittree); + ED_node_set_active(bmain, snode->edittree, node); - snode_update(snode, node); + snode_update(snode, node); - if (snode->nodetree->type == NTREE_TEXTURE) { - ntreeTexCheckCyclics(snode->edittree); - } + if (snode->nodetree->type == NTREE_TEXTURE) { + ntreeTexCheckCyclics(snode->edittree); + } - return node; + return node; } /* ********************** Add reroute operator ***************** */ -static bool add_reroute_intersect_check(bNodeLink *link, float mcoords[][2], int tot, float result[2]) +static bool add_reroute_intersect_check(bNodeLink *link, + float mcoords[][2], + int tot, + float result[2]) { - float coord_array[NODE_LINK_RESOL + 1][2]; - int i, b; - - if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { - - for (i = 0; i < tot - 1; i++) { - for (b = 0; b < NODE_LINK_RESOL; b++) { - if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { - result[0] = (mcoords[i][0] + mcoords[i + 1][0]) / 2.0f; - result[1] = (mcoords[i][1] + mcoords[i + 1][1]) / 2.0f; - return 1; - } - } - } - } - return 0; + float coord_array[NODE_LINK_RESOL + 1][2]; + int i, b; + + if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { + + for (i = 0; i < tot - 1; i++) { + for (b = 0; b < NODE_LINK_RESOL; b++) { + if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { + result[0] = (mcoords[i][0] + mcoords[i + 1][0]) / 2.0f; + result[1] = (mcoords[i][1] + mcoords[i + 1][1]) / 2.0f; + return 1; + } + } + } + } + return 0; } typedef struct bNodeSocketLink { - struct bNodeSocketLink *next, *prev; + struct bNodeSocketLink *next, *prev; - struct bNodeSocket *sock; - struct bNodeLink *link; - float point[2]; + struct bNodeSocket *sock; + struct bNodeLink *link; + float point[2]; } bNodeSocketLink; -static bNodeSocketLink *add_reroute_insert_socket_link(ListBase *lb, bNodeSocket *sock, bNodeLink *link, const float point[2]) +static bNodeSocketLink *add_reroute_insert_socket_link(ListBase *lb, + bNodeSocket *sock, + bNodeLink *link, + const float point[2]) { - bNodeSocketLink *socklink, *prev; - - socklink = MEM_callocN(sizeof(bNodeSocketLink), "socket link"); - socklink->sock = sock; - socklink->link = link; - copy_v2_v2(socklink->point, point); - - for (prev = lb->last; prev; prev = prev->prev) { - if (prev->sock == sock) { - break; - } - } - BLI_insertlinkafter(lb, prev, socklink); - return socklink; + bNodeSocketLink *socklink, *prev; + + socklink = MEM_callocN(sizeof(bNodeSocketLink), "socket link"); + socklink->sock = sock; + socklink->link = link; + copy_v2_v2(socklink->point, point); + + for (prev = lb->last; prev; prev = prev->prev) { + if (prev->sock == sock) { + break; + } + } + BLI_insertlinkafter(lb, prev, socklink); + return socklink; } -static bNodeSocketLink *add_reroute_do_socket_section(bContext *C, bNodeSocketLink *socklink, int in_out) +static bNodeSocketLink *add_reroute_do_socket_section(bContext *C, + bNodeSocketLink *socklink, + int in_out) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *reroute_node = NULL; - bNodeSocket *cursock = socklink->sock; - float insert_point[2]; - int num_links; - - zero_v2(insert_point); - num_links = 0; - - while (socklink && socklink->sock == cursock) { - if (!(socklink->link->flag & NODE_LINK_TEST)) { - socklink->link->flag |= NODE_LINK_TEST; - - /* create the reroute node for this cursock */ - if (!reroute_node) { - reroute_node = nodeAddStaticNode(C, ntree, NODE_REROUTE); - - /* add a single link to/from the reroute node to replace multiple links */ - if (in_out == SOCK_OUT) { - nodeAddLink(ntree, socklink->link->fromnode, socklink->link->fromsock, reroute_node, reroute_node->inputs.first); - } - else { - nodeAddLink(ntree, reroute_node, reroute_node->outputs.first, socklink->link->tonode, socklink->link->tosock); - } - } - - /* insert the reroute node into the link */ - if (in_out == SOCK_OUT) { - socklink->link->fromnode = reroute_node; - socklink->link->fromsock = reroute_node->outputs.first; - } - else { - socklink->link->tonode = reroute_node; - socklink->link->tosock = reroute_node->inputs.first; - } - - add_v2_v2(insert_point, socklink->point); - num_links++; - } - socklink = socklink->next; - } - - if (num_links > 0) { - /* average cut point from shared links */ - mul_v2_fl(insert_point, 1.0f / num_links); - - reroute_node->locx = insert_point[0] / UI_DPI_FAC; - reroute_node->locy = insert_point[1] / UI_DPI_FAC; - } - - return socklink; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *reroute_node = NULL; + bNodeSocket *cursock = socklink->sock; + float insert_point[2]; + int num_links; + + zero_v2(insert_point); + num_links = 0; + + while (socklink && socklink->sock == cursock) { + if (!(socklink->link->flag & NODE_LINK_TEST)) { + socklink->link->flag |= NODE_LINK_TEST; + + /* create the reroute node for this cursock */ + if (!reroute_node) { + reroute_node = nodeAddStaticNode(C, ntree, NODE_REROUTE); + + /* add a single link to/from the reroute node to replace multiple links */ + if (in_out == SOCK_OUT) { + nodeAddLink(ntree, + socklink->link->fromnode, + socklink->link->fromsock, + reroute_node, + reroute_node->inputs.first); + } + else { + nodeAddLink(ntree, + reroute_node, + reroute_node->outputs.first, + socklink->link->tonode, + socklink->link->tosock); + } + } + + /* insert the reroute node into the link */ + if (in_out == SOCK_OUT) { + socklink->link->fromnode = reroute_node; + socklink->link->fromsock = reroute_node->outputs.first; + } + else { + socklink->link->tonode = reroute_node; + socklink->link->tosock = reroute_node->inputs.first; + } + + add_v2_v2(insert_point, socklink->point); + num_links++; + } + socklink = socklink->next; + } + + if (num_links > 0) { + /* average cut point from shared links */ + mul_v2_fl(insert_point, 1.0f / num_links); + + reroute_node->locx = insert_point[0] / UI_DPI_FAC; + reroute_node->locy = insert_point[1] / UI_DPI_FAC; + } + + return socklink; } static int add_reroute_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - bNodeTree *ntree = snode->edittree; - float mcoords[256][2]; - int i = 0; - - /* Get the cut path */ - RNA_BEGIN (op->ptr, itemptr, "path") - { - float loc[2]; - - RNA_float_get_array(&itemptr, "loc", loc); - UI_view2d_region_to_view(&ar->v2d, (short)loc[0], (short)loc[1], - &mcoords[i][0], &mcoords[i][1]); - i++; - if (i >= 256) { - break; - } - } - RNA_END; - - if (i > 1) { - ListBase output_links, input_links; - bNodeLink *link; - bNodeSocketLink *socklink; - float insert_point[2]; - - /* always first */ - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - - node_deselect_all(snode); - - /* Find cut links and sort them by sockets */ - BLI_listbase_clear(&output_links); - BLI_listbase_clear(&input_links); - - for (link = ntree->links.first; link; link = link->next) { - if (nodeLinkIsHidden(link)) { - continue; - } - if (add_reroute_intersect_check(link, mcoords, i, insert_point)) { - add_reroute_insert_socket_link(&output_links, link->fromsock, link, insert_point); - add_reroute_insert_socket_link(&input_links, link->tosock, link, insert_point); - - /* Clear flag */ - link->flag &= ~NODE_LINK_TEST; - } - } - - /* Create reroute nodes for intersected links. - * Only one reroute if links share the same input/output socket. - */ - socklink = output_links.first; - while (socklink) { - socklink = add_reroute_do_socket_section(C, socklink, SOCK_OUT); - } - socklink = input_links.first; - while (socklink) { - socklink = add_reroute_do_socket_section(C, socklink, SOCK_IN); - } - - BLI_freelistN(&output_links); - BLI_freelistN(&input_links); - - /* always last */ - ntreeUpdateTree(CTX_data_main(C), ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; - } - - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + bNodeTree *ntree = snode->edittree; + float mcoords[256][2]; + int i = 0; + + /* Get the cut path */ + RNA_BEGIN (op->ptr, itemptr, "path") { + float loc[2]; + + RNA_float_get_array(&itemptr, "loc", loc); + UI_view2d_region_to_view( + &ar->v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]); + i++; + if (i >= 256) { + break; + } + } + RNA_END; + + if (i > 1) { + ListBase output_links, input_links; + bNodeLink *link; + bNodeSocketLink *socklink; + float insert_point[2]; + + /* always first */ + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + + node_deselect_all(snode); + + /* Find cut links and sort them by sockets */ + BLI_listbase_clear(&output_links); + BLI_listbase_clear(&input_links); + + for (link = ntree->links.first; link; link = link->next) { + if (nodeLinkIsHidden(link)) { + continue; + } + if (add_reroute_intersect_check(link, mcoords, i, insert_point)) { + add_reroute_insert_socket_link(&output_links, link->fromsock, link, insert_point); + add_reroute_insert_socket_link(&input_links, link->tosock, link, insert_point); + + /* Clear flag */ + link->flag &= ~NODE_LINK_TEST; + } + } + + /* Create reroute nodes for intersected links. + * Only one reroute if links share the same input/output socket. + */ + socklink = output_links.first; + while (socklink) { + socklink = add_reroute_do_socket_section(C, socklink, SOCK_OUT); + } + socklink = input_links.first; + while (socklink) { + socklink = add_reroute_do_socket_section(C, socklink, SOCK_IN); + } + + BLI_freelistN(&output_links); + BLI_freelistN(&input_links); + + /* always last */ + ntreeUpdateTree(CTX_data_main(C), ntree); + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; + } + + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; } void NODE_OT_add_reroute(wmOperatorType *ot) { - ot->name = "Add Reroute"; - ot->idname = "NODE_OT_add_reroute"; - ot->description = "Add a reroute node"; - - ot->invoke = WM_gesture_lines_invoke; - ot->modal = WM_gesture_lines_modal; - ot->exec = add_reroute_exec; - ot->cancel = WM_gesture_lines_cancel; - - ot->poll = ED_operator_node_editable; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - PropertyRNA *prop; - prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", ""); - RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); - /* internal */ - RNA_def_int(ot->srna, "cursor", BC_CROSSCURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); + ot->name = "Add Reroute"; + ot->idname = "NODE_OT_add_reroute"; + ot->description = "Add a reroute node"; + + ot->invoke = WM_gesture_lines_invoke; + ot->modal = WM_gesture_lines_modal; + ot->exec = add_reroute_exec; + ot->cancel = WM_gesture_lines_cancel; + + ot->poll = ED_operator_node_editable; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + PropertyRNA *prop; + prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", ""); + RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); + /* internal */ + RNA_def_int(ot->srna, "cursor", BC_CROSSCURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); } - /* ****************** Add File Node Operator ******************* */ static int node_add_file_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - Image *ima; - int type = 0; - - ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM); - if (!ima) { - return OPERATOR_CANCELLED; - } - - switch (snode->nodetree->type) { - case NTREE_SHADER: - type = SH_NODE_TEX_IMAGE; - break; - case NTREE_TEXTURE: - type = TEX_NODE_IMAGE; - break; - case NTREE_COMPOSIT: - type = CMP_NODE_IMAGE; - break; - default: - return OPERATOR_CANCELLED; - } - - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - - node = node_add_node(C, NULL, type, snode->cursor[0], snode->cursor[1]); - - if (!node) { - BKE_report(op->reports, RPT_WARNING, "Could not add an image node"); - return OPERATOR_CANCELLED; - } - - node->id = (ID *)ima; - - /* When adding new image file via drag-drop we need to load imbuf in order - * to get proper image source. - */ - if (RNA_struct_property_is_set(op->ptr, "filepath")) { - BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_RELOAD); - WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima); - } - - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + Image *ima; + int type = 0; + + ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM); + if (!ima) { + return OPERATOR_CANCELLED; + } + + switch (snode->nodetree->type) { + case NTREE_SHADER: + type = SH_NODE_TEX_IMAGE; + break; + case NTREE_TEXTURE: + type = TEX_NODE_IMAGE; + break; + case NTREE_COMPOSIT: + type = CMP_NODE_IMAGE; + break; + default: + return OPERATOR_CANCELLED; + } + + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + + node = node_add_node(C, NULL, type, snode->cursor[0], snode->cursor[1]); + + if (!node) { + BKE_report(op->reports, RPT_WARNING, "Could not add an image node"); + return OPERATOR_CANCELLED; + } + + node->id = (ID *)ima; + + /* When adding new image file via drag-drop we need to load imbuf in order + * to get proper image source. + */ + if (RNA_struct_property_is_set(op->ptr, "filepath")) { + BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_RELOAD); + WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima); + } + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; } static int node_add_file_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - ARegion *ar = CTX_wm_region(C); - SpaceNode *snode = CTX_wm_space_node(C); - - /* convert mouse coordinates to v2d space */ - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &snode->cursor[0], &snode->cursor[1]); - - snode->cursor[0] /= UI_DPI_FAC; - snode->cursor[1] /= UI_DPI_FAC; - - if (RNA_struct_property_is_set(op->ptr, "filepath") || RNA_struct_property_is_set(op->ptr, "name")) { - return node_add_file_exec(C, op); - } - else { - return WM_operator_filesel(C, op, event); - } + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + + /* convert mouse coordinates to v2d space */ + UI_view2d_region_to_view( + &ar->v2d, event->mval[0], event->mval[1], &snode->cursor[0], &snode->cursor[1]); + + snode->cursor[0] /= UI_DPI_FAC; + snode->cursor[1] /= UI_DPI_FAC; + + if (RNA_struct_property_is_set(op->ptr, "filepath") || + RNA_struct_property_is_set(op->ptr, "name")) { + return node_add_file_exec(C, op); + } + else { + return WM_operator_filesel(C, op, event); + } } void NODE_OT_add_file(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Add File Node"; - ot->description = "Add a file node to the current node editor"; - ot->idname = "NODE_OT_add_file"; - - /* callbacks */ - ot->exec = node_add_file_exec; - ot->invoke = node_add_file_invoke; - ot->poll = ED_operator_node_editable; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - WM_operator_properties_filesel( - ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, FILE_SPECIAL, FILE_OPENFILE, - WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); - RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); + /* identifiers */ + ot->name = "Add File Node"; + ot->description = "Add a file node to the current node editor"; + ot->idname = "NODE_OT_add_file"; + + /* callbacks */ + ot->exec = node_add_file_exec; + ot->invoke = node_add_file_invoke; + ot->poll = ED_operator_node_editable; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + WM_operator_properties_filesel(ot, + FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, + FILE_SPECIAL, + FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); + RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); } /* ****************** Add Mask Node Operator ******************* */ static bool node_add_mask_poll(bContext *C) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - return ED_operator_node_editable(C) && snode->nodetree->type == NTREE_COMPOSIT; + return ED_operator_node_editable(C) && snode->nodetree->type == NTREE_COMPOSIT; } static int node_add_mask_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - ID *mask = NULL; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + ID *mask = NULL; - /* check input variables */ - char name[MAX_ID_NAME - 2]; - RNA_string_get(op->ptr, "name", name); - mask = BKE_libblock_find_name(bmain, ID_MSK, name); - if (!mask) { - BKE_reportf(op->reports, RPT_ERROR, "Mask '%s' not found", name); - return OPERATOR_CANCELLED; - } + /* check input variables */ + char name[MAX_ID_NAME - 2]; + RNA_string_get(op->ptr, "name", name); + mask = BKE_libblock_find_name(bmain, ID_MSK, name); + if (!mask) { + BKE_reportf(op->reports, RPT_ERROR, "Mask '%s' not found", name); + return OPERATOR_CANCELLED; + } - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - node = node_add_node(C, NULL, CMP_NODE_MASK, snode->cursor[0], snode->cursor[1]); + node = node_add_node(C, NULL, CMP_NODE_MASK, snode->cursor[0], snode->cursor[1]); - if (!node) { - BKE_report(op->reports, RPT_WARNING, "Could not add a mask node"); - return OPERATOR_CANCELLED; - } + if (!node) { + BKE_report(op->reports, RPT_WARNING, "Could not add a mask node"); + return OPERATOR_CANCELLED; + } - node->id = mask; - id_us_plus(mask); + node->id = mask; + id_us_plus(mask); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(C, snode); + snode_dag_update(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_add_mask(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Add Mask Node"; - ot->description = "Add a mask node to the current node editor"; - ot->idname = "NODE_OT_add_mask"; + /* identifiers */ + ot->name = "Add Mask Node"; + ot->description = "Add a mask node to the current node editor"; + ot->idname = "NODE_OT_add_mask"; - /* callbacks */ - ot->exec = node_add_mask_exec; - ot->poll = node_add_mask_poll; + /* callbacks */ + ot->exec = node_add_mask_exec; + ot->poll = node_add_mask_poll; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; - RNA_def_string(ot->srna, "name", "Mask", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); + RNA_def_string(ot->srna, "name", "Mask", MAX_ID_NAME - 2, "Name", "Data-block name to assign"); } /********************** New node tree operator *********************/ static int new_node_tree_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - Main *bmain = CTX_data_main(C); - bNodeTree *ntree; - PointerRNA ptr, idptr; - PropertyRNA *prop; - const char *idname; - char treename_buf[MAX_ID_NAME - 2]; - const char *treename; - - if (RNA_struct_property_is_set(op->ptr, "type")) { - prop = RNA_struct_find_property(op->ptr, "type"); - RNA_property_enum_identifier(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &idname); - } - else if (snode) { - idname = snode->tree_idname; - } - else { - return OPERATOR_CANCELLED; - } - - if (RNA_struct_property_is_set(op->ptr, "name")) { - RNA_string_get(op->ptr, "name", treename_buf); - treename = treename_buf; - } - else { - treename = DATA_("NodeTree"); - } - - if (!ntreeTypeFind(idname)) { - BKE_reportf(op->reports, RPT_ERROR, "Node tree type %s undefined", idname); - return OPERATOR_CANCELLED; - } - - ntree = ntreeAddTree(bmain, treename, idname); - - /* hook into UI */ - UI_context_active_but_prop_get_templateID(C, &ptr, &prop); - - if (prop) { - /* RNA_property_pointer_set increases the user count, - * fixed here as the editor is the initial user. - */ - id_us_min(&ntree->id); - - RNA_id_pointer_create(&ntree->id, &idptr); - RNA_property_pointer_set(&ptr, prop, idptr); - RNA_property_update(C, &ptr, prop); - } - else if (snode) { - snode->nodetree = ntree; - - ED_node_tree_update(C); - } - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + Main *bmain = CTX_data_main(C); + bNodeTree *ntree; + PointerRNA ptr, idptr; + PropertyRNA *prop; + const char *idname; + char treename_buf[MAX_ID_NAME - 2]; + const char *treename; + + if (RNA_struct_property_is_set(op->ptr, "type")) { + prop = RNA_struct_find_property(op->ptr, "type"); + RNA_property_enum_identifier(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &idname); + } + else if (snode) { + idname = snode->tree_idname; + } + else { + return OPERATOR_CANCELLED; + } + + if (RNA_struct_property_is_set(op->ptr, "name")) { + RNA_string_get(op->ptr, "name", treename_buf); + treename = treename_buf; + } + else { + treename = DATA_("NodeTree"); + } + + if (!ntreeTypeFind(idname)) { + BKE_reportf(op->reports, RPT_ERROR, "Node tree type %s undefined", idname); + return OPERATOR_CANCELLED; + } + + ntree = ntreeAddTree(bmain, treename, idname); + + /* hook into UI */ + UI_context_active_but_prop_get_templateID(C, &ptr, &prop); + + if (prop) { + /* RNA_property_pointer_set increases the user count, + * fixed here as the editor is the initial user. + */ + id_us_min(&ntree->id); + + RNA_id_pointer_create(&ntree->id, &idptr); + RNA_property_pointer_set(&ptr, prop, idptr); + RNA_property_update(C, &ptr, prop); + } + else if (snode) { + snode->nodetree = ntree; + + ED_node_tree_update(C); + } + + return OPERATOR_FINISHED; } -static const EnumPropertyItem *new_node_tree_type_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) +static const EnumPropertyItem *new_node_tree_type_itemf(bContext *UNUSED(C), + PointerRNA *UNUSED(ptr), + PropertyRNA *UNUSED(prop), + bool *r_free) { - return rna_node_tree_type_itemf(NULL, NULL, r_free); + return rna_node_tree_type_itemf(NULL, NULL, r_free); } void NODE_OT_new_node_tree(wmOperatorType *ot) { - PropertyRNA *prop; + PropertyRNA *prop; - /* identifiers */ - ot->name = "New Node Tree"; - ot->idname = "NODE_OT_new_node_tree"; - ot->description = "Create a new node tree"; + /* identifiers */ + ot->name = "New Node Tree"; + ot->idname = "NODE_OT_new_node_tree"; + ot->description = "Create a new node tree"; - /* api callbacks */ - ot->exec = new_node_tree_exec; + /* api callbacks */ + ot->exec = new_node_tree_exec; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Tree Type", ""); - RNA_def_enum_funcs(prop, new_node_tree_type_itemf); - RNA_def_string(ot->srna, "name", "NodeTree", MAX_ID_NAME - 2, "Name", ""); + prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Tree Type", ""); + RNA_def_enum_funcs(prop, new_node_tree_type_itemf); + RNA_def_string(ot->srna, "name", "NodeTree", MAX_ID_NAME - 2, "Name", ""); } diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c index 13f8eb0729e..63e97ecd955 100644 --- a/source/blender/editors/space_node/node_buttons.c +++ b/source/blender/editors/space_node/node_buttons.c @@ -45,8 +45,7 @@ #include "UI_resources.h" -#include "node_intern.h" /* own include */ - +#include "node_intern.h" /* own include */ /* ******************* node space & buttons ************** */ @@ -54,181 +53,208 @@ /* poll for active nodetree */ static bool active_nodetree_poll(const bContext *C, PanelType *UNUSED(pt)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - return (snode && snode->nodetree); + return (snode && snode->nodetree); } #endif static bool node_sockets_poll(const bContext *C, PanelType *UNUSED(pt)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - return (snode && snode->nodetree && G.debug_value == 777); + return (snode && snode->nodetree && G.debug_value == 777); } static void node_sockets_panel(const bContext *C, Panel *pa) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = (snode) ? snode->edittree : NULL; - bNode *node = (ntree) ? nodeGetActive(ntree) : NULL; - bNodeSocket *sock; - uiLayout *layout = pa->layout, *split; - char name[UI_MAX_NAME_STR]; - - if (ELEM(NULL, ntree, node)) { - return; - } - - for (sock = node->inputs.first; sock; sock = sock->next) { - BLI_snprintf(name, sizeof(name), "%s:", sock->name); - - split = uiLayoutSplit(layout, 0.35f, false); - uiItemL(split, name, ICON_NONE); - uiTemplateNodeLink(split, ntree, node, sock); - } + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = (snode) ? snode->edittree : NULL; + bNode *node = (ntree) ? nodeGetActive(ntree) : NULL; + bNodeSocket *sock; + uiLayout *layout = pa->layout, *split; + char name[UI_MAX_NAME_STR]; + + if (ELEM(NULL, ntree, node)) { + return; + } + + for (sock = node->inputs.first; sock; sock = sock->next) { + BLI_snprintf(name, sizeof(name), "%s:", sock->name); + + split = uiLayoutSplit(layout, 0.35f, false); + uiItemL(split, name, ICON_NONE); + uiTemplateNodeLink(split, ntree, node, sock); + } } static bool node_tree_interface_poll(const bContext *C, PanelType *UNUSED(pt)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - return (snode && snode->edittree && (snode->edittree->inputs.first || snode->edittree->outputs.first)); + return (snode && snode->edittree && + (snode->edittree->inputs.first || snode->edittree->outputs.first)); } static bool node_tree_find_active_socket(bNodeTree *ntree, bNodeSocket **r_sock, int *r_in_out) { - bNodeSocket *sock; - for (sock = ntree->inputs.first; sock; sock = sock->next) { - if (sock->flag & SELECT) { - *r_sock = sock; - *r_in_out = SOCK_IN; - return true; - } - } - for (sock = ntree->outputs.first; sock; sock = sock->next) { - if (sock->flag & SELECT) { - *r_sock = sock; - *r_in_out = SOCK_OUT; - return true; - } - } - - *r_sock = NULL; - *r_in_out = 0; - return false; + bNodeSocket *sock; + for (sock = ntree->inputs.first; sock; sock = sock->next) { + if (sock->flag & SELECT) { + *r_sock = sock; + *r_in_out = SOCK_IN; + return true; + } + } + for (sock = ntree->outputs.first; sock; sock = sock->next) { + if (sock->flag & SELECT) { + *r_sock = sock; + *r_in_out = SOCK_OUT; + return true; + } + } + + *r_sock = NULL; + *r_in_out = 0; + return false; } static void node_tree_interface_panel(const bContext *C, Panel *pa) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = (snode) ? snode->edittree : NULL; - bNodeSocket *sock; - int in_out; - uiLayout *layout = pa->layout, *row, *split, *col; - PointerRNA ptr, sockptr, opptr; - wmOperatorType *ot; - - if (!ntree) { - return; - } - - RNA_id_pointer_create((ID *)ntree, &ptr); - - node_tree_find_active_socket(ntree, &sock, &in_out); - RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, sock, &sockptr); - - row = uiLayoutRow(layout, false); - - split = uiLayoutRow(row, true); - col = uiLayoutColumn(split, true); - ot = WM_operatortype_find("NODE_OT_tree_socket_add", false); - uiItemL(col, IFACE_("Inputs:"), ICON_NONE); - uiTemplateList(col, (bContext *)C, "NODE_UL_interface_sockets", "inputs", &ptr, "inputs", &ptr, "active_input", - NULL, 0, 0, 0, 0, false, false); - uiItemFullO_ptr(col, ot, "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr); - RNA_enum_set(&opptr, "in_out", SOCK_IN); - - col = uiLayoutColumn(split, true); - uiItemL(col, IFACE_("Outputs:"), ICON_NONE); - uiTemplateList(col, (bContext *)C, "NODE_UL_interface_sockets", "outputs", &ptr, "outputs", &ptr, "active_output", - NULL, 0, 0, 0, 0, false, false); - uiItemFullO_ptr(col, ot, "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr); - RNA_enum_set(&opptr, "in_out", SOCK_OUT); - - ot = WM_operatortype_find("NODE_OT_tree_socket_move", false); - col = uiLayoutColumn(row, true); - uiItemFullO_ptr(col, ot, "", ICON_TRIA_UP, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr); - RNA_enum_set(&opptr, "direction", 1); - uiItemFullO_ptr(col, ot, "", ICON_TRIA_DOWN, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr); - RNA_enum_set(&opptr, "direction", 2); - - if (sock) { - row = uiLayoutRow(layout, true); - uiItemR(row, &sockptr, "name", 0, NULL, ICON_NONE); - uiItemO(row, "", ICON_X, "NODE_OT_tree_socket_remove"); - - if (sock->typeinfo->interface_draw) { - uiItemS(layout); - sock->typeinfo->interface_draw((bContext *)C, layout, &sockptr); - } - } + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = (snode) ? snode->edittree : NULL; + bNodeSocket *sock; + int in_out; + uiLayout *layout = pa->layout, *row, *split, *col; + PointerRNA ptr, sockptr, opptr; + wmOperatorType *ot; + + if (!ntree) { + return; + } + + RNA_id_pointer_create((ID *)ntree, &ptr); + + node_tree_find_active_socket(ntree, &sock, &in_out); + RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, sock, &sockptr); + + row = uiLayoutRow(layout, false); + + split = uiLayoutRow(row, true); + col = uiLayoutColumn(split, true); + ot = WM_operatortype_find("NODE_OT_tree_socket_add", false); + uiItemL(col, IFACE_("Inputs:"), ICON_NONE); + uiTemplateList(col, + (bContext *)C, + "NODE_UL_interface_sockets", + "inputs", + &ptr, + "inputs", + &ptr, + "active_input", + NULL, + 0, + 0, + 0, + 0, + false, + false); + uiItemFullO_ptr(col, ot, "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr); + RNA_enum_set(&opptr, "in_out", SOCK_IN); + + col = uiLayoutColumn(split, true); + uiItemL(col, IFACE_("Outputs:"), ICON_NONE); + uiTemplateList(col, + (bContext *)C, + "NODE_UL_interface_sockets", + "outputs", + &ptr, + "outputs", + &ptr, + "active_output", + NULL, + 0, + 0, + 0, + 0, + false, + false); + uiItemFullO_ptr(col, ot, "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr); + RNA_enum_set(&opptr, "in_out", SOCK_OUT); + + ot = WM_operatortype_find("NODE_OT_tree_socket_move", false); + col = uiLayoutColumn(row, true); + uiItemFullO_ptr(col, ot, "", ICON_TRIA_UP, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr); + RNA_enum_set(&opptr, "direction", 1); + uiItemFullO_ptr(col, ot, "", ICON_TRIA_DOWN, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr); + RNA_enum_set(&opptr, "direction", 2); + + if (sock) { + row = uiLayoutRow(layout, true); + uiItemR(row, &sockptr, "name", 0, NULL, ICON_NONE); + uiItemO(row, "", ICON_X, "NODE_OT_tree_socket_remove"); + + if (sock->typeinfo->interface_draw) { + uiItemS(layout); + sock->typeinfo->interface_draw((bContext *)C, layout, &sockptr); + } + } } /* ******************* node buttons registration ************** */ void node_buttons_register(ARegionType *art) { - PanelType *pt; - - pt = MEM_callocN(sizeof(PanelType), "spacetype node panel node sockets"); - strcpy(pt->idname, "NODE_PT_sockets"); - strcpy(pt->category, N_("Node")); - strcpy(pt->label, N_("Sockets")); - strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); - pt->draw = node_sockets_panel; - pt->poll = node_sockets_poll; - pt->flag |= PNL_DEFAULT_CLOSED; - BLI_addtail(&art->paneltypes, pt); - - pt = MEM_callocN(sizeof(PanelType), "spacetype node panel tree interface"); - strcpy(pt->idname, "NODE_PT_node_tree_interface"); - strcpy(pt->category, N_("Node")); - strcpy(pt->label, N_("Interface")); - strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); - pt->draw = node_tree_interface_panel; - pt->poll = node_tree_interface_poll; - BLI_addtail(&art->paneltypes, pt); + PanelType *pt; + + pt = MEM_callocN(sizeof(PanelType), "spacetype node panel node sockets"); + strcpy(pt->idname, "NODE_PT_sockets"); + strcpy(pt->category, N_("Node")); + strcpy(pt->label, N_("Sockets")); + strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); + pt->draw = node_sockets_panel; + pt->poll = node_sockets_poll; + pt->flag |= PNL_DEFAULT_CLOSED; + BLI_addtail(&art->paneltypes, pt); + + pt = MEM_callocN(sizeof(PanelType), "spacetype node panel tree interface"); + strcpy(pt->idname, "NODE_PT_node_tree_interface"); + strcpy(pt->category, N_("Node")); + strcpy(pt->label, N_("Interface")); + strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); + pt->draw = node_tree_interface_panel; + pt->poll = node_tree_interface_poll; + BLI_addtail(&art->paneltypes, pt); } static int node_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = node_has_buttons_region(sa); + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = node_has_buttons_region(sa); - if (ar) { - ED_region_toggle_hidden(C, ar); - } + if (ar) { + ED_region_toggle_hidden(C, ar); + } - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } /* non-standard poll operator which doesn't care if there are any nodes */ static bool node_properties_poll(bContext *C) { - ScrArea *sa = CTX_wm_area(C); - return (sa && (sa->spacetype == SPACE_NODE)); + ScrArea *sa = CTX_wm_area(C); + return (sa && (sa->spacetype == SPACE_NODE)); } void NODE_OT_properties(wmOperatorType *ot) { - ot->name = "Toggle Sidebar"; - ot->description = "Toggle the properties region visibility"; - ot->idname = "NODE_OT_properties"; + ot->name = "Toggle Sidebar"; + ot->description = "Toggle the properties region visibility"; + ot->idname = "NODE_OT_properties"; - ot->exec = node_properties_toggle_exec; - ot->poll = node_properties_poll; + ot->exec = node_properties_toggle_exec; + ot->poll = node_properties_poll; - /* flags */ - ot->flag = 0; + /* flags */ + ot->flag = 0; } diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 6f7ebd36c09..a694ac2c38b 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -66,181 +66,183 @@ #include "RNA_access.h" -#include "node_intern.h" /* own include */ +#include "node_intern.h" /* own include */ #ifdef WITH_COMPOSITOR # include "COM_compositor.h" #endif /* XXX interface.h */ -extern void ui_draw_dropshadow(const rctf *rct, float radius, float aspect, float alpha, int select); +extern void ui_draw_dropshadow( + const rctf *rct, float radius, float aspect, float alpha, int select); float ED_node_grid_size(void) { - return U.widget_unit; + return U.widget_unit; } void ED_node_tree_update(const bContext *C) { - SpaceNode *snode = CTX_wm_space_node(C); - if (snode) { - snode_set_context(C); + SpaceNode *snode = CTX_wm_space_node(C); + if (snode) { + snode_set_context(C); - id_us_ensure_real(&snode->nodetree->id); - } + id_us_ensure_real(&snode->nodetree->id); + } } /* id is supposed to contain a node tree */ static bNodeTree *node_tree_from_ID(ID *id) { - if (id) { - short idtype = GS(id->name); - - switch (idtype) { - case ID_NT: - return (bNodeTree *)id; - case ID_MA: - return ((Material *)id)->nodetree; - case ID_LA: - return ((Light *)id)->nodetree; - case ID_WO: - return ((World *)id)->nodetree; - case ID_SCE: - return ((Scene *)id)->nodetree; - case ID_TE: - return ((Tex *)id)->nodetree; - case ID_LS: - return ((FreestyleLineStyle *)id)->nodetree; - } - } - - return NULL; + if (id) { + short idtype = GS(id->name); + + switch (idtype) { + case ID_NT: + return (bNodeTree *)id; + case ID_MA: + return ((Material *)id)->nodetree; + case ID_LA: + return ((Light *)id)->nodetree; + case ID_WO: + return ((World *)id)->nodetree; + case ID_SCE: + return ((Scene *)id)->nodetree; + case ID_TE: + return ((Tex *)id)->nodetree; + case ID_LS: + return ((FreestyleLineStyle *)id)->nodetree; + } + } + + return NULL; } void ED_node_tag_update_id(ID *id) { - bNodeTree *ntree = node_tree_from_ID(id); - if (id == NULL || ntree == NULL) { - return; - } - - /* TODO(sergey): With the new dependency graph it - * should be just enough to only tag ntree itself, - * all the users of this tree will have update - * flushed from the tree, - */ - DEG_id_tag_update(&ntree->id, 0); - - if (ntree->type == NTREE_SHADER) { - DEG_id_tag_update(id, 0); - - if (GS(id->name) == ID_MA) { - WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id); - } - else if (GS(id->name) == ID_LA) { - WM_main_add_notifier(NC_LAMP | ND_LIGHTING, id); - } - else if (GS(id->name) == ID_WO) { - WM_main_add_notifier(NC_WORLD | ND_WORLD, id); - } - } - else if (ntree->type == NTREE_COMPOSIT) { - WM_main_add_notifier(NC_SCENE | ND_NODES, id); - } - else if (ntree->type == NTREE_TEXTURE) { - DEG_id_tag_update(id, 0); - WM_main_add_notifier(NC_TEXTURE | ND_NODES, id); - } - else if (id == &ntree->id) { - /* node groups */ - DEG_id_tag_update(id, 0); - } + bNodeTree *ntree = node_tree_from_ID(id); + if (id == NULL || ntree == NULL) { + return; + } + + /* TODO(sergey): With the new dependency graph it + * should be just enough to only tag ntree itself, + * all the users of this tree will have update + * flushed from the tree, + */ + DEG_id_tag_update(&ntree->id, 0); + + if (ntree->type == NTREE_SHADER) { + DEG_id_tag_update(id, 0); + + if (GS(id->name) == ID_MA) { + WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id); + } + else if (GS(id->name) == ID_LA) { + WM_main_add_notifier(NC_LAMP | ND_LIGHTING, id); + } + else if (GS(id->name) == ID_WO) { + WM_main_add_notifier(NC_WORLD | ND_WORLD, id); + } + } + else if (ntree->type == NTREE_COMPOSIT) { + WM_main_add_notifier(NC_SCENE | ND_NODES, id); + } + else if (ntree->type == NTREE_TEXTURE) { + DEG_id_tag_update(id, 0); + WM_main_add_notifier(NC_TEXTURE | ND_NODES, id); + } + else if (id == &ntree->id) { + /* node groups */ + DEG_id_tag_update(id, 0); + } } void ED_node_tag_update_nodetree(Main *bmain, bNodeTree *ntree, bNode *node) { - if (!ntree) { - return; - } - - bool do_tag_update = true; - if (node != NULL) { - if (!node_connected_to_output(bmain, ntree, node)) { - do_tag_update = false; - } - } - - /* look through all datablocks, to support groups */ - if (do_tag_update) { - FOREACH_NODETREE_BEGIN(bmain, tntree, id) { - /* check if nodetree uses the group */ - if (ntreeHasTree(tntree, ntree)) { - ED_node_tag_update_id(id); - } - } FOREACH_NODETREE_END; - } - - if (ntree->type == NTREE_TEXTURE) { - ntreeTexCheckCyclics(ntree); - } + if (!ntree) { + return; + } + + bool do_tag_update = true; + if (node != NULL) { + if (!node_connected_to_output(bmain, ntree, node)) { + do_tag_update = false; + } + } + + /* look through all datablocks, to support groups */ + if (do_tag_update) { + FOREACH_NODETREE_BEGIN (bmain, tntree, id) { + /* check if nodetree uses the group */ + if (ntreeHasTree(tntree, ntree)) { + ED_node_tag_update_id(id); + } + } + FOREACH_NODETREE_END; + } + + if (ntree->type == NTREE_TEXTURE) { + ntreeTexCheckCyclics(ntree); + } } static bool compare_nodes(const bNode *a, const bNode *b) { - bNode *parent; - /* These tell if either the node or any of the parent nodes is selected. - * A selected parent means an unselected node is also in foreground! - */ - bool a_select = (a->flag & NODE_SELECT) != 0, b_select = (b->flag & NODE_SELECT) != 0; - bool a_active = (a->flag & NODE_ACTIVE) != 0, b_active = (b->flag & NODE_ACTIVE) != 0; - - /* if one is an ancestor of the other */ - /* XXX there might be a better sorting algorithm for stable topological sort, - * this is O(n^2) worst case */ - for (parent = a->parent; parent; parent = parent->parent) { - /* if b is an ancestor, it is always behind a */ - if (parent == b) { - return 1; - } - /* any selected ancestor moves the node forward */ - if (parent->flag & NODE_ACTIVE) { - a_active = 1; - } - if (parent->flag & NODE_SELECT) { - a_select = 1; - } - } - for (parent = b->parent; parent; parent = parent->parent) { - /* if a is an ancestor, it is always behind b */ - if (parent == a) { - return 0; - } - /* any selected ancestor moves the node forward */ - if (parent->flag & NODE_ACTIVE) { - b_active = 1; - } - if (parent->flag & NODE_SELECT) { - b_select = 1; - } - } - - /* if one of the nodes is in the background and the other not */ - if ((a->flag & NODE_BACKGROUND) && !(b->flag & NODE_BACKGROUND)) { - return 0; - } - else if (!(a->flag & NODE_BACKGROUND) && (b->flag & NODE_BACKGROUND)) { - return 1; - } - - /* if one has a higher selection state (active > selected > nothing) */ - if (!b_active && a_active) { - return 1; - } - else if (!b_select && (a_active || a_select)) { - return 1; - } - - return 0; + bNode *parent; + /* These tell if either the node or any of the parent nodes is selected. + * A selected parent means an unselected node is also in foreground! + */ + bool a_select = (a->flag & NODE_SELECT) != 0, b_select = (b->flag & NODE_SELECT) != 0; + bool a_active = (a->flag & NODE_ACTIVE) != 0, b_active = (b->flag & NODE_ACTIVE) != 0; + + /* if one is an ancestor of the other */ + /* XXX there might be a better sorting algorithm for stable topological sort, + * this is O(n^2) worst case */ + for (parent = a->parent; parent; parent = parent->parent) { + /* if b is an ancestor, it is always behind a */ + if (parent == b) { + return 1; + } + /* any selected ancestor moves the node forward */ + if (parent->flag & NODE_ACTIVE) { + a_active = 1; + } + if (parent->flag & NODE_SELECT) { + a_select = 1; + } + } + for (parent = b->parent; parent; parent = parent->parent) { + /* if a is an ancestor, it is always behind b */ + if (parent == a) { + return 0; + } + /* any selected ancestor moves the node forward */ + if (parent->flag & NODE_ACTIVE) { + b_active = 1; + } + if (parent->flag & NODE_SELECT) { + b_select = 1; + } + } + + /* if one of the nodes is in the background and the other not */ + if ((a->flag & NODE_BACKGROUND) && !(b->flag & NODE_BACKGROUND)) { + return 0; + } + else if (!(a->flag & NODE_BACKGROUND) && (b->flag & NODE_BACKGROUND)) { + return 1; + } + + /* if one has a higher selection state (active > selected > nothing) */ + if (!b_active && a_active) { + return 1; + } + else if (!b_select && (a_active || a_select)) { + return 1; + } + + return 0; } /* Sorts nodes by selection: unselected nodes first, then selected, @@ -248,418 +250,451 @@ static bool compare_nodes(const bNode *a, const bNode *b) */ void ED_node_sort(bNodeTree *ntree) { - /* merge sort is the algorithm of choice here */ - bNode *first_a, *first_b, *node_a, *node_b, *tmp; - int totnodes = BLI_listbase_count(&ntree->nodes); - int k, a, b; - - k = 1; - while (k < totnodes) { - first_a = first_b = ntree->nodes.first; - - do { - /* setup first_b pointer */ - for (b = 0; b < k && first_b; ++b) { - first_b = first_b->next; - } - /* all batches merged? */ - if (first_b == NULL) { - break; - } - - /* merge batches */ - node_a = first_a; - node_b = first_b; - a = b = 0; - while (a < k && b < k && node_b) { - if (compare_nodes(node_a, node_b) == 0) { - node_a = node_a->next; - a++; - } - else { - tmp = node_b; - node_b = node_b->next; - b++; - BLI_remlink(&ntree->nodes, tmp); - BLI_insertlinkbefore(&ntree->nodes, node_a, tmp); - } - } - - /* setup first pointers for next batch */ - first_b = node_b; - for (; b < k; ++b) { - /* all nodes sorted? */ - if (first_b == NULL) { - break; - } - first_b = first_b->next; - } - first_a = first_b; - } while (first_b); - - k = k << 1; - } + /* merge sort is the algorithm of choice here */ + bNode *first_a, *first_b, *node_a, *node_b, *tmp; + int totnodes = BLI_listbase_count(&ntree->nodes); + int k, a, b; + + k = 1; + while (k < totnodes) { + first_a = first_b = ntree->nodes.first; + + do { + /* setup first_b pointer */ + for (b = 0; b < k && first_b; ++b) { + first_b = first_b->next; + } + /* all batches merged? */ + if (first_b == NULL) { + break; + } + + /* merge batches */ + node_a = first_a; + node_b = first_b; + a = b = 0; + while (a < k && b < k && node_b) { + if (compare_nodes(node_a, node_b) == 0) { + node_a = node_a->next; + a++; + } + else { + tmp = node_b; + node_b = node_b->next; + b++; + BLI_remlink(&ntree->nodes, tmp); + BLI_insertlinkbefore(&ntree->nodes, node_a, tmp); + } + } + + /* setup first pointers for next batch */ + first_b = node_b; + for (; b < k; ++b) { + /* all nodes sorted? */ + if (first_b == NULL) { + break; + } + first_b = first_b->next; + } + first_a = first_b; + } while (first_b); + + k = k << 1; + } } - static void do_node_internal_buttons(bContext *C, void *UNUSED(node_v), int event) { - if (event == B_NODE_EXEC) { - SpaceNode *snode = CTX_wm_space_node(C); - if (snode && snode->id) { - ED_node_tag_update_id(snode->id); - } - } + if (event == B_NODE_EXEC) { + SpaceNode *snode = CTX_wm_space_node(C); + if (snode && snode->id) { + ED_node_tag_update_id(snode->id); + } + } } static void node_uiblocks_init(const bContext *C, bNodeTree *ntree) { - bNode *node; - char uiblockstr[32]; + bNode *node; + char uiblockstr[32]; - /* add node uiBlocks in drawing order - prevents events going to overlapping nodes */ + /* add node uiBlocks in drawing order - prevents events going to overlapping nodes */ - for (node = ntree->nodes.first; node; node = node->next) { - /* ui block */ - BLI_snprintf(uiblockstr, sizeof(uiblockstr), "node buttons %p", (void *)node); - node->block = UI_block_begin(C, CTX_wm_region(C), uiblockstr, UI_EMBOSS); - UI_block_func_handle_set(node->block, do_node_internal_buttons, node); + for (node = ntree->nodes.first; node; node = node->next) { + /* ui block */ + BLI_snprintf(uiblockstr, sizeof(uiblockstr), "node buttons %p", (void *)node); + node->block = UI_block_begin(C, CTX_wm_region(C), uiblockstr, UI_EMBOSS); + UI_block_func_handle_set(node->block, do_node_internal_buttons, node); - /* this cancels events for background nodes */ - UI_block_flag_enable(node->block, UI_BLOCK_CLIP_EVENTS); - } + /* this cancels events for background nodes */ + UI_block_flag_enable(node->block, UI_BLOCK_CLIP_EVENTS); + } } void node_to_view(struct bNode *node, float x, float y, float *rx, float *ry) { - nodeToView(node, x, y, rx, ry); - *rx *= UI_DPI_FAC; - *ry *= UI_DPI_FAC; + nodeToView(node, x, y, rx, ry); + *rx *= UI_DPI_FAC; + *ry *= UI_DPI_FAC; } void node_to_updated_rect(struct bNode *node, rctf *r_rect) { - node_to_view(node, node->offsetx, node->offsety, &r_rect->xmin, &r_rect->ymax); - node_to_view(node, node->offsetx + node->width, node->offsety - node->height, &r_rect->xmax, &r_rect->ymin); + node_to_view(node, node->offsetx, node->offsety, &r_rect->xmin, &r_rect->ymax); + node_to_view(node, + node->offsetx + node->width, + node->offsety - node->height, + &r_rect->xmax, + &r_rect->ymin); } void node_from_view(struct bNode *node, float x, float y, float *rx, float *ry) { - x /= UI_DPI_FAC; - y /= UI_DPI_FAC; - nodeFromView(node, x, y, rx, ry); + x /= UI_DPI_FAC; + y /= UI_DPI_FAC; + nodeFromView(node, x, y, rx, ry); } - /* based on settings in node, sets drawing rect info. each redraw! */ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) { - uiLayout *layout, *row; - PointerRNA nodeptr, sockptr; - bNodeSocket *nsock; - float locx, locy; - float dy; - int buty; - - RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr); - - /* get "global" coords */ - node_to_view(node, 0.0f, 0.0f, &locx, &locy); - dy = locy; - - /* header */ - dy -= NODE_DY; - - /* little bit space in top */ - if (node->outputs.first) { - dy -= NODE_DYS / 2; - } - - /* output sockets */ - bool add_output_space = false; - - for (nsock = node->outputs.first; nsock; nsock = nsock->next) { - if (nodeSocketIsHidden(nsock)) { - continue; - } - - RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr); - - layout = UI_block_layout( - node->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, - locx + NODE_DYS, dy, NODE_WIDTH(node) - NODE_DY, NODE_DY, 0, UI_style_get()); - - if (node->flag & NODE_MUTED) { - uiLayoutSetActive(layout, false); - } - - /* context pointers for current node and socket */ - uiLayoutSetContextPointer(layout, "node", &nodeptr); - uiLayoutSetContextPointer(layout, "socket", &sockptr); - - /* align output buttons to the right */ - row = uiLayoutRow(layout, 1); - uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); - - nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(nsock->name)); - - UI_block_align_end(node->block); - UI_block_layout_resolve(node->block, NULL, &buty); - - /* ensure minimum socket height in case layout is empty */ - buty = min_ii(buty, dy - NODE_DY); - - nsock->locx = locx + NODE_WIDTH(node); - /* place the socket circle in the middle of the layout */ - nsock->locy = 0.5f * (dy + buty); - - dy = buty; - if (nsock->next) { - dy -= NODE_SOCKDY; - } - - add_output_space = true; - } - - if (add_output_space) { - dy -= NODE_DY / 4; - } - - node->prvr.xmin = locx + NODE_DYS; - node->prvr.xmax = locx + NODE_WIDTH(node) - NODE_DYS; - - /* preview rect? */ - if (node->flag & NODE_PREVIEW) { - float aspect = 1.0f; - - if (node->preview_xsize && node->preview_ysize) { - aspect = (float)node->preview_ysize / (float)node->preview_xsize; - } - - dy -= NODE_DYS / 2; - node->prvr.ymax = dy; - - if (aspect <= 1.0f) { - node->prvr.ymin = dy - aspect * (NODE_WIDTH(node) - NODE_DY); - } - else { - /* width correction of image */ - /* XXX huh? (ton) */ - float dx = (NODE_WIDTH(node) - NODE_DYS) - (NODE_WIDTH(node) - NODE_DYS) / aspect; + uiLayout *layout, *row; + PointerRNA nodeptr, sockptr; + bNodeSocket *nsock; + float locx, locy; + float dy; + int buty; - node->prvr.ymin = dy - (NODE_WIDTH(node) - NODE_DY); + RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr); - node->prvr.xmin += 0.5f * dx; - node->prvr.xmax -= 0.5f * dx; - } - - dy = node->prvr.ymin - NODE_DYS / 2; - - /* make sure that maximums are bigger or equal to minimums */ - if (node->prvr.xmax < node->prvr.xmin) { - SWAP(float, node->prvr.xmax, node->prvr.xmin); - } - if (node->prvr.ymax < node->prvr.ymin) { - SWAP(float, node->prvr.ymax, node->prvr.ymin); - } - } - - /* buttons rect? */ - if (node->typeinfo->draw_buttons && (node->flag & NODE_OPTIONS)) { - dy -= NODE_DYS / 2; - - /* set this for uifunc() that don't use layout engine yet */ - node->butr.xmin = 0; - node->butr.xmax = NODE_WIDTH(node) - 2 * NODE_DYS; - node->butr.ymin = 0; - node->butr.ymax = 0; - - - layout = UI_block_layout( - node->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, - locx + NODE_DYS, dy, node->butr.xmax, 0, 0, UI_style_get()); - - if (node->flag & NODE_MUTED) { - uiLayoutSetActive(layout, false); - } - - uiLayoutSetContextPointer(layout, "node", &nodeptr); - - node->typeinfo->draw_buttons(layout, (bContext *)C, &nodeptr); - - UI_block_align_end(node->block); - UI_block_layout_resolve(node->block, NULL, &buty); - - dy = buty - NODE_DYS / 2; - } - - /* input sockets */ - for (nsock = node->inputs.first; nsock; nsock = nsock->next) { - if (nodeSocketIsHidden(nsock)) { - continue; - } - - RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr); - - layout = UI_block_layout( - node->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, - locx + NODE_DYS, dy, NODE_WIDTH(node) - NODE_DY, NODE_DY, 0, UI_style_get()); - - if (node->flag & NODE_MUTED) { - uiLayoutSetActive(layout, false); - } - - /* context pointers for current node and socket */ - uiLayoutSetContextPointer(layout, "node", &nodeptr); - uiLayoutSetContextPointer(layout, "socket", &sockptr); - - row = uiLayoutRow(layout, 1); - - nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(nsock->name)); - - UI_block_align_end(node->block); - UI_block_layout_resolve(node->block, NULL, &buty); - - /* ensure minimum socket height in case layout is empty */ - buty = min_ii(buty, dy - NODE_DY); - - nsock->locx = locx; - /* place the socket circle in the middle of the layout */ - nsock->locy = 0.5f * (dy + buty); - - dy = buty; - if (nsock->next) { - dy -= NODE_SOCKDY; - } - } - - /* little bit space in end */ - if (node->inputs.first || (node->flag & (NODE_OPTIONS | NODE_PREVIEW)) == 0) { - dy -= NODE_DYS / 2; - } - - node->totr.xmin = locx; - node->totr.xmax = locx + NODE_WIDTH(node); - node->totr.ymax = locy; - node->totr.ymin = min_ff(dy, locy - 2 * NODE_DY); - - /* Set the block bounds to clip mouse events from underlying nodes. - * Add a margin for sockets on each side. - */ - UI_block_bounds_set_explicit( - node->block, - node->totr.xmin - NODE_SOCKSIZE, - node->totr.ymin, - node->totr.xmax + NODE_SOCKSIZE, - node->totr.ymax); + /* get "global" coords */ + node_to_view(node, 0.0f, 0.0f, &locx, &locy); + dy = locy; + + /* header */ + dy -= NODE_DY; + + /* little bit space in top */ + if (node->outputs.first) { + dy -= NODE_DYS / 2; + } + + /* output sockets */ + bool add_output_space = false; + + for (nsock = node->outputs.first; nsock; nsock = nsock->next) { + if (nodeSocketIsHidden(nsock)) { + continue; + } + + RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr); + + layout = UI_block_layout(node->block, + UI_LAYOUT_VERTICAL, + UI_LAYOUT_PANEL, + locx + NODE_DYS, + dy, + NODE_WIDTH(node) - NODE_DY, + NODE_DY, + 0, + UI_style_get()); + + if (node->flag & NODE_MUTED) { + uiLayoutSetActive(layout, false); + } + + /* context pointers for current node and socket */ + uiLayoutSetContextPointer(layout, "node", &nodeptr); + uiLayoutSetContextPointer(layout, "socket", &sockptr); + + /* align output buttons to the right */ + row = uiLayoutRow(layout, 1); + uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); + + nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(nsock->name)); + + UI_block_align_end(node->block); + UI_block_layout_resolve(node->block, NULL, &buty); + + /* ensure minimum socket height in case layout is empty */ + buty = min_ii(buty, dy - NODE_DY); + + nsock->locx = locx + NODE_WIDTH(node); + /* place the socket circle in the middle of the layout */ + nsock->locy = 0.5f * (dy + buty); + + dy = buty; + if (nsock->next) { + dy -= NODE_SOCKDY; + } + + add_output_space = true; + } + + if (add_output_space) { + dy -= NODE_DY / 4; + } + + node->prvr.xmin = locx + NODE_DYS; + node->prvr.xmax = locx + NODE_WIDTH(node) - NODE_DYS; + + /* preview rect? */ + if (node->flag & NODE_PREVIEW) { + float aspect = 1.0f; + + if (node->preview_xsize && node->preview_ysize) { + aspect = (float)node->preview_ysize / (float)node->preview_xsize; + } + + dy -= NODE_DYS / 2; + node->prvr.ymax = dy; + + if (aspect <= 1.0f) { + node->prvr.ymin = dy - aspect * (NODE_WIDTH(node) - NODE_DY); + } + else { + /* width correction of image */ + /* XXX huh? (ton) */ + float dx = (NODE_WIDTH(node) - NODE_DYS) - (NODE_WIDTH(node) - NODE_DYS) / aspect; + + node->prvr.ymin = dy - (NODE_WIDTH(node) - NODE_DY); + + node->prvr.xmin += 0.5f * dx; + node->prvr.xmax -= 0.5f * dx; + } + + dy = node->prvr.ymin - NODE_DYS / 2; + + /* make sure that maximums are bigger or equal to minimums */ + if (node->prvr.xmax < node->prvr.xmin) { + SWAP(float, node->prvr.xmax, node->prvr.xmin); + } + if (node->prvr.ymax < node->prvr.ymin) { + SWAP(float, node->prvr.ymax, node->prvr.ymin); + } + } + + /* buttons rect? */ + if (node->typeinfo->draw_buttons && (node->flag & NODE_OPTIONS)) { + dy -= NODE_DYS / 2; + + /* set this for uifunc() that don't use layout engine yet */ + node->butr.xmin = 0; + node->butr.xmax = NODE_WIDTH(node) - 2 * NODE_DYS; + node->butr.ymin = 0; + node->butr.ymax = 0; + + layout = UI_block_layout(node->block, + UI_LAYOUT_VERTICAL, + UI_LAYOUT_PANEL, + locx + NODE_DYS, + dy, + node->butr.xmax, + 0, + 0, + UI_style_get()); + + if (node->flag & NODE_MUTED) { + uiLayoutSetActive(layout, false); + } + + uiLayoutSetContextPointer(layout, "node", &nodeptr); + + node->typeinfo->draw_buttons(layout, (bContext *)C, &nodeptr); + + UI_block_align_end(node->block); + UI_block_layout_resolve(node->block, NULL, &buty); + + dy = buty - NODE_DYS / 2; + } + + /* input sockets */ + for (nsock = node->inputs.first; nsock; nsock = nsock->next) { + if (nodeSocketIsHidden(nsock)) { + continue; + } + + RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr); + + layout = UI_block_layout(node->block, + UI_LAYOUT_VERTICAL, + UI_LAYOUT_PANEL, + locx + NODE_DYS, + dy, + NODE_WIDTH(node) - NODE_DY, + NODE_DY, + 0, + UI_style_get()); + + if (node->flag & NODE_MUTED) { + uiLayoutSetActive(layout, false); + } + + /* context pointers for current node and socket */ + uiLayoutSetContextPointer(layout, "node", &nodeptr); + uiLayoutSetContextPointer(layout, "socket", &sockptr); + + row = uiLayoutRow(layout, 1); + + nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(nsock->name)); + + UI_block_align_end(node->block); + UI_block_layout_resolve(node->block, NULL, &buty); + + /* ensure minimum socket height in case layout is empty */ + buty = min_ii(buty, dy - NODE_DY); + + nsock->locx = locx; + /* place the socket circle in the middle of the layout */ + nsock->locy = 0.5f * (dy + buty); + + dy = buty; + if (nsock->next) { + dy -= NODE_SOCKDY; + } + } + + /* little bit space in end */ + if (node->inputs.first || (node->flag & (NODE_OPTIONS | NODE_PREVIEW)) == 0) { + dy -= NODE_DYS / 2; + } + + node->totr.xmin = locx; + node->totr.xmax = locx + NODE_WIDTH(node); + node->totr.ymax = locy; + node->totr.ymin = min_ff(dy, locy - 2 * NODE_DY); + + /* Set the block bounds to clip mouse events from underlying nodes. + * Add a margin for sockets on each side. + */ + UI_block_bounds_set_explicit(node->block, + node->totr.xmin - NODE_SOCKSIZE, + node->totr.ymin, + node->totr.xmax + NODE_SOCKSIZE, + node->totr.ymax); } /* based on settings in node, sets drawing rect info. each redraw! */ static void node_update_hidden(bNode *node) { - bNodeSocket *nsock; - float locx, locy; - float rad, drad, hiddenrad = HIDDEN_RAD; - int totin = 0, totout = 0, tot; - - /* get "global" coords */ - node_to_view(node, 0.0f, 0.0f, &locx, &locy); - - /* calculate minimal radius */ - for (nsock = node->inputs.first; nsock; nsock = nsock->next) { - if (!nodeSocketIsHidden(nsock)) { - totin++; - } - } - for (nsock = node->outputs.first; nsock; nsock = nsock->next) { - if (!nodeSocketIsHidden(nsock)) { - totout++; - } - } - - tot = MAX2(totin, totout); - if (tot > 4) { - hiddenrad += 5.0f * (float)(tot - 4); - } - - node->totr.xmin = locx; - node->totr.xmax = locx + max_ff(NODE_WIDTH(node), 2 * hiddenrad); - node->totr.ymax = locy + (hiddenrad - 0.5f * NODE_DY); - node->totr.ymin = node->totr.ymax - 2 * hiddenrad; - - /* output sockets */ - rad = drad = (float)M_PI / (1.0f + (float)totout); - - for (nsock = node->outputs.first; nsock; nsock = nsock->next) { - if (!nodeSocketIsHidden(nsock)) { - nsock->locx = node->totr.xmax - hiddenrad + sinf(rad) * hiddenrad; - nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad; - rad += drad; - } - } - - /* input sockets */ - rad = drad = -(float)M_PI / (1.0f + (float)totin); - - for (nsock = node->inputs.first; nsock; nsock = nsock->next) { - if (!nodeSocketIsHidden(nsock)) { - nsock->locx = node->totr.xmin + hiddenrad + sinf(rad) * hiddenrad; - nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad; - rad += drad; - } - } - - /* Set the block bounds to clip mouse events from underlying nodes. - * Add a margin for sockets on each side. - */ - UI_block_bounds_set_explicit( - node->block, - node->totr.xmin - NODE_SOCKSIZE, - node->totr.ymin, - node->totr.xmax + NODE_SOCKSIZE, - node->totr.ymax); + bNodeSocket *nsock; + float locx, locy; + float rad, drad, hiddenrad = HIDDEN_RAD; + int totin = 0, totout = 0, tot; + + /* get "global" coords */ + node_to_view(node, 0.0f, 0.0f, &locx, &locy); + + /* calculate minimal radius */ + for (nsock = node->inputs.first; nsock; nsock = nsock->next) { + if (!nodeSocketIsHidden(nsock)) { + totin++; + } + } + for (nsock = node->outputs.first; nsock; nsock = nsock->next) { + if (!nodeSocketIsHidden(nsock)) { + totout++; + } + } + + tot = MAX2(totin, totout); + if (tot > 4) { + hiddenrad += 5.0f * (float)(tot - 4); + } + + node->totr.xmin = locx; + node->totr.xmax = locx + max_ff(NODE_WIDTH(node), 2 * hiddenrad); + node->totr.ymax = locy + (hiddenrad - 0.5f * NODE_DY); + node->totr.ymin = node->totr.ymax - 2 * hiddenrad; + + /* output sockets */ + rad = drad = (float)M_PI / (1.0f + (float)totout); + + for (nsock = node->outputs.first; nsock; nsock = nsock->next) { + if (!nodeSocketIsHidden(nsock)) { + nsock->locx = node->totr.xmax - hiddenrad + sinf(rad) * hiddenrad; + nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad; + rad += drad; + } + } + + /* input sockets */ + rad = drad = -(float)M_PI / (1.0f + (float)totin); + + for (nsock = node->inputs.first; nsock; nsock = nsock->next) { + if (!nodeSocketIsHidden(nsock)) { + nsock->locx = node->totr.xmin + hiddenrad + sinf(rad) * hiddenrad; + nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad; + rad += drad; + } + } + + /* Set the block bounds to clip mouse events from underlying nodes. + * Add a margin for sockets on each side. + */ + UI_block_bounds_set_explicit(node->block, + node->totr.xmin - NODE_SOCKSIZE, + node->totr.ymin, + node->totr.xmax + NODE_SOCKSIZE, + node->totr.ymax); } void node_update_default(const bContext *C, bNodeTree *ntree, bNode *node) { - if (node->flag & NODE_HIDDEN) { - node_update_hidden(node); - } - else { - node_update_basis(C, ntree, node); - } + if (node->flag & NODE_HIDDEN) { + node_update_hidden(node); + } + else { + node_update_basis(C, ntree, node); + } } int node_select_area_default(bNode *node, int x, int y) { - return BLI_rctf_isect_pt(&node->totr, x, y); + return BLI_rctf_isect_pt(&node->totr, x, y); } int node_tweak_area_default(bNode *node, int x, int y) { - return BLI_rctf_isect_pt(&node->totr, x, y); + return BLI_rctf_isect_pt(&node->totr, x, y); } int node_get_colorid(bNode *node) { - switch (node->typeinfo->nclass) { - case NODE_CLASS_INPUT: return TH_NODE_INPUT; - case NODE_CLASS_OUTPUT: return (node->flag & NODE_DO_OUTPUT) ? TH_NODE_OUTPUT : TH_NODE; - case NODE_CLASS_CONVERTOR: return TH_NODE_CONVERTOR; - case NODE_CLASS_OP_COLOR: return TH_NODE_COLOR; - case NODE_CLASS_OP_VECTOR: return TH_NODE_VECTOR; - case NODE_CLASS_OP_FILTER: return TH_NODE_FILTER; - case NODE_CLASS_GROUP: return TH_NODE_GROUP; - case NODE_CLASS_INTERFACE: return TH_NODE_INTERFACE; - case NODE_CLASS_MATTE: return TH_NODE_MATTE; - case NODE_CLASS_DISTORT: return TH_NODE_DISTORT; - case NODE_CLASS_TEXTURE: return TH_NODE_TEXTURE; - case NODE_CLASS_SHADER: return TH_NODE_SHADER; - case NODE_CLASS_SCRIPT: return TH_NODE_SCRIPT; - case NODE_CLASS_PATTERN: return TH_NODE_PATTERN; - case NODE_CLASS_LAYOUT: return TH_NODE_LAYOUT; - default: return TH_NODE; - } + switch (node->typeinfo->nclass) { + case NODE_CLASS_INPUT: + return TH_NODE_INPUT; + case NODE_CLASS_OUTPUT: + return (node->flag & NODE_DO_OUTPUT) ? TH_NODE_OUTPUT : TH_NODE; + case NODE_CLASS_CONVERTOR: + return TH_NODE_CONVERTOR; + case NODE_CLASS_OP_COLOR: + return TH_NODE_COLOR; + case NODE_CLASS_OP_VECTOR: + return TH_NODE_VECTOR; + case NODE_CLASS_OP_FILTER: + return TH_NODE_FILTER; + case NODE_CLASS_GROUP: + return TH_NODE_GROUP; + case NODE_CLASS_INTERFACE: + return TH_NODE_INTERFACE; + case NODE_CLASS_MATTE: + return TH_NODE_MATTE; + case NODE_CLASS_DISTORT: + return TH_NODE_DISTORT; + case NODE_CLASS_TEXTURE: + return TH_NODE_TEXTURE; + case NODE_CLASS_SHADER: + return TH_NODE_SHADER; + case NODE_CLASS_SCRIPT: + return TH_NODE_SCRIPT; + case NODE_CLASS_PATTERN: + return TH_NODE_PATTERN; + case NODE_CLASS_LAYOUT: + return TH_NODE_LAYOUT; + default: + return TH_NODE; + } } /* note: in cmp_util.c is similar code, for node_compo_pass_on() @@ -667,898 +702,1034 @@ int node_get_colorid(bNode *node) /* note: in node_edit.c is similar code, for untangle node */ static void node_draw_mute_line(View2D *v2d, SpaceNode *snode, bNode *node) { - bNodeLink *link; + bNodeLink *link; - GPU_blend(true); + GPU_blend(true); - for (link = node->internal_links.first; link; link = link->next) { - node_draw_link_bezier(v2d, snode, link, TH_REDALERT, TH_REDALERT, -1); - } + for (link = node->internal_links.first; link; link = link->next) { + node_draw_link_bezier(v2d, snode, link, TH_REDALERT, TH_REDALERT, -1); + } - GPU_blend(false); + GPU_blend(false); } -static void node_socket_circle_draw(const bContext *C, bNodeTree *ntree, PointerRNA node_ptr, bNodeSocket *sock, unsigned pos, unsigned col) +static void node_socket_circle_draw(const bContext *C, + bNodeTree *ntree, + PointerRNA node_ptr, + bNodeSocket *sock, + unsigned pos, + unsigned col) { - PointerRNA ptr; - float color[4]; + PointerRNA ptr; + float color[4]; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); - sock->typeinfo->draw_color((bContext *)C, &ptr, &node_ptr, color); + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + sock->typeinfo->draw_color((bContext *)C, &ptr, &node_ptr, color); - bNode *node = node_ptr.data; - if (node->flag & NODE_MUTED) { - color[3] *= 0.25f; - } + bNode *node = node_ptr.data; + if (node->flag & NODE_MUTED) { + color[3] *= 0.25f; + } - immAttr4fv(col, color); - immVertex2f(pos, sock->locx, sock->locy); + immAttr4fv(col, color); + immVertex2f(pos, sock->locx, sock->locy); } /* ************** Socket callbacks *********** */ static void node_draw_preview_background(float tile, rctf *rect) { - float x, y; - - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - /* draw checkerboard backdrop to show alpha */ - immUniformColor3ub(120, 120, 120); - immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax); - immUniformColor3ub(160, 160, 160); - - for (y = rect->ymin; y < rect->ymax; y += tile * 2) { - for (x = rect->xmin; x < rect->xmax; x += tile * 2) { - float tilex = tile, tiley = tile; - - if (x + tile > rect->xmax) { - tilex = rect->xmax - x; - } - if (y + tile > rect->ymax) { - tiley = rect->ymax - y; - } - - immRectf(pos, x, y, x + tilex, y + tiley); - } - } - for (y = rect->ymin + tile; y < rect->ymax; y += tile * 2) { - for (x = rect->xmin + tile; x < rect->xmax; x += tile * 2) { - float tilex = tile, tiley = tile; - - if (x + tile > rect->xmax) { - tilex = rect->xmax - x; - } - if (y + tile > rect->ymax) { - tiley = rect->ymax - y; - } - - immRectf(pos, x, y, x + tilex, y + tiley); - } - } - immUnbindProgram(); + float x, y; + + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + /* draw checkerboard backdrop to show alpha */ + immUniformColor3ub(120, 120, 120); + immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax); + immUniformColor3ub(160, 160, 160); + + for (y = rect->ymin; y < rect->ymax; y += tile * 2) { + for (x = rect->xmin; x < rect->xmax; x += tile * 2) { + float tilex = tile, tiley = tile; + + if (x + tile > rect->xmax) { + tilex = rect->xmax - x; + } + if (y + tile > rect->ymax) { + tiley = rect->ymax - y; + } + + immRectf(pos, x, y, x + tilex, y + tiley); + } + } + for (y = rect->ymin + tile; y < rect->ymax; y += tile * 2) { + for (x = rect->xmin + tile; x < rect->xmax; x += tile * 2) { + float tilex = tile, tiley = tile; + + if (x + tile > rect->xmax) { + tilex = rect->xmax - x; + } + if (y + tile > rect->ymax) { + tiley = rect->ymax - y; + } + + immRectf(pos, x, y, x + tilex, y + tiley); + } + } + immUnbindProgram(); } /* not a callback */ static void node_draw_preview(bNodePreview *preview, rctf *prv) { - float xrect = BLI_rctf_size_x(prv); - float yrect = BLI_rctf_size_y(prv); - float xscale = xrect / ((float)preview->xsize); - float yscale = yrect / ((float)preview->ysize); - float scale; - rctf draw_rect; - - /* uniform scale and offset */ - draw_rect = *prv; - if (xscale < yscale) { - float offset = 0.5f * (yrect - ((float)preview->ysize) * xscale); - draw_rect.ymin += offset; - draw_rect.ymax -= offset; - scale = xscale; - } - else { - float offset = 0.5f * (xrect - ((float)preview->xsize) * yscale); - draw_rect.xmin += offset; - draw_rect.xmax -= offset; - scale = yscale; - } - - node_draw_preview_background(BLI_rctf_size_x(prv) / 10.0f, &draw_rect); - - GPU_blend(true); - /* premul graphics */ - GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); - - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); - immDrawPixelsTex(&state, draw_rect.xmin, draw_rect.ymin, preview->xsize, preview->ysize, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, preview->rect, - scale, scale, NULL); - - GPU_blend(false); - - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - immUniformThemeColorShadeAlpha(TH_BACK, -15, +100); - imm_draw_box_wire_2d(pos, draw_rect.xmin, draw_rect.ymin, draw_rect.xmax, draw_rect.ymax); - immUnbindProgram(); + float xrect = BLI_rctf_size_x(prv); + float yrect = BLI_rctf_size_y(prv); + float xscale = xrect / ((float)preview->xsize); + float yscale = yrect / ((float)preview->ysize); + float scale; + rctf draw_rect; + + /* uniform scale and offset */ + draw_rect = *prv; + if (xscale < yscale) { + float offset = 0.5f * (yrect - ((float)preview->ysize) * xscale); + draw_rect.ymin += offset; + draw_rect.ymax -= offset; + scale = xscale; + } + else { + float offset = 0.5f * (xrect - ((float)preview->xsize) * yscale); + draw_rect.xmin += offset; + draw_rect.xmax -= offset; + scale = yscale; + } + + node_draw_preview_background(BLI_rctf_size_x(prv) / 10.0f, &draw_rect); + + GPU_blend(true); + /* premul graphics */ + GPU_blend_set_func_separate( + GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + immDrawPixelsTex(&state, + draw_rect.xmin, + draw_rect.ymin, + preview->xsize, + preview->ysize, + GL_RGBA, + GL_UNSIGNED_BYTE, + GL_LINEAR, + preview->rect, + scale, + scale, + NULL); + + GPU_blend(false); + + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformThemeColorShadeAlpha(TH_BACK, -15, +100); + imm_draw_box_wire_2d(pos, draw_rect.xmin, draw_rect.ymin, draw_rect.xmax, draw_rect.ymax); + immUnbindProgram(); } /* common handle function for operator buttons that need to select the node first */ static void node_toggle_button_cb(struct bContext *C, void *node_argv, void *op_argv) { - bNode *node = (bNode *)node_argv; - const char *opname = (const char *)op_argv; + bNode *node = (bNode *)node_argv; + const char *opname = (const char *)op_argv; - /* select & activate only the button's node */ - node_select_single(C, node); + /* select & activate only the button's node */ + node_select_single(C, node); - WM_operator_name_call(C, opname, WM_OP_INVOKE_DEFAULT, NULL); + WM_operator_name_call(C, opname, WM_OP_INVOKE_DEFAULT, NULL); } void node_draw_shadow(SpaceNode *snode, bNode *node, float radius, float alpha) { - rctf *rct = &node->totr; - - UI_draw_roundbox_corner_set(UI_CNR_ALL); - if (node->parent == NULL) { - ui_draw_dropshadow(rct, radius, snode->aspect, alpha, node->flag & SELECT); - } - else { - const float margin = 3.0f; - - float color[4] = {0.0f, 0.0f, 0.0f, 0.33f}; - UI_draw_roundbox_aa(true, rct->xmin - margin, rct->ymin - margin, - rct->xmax + margin, rct->ymax + margin, radius + margin, color); - } + rctf *rct = &node->totr; + + UI_draw_roundbox_corner_set(UI_CNR_ALL); + if (node->parent == NULL) { + ui_draw_dropshadow(rct, radius, snode->aspect, alpha, node->flag & SELECT); + } + else { + const float margin = 3.0f; + + float color[4] = {0.0f, 0.0f, 0.0f, 0.33f}; + UI_draw_roundbox_aa(true, + rct->xmin - margin, + rct->ymin - margin, + rct->xmax + margin, + rct->ymax + margin, + radius + margin, + color); + } } -void node_draw_sockets(View2D *v2d, const bContext *C, bNodeTree *ntree, bNode *node, bool draw_outputs, bool select_all) +void node_draw_sockets(View2D *v2d, + const bContext *C, + bNodeTree *ntree, + bNode *node, + bool draw_outputs, + bool select_all) { - const uint total_input_len = BLI_listbase_count(&node->inputs); - const uint total_output_len = BLI_listbase_count(&node->outputs); - - if (total_input_len + total_output_len == 0) { - return; - } - - PointerRNA node_ptr; - RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr); - - float scale; - UI_view2d_scale_get(v2d, &scale, NULL); - - GPUVertFormat *format = immVertexFormat(); - uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); - - GPU_blend(true); - GPU_enable_program_point_size(); - - immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_VARYING_COLOR_OUTLINE_AA); - - /* set handle size */ - immUniform1f("size", 2.0f * NODE_SOCKSIZE * scale); /* 2 * size to have diameter */ - - if (!select_all) { - /* outline for unselected sockets */ - immUniform1f("outlineWidth", 1.0f); - immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, 0.6f); - - immBeginAtMost(GPU_PRIM_POINTS, total_input_len + total_output_len); - } - - /* socket inputs */ - short selected_input_len = 0; - bNodeSocket *sock; - for (sock = node->inputs.first; sock; sock = sock->next) { - if (nodeSocketIsHidden(sock)) { - continue; - } - if (select_all || (sock->flag & SELECT)) { - ++selected_input_len; - continue; - } - - node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col); - } - - /* socket outputs */ - short selected_output_len = 0; - if (draw_outputs) { - for (sock = node->outputs.first; sock; sock = sock->next) { - if (nodeSocketIsHidden(sock)) { - continue; - } - if (select_all || (sock->flag & SELECT)) { - ++selected_output_len; - continue; - } - - node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col); - } - } - - if (!select_all) { - immEnd(); - } - - /* go back and draw selected sockets */ - if (selected_input_len + selected_output_len > 0) { - /* outline for selected sockets */ - float c[3]; - UI_GetThemeColor3fv(TH_TEXT_HI, c); - immUniform4f("outlineColor", c[0], c[1], c[2], 1.0f); - immUniform1f("outlineWidth", 1.5f); - - immBegin(GPU_PRIM_POINTS, selected_input_len + selected_output_len); - - if (selected_input_len) { - /* socket inputs */ - for (sock = node->inputs.first; sock; sock = sock->next) { - if (nodeSocketIsHidden(sock)) { - continue; - } - if (select_all || (sock->flag & SELECT)) { - node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col); - if (--selected_input_len == 0) { - break; /* stop as soon as last one is drawn */ - } - } - } - } - - if (selected_output_len) { - /* socket outputs */ - for (sock = node->outputs.first; sock; sock = sock->next) { - if (nodeSocketIsHidden(sock)) { - continue; - } - if (select_all || (sock->flag & SELECT)) { - node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col); - if (--selected_output_len == 0) { - break; /* stop as soon as last one is drawn */ - } - } - } - } - - immEnd(); - } - - immUnbindProgram(); - - GPU_disable_program_point_size(); - GPU_blend(false); + const uint total_input_len = BLI_listbase_count(&node->inputs); + const uint total_output_len = BLI_listbase_count(&node->outputs); + + if (total_input_len + total_output_len == 0) { + return; + } + + PointerRNA node_ptr; + RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr); + + float scale; + UI_view2d_scale_get(v2d, &scale, NULL); + + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); + + GPU_blend(true); + GPU_enable_program_point_size(); + + immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_VARYING_COLOR_OUTLINE_AA); + + /* set handle size */ + immUniform1f("size", 2.0f * NODE_SOCKSIZE * scale); /* 2 * size to have diameter */ + + if (!select_all) { + /* outline for unselected sockets */ + immUniform1f("outlineWidth", 1.0f); + immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, 0.6f); + + immBeginAtMost(GPU_PRIM_POINTS, total_input_len + total_output_len); + } + + /* socket inputs */ + short selected_input_len = 0; + bNodeSocket *sock; + for (sock = node->inputs.first; sock; sock = sock->next) { + if (nodeSocketIsHidden(sock)) { + continue; + } + if (select_all || (sock->flag & SELECT)) { + ++selected_input_len; + continue; + } + + node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col); + } + + /* socket outputs */ + short selected_output_len = 0; + if (draw_outputs) { + for (sock = node->outputs.first; sock; sock = sock->next) { + if (nodeSocketIsHidden(sock)) { + continue; + } + if (select_all || (sock->flag & SELECT)) { + ++selected_output_len; + continue; + } + + node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col); + } + } + + if (!select_all) { + immEnd(); + } + + /* go back and draw selected sockets */ + if (selected_input_len + selected_output_len > 0) { + /* outline for selected sockets */ + float c[3]; + UI_GetThemeColor3fv(TH_TEXT_HI, c); + immUniform4f("outlineColor", c[0], c[1], c[2], 1.0f); + immUniform1f("outlineWidth", 1.5f); + + immBegin(GPU_PRIM_POINTS, selected_input_len + selected_output_len); + + if (selected_input_len) { + /* socket inputs */ + for (sock = node->inputs.first; sock; sock = sock->next) { + if (nodeSocketIsHidden(sock)) { + continue; + } + if (select_all || (sock->flag & SELECT)) { + node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col); + if (--selected_input_len == 0) { + break; /* stop as soon as last one is drawn */ + } + } + } + } + + if (selected_output_len) { + /* socket outputs */ + for (sock = node->outputs.first; sock; sock = sock->next) { + if (nodeSocketIsHidden(sock)) { + continue; + } + if (select_all || (sock->flag & SELECT)) { + node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col); + if (--selected_output_len == 0) { + break; /* stop as soon as last one is drawn */ + } + } + } + } + + immEnd(); + } + + immUnbindProgram(); + + GPU_disable_program_point_size(); + GPU_blend(false); } -static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey key) +static void node_draw_basis(const bContext *C, + ARegion *ar, + SpaceNode *snode, + bNodeTree *ntree, + bNode *node, + bNodeInstanceKey key) { - bNodeInstanceHash *previews = CTX_data_pointer_get(C, "node_previews").data; - rctf *rct = &node->totr; - float iconofs; - /* float socket_size = NODE_SOCKSIZE*U.dpi/72; */ /* UNUSED */ - float iconbutw = 0.8f * UI_UNIT_X; - int color_id = node_get_colorid(node); - float color[4]; - char showname[128]; /* 128 used below */ - View2D *v2d = &ar->v2d; - - /* skip if out of view */ - if (BLI_rctf_isect(&node->totr, &v2d->cur, NULL) == false) { - UI_block_end(C, node->block); - node->block = NULL; - return; - } - - /* shadow */ - node_draw_shadow(snode, node, BASIS_RAD, 1.0f); - - if (node->flag & NODE_MUTED) { - /* Muted nodes are semi-transparent and colorless. */ - UI_GetThemeColor3fv(TH_NODE, color); - color[3] = 0.25f; - } - else { - /* Opaque headers for regular nodes. */ - UI_GetThemeColor3fv(color_id, color); - color[3] = 1.0f; - } - - GPU_line_width(1.0f); - - UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT); - UI_draw_roundbox_aa(true, rct->xmin, rct->ymax - NODE_DY, rct->xmax, rct->ymax, BASIS_RAD, color); - - /* show/hide icons */ - iconofs = rct->xmax - 0.35f * U.widget_unit; - - /* preview */ - if (node->typeinfo->flag & NODE_PREVIEW) { - uiBut *but; - iconofs -= iconbutw; - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); - but = uiDefIconBut(node->block, UI_BTYPE_BUT_TOGGLE, B_REDR, ICON_MATERIAL, - iconofs, rct->ymax - NODE_DY, iconbutw, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); - UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_preview_toggle"); - /* XXX this does not work when node is activated and the operator called right afterwards, - * since active ID is not updated yet (needs to process the notifier). - * This can only work as visual indicator! - */ -// if (!(node->flag & (NODE_ACTIVE_ID|NODE_DO_OUTPUT))) -// UI_but_flag_enable(but, UI_BUT_DISABLED); - UI_block_emboss_set(node->block, UI_EMBOSS); - } - /* group edit */ - if (node->type == NODE_GROUP) { - uiBut *but; - iconofs -= iconbutw; - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); - but = uiDefIconBut(node->block, UI_BTYPE_BUT_TOGGLE, B_REDR, ICON_NODETREE, - iconofs, rct->ymax - NODE_DY, iconbutw, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); - UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_group_edit"); - UI_block_emboss_set(node->block, UI_EMBOSS); - } - - /* title */ - if (node->flag & SELECT) { - UI_GetThemeColor4fv(TH_SELECT, color); - } - else { - UI_GetThemeColorBlendShade4fv(TH_SELECT, color_id, 0.4f, 10, color); - } - - /* open/close entirely? */ - { - uiBut *but; - int but_size = U.widget_unit * 0.8f; - /* XXX button uses a custom triangle draw below, so make it invisible without icon */ - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); - but = uiDefBut(node->block, UI_BTYPE_BUT_TOGGLE, B_REDR, "", - rct->xmin + 0.35f * U.widget_unit, rct->ymax - NODE_DY / 2.2f - but_size / 2, - but_size, but_size, NULL, 0, 0, 0, 0, ""); - UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_hide_toggle"); - UI_block_emboss_set(node->block, UI_EMBOSS); - - UI_GetThemeColor4fv(TH_TEXT, color); - /* custom draw function for this button */ - UI_draw_icon_tri(rct->xmin + 0.65f * U.widget_unit, rct->ymax - NODE_DY / 2.2f, 'v', color); - } - - nodeLabel(ntree, node, showname, sizeof(showname)); - - uiBut *but = uiDefBut(node->block, UI_BTYPE_LABEL, 0, showname, - (int)(rct->xmin + (NODE_MARGIN_X)), (int)(rct->ymax - NODE_DY), - (short)(iconofs - rct->xmin - 18.0f), (short)NODE_DY, - NULL, 0, 0, 0, 0, ""); - if (node->flag & NODE_MUTED) { - UI_but_flag_enable(but, UI_BUT_INACTIVE); - } - - /* body */ - if (!nodeIsRegistered(node)) { - /* use warning color to indicate undefined types */ - UI_GetThemeColor4fv(TH_REDALERT, color); - - } - else if (node->flag & NODE_MUTED) { - /* Muted nodes are semi-transparent and colorless. */ - UI_GetThemeColor4fv(TH_NODE, color); - } - else if (node->flag & NODE_CUSTOM_COLOR) { - rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], 1.0f); - } - else { - UI_GetThemeColor4fv(TH_NODE, color); - } - - if (node->flag & NODE_MUTED) { - color[3] = 0.5f; - } - - UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_LEFT | UI_CNR_BOTTOM_RIGHT); - UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax - NODE_DY, BASIS_RAD, color); - - /* outline active and selected emphasis */ - if (node->flag & SELECT) { - UI_GetThemeColorShadeAlpha4fv((node->flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, 0, -40, color); - - UI_draw_roundbox_corner_set(UI_CNR_ALL); - UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color); - } - - /* disable lines */ - if (node->flag & NODE_MUTED) { - node_draw_mute_line(v2d, snode, node); - } - - node_draw_sockets(v2d, C, ntree, node, true, false); - - /* preview */ - if (node->flag & NODE_PREVIEW && previews) { - bNodePreview *preview = BKE_node_instance_hash_lookup(previews, key); - if (preview && (preview->xsize && preview->ysize)) { - if (preview->rect && !BLI_rctf_is_empty(&node->prvr)) { - node_draw_preview(preview, &node->prvr); - } - } - } - - UI_ThemeClearColor(color_id); - - UI_block_end(C, node->block); - UI_block_draw(C, node->block); - node->block = NULL; + bNodeInstanceHash *previews = CTX_data_pointer_get(C, "node_previews").data; + rctf *rct = &node->totr; + float iconofs; + /* float socket_size = NODE_SOCKSIZE*U.dpi/72; */ /* UNUSED */ + float iconbutw = 0.8f * UI_UNIT_X; + int color_id = node_get_colorid(node); + float color[4]; + char showname[128]; /* 128 used below */ + View2D *v2d = &ar->v2d; + + /* skip if out of view */ + if (BLI_rctf_isect(&node->totr, &v2d->cur, NULL) == false) { + UI_block_end(C, node->block); + node->block = NULL; + return; + } + + /* shadow */ + node_draw_shadow(snode, node, BASIS_RAD, 1.0f); + + if (node->flag & NODE_MUTED) { + /* Muted nodes are semi-transparent and colorless. */ + UI_GetThemeColor3fv(TH_NODE, color); + color[3] = 0.25f; + } + else { + /* Opaque headers for regular nodes. */ + UI_GetThemeColor3fv(color_id, color); + color[3] = 1.0f; + } + + GPU_line_width(1.0f); + + UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT); + UI_draw_roundbox_aa( + true, rct->xmin, rct->ymax - NODE_DY, rct->xmax, rct->ymax, BASIS_RAD, color); + + /* show/hide icons */ + iconofs = rct->xmax - 0.35f * U.widget_unit; + + /* preview */ + if (node->typeinfo->flag & NODE_PREVIEW) { + uiBut *but; + iconofs -= iconbutw; + UI_block_emboss_set(node->block, UI_EMBOSS_NONE); + but = uiDefIconBut(node->block, + UI_BTYPE_BUT_TOGGLE, + B_REDR, + ICON_MATERIAL, + iconofs, + rct->ymax - NODE_DY, + iconbutw, + UI_UNIT_Y, + NULL, + 0, + 0, + 0, + 0, + ""); + UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_preview_toggle"); + /* XXX this does not work when node is activated and the operator called right afterwards, + * since active ID is not updated yet (needs to process the notifier). + * This can only work as visual indicator! + */ + // if (!(node->flag & (NODE_ACTIVE_ID|NODE_DO_OUTPUT))) + // UI_but_flag_enable(but, UI_BUT_DISABLED); + UI_block_emboss_set(node->block, UI_EMBOSS); + } + /* group edit */ + if (node->type == NODE_GROUP) { + uiBut *but; + iconofs -= iconbutw; + UI_block_emboss_set(node->block, UI_EMBOSS_NONE); + but = uiDefIconBut(node->block, + UI_BTYPE_BUT_TOGGLE, + B_REDR, + ICON_NODETREE, + iconofs, + rct->ymax - NODE_DY, + iconbutw, + UI_UNIT_Y, + NULL, + 0, + 0, + 0, + 0, + ""); + UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_group_edit"); + UI_block_emboss_set(node->block, UI_EMBOSS); + } + + /* title */ + if (node->flag & SELECT) { + UI_GetThemeColor4fv(TH_SELECT, color); + } + else { + UI_GetThemeColorBlendShade4fv(TH_SELECT, color_id, 0.4f, 10, color); + } + + /* open/close entirely? */ + { + uiBut *but; + int but_size = U.widget_unit * 0.8f; + /* XXX button uses a custom triangle draw below, so make it invisible without icon */ + UI_block_emboss_set(node->block, UI_EMBOSS_NONE); + but = uiDefBut(node->block, + UI_BTYPE_BUT_TOGGLE, + B_REDR, + "", + rct->xmin + 0.35f * U.widget_unit, + rct->ymax - NODE_DY / 2.2f - but_size / 2, + but_size, + but_size, + NULL, + 0, + 0, + 0, + 0, + ""); + UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_hide_toggle"); + UI_block_emboss_set(node->block, UI_EMBOSS); + + UI_GetThemeColor4fv(TH_TEXT, color); + /* custom draw function for this button */ + UI_draw_icon_tri(rct->xmin + 0.65f * U.widget_unit, rct->ymax - NODE_DY / 2.2f, 'v', color); + } + + nodeLabel(ntree, node, showname, sizeof(showname)); + + uiBut *but = uiDefBut(node->block, + UI_BTYPE_LABEL, + 0, + showname, + (int)(rct->xmin + (NODE_MARGIN_X)), + (int)(rct->ymax - NODE_DY), + (short)(iconofs - rct->xmin - 18.0f), + (short)NODE_DY, + NULL, + 0, + 0, + 0, + 0, + ""); + if (node->flag & NODE_MUTED) { + UI_but_flag_enable(but, UI_BUT_INACTIVE); + } + + /* body */ + if (!nodeIsRegistered(node)) { + /* use warning color to indicate undefined types */ + UI_GetThemeColor4fv(TH_REDALERT, color); + } + else if (node->flag & NODE_MUTED) { + /* Muted nodes are semi-transparent and colorless. */ + UI_GetThemeColor4fv(TH_NODE, color); + } + else if (node->flag & NODE_CUSTOM_COLOR) { + rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], 1.0f); + } + else { + UI_GetThemeColor4fv(TH_NODE, color); + } + + if (node->flag & NODE_MUTED) { + color[3] = 0.5f; + } + + UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_LEFT | UI_CNR_BOTTOM_RIGHT); + UI_draw_roundbox_aa( + true, rct->xmin, rct->ymin, rct->xmax, rct->ymax - NODE_DY, BASIS_RAD, color); + + /* outline active and selected emphasis */ + if (node->flag & SELECT) { + UI_GetThemeColorShadeAlpha4fv( + (node->flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, 0, -40, color); + + UI_draw_roundbox_corner_set(UI_CNR_ALL); + UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color); + } + + /* disable lines */ + if (node->flag & NODE_MUTED) { + node_draw_mute_line(v2d, snode, node); + } + + node_draw_sockets(v2d, C, ntree, node, true, false); + + /* preview */ + if (node->flag & NODE_PREVIEW && previews) { + bNodePreview *preview = BKE_node_instance_hash_lookup(previews, key); + if (preview && (preview->xsize && preview->ysize)) { + if (preview->rect && !BLI_rctf_is_empty(&node->prvr)) { + node_draw_preview(preview, &node->prvr); + } + } + } + + UI_ThemeClearColor(color_id); + + UI_block_end(C, node->block); + UI_block_draw(C, node->block); + node->block = NULL; } -static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey UNUSED(key)) +static void node_draw_hidden(const bContext *C, + ARegion *ar, + SpaceNode *snode, + bNodeTree *ntree, + bNode *node, + bNodeInstanceKey UNUSED(key)) { - rctf *rct = &node->totr; - float dx, centy = BLI_rctf_cent_y(rct); - float hiddenrad = BLI_rctf_size_y(rct) / 2.0f; - int color_id = node_get_colorid(node); - float color[4]; - char showname[128]; /* 128 is used below */ - View2D *v2d = &ar->v2d; - float scale; - - UI_view2d_scale_get(v2d, &scale, NULL); - - /* shadow */ - node_draw_shadow(snode, node, hiddenrad, 1.0f); - - /* body */ - if (node->flag & NODE_MUTED) { - /* Muted nodes are semi-transparent and colorless. */ - UI_GetThemeColor4fv(TH_NODE, color); - color[3] = 0.25f; - } - else { - UI_GetThemeColor4fv(color_id, color); - } - - UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad, color); - - /* outline active and selected emphasis */ - if (node->flag & SELECT) { - UI_GetThemeColorShadeAlpha4fv((node->flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, 0, -40, color); - - UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad, color); - } - - /* custom color inline */ - if (node->flag & NODE_CUSTOM_COLOR) { - GPU_blend(true); - GPU_line_smooth(true); - - UI_draw_roundbox_3fvAlpha(false, rct->xmin + 1, rct->ymin + 1, rct->xmax -1, rct->ymax - 1, hiddenrad, node->color, 1.0f); - - GPU_line_smooth(false); - GPU_blend(false); - } - - /* title */ - if (node->flag & SELECT) { - UI_GetThemeColor4fv(TH_SELECT, color); - } - else { - UI_GetThemeColorBlendShade4fv(TH_SELECT, color_id, 0.4f, 10, color); - } - - /* open entirely icon */ - { - uiBut *but; - int but_size = U.widget_unit * 0.8f; - /* XXX button uses a custom triangle draw below, so make it invisible without icon */ - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); - but = uiDefBut(node->block, UI_BTYPE_BUT_TOGGLE, B_REDR, "", - rct->xmin + 0.35f * U.widget_unit, centy - but_size / 2, - but_size, but_size, NULL, 0, 0, 0, 0, ""); - UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_hide_toggle"); - UI_block_emboss_set(node->block, UI_EMBOSS); - - UI_GetThemeColor4fv(TH_TEXT, color); - /* custom draw function for this button */ - UI_draw_icon_tri(rct->xmin + 0.65f * U.widget_unit, centy, 'h', color); - } - - /* disable lines */ - if (node->flag & NODE_MUTED) { - node_draw_mute_line(&ar->v2d, snode, node); - } - - nodeLabel(ntree, node, showname, sizeof(showname)); - - /* XXX - don't print into self! */ - //if (node->flag & NODE_MUTED) - // BLI_snprintf(showname, sizeof(showname), "[%s]", showname); - - uiBut *but = uiDefBut(node->block, UI_BTYPE_LABEL, 0, showname, - round_fl_to_int(rct->xmin + NODE_MARGIN_X), round_fl_to_int(centy - NODE_DY * 0.5f), - (short)(BLI_rctf_size_x(rct) - 18.0f - 12.0f), (short)NODE_DY, - NULL, 0, 0, 0, 0, ""); - if (node->flag & NODE_MUTED) { - UI_but_flag_enable(but, UI_BUT_INACTIVE); - } - - /* scale widget thing */ - uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); - - immUniformThemeColorShade(color_id, -10); - dx = 10.0f; - - immBegin(GPU_PRIM_LINES, 4); - immVertex2f(pos, rct->xmax - dx, centy - 4.0f); - immVertex2f(pos, rct->xmax - dx, centy + 4.0f); - - immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f); - immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f); - immEnd(); - - immUniformThemeColorShade(color_id, 30); - dx -= snode->aspect; - - immBegin(GPU_PRIM_LINES, 4); - immVertex2f(pos, rct->xmax - dx, centy - 4.0f); - immVertex2f(pos, rct->xmax - dx, centy + 4.0f); - - immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f); - immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f); - immEnd(); - - immUnbindProgram(); - - node_draw_sockets(v2d, C, ntree, node, true, false); - - UI_block_end(C, node->block); - UI_block_draw(C, node->block); - node->block = NULL; + rctf *rct = &node->totr; + float dx, centy = BLI_rctf_cent_y(rct); + float hiddenrad = BLI_rctf_size_y(rct) / 2.0f; + int color_id = node_get_colorid(node); + float color[4]; + char showname[128]; /* 128 is used below */ + View2D *v2d = &ar->v2d; + float scale; + + UI_view2d_scale_get(v2d, &scale, NULL); + + /* shadow */ + node_draw_shadow(snode, node, hiddenrad, 1.0f); + + /* body */ + if (node->flag & NODE_MUTED) { + /* Muted nodes are semi-transparent and colorless. */ + UI_GetThemeColor4fv(TH_NODE, color); + color[3] = 0.25f; + } + else { + UI_GetThemeColor4fv(color_id, color); + } + + UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad, color); + + /* outline active and selected emphasis */ + if (node->flag & SELECT) { + UI_GetThemeColorShadeAlpha4fv( + (node->flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, 0, -40, color); + + UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad, color); + } + + /* custom color inline */ + if (node->flag & NODE_CUSTOM_COLOR) { + GPU_blend(true); + GPU_line_smooth(true); + + UI_draw_roundbox_3fvAlpha(false, + rct->xmin + 1, + rct->ymin + 1, + rct->xmax - 1, + rct->ymax - 1, + hiddenrad, + node->color, + 1.0f); + + GPU_line_smooth(false); + GPU_blend(false); + } + + /* title */ + if (node->flag & SELECT) { + UI_GetThemeColor4fv(TH_SELECT, color); + } + else { + UI_GetThemeColorBlendShade4fv(TH_SELECT, color_id, 0.4f, 10, color); + } + + /* open entirely icon */ + { + uiBut *but; + int but_size = U.widget_unit * 0.8f; + /* XXX button uses a custom triangle draw below, so make it invisible without icon */ + UI_block_emboss_set(node->block, UI_EMBOSS_NONE); + but = uiDefBut(node->block, + UI_BTYPE_BUT_TOGGLE, + B_REDR, + "", + rct->xmin + 0.35f * U.widget_unit, + centy - but_size / 2, + but_size, + but_size, + NULL, + 0, + 0, + 0, + 0, + ""); + UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_hide_toggle"); + UI_block_emboss_set(node->block, UI_EMBOSS); + + UI_GetThemeColor4fv(TH_TEXT, color); + /* custom draw function for this button */ + UI_draw_icon_tri(rct->xmin + 0.65f * U.widget_unit, centy, 'h', color); + } + + /* disable lines */ + if (node->flag & NODE_MUTED) { + node_draw_mute_line(&ar->v2d, snode, node); + } + + nodeLabel(ntree, node, showname, sizeof(showname)); + + /* XXX - don't print into self! */ + //if (node->flag & NODE_MUTED) + // BLI_snprintf(showname, sizeof(showname), "[%s]", showname); + + uiBut *but = uiDefBut(node->block, + UI_BTYPE_LABEL, + 0, + showname, + round_fl_to_int(rct->xmin + NODE_MARGIN_X), + round_fl_to_int(centy - NODE_DY * 0.5f), + (short)(BLI_rctf_size_x(rct) - 18.0f - 12.0f), + (short)NODE_DY, + NULL, + 0, + 0, + 0, + 0, + ""); + if (node->flag & NODE_MUTED) { + UI_but_flag_enable(but, UI_BUT_INACTIVE); + } + + /* scale widget thing */ + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + immUniformThemeColorShade(color_id, -10); + dx = 10.0f; + + immBegin(GPU_PRIM_LINES, 4); + immVertex2f(pos, rct->xmax - dx, centy - 4.0f); + immVertex2f(pos, rct->xmax - dx, centy + 4.0f); + + immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f); + immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f); + immEnd(); + + immUniformThemeColorShade(color_id, 30); + dx -= snode->aspect; + + immBegin(GPU_PRIM_LINES, 4); + immVertex2f(pos, rct->xmax - dx, centy - 4.0f); + immVertex2f(pos, rct->xmax - dx, centy + 4.0f); + + immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f); + immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f); + immEnd(); + + immUnbindProgram(); + + node_draw_sockets(v2d, C, ntree, node, true, false); + + UI_block_end(C, node->block); + UI_block_draw(C, node->block); + node->block = NULL; } int node_get_resize_cursor(int directions) { - if (directions == 0) { - return CURSOR_STD; - } - else if ((directions & ~(NODE_RESIZE_TOP | NODE_RESIZE_BOTTOM)) == 0) { - return CURSOR_Y_MOVE; - } - else if ((directions & ~(NODE_RESIZE_RIGHT | NODE_RESIZE_LEFT)) == 0) { - return CURSOR_X_MOVE; - } - else { - return CURSOR_EDIT; - } + if (directions == 0) { + return CURSOR_STD; + } + else if ((directions & ~(NODE_RESIZE_TOP | NODE_RESIZE_BOTTOM)) == 0) { + return CURSOR_Y_MOVE; + } + else if ((directions & ~(NODE_RESIZE_RIGHT | NODE_RESIZE_LEFT)) == 0) { + return CURSOR_X_MOVE; + } + else { + return CURSOR_EDIT; + } } void node_set_cursor(wmWindow *win, SpaceNode *snode, float cursor[2]) { - bNodeTree *ntree = snode->edittree; - bNode *node; - bNodeSocket *sock; - int wmcursor = CURSOR_STD; - - if (ntree) { - if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN | SOCK_OUT)) { - /* pass */ - } - else { - /* check nodes front to back */ - for (node = ntree->nodes.last; node; node = node->prev) { - if (BLI_rctf_isect_pt(&node->totr, cursor[0], cursor[1])) { - break; /* first hit on node stops */ - } - } - if (node) { - int dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); - wmcursor = node_get_resize_cursor(dir); - } - } - } - - WM_cursor_set(win, wmcursor); + bNodeTree *ntree = snode->edittree; + bNode *node; + bNodeSocket *sock; + int wmcursor = CURSOR_STD; + + if (ntree) { + if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN | SOCK_OUT)) { + /* pass */ + } + else { + /* check nodes front to back */ + for (node = ntree->nodes.last; node; node = node->prev) { + if (BLI_rctf_isect_pt(&node->totr, cursor[0], cursor[1])) { + break; /* first hit on node stops */ + } + } + if (node) { + int dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); + wmcursor = node_get_resize_cursor(dir); + } + } + } + + WM_cursor_set(win, wmcursor); } -void node_draw_default(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey key) +void node_draw_default(const bContext *C, + ARegion *ar, + SpaceNode *snode, + bNodeTree *ntree, + bNode *node, + bNodeInstanceKey key) { - if (node->flag & NODE_HIDDEN) { - node_draw_hidden(C, ar, snode, ntree, node, key); - } - else { - node_draw_basis(C, ar, snode, ntree, node, key); - } + if (node->flag & NODE_HIDDEN) { + node_draw_hidden(C, ar, snode, ntree, node, key); + } + else { + node_draw_basis(C, ar, snode, ntree, node, key); + } } static void node_update(const bContext *C, bNodeTree *ntree, bNode *node) { - if (node->typeinfo->draw_nodetype_prepare) { - node->typeinfo->draw_nodetype_prepare(C, ntree, node); - } + if (node->typeinfo->draw_nodetype_prepare) { + node->typeinfo->draw_nodetype_prepare(C, ntree, node); + } } void node_update_nodetree(const bContext *C, bNodeTree *ntree) { - bNode *node; + bNode *node; - /* make sure socket "used" tags are correct, for displaying value buttons */ - ntreeTagUsedSockets(ntree); + /* make sure socket "used" tags are correct, for displaying value buttons */ + ntreeTagUsedSockets(ntree); - /* update nodes front to back, so children sizes get updated before parents */ - for (node = ntree->nodes.last; node; node = node->prev) { - node_update(C, ntree, node); - } + /* update nodes front to back, so children sizes get updated before parents */ + for (node = ntree->nodes.last; node; node = node->prev) { + node_update(C, ntree, node); + } } -static void node_draw(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey key) +static void node_draw(const bContext *C, + ARegion *ar, + SpaceNode *snode, + bNodeTree *ntree, + bNode *node, + bNodeInstanceKey key) { - if (node->typeinfo->draw_nodetype) { - node->typeinfo->draw_nodetype(C, ar, snode, ntree, node, key); - } + if (node->typeinfo->draw_nodetype) { + node->typeinfo->draw_nodetype(C, ar, snode, ntree, node, key); + } } #define USE_DRAW_TOT_UPDATE -void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNodeInstanceKey parent_key) +void node_draw_nodetree(const bContext *C, + ARegion *ar, + SpaceNode *snode, + bNodeTree *ntree, + bNodeInstanceKey parent_key) { - bNode *node; - bNodeLink *link; - int a; + bNode *node; + bNodeLink *link; + int a; - if (ntree == NULL) { - return; /* groups... */ - } + if (ntree == NULL) { + return; /* groups... */ + } #ifdef USE_DRAW_TOT_UPDATE - if (ntree->nodes.first) { - BLI_rctf_init_minmax(&ar->v2d.tot); - } + if (ntree->nodes.first) { + BLI_rctf_init_minmax(&ar->v2d.tot); + } #endif - /* draw background nodes, last nodes in front */ - for (a = 0, node = ntree->nodes.first; node; node = node->next, a++) { - bNodeInstanceKey key; + /* draw background nodes, last nodes in front */ + for (a = 0, node = ntree->nodes.first; node; node = node->next, a++) { + bNodeInstanceKey key; #ifdef USE_DRAW_TOT_UPDATE - /* unrelated to background nodes, update the v2d->tot, - * can be anywhere before we draw the scroll bars */ - BLI_rctf_union(&ar->v2d.tot, &node->totr); + /* unrelated to background nodes, update the v2d->tot, + * can be anywhere before we draw the scroll bars */ + BLI_rctf_union(&ar->v2d.tot, &node->totr); #endif - if (!(node->flag & NODE_BACKGROUND)) { - continue; - } - - key = BKE_node_instance_key(parent_key, ntree, node); - node->nr = a; /* index of node in list, used for exec event code */ - node_draw(C, ar, snode, ntree, node, key); - } - - /* node lines */ - GPU_blend(true); - nodelink_batch_start(snode); - for (link = ntree->links.first; link; link = link->next) { - if (!nodeLinkIsHidden(link)) { - node_draw_link(&ar->v2d, snode, link); - } - } - nodelink_batch_end(snode); - GPU_blend(false); - - /* draw foreground nodes, last nodes in front */ - for (a = 0, node = ntree->nodes.first; node; node = node->next, a++) { - bNodeInstanceKey key; - if (node->flag & NODE_BACKGROUND) { - continue; - } - - key = BKE_node_instance_key(parent_key, ntree, node); - node->nr = a; /* index of node in list, used for exec event code */ - node_draw(C, ar, snode, ntree, node, key); - } + if (!(node->flag & NODE_BACKGROUND)) { + continue; + } + + key = BKE_node_instance_key(parent_key, ntree, node); + node->nr = a; /* index of node in list, used for exec event code */ + node_draw(C, ar, snode, ntree, node, key); + } + + /* node lines */ + GPU_blend(true); + nodelink_batch_start(snode); + for (link = ntree->links.first; link; link = link->next) { + if (!nodeLinkIsHidden(link)) { + node_draw_link(&ar->v2d, snode, link); + } + } + nodelink_batch_end(snode); + GPU_blend(false); + + /* draw foreground nodes, last nodes in front */ + for (a = 0, node = ntree->nodes.first; node; node = node->next, a++) { + bNodeInstanceKey key; + if (node->flag & NODE_BACKGROUND) { + continue; + } + + key = BKE_node_instance_key(parent_key, ntree, node); + node->nr = a; /* index of node in list, used for exec event code */ + node_draw(C, ar, snode, ntree, node, key); + } } /* draw tree path info in lower left corner */ static void draw_tree_path(SpaceNode *snode) { - char info[256]; + char info[256]; - ED_node_tree_path_get_fixedbuf(snode, info, sizeof(info)); + ED_node_tree_path_get_fixedbuf(snode, info, sizeof(info)); - UI_FontThemeColor(BLF_default(), TH_TEXT_HI); - BLF_draw_default(1.5f * UI_UNIT_X, 1.5f * UI_UNIT_Y, 0.0f, info, sizeof(info)); + UI_FontThemeColor(BLF_default(), TH_TEXT_HI); + BLF_draw_default(1.5f * UI_UNIT_X, 1.5f * UI_UNIT_Y, 0.0f, info, sizeof(info)); } static void snode_setup_v2d(SpaceNode *snode, ARegion *ar, const float center[2]) { - View2D *v2d = &ar->v2d; + View2D *v2d = &ar->v2d; - /* shift view to node tree center */ - UI_view2d_center_set(v2d, center[0], center[1]); - UI_view2d_view_ortho(v2d); + /* shift view to node tree center */ + UI_view2d_center_set(v2d, center[0], center[1]); + UI_view2d_view_ortho(v2d); - /* aspect+font, set each time */ - snode->aspect = BLI_rctf_size_x(&v2d->cur) / (float)ar->winx; - // XXX snode->curfont = uiSetCurFont_ext(snode->aspect); + /* aspect+font, set each time */ + snode->aspect = BLI_rctf_size_x(&v2d->cur) / (float)ar->winx; + // XXX snode->curfont = uiSetCurFont_ext(snode->aspect); } -static void draw_nodetree(const bContext *C, ARegion *ar, bNodeTree *ntree, bNodeInstanceKey parent_key) +static void draw_nodetree(const bContext *C, + ARegion *ar, + bNodeTree *ntree, + bNodeInstanceKey parent_key) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - node_uiblocks_init(C, ntree); + node_uiblocks_init(C, ntree); - node_update_nodetree(C, ntree); - node_draw_nodetree(C, ar, snode, ntree, parent_key); + node_update_nodetree(C, ntree); + node_draw_nodetree(C, ar, snode, ntree, parent_key); } /* shade the parent node group and add a uiBlock to clip mouse events */ static void draw_group_overlay(const bContext *C, ARegion *ar) { - View2D *v2d = &ar->v2d; - rctf rect = v2d->cur; - uiBlock *block; - float color[4]; - - /* shade node groups to separate them visually */ - GPU_blend(true); - - UI_GetThemeColorShadeAlpha4fv(TH_NODE_GROUP, 0, 0, color); - UI_draw_roundbox_corner_set(UI_CNR_NONE); - UI_draw_roundbox_4fv(true, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 0, color); - GPU_blend(false); - - /* set the block bounds to clip mouse events from underlying nodes */ - block = UI_block_begin(C, ar, "node tree bounds block", UI_EMBOSS); - UI_block_bounds_set_explicit(block, rect.xmin, rect.ymin, rect.xmax, rect.ymax); - UI_block_flag_enable(block, UI_BLOCK_CLIP_EVENTS); - UI_block_end(C, block); + View2D *v2d = &ar->v2d; + rctf rect = v2d->cur; + uiBlock *block; + float color[4]; + + /* shade node groups to separate them visually */ + GPU_blend(true); + + UI_GetThemeColorShadeAlpha4fv(TH_NODE_GROUP, 0, 0, color); + UI_draw_roundbox_corner_set(UI_CNR_NONE); + UI_draw_roundbox_4fv(true, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 0, color); + GPU_blend(false); + + /* set the block bounds to clip mouse events from underlying nodes */ + block = UI_block_begin(C, ar, "node tree bounds block", UI_EMBOSS); + UI_block_bounds_set_explicit(block, rect.xmin, rect.ymin, rect.xmax, rect.ymax); + UI_block_flag_enable(block, UI_BLOCK_CLIP_EVENTS); + UI_block_end(C, block); } void drawnodespace(const bContext *C, ARegion *ar) { - wmWindow *win = CTX_wm_window(C); - View2DScrollers *scrollers; - SpaceNode *snode = CTX_wm_space_node(C); - View2D *v2d = &ar->v2d; - - UI_ThemeClearColor(TH_BACK); - GPU_clear(GPU_COLOR_BIT); - - UI_view2d_view_ortho(v2d); + wmWindow *win = CTX_wm_window(C); + View2DScrollers *scrollers; + SpaceNode *snode = CTX_wm_space_node(C); + View2D *v2d = &ar->v2d; - /* XXX snode->cursor set in coordspace for placing new nodes, used for drawing noodles too */ - UI_view2d_region_to_view(&ar->v2d, win->eventstate->x - ar->winrct.xmin, win->eventstate->y - ar->winrct.ymin, - &snode->cursor[0], &snode->cursor[1]); - snode->cursor[0] /= UI_DPI_FAC; - snode->cursor[1] /= UI_DPI_FAC; - - ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); - - /* only set once */ - GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); - - /* nodes */ - snode_set_context(C); - - /* draw parent node trees */ - if (snode->treepath.last) { - static const int max_depth = 2; - bNodeTreePath *path; - int depth, curdepth; - float center[2]; - bNodeTree *ntree; - bNodeLinkDrag *nldrag; - LinkData *linkdata; - - path = snode->treepath.last; - - /* update tree path name (drawn in the bottom left) */ - ID *name_id = (path->nodetree && path->nodetree != snode->nodetree) ? &path->nodetree->id : snode->id; - - if (name_id && UNLIKELY(!STREQ(path->node_name, name_id->name + 2))) { - BLI_strncpy(path->node_name, name_id->name + 2, sizeof(path->node_name)); - } - - /* current View2D center, will be set temporarily for parent node trees */ - UI_view2d_center_get(v2d, ¢er[0], ¢er[1]); - - /* store new view center in path and current edittree */ - copy_v2_v2(path->view_center, center); - if (snode->edittree) { - copy_v2_v2(snode->edittree->view_center, center); - } - - depth = 0; - while (path->prev && depth < max_depth) { - path = path->prev; - ++depth; - } - - /* parent node trees in the background */ - for (curdepth = depth; curdepth > 0; path = path->next, --curdepth) { - ntree = path->nodetree; - if (ntree) { - snode_setup_v2d(snode, ar, path->view_center); - - draw_nodetree(C, ar, ntree, path->parent_key); - - draw_group_overlay(C, ar); - } - } - - /* top-level edit tree */ - ntree = path->nodetree; - if (ntree) { - snode_setup_v2d(snode, ar, center); - - /* grid, uses theme color based on node path depth */ - UI_view2d_multi_grid_draw(v2d, (depth > 0 ? TH_NODE_GROUP : TH_BACK), ED_node_grid_size(), NODE_GRID_STEPS, 2); - - /* backdrop */ - draw_nodespace_back_pix(C, ar, snode, path->parent_key); - - { - float original_proj[4][4]; - GPU_matrix_projection_get(original_proj); - - GPU_matrix_push(); - GPU_matrix_identity_set(); - - wmOrtho2_pixelspace(ar->winx, ar->winy); - - WM_gizmomap_draw(ar->gizmo_map, C, WM_GIZMOMAP_DRAWSTEP_2D); - - GPU_matrix_pop(); - GPU_matrix_projection_set(original_proj); - } - - draw_nodetree(C, ar, ntree, path->parent_key); - } - - /* temporary links */ - GPU_blend(true); - GPU_line_smooth(true); - for (nldrag = snode->linkdrag.first; nldrag; nldrag = nldrag->next) { - for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { - node_draw_link(v2d, snode, (bNodeLink *)linkdata->data); - } - } - GPU_line_smooth(false); - GPU_blend(false); - - if (snode->flag & SNODE_SHOW_GPENCIL) { - /* draw grease-pencil ('canvas' strokes) */ - ED_annotation_draw_view2d(C, true); - } - } - else { - /* default grid */ - UI_view2d_multi_grid_draw(v2d, TH_BACK, ED_node_grid_size(), NODE_GRID_STEPS, 2); - - /* backdrop */ - draw_nodespace_back_pix(C, ar, snode, NODE_INSTANCE_KEY_NONE); - } - - ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); - - /* reset view matrix */ - UI_view2d_view_restore(C); - - if (snode->treepath.last) { - if (snode->flag & SNODE_SHOW_GPENCIL) { - /* draw grease-pencil (screen strokes, and also paintbuffer) */ - ED_annotation_draw_view2d(C, false); - } - } - - /* tree path info */ - draw_tree_path(snode); - - /* scrollers */ - scrollers = UI_view2d_scrollers_calc(C, v2d, NULL, 10, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); - UI_view2d_scrollers_free(scrollers); + UI_ThemeClearColor(TH_BACK); + GPU_clear(GPU_COLOR_BIT); + + UI_view2d_view_ortho(v2d); + + /* XXX snode->cursor set in coordspace for placing new nodes, used for drawing noodles too */ + UI_view2d_region_to_view(&ar->v2d, + win->eventstate->x - ar->winrct.xmin, + win->eventstate->y - ar->winrct.ymin, + &snode->cursor[0], + &snode->cursor[1]); + snode->cursor[0] /= UI_DPI_FAC; + snode->cursor[1] /= UI_DPI_FAC; + + ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); + + /* only set once */ + GPU_blend_set_func_separate( + GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + + /* nodes */ + snode_set_context(C); + + /* draw parent node trees */ + if (snode->treepath.last) { + static const int max_depth = 2; + bNodeTreePath *path; + int depth, curdepth; + float center[2]; + bNodeTree *ntree; + bNodeLinkDrag *nldrag; + LinkData *linkdata; + + path = snode->treepath.last; + + /* update tree path name (drawn in the bottom left) */ + ID *name_id = (path->nodetree && path->nodetree != snode->nodetree) ? &path->nodetree->id : + snode->id; + + if (name_id && UNLIKELY(!STREQ(path->node_name, name_id->name + 2))) { + BLI_strncpy(path->node_name, name_id->name + 2, sizeof(path->node_name)); + } + + /* current View2D center, will be set temporarily for parent node trees */ + UI_view2d_center_get(v2d, ¢er[0], ¢er[1]); + + /* store new view center in path and current edittree */ + copy_v2_v2(path->view_center, center); + if (snode->edittree) { + copy_v2_v2(snode->edittree->view_center, center); + } + + depth = 0; + while (path->prev && depth < max_depth) { + path = path->prev; + ++depth; + } + + /* parent node trees in the background */ + for (curdepth = depth; curdepth > 0; path = path->next, --curdepth) { + ntree = path->nodetree; + if (ntree) { + snode_setup_v2d(snode, ar, path->view_center); + + draw_nodetree(C, ar, ntree, path->parent_key); + + draw_group_overlay(C, ar); + } + } + + /* top-level edit tree */ + ntree = path->nodetree; + if (ntree) { + snode_setup_v2d(snode, ar, center); + + /* grid, uses theme color based on node path depth */ + UI_view2d_multi_grid_draw( + v2d, (depth > 0 ? TH_NODE_GROUP : TH_BACK), ED_node_grid_size(), NODE_GRID_STEPS, 2); + + /* backdrop */ + draw_nodespace_back_pix(C, ar, snode, path->parent_key); + + { + float original_proj[4][4]; + GPU_matrix_projection_get(original_proj); + + GPU_matrix_push(); + GPU_matrix_identity_set(); + + wmOrtho2_pixelspace(ar->winx, ar->winy); + + WM_gizmomap_draw(ar->gizmo_map, C, WM_GIZMOMAP_DRAWSTEP_2D); + + GPU_matrix_pop(); + GPU_matrix_projection_set(original_proj); + } + + draw_nodetree(C, ar, ntree, path->parent_key); + } + + /* temporary links */ + GPU_blend(true); + GPU_line_smooth(true); + for (nldrag = snode->linkdrag.first; nldrag; nldrag = nldrag->next) { + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { + node_draw_link(v2d, snode, (bNodeLink *)linkdata->data); + } + } + GPU_line_smooth(false); + GPU_blend(false); + + if (snode->flag & SNODE_SHOW_GPENCIL) { + /* draw grease-pencil ('canvas' strokes) */ + ED_annotation_draw_view2d(C, true); + } + } + else { + /* default grid */ + UI_view2d_multi_grid_draw(v2d, TH_BACK, ED_node_grid_size(), NODE_GRID_STEPS, 2); + + /* backdrop */ + draw_nodespace_back_pix(C, ar, snode, NODE_INSTANCE_KEY_NONE); + } + + ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); + + /* reset view matrix */ + UI_view2d_view_restore(C); + + if (snode->treepath.last) { + if (snode->flag & SNODE_SHOW_GPENCIL) { + /* draw grease-pencil (screen strokes, and also paintbuffer) */ + ED_annotation_draw_view2d(C, false); + } + } + + /* tree path info */ + draw_tree_path(snode); + + /* scrollers */ + scrollers = UI_view2d_scrollers_calc( + C, v2d, NULL, 10, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); + UI_view2d_scrollers_draw(C, v2d, scrollers); + UI_view2d_scrollers_free(scrollers); } diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 27efb6c9a10..84f512957c7 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -46,8 +46,7 @@ #include "RE_engine.h" #include "RE_pipeline.h" - -#include "ED_node.h" /* own include */ +#include "ED_node.h" /* own include */ #include "ED_select_utils.h" #include "ED_screen.h" #include "ED_render.h" @@ -65,199 +64,210 @@ #include "IMB_imbuf_types.h" -#include "node_intern.h" /* own include */ +#include "node_intern.h" /* own include */ #include "NOD_composite.h" #include "NOD_shader.h" #include "NOD_texture.h" - #define USE_ESC_COMPO /* ***************** composite job manager ********************** */ enum { - COM_RECALC_COMPOSITE = 1, - COM_RECALC_VIEWER = 2, + COM_RECALC_COMPOSITE = 1, + COM_RECALC_VIEWER = 2, }; typedef struct CompoJob { - Main *bmain; - Scene *scene; - bNodeTree *ntree; - bNodeTree *localtree; - const short *stop; - short *do_update; - float *progress; - int recalc_flags; + Main *bmain; + Scene *scene; + bNodeTree *ntree; + bNodeTree *localtree; + const short *stop; + short *do_update; + float *progress; + int recalc_flags; } CompoJob; static void compo_tag_output_nodes(bNodeTree *nodetree, int recalc_flags) { - bNode *node; - - for (node = nodetree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_COMPOSITE) { - if (recalc_flags & COM_RECALC_COMPOSITE) { - node->flag |= NODE_DO_OUTPUT_RECALC; - } - } - else if (node->type == CMP_NODE_VIEWER || node->type == CMP_NODE_SPLITVIEWER) { - if (recalc_flags & COM_RECALC_VIEWER) { - node->flag |= NODE_DO_OUTPUT_RECALC; - } - } - else if (node->type == NODE_GROUP) { - if (node->id) { - compo_tag_output_nodes((bNodeTree *)node->id, recalc_flags); - } - } - } + bNode *node; + + for (node = nodetree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_COMPOSITE) { + if (recalc_flags & COM_RECALC_COMPOSITE) { + node->flag |= NODE_DO_OUTPUT_RECALC; + } + } + else if (node->type == CMP_NODE_VIEWER || node->type == CMP_NODE_SPLITVIEWER) { + if (recalc_flags & COM_RECALC_VIEWER) { + node->flag |= NODE_DO_OUTPUT_RECALC; + } + } + else if (node->type == NODE_GROUP) { + if (node->id) { + compo_tag_output_nodes((bNodeTree *)node->id, recalc_flags); + } + } + } } static int compo_get_recalc_flags(const bContext *C) { - wmWindowManager *wm = CTX_wm_manager(C); - wmWindow *win; - int recalc_flags = 0; - - for (win = wm->windows.first; win; win = win->next) { - const bScreen *sc = WM_window_get_active_screen(win); - ScrArea *sa; - - for (sa = sc->areabase.first; sa; sa = sa->next) { - if (sa->spacetype == SPACE_IMAGE) { - SpaceImage *sima = sa->spacedata.first; - if (sima->image) { - if (sima->image->type == IMA_TYPE_R_RESULT) { - recalc_flags |= COM_RECALC_COMPOSITE; - } - else if (sima->image->type == IMA_TYPE_COMPOSITE) { - recalc_flags |= COM_RECALC_VIEWER; - } - } - } - else if (sa->spacetype == SPACE_NODE) { - SpaceNode *snode = sa->spacedata.first; - if (snode->flag & SNODE_BACKDRAW) { - recalc_flags |= COM_RECALC_VIEWER; - } - } - } - } - - return recalc_flags; + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win; + int recalc_flags = 0; + + for (win = wm->windows.first; win; win = win->next) { + const bScreen *sc = WM_window_get_active_screen(win); + ScrArea *sa; + + for (sa = sc->areabase.first; sa; sa = sa->next) { + if (sa->spacetype == SPACE_IMAGE) { + SpaceImage *sima = sa->spacedata.first; + if (sima->image) { + if (sima->image->type == IMA_TYPE_R_RESULT) { + recalc_flags |= COM_RECALC_COMPOSITE; + } + else if (sima->image->type == IMA_TYPE_COMPOSITE) { + recalc_flags |= COM_RECALC_VIEWER; + } + } + } + else if (sa->spacetype == SPACE_NODE) { + SpaceNode *snode = sa->spacedata.first; + if (snode->flag & SNODE_BACKDRAW) { + recalc_flags |= COM_RECALC_VIEWER; + } + } + } + } + + return recalc_flags; } /* called by compo, only to check job 'stop' value */ static int compo_breakjob(void *cjv) { - CompoJob *cj = cjv; + CompoJob *cj = cjv; - /* without G.is_break 'ESC' wont quit - which annoys users */ - return (*(cj->stop) + /* without G.is_break 'ESC' wont quit - which annoys users */ + return (*(cj->stop) #ifdef USE_ESC_COMPO - || - G.is_break + || G.is_break #endif - ); + ); } /* called by compo, wmJob sends notifier */ static void compo_statsdrawjob(void *cjv, const char *UNUSED(str)) { - CompoJob *cj = cjv; + CompoJob *cj = cjv; - *(cj->do_update) = true; + *(cj->do_update) = true; } /* called by compo, wmJob sends notifier */ static void compo_redrawjob(void *cjv) { - CompoJob *cj = cjv; + CompoJob *cj = cjv; - *(cj->do_update) = true; + *(cj->do_update) = true; } static void compo_freejob(void *cjv) { - CompoJob *cj = cjv; + CompoJob *cj = cjv; - if (cj->localtree) { - ntreeLocalMerge(cj->bmain, cj->localtree, cj->ntree); - } - MEM_freeN(cj); + if (cj->localtree) { + ntreeLocalMerge(cj->bmain, cj->localtree, cj->ntree); + } + MEM_freeN(cj); } /* only now we copy the nodetree, so adding many jobs while * sliding buttons doesn't frustrate */ static void compo_initjob(void *cjv) { - CompoJob *cj = cjv; + CompoJob *cj = cjv; - cj->localtree = ntreeLocalize(cj->ntree); + cj->localtree = ntreeLocalize(cj->ntree); - if (cj->recalc_flags) { - compo_tag_output_nodes(cj->localtree, cj->recalc_flags); - } + if (cj->recalc_flags) { + compo_tag_output_nodes(cj->localtree, cj->recalc_flags); + } } /* called before redraw notifiers, it moves finished previews over */ static void compo_updatejob(void *UNUSED(cjv)) { - WM_main_add_notifier(NC_SCENE | ND_COMPO_RESULT, NULL); + WM_main_add_notifier(NC_SCENE | ND_COMPO_RESULT, NULL); } static void compo_progressjob(void *cjv, float progress) { - CompoJob *cj = cjv; + CompoJob *cj = cjv; - *(cj->progress) = progress; + *(cj->progress) = progress; } /* only this runs inside thread */ static void compo_startjob(void *cjv, short *stop, short *do_update, float *progress) { - CompoJob *cj = cjv; - bNodeTree *ntree = cj->localtree; - Scene *scene = cj->scene; - SceneRenderView *srv; - - if (scene->use_nodes == false) { - return; - } - - cj->stop = stop; - cj->do_update = do_update; - cj->progress = progress; - - ntree->test_break = compo_breakjob; - ntree->tbh = cj; - ntree->stats_draw = compo_statsdrawjob; - ntree->sdh = cj; - ntree->progress = compo_progressjob; - ntree->prh = cj; - ntree->update_draw = compo_redrawjob; - ntree->udh = cj; - - // XXX BIF_store_spare(); - /* 1 is do_previews */ - - if ((cj->scene->r.scemode & R_MULTIVIEW) == 0) { - ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, false, true, &scene->view_settings, &scene->display_settings, ""); - } - else { - for (srv = scene->r.views.first; srv; srv = srv->next) { - if (BKE_scene_multiview_is_render_view_active(&scene->r, srv) == false) { - continue; - } - ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, false, true, &scene->view_settings, &scene->display_settings, srv->name); - } - } - - ntree->test_break = NULL; - ntree->stats_draw = NULL; - ntree->progress = NULL; - + CompoJob *cj = cjv; + bNodeTree *ntree = cj->localtree; + Scene *scene = cj->scene; + SceneRenderView *srv; + + if (scene->use_nodes == false) { + return; + } + + cj->stop = stop; + cj->do_update = do_update; + cj->progress = progress; + + ntree->test_break = compo_breakjob; + ntree->tbh = cj; + ntree->stats_draw = compo_statsdrawjob; + ntree->sdh = cj; + ntree->progress = compo_progressjob; + ntree->prh = cj; + ntree->update_draw = compo_redrawjob; + ntree->udh = cj; + + // XXX BIF_store_spare(); + /* 1 is do_previews */ + + if ((cj->scene->r.scemode & R_MULTIVIEW) == 0) { + ntreeCompositExecTree(cj->scene, + ntree, + &cj->scene->r, + false, + true, + &scene->view_settings, + &scene->display_settings, + ""); + } + else { + for (srv = scene->r.views.first; srv; srv = srv->next) { + if (BKE_scene_multiview_is_render_view_active(&scene->r, srv) == false) { + continue; + } + ntreeCompositExecTree(cj->scene, + ntree, + &cj->scene->r, + false, + true, + &scene->view_settings, + &scene->display_settings, + srv->name); + } + } + + ntree->test_break = NULL; + ntree->stats_draw = NULL; + ntree->progress = NULL; } /** @@ -269,38 +279,43 @@ static void compo_startjob(void *cjv, short *stop, short *do_update, float *prog */ void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene *scene_owner) { - wmJob *wm_job; - CompoJob *cj; - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); + wmJob *wm_job; + CompoJob *cj; + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); - /* to fix bug: [#32272] */ - if (G.is_rendering) { - return; - } + /* to fix bug: [#32272] */ + if (G.is_rendering) { + return; + } #ifdef USE_ESC_COMPO - G.is_break = false; + G.is_break = false; #endif - BKE_image_backup_render(scene, BKE_image_verify_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result"), false); + BKE_image_backup_render( + scene, BKE_image_verify_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result"), false); - wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene_owner, "Compositing", - WM_JOB_EXCL_RENDER | WM_JOB_PROGRESS, WM_JOB_TYPE_COMPOSITE); - cj = MEM_callocN(sizeof(CompoJob), "compo job"); + wm_job = WM_jobs_get(CTX_wm_manager(C), + CTX_wm_window(C), + scene_owner, + "Compositing", + WM_JOB_EXCL_RENDER | WM_JOB_PROGRESS, + WM_JOB_TYPE_COMPOSITE); + cj = MEM_callocN(sizeof(CompoJob), "compo job"); - /* customdata for preview thread */ - cj->bmain = bmain; - cj->scene = scene; - cj->ntree = nodetree; - cj->recalc_flags = compo_get_recalc_flags(C); + /* customdata for preview thread */ + cj->bmain = bmain; + cj->scene = scene; + cj->ntree = nodetree; + cj->recalc_flags = compo_get_recalc_flags(C); - /* setup job */ - WM_jobs_customdata_set(wm_job, cj, compo_freejob); - WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_COMPO_RESULT, NC_SCENE | ND_COMPO_RESULT); - WM_jobs_callbacks(wm_job, compo_startjob, compo_initjob, compo_updatejob, NULL); + /* setup job */ + WM_jobs_customdata_set(wm_job, cj, compo_freejob); + WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_COMPO_RESULT, NC_SCENE | ND_COMPO_RESULT); + WM_jobs_callbacks(wm_job, compo_startjob, compo_initjob, compo_updatejob, NULL); - WM_jobs_start(CTX_wm_manager(C), wm_job); + WM_jobs_start(CTX_wm_manager(C), wm_job); } /* ***************************************** */ @@ -308,447 +323,449 @@ void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene /* operator poll callback */ bool composite_node_active(bContext *C) { - if (ED_operator_node_active(C)) { - SpaceNode *snode = CTX_wm_space_node(C); - if (ED_node_is_compositor(snode)) { - return 1; - } - } - return 0; + if (ED_operator_node_active(C)) { + SpaceNode *snode = CTX_wm_space_node(C); + if (ED_node_is_compositor(snode)) { + return 1; + } + } + return 0; } /* operator poll callback */ bool composite_node_editable(bContext *C) { - if (ED_operator_node_editable(C)) { - SpaceNode *snode = CTX_wm_space_node(C); - if (ED_node_is_compositor(snode)) { - return 1; - } - } - return 0; + if (ED_operator_node_editable(C)) { + SpaceNode *snode = CTX_wm_space_node(C); + if (ED_node_is_compositor(snode)) { + return 1; + } + } + return 0; } void snode_dag_update(bContext *C, SpaceNode *snode) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(C); - /* for groups, update all ID's using this */ - if (snode->edittree != snode->nodetree) { - FOREACH_NODETREE_BEGIN(bmain, tntree, id) { - if (ntreeHasTree(tntree, snode->edittree)) { - DEG_id_tag_update(id, 0); - } - } FOREACH_NODETREE_END; - } + /* for groups, update all ID's using this */ + if (snode->edittree != snode->nodetree) { + FOREACH_NODETREE_BEGIN (bmain, tntree, id) { + if (ntreeHasTree(tntree, snode->edittree)) { + DEG_id_tag_update(id, 0); + } + } + FOREACH_NODETREE_END; + } - DEG_id_tag_update(snode->id, 0); + DEG_id_tag_update(snode->id, 0); } void snode_notify(bContext *C, SpaceNode *snode) { - ID *id = snode->id; - - WM_event_add_notifier(C, NC_NODE | NA_EDITED, NULL); - - if (ED_node_is_shader(snode)) { - if (GS(id->name) == ID_MA) { - WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id); - } - else if (GS(id->name) == ID_LA) { - WM_main_add_notifier(NC_LAMP | ND_LIGHTING, id); - } - else if (GS(id->name) == ID_WO) { - WM_main_add_notifier(NC_WORLD | ND_WORLD, id); - } - } - else if (ED_node_is_compositor(snode)) { - WM_event_add_notifier(C, NC_SCENE | ND_NODES, id); - } - else if (ED_node_is_texture(snode)) { - WM_event_add_notifier(C, NC_TEXTURE | ND_NODES, id); - } + ID *id = snode->id; + + WM_event_add_notifier(C, NC_NODE | NA_EDITED, NULL); + + if (ED_node_is_shader(snode)) { + if (GS(id->name) == ID_MA) { + WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id); + } + else if (GS(id->name) == ID_LA) { + WM_main_add_notifier(NC_LAMP | ND_LIGHTING, id); + } + else if (GS(id->name) == ID_WO) { + WM_main_add_notifier(NC_WORLD | ND_WORLD, id); + } + } + else if (ED_node_is_compositor(snode)) { + WM_event_add_notifier(C, NC_SCENE | ND_NODES, id); + } + else if (ED_node_is_texture(snode)) { + WM_event_add_notifier(C, NC_TEXTURE | ND_NODES, id); + } } void ED_node_set_tree_type(SpaceNode *snode, bNodeTreeType *typeinfo) { - if (typeinfo) { - BLI_strncpy(snode->tree_idname, typeinfo->idname, sizeof(snode->tree_idname)); - } - else { - snode->tree_idname[0] = '\0'; - } + if (typeinfo) { + BLI_strncpy(snode->tree_idname, typeinfo->idname, sizeof(snode->tree_idname)); + } + else { + snode->tree_idname[0] = '\0'; + } } bool ED_node_is_compositor(struct SpaceNode *snode) { - return STREQ(snode->tree_idname, ntreeType_Composite->idname); + return STREQ(snode->tree_idname, ntreeType_Composite->idname); } bool ED_node_is_shader(struct SpaceNode *snode) { - return STREQ(snode->tree_idname, ntreeType_Shader->idname); + return STREQ(snode->tree_idname, ntreeType_Shader->idname); } bool ED_node_is_texture(struct SpaceNode *snode) { - return STREQ(snode->tree_idname, ntreeType_Texture->idname); + return STREQ(snode->tree_idname, ntreeType_Texture->idname); } /* assumes nothing being done in ntree yet, sets the default in/out node */ /* called from shading buttons or header */ void ED_node_shader_default(const bContext *C, ID *id) { - bNode *in, *out; - bNodeSocket *fromsock, *tosock, *sock; - bNodeTree *ntree; - int output_type, shader_type; - float color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }, strength = 1.0f; - - ntree = ntreeAddTree(NULL, "Shader Nodetree", ntreeType_Shader->idname); - - switch (GS(id->name)) { - case ID_MA: - { - Material *ma = (Material *)id; - ma->nodetree = ntree; - - output_type = SH_NODE_OUTPUT_MATERIAL; - shader_type = SH_NODE_BSDF_PRINCIPLED; - - copy_v3_v3(color, &ma->r); - strength = 0.0f; - break; - } - case ID_WO: - { - World *wo = (World *)id; - wo->nodetree = ntree; - - output_type = SH_NODE_OUTPUT_WORLD; - shader_type = SH_NODE_BACKGROUND; - - copy_v3_v3(color, &wo->horr); - strength = 1.0f; - break; - } - case ID_LA: - { - Light *la = (Light *)id; - la->nodetree = ntree; - - output_type = SH_NODE_OUTPUT_LIGHT; - shader_type = SH_NODE_EMISSION; - - copy_v3_v3(color, &la->r); - if (la->type == LA_LOCAL || la->type == LA_SPOT || la->type == LA_AREA) { - strength = 100.0f; - } - else { - strength = 1.0f; - } - break; - } - default: - printf("ED_node_shader_default called on wrong ID type.\n"); - return; - } - - out = nodeAddStaticNode(C, ntree, output_type); - out->locx = 300.0f; out->locy = 300.0f; - - in = nodeAddStaticNode(C, ntree, shader_type); - in->locx = 10.0f; in->locy = 300.0f; - nodeSetActive(ntree, in); - - /* only a link from color to color */ - fromsock = in->outputs.first; - tosock = out->inputs.first; - nodeAddLink(ntree, in, fromsock, out, tosock); - - /* default values */ - PointerRNA sockptr; - sock = in->inputs.first; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sockptr); - - RNA_float_set_array(&sockptr, "default_value", color); - - if (strength != 0.0f) { - sock = in->inputs.last; - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sockptr); - RNA_float_set(&sockptr, "default_value", strength); - } - - ntreeUpdateTree(CTX_data_main(C), ntree); + bNode *in, *out; + bNodeSocket *fromsock, *tosock, *sock; + bNodeTree *ntree; + int output_type, shader_type; + float color[4] = {0.0f, 0.0f, 0.0f, 1.0f}, strength = 1.0f; + + ntree = ntreeAddTree(NULL, "Shader Nodetree", ntreeType_Shader->idname); + + switch (GS(id->name)) { + case ID_MA: { + Material *ma = (Material *)id; + ma->nodetree = ntree; + + output_type = SH_NODE_OUTPUT_MATERIAL; + shader_type = SH_NODE_BSDF_PRINCIPLED; + + copy_v3_v3(color, &ma->r); + strength = 0.0f; + break; + } + case ID_WO: { + World *wo = (World *)id; + wo->nodetree = ntree; + + output_type = SH_NODE_OUTPUT_WORLD; + shader_type = SH_NODE_BACKGROUND; + + copy_v3_v3(color, &wo->horr); + strength = 1.0f; + break; + } + case ID_LA: { + Light *la = (Light *)id; + la->nodetree = ntree; + + output_type = SH_NODE_OUTPUT_LIGHT; + shader_type = SH_NODE_EMISSION; + + copy_v3_v3(color, &la->r); + if (la->type == LA_LOCAL || la->type == LA_SPOT || la->type == LA_AREA) { + strength = 100.0f; + } + else { + strength = 1.0f; + } + break; + } + default: + printf("ED_node_shader_default called on wrong ID type.\n"); + return; + } + + out = nodeAddStaticNode(C, ntree, output_type); + out->locx = 300.0f; + out->locy = 300.0f; + + in = nodeAddStaticNode(C, ntree, shader_type); + in->locx = 10.0f; + in->locy = 300.0f; + nodeSetActive(ntree, in); + + /* only a link from color to color */ + fromsock = in->outputs.first; + tosock = out->inputs.first; + nodeAddLink(ntree, in, fromsock, out, tosock); + + /* default values */ + PointerRNA sockptr; + sock = in->inputs.first; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sockptr); + + RNA_float_set_array(&sockptr, "default_value", color); + + if (strength != 0.0f) { + sock = in->inputs.last; + RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sockptr); + RNA_float_set(&sockptr, "default_value", strength); + } + + ntreeUpdateTree(CTX_data_main(C), ntree); } /* assumes nothing being done in ntree yet, sets the default in/out node */ /* called from shading buttons or header */ void ED_node_composit_default(const bContext *C, struct Scene *sce) { - bNode *in, *out; - bNodeSocket *fromsock, *tosock; + bNode *in, *out; + bNodeSocket *fromsock, *tosock; - /* but lets check it anyway */ - if (sce->nodetree) { - if (G.debug & G_DEBUG) { - printf("error in composite initialize\n"); - } - return; - } + /* but lets check it anyway */ + if (sce->nodetree) { + if (G.debug & G_DEBUG) { + printf("error in composite initialize\n"); + } + return; + } - sce->nodetree = ntreeAddTree(NULL, "Compositing Nodetree", ntreeType_Composite->idname); + sce->nodetree = ntreeAddTree(NULL, "Compositing Nodetree", ntreeType_Composite->idname); - sce->nodetree->chunksize = 256; - sce->nodetree->edit_quality = NTREE_QUALITY_HIGH; - sce->nodetree->render_quality = NTREE_QUALITY_HIGH; + sce->nodetree->chunksize = 256; + sce->nodetree->edit_quality = NTREE_QUALITY_HIGH; + sce->nodetree->render_quality = NTREE_QUALITY_HIGH; - out = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_COMPOSITE); - out->locx = 300.0f; out->locy = 400.0f; + out = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_COMPOSITE); + out->locx = 300.0f; + out->locy = 400.0f; - in = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_R_LAYERS); - in->locx = 10.0f; in->locy = 400.0f; - nodeSetActive(sce->nodetree, in); + in = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_R_LAYERS); + in->locx = 10.0f; + in->locy = 400.0f; + nodeSetActive(sce->nodetree, in); - /* links from color to color */ - fromsock = in->outputs.first; - tosock = out->inputs.first; - nodeAddLink(sce->nodetree, in, fromsock, out, tosock); + /* links from color to color */ + fromsock = in->outputs.first; + tosock = out->inputs.first; + nodeAddLink(sce->nodetree, in, fromsock, out, tosock); - ntreeUpdateTree(CTX_data_main(C), sce->nodetree); + ntreeUpdateTree(CTX_data_main(C), sce->nodetree); } /* assumes nothing being done in ntree yet, sets the default in/out node */ /* called from shading buttons or header */ void ED_node_texture_default(const bContext *C, Tex *tx) { - bNode *in, *out; - bNodeSocket *fromsock, *tosock; + bNode *in, *out; + bNodeSocket *fromsock, *tosock; - /* but lets check it anyway */ - if (tx->nodetree) { - if (G.debug & G_DEBUG) { - printf("error in texture initialize\n"); - } - return; - } + /* but lets check it anyway */ + if (tx->nodetree) { + if (G.debug & G_DEBUG) { + printf("error in texture initialize\n"); + } + return; + } - tx->nodetree = ntreeAddTree(NULL, "Texture Nodetree", ntreeType_Texture->idname); + tx->nodetree = ntreeAddTree(NULL, "Texture Nodetree", ntreeType_Texture->idname); - out = nodeAddStaticNode(C, tx->nodetree, TEX_NODE_OUTPUT); - out->locx = 300.0f; out->locy = 300.0f; + out = nodeAddStaticNode(C, tx->nodetree, TEX_NODE_OUTPUT); + out->locx = 300.0f; + out->locy = 300.0f; - in = nodeAddStaticNode(C, tx->nodetree, TEX_NODE_CHECKER); - in->locx = 10.0f; in->locy = 300.0f; - nodeSetActive(tx->nodetree, in); + in = nodeAddStaticNode(C, tx->nodetree, TEX_NODE_CHECKER); + in->locx = 10.0f; + in->locy = 300.0f; + nodeSetActive(tx->nodetree, in); - fromsock = in->outputs.first; - tosock = out->inputs.first; - nodeAddLink(tx->nodetree, in, fromsock, out, tosock); + fromsock = in->outputs.first; + tosock = out->inputs.first; + nodeAddLink(tx->nodetree, in, fromsock, out, tosock); - ntreeUpdateTree(CTX_data_main(C), tx->nodetree); + ntreeUpdateTree(CTX_data_main(C), tx->nodetree); } /* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */ void snode_set_context(const bContext *C) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTreeType *treetype = ntreeTypeFind(snode->tree_idname); - bNodeTree *ntree = snode->nodetree; - ID *id = snode->id, *from = snode->from; - - /* check the tree type */ - if (!treetype || - (treetype->poll && !treetype->poll(C, treetype))) - { - /* invalid tree type, skip - * NB: not resetting the node path here, invalid bNodeTreeType - * may still be registered at a later point. - */ - return; - } - - if (snode->nodetree && !STREQ(snode->nodetree->idname, snode->tree_idname)) { - /* current tree does not match selected type, clear tree path */ - ntree = NULL; - id = NULL; - from = NULL; - } - - if (!(snode->flag & SNODE_PIN) || ntree == NULL) { - if (treetype->get_from_context) { - /* reset and update from context */ - ntree = NULL; - id = NULL; - from = NULL; - - treetype->get_from_context(C, treetype, &ntree, &id, &from); - } - } - - if (snode->nodetree != ntree || snode->id != id || snode->from != from || - (snode->treepath.last == NULL && ntree)) - { - ED_node_tree_start(snode, ntree, id, from); - } + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTreeType *treetype = ntreeTypeFind(snode->tree_idname); + bNodeTree *ntree = snode->nodetree; + ID *id = snode->id, *from = snode->from; + + /* check the tree type */ + if (!treetype || (treetype->poll && !treetype->poll(C, treetype))) { + /* invalid tree type, skip + * NB: not resetting the node path here, invalid bNodeTreeType + * may still be registered at a later point. + */ + return; + } + + if (snode->nodetree && !STREQ(snode->nodetree->idname, snode->tree_idname)) { + /* current tree does not match selected type, clear tree path */ + ntree = NULL; + id = NULL; + from = NULL; + } + + if (!(snode->flag & SNODE_PIN) || ntree == NULL) { + if (treetype->get_from_context) { + /* reset and update from context */ + ntree = NULL; + id = NULL; + from = NULL; + + treetype->get_from_context(C, treetype, &ntree, &id, &from); + } + } + + if (snode->nodetree != ntree || snode->id != id || snode->from != from || + (snode->treepath.last == NULL && ntree)) { + ED_node_tree_start(snode, ntree, id, from); + } } void snode_update(SpaceNode *snode, bNode *node) { - bNodeTreePath *path; + bNodeTreePath *path; - /* XXX this only updates nodes in the current node space tree path. - * The function supposedly should update any potential group node linking to changed tree, - * this really requires a working depsgraph ... - */ + /* XXX this only updates nodes in the current node space tree path. + * The function supposedly should update any potential group node linking to changed tree, + * this really requires a working depsgraph ... + */ - /* update all edited group nodes */ - path = snode->treepath.last; - if (path) { - bNodeTree *ngroup = path->nodetree; - for (path = path->prev; path; path = path->prev) { - nodeUpdateID(path->nodetree, (ID *)ngroup); - ngroup = path->nodetree; - } - } + /* update all edited group nodes */ + path = snode->treepath.last; + if (path) { + bNodeTree *ngroup = path->nodetree; + for (path = path->prev; path; path = path->prev) { + nodeUpdateID(path->nodetree, (ID *)ngroup); + ngroup = path->nodetree; + } + } - if (node) { - nodeUpdate(snode->edittree, node); - } + if (node) { + nodeUpdate(snode->edittree, node); + } } void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node) { - const bool was_active_texture = (node->flag & NODE_ACTIVE_TEXTURE) != 0; - - nodeSetActive(ntree, node); - - if (node->type != NODE_GROUP) { - const bool was_output = (node->flag & NODE_DO_OUTPUT) != 0; - bool do_update = false; - - /* generic node group output: set node as active output */ - if (node->type == NODE_GROUP_OUTPUT) { - bNode *tnode; - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { - if (tnode->type == NODE_GROUP_OUTPUT) { - tnode->flag &= ~NODE_DO_OUTPUT; - } - } - - node->flag |= NODE_DO_OUTPUT; - if (!was_output) { - do_update = 1; - } - } - - /* tree specific activate calls */ - if (ntree->type == NTREE_SHADER) { - /* when we select a material, active texture is cleared, for buttons */ - if (node->id && ELEM(GS(node->id->name), ID_MA, ID_LA, ID_WO)) { - nodeClearActiveID(ntree, ID_TE); - } - - if (ELEM(node->type, SH_NODE_OUTPUT_MATERIAL, - SH_NODE_OUTPUT_WORLD, SH_NODE_OUTPUT_LIGHT, SH_NODE_OUTPUT_LINESTYLE)) - { - bNode *tnode; - - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { - if (tnode->type == node->type) { - tnode->flag &= ~NODE_DO_OUTPUT; - } - } - - node->flag |= NODE_DO_OUTPUT; - if (was_output == 0) { - ED_node_tag_update_nodetree(bmain, ntree, node); - } - } - else if (do_update) { - ED_node_tag_update_nodetree(bmain, ntree, node); - } - - /* if active texture changed, free glsl materials */ - if ((node->flag & NODE_ACTIVE_TEXTURE) && !was_active_texture) { - Material *ma; - World *wo; - - for (ma = bmain->materials.first; ma; ma = ma->id.next) { - if (ma->nodetree && ma->use_nodes && ntreeHasTree(ma->nodetree, ntree)) { - GPU_material_free(&ma->gpumaterial); - } - } - - for (wo = bmain->worlds.first; wo; wo = wo->id.next) { - if (wo->nodetree && wo->use_nodes && ntreeHasTree(wo->nodetree, ntree)) { - GPU_material_free(&wo->gpumaterial); - } - } - - ED_node_tag_update_nodetree(bmain, ntree, node); - WM_main_add_notifier(NC_IMAGE, NULL); - } - - WM_main_add_notifier(NC_MATERIAL | ND_NODES, node->id); - } - else if (ntree->type == NTREE_COMPOSIT) { - /* make active viewer, currently only 1 supported... */ - if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { - bNode *tnode; - - - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { - if (ELEM(tnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { - tnode->flag &= ~NODE_DO_OUTPUT; - } - } - - node->flag |= NODE_DO_OUTPUT; - if (was_output == 0) { - ED_node_tag_update_nodetree(bmain, ntree, node); - } - - /* addnode() doesn't link this yet... */ - node->id = (ID *)BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - } - else if (node->type == CMP_NODE_COMPOSITE) { - if (was_output == 0) { - bNode *tnode; - - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { - if (tnode->type == CMP_NODE_COMPOSITE) { - tnode->flag &= ~NODE_DO_OUTPUT; - } - } - - node->flag |= NODE_DO_OUTPUT; - ED_node_tag_update_nodetree(bmain, ntree, node); - } - } - else if (do_update) { - ED_node_tag_update_nodetree(bmain, ntree, node); - } - } - else if (ntree->type == NTREE_TEXTURE) { - // XXX + const bool was_active_texture = (node->flag & NODE_ACTIVE_TEXTURE) != 0; + + nodeSetActive(ntree, node); + + if (node->type != NODE_GROUP) { + const bool was_output = (node->flag & NODE_DO_OUTPUT) != 0; + bool do_update = false; + + /* generic node group output: set node as active output */ + if (node->type == NODE_GROUP_OUTPUT) { + bNode *tnode; + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { + if (tnode->type == NODE_GROUP_OUTPUT) { + tnode->flag &= ~NODE_DO_OUTPUT; + } + } + + node->flag |= NODE_DO_OUTPUT; + if (!was_output) { + do_update = 1; + } + } + + /* tree specific activate calls */ + if (ntree->type == NTREE_SHADER) { + /* when we select a material, active texture is cleared, for buttons */ + if (node->id && ELEM(GS(node->id->name), ID_MA, ID_LA, ID_WO)) { + nodeClearActiveID(ntree, ID_TE); + } + + if (ELEM(node->type, + SH_NODE_OUTPUT_MATERIAL, + SH_NODE_OUTPUT_WORLD, + SH_NODE_OUTPUT_LIGHT, + SH_NODE_OUTPUT_LINESTYLE)) { + bNode *tnode; + + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { + if (tnode->type == node->type) { + tnode->flag &= ~NODE_DO_OUTPUT; + } + } + + node->flag |= NODE_DO_OUTPUT; + if (was_output == 0) { + ED_node_tag_update_nodetree(bmain, ntree, node); + } + } + else if (do_update) { + ED_node_tag_update_nodetree(bmain, ntree, node); + } + + /* if active texture changed, free glsl materials */ + if ((node->flag & NODE_ACTIVE_TEXTURE) && !was_active_texture) { + Material *ma; + World *wo; + + for (ma = bmain->materials.first; ma; ma = ma->id.next) { + if (ma->nodetree && ma->use_nodes && ntreeHasTree(ma->nodetree, ntree)) { + GPU_material_free(&ma->gpumaterial); + } + } + + for (wo = bmain->worlds.first; wo; wo = wo->id.next) { + if (wo->nodetree && wo->use_nodes && ntreeHasTree(wo->nodetree, ntree)) { + GPU_material_free(&wo->gpumaterial); + } + } + + ED_node_tag_update_nodetree(bmain, ntree, node); + WM_main_add_notifier(NC_IMAGE, NULL); + } + + WM_main_add_notifier(NC_MATERIAL | ND_NODES, node->id); + } + else if (ntree->type == NTREE_COMPOSIT) { + /* make active viewer, currently only 1 supported... */ + if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { + bNode *tnode; + + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { + if (ELEM(tnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { + tnode->flag &= ~NODE_DO_OUTPUT; + } + } + + node->flag |= NODE_DO_OUTPUT; + if (was_output == 0) { + ED_node_tag_update_nodetree(bmain, ntree, node); + } + + /* addnode() doesn't link this yet... */ + node->id = (ID *)BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + } + else if (node->type == CMP_NODE_COMPOSITE) { + if (was_output == 0) { + bNode *tnode; + + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { + if (tnode->type == CMP_NODE_COMPOSITE) { + tnode->flag &= ~NODE_DO_OUTPUT; + } + } + + node->flag |= NODE_DO_OUTPUT; + ED_node_tag_update_nodetree(bmain, ntree, node); + } + } + else if (do_update) { + ED_node_tag_update_nodetree(bmain, ntree, node); + } + } + else if (ntree->type == NTREE_TEXTURE) { + // XXX #if 0 - if (node->id) - ; // XXX BIF_preview_changed(-1); - // allqueue(REDRAWBUTSSHADING, 1); - // allqueue(REDRAWIPO, 0); + if (node->id) + ; // XXX BIF_preview_changed(-1); + // allqueue(REDRAWBUTSSHADING, 1); + // allqueue(REDRAWIPO, 0); #endif - } - } + } + } } void ED_node_post_apply_transform(bContext *UNUSED(C), bNodeTree *UNUSED(ntree)) { - /* XXX This does not work due to layout functions relying on node->block, - * which only exists during actual drawing. Can we rely on valid totr rects? - */ - /* make sure nodes have correct bounding boxes after transform */ - /* node_update_nodetree(C, ntree, 0.0f, 0.0f); */ + /* XXX This does not work due to layout functions relying on node->block, + * which only exists during actual drawing. Can we rely on valid totr rects? + */ + /* make sure nodes have correct bounding boxes after transform */ + /* node_update_nodetree(C, ntree, 0.0f, 0.0f); */ } /* ***************** generic operator functions for nodes ***************** */ @@ -757,61 +774,61 @@ void ED_node_post_apply_transform(bContext *UNUSED(C), bNodeTree *UNUSED(ntree)) static bool edit_node_poll(bContext *C) { - return ED_operator_node_active(C); + return ED_operator_node_active(C); } static void edit_node_properties(wmOperatorType *ot) { - /* XXX could node be a context pointer? */ - RNA_def_string(ot->srna, "node", NULL, MAX_NAME, "Node", ""); - RNA_def_int(ot->srna, "socket", 0, 0, MAX_SOCKET, "Socket", "", 0, MAX_SOCKET); - RNA_def_enum(ot->srna, "in_out", rna_enum_node_socket_in_out_items, SOCK_IN, "Socket Side", ""); + /* XXX could node be a context pointer? */ + RNA_def_string(ot->srna, "node", NULL, MAX_NAME, "Node", ""); + RNA_def_int(ot->srna, "socket", 0, 0, MAX_SOCKET, "Socket", "", 0, MAX_SOCKET); + RNA_def_enum(ot->srna, "in_out", rna_enum_node_socket_in_out_items, SOCK_IN, "Socket Side", ""); } static int edit_node_invoke_properties(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "node")) { - bNode *node = CTX_data_pointer_get_type(C, "node", &RNA_Node).data; - if (!node) - return 0; - else - RNA_string_set(op->ptr, "node", node->name); - } + if (!RNA_struct_property_is_set(op->ptr, "node")) { + bNode *node = CTX_data_pointer_get_type(C, "node", &RNA_Node).data; + if (!node) + return 0; + else + RNA_string_set(op->ptr, "node", node->name); + } - if (!RNA_struct_property_is_set(op->ptr, "in_out")) - RNA_enum_set(op->ptr, "in_out", SOCK_IN); + if (!RNA_struct_property_is_set(op->ptr, "in_out")) + RNA_enum_set(op->ptr, "in_out", SOCK_IN); - if (!RNA_struct_property_is_set(op->ptr, "socket")) - RNA_int_set(op->ptr, "socket", 0); + if (!RNA_struct_property_is_set(op->ptr, "socket")) + RNA_int_set(op->ptr, "socket", 0); - return 1; + return 1; } static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **rnode, bNodeSocket **rsock, int *rin_out) { - bNode *node; - bNodeSocket *sock = NULL; - char nodename[MAX_NAME]; - int sockindex; - int in_out; + bNode *node; + bNodeSocket *sock = NULL; + char nodename[MAX_NAME]; + int sockindex; + int in_out; - RNA_string_get(op->ptr, "node", nodename); - node = nodeFindNodebyName(ntree, nodename); + RNA_string_get(op->ptr, "node", nodename); + node = nodeFindNodebyName(ntree, nodename); - in_out = RNA_enum_get(op->ptr, "in_out"); + in_out = RNA_enum_get(op->ptr, "in_out"); - sockindex = RNA_int_get(op->ptr, "socket"); - switch (in_out) { - case SOCK_IN: sock = BLI_findlink(&node->inputs, sockindex); break; - case SOCK_OUT: sock = BLI_findlink(&node->outputs, sockindex); break; - } + sockindex = RNA_int_get(op->ptr, "socket"); + switch (in_out) { + case SOCK_IN: sock = BLI_findlink(&node->inputs, sockindex); break; + case SOCK_OUT: sock = BLI_findlink(&node->outputs, sockindex); break; + } - if (rnode) - *rnode = node; - if (rsock) - *rsock = sock; - if (rin_out) - *rin_out = in_out; + if (rnode) + *rnode = node; + if (rsock) + *rsock = sock; + if (rin_out) + *rin_out = in_out; } #endif @@ -820,1929 +837,1940 @@ static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **r /* is rct in visible part of node? */ static bNode *visible_node(SpaceNode *snode, const rctf *rct) { - bNode *node; + bNode *node; - for (node = snode->edittree->nodes.last; node; node = node->prev) { - if (BLI_rctf_isect(&node->totr, rct, NULL)) { - break; - } - } - return node; + for (node = snode->edittree->nodes.last; node; node = node->prev) { + if (BLI_rctf_isect(&node->totr, rct, NULL)) { + break; + } + } + return node; } /* ********************** size widget operator ******************** */ typedef struct NodeSizeWidget { - float mxstart, mystart; - float oldlocx, oldlocy; - float oldoffsetx, oldoffsety; - float oldwidth, oldheight; - int directions; + float mxstart, mystart; + float oldlocx, oldlocy; + float oldoffsetx, oldoffsety; + float oldwidth, oldheight; + int directions; } NodeSizeWidget; -static void node_resize_init(bContext *C, wmOperator *op, const wmEvent *UNUSED(event), bNode *node, int dir) +static void node_resize_init( + bContext *C, wmOperator *op, const wmEvent *UNUSED(event), bNode *node, int dir) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - NodeSizeWidget *nsw = MEM_callocN(sizeof(NodeSizeWidget), "size widget op data"); + NodeSizeWidget *nsw = MEM_callocN(sizeof(NodeSizeWidget), "size widget op data"); - op->customdata = nsw; - nsw->mxstart = snode->cursor[0] * UI_DPI_FAC; - nsw->mystart = snode->cursor[1] * UI_DPI_FAC; + op->customdata = nsw; + nsw->mxstart = snode->cursor[0] * UI_DPI_FAC; + nsw->mystart = snode->cursor[1] * UI_DPI_FAC; - /* store old */ - nsw->oldlocx = node->locx; - nsw->oldlocy = node->locy; - nsw->oldoffsetx = node->offsetx; - nsw->oldoffsety = node->offsety; - nsw->oldwidth = node->width; - nsw->oldheight = node->height; - nsw->directions = dir; + /* store old */ + nsw->oldlocx = node->locx; + nsw->oldlocy = node->locy; + nsw->oldoffsetx = node->offsetx; + nsw->oldoffsety = node->offsety; + nsw->oldwidth = node->width; + nsw->oldheight = node->height; + nsw->directions = dir; - WM_cursor_modal_set(CTX_wm_window(C), node_get_resize_cursor(dir)); - /* add modal handler */ - WM_event_add_modal_handler(C, op); + WM_cursor_modal_set(CTX_wm_window(C), node_get_resize_cursor(dir)); + /* add modal handler */ + WM_event_add_modal_handler(C, op); } static void node_resize_exit(bContext *C, wmOperator *op, bool UNUSED(cancel)) { - WM_cursor_modal_restore(CTX_wm_window(C)); + WM_cursor_modal_restore(CTX_wm_window(C)); - MEM_freeN(op->customdata); - op->customdata = NULL; + MEM_freeN(op->customdata); + op->customdata = NULL; } static int node_resize_modal(bContext *C, wmOperator *op, const wmEvent *event) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - bNode *node = nodeGetActive(snode->edittree); - NodeSizeWidget *nsw = op->customdata; - float mx, my, dx, dy; - - switch (event->type) { - case MOUSEMOVE: - - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mx, &my); - dx = (mx - nsw->mxstart) / UI_DPI_FAC; - dy = (my - nsw->mystart) / UI_DPI_FAC; - - if (node) { - float *pwidth; - float oldwidth, widthmin, widthmax; - - pwidth = &node->width; - oldwidth = nsw->oldwidth; - widthmin = node->typeinfo->minwidth; - widthmax = node->typeinfo->maxwidth; - - { - if (nsw->directions & NODE_RESIZE_RIGHT) { - *pwidth = oldwidth + dx; - CLAMP(*pwidth, widthmin, widthmax); - } - if (nsw->directions & NODE_RESIZE_LEFT) { - float locmax = nsw->oldlocx + oldwidth; - - node->locx = nsw->oldlocx + dx; - CLAMP(node->locx, locmax - widthmax, locmax - widthmin); - *pwidth = locmax - node->locx; - } - } - - /* height works the other way round ... */ - { - float heightmin = UI_DPI_FAC * node->typeinfo->minheight; - float heightmax = UI_DPI_FAC * node->typeinfo->maxheight; - if (nsw->directions & NODE_RESIZE_TOP) { - float locmin = nsw->oldlocy - nsw->oldheight; - - node->locy = nsw->oldlocy + dy; - CLAMP(node->locy, locmin + heightmin, locmin + heightmax); - node->height = node->locy - locmin; - } - if (nsw->directions & NODE_RESIZE_BOTTOM) { - node->height = nsw->oldheight - dy; - CLAMP(node->height, heightmin, heightmax); - } - } - - /* XXX make callback? */ - if (node->type == NODE_FRAME) { - /* keep the offset symmetric around center point */ - if (nsw->directions & NODE_RESIZE_LEFT) { - node->locx = nsw->oldlocx + 0.5f * dx; - node->offsetx = nsw->oldoffsetx + 0.5f * dx; - } - if (nsw->directions & NODE_RESIZE_RIGHT) { - node->locx = nsw->oldlocx + 0.5f * dx; - node->offsetx = nsw->oldoffsetx - 0.5f * dx; - } - if (nsw->directions & NODE_RESIZE_TOP) { - node->locy = nsw->oldlocy + 0.5f * dy; - node->offsety = nsw->oldoffsety + 0.5f * dy; - } - if (nsw->directions & NODE_RESIZE_BOTTOM) { - node->locy = nsw->oldlocy + 0.5f * dy; - node->offsety = nsw->oldoffsety - 0.5f * dy; - } - } - } - - ED_region_tag_redraw(ar); - - break; - - case LEFTMOUSE: - case MIDDLEMOUSE: - case RIGHTMOUSE: - if (event->val == KM_RELEASE) { - node_resize_exit(C, op, false); - ED_node_post_apply_transform(C, snode->edittree); - - return OPERATOR_FINISHED; - } - break; - } - - return OPERATOR_RUNNING_MODAL; + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + bNode *node = nodeGetActive(snode->edittree); + NodeSizeWidget *nsw = op->customdata; + float mx, my, dx, dy; + + switch (event->type) { + case MOUSEMOVE: + + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mx, &my); + dx = (mx - nsw->mxstart) / UI_DPI_FAC; + dy = (my - nsw->mystart) / UI_DPI_FAC; + + if (node) { + float *pwidth; + float oldwidth, widthmin, widthmax; + + pwidth = &node->width; + oldwidth = nsw->oldwidth; + widthmin = node->typeinfo->minwidth; + widthmax = node->typeinfo->maxwidth; + + { + if (nsw->directions & NODE_RESIZE_RIGHT) { + *pwidth = oldwidth + dx; + CLAMP(*pwidth, widthmin, widthmax); + } + if (nsw->directions & NODE_RESIZE_LEFT) { + float locmax = nsw->oldlocx + oldwidth; + + node->locx = nsw->oldlocx + dx; + CLAMP(node->locx, locmax - widthmax, locmax - widthmin); + *pwidth = locmax - node->locx; + } + } + + /* height works the other way round ... */ + { + float heightmin = UI_DPI_FAC * node->typeinfo->minheight; + float heightmax = UI_DPI_FAC * node->typeinfo->maxheight; + if (nsw->directions & NODE_RESIZE_TOP) { + float locmin = nsw->oldlocy - nsw->oldheight; + + node->locy = nsw->oldlocy + dy; + CLAMP(node->locy, locmin + heightmin, locmin + heightmax); + node->height = node->locy - locmin; + } + if (nsw->directions & NODE_RESIZE_BOTTOM) { + node->height = nsw->oldheight - dy; + CLAMP(node->height, heightmin, heightmax); + } + } + + /* XXX make callback? */ + if (node->type == NODE_FRAME) { + /* keep the offset symmetric around center point */ + if (nsw->directions & NODE_RESIZE_LEFT) { + node->locx = nsw->oldlocx + 0.5f * dx; + node->offsetx = nsw->oldoffsetx + 0.5f * dx; + } + if (nsw->directions & NODE_RESIZE_RIGHT) { + node->locx = nsw->oldlocx + 0.5f * dx; + node->offsetx = nsw->oldoffsetx - 0.5f * dx; + } + if (nsw->directions & NODE_RESIZE_TOP) { + node->locy = nsw->oldlocy + 0.5f * dy; + node->offsety = nsw->oldoffsety + 0.5f * dy; + } + if (nsw->directions & NODE_RESIZE_BOTTOM) { + node->locy = nsw->oldlocy + 0.5f * dy; + node->offsety = nsw->oldoffsety - 0.5f * dy; + } + } + } + + ED_region_tag_redraw(ar); + + break; + + case LEFTMOUSE: + case MIDDLEMOUSE: + case RIGHTMOUSE: + if (event->val == KM_RELEASE) { + node_resize_exit(C, op, false); + ED_node_post_apply_transform(C, snode->edittree); + + return OPERATOR_FINISHED; + } + break; + } + + return OPERATOR_RUNNING_MODAL; } static int node_resize_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - bNode *node = nodeGetActive(snode->edittree); - int dir; + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + bNode *node = nodeGetActive(snode->edittree); + int dir; - if (node) { - float cursor[2]; + if (node) { + float cursor[2]; - /* convert mouse coordinates to v2d space */ - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &cursor[0], &cursor[1]); - dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); - if (dir != 0) { - node_resize_init(C, op, event, node, dir); - return OPERATOR_RUNNING_MODAL; - } - } - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + /* convert mouse coordinates to v2d space */ + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); + dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); + if (dir != 0) { + node_resize_init(C, op, event, node, dir); + return OPERATOR_RUNNING_MODAL; + } + } + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; } static void node_resize_cancel(bContext *C, wmOperator *op) { - node_resize_exit(C, op, true); + node_resize_exit(C, op, true); } void NODE_OT_resize(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Resize Node"; - ot->idname = "NODE_OT_resize"; - ot->description = "Resize a node"; + /* identifiers */ + ot->name = "Resize Node"; + ot->idname = "NODE_OT_resize"; + ot->description = "Resize a node"; - /* api callbacks */ - ot->invoke = node_resize_invoke; - ot->modal = node_resize_modal; - ot->poll = ED_operator_node_active; - ot->cancel = node_resize_cancel; + /* api callbacks */ + ot->invoke = node_resize_invoke; + ot->modal = node_resize_modal; + ot->poll = ED_operator_node_active; + ot->cancel = node_resize_cancel; - /* flags */ - ot->flag = OPTYPE_BLOCKING; + /* flags */ + ot->flag = OPTYPE_BLOCKING; } - /* ********************** hidden sockets ******************** */ int node_has_hidden_sockets(bNode *node) { - bNodeSocket *sock; + bNodeSocket *sock; - for (sock = node->inputs.first; sock; sock = sock->next) { - if (sock->flag & SOCK_HIDDEN) { - return 1; - } - } - for (sock = node->outputs.first; sock; sock = sock->next) { - if (sock->flag & SOCK_HIDDEN) { - return 1; - } - } - return 0; + for (sock = node->inputs.first; sock; sock = sock->next) { + if (sock->flag & SOCK_HIDDEN) { + return 1; + } + } + for (sock = node->outputs.first; sock; sock = sock->next) { + if (sock->flag & SOCK_HIDDEN) { + return 1; + } + } + return 0; } void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set) { - bNodeSocket *sock; - - if (set == 0) { - for (sock = node->inputs.first; sock; sock = sock->next) { - sock->flag &= ~SOCK_HIDDEN; - } - for (sock = node->outputs.first; sock; sock = sock->next) { - sock->flag &= ~SOCK_HIDDEN; - } - } - else { - /* hide unused sockets */ - for (sock = node->inputs.first; sock; sock = sock->next) { - if (sock->link == NULL) { - sock->flag |= SOCK_HIDDEN; - } - } - for (sock = node->outputs.first; sock; sock = sock->next) { - if (nodeCountSocketLinks(snode->edittree, sock) == 0) { - sock->flag |= SOCK_HIDDEN; - } - } - } + bNodeSocket *sock; + + if (set == 0) { + for (sock = node->inputs.first; sock; sock = sock->next) { + sock->flag &= ~SOCK_HIDDEN; + } + for (sock = node->outputs.first; sock; sock = sock->next) { + sock->flag &= ~SOCK_HIDDEN; + } + } + else { + /* hide unused sockets */ + for (sock = node->inputs.first; sock; sock = sock->next) { + if (sock->link == NULL) { + sock->flag |= SOCK_HIDDEN; + } + } + for (sock = node->outputs.first; sock; sock = sock->next) { + if (nodeCountSocketLinks(snode->edittree, sock) == 0) { + sock->flag |= SOCK_HIDDEN; + } + } + } } - /* checks snode->mouse position, and returns found node/socket */ /* type is SOCK_IN and/or SOCK_OUT */ -int node_find_indicated_socket(SpaceNode *snode, bNode **nodep, bNodeSocket **sockp, float cursor[2], int in_out) -{ - bNode *node; - bNodeSocket *sock; - rctf rect; - - *nodep = NULL; - *sockp = NULL; - - /* check if we click in a socket */ - for (node = snode->edittree->nodes.first; node; node = node->next) { - - BLI_rctf_init_pt_radius(&rect, cursor, NODE_SOCKSIZE + 4); - - if (!(node->flag & NODE_HIDDEN)) { - /* extra padding inside and out - allow dragging on the text areas too */ - if (in_out == SOCK_IN) { - rect.xmax += NODE_SOCKSIZE; - rect.xmin -= NODE_SOCKSIZE * 4; - } - else if (in_out == SOCK_OUT) { - rect.xmax += NODE_SOCKSIZE * 4; - rect.xmin -= NODE_SOCKSIZE; - } - } - - if (in_out & SOCK_IN) { - for (sock = node->inputs.first; sock; sock = sock->next) { - if (!nodeSocketIsHidden(sock)) { - if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) { - if (node == visible_node(snode, &rect)) { - *nodep = node; - *sockp = sock; - return 1; - } - } - } - } - } - if (in_out & SOCK_OUT) { - for (sock = node->outputs.first; sock; sock = sock->next) { - if (!nodeSocketIsHidden(sock)) { - if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) { - if (node == visible_node(snode, &rect)) { - *nodep = node; - *sockp = sock; - return 1; - } - } - } - } - } - } - - return 0; +int node_find_indicated_socket( + SpaceNode *snode, bNode **nodep, bNodeSocket **sockp, float cursor[2], int in_out) +{ + bNode *node; + bNodeSocket *sock; + rctf rect; + + *nodep = NULL; + *sockp = NULL; + + /* check if we click in a socket */ + for (node = snode->edittree->nodes.first; node; node = node->next) { + + BLI_rctf_init_pt_radius(&rect, cursor, NODE_SOCKSIZE + 4); + + if (!(node->flag & NODE_HIDDEN)) { + /* extra padding inside and out - allow dragging on the text areas too */ + if (in_out == SOCK_IN) { + rect.xmax += NODE_SOCKSIZE; + rect.xmin -= NODE_SOCKSIZE * 4; + } + else if (in_out == SOCK_OUT) { + rect.xmax += NODE_SOCKSIZE * 4; + rect.xmin -= NODE_SOCKSIZE; + } + } + + if (in_out & SOCK_IN) { + for (sock = node->inputs.first; sock; sock = sock->next) { + if (!nodeSocketIsHidden(sock)) { + if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) { + if (node == visible_node(snode, &rect)) { + *nodep = node; + *sockp = sock; + return 1; + } + } + } + } + } + if (in_out & SOCK_OUT) { + for (sock = node->outputs.first; sock; sock = sock->next) { + if (!nodeSocketIsHidden(sock)) { + if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) { + if (node == visible_node(snode, &rect)) { + *nodep = node; + *sockp = sock; + return 1; + } + } + } + } + } + } + + return 0; } /* ****************** Duplicate *********************** */ static void node_duplicate_reparent_recursive(bNode *node) { - bNode *parent; + bNode *parent; - node->flag |= NODE_TEST; + node->flag |= NODE_TEST; - /* find first selected parent */ - for (parent = node->parent; parent; parent = parent->parent) { - if (parent->flag & SELECT) { - if (!(parent->flag & NODE_TEST)) { - node_duplicate_reparent_recursive(parent); - } - break; - } - } - /* reparent node copy to parent copy */ - if (parent) { - nodeDetachNode(node->new_node); - nodeAttachNode(node->new_node, parent->new_node); - } + /* find first selected parent */ + for (parent = node->parent; parent; parent = parent->parent) { + if (parent->flag & SELECT) { + if (!(parent->flag & NODE_TEST)) { + node_duplicate_reparent_recursive(parent); + } + break; + } + } + /* reparent node copy to parent copy */ + if (parent) { + nodeDetachNode(node->new_node); + nodeAttachNode(node->new_node, parent->new_node); + } } static int node_duplicate_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *node, *newnode, *lastnode; - bNodeLink *link, *newlink, *lastlink; - const bool keep_inputs = RNA_boolean_get(op->ptr, "keep_inputs"); - bool do_tag_update = false; - - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - - lastnode = ntree->nodes.last; - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - newnode = BKE_node_copy_ex(ntree, node, LIB_ID_COPY_DEFAULT); - - /* to ensure redraws or rerenders happen */ - ED_node_tag_update_id(snode->id); - } - - /* make sure we don't copy new nodes again! */ - if (node == lastnode) { - break; - } - } - - /* copy links between selected nodes - * NB: this depends on correct node->new_node and sock->new_sock pointers from above copy! - */ - lastlink = ntree->links.last; - for (link = ntree->links.first; link; link = link->next) { - /* This creates new links between copied nodes. - * If keep_inputs is set, also copies input links from unselected (when fromnode==NULL)! - */ - if (link->tonode && (link->tonode->flag & NODE_SELECT) && - (keep_inputs || (link->fromnode && (link->fromnode->flag & NODE_SELECT)))) - { - newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink"); - newlink->flag = link->flag; - newlink->tonode = link->tonode->new_node; - newlink->tosock = link->tosock->new_sock; - if (link->fromnode && (link->fromnode->flag & NODE_SELECT)) { - newlink->fromnode = link->fromnode->new_node; - newlink->fromsock = link->fromsock->new_sock; - } - else { - /* input node not copied, this keeps the original input linked */ - newlink->fromnode = link->fromnode; - newlink->fromsock = link->fromsock; - } - - BLI_addtail(&ntree->links, newlink); - } - - /* make sure we don't copy new links again! */ - if (link == lastlink) { - break; - } - } - - /* clear flags for recursive depth-first iteration */ - for (node = ntree->nodes.first; node; node = node->next) { - node->flag &= ~NODE_TEST; - } - /* reparent copied nodes */ - for (node = ntree->nodes.first; node; node = node->next) { - if ((node->flag & SELECT) && !(node->flag & NODE_TEST)) { - node_duplicate_reparent_recursive(node); - } - - /* only has to check old nodes */ - if (node == lastnode) { - break; - } - } - - /* deselect old nodes, select the copies instead */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - /* has been set during copy above */ - newnode = node->new_node; - - nodeSetSelected(node, false); - node->flag &= ~NODE_ACTIVE; - nodeSetSelected(newnode, true); - - do_tag_update |= (do_tag_update || node_connected_to_output(bmain, ntree, newnode)); - } - - /* make sure we don't copy new nodes again! */ - if (node == lastnode) { - break; - } - } - - ntreeUpdateTree(CTX_data_main(C), snode->edittree); - - snode_notify(C, snode); - if (do_tag_update) { - snode_dag_update(C, snode); - } - - return OPERATOR_FINISHED; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *node, *newnode, *lastnode; + bNodeLink *link, *newlink, *lastlink; + const bool keep_inputs = RNA_boolean_get(op->ptr, "keep_inputs"); + bool do_tag_update = false; + + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + + lastnode = ntree->nodes.last; + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + newnode = BKE_node_copy_ex(ntree, node, LIB_ID_COPY_DEFAULT); + + /* to ensure redraws or rerenders happen */ + ED_node_tag_update_id(snode->id); + } + + /* make sure we don't copy new nodes again! */ + if (node == lastnode) { + break; + } + } + + /* copy links between selected nodes + * NB: this depends on correct node->new_node and sock->new_sock pointers from above copy! + */ + lastlink = ntree->links.last; + for (link = ntree->links.first; link; link = link->next) { + /* This creates new links between copied nodes. + * If keep_inputs is set, also copies input links from unselected (when fromnode==NULL)! + */ + if (link->tonode && (link->tonode->flag & NODE_SELECT) && + (keep_inputs || (link->fromnode && (link->fromnode->flag & NODE_SELECT)))) { + newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink"); + newlink->flag = link->flag; + newlink->tonode = link->tonode->new_node; + newlink->tosock = link->tosock->new_sock; + if (link->fromnode && (link->fromnode->flag & NODE_SELECT)) { + newlink->fromnode = link->fromnode->new_node; + newlink->fromsock = link->fromsock->new_sock; + } + else { + /* input node not copied, this keeps the original input linked */ + newlink->fromnode = link->fromnode; + newlink->fromsock = link->fromsock; + } + + BLI_addtail(&ntree->links, newlink); + } + + /* make sure we don't copy new links again! */ + if (link == lastlink) { + break; + } + } + + /* clear flags for recursive depth-first iteration */ + for (node = ntree->nodes.first; node; node = node->next) { + node->flag &= ~NODE_TEST; + } + /* reparent copied nodes */ + for (node = ntree->nodes.first; node; node = node->next) { + if ((node->flag & SELECT) && !(node->flag & NODE_TEST)) { + node_duplicate_reparent_recursive(node); + } + + /* only has to check old nodes */ + if (node == lastnode) { + break; + } + } + + /* deselect old nodes, select the copies instead */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + /* has been set during copy above */ + newnode = node->new_node; + + nodeSetSelected(node, false); + node->flag &= ~NODE_ACTIVE; + nodeSetSelected(newnode, true); + + do_tag_update |= (do_tag_update || node_connected_to_output(bmain, ntree, newnode)); + } + + /* make sure we don't copy new nodes again! */ + if (node == lastnode) { + break; + } + } + + ntreeUpdateTree(CTX_data_main(C), snode->edittree); + + snode_notify(C, snode); + if (do_tag_update) { + snode_dag_update(C, snode); + } + + return OPERATOR_FINISHED; } void NODE_OT_duplicate(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Duplicate Nodes"; - ot->description = "Duplicate selected nodes"; - ot->idname = "NODE_OT_duplicate"; + /* identifiers */ + ot->name = "Duplicate Nodes"; + ot->description = "Duplicate selected nodes"; + ot->idname = "NODE_OT_duplicate"; - /* api callbacks */ - ot->exec = node_duplicate_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = node_duplicate_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_boolean(ot->srna, "keep_inputs", 0, "Keep Inputs", "Keep the input links to duplicated nodes"); + RNA_def_boolean( + ot->srna, "keep_inputs", 0, "Keep Inputs", "Keep the input links to duplicated nodes"); } bool ED_node_select_check(ListBase *lb) { - for (bNode *node = lb->first; node; node = node->next) { - if (node->flag & NODE_SELECT) { - return true; - } - } + for (bNode *node = lb->first; node; node = node->next) { + if (node->flag & NODE_SELECT) { + return true; + } + } - return false; + return false; } void ED_node_select_all(ListBase *lb, int action) { - if (action == SEL_TOGGLE) { - if (ED_node_select_check(lb)) { - action = SEL_DESELECT; - } - else { - action = SEL_SELECT; - } - } - - for (bNode *node = lb->first; node; node = node->next) { - switch (action) { - case SEL_SELECT: - nodeSetSelected(node, true); - break; - case SEL_DESELECT: - nodeSetSelected(node, false); - break; - case SEL_INVERT: - nodeSetSelected(node, !(node->flag & SELECT)); - break; - } - } + if (action == SEL_TOGGLE) { + if (ED_node_select_check(lb)) { + action = SEL_DESELECT; + } + else { + action = SEL_SELECT; + } + } + + for (bNode *node = lb->first; node; node = node->next) { + switch (action) { + case SEL_SELECT: + nodeSetSelected(node, true); + break; + case SEL_DESELECT: + nodeSetSelected(node, false); + break; + case SEL_INVERT: + nodeSetSelected(node, !(node->flag & SELECT)); + break; + } + } } /* ******************************** */ // XXX some code needing updating to operators... - /* goes over all scenes, reads render layers */ static int node_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - Scene *curscene = CTX_data_scene(C), *scene; - bNode *node; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + Scene *curscene = CTX_data_scene(C), *scene; + bNode *node; - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - /* first tag scenes unread */ - for (scene = bmain->scenes.first; scene; scene = scene->id.next) { - scene->id.tag |= LIB_TAG_DOIT; - } + /* first tag scenes unread */ + for (scene = bmain->scenes.first; scene; scene = scene->id.next) { + scene->id.tag |= LIB_TAG_DOIT; + } - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_R_LAYERS) { - ID *id = node->id; - if (id->tag & LIB_TAG_DOIT) { - RE_ReadRenderResult(curscene, (Scene *)id); - ntreeCompositTagRender((Scene *)id); - id->tag &= ~LIB_TAG_DOIT; - } - } - } + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_R_LAYERS) { + ID *id = node->id; + if (id->tag & LIB_TAG_DOIT) { + RE_ReadRenderResult(curscene, (Scene *)id); + ntreeCompositTagRender((Scene *)id); + id->tag &= ~LIB_TAG_DOIT; + } + } + } - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(C, snode); + snode_dag_update(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_read_viewlayers(wmOperatorType *ot) { - ot->name = "Read View Layers"; - ot->idname = "NODE_OT_read_viewlayers"; - ot->description = "Read all render layers of all used scenes"; + ot->name = "Read View Layers"; + ot->idname = "NODE_OT_read_viewlayers"; + ot->description = "Read all render layers of all used scenes"; - ot->exec = node_read_viewlayers_exec; + ot->exec = node_read_viewlayers_exec; - ot->poll = composite_node_active; + ot->poll = composite_node_active; - /* flags */ - ot->flag = 0; + /* flags */ + ot->flag = 0; } int node_render_changed_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene *sce = CTX_data_scene(C); - bNode *node; + Scene *sce = CTX_data_scene(C); + bNode *node; - for (node = sce->nodetree->nodes.first; node; node = node->next) { - if (node->id == (ID *)sce && node->need_exec) { - break; - } - } - if (node) { - ViewLayer *view_layer = BLI_findlink(&sce->view_layers, node->custom1); + for (node = sce->nodetree->nodes.first; node; node = node->next) { + if (node->id == (ID *)sce && node->need_exec) { + break; + } + } + if (node) { + ViewLayer *view_layer = BLI_findlink(&sce->view_layers, node->custom1); - if (view_layer) { - PointerRNA op_ptr; + if (view_layer) { + PointerRNA op_ptr; - WM_operator_properties_create(&op_ptr, "RENDER_OT_render"); - RNA_string_set(&op_ptr, "layer", view_layer->name); - RNA_string_set(&op_ptr, "scene", sce->id.name + 2); + WM_operator_properties_create(&op_ptr, "RENDER_OT_render"); + RNA_string_set(&op_ptr, "layer", view_layer->name); + RNA_string_set(&op_ptr, "scene", sce->id.name + 2); - /* to keep keypositions */ - sce->r.scemode |= R_NO_FRAME_UPDATE; + /* to keep keypositions */ + sce->r.scemode |= R_NO_FRAME_UPDATE; - WM_operator_name_call(C, "RENDER_OT_render", WM_OP_INVOKE_DEFAULT, &op_ptr); + WM_operator_name_call(C, "RENDER_OT_render", WM_OP_INVOKE_DEFAULT, &op_ptr); - WM_operator_properties_free(&op_ptr); + WM_operator_properties_free(&op_ptr); - return OPERATOR_FINISHED; - } - } - return OPERATOR_CANCELLED; + return OPERATOR_FINISHED; + } + } + return OPERATOR_CANCELLED; } void NODE_OT_render_changed(wmOperatorType *ot) { - ot->name = "Render Changed Layer"; - ot->idname = "NODE_OT_render_changed"; - ot->description = "Render current scene, when input node's layer has been changed"; + ot->name = "Render Changed Layer"; + ot->idname = "NODE_OT_render_changed"; + ot->description = "Render current scene, when input node's layer has been changed"; - ot->exec = node_render_changed_exec; + ot->exec = node_render_changed_exec; - ot->poll = composite_node_active; + ot->poll = composite_node_active; - /* flags */ - ot->flag = 0; + /* flags */ + ot->flag = 0; } - /* ****************** Hide operator *********************** */ static void node_flag_toggle_exec(SpaceNode *snode, int toggle_flag) { - bNode *node; - int tot_eq = 0, tot_neq = 0; - - /* Toggles the flag on all selected nodes. - * If the flag is set on all nodes it is unset. - * If the flag is not set on all nodes, it is set. - */ - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - - if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0) { - continue; - } - if (toggle_flag == NODE_OPTIONS && !(node->typeinfo->draw_buttons || node->typeinfo->draw_buttons_ex)) { - continue; - } - - if (node->flag & toggle_flag) { - tot_eq++; - } - else { - tot_neq++; - } - } - } - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - - if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0) { - continue; - } - if (toggle_flag == NODE_OPTIONS && !(node->typeinfo->draw_buttons || node->typeinfo->draw_buttons_ex)) { - continue; - } - - if ((tot_eq && tot_neq) || tot_eq == 0) { - node->flag |= toggle_flag; - } - else { - node->flag &= ~toggle_flag; - } - } - } + bNode *node; + int tot_eq = 0, tot_neq = 0; + + /* Toggles the flag on all selected nodes. + * If the flag is set on all nodes it is unset. + * If the flag is not set on all nodes, it is set. + */ + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + + if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0) { + continue; + } + if (toggle_flag == NODE_OPTIONS && + !(node->typeinfo->draw_buttons || node->typeinfo->draw_buttons_ex)) { + continue; + } + + if (node->flag & toggle_flag) { + tot_eq++; + } + else { + tot_neq++; + } + } + } + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + + if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0) { + continue; + } + if (toggle_flag == NODE_OPTIONS && + !(node->typeinfo->draw_buttons || node->typeinfo->draw_buttons_ex)) { + continue; + } + + if ((tot_eq && tot_neq) || tot_eq == 0) { + node->flag |= toggle_flag; + } + else { + node->flag &= ~toggle_flag; + } + } + } } static int node_hide_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - /* sanity checking (poll callback checks this already) */ - if ((snode == NULL) || (snode->edittree == NULL)) { - return OPERATOR_CANCELLED; - } + /* sanity checking (poll callback checks this already) */ + if ((snode == NULL) || (snode->edittree == NULL)) { + return OPERATOR_CANCELLED; + } - node_flag_toggle_exec(snode, NODE_HIDDEN); + node_flag_toggle_exec(snode, NODE_HIDDEN); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_hide_toggle(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Hide"; - ot->description = "Toggle hiding of selected nodes"; - ot->idname = "NODE_OT_hide_toggle"; + /* identifiers */ + ot->name = "Hide"; + ot->description = "Toggle hiding of selected nodes"; + ot->idname = "NODE_OT_hide_toggle"; - /* callbacks */ - ot->exec = node_hide_toggle_exec; - ot->poll = ED_operator_node_active; + /* callbacks */ + ot->exec = node_hide_toggle_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int node_preview_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - /* sanity checking (poll callback checks this already) */ - if ((snode == NULL) || (snode->edittree == NULL)) { - return OPERATOR_CANCELLED; - } + /* sanity checking (poll callback checks this already) */ + if ((snode == NULL) || (snode->edittree == NULL)) { + return OPERATOR_CANCELLED; + } - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - node_flag_toggle_exec(snode, NODE_PREVIEW); + node_flag_toggle_exec(snode, NODE_PREVIEW); - snode_notify(C, snode); + snode_notify(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_preview_toggle(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Toggle Node Preview"; - ot->description = "Toggle preview display for selected nodes"; - ot->idname = "NODE_OT_preview_toggle"; + /* identifiers */ + ot->name = "Toggle Node Preview"; + ot->description = "Toggle preview display for selected nodes"; + ot->idname = "NODE_OT_preview_toggle"; - /* callbacks */ - ot->exec = node_preview_toggle_exec; - ot->poll = ED_operator_node_active; + /* callbacks */ + ot->exec = node_preview_toggle_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int node_options_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - /* sanity checking (poll callback checks this already) */ - if ((snode == NULL) || (snode->edittree == NULL)) { - return OPERATOR_CANCELLED; - } + /* sanity checking (poll callback checks this already) */ + if ((snode == NULL) || (snode->edittree == NULL)) { + return OPERATOR_CANCELLED; + } - node_flag_toggle_exec(snode, NODE_OPTIONS); + node_flag_toggle_exec(snode, NODE_OPTIONS); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_options_toggle(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Toggle Node Options"; - ot->description = "Toggle option buttons display for selected nodes"; - ot->idname = "NODE_OT_options_toggle"; + /* identifiers */ + ot->name = "Toggle Node Options"; + ot->description = "Toggle option buttons display for selected nodes"; + ot->idname = "NODE_OT_options_toggle"; - /* callbacks */ - ot->exec = node_options_toggle_exec; - ot->poll = ED_operator_node_active; + /* callbacks */ + ot->exec = node_options_toggle_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int node_socket_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - int hidden; + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + int hidden; - /* sanity checking (poll callback checks this already) */ - if ((snode == NULL) || (snode->edittree == NULL)) { - return OPERATOR_CANCELLED; - } + /* sanity checking (poll callback checks this already) */ + if ((snode == NULL) || (snode->edittree == NULL)) { + return OPERATOR_CANCELLED; + } - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - /* Toggle for all selected nodes */ - hidden = 0; - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - if (node_has_hidden_sockets(node)) { - hidden = 1; - break; - } - } - } + /* Toggle for all selected nodes */ + hidden = 0; + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + if (node_has_hidden_sockets(node)) { + hidden = 1; + break; + } + } + } - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - node_set_hidden_sockets(snode, node, !hidden); - } - } + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + node_set_hidden_sockets(snode, node, !hidden); + } + } - ntreeUpdateTree(CTX_data_main(C), snode->edittree); + ntreeUpdateTree(CTX_data_main(C), snode->edittree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_hide_socket_toggle(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Toggle Hidden Node Sockets"; - ot->description = "Toggle unused node socket display"; - ot->idname = "NODE_OT_hide_socket_toggle"; + /* identifiers */ + ot->name = "Toggle Hidden Node Sockets"; + ot->description = "Toggle unused node socket display"; + ot->idname = "NODE_OT_hide_socket_toggle"; - /* callbacks */ - ot->exec = node_socket_toggle_exec; - ot->poll = ED_operator_node_active; + /* callbacks */ + ot->exec = node_socket_toggle_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Mute operator *********************** */ static int node_mute_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - bool do_tag_update = false; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + bool do_tag_update = false; - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - for (node = snode->edittree->nodes.first; node; node = node->next) { - /* Only allow muting of nodes having a mute func! */ - if ((node->flag & SELECT) && node->typeinfo->update_internal_links) { - node->flag ^= NODE_MUTED; - snode_update(snode, node); - do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node)); - } - } + for (node = snode->edittree->nodes.first; node; node = node->next) { + /* Only allow muting of nodes having a mute func! */ + if ((node->flag & SELECT) && node->typeinfo->update_internal_links) { + node->flag ^= NODE_MUTED; + snode_update(snode, node); + do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node)); + } + } - snode_notify(C, snode); - if (do_tag_update) { - snode_dag_update(C, snode); - } + snode_notify(C, snode); + if (do_tag_update) { + snode_dag_update(C, snode); + } - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_mute_toggle(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Toggle Node Mute"; - ot->description = "Toggle muting of the nodes"; - ot->idname = "NODE_OT_mute_toggle"; + /* identifiers */ + ot->name = "Toggle Node Mute"; + ot->description = "Toggle muting of the nodes"; + ot->idname = "NODE_OT_mute_toggle"; - /* callbacks */ - ot->exec = node_mute_exec; - ot->poll = ED_operator_node_editable; + /* callbacks */ + ot->exec = node_mute_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Delete operator ******************* */ static int node_delete_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node, *next; - bool do_tag_update = false; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node, *next; + bool do_tag_update = false; - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - for (node = snode->edittree->nodes.first; node; node = next) { - next = node->next; - if (node->flag & SELECT) { - do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node)); - nodeRemoveNode(bmain, snode->edittree, node, true); - } - } + for (node = snode->edittree->nodes.first; node; node = next) { + next = node->next; + if (node->flag & SELECT) { + do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node)); + nodeRemoveNode(bmain, snode->edittree, node, true); + } + } - ntreeUpdateTree(CTX_data_main(C), snode->edittree); + ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); - if (do_tag_update) { - snode_dag_update(C, snode); - } + snode_notify(C, snode); + if (do_tag_update) { + snode_dag_update(C, snode); + } - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_delete(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Delete"; - ot->description = "Delete selected nodes"; - ot->idname = "NODE_OT_delete"; + /* identifiers */ + ot->name = "Delete"; + ot->description = "Delete selected nodes"; + ot->idname = "NODE_OT_delete"; - /* api callbacks */ - ot->exec = node_delete_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = node_delete_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Switch View ******************* */ static bool node_switch_view_poll(bContext *C) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - if (snode && snode->edittree) { - return true; - } + if (snode && snode->edittree) { + return true; + } - return false; + return false; } static int node_switch_view_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node, *next; + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node, *next; - for (node = snode->edittree->nodes.first; node; node = next) { - next = node->next; - if (node->flag & SELECT) { - /* call the update function from the Switch View node */ - node->update = NODE_UPDATE_OPERATOR; - } - } + for (node = snode->edittree->nodes.first; node; node = next) { + next = node->next; + if (node->flag & SELECT) { + /* call the update function from the Switch View node */ + node->update = NODE_UPDATE_OPERATOR; + } + } - ntreeUpdateTree(CTX_data_main(C), snode->edittree); + ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(C, snode); + snode_dag_update(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_switch_view_update(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Update Views"; - ot->description = "Update views of selected node"; - ot->idname = "NODE_OT_switch_view_update"; + /* identifiers */ + ot->name = "Update Views"; + ot->description = "Update views of selected node"; + ot->idname = "NODE_OT_switch_view_update"; - /* api callbacks */ - ot->exec = node_switch_view_exec; - ot->poll = node_switch_view_poll; + /* api callbacks */ + ot->exec = node_switch_view_exec; + ot->poll = node_switch_view_poll; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Delete with reconnect ******************* */ static int node_delete_reconnect_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node, *next; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node, *next; - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - for (node = snode->edittree->nodes.first; node; node = next) { - next = node->next; - if (node->flag & SELECT) { - nodeInternalRelink(snode->edittree, node); - nodeRemoveNode(bmain, snode->edittree, node, true); - } - } + for (node = snode->edittree->nodes.first; node; node = next) { + next = node->next; + if (node->flag & SELECT) { + nodeInternalRelink(snode->edittree, node); + nodeRemoveNode(bmain, snode->edittree, node, true); + } + } - ntreeUpdateTree(CTX_data_main(C), snode->edittree); + ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(C, snode); + snode_dag_update(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_delete_reconnect(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Delete with Reconnect"; - ot->description = "Delete nodes; will reconnect nodes as if deletion was muted"; - ot->idname = "NODE_OT_delete_reconnect"; + /* identifiers */ + ot->name = "Delete with Reconnect"; + ot->description = "Delete nodes; will reconnect nodes as if deletion was muted"; + ot->idname = "NODE_OT_delete_reconnect"; - /* api callbacks */ - ot->exec = node_delete_reconnect_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = node_delete_reconnect_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } - /* ****************** File Output Add Socket ******************* */ static int node_output_file_add_socket_exec(bContext *C, wmOperator *op) { - Scene *scene = CTX_data_scene(C); - SpaceNode *snode = CTX_wm_space_node(C); - PointerRNA ptr = CTX_data_pointer_get(C, "node"); - bNodeTree *ntree = NULL; - bNode *node = NULL; - char file_path[MAX_NAME]; + Scene *scene = CTX_data_scene(C); + SpaceNode *snode = CTX_wm_space_node(C); + PointerRNA ptr = CTX_data_pointer_get(C, "node"); + bNodeTree *ntree = NULL; + bNode *node = NULL; + char file_path[MAX_NAME]; - if (ptr.data) { - node = ptr.data; - ntree = ptr.id.data; - } - else if (snode && snode->edittree) { - ntree = snode->edittree; - node = nodeGetActive(snode->edittree); - } + if (ptr.data) { + node = ptr.data; + ntree = ptr.id.data; + } + else if (snode && snode->edittree) { + ntree = snode->edittree; + node = nodeGetActive(snode->edittree); + } - if (!node || node->type != CMP_NODE_OUTPUT_FILE) { - return OPERATOR_CANCELLED; - } + if (!node || node->type != CMP_NODE_OUTPUT_FILE) { + return OPERATOR_CANCELLED; + } - RNA_string_get(op->ptr, "file_path", file_path); - ntreeCompositOutputFileAddSocket(ntree, node, file_path, &scene->r.im_format); + RNA_string_get(op->ptr, "file_path", file_path); + ntreeCompositOutputFileAddSocket(ntree, node, file_path, &scene->r.im_format); - snode_notify(C, snode); + snode_notify(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_output_file_add_socket(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Add File Node Socket"; - ot->description = "Add a new input to a file output node"; - ot->idname = "NODE_OT_output_file_add_socket"; + /* identifiers */ + ot->name = "Add File Node Socket"; + ot->description = "Add a new input to a file output node"; + ot->idname = "NODE_OT_output_file_add_socket"; - /* callbacks */ - ot->exec = node_output_file_add_socket_exec; - ot->poll = composite_node_editable; + /* callbacks */ + ot->exec = node_output_file_add_socket_exec; + ot->poll = composite_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_string(ot->srna, "file_path", "Image", MAX_NAME, "File Path", "Sub-path of the output file"); + RNA_def_string( + ot->srna, "file_path", "Image", MAX_NAME, "File Path", "Sub-path of the output file"); } /* ****************** Multi File Output Remove Socket ******************* */ static int node_output_file_remove_active_socket_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - PointerRNA ptr = CTX_data_pointer_get(C, "node"); - bNodeTree *ntree = NULL; - bNode *node = NULL; + SpaceNode *snode = CTX_wm_space_node(C); + PointerRNA ptr = CTX_data_pointer_get(C, "node"); + bNodeTree *ntree = NULL; + bNode *node = NULL; - if (ptr.data) { - node = ptr.data; - ntree = ptr.id.data; - } - else if (snode && snode->edittree) { - ntree = snode->edittree; - node = nodeGetActive(snode->edittree); - } + if (ptr.data) { + node = ptr.data; + ntree = ptr.id.data; + } + else if (snode && snode->edittree) { + ntree = snode->edittree; + node = nodeGetActive(snode->edittree); + } - if (!node || node->type != CMP_NODE_OUTPUT_FILE) { - return OPERATOR_CANCELLED; - } + if (!node || node->type != CMP_NODE_OUTPUT_FILE) { + return OPERATOR_CANCELLED; + } - if (!ntreeCompositOutputFileRemoveActiveSocket(ntree, node)) { - return OPERATOR_CANCELLED; - } + if (!ntreeCompositOutputFileRemoveActiveSocket(ntree, node)) { + return OPERATOR_CANCELLED; + } - snode_notify(C, snode); + snode_notify(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_output_file_remove_active_socket(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Remove File Node Socket"; - ot->description = "Remove active input from a file output node"; - ot->idname = "NODE_OT_output_file_remove_active_socket"; + /* identifiers */ + ot->name = "Remove File Node Socket"; + ot->description = "Remove active input from a file output node"; + ot->idname = "NODE_OT_output_file_remove_active_socket"; - /* callbacks */ - ot->exec = node_output_file_remove_active_socket_exec; - ot->poll = composite_node_editable; + /* callbacks */ + ot->exec = node_output_file_remove_active_socket_exec; + ot->poll = composite_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Multi File Output Move Socket ******************* */ static int node_output_file_move_active_socket_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - PointerRNA ptr = CTX_data_pointer_get(C, "node"); - bNode *node = NULL; - NodeImageMultiFile *nimf; - bNodeSocket *sock; - int direction; - - if (ptr.data) { - node = ptr.data; - } - else if (snode && snode->edittree) { - node = nodeGetActive(snode->edittree); - } - - if (!node || node->type != CMP_NODE_OUTPUT_FILE) { - return OPERATOR_CANCELLED; - } - - nimf = node->storage; - - sock = BLI_findlink(&node->inputs, nimf->active_input); - if (!sock) { - return OPERATOR_CANCELLED; - } - - direction = RNA_enum_get(op->ptr, "direction"); - - if (direction == 1) { - bNodeSocket *before = sock->prev; - if (!before) { - return OPERATOR_CANCELLED; - } - BLI_remlink(&node->inputs, sock); - BLI_insertlinkbefore(&node->inputs, before, sock); - nimf->active_input--; - } - else { - bNodeSocket *after = sock->next; - if (!after) { - return OPERATOR_CANCELLED; - } - BLI_remlink(&node->inputs, sock); - BLI_insertlinkafter(&node->inputs, after, sock); - nimf->active_input++; - } - - snode_notify(C, snode); - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + PointerRNA ptr = CTX_data_pointer_get(C, "node"); + bNode *node = NULL; + NodeImageMultiFile *nimf; + bNodeSocket *sock; + int direction; + + if (ptr.data) { + node = ptr.data; + } + else if (snode && snode->edittree) { + node = nodeGetActive(snode->edittree); + } + + if (!node || node->type != CMP_NODE_OUTPUT_FILE) { + return OPERATOR_CANCELLED; + } + + nimf = node->storage; + + sock = BLI_findlink(&node->inputs, nimf->active_input); + if (!sock) { + return OPERATOR_CANCELLED; + } + + direction = RNA_enum_get(op->ptr, "direction"); + + if (direction == 1) { + bNodeSocket *before = sock->prev; + if (!before) { + return OPERATOR_CANCELLED; + } + BLI_remlink(&node->inputs, sock); + BLI_insertlinkbefore(&node->inputs, before, sock); + nimf->active_input--; + } + else { + bNodeSocket *after = sock->next; + if (!after) { + return OPERATOR_CANCELLED; + } + BLI_remlink(&node->inputs, sock); + BLI_insertlinkafter(&node->inputs, after, sock); + nimf->active_input++; + } + + snode_notify(C, snode); + + return OPERATOR_FINISHED; } void NODE_OT_output_file_move_active_socket(wmOperatorType *ot) { - static const EnumPropertyItem direction_items[] = { - {1, "UP", 0, "Up", ""}, - {2, "DOWN", 0, "Down", ""}, - { 0, NULL, 0, NULL, NULL } - }; + static const EnumPropertyItem direction_items[] = { + {1, "UP", 0, "Up", ""}, {2, "DOWN", 0, "Down", ""}, {0, NULL, 0, NULL, NULL}}; - /* identifiers */ - ot->name = "Move File Node Socket"; - ot->description = "Move the active input of a file output node up or down the list"; - ot->idname = "NODE_OT_output_file_move_active_socket"; + /* identifiers */ + ot->name = "Move File Node Socket"; + ot->description = "Move the active input of a file output node up or down the list"; + ot->idname = "NODE_OT_output_file_move_active_socket"; - /* callbacks */ - ot->exec = node_output_file_move_active_socket_exec; - ot->poll = composite_node_editable; + /* callbacks */ + ot->exec = node_output_file_move_active_socket_exec; + ot->poll = composite_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_enum(ot->srna, "direction", direction_items, 2, "Direction", ""); + RNA_def_enum(ot->srna, "direction", direction_items, 2, "Direction", ""); } /* ****************** Copy Node Color ******************* */ static int node_copy_color_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *node, *tnode; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *node, *tnode; - if (!ntree) { - return OPERATOR_CANCELLED; - } - node = nodeGetActive(ntree); - if (!node) { - return OPERATOR_CANCELLED; - } + if (!ntree) { + return OPERATOR_CANCELLED; + } + node = nodeGetActive(ntree); + if (!node) { + return OPERATOR_CANCELLED; + } - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { - if (tnode->flag & NODE_SELECT && tnode != node) { - if (node->flag & NODE_CUSTOM_COLOR) { - tnode->flag |= NODE_CUSTOM_COLOR; - copy_v3_v3(tnode->color, node->color); - } - else { - tnode->flag &= ~NODE_CUSTOM_COLOR; - } - } - } + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { + if (tnode->flag & NODE_SELECT && tnode != node) { + if (node->flag & NODE_CUSTOM_COLOR) { + tnode->flag |= NODE_CUSTOM_COLOR; + copy_v3_v3(tnode->color, node->color); + } + else { + tnode->flag &= ~NODE_CUSTOM_COLOR; + } + } + } - ED_node_sort(ntree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + ED_node_sort(ntree); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_node_copy_color(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Copy Color"; - ot->description = "Copy color to all selected nodes"; - ot->idname = "NODE_OT_node_copy_color"; + /* identifiers */ + ot->name = "Copy Color"; + ot->description = "Copy color to all selected nodes"; + ot->idname = "NODE_OT_node_copy_color"; - /* api callbacks */ - ot->exec = node_copy_color_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = node_copy_color_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Copy to clipboard ******************* */ static int node_clipboard_copy_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *node; - bNodeLink *link, *newlink; - - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - - /* clear current clipboard */ - BKE_node_clipboard_clear(); - BKE_node_clipboard_init(ntree); - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - /* No ID refcounting, this node is virtual, detached from any actual Blender data currently. */ - bNode *new_node = BKE_node_copy_ex(NULL, node, LIB_ID_CREATE_NO_USER_REFCOUNT); - BKE_node_clipboard_add_node(new_node); - } - } - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - bNode *new_node = node->new_node; - - /* ensure valid pointers */ - if (new_node->parent) { - /* parent pointer must be redirected to new node or detached if parent is - * not copied */ - if (new_node->parent->flag & NODE_SELECT) { - new_node->parent = new_node->parent->new_node; - } - else { - nodeDetachNode(new_node); - } - } - } - } - - /* copy links between selected nodes - * NB: this depends on correct node->new_node and sock->new_sock pointers from above copy! - */ - for (link = ntree->links.first; link; link = link->next) { - /* This creates new links between copied nodes. */ - if (link->tonode && (link->tonode->flag & NODE_SELECT) && - link->fromnode && (link->fromnode->flag & NODE_SELECT)) - { - newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink"); - newlink->flag = link->flag; - newlink->tonode = link->tonode->new_node; - newlink->tosock = link->tosock->new_sock; - newlink->fromnode = link->fromnode->new_node; - newlink->fromsock = link->fromsock->new_sock; - - BKE_node_clipboard_add_link(newlink); - } - } - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *node; + bNodeLink *link, *newlink; + + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + + /* clear current clipboard */ + BKE_node_clipboard_clear(); + BKE_node_clipboard_init(ntree); + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + /* No ID refcounting, this node is virtual, detached from any actual Blender data currently. */ + bNode *new_node = BKE_node_copy_ex(NULL, node, LIB_ID_CREATE_NO_USER_REFCOUNT); + BKE_node_clipboard_add_node(new_node); + } + } + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + bNode *new_node = node->new_node; + + /* ensure valid pointers */ + if (new_node->parent) { + /* parent pointer must be redirected to new node or detached if parent is + * not copied */ + if (new_node->parent->flag & NODE_SELECT) { + new_node->parent = new_node->parent->new_node; + } + else { + nodeDetachNode(new_node); + } + } + } + } + + /* copy links between selected nodes + * NB: this depends on correct node->new_node and sock->new_sock pointers from above copy! + */ + for (link = ntree->links.first; link; link = link->next) { + /* This creates new links between copied nodes. */ + if (link->tonode && (link->tonode->flag & NODE_SELECT) && link->fromnode && + (link->fromnode->flag & NODE_SELECT)) { + newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink"); + newlink->flag = link->flag; + newlink->tonode = link->tonode->new_node; + newlink->tosock = link->tosock->new_sock; + newlink->fromnode = link->fromnode->new_node; + newlink->fromsock = link->fromsock->new_sock; + + BKE_node_clipboard_add_link(newlink); + } + } + + return OPERATOR_FINISHED; } void NODE_OT_clipboard_copy(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Copy to Clipboard"; - ot->description = "Copies selected nodes to the clipboard"; - ot->idname = "NODE_OT_clipboard_copy"; + /* identifiers */ + ot->name = "Copy to Clipboard"; + ot->description = "Copies selected nodes to the clipboard"; + ot->idname = "NODE_OT_clipboard_copy"; - /* api callbacks */ - ot->exec = node_clipboard_copy_exec; - ot->poll = ED_operator_node_active; + /* api callbacks */ + ot->exec = node_clipboard_copy_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Paste from clipboard ******************* */ static int node_clipboard_paste_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - const ListBase *clipboard_nodes_lb; - const ListBase *clipboard_links_lb; - bNode *node; - bNodeLink *link; - int num_nodes; - float center[2]; - bool is_clipboard_valid, all_nodes_valid; - - /* validate pointers in the clipboard */ - is_clipboard_valid = BKE_node_clipboard_validate(); - clipboard_nodes_lb = BKE_node_clipboard_get_nodes(); - clipboard_links_lb = BKE_node_clipboard_get_links(); - - if (BLI_listbase_is_empty(clipboard_nodes_lb)) { - BKE_report(op->reports, RPT_ERROR, "Clipboard is empty"); - return OPERATOR_CANCELLED; - } - - if (BKE_node_clipboard_get_type() != ntree->type) { - BKE_report(op->reports, RPT_ERROR, "Clipboard nodes are an incompatible type"); - return OPERATOR_CANCELLED; - } - - /* only warn */ - if (is_clipboard_valid == false) { - BKE_report(op->reports, RPT_WARNING, "Some nodes references could not be restored, will be left empty"); - } - - /* make sure all clipboard nodes would be valid in the target tree */ - all_nodes_valid = true; - for (node = clipboard_nodes_lb->first; node; node = node->next) { - if (!node->typeinfo->poll_instance || !node->typeinfo->poll_instance(node, ntree)) { - all_nodes_valid = false; - BKE_reportf(op->reports, RPT_ERROR, "Cannot add node %s into node tree %s", node->name, ntree->id.name + 2); - } - } - if (!all_nodes_valid) { - return OPERATOR_CANCELLED; - } - - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - - /* deselect old nodes */ - node_deselect_all(snode); - - /* calculate "barycenter" for placing on mouse cursor */ - zero_v2(center); - for (node = clipboard_nodes_lb->first, num_nodes = 0; node; node = node->next, num_nodes++) { - center[0] += BLI_rctf_cent_x(&node->totr); - center[1] += BLI_rctf_cent_y(&node->totr); - } - mul_v2_fl(center, 1.0 / num_nodes); - - /* copy nodes from clipboard */ - for (node = clipboard_nodes_lb->first; node; node = node->next) { - bNode *new_node = BKE_node_copy_ex(ntree, node, LIB_ID_COPY_DEFAULT); - - /* pasted nodes are selected */ - nodeSetSelected(new_node, true); - } - - /* reparent copied nodes */ - for (node = clipboard_nodes_lb->first; node; node = node->next) { - bNode *new_node = node->new_node; - if (new_node->parent) { - new_node->parent = new_node->parent->new_node; - } - } - - for (link = clipboard_links_lb->first; link; link = link->next) { - nodeAddLink(ntree, link->fromnode->new_node, link->fromsock->new_sock, - link->tonode->new_node, link->tosock->new_sock); - } - - ntreeUpdateTree(CTX_data_main(C), snode->edittree); - - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + const ListBase *clipboard_nodes_lb; + const ListBase *clipboard_links_lb; + bNode *node; + bNodeLink *link; + int num_nodes; + float center[2]; + bool is_clipboard_valid, all_nodes_valid; + + /* validate pointers in the clipboard */ + is_clipboard_valid = BKE_node_clipboard_validate(); + clipboard_nodes_lb = BKE_node_clipboard_get_nodes(); + clipboard_links_lb = BKE_node_clipboard_get_links(); + + if (BLI_listbase_is_empty(clipboard_nodes_lb)) { + BKE_report(op->reports, RPT_ERROR, "Clipboard is empty"); + return OPERATOR_CANCELLED; + } + + if (BKE_node_clipboard_get_type() != ntree->type) { + BKE_report(op->reports, RPT_ERROR, "Clipboard nodes are an incompatible type"); + return OPERATOR_CANCELLED; + } + + /* only warn */ + if (is_clipboard_valid == false) { + BKE_report(op->reports, + RPT_WARNING, + "Some nodes references could not be restored, will be left empty"); + } + + /* make sure all clipboard nodes would be valid in the target tree */ + all_nodes_valid = true; + for (node = clipboard_nodes_lb->first; node; node = node->next) { + if (!node->typeinfo->poll_instance || !node->typeinfo->poll_instance(node, ntree)) { + all_nodes_valid = false; + BKE_reportf(op->reports, + RPT_ERROR, + "Cannot add node %s into node tree %s", + node->name, + ntree->id.name + 2); + } + } + if (!all_nodes_valid) { + return OPERATOR_CANCELLED; + } + + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + + /* deselect old nodes */ + node_deselect_all(snode); + + /* calculate "barycenter" for placing on mouse cursor */ + zero_v2(center); + for (node = clipboard_nodes_lb->first, num_nodes = 0; node; node = node->next, num_nodes++) { + center[0] += BLI_rctf_cent_x(&node->totr); + center[1] += BLI_rctf_cent_y(&node->totr); + } + mul_v2_fl(center, 1.0 / num_nodes); + + /* copy nodes from clipboard */ + for (node = clipboard_nodes_lb->first; node; node = node->next) { + bNode *new_node = BKE_node_copy_ex(ntree, node, LIB_ID_COPY_DEFAULT); + + /* pasted nodes are selected */ + nodeSetSelected(new_node, true); + } + + /* reparent copied nodes */ + for (node = clipboard_nodes_lb->first; node; node = node->next) { + bNode *new_node = node->new_node; + if (new_node->parent) { + new_node->parent = new_node->parent->new_node; + } + } + + for (link = clipboard_links_lb->first; link; link = link->next) { + nodeAddLink(ntree, + link->fromnode->new_node, + link->fromsock->new_sock, + link->tonode->new_node, + link->tosock->new_sock); + } + + ntreeUpdateTree(CTX_data_main(C), snode->edittree); + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; } void NODE_OT_clipboard_paste(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Paste from Clipboard"; - ot->description = "Pastes nodes from the clipboard to the active node tree"; - ot->idname = "NODE_OT_clipboard_paste"; + /* identifiers */ + ot->name = "Paste from Clipboard"; + ot->description = "Pastes nodes from the clipboard to the active node tree"; + ot->idname = "NODE_OT_clipboard_paste"; - /* api callbacks */ - ot->exec = node_clipboard_paste_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = node_clipboard_paste_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /********************** Add interface socket operator *********************/ static bNodeSocket *ntree_get_active_interface_socket(ListBase *lb) { - bNodeSocket *sock; - for (sock = lb->first; sock; sock = sock->next) { - if (sock->flag & SELECT) { - return sock; - } - } - return NULL; + bNodeSocket *sock; + for (sock = lb->first; sock; sock = sock->next) { + if (sock->flag & SELECT) { + return sock; + } + } + return NULL; } static int ntree_socket_add_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - int in_out = RNA_enum_get(op->ptr, "in_out"); - PointerRNA ntree_ptr; - bNodeSocket *sock, *tsock, *active_sock; - const char *default_name; - - RNA_id_pointer_create((ID *)ntree, &ntree_ptr); - - if (in_out == SOCK_IN) { - active_sock = ntree_get_active_interface_socket(&ntree->inputs); - default_name = "Input"; - } - else { - active_sock = ntree_get_active_interface_socket(&ntree->outputs); - default_name = "Output"; - } - - if (active_sock) { - /* insert a copy of the active socket right after it */ - sock = ntreeInsertSocketInterface(ntree, in_out, active_sock->idname, active_sock->next, active_sock->name); - /* XXX this only works for actual sockets, not interface templates! */ - /*nodeSocketCopyValue(sock, &ntree_ptr, active_sock, &ntree_ptr);*/ - } - else { - /* XXX TODO define default socket type for a tree! */ - sock = ntreeAddSocketInterface(ntree, in_out, "NodeSocketFloat", default_name); - } - - /* deactivate sockets (has to check both lists) */ - for (tsock = ntree->inputs.first; tsock; tsock = tsock->next) { - tsock->flag &= ~SELECT; - } - for (tsock = ntree->outputs.first; tsock; tsock = tsock->next) { - tsock->flag &= ~SELECT; - } - /* make the new socket active */ - sock->flag |= SELECT; - - ntreeUpdateTree(CTX_data_main(C), ntree); - - snode_notify(C, snode); - snode_dag_update(C, snode); - - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + int in_out = RNA_enum_get(op->ptr, "in_out"); + PointerRNA ntree_ptr; + bNodeSocket *sock, *tsock, *active_sock; + const char *default_name; + + RNA_id_pointer_create((ID *)ntree, &ntree_ptr); + + if (in_out == SOCK_IN) { + active_sock = ntree_get_active_interface_socket(&ntree->inputs); + default_name = "Input"; + } + else { + active_sock = ntree_get_active_interface_socket(&ntree->outputs); + default_name = "Output"; + } + + if (active_sock) { + /* insert a copy of the active socket right after it */ + sock = ntreeInsertSocketInterface( + ntree, in_out, active_sock->idname, active_sock->next, active_sock->name); + /* XXX this only works for actual sockets, not interface templates! */ + /*nodeSocketCopyValue(sock, &ntree_ptr, active_sock, &ntree_ptr);*/ + } + else { + /* XXX TODO define default socket type for a tree! */ + sock = ntreeAddSocketInterface(ntree, in_out, "NodeSocketFloat", default_name); + } + + /* deactivate sockets (has to check both lists) */ + for (tsock = ntree->inputs.first; tsock; tsock = tsock->next) { + tsock->flag &= ~SELECT; + } + for (tsock = ntree->outputs.first; tsock; tsock = tsock->next) { + tsock->flag &= ~SELECT; + } + /* make the new socket active */ + sock->flag |= SELECT; + + ntreeUpdateTree(CTX_data_main(C), ntree); + + snode_notify(C, snode); + snode_dag_update(C, snode); + + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; } void NODE_OT_tree_socket_add(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Add Node Tree Interface Socket"; - ot->description = "Add an input or output socket to the current node tree"; - ot->idname = "NODE_OT_tree_socket_add"; + /* identifiers */ + ot->name = "Add Node Tree Interface Socket"; + ot->description = "Add an input or output socket to the current node tree"; + ot->idname = "NODE_OT_tree_socket_add"; - /* api callbacks */ - ot->exec = ntree_socket_add_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = ntree_socket_add_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_enum(ot->srna, "in_out", rna_enum_node_socket_in_out_items, SOCK_IN, "Socket Type", ""); + RNA_def_enum(ot->srna, "in_out", rna_enum_node_socket_in_out_items, SOCK_IN, "Socket Type", ""); } /********************** Remove interface socket operator *********************/ static int ntree_socket_remove_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNodeSocket *iosock, *active_sock; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNodeSocket *iosock, *active_sock; - iosock = ntree_get_active_interface_socket(&ntree->inputs); - if (!iosock) { - iosock = ntree_get_active_interface_socket(&ntree->outputs); - } - if (!iosock) { - return OPERATOR_CANCELLED; - } + iosock = ntree_get_active_interface_socket(&ntree->inputs); + if (!iosock) { + iosock = ntree_get_active_interface_socket(&ntree->outputs); + } + if (!iosock) { + return OPERATOR_CANCELLED; + } - /* preferably next socket becomes active, otherwise try previous socket */ - active_sock = (iosock->next ? iosock->next : iosock->prev); - ntreeRemoveSocketInterface(ntree, iosock); + /* preferably next socket becomes active, otherwise try previous socket */ + active_sock = (iosock->next ? iosock->next : iosock->prev); + ntreeRemoveSocketInterface(ntree, iosock); - /* set active socket */ - if (active_sock) { - active_sock->flag |= SELECT; - } + /* set active socket */ + if (active_sock) { + active_sock->flag |= SELECT; + } - ntreeUpdateTree(CTX_data_main(C), ntree); + ntreeUpdateTree(CTX_data_main(C), ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(C, snode); + snode_dag_update(C, snode); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_tree_socket_remove(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Remove Node Tree Interface Socket"; - ot->description = "Remove an input or output socket to the current node tree"; - ot->idname = "NODE_OT_tree_socket_remove"; + /* identifiers */ + ot->name = "Remove Node Tree Interface Socket"; + ot->description = "Remove an input or output socket to the current node tree"; + ot->idname = "NODE_OT_tree_socket_remove"; - /* api callbacks */ - ot->exec = ntree_socket_remove_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = ntree_socket_remove_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /********************** Move interface socket operator *********************/ static const EnumPropertyItem move_direction_items[] = { - { 1, "UP", 0, "Up", "" }, - { 2, "DOWN", 0, "Down", "" }, - { 0, NULL, 0, NULL, NULL }, + {1, "UP", 0, "Up", ""}, + {2, "DOWN", 0, "Down", ""}, + {0, NULL, 0, NULL, NULL}, }; static int ntree_socket_move_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - int direction = RNA_enum_get(op->ptr, "direction"); - bNodeSocket *iosock; - ListBase *lb; - - lb = &ntree->inputs; - iosock = ntree_get_active_interface_socket(lb); - if (!iosock) { - lb = &ntree->outputs; - iosock = ntree_get_active_interface_socket(lb); - } - if (!iosock) { - return OPERATOR_CANCELLED; - } - - switch (direction) { - case 1: - { /* up */ - bNodeSocket *before = iosock->prev; - BLI_remlink(lb, iosock); - if (before) { - BLI_insertlinkbefore(lb, before, iosock); - } - else { - BLI_addhead(lb, iosock); - } - break; - } - case 2: - { /* down */ - bNodeSocket *after = iosock->next; - BLI_remlink(lb, iosock); - if (after) { - BLI_insertlinkafter(lb, after, iosock); - } - else { - BLI_addtail(lb, iosock); - } - break; - } - } - - ntreeUpdateTree(CTX_data_main(C), ntree); - - snode_notify(C, snode); - snode_dag_update(C, snode); - - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + int direction = RNA_enum_get(op->ptr, "direction"); + bNodeSocket *iosock; + ListBase *lb; + + lb = &ntree->inputs; + iosock = ntree_get_active_interface_socket(lb); + if (!iosock) { + lb = &ntree->outputs; + iosock = ntree_get_active_interface_socket(lb); + } + if (!iosock) { + return OPERATOR_CANCELLED; + } + + switch (direction) { + case 1: { /* up */ + bNodeSocket *before = iosock->prev; + BLI_remlink(lb, iosock); + if (before) { + BLI_insertlinkbefore(lb, before, iosock); + } + else { + BLI_addhead(lb, iosock); + } + break; + } + case 2: { /* down */ + bNodeSocket *after = iosock->next; + BLI_remlink(lb, iosock); + if (after) { + BLI_insertlinkafter(lb, after, iosock); + } + else { + BLI_addtail(lb, iosock); + } + break; + } + } + + ntreeUpdateTree(CTX_data_main(C), ntree); + + snode_notify(C, snode); + snode_dag_update(C, snode); + + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; } void NODE_OT_tree_socket_move(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Move Node Tree Socket"; - ot->description = "Move a socket up or down in the current node tree's sockets stack"; - ot->idname = "NODE_OT_tree_socket_move"; + /* identifiers */ + ot->name = "Move Node Tree Socket"; + ot->description = "Move a socket up or down in the current node tree's sockets stack"; + ot->idname = "NODE_OT_tree_socket_move"; - /* api callbacks */ - ot->exec = ntree_socket_move_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = ntree_socket_move_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_enum(ot->srna, "direction", move_direction_items, 1, "Direction", ""); + RNA_def_enum(ot->srna, "direction", move_direction_items, 1, "Direction", ""); } /* ********************** Shader Script Update ******************/ static bool node_shader_script_update_poll(bContext *C) { - Scene *scene = CTX_data_scene(C); - RenderEngineType *type = RE_engines_find(scene->r.engine); - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - Text *text; + Scene *scene = CTX_data_scene(C); + RenderEngineType *type = RE_engines_find(scene->r.engine); + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + Text *text; - /* test if we have a render engine that supports shaders scripts */ - if (!(type && type->update_script_node)) { - return 0; - } + /* test if we have a render engine that supports shaders scripts */ + if (!(type && type->update_script_node)) { + return 0; + } - /* see if we have a shader script node in context */ - node = CTX_data_pointer_get_type(C, "node", &RNA_ShaderNodeScript).data; + /* see if we have a shader script node in context */ + node = CTX_data_pointer_get_type(C, "node", &RNA_ShaderNodeScript).data; - if (!node && snode && snode->edittree) { - node = nodeGetActive(snode->edittree); - } + if (!node && snode && snode->edittree) { + node = nodeGetActive(snode->edittree); + } - if (node && node->type == SH_NODE_SCRIPT) { - NodeShaderScript *nss = node->storage; + if (node && node->type == SH_NODE_SCRIPT) { + NodeShaderScript *nss = node->storage; - if (node->id || nss->filepath[0]) { - return ED_operator_node_editable(C); - } - } + if (node->id || nss->filepath[0]) { + return ED_operator_node_editable(C); + } + } - /* see if we have a text datablock in context */ - text = CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data; - if (text) { - return 1; - } + /* see if we have a text datablock in context */ + text = CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data; + if (text) { + return 1; + } - /* we don't check if text datablock is actually in use, too slow for poll */ + /* we don't check if text datablock is actually in use, too slow for poll */ - return 0; + return 0; } /* recursively check for script nodes in groups using this text and update */ -static bool node_shader_script_update_text_recursive(RenderEngine *engine, RenderEngineType *type, bNodeTree *ntree, Text *text) +static bool node_shader_script_update_text_recursive(RenderEngine *engine, + RenderEngineType *type, + bNodeTree *ntree, + Text *text) { - bool found = false; - bNode *node; + bool found = false; + bNode *node; - ntree->done = true; + ntree->done = true; - /* update each script that is using this text datablock */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == NODE_GROUP) { - bNodeTree *ngroup = (bNodeTree *)node->id; - if (ngroup && !ngroup->done) { - found |= node_shader_script_update_text_recursive(engine, type, ngroup, text); - } - } - else if (node->type == SH_NODE_SCRIPT && node->id == &text->id) { - type->update_script_node(engine, ntree, node); - found = true; - } - } + /* update each script that is using this text datablock */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == NODE_GROUP) { + bNodeTree *ngroup = (bNodeTree *)node->id; + if (ngroup && !ngroup->done) { + found |= node_shader_script_update_text_recursive(engine, type, ngroup, text); + } + } + else if (node->type == SH_NODE_SCRIPT && node->id == &text->id) { + type->update_script_node(engine, ntree, node); + found = true; + } + } - return found; + return found; } static int node_shader_script_update_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - SpaceNode *snode = CTX_wm_space_node(C); - PointerRNA nodeptr = CTX_data_pointer_get_type(C, "node", &RNA_ShaderNodeScript); - bNodeTree *ntree_base = NULL; - bNode *node = NULL; - RenderEngine *engine; - RenderEngineType *type; - bool found = false; - - /* setup render engine */ - type = RE_engines_find(scene->r.engine); - engine = RE_engine_create(type); - engine->reports = op->reports; - - /* get node */ - if (nodeptr.data) { - ntree_base = nodeptr.id.data; - node = nodeptr.data; - } - else if (snode && snode->edittree) { - ntree_base = snode->edittree; - node = nodeGetActive(snode->edittree); - } - - if (node) { - /* update single node */ - type->update_script_node(engine, ntree_base, node); - - found = true; - } - else { - /* update all nodes using text datablock */ - Text *text = CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data; - - if (text) { - /* clear flags for recursion check */ - FOREACH_NODETREE_BEGIN(bmain, ntree, id) { - if (ntree->type == NTREE_SHADER) { - ntree->done = false; - } - } FOREACH_NODETREE_END; - - FOREACH_NODETREE_BEGIN(bmain, ntree, id) { - if (ntree->type == NTREE_SHADER) { - if (!ntree->done) { - found |= node_shader_script_update_text_recursive(engine, type, ntree, text); - } - } - } FOREACH_NODETREE_END; - - if (!found) { - BKE_report(op->reports, RPT_INFO, "Text not used by any node, no update done"); - } - } - } - - RE_engine_free(engine); - - return (found) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + SpaceNode *snode = CTX_wm_space_node(C); + PointerRNA nodeptr = CTX_data_pointer_get_type(C, "node", &RNA_ShaderNodeScript); + bNodeTree *ntree_base = NULL; + bNode *node = NULL; + RenderEngine *engine; + RenderEngineType *type; + bool found = false; + + /* setup render engine */ + type = RE_engines_find(scene->r.engine); + engine = RE_engine_create(type); + engine->reports = op->reports; + + /* get node */ + if (nodeptr.data) { + ntree_base = nodeptr.id.data; + node = nodeptr.data; + } + else if (snode && snode->edittree) { + ntree_base = snode->edittree; + node = nodeGetActive(snode->edittree); + } + + if (node) { + /* update single node */ + type->update_script_node(engine, ntree_base, node); + + found = true; + } + else { + /* update all nodes using text datablock */ + Text *text = CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data; + + if (text) { + /* clear flags for recursion check */ + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + if (ntree->type == NTREE_SHADER) { + ntree->done = false; + } + } + FOREACH_NODETREE_END; + + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + if (ntree->type == NTREE_SHADER) { + if (!ntree->done) { + found |= node_shader_script_update_text_recursive(engine, type, ntree, text); + } + } + } + FOREACH_NODETREE_END; + + if (!found) { + BKE_report(op->reports, RPT_INFO, "Text not used by any node, no update done"); + } + } + } + + RE_engine_free(engine); + + return (found) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } void NODE_OT_shader_script_update(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Script Node Update"; - ot->description = "Update shader script node with new sockets and options from the script"; - ot->idname = "NODE_OT_shader_script_update"; + /* identifiers */ + ot->name = "Script Node Update"; + ot->description = "Update shader script node with new sockets and options from the script"; + ot->idname = "NODE_OT_shader_script_update"; - /* api callbacks */ - ot->exec = node_shader_script_update_exec; - ot->poll = node_shader_script_update_poll; + /* api callbacks */ + ot->exec = node_shader_script_update_exec; + ot->poll = node_shader_script_update_poll; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ********************** Viewer border ******************/ -static void viewer_border_corner_to_backdrop(SpaceNode *snode, ARegion *ar, int x, int y, - int backdrop_width, int backdrop_height, - float *fx, float *fy) +static void viewer_border_corner_to_backdrop(SpaceNode *snode, + ARegion *ar, + int x, + int y, + int backdrop_width, + int backdrop_height, + float *fx, + float *fy) { - float bufx, bufy; + float bufx, bufy; - bufx = backdrop_width * snode->zoom; - bufy = backdrop_height * snode->zoom; + bufx = backdrop_width * snode->zoom; + bufy = backdrop_height * snode->zoom; - *fx = (bufx > 0.0f ? ((float) x - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); - *fy = (bufy > 0.0f ? ((float) y - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); + *fx = (bufx > 0.0f ? ((float)x - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); + *fy = (bufy > 0.0f ? ((float)y - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); } static int viewer_border_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - Image *ima; - void *lock; - ImBuf *ibuf; + Main *bmain = CTX_data_main(C); + Image *ima; + void *lock; + ImBuf *ibuf; - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - if (ibuf) { - ARegion *ar = CTX_wm_region(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *btree = snode->nodetree; - rcti rect; - rctf rectf; + if (ibuf) { + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *btree = snode->nodetree; + rcti rect; + rctf rectf; - /* get border from operator */ - WM_operator_properties_border_to_rcti(op, &rect); + /* get border from operator */ + WM_operator_properties_border_to_rcti(op, &rect); - /* convert border to unified space within backdrop image */ - viewer_border_corner_to_backdrop(snode, ar, rect.xmin, rect.ymin, ibuf->x, ibuf->y, - &rectf.xmin, &rectf.ymin); + /* convert border to unified space within backdrop image */ + viewer_border_corner_to_backdrop( + snode, ar, rect.xmin, rect.ymin, ibuf->x, ibuf->y, &rectf.xmin, &rectf.ymin); - viewer_border_corner_to_backdrop(snode, ar, rect.xmax, rect.ymax, ibuf->x, ibuf->y, - &rectf.xmax, &rectf.ymax); + viewer_border_corner_to_backdrop( + snode, ar, rect.xmax, rect.ymax, ibuf->x, ibuf->y, &rectf.xmax, &rectf.ymax); - /* clamp coordinates */ - rectf.xmin = max_ff(rectf.xmin, 0.0f); - rectf.ymin = max_ff(rectf.ymin, 0.0f); - rectf.xmax = min_ff(rectf.xmax, 1.0f); - rectf.ymax = min_ff(rectf.ymax, 1.0f); + /* clamp coordinates */ + rectf.xmin = max_ff(rectf.xmin, 0.0f); + rectf.ymin = max_ff(rectf.ymin, 0.0f); + rectf.xmax = min_ff(rectf.xmax, 1.0f); + rectf.ymax = min_ff(rectf.ymax, 1.0f); - if (rectf.xmin < rectf.xmax && rectf.ymin < rectf.ymax) { - btree->viewer_border = rectf; + if (rectf.xmin < rectf.xmax && rectf.ymin < rectf.ymax) { + btree->viewer_border = rectf; - if (rectf.xmin == 0.0f && rectf.ymin == 0.0f && - rectf.xmax == 1.0f && rectf.ymax == 1.0f) - { - btree->flag &= ~NTREE_VIEWER_BORDER; - } - else { - btree->flag |= NTREE_VIEWER_BORDER; - } + if (rectf.xmin == 0.0f && rectf.ymin == 0.0f && rectf.xmax == 1.0f && rectf.ymax == 1.0f) { + btree->flag &= ~NTREE_VIEWER_BORDER; + } + else { + btree->flag |= NTREE_VIEWER_BORDER; + } - snode_notify(C, snode); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - } - else { - btree->flag &= ~NTREE_VIEWER_BORDER; - } - } + snode_notify(C, snode); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + } + else { + btree->flag &= ~NTREE_VIEWER_BORDER; + } + } - BKE_image_release_ibuf(ima, ibuf, lock); + BKE_image_release_ibuf(ima, ibuf, lock); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_viewer_border(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Viewer Border"; - ot->description = "Set the boundaries for viewer operations"; - ot->idname = "NODE_OT_viewer_border"; + /* identifiers */ + ot->name = "Viewer Border"; + ot->description = "Set the boundaries for viewer operations"; + ot->idname = "NODE_OT_viewer_border"; - /* api callbacks */ - ot->invoke = WM_gesture_box_invoke; - ot->exec = viewer_border_exec; - ot->modal = WM_gesture_box_modal; - ot->cancel = WM_gesture_box_cancel; - ot->poll = composite_node_active; + /* api callbacks */ + ot->invoke = WM_gesture_box_invoke; + ot->exec = viewer_border_exec; + ot->modal = WM_gesture_box_modal; + ot->cancel = WM_gesture_box_cancel; + ot->poll = composite_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* properties */ - WM_operator_properties_gesture_box_select(ot); + /* properties */ + WM_operator_properties_gesture_box_select(ot); } static int clear_viewer_border_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *btree = snode->nodetree; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *btree = snode->nodetree; - btree->flag &= ~NTREE_VIEWER_BORDER; - snode_notify(C, snode); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + btree->flag &= ~NTREE_VIEWER_BORDER; + snode_notify(C, snode); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_clear_viewer_border(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Clear Viewer Border"; - ot->description = "Clear the boundaries for viewer operations"; - ot->idname = "NODE_OT_clear_viewer_border"; + /* identifiers */ + ot->name = "Clear Viewer Border"; + ot->description = "Clear the boundaries for viewer operations"; + ot->idname = "NODE_OT_clear_viewer_border"; - /* api callbacks */ - ot->exec = clear_viewer_border_exec; - ot->poll = composite_node_active; + /* api callbacks */ + ot->exec = clear_viewer_border_exec; + ot->poll = composite_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Cryptomatte Add Socket ******************* */ static int node_cryptomatte_add_socket_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - PointerRNA ptr = CTX_data_pointer_get(C, "node"); - bNodeTree *ntree = NULL; - bNode *node = NULL; + SpaceNode *snode = CTX_wm_space_node(C); + PointerRNA ptr = CTX_data_pointer_get(C, "node"); + bNodeTree *ntree = NULL; + bNode *node = NULL; - if (ptr.data) { - node = ptr.data; - ntree = ptr.id.data; - } - else if (snode && snode->edittree) { - ntree = snode->edittree; - node = nodeGetActive(snode->edittree); - } + if (ptr.data) { + node = ptr.data; + ntree = ptr.id.data; + } + else if (snode && snode->edittree) { + ntree = snode->edittree; + node = nodeGetActive(snode->edittree); + } - if (!node || node->type != CMP_NODE_CRYPTOMATTE) { - return OPERATOR_CANCELLED; - } + if (!node || node->type != CMP_NODE_CRYPTOMATTE) { + return OPERATOR_CANCELLED; + } - ntreeCompositCryptomatteAddSocket(ntree, node); + ntreeCompositCryptomatteAddSocket(ntree, node); - snode_notify(C, snode); + snode_notify(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_cryptomatte_layer_add(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Add Cryptomatte Socket"; - ot->description = "Add a new input layer to a Cryptomatte node"; - ot->idname = "NODE_OT_cryptomatte_layer_add"; + /* identifiers */ + ot->name = "Add Cryptomatte Socket"; + ot->description = "Add a new input layer to a Cryptomatte node"; + ot->idname = "NODE_OT_cryptomatte_layer_add"; - /* callbacks */ - ot->exec = node_cryptomatte_add_socket_exec; - ot->poll = composite_node_editable; + /* callbacks */ + ot->exec = node_cryptomatte_add_socket_exec; + ot->poll = composite_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Cryptomatte Remove Socket ******************* */ static int node_cryptomatte_remove_socket_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - PointerRNA ptr = CTX_data_pointer_get(C, "node"); - bNodeTree *ntree = NULL; - bNode *node = NULL; + SpaceNode *snode = CTX_wm_space_node(C); + PointerRNA ptr = CTX_data_pointer_get(C, "node"); + bNodeTree *ntree = NULL; + bNode *node = NULL; - if (ptr.data) { - node = ptr.data; - ntree = ptr.id.data; - } - else if (snode && snode->edittree) { - ntree = snode->edittree; - node = nodeGetActive(snode->edittree); - } + if (ptr.data) { + node = ptr.data; + ntree = ptr.id.data; + } + else if (snode && snode->edittree) { + ntree = snode->edittree; + node = nodeGetActive(snode->edittree); + } - if (!node || node->type != CMP_NODE_CRYPTOMATTE) { - return OPERATOR_CANCELLED; - } + if (!node || node->type != CMP_NODE_CRYPTOMATTE) { + return OPERATOR_CANCELLED; + } - if (!ntreeCompositCryptomatteRemoveSocket(ntree, node)) { - return OPERATOR_CANCELLED; - } + if (!ntreeCompositCryptomatteRemoveSocket(ntree, node)) { + return OPERATOR_CANCELLED; + } - snode_notify(C, snode); + snode_notify(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_cryptomatte_layer_remove(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Remove Cryptomatte Socket"; - ot->description = "Remove layer from a Cryptomatte node"; - ot->idname = "NODE_OT_cryptomatte_layer_remove"; + /* identifiers */ + ot->name = "Remove Cryptomatte Socket"; + ot->description = "Remove layer from a Cryptomatte node"; + ot->idname = "NODE_OT_cryptomatte_layer_remove"; - /* callbacks */ - ot->exec = node_cryptomatte_remove_socket_exec; - ot->poll = composite_node_editable; + /* callbacks */ + ot->exec = node_cryptomatte_remove_socket_exec; + ot->poll = composite_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } diff --git a/source/blender/editors/space_node/node_gizmo.c b/source/blender/editors/space_node/node_gizmo.c index a511d6b9bd4..dbbef222250 100644 --- a/source/blender/editors/space_node/node_gizmo.c +++ b/source/blender/editors/space_node/node_gizmo.c @@ -43,153 +43,154 @@ #include "node_intern.h" - /* -------------------------------------------------------------------- */ /** \name Local Utilities * \{ */ -static void node_gizmo_calc_matrix_space( - const SpaceNode *snode, const ARegion *ar, float matrix_space[4][4]) +static void node_gizmo_calc_matrix_space(const SpaceNode *snode, + const ARegion *ar, + float matrix_space[4][4]) { - unit_m4(matrix_space); - mul_v3_fl(matrix_space[0], snode->zoom); - mul_v3_fl(matrix_space[1], snode->zoom); - matrix_space[3][0] = (ar->winx / 2) + snode->xof; - matrix_space[3][1] = (ar->winy / 2) + snode->yof; + unit_m4(matrix_space); + mul_v3_fl(matrix_space[0], snode->zoom); + mul_v3_fl(matrix_space[1], snode->zoom); + matrix_space[3][0] = (ar->winx / 2) + snode->xof; + matrix_space[3][1] = (ar->winy / 2) + snode->yof; } -static void node_gizmo_calc_matrix_space_with_image_dims( - const SpaceNode *snode, const ARegion *ar, const float image_dims[2], float matrix_space[4][4]) +static void node_gizmo_calc_matrix_space_with_image_dims(const SpaceNode *snode, + const ARegion *ar, + const float image_dims[2], + float matrix_space[4][4]) { - unit_m4(matrix_space); - mul_v3_fl(matrix_space[0], snode->zoom * image_dims[0]); - mul_v3_fl(matrix_space[1], snode->zoom * image_dims[1]); - matrix_space[3][0] = ((ar->winx / 2) + snode->xof) - ((image_dims[0] / 2.0f) * snode->zoom); - matrix_space[3][1] = ((ar->winy / 2) + snode->yof) - ((image_dims[1] / 2.0f) * snode->zoom); + unit_m4(matrix_space); + mul_v3_fl(matrix_space[0], snode->zoom * image_dims[0]); + mul_v3_fl(matrix_space[1], snode->zoom * image_dims[1]); + matrix_space[3][0] = ((ar->winx / 2) + snode->xof) - ((image_dims[0] / 2.0f) * snode->zoom); + matrix_space[3][1] = ((ar->winy / 2) + snode->yof) - ((image_dims[1] / 2.0f) * snode->zoom); } /** \} */ - - /* -------------------------------------------------------------------- */ /** \name Backdrop Gizmo * \{ */ -static void gizmo_node_backdrop_prop_matrix_get( - const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, - void *value_p) +static void gizmo_node_backdrop_prop_matrix_get(const wmGizmo *UNUSED(gz), + wmGizmoProperty *gz_prop, + void *value_p) { - float (*matrix)[4] = value_p; - BLI_assert(gz_prop->type->array_length == 16); - const SpaceNode *snode = gz_prop->custom_func.user_data; - matrix[0][0] = snode->zoom; - matrix[1][1] = snode->zoom; - matrix[3][0] = snode->xof; - matrix[3][1] = snode->yof; + float(*matrix)[4] = value_p; + BLI_assert(gz_prop->type->array_length == 16); + const SpaceNode *snode = gz_prop->custom_func.user_data; + matrix[0][0] = snode->zoom; + matrix[1][1] = snode->zoom; + matrix[3][0] = snode->xof; + matrix[3][1] = snode->yof; } -static void gizmo_node_backdrop_prop_matrix_set( - const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, - const void *value_p) +static void gizmo_node_backdrop_prop_matrix_set(const wmGizmo *UNUSED(gz), + wmGizmoProperty *gz_prop, + const void *value_p) { - const float (*matrix)[4] = value_p; - BLI_assert(gz_prop->type->array_length == 16); - SpaceNode *snode = gz_prop->custom_func.user_data; - snode->zoom = matrix[0][0]; - snode->zoom = matrix[1][1]; - snode->xof = matrix[3][0]; - snode->yof = matrix[3][1]; + const float(*matrix)[4] = value_p; + BLI_assert(gz_prop->type->array_length == 16); + SpaceNode *snode = gz_prop->custom_func.user_data; + snode->zoom = matrix[0][0]; + snode->zoom = matrix[1][1]; + snode->xof = matrix[3][0]; + snode->yof = matrix[3][1]; } static bool WIDGETGROUP_node_transform_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - if ((snode->flag & SNODE_BACKDRAW) == 0) { - return false; - } + if ((snode->flag & SNODE_BACKDRAW) == 0) { + return false; + } - if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) { - bNode *node = nodeGetActive(snode->edittree); + if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) { + bNode *node = nodeGetActive(snode->edittree); - if (node && ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { - return true; - } - } + if (node && ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { + return true; + } + } - return false; + return false; } static void WIDGETGROUP_node_transform_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) { - wmGizmoWrapper *wwrapper = MEM_mallocN(sizeof(wmGizmoWrapper), __func__); + wmGizmoWrapper *wwrapper = MEM_mallocN(sizeof(wmGizmoWrapper), __func__); - wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, NULL); + wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, NULL); - RNA_enum_set(wwrapper->gizmo->ptr, "transform", - ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE | ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM); + RNA_enum_set(wwrapper->gizmo->ptr, + "transform", + ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE | ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE_UNIFORM); - gzgroup->customdata = wwrapper; + gzgroup->customdata = wwrapper; } static void WIDGETGROUP_node_transform_refresh(const bContext *C, wmGizmoGroup *gzgroup) { - Main *bmain = CTX_data_main(C); - wmGizmo *cage = ((wmGizmoWrapper *)gzgroup->customdata)->gizmo; - const ARegion *ar = CTX_wm_region(C); - /* center is always at the origin */ - const float origin[3] = {ar->winx / 2, ar->winy / 2}; - - void *lock; - Image *ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - - if (ibuf) { - const float dims[2] = { - (ibuf->x > 0) ? ibuf->x : 64.0f, - (ibuf->y > 0) ? ibuf->y : 64.0f, - }; - - RNA_float_set_array(cage->ptr, "dimensions", dims); - WM_gizmo_set_matrix_location(cage, origin); - WM_gizmo_set_flag(cage, WM_GIZMO_HIDDEN, false); - - /* need to set property here for undo. TODO would prefer to do this in _init */ - SpaceNode *snode = CTX_wm_space_node(C); + Main *bmain = CTX_data_main(C); + wmGizmo *cage = ((wmGizmoWrapper *)gzgroup->customdata)->gizmo; + const ARegion *ar = CTX_wm_region(C); + /* center is always at the origin */ + const float origin[3] = {ar->winx / 2, ar->winy / 2}; + + void *lock; + Image *ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + + if (ibuf) { + const float dims[2] = { + (ibuf->x > 0) ? ibuf->x : 64.0f, + (ibuf->y > 0) ? ibuf->y : 64.0f, + }; + + RNA_float_set_array(cage->ptr, "dimensions", dims); + WM_gizmo_set_matrix_location(cage, origin); + WM_gizmo_set_flag(cage, WM_GIZMO_HIDDEN, false); + + /* need to set property here for undo. TODO would prefer to do this in _init */ + SpaceNode *snode = CTX_wm_space_node(C); #if 0 - PointerRNA nodeptr; - RNA_pointer_create(snode->id, &RNA_SpaceNodeEditor, snode, &nodeptr); - WM_gizmo_target_property_def_rna(cage, "offset", &nodeptr, "backdrop_offset", -1); - WM_gizmo_target_property_def_rna(cage, "scale", &nodeptr, "backdrop_zoom", -1); + PointerRNA nodeptr; + RNA_pointer_create(snode->id, &RNA_SpaceNodeEditor, snode, &nodeptr); + WM_gizmo_target_property_def_rna(cage, "offset", &nodeptr, "backdrop_offset", -1); + WM_gizmo_target_property_def_rna(cage, "scale", &nodeptr, "backdrop_zoom", -1); #endif - WM_gizmo_target_property_def_func( - cage, "matrix", - &(const struct wmGizmoPropertyFnParams) { - .value_get_fn = gizmo_node_backdrop_prop_matrix_get, - .value_set_fn = gizmo_node_backdrop_prop_matrix_set, - .range_get_fn = NULL, - .user_data = snode, - }); - } - else { - WM_gizmo_set_flag(cage, WM_GIZMO_HIDDEN, true); - } - - BKE_image_release_ibuf(ima, ibuf, lock); + WM_gizmo_target_property_def_func(cage, + "matrix", + &(const struct wmGizmoPropertyFnParams){ + .value_get_fn = gizmo_node_backdrop_prop_matrix_get, + .value_set_fn = gizmo_node_backdrop_prop_matrix_set, + .range_get_fn = NULL, + .user_data = snode, + }); + } + else { + WM_gizmo_set_flag(cage, WM_GIZMO_HIDDEN, true); + } + + BKE_image_release_ibuf(ima, ibuf, lock); } void NODE_GGT_backdrop_transform(wmGizmoGroupType *gzgt) { - gzgt->name = "Backdrop Transform Widget"; - gzgt->idname = "NODE_GGT_backdrop_transform"; + gzgt->name = "Backdrop Transform Widget"; + gzgt->idname = "NODE_GGT_backdrop_transform"; - gzgt->flag |= WM_GIZMOGROUPTYPE_PERSISTENT; + gzgt->flag |= WM_GIZMOGROUPTYPE_PERSISTENT; - gzgt->poll = WIDGETGROUP_node_transform_poll; - gzgt->setup = WIDGETGROUP_node_transform_setup; - gzgt->refresh = WIDGETGROUP_node_transform_refresh; + gzgt->poll = WIDGETGROUP_node_transform_poll; + gzgt->setup = WIDGETGROUP_node_transform_setup; + gzgt->refresh = WIDGETGROUP_node_transform_refresh; } /** \} */ @@ -199,199 +200,218 @@ void NODE_GGT_backdrop_transform(wmGizmoGroupType *gzgt) * \{ */ struct NodeCropWidgetGroup { - wmGizmo *border; + wmGizmo *border; - struct { - float dims[2]; - } state; + struct { + float dims[2]; + } state; - struct { - PointerRNA ptr; - PropertyRNA *prop; - bContext *context; - } update_data; + struct { + PointerRNA ptr; + PropertyRNA *prop; + bContext *context; + } update_data; }; static void gizmo_node_crop_update(struct NodeCropWidgetGroup *crop_group) { - RNA_property_update(crop_group->update_data.context, &crop_group->update_data.ptr, crop_group->update_data.prop); + RNA_property_update( + crop_group->update_data.context, &crop_group->update_data.ptr, crop_group->update_data.prop); } -static void two_xy_to_rect(const NodeTwoXYs *nxy, rctf *rect, const float dims[2], bool is_relative) +static void two_xy_to_rect(const NodeTwoXYs *nxy, + rctf *rect, + const float dims[2], + bool is_relative) { - if (is_relative) { - rect->xmin = nxy->fac_x1; - rect->xmax = nxy->fac_x2; - rect->ymin = nxy->fac_y1; - rect->ymax = nxy->fac_y2; - } - else { - rect->xmin = nxy->x1 / dims[0]; - rect->xmax = nxy->x2 / dims[0]; - rect->ymin = nxy->y1 / dims[1]; - rect->ymax = nxy->y2 / dims[1]; - } + if (is_relative) { + rect->xmin = nxy->fac_x1; + rect->xmax = nxy->fac_x2; + rect->ymin = nxy->fac_y1; + rect->ymax = nxy->fac_y2; + } + else { + rect->xmin = nxy->x1 / dims[0]; + rect->xmax = nxy->x2 / dims[0]; + rect->ymin = nxy->y1 / dims[1]; + rect->ymax = nxy->y2 / dims[1]; + } } -static void two_xy_from_rect(NodeTwoXYs *nxy, const rctf *rect, const float dims[2], bool is_relative) +static void two_xy_from_rect(NodeTwoXYs *nxy, + const rctf *rect, + const float dims[2], + bool is_relative) { - if (is_relative) { - nxy->fac_x1 = rect->xmin; - nxy->fac_x2 = rect->xmax; - nxy->fac_y1 = rect->ymin; - nxy->fac_y2 = rect->ymax; - } - else { - nxy->x1 = rect->xmin * dims[0]; - nxy->x2 = rect->xmax * dims[0]; - nxy->y1 = rect->ymin * dims[1]; - nxy->y2 = rect->ymax * dims[1]; - } + if (is_relative) { + nxy->fac_x1 = rect->xmin; + nxy->fac_x2 = rect->xmax; + nxy->fac_y1 = rect->ymin; + nxy->fac_y2 = rect->ymax; + } + else { + nxy->x1 = rect->xmin * dims[0]; + nxy->x2 = rect->xmax * dims[0]; + nxy->y1 = rect->ymin * dims[1]; + nxy->y2 = rect->ymax * dims[1]; + } } /* scale callbacks */ -static void gizmo_node_crop_prop_matrix_get( - const wmGizmo *gz, wmGizmoProperty *gz_prop, - void *value_p) +static void gizmo_node_crop_prop_matrix_get(const wmGizmo *gz, + wmGizmoProperty *gz_prop, + void *value_p) { - float (*matrix)[4] = value_p; - BLI_assert(gz_prop->type->array_length == 16); - struct NodeCropWidgetGroup *crop_group = gz->parent_gzgroup->customdata; - const float *dims = crop_group->state.dims; - const bNode *node = gz_prop->custom_func.user_data; - const NodeTwoXYs *nxy = node->storage; - bool is_relative = (bool)node->custom2; - rctf rct; - two_xy_to_rect(nxy, &rct, dims, is_relative); - matrix[0][0] = fabsf(BLI_rctf_size_x(&rct)); - matrix[1][1] = fabsf(BLI_rctf_size_y(&rct)); - matrix[3][0] = (BLI_rctf_cent_x(&rct) - 0.5f) * dims[0]; - matrix[3][1] = (BLI_rctf_cent_y(&rct) - 0.5f) * dims[1]; + float(*matrix)[4] = value_p; + BLI_assert(gz_prop->type->array_length == 16); + struct NodeCropWidgetGroup *crop_group = gz->parent_gzgroup->customdata; + const float *dims = crop_group->state.dims; + const bNode *node = gz_prop->custom_func.user_data; + const NodeTwoXYs *nxy = node->storage; + bool is_relative = (bool)node->custom2; + rctf rct; + two_xy_to_rect(nxy, &rct, dims, is_relative); + matrix[0][0] = fabsf(BLI_rctf_size_x(&rct)); + matrix[1][1] = fabsf(BLI_rctf_size_y(&rct)); + matrix[3][0] = (BLI_rctf_cent_x(&rct) - 0.5f) * dims[0]; + matrix[3][1] = (BLI_rctf_cent_y(&rct) - 0.5f) * dims[1]; } -static void gizmo_node_crop_prop_matrix_set( - const wmGizmo *gz, wmGizmoProperty *gz_prop, - const void *value_p) +static void gizmo_node_crop_prop_matrix_set(const wmGizmo *gz, + wmGizmoProperty *gz_prop, + const void *value_p) { - const float (*matrix)[4] = value_p; - BLI_assert(gz_prop->type->array_length == 16); - struct NodeCropWidgetGroup *crop_group = gz->parent_gzgroup->customdata; - const float *dims = crop_group->state.dims; - bNode *node = gz_prop->custom_func.user_data; - NodeTwoXYs *nxy = node->storage; - bool is_relative = (bool)node->custom2; - rctf rct; - two_xy_to_rect(nxy, &rct, dims, is_relative); - const bool nx = rct.xmin > rct.xmax; - const bool ny = rct.ymin > rct.ymax; - BLI_rctf_resize(&rct, fabsf(matrix[0][0]), fabsf(matrix[1][1])); - BLI_rctf_recenter(&rct, (matrix[3][0] / dims[0]) + 0.5f, (matrix[3][1] / dims[1]) + 0.5f); - BLI_rctf_isect(&(rctf){ .xmin = 0, .ymin = 0, .xmax = 1, .ymax = 1, }, &rct, &rct); - if (nx) { - SWAP(float, rct.xmin, rct.xmax); - } - if (ny) { - SWAP(float, rct.ymin, rct.ymax); - } - two_xy_from_rect(nxy, &rct, dims, is_relative); - gizmo_node_crop_update(crop_group); + const float(*matrix)[4] = value_p; + BLI_assert(gz_prop->type->array_length == 16); + struct NodeCropWidgetGroup *crop_group = gz->parent_gzgroup->customdata; + const float *dims = crop_group->state.dims; + bNode *node = gz_prop->custom_func.user_data; + NodeTwoXYs *nxy = node->storage; + bool is_relative = (bool)node->custom2; + rctf rct; + two_xy_to_rect(nxy, &rct, dims, is_relative); + const bool nx = rct.xmin > rct.xmax; + const bool ny = rct.ymin > rct.ymax; + BLI_rctf_resize(&rct, fabsf(matrix[0][0]), fabsf(matrix[1][1])); + BLI_rctf_recenter(&rct, (matrix[3][0] / dims[0]) + 0.5f, (matrix[3][1] / dims[1]) + 0.5f); + BLI_rctf_isect( + &(rctf){ + .xmin = 0, + .ymin = 0, + .xmax = 1, + .ymax = 1, + }, + &rct, + &rct); + if (nx) { + SWAP(float, rct.xmin, rct.xmax); + } + if (ny) { + SWAP(float, rct.ymin, rct.ymax); + } + two_xy_from_rect(nxy, &rct, dims, is_relative); + gizmo_node_crop_update(crop_group); } static bool WIDGETGROUP_node_crop_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - if ((snode->flag & SNODE_BACKDRAW) == 0) { - return false; - } + if ((snode->flag & SNODE_BACKDRAW) == 0) { + return false; + } - if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) { - bNode *node = nodeGetActive(snode->edittree); + if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) { + bNode *node = nodeGetActive(snode->edittree); - if (node && ELEM(node->type, CMP_NODE_CROP)) { - /* ignore 'use_crop_size', we can't usefully edit the crop in this case. */ - if ((node->custom1 & (1 << 0)) == 0) { - return true; - } - } - } + if (node && ELEM(node->type, CMP_NODE_CROP)) { + /* ignore 'use_crop_size', we can't usefully edit the crop in this case. */ + if ((node->custom1 & (1 << 0)) == 0) { + return true; + } + } + } - return false; + return false; } static void WIDGETGROUP_node_crop_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) { - struct NodeCropWidgetGroup *crop_group = MEM_mallocN(sizeof(struct NodeCropWidgetGroup), __func__); + struct NodeCropWidgetGroup *crop_group = MEM_mallocN(sizeof(struct NodeCropWidgetGroup), + __func__); - crop_group->border = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, NULL); + crop_group->border = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, NULL); - RNA_enum_set(crop_group->border->ptr, "transform", - ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE | ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE); + RNA_enum_set(crop_group->border->ptr, + "transform", + ED_GIZMO_CAGE2D_XFORM_FLAG_TRANSLATE | ED_GIZMO_CAGE2D_XFORM_FLAG_SCALE); - gzgroup->customdata = crop_group; + gzgroup->customdata = crop_group; } static void WIDGETGROUP_node_crop_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) { - ARegion *ar = CTX_wm_region(C); - wmGizmo *gz = gzgroup->gizmos.first; + ARegion *ar = CTX_wm_region(C); + wmGizmo *gz = gzgroup->gizmos.first; - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - node_gizmo_calc_matrix_space(snode, ar, gz->matrix_space); + node_gizmo_calc_matrix_space(snode, ar, gz->matrix_space); } static void WIDGETGROUP_node_crop_refresh(const bContext *C, wmGizmoGroup *gzgroup) { - Main *bmain = CTX_data_main(C); - struct NodeCropWidgetGroup *crop_group = gzgroup->customdata; - wmGizmo *gz = crop_group->border; - - void *lock; - Image *ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - - if (ibuf) { - crop_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f; - crop_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f; - - RNA_float_set_array(gz->ptr, "dimensions", crop_group->state.dims); - WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, false); - - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node = nodeGetActive(snode->edittree); - - crop_group->update_data.context = (bContext *)C; - RNA_pointer_create((ID *)snode->edittree, &RNA_CompositorNodeCrop, node, &crop_group->update_data.ptr); - crop_group->update_data.prop = RNA_struct_find_property(&crop_group->update_data.ptr, "relative"); - - WM_gizmo_target_property_def_func( - gz, "matrix", - &(const struct wmGizmoPropertyFnParams) { - .value_get_fn = gizmo_node_crop_prop_matrix_get, - .value_set_fn = gizmo_node_crop_prop_matrix_set, - .range_get_fn = NULL, - .user_data = node, - }); - } - else { - WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); - } - - BKE_image_release_ibuf(ima, ibuf, lock); + Main *bmain = CTX_data_main(C); + struct NodeCropWidgetGroup *crop_group = gzgroup->customdata; + wmGizmo *gz = crop_group->border; + + void *lock; + Image *ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + + if (ibuf) { + crop_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f; + crop_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f; + + RNA_float_set_array(gz->ptr, "dimensions", crop_group->state.dims); + WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, false); + + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node = nodeGetActive(snode->edittree); + + crop_group->update_data.context = (bContext *)C; + RNA_pointer_create( + (ID *)snode->edittree, &RNA_CompositorNodeCrop, node, &crop_group->update_data.ptr); + crop_group->update_data.prop = RNA_struct_find_property(&crop_group->update_data.ptr, + "relative"); + + WM_gizmo_target_property_def_func(gz, + "matrix", + &(const struct wmGizmoPropertyFnParams){ + .value_get_fn = gizmo_node_crop_prop_matrix_get, + .value_set_fn = gizmo_node_crop_prop_matrix_set, + .range_get_fn = NULL, + .user_data = node, + }); + } + else { + WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); + } + + BKE_image_release_ibuf(ima, ibuf, lock); } void NODE_GGT_backdrop_crop(wmGizmoGroupType *gzgt) { - gzgt->name = "Backdrop Crop Widget"; - gzgt->idname = "NODE_GGT_backdrop_crop"; + gzgt->name = "Backdrop Crop Widget"; + gzgt->idname = "NODE_GGT_backdrop_crop"; - gzgt->flag |= WM_GIZMOGROUPTYPE_PERSISTENT; + gzgt->flag |= WM_GIZMOGROUPTYPE_PERSISTENT; - gzgt->poll = WIDGETGROUP_node_crop_poll; - gzgt->setup = WIDGETGROUP_node_crop_setup; - gzgt->draw_prepare = WIDGETGROUP_node_crop_draw_prepare; - gzgt->refresh = WIDGETGROUP_node_crop_refresh; + gzgt->poll = WIDGETGROUP_node_crop_poll; + gzgt->setup = WIDGETGROUP_node_crop_setup; + gzgt->draw_prepare = WIDGETGROUP_node_crop_draw_prepare; + gzgt->refresh = WIDGETGROUP_node_crop_refresh; } /** \} */ @@ -401,220 +421,221 @@ void NODE_GGT_backdrop_crop(wmGizmoGroupType *gzgt) * \{ */ struct NodeSunBeamsWidgetGroup { - wmGizmo *gizmo; + wmGizmo *gizmo; - struct { - float dims[2]; - } state; + struct { + float dims[2]; + } state; }; static bool WIDGETGROUP_node_sbeam_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - if ((snode->flag & SNODE_BACKDRAW) == 0) { - return false; - } + if ((snode->flag & SNODE_BACKDRAW) == 0) { + return false; + } - if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) { - bNode *node = nodeGetActive(snode->edittree); + if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) { + bNode *node = nodeGetActive(snode->edittree); - if (node && ELEM(node->type, CMP_NODE_SUNBEAMS)) { - return true; - } - } + if (node && ELEM(node->type, CMP_NODE_SUNBEAMS)) { + return true; + } + } - return false; + return false; } static void WIDGETGROUP_node_sbeam_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) { - struct NodeSunBeamsWidgetGroup *sbeam_group = MEM_mallocN(sizeof(struct NodeSunBeamsWidgetGroup), __func__); + struct NodeSunBeamsWidgetGroup *sbeam_group = MEM_mallocN(sizeof(struct NodeSunBeamsWidgetGroup), + __func__); - sbeam_group->gizmo = WM_gizmo_new("GIZMO_GT_move_3d", gzgroup, NULL); - wmGizmo *gz = sbeam_group->gizmo; + sbeam_group->gizmo = WM_gizmo_new("GIZMO_GT_move_3d", gzgroup, NULL); + wmGizmo *gz = sbeam_group->gizmo; - RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_MOVE_STYLE_CROSS_2D); + RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_MOVE_STYLE_CROSS_2D); - gz->scale_basis = 0.05f; + gz->scale_basis = 0.05f; - gzgroup->customdata = sbeam_group; + gzgroup->customdata = sbeam_group; } static void WIDGETGROUP_node_sbeam_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) { - struct NodeSunBeamsWidgetGroup *sbeam_group = gzgroup->customdata; - ARegion *ar = CTX_wm_region(C); - wmGizmo *gz = gzgroup->gizmos.first; + struct NodeSunBeamsWidgetGroup *sbeam_group = gzgroup->customdata; + ARegion *ar = CTX_wm_region(C); + wmGizmo *gz = gzgroup->gizmos.first; - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - node_gizmo_calc_matrix_space_with_image_dims(snode, ar, sbeam_group->state.dims, gz->matrix_space); + node_gizmo_calc_matrix_space_with_image_dims( + snode, ar, sbeam_group->state.dims, gz->matrix_space); } static void WIDGETGROUP_node_sbeam_refresh(const bContext *C, wmGizmoGroup *gzgroup) { - Main *bmain = CTX_data_main(C); - struct NodeSunBeamsWidgetGroup *sbeam_group = gzgroup->customdata; - wmGizmo *gz = sbeam_group->gizmo; + Main *bmain = CTX_data_main(C); + struct NodeSunBeamsWidgetGroup *sbeam_group = gzgroup->customdata; + wmGizmo *gz = sbeam_group->gizmo; - void *lock; - Image *ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + void *lock; + Image *ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - if (ibuf) { - sbeam_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f; - sbeam_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f; + if (ibuf) { + sbeam_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f; + sbeam_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f; - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node = nodeGetActive(snode->edittree); + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node = nodeGetActive(snode->edittree); - /* need to set property here for undo. TODO would prefer to do this in _init */ - PointerRNA nodeptr; - RNA_pointer_create((ID *)snode->edittree, &RNA_CompositorNodeSunBeams, node, &nodeptr); - WM_gizmo_target_property_def_rna(gz, "offset", &nodeptr, "source", -1); + /* need to set property here for undo. TODO would prefer to do this in _init */ + PointerRNA nodeptr; + RNA_pointer_create((ID *)snode->edittree, &RNA_CompositorNodeSunBeams, node, &nodeptr); + WM_gizmo_target_property_def_rna(gz, "offset", &nodeptr, "source", -1); - WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_MODAL, true); - } - else { - WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); - } + WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_MODAL, true); + } + else { + WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); + } - BKE_image_release_ibuf(ima, ibuf, lock); + BKE_image_release_ibuf(ima, ibuf, lock); } void NODE_GGT_backdrop_sun_beams(wmGizmoGroupType *gzgt) { - gzgt->name = "Sun Beams Widget"; - gzgt->idname = "NODE_GGT_sbeam"; + gzgt->name = "Sun Beams Widget"; + gzgt->idname = "NODE_GGT_sbeam"; - gzgt->flag |= WM_GIZMOGROUPTYPE_PERSISTENT; + gzgt->flag |= WM_GIZMOGROUPTYPE_PERSISTENT; - gzgt->poll = WIDGETGROUP_node_sbeam_poll; - gzgt->setup = WIDGETGROUP_node_sbeam_setup; - gzgt->draw_prepare = WIDGETGROUP_node_sbeam_draw_prepare; - gzgt->refresh = WIDGETGROUP_node_sbeam_refresh; + gzgt->poll = WIDGETGROUP_node_sbeam_poll; + gzgt->setup = WIDGETGROUP_node_sbeam_setup; + gzgt->draw_prepare = WIDGETGROUP_node_sbeam_draw_prepare; + gzgt->refresh = WIDGETGROUP_node_sbeam_refresh; } /** \} */ - - /* -------------------------------------------------------------------- */ /** \name Corner Pin * \{ */ struct NodeCornerPinWidgetGroup { - wmGizmo *gizmos[4]; + wmGizmo *gizmos[4]; - struct { - float dims[2]; - } state; + struct { + float dims[2]; + } state; }; static bool WIDGETGROUP_node_corner_pin_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt)) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - if ((snode->flag & SNODE_BACKDRAW) == 0) { - return false; - } + if ((snode->flag & SNODE_BACKDRAW) == 0) { + return false; + } - if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) { - bNode *node = nodeGetActive(snode->edittree); + if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) { + bNode *node = nodeGetActive(snode->edittree); - if (node && ELEM(node->type, CMP_NODE_CORNERPIN)) { - return true; - } - } + if (node && ELEM(node->type, CMP_NODE_CORNERPIN)) { + return true; + } + } - return false; + return false; } static void WIDGETGROUP_node_corner_pin_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) { - struct NodeCornerPinWidgetGroup *cpin_group = MEM_mallocN(sizeof(struct NodeCornerPinWidgetGroup), __func__); - const wmGizmoType *gzt_move_3d = WM_gizmotype_find("GIZMO_GT_move_3d", false); + struct NodeCornerPinWidgetGroup *cpin_group = MEM_mallocN( + sizeof(struct NodeCornerPinWidgetGroup), __func__); + const wmGizmoType *gzt_move_3d = WM_gizmotype_find("GIZMO_GT_move_3d", false); - for (int i = 0; i < 4; i++) { - cpin_group->gizmos[i] = WM_gizmo_new_ptr(gzt_move_3d, gzgroup, NULL); - wmGizmo *gz = cpin_group->gizmos[i]; + for (int i = 0; i < 4; i++) { + cpin_group->gizmos[i] = WM_gizmo_new_ptr(gzt_move_3d, gzgroup, NULL); + wmGizmo *gz = cpin_group->gizmos[i]; - RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_MOVE_STYLE_CROSS_2D); + RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_MOVE_STYLE_CROSS_2D); - gz->scale_basis = 0.01f; - } + gz->scale_basis = 0.01f; + } - gzgroup->customdata = cpin_group; + gzgroup->customdata = cpin_group; } static void WIDGETGROUP_node_corner_pin_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) { - struct NodeCornerPinWidgetGroup *cpin_group = gzgroup->customdata; - ARegion *ar = CTX_wm_region(C); + struct NodeCornerPinWidgetGroup *cpin_group = gzgroup->customdata; + ARegion *ar = CTX_wm_region(C); - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - float matrix_space[4][4]; - node_gizmo_calc_matrix_space_with_image_dims(snode, ar, cpin_group->state.dims, matrix_space); + float matrix_space[4][4]; + node_gizmo_calc_matrix_space_with_image_dims(snode, ar, cpin_group->state.dims, matrix_space); - for (int i = 0; i < 4; i++) { - wmGizmo *gz = cpin_group->gizmos[i]; - copy_m4_m4(gz->matrix_space, matrix_space); - } + for (int i = 0; i < 4; i++) { + wmGizmo *gz = cpin_group->gizmos[i]; + copy_m4_m4(gz->matrix_space, matrix_space); + } } static void WIDGETGROUP_node_corner_pin_refresh(const bContext *C, wmGizmoGroup *gzgroup) { - Main *bmain = CTX_data_main(C); - struct NodeCornerPinWidgetGroup *cpin_group = gzgroup->customdata; - - void *lock; - Image *ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - - if (ibuf) { - cpin_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f; - cpin_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f; - - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node = nodeGetActive(snode->edittree); - - /* need to set property here for undo. TODO would prefer to do this in _init */ - int i = 0; - for (bNodeSocket *sock = node->inputs.first; sock && i < 4; sock = sock->next) { - if (sock->type == SOCK_VECTOR) { - wmGizmo *gz = cpin_group->gizmos[i++]; - - PointerRNA sockptr; - RNA_pointer_create((ID *)snode->edittree, &RNA_NodeSocket, sock, &sockptr); - WM_gizmo_target_property_def_rna(gz, "offset", &sockptr, "default_value", -1); - - WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_MODAL, true); - } - } - } - else { - for (int i = 0; i < 4; i++) { - wmGizmo *gz = cpin_group->gizmos[i]; - WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); - } - } - - BKE_image_release_ibuf(ima, ibuf, lock); + Main *bmain = CTX_data_main(C); + struct NodeCornerPinWidgetGroup *cpin_group = gzgroup->customdata; + + void *lock; + Image *ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + + if (ibuf) { + cpin_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f; + cpin_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f; + + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node = nodeGetActive(snode->edittree); + + /* need to set property here for undo. TODO would prefer to do this in _init */ + int i = 0; + for (bNodeSocket *sock = node->inputs.first; sock && i < 4; sock = sock->next) { + if (sock->type == SOCK_VECTOR) { + wmGizmo *gz = cpin_group->gizmos[i++]; + + PointerRNA sockptr; + RNA_pointer_create((ID *)snode->edittree, &RNA_NodeSocket, sock, &sockptr); + WM_gizmo_target_property_def_rna(gz, "offset", &sockptr, "default_value", -1); + + WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_MODAL, true); + } + } + } + else { + for (int i = 0; i < 4; i++) { + wmGizmo *gz = cpin_group->gizmos[i]; + WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); + } + } + + BKE_image_release_ibuf(ima, ibuf, lock); } void NODE_GGT_backdrop_corner_pin(wmGizmoGroupType *gzgt) { - gzgt->name = "Corner Pin Widget"; - gzgt->idname = "NODE_GGT_backdrop_corner_pin"; + gzgt->name = "Corner Pin Widget"; + gzgt->idname = "NODE_GGT_backdrop_corner_pin"; - gzgt->flag |= WM_GIZMOGROUPTYPE_PERSISTENT; + gzgt->flag |= WM_GIZMOGROUPTYPE_PERSISTENT; - gzgt->poll = WIDGETGROUP_node_corner_pin_poll; - gzgt->setup = WIDGETGROUP_node_corner_pin_setup; - gzgt->draw_prepare = WIDGETGROUP_node_corner_pin_draw_prepare; - gzgt->refresh = WIDGETGROUP_node_corner_pin_refresh; + gzgt->poll = WIDGETGROUP_node_corner_pin_poll; + gzgt->setup = WIDGETGROUP_node_corner_pin_setup; + gzgt->draw_prepare = WIDGETGROUP_node_corner_pin_draw_prepare; + gzgt->refresh = WIDGETGROUP_node_corner_pin_refresh; } /** \} */ diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c index e38d29454dc..3c65c4854b8 100644 --- a/source/blender/editors/space_node/node_group.c +++ b/source/blender/editors/space_node/node_group.c @@ -43,7 +43,7 @@ #include "DEG_depsgraph_build.h" -#include "ED_node.h" /* own include */ +#include "ED_node.h" /* own include */ #include "ED_screen.h" #include "ED_render.h" @@ -55,127 +55,123 @@ #include "UI_resources.h" -#include "node_intern.h" /* own include */ +#include "node_intern.h" /* own include */ #include "NOD_common.h" static bool node_group_operator_active(bContext *C) { - if (ED_operator_node_active(C)) { - SpaceNode *snode = CTX_wm_space_node(C); - - /* Group operators only defined for standard node tree types. - * Disabled otherwise to allow pynodes define their own operators - * with same keymap. - */ - if (STREQ(snode->tree_idname, "ShaderNodeTree") || - STREQ(snode->tree_idname, "CompositorNodeTree") || - STREQ(snode->tree_idname, "TextureNodeTree")) - { - return true; - } - } - return false; + if (ED_operator_node_active(C)) { + SpaceNode *snode = CTX_wm_space_node(C); + + /* Group operators only defined for standard node tree types. + * Disabled otherwise to allow pynodes define their own operators + * with same keymap. + */ + if (STREQ(snode->tree_idname, "ShaderNodeTree") || + STREQ(snode->tree_idname, "CompositorNodeTree") || + STREQ(snode->tree_idname, "TextureNodeTree")) { + return true; + } + } + return false; } static bool node_group_operator_editable(bContext *C) { - if (ED_operator_node_editable(C)) { - SpaceNode *snode = CTX_wm_space_node(C); - - /* Group operators only defined for standard node tree types. - * Disabled otherwise to allow pynodes define their own operators - * with same keymap. - */ - if (ED_node_is_shader(snode) || - ED_node_is_compositor(snode) || - ED_node_is_texture(snode)) - { - return true; - } - } - return false; + if (ED_operator_node_editable(C)) { + SpaceNode *snode = CTX_wm_space_node(C); + + /* Group operators only defined for standard node tree types. + * Disabled otherwise to allow pynodes define their own operators + * with same keymap. + */ + if (ED_node_is_shader(snode) || ED_node_is_compositor(snode) || ED_node_is_texture(snode)) { + return true; + } + } + return false; } static const char *group_ntree_idname(bContext *C) { - SpaceNode *snode = CTX_wm_space_node(C); - return snode->tree_idname; + SpaceNode *snode = CTX_wm_space_node(C); + return snode->tree_idname; } static const char *group_node_idname(bContext *C) { - SpaceNode *snode = CTX_wm_space_node(C); - - if (ED_node_is_shader(snode)) { - return "ShaderNodeGroup"; - } - else if (ED_node_is_compositor(snode)) { - return "CompositorNodeGroup"; - } - else if (ED_node_is_texture(snode)) { - return "TextureNodeGroup"; - } - - return ""; + SpaceNode *snode = CTX_wm_space_node(C); + + if (ED_node_is_shader(snode)) { + return "ShaderNodeGroup"; + } + else if (ED_node_is_compositor(snode)) { + return "CompositorNodeGroup"; + } + else if (ED_node_is_texture(snode)) { + return "TextureNodeGroup"; + } + + return ""; } static bNode *node_group_get_active(bContext *C, const char *node_idname) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node = nodeGetActive(snode->edittree); - - if (node && STREQ(node->idname, node_idname)) { - return node; - } - else { - return NULL; - } + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node = nodeGetActive(snode->edittree); + + if (node && STREQ(node->idname, node_idname)) { + return node; + } + else { + return NULL; + } } /* ***************** Edit Group operator ************* */ static int node_group_edit_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - const char *node_idname = group_node_idname(C); - bNode *gnode; - const bool exit = RNA_boolean_get(op->ptr, "exit"); + SpaceNode *snode = CTX_wm_space_node(C); + const char *node_idname = group_node_idname(C); + bNode *gnode; + const bool exit = RNA_boolean_get(op->ptr, "exit"); - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - gnode = node_group_get_active(C, node_idname); + gnode = node_group_get_active(C, node_idname); - if (gnode && !exit) { - bNodeTree *ngroup = (bNodeTree *)gnode->id; + if (gnode && !exit) { + bNodeTree *ngroup = (bNodeTree *)gnode->id; - if (ngroup) { - ED_node_tree_push(snode, ngroup, gnode); - } - } - else { - ED_node_tree_pop(snode); - } + if (ngroup) { + ED_node_tree_push(snode, ngroup, gnode); + } + } + else { + ED_node_tree_pop(snode); + } - WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL); + WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_group_edit(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Edit Group"; - ot->description = "Edit node group"; - ot->idname = "NODE_OT_group_edit"; + /* identifiers */ + ot->name = "Edit Group"; + ot->description = "Edit node group"; + ot->idname = "NODE_OT_group_edit"; - /* api callbacks */ - ot->exec = node_group_edit_exec; - ot->poll = node_group_operator_active; + /* api callbacks */ + ot->exec = node_group_edit_exec; + ot->poll = node_group_operator_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_boolean(ot->srna, "exit", false, "Exit", ""); + RNA_def_boolean(ot->srna, "exit", false, "Exit", ""); } /* ******************** Ungroup operator ********************** */ @@ -183,882 +179,900 @@ void NODE_OT_group_edit(wmOperatorType *ot) /* returns 1 if its OK */ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) { - bNodeLink *link, *linkn, *tlink; - bNode *node, *nextnode; - bNodeTree *ngroup, *wgroup; - ListBase anim_basepaths = {NULL, NULL}; - LinkNode *nodes_delayed_free = NULL; - - ngroup = (bNodeTree *)gnode->id; - - /* clear new pointers, set in copytree */ - for (node = ntree->nodes.first; node; node = node->next) { - node->new_node = NULL; - } - - /* wgroup is a temporary copy of the NodeTree we're merging in - * - all of wgroup's nodes are transferred across to their new home - * - ngroup (i.e. the source NodeTree) is left unscathed - * - temp copy. don't change ID usercount - */ - wgroup = ntreeCopyTree_ex(ngroup, bmain, false); - - /* Add the nodes into the ntree */ - for (node = wgroup->nodes.first; node; node = nextnode) { - nextnode = node->next; - - /* Remove interface nodes. - * This also removes remaining links to and from interface nodes. - */ - if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) { - /* We must delay removal since sockets will reference this node. see: T52092 */ - BLI_linklist_prepend(&nodes_delayed_free, node); - } - - /* keep track of this node's RNA "base" path (the part of the path identifying the node) - * if the old nodetree has animation data which potentially covers this node - */ - if (wgroup->adt) { - PointerRNA ptr; - char *path; - - RNA_pointer_create(&wgroup->id, &RNA_Node, node, &ptr); - path = RNA_path_from_ID_to_struct(&ptr); - - if (path) { - BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); - } - } - - /* migrate node */ - BLI_remlink(&wgroup->nodes, node); - BLI_addtail(&ntree->nodes, node); - - /* ensure unique node name in the node tree */ - nodeUniqueName(ntree, node); - - if (!node->parent) { - node->locx += gnode->locx; - node->locy += gnode->locy; - } - - node->flag |= NODE_SELECT; - } - - /* Add internal links to the ntree */ - for (link = wgroup->links.first; link; link = linkn) { - linkn = link->next; - BLI_remlink(&wgroup->links, link); - BLI_addtail(&ntree->links, link); - } - - /* and copy across the animation, - * note that the animation data's action can be NULL here */ - if (wgroup->adt) { - LinkData *ld, *ldn = NULL; - bAction *waction; - - /* firstly, wgroup needs to temporary dummy action - * that can be destroyed, as it shares copies */ - waction = wgroup->adt->action = BKE_action_copy(bmain, wgroup->adt->action); - - /* now perform the moving */ - BKE_animdata_separate_by_basepath(bmain, &wgroup->id, &ntree->id, &anim_basepaths); - - /* paths + their wrappers need to be freed */ - for (ld = anim_basepaths.first; ld; ld = ldn) { - ldn = ld->next; - - MEM_freeN(ld->data); - BLI_freelinkN(&anim_basepaths, ld); - } - - /* free temp action too */ - if (waction) { - BKE_id_free(bmain, waction); - wgroup->adt->action = NULL; - } - } - - /* free the group tree (takes care of user count) */ - BKE_id_free(bmain, wgroup); - - /* restore external links to and from the gnode */ - /* note: the nodes have been copied to intermediate wgroup first (so need to use new_node), - * then transferred to ntree (new_node pointers remain valid). - */ - - /* input links */ - for (link = ngroup->links.first; link; link = link->next) { - if (link->fromnode->type == NODE_GROUP_INPUT) { - const char *identifier = link->fromsock->identifier; - int num_external_links = 0; - - /* find external links to this input */ - for (tlink = ntree->links.first; tlink; tlink = tlink->next) { - if (tlink->tonode == gnode && STREQ(tlink->tosock->identifier, identifier)) { - nodeAddLink(ntree, tlink->fromnode, tlink->fromsock, link->tonode->new_node, link->tosock->new_sock); - ++num_external_links; - } - } - - /* if group output is not externally linked, - * convert the constant input value to ensure somewhat consistent behavior */ - if (num_external_links == 0) { - /* XXX TODO bNodeSocket *sock = node_group_find_input_socket(gnode, identifier); - BLI_assert(sock);*/ - - /* XXX TODO - * nodeSocketCopy(ntree, link->tosock->new_sock, link->tonode->new_node, - * ntree, sock, gnode);*/ - } - } - } - - /* output links */ - for (link = ntree->links.first; link; link = link->next) { - if (link->fromnode == gnode) { - const char *identifier = link->fromsock->identifier; - int num_internal_links = 0; - - /* find internal links to this output */ - for (tlink = ngroup->links.first; tlink; tlink = tlink->next) { - /* only use active output node */ - if (tlink->tonode->type == NODE_GROUP_OUTPUT && (tlink->tonode->flag & NODE_DO_OUTPUT)) { - if (STREQ(tlink->tosock->identifier, identifier)) { - nodeAddLink(ntree, tlink->fromnode->new_node, tlink->fromsock->new_sock, link->tonode, link->tosock); - ++num_internal_links; - } - } - } - - /* if group output is not internally linked, - * convert the constant output value to ensure somewhat consistent behavior */ - if (num_internal_links == 0) { - /* XXX TODO bNodeSocket *sock = node_group_find_output_socket(gnode, identifier); - BLI_assert(sock);*/ - - /* XXX TODO - * nodeSocketCopy(ntree, link->tosock, link->tonode, ntree, sock, gnode); */ - } - } - } - - while (nodes_delayed_free) { - node = BLI_linklist_pop(&nodes_delayed_free); - nodeRemoveNode(bmain, ntree, node, false); - } - - /* delete the group instance */ - nodeRemoveNode(bmain, ntree, gnode, false); - - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - - return 1; + bNodeLink *link, *linkn, *tlink; + bNode *node, *nextnode; + bNodeTree *ngroup, *wgroup; + ListBase anim_basepaths = {NULL, NULL}; + LinkNode *nodes_delayed_free = NULL; + + ngroup = (bNodeTree *)gnode->id; + + /* clear new pointers, set in copytree */ + for (node = ntree->nodes.first; node; node = node->next) { + node->new_node = NULL; + } + + /* wgroup is a temporary copy of the NodeTree we're merging in + * - all of wgroup's nodes are transferred across to their new home + * - ngroup (i.e. the source NodeTree) is left unscathed + * - temp copy. don't change ID usercount + */ + wgroup = ntreeCopyTree_ex(ngroup, bmain, false); + + /* Add the nodes into the ntree */ + for (node = wgroup->nodes.first; node; node = nextnode) { + nextnode = node->next; + + /* Remove interface nodes. + * This also removes remaining links to and from interface nodes. + */ + if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) { + /* We must delay removal since sockets will reference this node. see: T52092 */ + BLI_linklist_prepend(&nodes_delayed_free, node); + } + + /* keep track of this node's RNA "base" path (the part of the path identifying the node) + * if the old nodetree has animation data which potentially covers this node + */ + if (wgroup->adt) { + PointerRNA ptr; + char *path; + + RNA_pointer_create(&wgroup->id, &RNA_Node, node, &ptr); + path = RNA_path_from_ID_to_struct(&ptr); + + if (path) { + BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } + } + + /* migrate node */ + BLI_remlink(&wgroup->nodes, node); + BLI_addtail(&ntree->nodes, node); + + /* ensure unique node name in the node tree */ + nodeUniqueName(ntree, node); + + if (!node->parent) { + node->locx += gnode->locx; + node->locy += gnode->locy; + } + + node->flag |= NODE_SELECT; + } + + /* Add internal links to the ntree */ + for (link = wgroup->links.first; link; link = linkn) { + linkn = link->next; + BLI_remlink(&wgroup->links, link); + BLI_addtail(&ntree->links, link); + } + + /* and copy across the animation, + * note that the animation data's action can be NULL here */ + if (wgroup->adt) { + LinkData *ld, *ldn = NULL; + bAction *waction; + + /* firstly, wgroup needs to temporary dummy action + * that can be destroyed, as it shares copies */ + waction = wgroup->adt->action = BKE_action_copy(bmain, wgroup->adt->action); + + /* now perform the moving */ + BKE_animdata_separate_by_basepath(bmain, &wgroup->id, &ntree->id, &anim_basepaths); + + /* paths + their wrappers need to be freed */ + for (ld = anim_basepaths.first; ld; ld = ldn) { + ldn = ld->next; + + MEM_freeN(ld->data); + BLI_freelinkN(&anim_basepaths, ld); + } + + /* free temp action too */ + if (waction) { + BKE_id_free(bmain, waction); + wgroup->adt->action = NULL; + } + } + + /* free the group tree (takes care of user count) */ + BKE_id_free(bmain, wgroup); + + /* restore external links to and from the gnode */ + /* note: the nodes have been copied to intermediate wgroup first (so need to use new_node), + * then transferred to ntree (new_node pointers remain valid). + */ + + /* input links */ + for (link = ngroup->links.first; link; link = link->next) { + if (link->fromnode->type == NODE_GROUP_INPUT) { + const char *identifier = link->fromsock->identifier; + int num_external_links = 0; + + /* find external links to this input */ + for (tlink = ntree->links.first; tlink; tlink = tlink->next) { + if (tlink->tonode == gnode && STREQ(tlink->tosock->identifier, identifier)) { + nodeAddLink(ntree, + tlink->fromnode, + tlink->fromsock, + link->tonode->new_node, + link->tosock->new_sock); + ++num_external_links; + } + } + + /* if group output is not externally linked, + * convert the constant input value to ensure somewhat consistent behavior */ + if (num_external_links == 0) { + /* XXX TODO bNodeSocket *sock = node_group_find_input_socket(gnode, identifier); + BLI_assert(sock);*/ + + /* XXX TODO + * nodeSocketCopy(ntree, link->tosock->new_sock, link->tonode->new_node, + * ntree, sock, gnode);*/ + } + } + } + + /* output links */ + for (link = ntree->links.first; link; link = link->next) { + if (link->fromnode == gnode) { + const char *identifier = link->fromsock->identifier; + int num_internal_links = 0; + + /* find internal links to this output */ + for (tlink = ngroup->links.first; tlink; tlink = tlink->next) { + /* only use active output node */ + if (tlink->tonode->type == NODE_GROUP_OUTPUT && (tlink->tonode->flag & NODE_DO_OUTPUT)) { + if (STREQ(tlink->tosock->identifier, identifier)) { + nodeAddLink(ntree, + tlink->fromnode->new_node, + tlink->fromsock->new_sock, + link->tonode, + link->tosock); + ++num_internal_links; + } + } + } + + /* if group output is not internally linked, + * convert the constant output value to ensure somewhat consistent behavior */ + if (num_internal_links == 0) { + /* XXX TODO bNodeSocket *sock = node_group_find_output_socket(gnode, identifier); + BLI_assert(sock);*/ + + /* XXX TODO + * nodeSocketCopy(ntree, link->tosock, link->tonode, ntree, sock, gnode); */ + } + } + } + + while (nodes_delayed_free) { + node = BLI_linklist_pop(&nodes_delayed_free); + nodeRemoveNode(bmain, ntree, node, false); + } + + /* delete the group instance */ + nodeRemoveNode(bmain, ntree, gnode, false); + + ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + + return 1; } - static int node_group_ungroup_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - const char *node_idname = group_node_idname(C); - bNode *gnode; - - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - - gnode = node_group_get_active(C, node_idname); - if (!gnode) { - return OPERATOR_CANCELLED; - } - - if (gnode->id && node_group_ungroup(bmain, snode->edittree, gnode)) { - ntreeUpdateTree(bmain, snode->nodetree); - } - else { - BKE_report(op->reports, RPT_WARNING, "Cannot ungroup"); - return OPERATOR_CANCELLED; - } - - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + const char *node_idname = group_node_idname(C); + bNode *gnode; + + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + + gnode = node_group_get_active(C, node_idname); + if (!gnode) { + return OPERATOR_CANCELLED; + } + + if (gnode->id && node_group_ungroup(bmain, snode->edittree, gnode)) { + ntreeUpdateTree(bmain, snode->nodetree); + } + else { + BKE_report(op->reports, RPT_WARNING, "Cannot ungroup"); + return OPERATOR_CANCELLED; + } + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; } void NODE_OT_group_ungroup(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Ungroup"; - ot->description = "Ungroup selected nodes"; - ot->idname = "NODE_OT_group_ungroup"; + /* identifiers */ + ot->name = "Ungroup"; + ot->description = "Ungroup selected nodes"; + ot->idname = "NODE_OT_group_ungroup"; - /* api callbacks */ - ot->exec = node_group_ungroup_exec; - ot->poll = node_group_operator_editable; + /* api callbacks */ + ot->exec = node_group_ungroup_exec; + ot->poll = node_group_operator_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ******************** Separate operator ********************** */ /* returns 1 if its OK */ static int node_group_separate_selected( - Main *bmain, bNodeTree *ntree, bNodeTree *ngroup, float offx, float offy, int make_copy) + Main *bmain, bNodeTree *ntree, bNodeTree *ngroup, float offx, float offy, int make_copy) { - bNodeLink *link, *link_next; - bNode *node, *node_next, *newnode; - ListBase anim_basepaths = {NULL, NULL}; - - /* deselect all nodes in the target tree */ - for (node = ntree->nodes.first; node; node = node->next) { - nodeSetSelected(node, false); - } - - /* clear new pointers, set in BKE_node_copy_ex(). */ - for (node = ngroup->nodes.first; node; node = node->next) { - node->new_node = NULL; - } - - /* add selected nodes into the ntree */ - for (node = ngroup->nodes.first; node; node = node_next) { - node_next = node->next; - if (!(node->flag & NODE_SELECT)) { - continue; - } - - /* ignore interface nodes */ - if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) { - nodeSetSelected(node, false); - continue; - } - - if (make_copy) { - /* make a copy */ - newnode = BKE_node_copy_ex(ngroup, node, LIB_ID_COPY_DEFAULT); - } - else { - /* use the existing node */ - newnode = node; - } - - /* keep track of this node's RNA "base" path (the part of the path identifying the node) - * if the old nodetree has animation data which potentially covers this node - */ - if (ngroup->adt) { - PointerRNA ptr; - char *path; - - RNA_pointer_create(&ngroup->id, &RNA_Node, newnode, &ptr); - path = RNA_path_from_ID_to_struct(&ptr); - - if (path) { - BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); - } - } - - /* ensure valid parent pointers, detach if parent stays inside the group */ - if (newnode->parent && !(newnode->parent->flag & NODE_SELECT)) { - nodeDetachNode(newnode); - } - - /* migrate node */ - BLI_remlink(&ngroup->nodes, newnode); - BLI_addtail(&ntree->nodes, newnode); - - /* ensure unique node name in the node tree */ - nodeUniqueName(ntree, newnode); - - if (!newnode->parent) { - newnode->locx += offx; - newnode->locy += offy; - } - } - - /* add internal links to the ntree */ - for (link = ngroup->links.first; link; link = link_next) { - const bool fromselect = (link->fromnode && (link->fromnode->flag & NODE_SELECT)); - const bool toselect = (link->tonode && (link->tonode->flag & NODE_SELECT)); - link_next = link->next; - - if (make_copy) { - /* make a copy of internal links */ - if (fromselect && toselect) { - nodeAddLink(ntree, link->fromnode->new_node, link->fromsock->new_sock, link->tonode->new_node, link->tosock->new_sock); - } - } - else { - /* move valid links over, delete broken links */ - if (fromselect && toselect) { - BLI_remlink(&ngroup->links, link); - BLI_addtail(&ntree->links, link); - } - else if (fromselect || toselect) { - nodeRemLink(ngroup, link); - } - } - } - - /* and copy across the animation, - * note that the animation data's action can be NULL here */ - if (ngroup->adt) { - LinkData *ld, *ldn = NULL; - - /* now perform the moving */ - BKE_animdata_separate_by_basepath(bmain, &ngroup->id, &ntree->id, &anim_basepaths); - - /* paths + their wrappers need to be freed */ - for (ld = anim_basepaths.first; ld; ld = ldn) { - ldn = ld->next; - - MEM_freeN(ld->data); - BLI_freelinkN(&anim_basepaths, ld); - } - } - - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - if (!make_copy) { - ngroup->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - } - - return 1; + bNodeLink *link, *link_next; + bNode *node, *node_next, *newnode; + ListBase anim_basepaths = {NULL, NULL}; + + /* deselect all nodes in the target tree */ + for (node = ntree->nodes.first; node; node = node->next) { + nodeSetSelected(node, false); + } + + /* clear new pointers, set in BKE_node_copy_ex(). */ + for (node = ngroup->nodes.first; node; node = node->next) { + node->new_node = NULL; + } + + /* add selected nodes into the ntree */ + for (node = ngroup->nodes.first; node; node = node_next) { + node_next = node->next; + if (!(node->flag & NODE_SELECT)) { + continue; + } + + /* ignore interface nodes */ + if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) { + nodeSetSelected(node, false); + continue; + } + + if (make_copy) { + /* make a copy */ + newnode = BKE_node_copy_ex(ngroup, node, LIB_ID_COPY_DEFAULT); + } + else { + /* use the existing node */ + newnode = node; + } + + /* keep track of this node's RNA "base" path (the part of the path identifying the node) + * if the old nodetree has animation data which potentially covers this node + */ + if (ngroup->adt) { + PointerRNA ptr; + char *path; + + RNA_pointer_create(&ngroup->id, &RNA_Node, newnode, &ptr); + path = RNA_path_from_ID_to_struct(&ptr); + + if (path) { + BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } + } + + /* ensure valid parent pointers, detach if parent stays inside the group */ + if (newnode->parent && !(newnode->parent->flag & NODE_SELECT)) { + nodeDetachNode(newnode); + } + + /* migrate node */ + BLI_remlink(&ngroup->nodes, newnode); + BLI_addtail(&ntree->nodes, newnode); + + /* ensure unique node name in the node tree */ + nodeUniqueName(ntree, newnode); + + if (!newnode->parent) { + newnode->locx += offx; + newnode->locy += offy; + } + } + + /* add internal links to the ntree */ + for (link = ngroup->links.first; link; link = link_next) { + const bool fromselect = (link->fromnode && (link->fromnode->flag & NODE_SELECT)); + const bool toselect = (link->tonode && (link->tonode->flag & NODE_SELECT)); + link_next = link->next; + + if (make_copy) { + /* make a copy of internal links */ + if (fromselect && toselect) { + nodeAddLink(ntree, + link->fromnode->new_node, + link->fromsock->new_sock, + link->tonode->new_node, + link->tosock->new_sock); + } + } + else { + /* move valid links over, delete broken links */ + if (fromselect && toselect) { + BLI_remlink(&ngroup->links, link); + BLI_addtail(&ntree->links, link); + } + else if (fromselect || toselect) { + nodeRemLink(ngroup, link); + } + } + } + + /* and copy across the animation, + * note that the animation data's action can be NULL here */ + if (ngroup->adt) { + LinkData *ld, *ldn = NULL; + + /* now perform the moving */ + BKE_animdata_separate_by_basepath(bmain, &ngroup->id, &ntree->id, &anim_basepaths); + + /* paths + their wrappers need to be freed */ + for (ld = anim_basepaths.first; ld; ld = ldn) { + ldn = ld->next; + + MEM_freeN(ld->data); + BLI_freelinkN(&anim_basepaths, ld); + } + } + + ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + if (!make_copy) { + ngroup->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + } + + return 1; } typedef enum eNodeGroupSeparateType { - NODE_GS_COPY, - NODE_GS_MOVE, + NODE_GS_COPY, + NODE_GS_MOVE, } eNodeGroupSeparateType; /* Operator Property */ static const EnumPropertyItem node_group_separate_types[] = { - {NODE_GS_COPY, "COPY", 0, "Copy", "Copy to parent node tree, keep group intact"}, - {NODE_GS_MOVE, "MOVE", 0, "Move", "Move to parent node tree, remove from group"}, - {0, NULL, 0, NULL, NULL}, + {NODE_GS_COPY, "COPY", 0, "Copy", "Copy to parent node tree, keep group intact"}, + {NODE_GS_MOVE, "MOVE", 0, "Move", "Move to parent node tree, remove from group"}, + {0, NULL, 0, NULL, NULL}, }; static int node_group_separate_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ngroup, *nparent; - int type = RNA_enum_get(op->ptr, "type"); - float offx, offy; - - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - - /* are we inside of a group? */ - ngroup = snode->edittree; - nparent = ED_node_tree_get(snode, 1); - if (!nparent) { - BKE_report(op->reports, RPT_WARNING, "Not inside node group"); - return OPERATOR_CANCELLED; - } - /* get node tree offset */ - snode_group_offset(snode, &offx, &offy); - - switch (type) { - case NODE_GS_COPY: - if (!node_group_separate_selected(bmain, nparent, ngroup, offx, offy, true)) { - BKE_report(op->reports, RPT_WARNING, "Cannot separate nodes"); - return OPERATOR_CANCELLED; - } - break; - case NODE_GS_MOVE: - if (!node_group_separate_selected(bmain, nparent, ngroup, offx, offy, false)) { - BKE_report(op->reports, RPT_WARNING, "Cannot separate nodes"); - return OPERATOR_CANCELLED; - } - break; - } - - /* switch to parent tree */ - ED_node_tree_pop(snode); - - ntreeUpdateTree(CTX_data_main(C), snode->nodetree); - - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ngroup, *nparent; + int type = RNA_enum_get(op->ptr, "type"); + float offx, offy; + + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + + /* are we inside of a group? */ + ngroup = snode->edittree; + nparent = ED_node_tree_get(snode, 1); + if (!nparent) { + BKE_report(op->reports, RPT_WARNING, "Not inside node group"); + return OPERATOR_CANCELLED; + } + /* get node tree offset */ + snode_group_offset(snode, &offx, &offy); + + switch (type) { + case NODE_GS_COPY: + if (!node_group_separate_selected(bmain, nparent, ngroup, offx, offy, true)) { + BKE_report(op->reports, RPT_WARNING, "Cannot separate nodes"); + return OPERATOR_CANCELLED; + } + break; + case NODE_GS_MOVE: + if (!node_group_separate_selected(bmain, nparent, ngroup, offx, offy, false)) { + BKE_report(op->reports, RPT_WARNING, "Cannot separate nodes"); + return OPERATOR_CANCELLED; + } + break; + } + + /* switch to parent tree */ + ED_node_tree_pop(snode); + + ntreeUpdateTree(CTX_data_main(C), snode->nodetree); + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; } -static int node_group_separate_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) +static int node_group_separate_invoke(bContext *C, + wmOperator *UNUSED(op), + const wmEvent *UNUSED(event)) { - uiPopupMenu *pup = UI_popup_menu_begin(C, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Separate"), ICON_NONE); - uiLayout *layout = UI_popup_menu_layout(pup); + uiPopupMenu *pup = UI_popup_menu_begin( + C, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Separate"), ICON_NONE); + uiLayout *layout = UI_popup_menu_layout(pup); - uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); - uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_COPY); - uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_MOVE); + uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); + uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_COPY); + uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_MOVE); - UI_popup_menu_end(C, pup); + UI_popup_menu_end(C, pup); - return OPERATOR_INTERFACE; + return OPERATOR_INTERFACE; } void NODE_OT_group_separate(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Separate"; - ot->description = "Separate selected nodes from the node group"; - ot->idname = "NODE_OT_group_separate"; + /* identifiers */ + ot->name = "Separate"; + ot->description = "Separate selected nodes from the node group"; + ot->idname = "NODE_OT_group_separate"; - /* api callbacks */ - ot->invoke = node_group_separate_invoke; - ot->exec = node_group_separate_exec; - ot->poll = node_group_operator_editable; + /* api callbacks */ + ot->invoke = node_group_separate_invoke; + ot->exec = node_group_separate_exec; + ot->poll = node_group_operator_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_enum(ot->srna, "type", node_group_separate_types, NODE_GS_COPY, "Type", ""); + RNA_def_enum(ot->srna, "type", node_group_separate_types, NODE_GS_COPY, "Type", ""); } /* ****************** Make Group operator ******************* */ static bool node_group_make_use_node(bNode *node, bNode *gnode) { - return (node != gnode && - !ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT) && - (node->flag & NODE_SELECT)); + return (node != gnode && !ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT) && + (node->flag & NODE_SELECT)); } -static bool node_group_make_test_selected(bNodeTree *ntree, bNode *gnode, const char *ntree_idname, struct ReportList *reports) +static bool node_group_make_test_selected(bNodeTree *ntree, + bNode *gnode, + const char *ntree_idname, + struct ReportList *reports) { - bNodeTree *ngroup; - bNode *node; - bNodeLink *link; - int ok = true; - - /* make a local pseudo node tree to pass to the node poll functions */ - ngroup = ntreeAddTree(NULL, "Pseudo Node Group", ntree_idname); - - /* check poll functions for selected nodes */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node_group_make_use_node(node, gnode)) { - if (node->typeinfo->poll_instance && !node->typeinfo->poll_instance(node, ngroup)) { - BKE_reportf(reports, RPT_WARNING, "Can not add node '%s' in a group", node->name); - ok = false; - break; - } - } - - node->done = 0; - } - - /* free local pseudo node tree again */ - ntreeFreeTree(ngroup); - MEM_freeN(ngroup); - if (!ok) { - return false; - } - - /* check if all connections are OK, no unselected node has both - * inputs and outputs to a selection */ - for (link = ntree->links.first; link; link = link->next) { - if (node_group_make_use_node(link->fromnode, gnode)) { - link->tonode->done |= 1; - } - if (node_group_make_use_node(link->tonode, gnode)) { - link->fromnode->done |= 2; - } - } - for (node = ntree->nodes.first; node; node = node->next) { - if (!(node->flag & NODE_SELECT) && - node != gnode && - node->done == 3) - { - return false; - } - } - return true; + bNodeTree *ngroup; + bNode *node; + bNodeLink *link; + int ok = true; + + /* make a local pseudo node tree to pass to the node poll functions */ + ngroup = ntreeAddTree(NULL, "Pseudo Node Group", ntree_idname); + + /* check poll functions for selected nodes */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node_group_make_use_node(node, gnode)) { + if (node->typeinfo->poll_instance && !node->typeinfo->poll_instance(node, ngroup)) { + BKE_reportf(reports, RPT_WARNING, "Can not add node '%s' in a group", node->name); + ok = false; + break; + } + } + + node->done = 0; + } + + /* free local pseudo node tree again */ + ntreeFreeTree(ngroup); + MEM_freeN(ngroup); + if (!ok) { + return false; + } + + /* check if all connections are OK, no unselected node has both + * inputs and outputs to a selection */ + for (link = ntree->links.first; link; link = link->next) { + if (node_group_make_use_node(link->fromnode, gnode)) { + link->tonode->done |= 1; + } + if (node_group_make_use_node(link->tonode, gnode)) { + link->fromnode->done |= 2; + } + } + for (node = ntree->nodes.first; node; node = node->next) { + if (!(node->flag & NODE_SELECT) && node != gnode && node->done == 3) { + return false; + } + } + return true; } static int node_get_selected_minmax(bNodeTree *ntree, bNode *gnode, float *min, float *max) { - bNode *node; - float loc[2]; - int totselect = 0; - - INIT_MINMAX2(min, max); - for (node = ntree->nodes.first; node; node = node->next) { - if (node_group_make_use_node(node, gnode)) { - nodeToView(node, 0.0f, 0.0f, &loc[0], &loc[1]); - minmax_v2v2_v2(min, max, loc); - ++totselect; - } - } - - /* sane min/max if no selected nodes */ - if (totselect == 0) { - min[0] = min[1] = max[0] = max[1] = 0.0f; - } - - return totselect; + bNode *node; + float loc[2]; + int totselect = 0; + + INIT_MINMAX2(min, max); + for (node = ntree->nodes.first; node; node = node->next) { + if (node_group_make_use_node(node, gnode)) { + nodeToView(node, 0.0f, 0.0f, &loc[0], &loc[1]); + minmax_v2v2_v2(min, max, loc); + ++totselect; + } + } + + /* sane min/max if no selected nodes */ + if (totselect == 0) { + min[0] = min[1] = max[0] = max[1] = 0.0f; + } + + return totselect; } static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, bNode *gnode) { - Main *bmain = CTX_data_main(C); - bNodeTree *ngroup = (bNodeTree *)gnode->id; - bNodeLink *link, *linkn; - bNode *node, *nextn; - bNodeSocket *sock; - ListBase anim_basepaths = {NULL, NULL}; - float min[2], max[2], center[2]; - int totselect; - bool expose_all = false; - bNode *input_node, *output_node; - - /* XXX rough guess, not nice but we don't have access to UI constants here ... */ - static const float offsetx = 200; - static const float offsety = 0.0f; - - /* deselect all nodes in the target tree */ - for (node = ngroup->nodes.first; node; node = node->next) { - nodeSetSelected(node, false); - } - - totselect = node_get_selected_minmax(ntree, gnode, min, max); - add_v2_v2v2(center, min, max); - mul_v2_fl(center, 0.5f); - - /* auto-add interface for "solo" nodes */ - if (totselect == 1) { - expose_all = true; - } - - /* move nodes over */ - for (node = ntree->nodes.first; node; node = nextn) { - nextn = node->next; - if (node_group_make_use_node(node, gnode)) { - /* keep track of this node's RNA "base" path (the part of the pat identifying the node) - * if the old nodetree has animation data which potentially covers this node - */ - if (ntree->adt) { - PointerRNA ptr; - char *path; - - RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); - path = RNA_path_from_ID_to_struct(&ptr); - - if (path) { - BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); - } - } - - /* ensure valid parent pointers, detach if parent stays outside the group */ - if (node->parent && !(node->parent->flag & NODE_SELECT)) { - nodeDetachNode(node); - } - - /* change node-collection membership */ - BLI_remlink(&ntree->nodes, node); - BLI_addtail(&ngroup->nodes, node); - - /* ensure unique node name in the ngroup */ - nodeUniqueName(ngroup, node); - } - } - - /* move animation data over */ - if (ntree->adt) { - LinkData *ld, *ldn = NULL; - - BKE_animdata_separate_by_basepath(bmain, &ntree->id, &ngroup->id, &anim_basepaths); - - /* paths + their wrappers need to be freed */ - for (ld = anim_basepaths.first; ld; ld = ldn) { - ldn = ld->next; - - MEM_freeN(ld->data); - BLI_freelinkN(&anim_basepaths, ld); - } - } - - /* node groups don't use internal cached data */ - ntreeFreeCache(ngroup); - - /* create input node */ - input_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_INPUT); - input_node->locx = min[0] - center[0] - offsetx; - input_node->locy = -offsety; - - /* create output node */ - output_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_OUTPUT); - output_node->locx = max[0] - center[0] + offsetx; - output_node->locy = -offsety; - - /* relink external sockets */ - for (link = ntree->links.first; link; link = linkn) { - int fromselect = node_group_make_use_node(link->fromnode, gnode); - int toselect = node_group_make_use_node(link->tonode, gnode); - - linkn = link->next; - - if ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode)) { - /* remove all links to/from the gnode. - * this can remove link information, but there's no general way to preserve it. - */ - nodeRemLink(ntree, link); - } - else if (fromselect && toselect) { - BLI_remlink(&ntree->links, link); - BLI_addtail(&ngroup->links, link); - } - else if (toselect) { - bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link->tonode, link->tosock); - bNodeSocket *input_sock; - - /* update the group node and interface node sockets, - * so the new interface socket can be linked. - */ - node_group_verify(ntree, gnode, (ID *)ngroup); - node_group_input_verify(ngroup, input_node, (ID *)ngroup); - - /* create new internal link */ - input_sock = node_group_input_find_socket(input_node, iosock->identifier); - nodeAddLink(ngroup, input_node, input_sock, link->tonode, link->tosock); - - /* redirect external link */ - link->tonode = gnode; - link->tosock = node_group_find_input_socket(gnode, iosock->identifier); - } - else if (fromselect) { - /* First check whether the source of this link is already connected to an output. - * If yes, reuse that output instead of duplicating it. */ - bool connected = false; - bNodeLink *olink; - for (olink = ngroup->links.first; olink; olink = olink->next) { - if (olink->fromsock == link->fromsock && olink->tonode == output_node) { - bNodeSocket *output_sock = node_group_find_output_socket(gnode, olink->tosock->identifier); - link->fromnode = gnode; - link->fromsock = output_sock; - connected = true; - } - } - - if (!connected) { - bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link->fromnode, link->fromsock); - bNodeSocket *output_sock; - - /* update the group node and interface node sockets, - * so the new interface socket can be linked. - */ - node_group_verify(ntree, gnode, (ID *)ngroup); - node_group_output_verify(ngroup, output_node, (ID *)ngroup); - - /* create new internal link */ - output_sock = node_group_output_find_socket(output_node, iosock->identifier); - nodeAddLink(ngroup, link->fromnode, link->fromsock, output_node, output_sock); - - /* redirect external link */ - link->fromnode = gnode; - link->fromsock = node_group_find_output_socket(gnode, iosock->identifier); - } - } - } - - /* move nodes in the group to the center */ - for (node = ngroup->nodes.first; node; node = node->next) { - if (node_group_make_use_node(node, gnode) && !node->parent) { - node->locx -= center[0]; - node->locy -= center[1]; - } - } - - /* expose all unlinked sockets too */ - if (expose_all) { - for (node = ngroup->nodes.first; node; node = node->next) { - if (node_group_make_use_node(node, gnode)) { - for (sock = node->inputs.first; sock; sock = sock->next) { - bNodeSocket *iosock, *input_sock; - bool skip = false; - for (link = ngroup->links.first; link; link = link->next) { - if (link->tosock == sock) { - skip = true; - break; - } - } - if (skip) { - continue; - } - - iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock); - - node_group_input_verify(ngroup, input_node, (ID *)ngroup); - - /* create new internal link */ - input_sock = node_group_input_find_socket(input_node, iosock->identifier); - nodeAddLink(ngroup, input_node, input_sock, node, sock); - } - - for (sock = node->outputs.first; sock; sock = sock->next) { - bNodeSocket *iosock, *output_sock; - bool skip = false; - for (link = ngroup->links.first; link; link = link->next) { - if (link->fromsock == sock) { - skip = true; - } - } - if (skip) { - continue; - } - - iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock); - - node_group_output_verify(ngroup, output_node, (ID *)ngroup); - - /* create new internal link */ - output_sock = node_group_output_find_socket(output_node, iosock->identifier); - nodeAddLink(ngroup, node, sock, output_node, output_sock); - } - } - } - } - - /* update of the group tree */ - ngroup->update |= NTREE_UPDATE | NTREE_UPDATE_LINKS; - /* update of the tree containing the group instance node */ - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + Main *bmain = CTX_data_main(C); + bNodeTree *ngroup = (bNodeTree *)gnode->id; + bNodeLink *link, *linkn; + bNode *node, *nextn; + bNodeSocket *sock; + ListBase anim_basepaths = {NULL, NULL}; + float min[2], max[2], center[2]; + int totselect; + bool expose_all = false; + bNode *input_node, *output_node; + + /* XXX rough guess, not nice but we don't have access to UI constants here ... */ + static const float offsetx = 200; + static const float offsety = 0.0f; + + /* deselect all nodes in the target tree */ + for (node = ngroup->nodes.first; node; node = node->next) { + nodeSetSelected(node, false); + } + + totselect = node_get_selected_minmax(ntree, gnode, min, max); + add_v2_v2v2(center, min, max); + mul_v2_fl(center, 0.5f); + + /* auto-add interface for "solo" nodes */ + if (totselect == 1) { + expose_all = true; + } + + /* move nodes over */ + for (node = ntree->nodes.first; node; node = nextn) { + nextn = node->next; + if (node_group_make_use_node(node, gnode)) { + /* keep track of this node's RNA "base" path (the part of the pat identifying the node) + * if the old nodetree has animation data which potentially covers this node + */ + if (ntree->adt) { + PointerRNA ptr; + char *path; + + RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); + path = RNA_path_from_ID_to_struct(&ptr); + + if (path) { + BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } + } + + /* ensure valid parent pointers, detach if parent stays outside the group */ + if (node->parent && !(node->parent->flag & NODE_SELECT)) { + nodeDetachNode(node); + } + + /* change node-collection membership */ + BLI_remlink(&ntree->nodes, node); + BLI_addtail(&ngroup->nodes, node); + + /* ensure unique node name in the ngroup */ + nodeUniqueName(ngroup, node); + } + } + + /* move animation data over */ + if (ntree->adt) { + LinkData *ld, *ldn = NULL; + + BKE_animdata_separate_by_basepath(bmain, &ntree->id, &ngroup->id, &anim_basepaths); + + /* paths + their wrappers need to be freed */ + for (ld = anim_basepaths.first; ld; ld = ldn) { + ldn = ld->next; + + MEM_freeN(ld->data); + BLI_freelinkN(&anim_basepaths, ld); + } + } + + /* node groups don't use internal cached data */ + ntreeFreeCache(ngroup); + + /* create input node */ + input_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_INPUT); + input_node->locx = min[0] - center[0] - offsetx; + input_node->locy = -offsety; + + /* create output node */ + output_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_OUTPUT); + output_node->locx = max[0] - center[0] + offsetx; + output_node->locy = -offsety; + + /* relink external sockets */ + for (link = ntree->links.first; link; link = linkn) { + int fromselect = node_group_make_use_node(link->fromnode, gnode); + int toselect = node_group_make_use_node(link->tonode, gnode); + + linkn = link->next; + + if ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode)) { + /* remove all links to/from the gnode. + * this can remove link information, but there's no general way to preserve it. + */ + nodeRemLink(ntree, link); + } + else if (fromselect && toselect) { + BLI_remlink(&ntree->links, link); + BLI_addtail(&ngroup->links, link); + } + else if (toselect) { + bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link->tonode, link->tosock); + bNodeSocket *input_sock; + + /* update the group node and interface node sockets, + * so the new interface socket can be linked. + */ + node_group_verify(ntree, gnode, (ID *)ngroup); + node_group_input_verify(ngroup, input_node, (ID *)ngroup); + + /* create new internal link */ + input_sock = node_group_input_find_socket(input_node, iosock->identifier); + nodeAddLink(ngroup, input_node, input_sock, link->tonode, link->tosock); + + /* redirect external link */ + link->tonode = gnode; + link->tosock = node_group_find_input_socket(gnode, iosock->identifier); + } + else if (fromselect) { + /* First check whether the source of this link is already connected to an output. + * If yes, reuse that output instead of duplicating it. */ + bool connected = false; + bNodeLink *olink; + for (olink = ngroup->links.first; olink; olink = olink->next) { + if (olink->fromsock == link->fromsock && olink->tonode == output_node) { + bNodeSocket *output_sock = node_group_find_output_socket(gnode, + olink->tosock->identifier); + link->fromnode = gnode; + link->fromsock = output_sock; + connected = true; + } + } + + if (!connected) { + bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket( + ngroup, link->fromnode, link->fromsock); + bNodeSocket *output_sock; + + /* update the group node and interface node sockets, + * so the new interface socket can be linked. + */ + node_group_verify(ntree, gnode, (ID *)ngroup); + node_group_output_verify(ngroup, output_node, (ID *)ngroup); + + /* create new internal link */ + output_sock = node_group_output_find_socket(output_node, iosock->identifier); + nodeAddLink(ngroup, link->fromnode, link->fromsock, output_node, output_sock); + + /* redirect external link */ + link->fromnode = gnode; + link->fromsock = node_group_find_output_socket(gnode, iosock->identifier); + } + } + } + + /* move nodes in the group to the center */ + for (node = ngroup->nodes.first; node; node = node->next) { + if (node_group_make_use_node(node, gnode) && !node->parent) { + node->locx -= center[0]; + node->locy -= center[1]; + } + } + + /* expose all unlinked sockets too */ + if (expose_all) { + for (node = ngroup->nodes.first; node; node = node->next) { + if (node_group_make_use_node(node, gnode)) { + for (sock = node->inputs.first; sock; sock = sock->next) { + bNodeSocket *iosock, *input_sock; + bool skip = false; + for (link = ngroup->links.first; link; link = link->next) { + if (link->tosock == sock) { + skip = true; + break; + } + } + if (skip) { + continue; + } + + iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock); + + node_group_input_verify(ngroup, input_node, (ID *)ngroup); + + /* create new internal link */ + input_sock = node_group_input_find_socket(input_node, iosock->identifier); + nodeAddLink(ngroup, input_node, input_sock, node, sock); + } + + for (sock = node->outputs.first; sock; sock = sock->next) { + bNodeSocket *iosock, *output_sock; + bool skip = false; + for (link = ngroup->links.first; link; link = link->next) { + if (link->fromsock == sock) { + skip = true; + } + } + if (skip) { + continue; + } + + iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock); + + node_group_output_verify(ngroup, output_node, (ID *)ngroup); + + /* create new internal link */ + output_sock = node_group_output_find_socket(output_node, iosock->identifier); + nodeAddLink(ngroup, node, sock, output_node, output_sock); + } + } + } + } + + /* update of the group tree */ + ngroup->update |= NTREE_UPDATE | NTREE_UPDATE_LINKS; + /* update of the tree containing the group instance node */ + ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; } -static bNode *node_group_make_from_selected(const bContext *C, bNodeTree *ntree, const char *ntype, const char *ntreetype) +static bNode *node_group_make_from_selected(const bContext *C, + bNodeTree *ntree, + const char *ntype, + const char *ntreetype) { - Main *bmain = CTX_data_main(C); - bNode *gnode; - bNodeTree *ngroup; - float min[2], max[2]; - int totselect; + Main *bmain = CTX_data_main(C); + bNode *gnode; + bNodeTree *ngroup; + float min[2], max[2]; + int totselect; - totselect = node_get_selected_minmax(ntree, NULL, min, max); - /* don't make empty group */ - if (totselect == 0) { - return NULL; - } + totselect = node_get_selected_minmax(ntree, NULL, min, max); + /* don't make empty group */ + if (totselect == 0) { + return NULL; + } - /* new nodetree */ - ngroup = ntreeAddTree(bmain, "NodeGroup", ntreetype); + /* new nodetree */ + ngroup = ntreeAddTree(bmain, "NodeGroup", ntreetype); - /* make group node */ - gnode = nodeAddNode(C, ntree, ntype); - gnode->id = (ID *)ngroup; + /* make group node */ + gnode = nodeAddNode(C, ntree, ntype); + gnode->id = (ID *)ngroup; - gnode->locx = 0.5f * (min[0] + max[0]); - gnode->locy = 0.5f * (min[1] + max[1]); + gnode->locx = 0.5f * (min[0] + max[0]); + gnode->locy = 0.5f * (min[1] + max[1]); - node_group_make_insert_selected(C, ntree, gnode); + node_group_make_insert_selected(C, ntree, gnode); - /* update of the tree containing the group instance node */ - ntree->update |= NTREE_UPDATE_NODES; + /* update of the tree containing the group instance node */ + ntree->update |= NTREE_UPDATE_NODES; - return gnode; + return gnode; } static int node_group_make_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - const char *ntree_idname = group_ntree_idname(C); - const char *node_idname = group_node_idname(C); - bNodeTree *ngroup; - bNode *gnode; - Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + const char *ntree_idname = group_ntree_idname(C); + const char *node_idname = group_node_idname(C); + bNodeTree *ngroup; + bNode *gnode; + Main *bmain = CTX_data_main(C); - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - if (!node_group_make_test_selected(ntree, NULL, ntree_idname, op->reports)) { - return OPERATOR_CANCELLED; - } + if (!node_group_make_test_selected(ntree, NULL, ntree_idname, op->reports)) { + return OPERATOR_CANCELLED; + } - gnode = node_group_make_from_selected(C, ntree, node_idname, ntree_idname); + gnode = node_group_make_from_selected(C, ntree, node_idname, ntree_idname); - if (gnode) { - ngroup = (bNodeTree *)gnode->id; + if (gnode) { + ngroup = (bNodeTree *)gnode->id; - nodeSetActive(ntree, gnode); - if (ngroup) { - ED_node_tree_push(snode, ngroup, gnode); - ntreeUpdateTree(bmain, ngroup); - } - } + nodeSetActive(ntree, gnode); + if (ngroup) { + ED_node_tree_push(snode, ngroup, gnode); + ntreeUpdateTree(bmain, ngroup); + } + } - ntreeUpdateTree(bmain, ntree); + ntreeUpdateTree(bmain, ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(C, snode); + snode_dag_update(C, snode); - /* We broke relations in node tree, need to rebuild them in the grahes. */ - DEG_relations_tag_update(bmain); + /* We broke relations in node tree, need to rebuild them in the grahes. */ + DEG_relations_tag_update(bmain); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_group_make(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Make Group"; - ot->description = "Make group from selected nodes"; - ot->idname = "NODE_OT_group_make"; + /* identifiers */ + ot->name = "Make Group"; + ot->description = "Make group from selected nodes"; + ot->idname = "NODE_OT_group_make"; - /* api callbacks */ - ot->exec = node_group_make_exec; - ot->poll = node_group_operator_editable; + /* api callbacks */ + ot->exec = node_group_make_exec; + ot->poll = node_group_operator_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Group Insert operator ******************* */ static int node_group_insert_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNodeTree *ngroup; - const char *node_idname = group_node_idname(C); - bNode *gnode; - Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNodeTree *ngroup; + const char *node_idname = group_node_idname(C); + bNode *gnode; + Main *bmain = CTX_data_main(C); - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - gnode = node_group_get_active(C, node_idname); + gnode = node_group_get_active(C, node_idname); - if (!gnode || !gnode->id) { - return OPERATOR_CANCELLED; - } + if (!gnode || !gnode->id) { + return OPERATOR_CANCELLED; + } - ngroup = (bNodeTree *)gnode->id; - if (!node_group_make_test_selected(ntree, gnode, ngroup->idname, op->reports)) { - return OPERATOR_CANCELLED; - } + ngroup = (bNodeTree *)gnode->id; + if (!node_group_make_test_selected(ntree, gnode, ngroup->idname, op->reports)) { + return OPERATOR_CANCELLED; + } - node_group_make_insert_selected(C, ntree, gnode); + node_group_make_insert_selected(C, ntree, gnode); - nodeSetActive(ntree, gnode); - ED_node_tree_push(snode, ngroup, gnode); - ntreeUpdateTree(bmain, ngroup); + nodeSetActive(ntree, gnode); + ED_node_tree_push(snode, ngroup, gnode); + ntreeUpdateTree(bmain, ngroup); - ntreeUpdateTree(bmain, ntree); + ntreeUpdateTree(bmain, ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(C, snode); + snode_dag_update(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_group_insert(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Group Insert"; - ot->description = "Insert selected nodes into a node group"; - ot->idname = "NODE_OT_group_insert"; + /* identifiers */ + ot->name = "Group Insert"; + ot->description = "Insert selected nodes into a node group"; + ot->idname = "NODE_OT_group_insert"; - /* api callbacks */ - ot->exec = node_group_insert_exec; - ot->poll = node_group_operator_editable; + /* api callbacks */ + ot->exec = node_group_insert_exec; + ot->poll = node_group_operator_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index dbd6ef163e3..7b4102ce324 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -43,14 +43,14 @@ struct wmWindow; /* temp data to pass on to modal */ typedef struct bNodeLinkDrag { - struct bNodeLinkDrag *next, *prev; - - /* List of links dragged by the operator. - * Note: This is a list of LinkData structs on top of the actual bNodeLinks. - * This way the links can be added to the node tree while being stored in this list. - */ - ListBase links; - int in_out; + struct bNodeLinkDrag *next, *prev; + + /* List of links dragged by the operator. + * Note: This is a list of LinkData structs on top of the actual bNodeLinks. + * This way the links can be added to the node tree while being stored in this list. + */ + ListBase links; + int in_out; } bNodeLinkDrag; /* space_node.c */ @@ -64,19 +64,31 @@ void snode_group_offset(struct SpaceNode *snode, float *x, float *y); int node_get_colorid(struct bNode *node); int node_get_resize_cursor(int directions); void node_draw_shadow(struct SpaceNode *snode, struct bNode *node, float radius, float alpha); -void node_draw_default(const struct bContext *C, struct ARegion *ar, struct SpaceNode *snode, - struct bNodeTree *ntree, struct bNode *node, bNodeInstanceKey key); -void node_draw_sockets(struct View2D *v2d, const struct bContext *C, struct bNodeTree *ntree, struct bNode *node, bool draw_outputs, bool select_all); +void node_draw_default(const struct bContext *C, + struct ARegion *ar, + struct SpaceNode *snode, + struct bNodeTree *ntree, + struct bNode *node, + bNodeInstanceKey key); +void node_draw_sockets(struct View2D *v2d, + const struct bContext *C, + struct bNodeTree *ntree, + struct bNode *node, + bool draw_outputs, + bool select_all); void node_update_default(const struct bContext *C, struct bNodeTree *ntree, struct bNode *node); int node_select_area_default(struct bNode *node, int x, int y); int node_tweak_area_default(struct bNode *node, int x, int y); void node_update_nodetree(const struct bContext *C, struct bNodeTree *ntree); -void node_draw_nodetree(const struct bContext *C, struct ARegion *ar, struct SpaceNode *snode, - struct bNodeTree *ntree, bNodeInstanceKey parent_key); +void node_draw_nodetree(const struct bContext *C, + struct ARegion *ar, + struct SpaceNode *snode, + struct bNodeTree *ntree, + bNodeInstanceKey parent_key); void drawnodespace(const bContext *C, ARegion *ar); void node_set_cursor(struct wmWindow *win, struct SpaceNode *snode, float cursor[2]); - /* DPI scaled coords */ +/* DPI scaled coords */ void node_to_view(struct bNode *node, float x, float y, float *rx, float *ry); void node_to_updated_rect(struct bNode *node, rctf *r_rect); void node_from_view(struct bNode *node, float x, float y, float *rx, float *ry); @@ -113,8 +125,11 @@ void NODE_OT_select_same_type_step(struct wmOperatorType *ot); void NODE_OT_find_node(struct wmOperatorType *ot); /* node_view.c */ -int space_node_view_flag(struct bContext *C, SpaceNode *snode, ARegion *ar, - const int node_flag, const int smooth_viewtx); +int space_node_view_flag(struct bContext *C, + SpaceNode *snode, + ARegion *ar, + const int node_flag, + const int smooth_viewtx); void NODE_OT_view_all(struct wmOperatorType *ot); void NODE_OT_view_selected(struct wmOperatorType *ot); @@ -129,20 +144,31 @@ void nodelink_batch_start(struct SpaceNode *snode); void nodelink_batch_end(struct SpaceNode *snode); void node_draw_link(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link); -void node_draw_link_bezier(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link, int th_col1, int th_col2, int th_col3); -bool node_link_bezier_points(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link, float coord_array[][2], int resol); +void node_draw_link_bezier(struct View2D *v2d, + struct SpaceNode *snode, + struct bNodeLink *link, + int th_col1, + int th_col2, + int th_col3); +bool node_link_bezier_points(struct View2D *v2d, + struct SpaceNode *snode, + struct bNodeLink *link, + float coord_array[][2], + int resol); // void node_draw_link_straight(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 ); -void draw_nodespace_back_pix(const struct bContext *C, struct ARegion *ar, struct SpaceNode *snode, bNodeInstanceKey parent_key); - +void draw_nodespace_back_pix(const struct bContext *C, + struct ARegion *ar, + struct SpaceNode *snode, + bNodeInstanceKey parent_key); /* node_add.c */ -bNode *node_add_node(const struct bContext *C, const char *idname, int type, float locx, float locy); +bNode *node_add_node( + const struct bContext *C, const char *idname, int type, float locx, float locy); void NODE_OT_add_reroute(struct wmOperatorType *ot); void NODE_OT_add_file(struct wmOperatorType *ot); void NODE_OT_add_mask(struct wmOperatorType *ot); void NODE_OT_new_node_tree(struct wmOperatorType *ot); - /* node_group.c */ void NODE_OT_group_make(struct wmOperatorType *ot); void NODE_OT_group_insert(struct wmOperatorType *ot); @@ -150,7 +176,6 @@ void NODE_OT_group_ungroup(struct wmOperatorType *ot); void NODE_OT_group_separate(struct wmOperatorType *ot); void NODE_OT_group_edit(struct wmOperatorType *ot); - /* node_relationships.c */ bool node_connected_to_output(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node); @@ -180,7 +205,11 @@ bool composite_node_editable(struct bContext *C); int node_has_hidden_sockets(bNode *node); void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set); int node_render_changed_exec(bContext *, struct wmOperator *); -int node_find_indicated_socket(struct SpaceNode *snode, struct bNode **nodep, struct bNodeSocket **sockp, float cursor[2], int in_out); +int node_find_indicated_socket(struct SpaceNode *snode, + struct bNode **nodep, + struct bNodeSocket **sockp, + float cursor[2], + int in_out); void NODE_OT_duplicate(struct wmOperatorType *ot); void NODE_OT_delete(struct wmOperatorType *ot); @@ -201,7 +230,7 @@ void NODE_OT_output_file_add_socket(struct wmOperatorType *ot); void NODE_OT_output_file_remove_active_socket(struct wmOperatorType *ot); void NODE_OT_output_file_move_active_socket(struct wmOperatorType *ot); -void NODE_OT_switch_view_update (struct wmOperatorType *ot); +void NODE_OT_switch_view_update(struct wmOperatorType *ot); /* Note: clipboard_cut is a simple macro of copy + delete */ void NODE_OT_clipboard_copy(struct wmOperatorType *ot); @@ -230,36 +259,36 @@ extern const char *node_context_dir[]; // XXXXXX // nodes draw without dpi - the view zoom is flexible -#define HIDDEN_RAD (0.75f * U.widget_unit) -#define BASIS_RAD (0.2f * U.widget_unit) -#define NODE_DYS (U.widget_unit / 2) -#define NODE_DY U.widget_unit -#define NODE_SOCKDY (0.08f * U.widget_unit) -#define NODE_WIDTH(node) (node->width * UI_DPI_FAC) +#define HIDDEN_RAD (0.75f * U.widget_unit) +#define BASIS_RAD (0.2f * U.widget_unit) +#define NODE_DYS (U.widget_unit / 2) +#define NODE_DY U.widget_unit +#define NODE_SOCKDY (0.08f * U.widget_unit) +#define NODE_WIDTH(node) (node->width * UI_DPI_FAC) #define NODE_HEIGHT(node) (node->height * UI_DPI_FAC) -#define NODE_MARGIN_X (0.75f * U.widget_unit) -#define NODE_SOCKSIZE (0.25f * U.widget_unit) +#define NODE_MARGIN_X (0.75f * U.widget_unit) +#define NODE_SOCKSIZE (0.25f * U.widget_unit) #define NODE_RESIZE_MARGIN (0.20f * U.widget_unit) #define NODE_LINK_RESOL 12 // XXX button events (butspace) enum eNodeSpace_ButEvents { - B_NOP = 0, - B_REDR = 1, - B_NODE_USEMAT, - B_NODE_USESCENE, - B_NODE_USETEX, - B_TEXBROWSE, - B_TEXALONE, - B_TEXLOCAL, - B_TEXDELETE, - B_TEXPRV, - B_AUTOTEXNAME, - B_KEEPDATA, - B_NODE_EXEC, - B_MATPRV, - B_NODE_LOADIMAGE, - B_NODE_SETIMAGE, + B_NOP = 0, + B_REDR = 1, + B_NODE_USEMAT, + B_NODE_USESCENE, + B_NODE_USETEX, + B_TEXBROWSE, + B_TEXALONE, + B_TEXLOCAL, + B_TEXDELETE, + B_TEXPRV, + B_AUTOTEXNAME, + B_KEEPDATA, + B_NODE_EXEC, + B_MATPRV, + B_NODE_LOADIMAGE, + B_NODE_SETIMAGE, }; #endif /* __NODE_INTERN_H__ */ diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index 517e4df1dc1..ce6bf2820c6 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -21,14 +21,13 @@ * \ingroup spnode */ - #include "DNA_node_types.h" #include "BLI_utildefines.h" #include "BKE_context.h" -#include "ED_node.h" /* own include */ +#include "ED_node.h" /* own include */ #include "ED_screen.h" #include "ED_select_utils.h" #include "ED_transform.h" @@ -38,170 +37,180 @@ #include "WM_api.h" #include "WM_types.h" -#include "node_intern.h" /* own include */ +#include "node_intern.h" /* own include */ void node_operatortypes(void) { - WM_operatortype_append(NODE_OT_properties); - WM_operatortype_append(NODE_OT_toolbar); + WM_operatortype_append(NODE_OT_properties); + WM_operatortype_append(NODE_OT_toolbar); - WM_operatortype_append(NODE_OT_select); - WM_operatortype_append(NODE_OT_select_all); - WM_operatortype_append(NODE_OT_select_linked_to); - WM_operatortype_append(NODE_OT_select_linked_from); - WM_operatortype_append(NODE_OT_select_box); - WM_operatortype_append(NODE_OT_select_circle); - WM_operatortype_append(NODE_OT_select_lasso); - WM_operatortype_append(NODE_OT_select_grouped); - WM_operatortype_append(NODE_OT_select_same_type_step); + WM_operatortype_append(NODE_OT_select); + WM_operatortype_append(NODE_OT_select_all); + WM_operatortype_append(NODE_OT_select_linked_to); + WM_operatortype_append(NODE_OT_select_linked_from); + WM_operatortype_append(NODE_OT_select_box); + WM_operatortype_append(NODE_OT_select_circle); + WM_operatortype_append(NODE_OT_select_lasso); + WM_operatortype_append(NODE_OT_select_grouped); + WM_operatortype_append(NODE_OT_select_same_type_step); - WM_operatortype_append(NODE_OT_find_node); + WM_operatortype_append(NODE_OT_find_node); - WM_operatortype_append(NODE_OT_view_all); - WM_operatortype_append(NODE_OT_view_selected); + WM_operatortype_append(NODE_OT_view_all); + WM_operatortype_append(NODE_OT_view_selected); - WM_operatortype_append(NODE_OT_mute_toggle); - WM_operatortype_append(NODE_OT_hide_toggle); - WM_operatortype_append(NODE_OT_preview_toggle); - WM_operatortype_append(NODE_OT_options_toggle); - WM_operatortype_append(NODE_OT_hide_socket_toggle); - WM_operatortype_append(NODE_OT_node_copy_color); + WM_operatortype_append(NODE_OT_mute_toggle); + WM_operatortype_append(NODE_OT_hide_toggle); + WM_operatortype_append(NODE_OT_preview_toggle); + WM_operatortype_append(NODE_OT_options_toggle); + WM_operatortype_append(NODE_OT_hide_socket_toggle); + WM_operatortype_append(NODE_OT_node_copy_color); - WM_operatortype_append(NODE_OT_duplicate); - WM_operatortype_append(NODE_OT_delete); - WM_operatortype_append(NODE_OT_delete_reconnect); - WM_operatortype_append(NODE_OT_resize); + WM_operatortype_append(NODE_OT_duplicate); + WM_operatortype_append(NODE_OT_delete); + WM_operatortype_append(NODE_OT_delete_reconnect); + WM_operatortype_append(NODE_OT_resize); - WM_operatortype_append(NODE_OT_link); - WM_operatortype_append(NODE_OT_link_make); - WM_operatortype_append(NODE_OT_links_cut); - WM_operatortype_append(NODE_OT_links_detach); - WM_operatortype_append(NODE_OT_add_reroute); + WM_operatortype_append(NODE_OT_link); + WM_operatortype_append(NODE_OT_link_make); + WM_operatortype_append(NODE_OT_links_cut); + WM_operatortype_append(NODE_OT_links_detach); + WM_operatortype_append(NODE_OT_add_reroute); - WM_operatortype_append(NODE_OT_group_make); - WM_operatortype_append(NODE_OT_group_insert); - WM_operatortype_append(NODE_OT_group_ungroup); - WM_operatortype_append(NODE_OT_group_separate); - WM_operatortype_append(NODE_OT_group_edit); + WM_operatortype_append(NODE_OT_group_make); + WM_operatortype_append(NODE_OT_group_insert); + WM_operatortype_append(NODE_OT_group_ungroup); + WM_operatortype_append(NODE_OT_group_separate); + WM_operatortype_append(NODE_OT_group_edit); - WM_operatortype_append(NODE_OT_link_viewer); + WM_operatortype_append(NODE_OT_link_viewer); - WM_operatortype_append(NODE_OT_insert_offset); + WM_operatortype_append(NODE_OT_insert_offset); - WM_operatortype_append(NODE_OT_read_viewlayers); - WM_operatortype_append(NODE_OT_render_changed); + WM_operatortype_append(NODE_OT_read_viewlayers); + WM_operatortype_append(NODE_OT_render_changed); - WM_operatortype_append(NODE_OT_backimage_move); - WM_operatortype_append(NODE_OT_backimage_zoom); - WM_operatortype_append(NODE_OT_backimage_fit); - WM_operatortype_append(NODE_OT_backimage_sample); + WM_operatortype_append(NODE_OT_backimage_move); + WM_operatortype_append(NODE_OT_backimage_zoom); + WM_operatortype_append(NODE_OT_backimage_fit); + WM_operatortype_append(NODE_OT_backimage_sample); - WM_operatortype_append(NODE_OT_add_file); - WM_operatortype_append(NODE_OT_add_mask); + WM_operatortype_append(NODE_OT_add_file); + WM_operatortype_append(NODE_OT_add_mask); - WM_operatortype_append(NODE_OT_new_node_tree); + WM_operatortype_append(NODE_OT_new_node_tree); - WM_operatortype_append(NODE_OT_output_file_add_socket); - WM_operatortype_append(NODE_OT_output_file_remove_active_socket); - WM_operatortype_append(NODE_OT_output_file_move_active_socket); + WM_operatortype_append(NODE_OT_output_file_add_socket); + WM_operatortype_append(NODE_OT_output_file_remove_active_socket); + WM_operatortype_append(NODE_OT_output_file_move_active_socket); - WM_operatortype_append(NODE_OT_parent_set); - WM_operatortype_append(NODE_OT_join); - WM_operatortype_append(NODE_OT_attach); - WM_operatortype_append(NODE_OT_detach); + WM_operatortype_append(NODE_OT_parent_set); + WM_operatortype_append(NODE_OT_join); + WM_operatortype_append(NODE_OT_attach); + WM_operatortype_append(NODE_OT_detach); - WM_operatortype_append(NODE_OT_clipboard_copy); - WM_operatortype_append(NODE_OT_clipboard_paste); + WM_operatortype_append(NODE_OT_clipboard_copy); + WM_operatortype_append(NODE_OT_clipboard_paste); - WM_operatortype_append(NODE_OT_shader_script_update); + WM_operatortype_append(NODE_OT_shader_script_update); - WM_operatortype_append(NODE_OT_viewer_border); - WM_operatortype_append(NODE_OT_clear_viewer_border); + WM_operatortype_append(NODE_OT_viewer_border); + WM_operatortype_append(NODE_OT_clear_viewer_border); - WM_operatortype_append(NODE_OT_switch_view_update); + WM_operatortype_append(NODE_OT_switch_view_update); - WM_operatortype_append(NODE_OT_tree_socket_add); - WM_operatortype_append(NODE_OT_tree_socket_remove); - WM_operatortype_append(NODE_OT_tree_socket_move); + WM_operatortype_append(NODE_OT_tree_socket_add); + WM_operatortype_append(NODE_OT_tree_socket_remove); + WM_operatortype_append(NODE_OT_tree_socket_move); - WM_operatortype_append(NODE_OT_cryptomatte_layer_add); - WM_operatortype_append(NODE_OT_cryptomatte_layer_remove); + WM_operatortype_append(NODE_OT_cryptomatte_layer_add); + WM_operatortype_append(NODE_OT_cryptomatte_layer_remove); } void ED_operatormacros_node(void) { - wmOperatorType *ot; - wmOperatorTypeMacro *mot; - - ot = WM_operatortype_append_macro("NODE_OT_select_link_viewer", "Link Viewer", - "Select node and link it to a viewer node", - OPTYPE_UNDO); - mot = WM_operatortype_macro_define(ot, "NODE_OT_select"); - RNA_boolean_set(mot->ptr, "extend", false); - RNA_boolean_set(mot->ptr, "socket_select", true); - WM_operatortype_macro_define(ot, "NODE_OT_link_viewer"); - - ot = WM_operatortype_append_macro("NODE_OT_translate_attach", "Move and Attach", - "Move nodes and attach to frame", - OPTYPE_UNDO | OPTYPE_REGISTER); - mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_boolean_set(mot->ptr, "release_confirm", true); - WM_operatortype_macro_define(ot, "NODE_OT_attach"); - WM_operatortype_macro_define(ot, "NODE_OT_insert_offset"); - - /* NODE_OT_translate_attach with remove_on_canel set to true */ - ot = WM_operatortype_append_macro("NODE_OT_translate_attach_remove_on_cancel", "Move and Attach", - "Move nodes and attach to frame", - OPTYPE_UNDO | OPTYPE_REGISTER); - mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_boolean_set(mot->ptr, "release_confirm", true); - RNA_boolean_set(mot->ptr, "remove_on_cancel", true); - WM_operatortype_macro_define(ot, "NODE_OT_attach"); - WM_operatortype_macro_define(ot, "NODE_OT_insert_offset"); - - /* Note: Currently not in a default keymap or menu due to messy keymaps - * and tricky invoke functionality. - * Kept around in case users want to make own shortcuts. - */ - ot = WM_operatortype_append_macro("NODE_OT_detach_translate_attach", "Detach and Move", - "Detach nodes, move and attach to frame", - OPTYPE_UNDO | OPTYPE_REGISTER); - WM_operatortype_macro_define(ot, "NODE_OT_detach"); - mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_boolean_set(mot->ptr, "release_confirm", true); - WM_operatortype_macro_define(ot, "NODE_OT_attach"); - - ot = WM_operatortype_append_macro("NODE_OT_duplicate_move", "Duplicate", - "Duplicate selected nodes and move them", - OPTYPE_UNDO | OPTYPE_REGISTER); - WM_operatortype_macro_define(ot, "NODE_OT_duplicate"); - WM_operatortype_macro_define(ot, "NODE_OT_translate_attach"); - - /* modified operator call for duplicating with input links */ - ot = WM_operatortype_append_macro("NODE_OT_duplicate_move_keep_inputs", "Duplicate", - "Duplicate selected nodes keeping input links and move them", - OPTYPE_UNDO | OPTYPE_REGISTER); - mot = WM_operatortype_macro_define(ot, "NODE_OT_duplicate"); - RNA_boolean_set(mot->ptr, "keep_inputs", true); - WM_operatortype_macro_define(ot, "NODE_OT_translate_attach"); - - ot = WM_operatortype_append_macro("NODE_OT_move_detach_links", "Detach", "Move a node to detach links", - OPTYPE_UNDO | OPTYPE_REGISTER); - WM_operatortype_macro_define(ot, "NODE_OT_links_detach"); - WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - WM_operatortype_macro_define(ot, "NODE_OT_insert_offset"); - - ot = WM_operatortype_append_macro("NODE_OT_move_detach_links_release", "Detach", "Move a node to detach links", - OPTYPE_UNDO | OPTYPE_REGISTER); - WM_operatortype_macro_define(ot, "NODE_OT_links_detach"); - WM_operatortype_macro_define(ot, "NODE_OT_translate_attach"); + wmOperatorType *ot; + wmOperatorTypeMacro *mot; + + ot = WM_operatortype_append_macro("NODE_OT_select_link_viewer", + "Link Viewer", + "Select node and link it to a viewer node", + OPTYPE_UNDO); + mot = WM_operatortype_macro_define(ot, "NODE_OT_select"); + RNA_boolean_set(mot->ptr, "extend", false); + RNA_boolean_set(mot->ptr, "socket_select", true); + WM_operatortype_macro_define(ot, "NODE_OT_link_viewer"); + + ot = WM_operatortype_append_macro("NODE_OT_translate_attach", + "Move and Attach", + "Move nodes and attach to frame", + OPTYPE_UNDO | OPTYPE_REGISTER); + mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); + RNA_boolean_set(mot->ptr, "release_confirm", true); + WM_operatortype_macro_define(ot, "NODE_OT_attach"); + WM_operatortype_macro_define(ot, "NODE_OT_insert_offset"); + + /* NODE_OT_translate_attach with remove_on_canel set to true */ + ot = WM_operatortype_append_macro("NODE_OT_translate_attach_remove_on_cancel", + "Move and Attach", + "Move nodes and attach to frame", + OPTYPE_UNDO | OPTYPE_REGISTER); + mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); + RNA_boolean_set(mot->ptr, "release_confirm", true); + RNA_boolean_set(mot->ptr, "remove_on_cancel", true); + WM_operatortype_macro_define(ot, "NODE_OT_attach"); + WM_operatortype_macro_define(ot, "NODE_OT_insert_offset"); + + /* Note: Currently not in a default keymap or menu due to messy keymaps + * and tricky invoke functionality. + * Kept around in case users want to make own shortcuts. + */ + ot = WM_operatortype_append_macro("NODE_OT_detach_translate_attach", + "Detach and Move", + "Detach nodes, move and attach to frame", + OPTYPE_UNDO | OPTYPE_REGISTER); + WM_operatortype_macro_define(ot, "NODE_OT_detach"); + mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); + RNA_boolean_set(mot->ptr, "release_confirm", true); + WM_operatortype_macro_define(ot, "NODE_OT_attach"); + + ot = WM_operatortype_append_macro("NODE_OT_duplicate_move", + "Duplicate", + "Duplicate selected nodes and move them", + OPTYPE_UNDO | OPTYPE_REGISTER); + WM_operatortype_macro_define(ot, "NODE_OT_duplicate"); + WM_operatortype_macro_define(ot, "NODE_OT_translate_attach"); + + /* modified operator call for duplicating with input links */ + ot = WM_operatortype_append_macro("NODE_OT_duplicate_move_keep_inputs", + "Duplicate", + "Duplicate selected nodes keeping input links and move them", + OPTYPE_UNDO | OPTYPE_REGISTER); + mot = WM_operatortype_macro_define(ot, "NODE_OT_duplicate"); + RNA_boolean_set(mot->ptr, "keep_inputs", true); + WM_operatortype_macro_define(ot, "NODE_OT_translate_attach"); + + ot = WM_operatortype_append_macro("NODE_OT_move_detach_links", + "Detach", + "Move a node to detach links", + OPTYPE_UNDO | OPTYPE_REGISTER); + WM_operatortype_macro_define(ot, "NODE_OT_links_detach"); + WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); + WM_operatortype_macro_define(ot, "NODE_OT_insert_offset"); + + ot = WM_operatortype_append_macro("NODE_OT_move_detach_links_release", + "Detach", + "Move a node to detach links", + OPTYPE_UNDO | OPTYPE_REGISTER); + WM_operatortype_macro_define(ot, "NODE_OT_links_detach"); + WM_operatortype_macro_define(ot, "NODE_OT_translate_attach"); } void node_keymap(struct wmKeyConfig *keyconf) { - /* Entire Editor only ----------------- */ - WM_keymap_ensure(keyconf, "Node Generic", SPACE_NODE, 0); + /* Entire Editor only ----------------- */ + WM_keymap_ensure(keyconf, "Node Generic", SPACE_NODE, 0); - /* Main Region only ----------------- */ - WM_keymap_ensure(keyconf, "Node Editor", SPACE_NODE, 0); + /* Main Region only ----------------- */ + WM_keymap_ensure(keyconf, "Node Editor", SPACE_NODE, 0); } diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index afb0c833aa8..14636dad8c6 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -36,7 +36,7 @@ #include "BKE_main.h" #include "BKE_node.h" -#include "ED_node.h" /* own include */ +#include "ED_node.h" /* own include */ #include "ED_screen.h" #include "ED_render.h" #include "ED_util.h" @@ -52,913 +52,905 @@ #include "BLT_translation.h" -#include "node_intern.h" /* own include */ +#include "node_intern.h" /* own include */ /* ****************** Relations helpers *********************** */ static bool ntree_has_drivers(bNodeTree *ntree) { - AnimData *adt = BKE_animdata_from_id(&ntree->id); - if (adt == NULL) { - return false; - } - return !BLI_listbase_is_empty(&adt->drivers); + AnimData *adt = BKE_animdata_from_id(&ntree->id); + if (adt == NULL) { + return false; + } + return !BLI_listbase_is_empty(&adt->drivers); } -static bool ntree_check_nodes_connected_dfs(bNodeTree *ntree, - bNode *from, - bNode *to) +static bool ntree_check_nodes_connected_dfs(bNodeTree *ntree, bNode *from, bNode *to) { - if (from->flag & NODE_TEST) { - return false; - } - from->flag |= NODE_TEST; - for (bNodeLink *link = ntree->links.first; link != NULL; link = link->next) { - if (link->fromnode == from) { - if (link->tonode == to) { - return true; - } - else { - if (ntree_check_nodes_connected_dfs(ntree, link->tonode, to)) { - return true; - } - } - } - } - return false; + if (from->flag & NODE_TEST) { + return false; + } + from->flag |= NODE_TEST; + for (bNodeLink *link = ntree->links.first; link != NULL; link = link->next) { + if (link->fromnode == from) { + if (link->tonode == to) { + return true; + } + else { + if (ntree_check_nodes_connected_dfs(ntree, link->tonode, to)) { + return true; + } + } + } + } + return false; } static bool ntree_check_nodes_connected(bNodeTree *ntree, bNode *from, bNode *to) { - if (from == to) { - return true; - } - ntreeNodeFlagSet(ntree, NODE_TEST, false); - return ntree_check_nodes_connected_dfs(ntree, from, to); + if (from == to) { + return true; + } + ntreeNodeFlagSet(ntree, NODE_TEST, false); + return ntree_check_nodes_connected_dfs(ntree, from, to); } static bool node_group_has_output_dfs(bNode *node) { - bNodeTree *ntree = (bNodeTree *)node->id; - if (ntree->id.tag & LIB_TAG_DOIT) { - return false; - } - ntree->id.tag |= LIB_TAG_DOIT; - for (bNode *current_node = ntree->nodes.first; - current_node != NULL; - current_node = current_node->next) - { - if (current_node->type == NODE_GROUP) { - if (current_node->id && node_group_has_output_dfs(current_node)) { - return true; - } - } - if (current_node->flag & NODE_DO_OUTPUT && - current_node->type != NODE_GROUP_OUTPUT) - { - return true; - } - } - return false; + bNodeTree *ntree = (bNodeTree *)node->id; + if (ntree->id.tag & LIB_TAG_DOIT) { + return false; + } + ntree->id.tag |= LIB_TAG_DOIT; + for (bNode *current_node = ntree->nodes.first; current_node != NULL; + current_node = current_node->next) { + if (current_node->type == NODE_GROUP) { + if (current_node->id && node_group_has_output_dfs(current_node)) { + return true; + } + } + if (current_node->flag & NODE_DO_OUTPUT && current_node->type != NODE_GROUP_OUTPUT) { + return true; + } + } + return false; } static bool node_group_has_output(Main *bmain, bNode *node) { - BLI_assert(ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)); - bNodeTree *ntree = (bNodeTree *)node->id; - if (ntree == NULL) { - return false; - } - BKE_main_id_tag_listbase(&bmain->nodetrees, LIB_TAG_DOIT, false); - return node_group_has_output_dfs(node); + BLI_assert(ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)); + bNodeTree *ntree = (bNodeTree *)node->id; + if (ntree == NULL) { + return false; + } + BKE_main_id_tag_listbase(&bmain->nodetrees, LIB_TAG_DOIT, false); + return node_group_has_output_dfs(node); } bool node_connected_to_output(Main *bmain, bNodeTree *ntree, bNode *node) { - /* Special case for drivers: if node tree has any drivers we assume it is - * always to be tagged for update when node changes. Otherwise we will be - * doomed to do some deep and nasty deep search of indirect dependencies, - * which will be too complicated without real benefit. - */ - if (ntree_has_drivers(ntree)) { - return true; - } - for (bNode *current_node = ntree->nodes.first; - current_node != NULL; - current_node = current_node->next) - { - /* Special case for group nodes -- if modified node connected to a group - * with active output inside we consider refresh is needed. - * - * We could make check more grained here by taking which socket the node - * is connected to and so eventually. - */ - if (ELEM(current_node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { - if (current_node->id != NULL && - ntree_has_drivers((bNodeTree *)current_node->id)) - { - return true; - } - if (ntree_check_nodes_connected(ntree, node, current_node) && - node_group_has_output(bmain, current_node)) - { - return true; - } - } - if (current_node->flag & NODE_DO_OUTPUT) { - if (ntree_check_nodes_connected(ntree, node, current_node)) { - return true; - } - } - } - return false; + /* Special case for drivers: if node tree has any drivers we assume it is + * always to be tagged for update when node changes. Otherwise we will be + * doomed to do some deep and nasty deep search of indirect dependencies, + * which will be too complicated without real benefit. + */ + if (ntree_has_drivers(ntree)) { + return true; + } + for (bNode *current_node = ntree->nodes.first; current_node != NULL; + current_node = current_node->next) { + /* Special case for group nodes -- if modified node connected to a group + * with active output inside we consider refresh is needed. + * + * We could make check more grained here by taking which socket the node + * is connected to and so eventually. + */ + if (ELEM(current_node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { + if (current_node->id != NULL && ntree_has_drivers((bNodeTree *)current_node->id)) { + return true; + } + if (ntree_check_nodes_connected(ntree, node, current_node) && + node_group_has_output(bmain, current_node)) { + return true; + } + } + if (current_node->flag & NODE_DO_OUTPUT) { + if (ntree_check_nodes_connected(ntree, node, current_node)) { + return true; + } + } + } + return false; } /* ****************** Add *********************** */ - typedef struct bNodeListItem { - struct bNodeListItem *next, *prev; - struct bNode *node; + struct bNodeListItem *next, *prev; + struct bNode *node; } bNodeListItem; typedef struct NodeInsertOfsData { - bNodeTree *ntree; - bNode *insert; /* inserted node */ - bNode *prev, *next; /* prev/next node in the chain */ - bNode *insert_parent; + bNodeTree *ntree; + bNode *insert; /* inserted node */ + bNode *prev, *next; /* prev/next node in the chain */ + bNode *insert_parent; - wmTimer *anim_timer; + wmTimer *anim_timer; - float offset_x; /* offset to apply to node chain */ + float offset_x; /* offset to apply to node chain */ } NodeInsertOfsData; static int sort_nodes_locx(const void *a, const void *b) { - const bNodeListItem *nli1 = a; - const bNodeListItem *nli2 = b; - const bNode *node1 = nli1->node; - const bNode *node2 = nli2->node; - - if (node1->locx > node2->locx) { - return 1; - } - else { - return 0; - } + const bNodeListItem *nli1 = a; + const bNodeListItem *nli2 = b; + const bNode *node1 = nli1->node; + const bNode *node2 = nli2->node; + + if (node1->locx > node2->locx) { + return 1; + } + else { + return 0; + } } static bool socket_is_available(bNodeTree *UNUSED(ntree), bNodeSocket *sock, const bool allow_used) { - if (nodeSocketIsHidden(sock)) { - return 0; - } + if (nodeSocketIsHidden(sock)) { + return 0; + } - if (!allow_used && (sock->flag & SOCK_IN_USE)) { - return 0; - } + if (!allow_used && (sock->flag & SOCK_IN_USE)) { + return 0; + } - return 1; + return 1; } -static bNodeSocket *best_socket_output(bNodeTree *ntree, bNode *node, bNodeSocket *sock_target, const bool allow_multiple) +static bNodeSocket *best_socket_output(bNodeTree *ntree, + bNode *node, + bNodeSocket *sock_target, + const bool allow_multiple) { - bNodeSocket *sock; - - /* first look for selected output */ - for (sock = node->outputs.first; sock; sock = sock->next) { - if (!socket_is_available(ntree, sock, allow_multiple)) { - continue; - } - - if (sock->flag & SELECT) { - return sock; - } - } - - /* try to find a socket with a matching name */ - for (sock = node->outputs.first; sock; sock = sock->next) { - if (!socket_is_available(ntree, sock, allow_multiple)) { - continue; - } - - /* check for same types */ - if (sock->type == sock_target->type) { - if (STREQ(sock->name, sock_target->name)) { - return sock; - } - } - } - - /* otherwise settle for the first available socket of the right type */ - for (sock = node->outputs.first; sock; sock = sock->next) { - - if (!socket_is_available(ntree, sock, allow_multiple)) { - continue; - } - - /* check for same types */ - if (sock->type == sock_target->type) { - return sock; - } - } - - return NULL; + bNodeSocket *sock; + + /* first look for selected output */ + for (sock = node->outputs.first; sock; sock = sock->next) { + if (!socket_is_available(ntree, sock, allow_multiple)) { + continue; + } + + if (sock->flag & SELECT) { + return sock; + } + } + + /* try to find a socket with a matching name */ + for (sock = node->outputs.first; sock; sock = sock->next) { + if (!socket_is_available(ntree, sock, allow_multiple)) { + continue; + } + + /* check for same types */ + if (sock->type == sock_target->type) { + if (STREQ(sock->name, sock_target->name)) { + return sock; + } + } + } + + /* otherwise settle for the first available socket of the right type */ + for (sock = node->outputs.first; sock; sock = sock->next) { + + if (!socket_is_available(ntree, sock, allow_multiple)) { + continue; + } + + /* check for same types */ + if (sock->type == sock_target->type) { + return sock; + } + } + + return NULL; } /* this is a bit complicated, but designed to prioritize finding * sockets of higher types, such as image, first */ static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, int replace) { - bNodeSocket *sock; - int socktype, maxtype = 0; - int a = 0; - - for (sock = node->inputs.first; sock; sock = sock->next) { - maxtype = max_ii(sock->type, maxtype); - } - - /* find sockets of higher 'types' first (i.e. image) */ - for (socktype = maxtype; socktype >= 0; socktype--) { - for (sock = node->inputs.first; sock; sock = sock->next) { - - if (!socket_is_available(ntree, sock, replace)) { - a++; - continue; - } - - if (sock->type == socktype) { - /* increment to make sure we don't keep finding - * the same socket on every attempt running this function */ - a++; - if (a > num) { - return sock; - } - } - } - } - - return NULL; + bNodeSocket *sock; + int socktype, maxtype = 0; + int a = 0; + + for (sock = node->inputs.first; sock; sock = sock->next) { + maxtype = max_ii(sock->type, maxtype); + } + + /* find sockets of higher 'types' first (i.e. image) */ + for (socktype = maxtype; socktype >= 0; socktype--) { + for (sock = node->inputs.first; sock; sock = sock->next) { + + if (!socket_is_available(ntree, sock, replace)) { + a++; + continue; + } + + if (sock->type == socktype) { + /* increment to make sure we don't keep finding + * the same socket on every attempt running this function */ + a++; + if (a > num) { + return sock; + } + } + } + } + + return NULL; } -static bool snode_autoconnect_input(SpaceNode *snode, bNode *node_fr, bNodeSocket *sock_fr, bNode *node_to, bNodeSocket *sock_to, int replace) +static bool snode_autoconnect_input(SpaceNode *snode, + bNode *node_fr, + bNodeSocket *sock_fr, + bNode *node_to, + bNodeSocket *sock_to, + int replace) { - bNodeTree *ntree = snode->edittree; + bNodeTree *ntree = snode->edittree; - /* then we can connect */ - if (replace) { - nodeRemSocketLinks(ntree, sock_to); - } + /* then we can connect */ + if (replace) { + nodeRemSocketLinks(ntree, sock_to); + } - nodeAddLink(ntree, node_fr, sock_fr, node_to, sock_to); - return true; + nodeAddLink(ntree, node_fr, sock_fr, node_to, sock_to); + return true; } -static void snode_autoconnect(Main *bmain, SpaceNode *snode, const bool allow_multiple, const bool replace) +static void snode_autoconnect(Main *bmain, + SpaceNode *snode, + const bool allow_multiple, + const bool replace) { - bNodeTree *ntree = snode->edittree; - ListBase *nodelist = MEM_callocN(sizeof(ListBase), "items_list"); - bNodeListItem *nli; - bNode *node; - int i, numlinks = 0; - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & NODE_SELECT) { - nli = MEM_mallocN(sizeof(bNodeListItem), "temporary node list item"); - nli->node = node; - BLI_addtail(nodelist, nli); - } - } - - /* sort nodes left to right */ - BLI_listbase_sort(nodelist, sort_nodes_locx); - - for (nli = nodelist->first; nli; nli = nli->next) { - bNode *node_fr, *node_to; - bNodeSocket *sock_fr, *sock_to; - bool has_selected_inputs = false; - - if (nli->next == NULL) { - break; - } - - node_fr = nli->node; - node_to = nli->next->node; - /* corner case: input/output node aligned the wrong way around (T47729) */ - if (BLI_listbase_is_empty(&node_to->inputs) || BLI_listbase_is_empty(&node_fr->outputs)) { - SWAP(bNode *, node_fr, node_to); - } - - /* if there are selected sockets, connect those */ - for (sock_to = node_to->inputs.first; sock_to; sock_to = sock_to->next) { - if (sock_to->flag & SELECT) { - has_selected_inputs = 1; - - if (!socket_is_available(ntree, sock_to, replace)) { - continue; - } - - /* check for an appropriate output socket to connect from */ - sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple); - if (!sock_fr) { - continue; - } - - if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) { - numlinks++; - } - } - } - - if (!has_selected_inputs) { - /* no selected inputs, connect by finding suitable match */ - int num_inputs = BLI_listbase_count(&node_to->inputs); - - for (i = 0; i < num_inputs; i++) { - - /* find the best guess input socket */ - sock_to = best_socket_input(ntree, node_to, i, replace); - if (!sock_to) { - continue; - } - - /* check for an appropriate output socket to connect from */ - sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple); - if (!sock_fr) { - continue; - } - - if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) { - numlinks++; - break; - } - } - } - } - - if (numlinks > 0) { - ntreeUpdateTree(bmain, ntree); - } - - BLI_freelistN(nodelist); - MEM_freeN(nodelist); + bNodeTree *ntree = snode->edittree; + ListBase *nodelist = MEM_callocN(sizeof(ListBase), "items_list"); + bNodeListItem *nli; + bNode *node; + int i, numlinks = 0; + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & NODE_SELECT) { + nli = MEM_mallocN(sizeof(bNodeListItem), "temporary node list item"); + nli->node = node; + BLI_addtail(nodelist, nli); + } + } + + /* sort nodes left to right */ + BLI_listbase_sort(nodelist, sort_nodes_locx); + + for (nli = nodelist->first; nli; nli = nli->next) { + bNode *node_fr, *node_to; + bNodeSocket *sock_fr, *sock_to; + bool has_selected_inputs = false; + + if (nli->next == NULL) { + break; + } + + node_fr = nli->node; + node_to = nli->next->node; + /* corner case: input/output node aligned the wrong way around (T47729) */ + if (BLI_listbase_is_empty(&node_to->inputs) || BLI_listbase_is_empty(&node_fr->outputs)) { + SWAP(bNode *, node_fr, node_to); + } + + /* if there are selected sockets, connect those */ + for (sock_to = node_to->inputs.first; sock_to; sock_to = sock_to->next) { + if (sock_to->flag & SELECT) { + has_selected_inputs = 1; + + if (!socket_is_available(ntree, sock_to, replace)) { + continue; + } + + /* check for an appropriate output socket to connect from */ + sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple); + if (!sock_fr) { + continue; + } + + if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) { + numlinks++; + } + } + } + + if (!has_selected_inputs) { + /* no selected inputs, connect by finding suitable match */ + int num_inputs = BLI_listbase_count(&node_to->inputs); + + for (i = 0; i < num_inputs; i++) { + + /* find the best guess input socket */ + sock_to = best_socket_input(ntree, node_to, i, replace); + if (!sock_to) { + continue; + } + + /* check for an appropriate output socket to connect from */ + sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple); + if (!sock_fr) { + continue; + } + + if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) { + numlinks++; + break; + } + } + } + } + + if (numlinks > 0) { + ntreeUpdateTree(bmain, ntree); + } + + BLI_freelistN(nodelist); + MEM_freeN(nodelist); } /* *************************** link viewer op ******************** */ static int node_link_viewer(const bContext *C, bNode *tonode) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - bNodeLink *link; - bNodeSocket *sock; - - /* context check */ - if (tonode == NULL || BLI_listbase_is_empty(&tonode->outputs)) { - return OPERATOR_CANCELLED; - } - if (ELEM(tonode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { - return OPERATOR_CANCELLED; - } - - /* get viewer */ - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { - if (node->flag & NODE_DO_OUTPUT) { - break; - } - } - } - /* no viewer, we make one active */ - if (node == NULL) { - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { - node->flag |= NODE_DO_OUTPUT; - break; - } - } - } - - sock = NULL; - - /* try to find an already connected socket to cycle to the next */ - if (node) { - link = NULL; - for (link = snode->edittree->links.first; link; link = link->next) { - if (link->tonode == node && link->fromnode == tonode) { - if (link->tosock == node->inputs.first) { - break; - } - } - } - if (link) { - /* unlink existing connection */ - sock = link->fromsock; - nodeRemLink(snode->edittree, link); - - /* find a socket after the previously connected socket */ - for (sock = sock->next; sock; sock = sock->next) { - if (!nodeSocketIsHidden(sock)) { - break; - } - } - } - } - - if (tonode) { - /* Find a selected socket that overrides the socket to connect to */ - for (bNodeSocket *sock2 = tonode->outputs.first; sock2; sock2 = sock2->next) { - if (!nodeSocketIsHidden(sock2) && sock2->flag & SELECT) { - sock = sock2; - break; - } - } - } - - - /* find a socket starting from the first socket */ - if (!sock) { - for (sock = tonode->outputs.first; sock; sock = sock->next) { - if (!nodeSocketIsHidden(sock)) { - break; - } - } - } - - if (sock) { - /* add a new viewer if none exists yet */ - if (!node) { - /* XXX location is a quick hack, just place it next to the linked socket */ - node = node_add_node(C, NULL, CMP_NODE_VIEWER, sock->locx + 100, sock->locy); - if (!node) { - return OPERATOR_CANCELLED; - } - - link = NULL; - } - else { - /* get link to viewer */ - for (link = snode->edittree->links.first; link; link = link->next) { - if (link->tonode == node && link->tosock == node->inputs.first) { - break; - } - } - } - - if (link == NULL) { - nodeAddLink(snode->edittree, tonode, sock, node, node->inputs.first); - } - else { - link->fromnode = tonode; - link->fromsock = sock; - /* make sure the dependency sorting is updated */ - snode->edittree->update |= NTREE_UPDATE_LINKS; - } - ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_update(snode, node); - } - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + bNodeLink *link; + bNodeSocket *sock; + + /* context check */ + if (tonode == NULL || BLI_listbase_is_empty(&tonode->outputs)) { + return OPERATOR_CANCELLED; + } + if (ELEM(tonode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { + return OPERATOR_CANCELLED; + } + + /* get viewer */ + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { + if (node->flag & NODE_DO_OUTPUT) { + break; + } + } + } + /* no viewer, we make one active */ + if (node == NULL) { + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { + node->flag |= NODE_DO_OUTPUT; + break; + } + } + } + + sock = NULL; + + /* try to find an already connected socket to cycle to the next */ + if (node) { + link = NULL; + for (link = snode->edittree->links.first; link; link = link->next) { + if (link->tonode == node && link->fromnode == tonode) { + if (link->tosock == node->inputs.first) { + break; + } + } + } + if (link) { + /* unlink existing connection */ + sock = link->fromsock; + nodeRemLink(snode->edittree, link); + + /* find a socket after the previously connected socket */ + for (sock = sock->next; sock; sock = sock->next) { + if (!nodeSocketIsHidden(sock)) { + break; + } + } + } + } + + if (tonode) { + /* Find a selected socket that overrides the socket to connect to */ + for (bNodeSocket *sock2 = tonode->outputs.first; sock2; sock2 = sock2->next) { + if (!nodeSocketIsHidden(sock2) && sock2->flag & SELECT) { + sock = sock2; + break; + } + } + } + + /* find a socket starting from the first socket */ + if (!sock) { + for (sock = tonode->outputs.first; sock; sock = sock->next) { + if (!nodeSocketIsHidden(sock)) { + break; + } + } + } + + if (sock) { + /* add a new viewer if none exists yet */ + if (!node) { + /* XXX location is a quick hack, just place it next to the linked socket */ + node = node_add_node(C, NULL, CMP_NODE_VIEWER, sock->locx + 100, sock->locy); + if (!node) { + return OPERATOR_CANCELLED; + } + + link = NULL; + } + else { + /* get link to viewer */ + for (link = snode->edittree->links.first; link; link = link->next) { + if (link->tonode == node && link->tosock == node->inputs.first) { + break; + } + } + } + + if (link == NULL) { + nodeAddLink(snode->edittree, tonode, sock, node, node->inputs.first); + } + else { + link->fromnode = tonode; + link->fromsock = sock; + /* make sure the dependency sorting is updated */ + snode->edittree->update |= NTREE_UPDATE_LINKS; + } + ntreeUpdateTree(CTX_data_main(C), snode->edittree); + snode_update(snode, node); + } + + return OPERATOR_FINISHED; } - static int node_active_link_viewer_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; - node = nodeGetActive(snode->edittree); + node = nodeGetActive(snode->edittree); - if (!node) { - return OPERATOR_CANCELLED; - } + if (!node) { + return OPERATOR_CANCELLED; + } - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - if (node_link_viewer(C, node) == OPERATOR_CANCELLED) { - return OPERATOR_CANCELLED; - } + if (node_link_viewer(C, node) == OPERATOR_CANCELLED) { + return OPERATOR_CANCELLED; + } - snode_notify(C, snode); + snode_notify(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } - void NODE_OT_link_viewer(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Link to Viewer Node"; - ot->description = "Link to viewer node"; - ot->idname = "NODE_OT_link_viewer"; + /* identifiers */ + ot->name = "Link to Viewer Node"; + ot->description = "Link to viewer node"; + ot->idname = "NODE_OT_link_viewer"; - /* api callbacks */ - ot->exec = node_active_link_viewer_exec; - ot->poll = composite_node_editable; + /* api callbacks */ + ot->exec = node_active_link_viewer_exec; + ot->poll = composite_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } - /* *************************** add link op ******************** */ static void node_link_update_header(bContext *C, bNodeLinkDrag *UNUSED(nldrag)) { - char header[UI_MAX_DRAW_STR]; + char header[UI_MAX_DRAW_STR]; - BLI_strncpy(header, IFACE_("LMB: drag node link, RMB: cancel"), sizeof(header)); - ED_workspace_status_text(C, header); + BLI_strncpy(header, IFACE_("LMB: drag node link, RMB: cancel"), sizeof(header)); + ED_workspace_status_text(C, header); } static int node_count_links(bNodeTree *ntree, bNodeSocket *sock) { - bNodeLink *link; - int count = 0; - for (link = ntree->links.first; link; link = link->next) { - if (link->fromsock == sock) { - ++count; - } - if (link->tosock == sock) { - ++count; - } - } - return count; + bNodeLink *link; + int count = 0; + for (link = ntree->links.first; link; link = link->next) { + if (link->fromsock == sock) { + ++count; + } + if (link->tosock == sock) { + ++count; + } + } + return count; } static void node_remove_extra_links(SpaceNode *snode, bNodeLink *link) { - bNodeTree *ntree = snode->edittree; - bNodeSocket *from = link->fromsock, *to = link->tosock; - bNodeLink *tlink, *tlink_next; - int to_count = node_count_links(ntree, to); - int from_count = node_count_links(ntree, from); - - for (tlink = ntree->links.first; tlink; tlink = tlink_next) { - tlink_next = tlink->next; - if (tlink == link) { - continue; - } - - if (tlink && tlink->fromsock == from) { - if (from_count > from->limit) { - nodeRemLink(ntree, tlink); - tlink = NULL; - --from_count; - } - } - - if (tlink && tlink->tosock == to) { - if (to_count > to->limit) { - nodeRemLink(ntree, tlink); - tlink = NULL; - --to_count; - } - } - } + bNodeTree *ntree = snode->edittree; + bNodeSocket *from = link->fromsock, *to = link->tosock; + bNodeLink *tlink, *tlink_next; + int to_count = node_count_links(ntree, to); + int from_count = node_count_links(ntree, from); + + for (tlink = ntree->links.first; tlink; tlink = tlink_next) { + tlink_next = tlink->next; + if (tlink == link) { + continue; + } + + if (tlink && tlink->fromsock == from) { + if (from_count > from->limit) { + nodeRemLink(ntree, tlink); + tlink = NULL; + --from_count; + } + } + + if (tlink && tlink->tosock == to) { + if (to_count > to->limit) { + nodeRemLink(ntree, tlink); + tlink = NULL; + --to_count; + } + } + } } static void node_link_exit(bContext *C, wmOperator *op, bool apply_links) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNodeLinkDrag *nldrag = op->customdata; - LinkData *linkdata; - bool do_tag_update = false; - - /* avoid updates while applying links */ - ntree->is_updating = true; - for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { - bNodeLink *link = linkdata->data; - - /* See note below, but basically TEST flag means that the link - * was connected to output (or to a node which affects the - * output). - */ - do_tag_update |= (link->flag & NODE_LINK_TEST) != 0; - - if (apply_links && link->tosock && link->fromsock) { - /* before actually adding the link, - * let nodes perform special link insertion handling - */ - if (link->fromnode->typeinfo->insert_link) { - link->fromnode->typeinfo->insert_link(ntree, link->fromnode, link); - } - if (link->tonode->typeinfo->insert_link) { - link->tonode->typeinfo->insert_link(ntree, link->tonode, link); - } - - /* add link to the node tree */ - BLI_addtail(&ntree->links, link); - - ntree->update |= NTREE_UPDATE_LINKS; - - /* tag tonode for update */ - link->tonode->update |= NODE_UPDATE; - - /* we might need to remove a link */ - node_remove_extra_links(snode, link); - - if (link->tonode) { - do_tag_update |= (do_tag_update || node_connected_to_output(bmain, ntree, link->tonode)); - } - } - else { - nodeRemLink(ntree, link); - } - } - ntree->is_updating = false; - - ntreeUpdateTree(bmain, ntree); - snode_notify(C, snode); - if (do_tag_update) { - snode_dag_update(C, snode); - } - - BLI_remlink(&snode->linkdrag, nldrag); - /* links->data pointers are either held by the tree or freed already */ - BLI_freelistN(&nldrag->links); - MEM_freeN(nldrag); + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNodeLinkDrag *nldrag = op->customdata; + LinkData *linkdata; + bool do_tag_update = false; + + /* avoid updates while applying links */ + ntree->is_updating = true; + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { + bNodeLink *link = linkdata->data; + + /* See note below, but basically TEST flag means that the link + * was connected to output (or to a node which affects the + * output). + */ + do_tag_update |= (link->flag & NODE_LINK_TEST) != 0; + + if (apply_links && link->tosock && link->fromsock) { + /* before actually adding the link, + * let nodes perform special link insertion handling + */ + if (link->fromnode->typeinfo->insert_link) { + link->fromnode->typeinfo->insert_link(ntree, link->fromnode, link); + } + if (link->tonode->typeinfo->insert_link) { + link->tonode->typeinfo->insert_link(ntree, link->tonode, link); + } + + /* add link to the node tree */ + BLI_addtail(&ntree->links, link); + + ntree->update |= NTREE_UPDATE_LINKS; + + /* tag tonode for update */ + link->tonode->update |= NODE_UPDATE; + + /* we might need to remove a link */ + node_remove_extra_links(snode, link); + + if (link->tonode) { + do_tag_update |= (do_tag_update || node_connected_to_output(bmain, ntree, link->tonode)); + } + } + else { + nodeRemLink(ntree, link); + } + } + ntree->is_updating = false; + + ntreeUpdateTree(bmain, ntree); + snode_notify(C, snode); + if (do_tag_update) { + snode_dag_update(C, snode); + } + + BLI_remlink(&snode->linkdrag, nldrag); + /* links->data pointers are either held by the tree or freed already */ + BLI_freelistN(&nldrag->links); + MEM_freeN(nldrag); } static void node_link_find_socket(bContext *C, wmOperator *op, float cursor[2]) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeLinkDrag *nldrag = op->customdata; - bNode *tnode; - bNodeSocket *tsock = NULL; - LinkData *linkdata; - - if (nldrag->in_out == SOCK_OUT) { - if (node_find_indicated_socket(snode, &tnode, &tsock, cursor, SOCK_IN)) { - for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { - bNodeLink *link = linkdata->data; - - /* skip if this is already the target socket */ - if (link->tosock == tsock) { - continue; - } - /* skip if socket is on the same node as the fromsock */ - if (tnode && link->fromnode == tnode) { - continue; - } - - /* attach links to the socket */ - link->tonode = tnode; - link->tosock = tsock; - } - } - else { - for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { - bNodeLink *link = linkdata->data; - - link->tonode = NULL; - link->tosock = NULL; - } - } - } - else { - if (node_find_indicated_socket(snode, &tnode, &tsock, cursor, SOCK_OUT)) { - for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { - bNodeLink *link = linkdata->data; - - /* skip if this is already the target socket */ - if (link->fromsock == tsock) { - continue; - } - /* skip if socket is on the same node as the fromsock */ - if (tnode && link->tonode == tnode) { - continue; - } - - /* attach links to the socket */ - link->fromnode = tnode; - link->fromsock = tsock; - } - } - else { - for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { - bNodeLink *link = linkdata->data; - - link->fromnode = NULL; - link->fromsock = NULL; - } - } - } + SpaceNode *snode = CTX_wm_space_node(C); + bNodeLinkDrag *nldrag = op->customdata; + bNode *tnode; + bNodeSocket *tsock = NULL; + LinkData *linkdata; + + if (nldrag->in_out == SOCK_OUT) { + if (node_find_indicated_socket(snode, &tnode, &tsock, cursor, SOCK_IN)) { + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { + bNodeLink *link = linkdata->data; + + /* skip if this is already the target socket */ + if (link->tosock == tsock) { + continue; + } + /* skip if socket is on the same node as the fromsock */ + if (tnode && link->fromnode == tnode) { + continue; + } + + /* attach links to the socket */ + link->tonode = tnode; + link->tosock = tsock; + } + } + else { + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { + bNodeLink *link = linkdata->data; + + link->tonode = NULL; + link->tosock = NULL; + } + } + } + else { + if (node_find_indicated_socket(snode, &tnode, &tsock, cursor, SOCK_OUT)) { + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { + bNodeLink *link = linkdata->data; + + /* skip if this is already the target socket */ + if (link->fromsock == tsock) { + continue; + } + /* skip if socket is on the same node as the fromsock */ + if (tnode && link->tonode == tnode) { + continue; + } + + /* attach links to the socket */ + link->fromnode = tnode; + link->fromsock = tsock; + } + } + else { + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { + bNodeLink *link = linkdata->data; + + link->fromnode = NULL; + link->fromsock = NULL; + } + } + } } /* loop that adds a nodelink, called by function below */ /* in_out = starting socket */ static int node_link_modal(bContext *C, wmOperator *op, const wmEvent *event) { - bNodeLinkDrag *nldrag = op->customdata; - ARegion *ar = CTX_wm_region(C); - float cursor[2]; - - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &cursor[0], &cursor[1]); - - switch (event->type) { - case MOUSEMOVE: - node_link_find_socket(C, op, cursor); - - node_link_update_header(C, nldrag); - ED_region_tag_redraw(ar); - break; - - case LEFTMOUSE: - case RIGHTMOUSE: - case MIDDLEMOUSE: - { - if (event->val == KM_RELEASE) { - node_link_exit(C, op, true); - - ED_workspace_status_text(C, NULL); - ED_region_tag_redraw(ar); - return OPERATOR_FINISHED; - } - break; - } - } - - return OPERATOR_RUNNING_MODAL; + bNodeLinkDrag *nldrag = op->customdata; + ARegion *ar = CTX_wm_region(C); + float cursor[2]; + + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); + + switch (event->type) { + case MOUSEMOVE: + node_link_find_socket(C, op, cursor); + + node_link_update_header(C, nldrag); + ED_region_tag_redraw(ar); + break; + + case LEFTMOUSE: + case RIGHTMOUSE: + case MIDDLEMOUSE: { + if (event->val == KM_RELEASE) { + node_link_exit(C, op, true); + + ED_workspace_status_text(C, NULL); + ED_region_tag_redraw(ar); + return OPERATOR_FINISHED; + } + break; + } + } + + return OPERATOR_RUNNING_MODAL; } /* return 1 when socket clicked */ static bNodeLinkDrag *node_link_init(Main *bmain, SpaceNode *snode, float cursor[2], bool detach) { - bNode *node; - bNodeSocket *sock; - bNodeLink *link, *link_next, *oplink; - bNodeLinkDrag *nldrag = NULL; - LinkData *linkdata; - int num_links; - - /* output indicated? */ - if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_OUT)) { - nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); - - num_links = nodeCountSocketLinks(snode->edittree, sock); - if (num_links > 0 && (num_links >= sock->limit || detach)) { - /* dragged links are fixed on input side */ - nldrag->in_out = SOCK_IN; - /* detach current links and store them in the operator data */ - for (link = snode->edittree->links.first; link; link = link_next) { - link_next = link->next; - if (link->fromsock == sock) { - linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); - linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); - *oplink = *link; - oplink->next = oplink->prev = NULL; - oplink->flag |= NODE_LINK_VALID; - - /* The link could be disconnected and in that case we - * wouldn't be able to check whether tag update is - * needed or not when releasing mouse button. So we - * cache whether the link affects output or not here - * using TEST flag. - */ - oplink->flag &= ~NODE_LINK_TEST; - if (node_connected_to_output(bmain, snode->edittree, link->tonode)) { - oplink->flag |= NODE_LINK_TEST; - } - - BLI_addtail(&nldrag->links, linkdata); - nodeRemLink(snode->edittree, link); - } - } - } - else { - /* dragged links are fixed on output side */ - nldrag->in_out = SOCK_OUT; - /* create a new link */ - linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); - linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); - oplink->fromnode = node; - oplink->fromsock = sock; - oplink->flag |= NODE_LINK_VALID; - oplink->flag &= ~NODE_LINK_TEST; - if (node_connected_to_output(bmain, snode->edittree, node)) { - oplink->flag |= NODE_LINK_TEST; - } - - BLI_addtail(&nldrag->links, linkdata); - } - } - /* or an input? */ - else if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN)) { - nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); - - num_links = nodeCountSocketLinks(snode->edittree, sock); - if (num_links > 0 && (num_links >= sock->limit || detach)) { - /* dragged links are fixed on output side */ - nldrag->in_out = SOCK_OUT; - /* detach current links and store them in the operator data */ - for (link = snode->edittree->links.first; link; link = link_next) { - link_next = link->next; - if (link->tosock == sock) { - linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); - linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); - *oplink = *link; - oplink->next = oplink->prev = NULL; - oplink->flag |= NODE_LINK_VALID; - oplink->flag &= ~NODE_LINK_TEST; - if (node_connected_to_output(bmain, snode->edittree, link->tonode)) { - oplink->flag |= NODE_LINK_TEST; - } - - BLI_addtail(&nldrag->links, linkdata); - nodeRemLink(snode->edittree, link); - - /* send changed event to original link->tonode */ - if (node) { - snode_update(snode, node); - } - } - } - } - else { - /* dragged links are fixed on input side */ - nldrag->in_out = SOCK_IN; - /* create a new link */ - linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); - linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); - oplink->tonode = node; - oplink->tosock = sock; - oplink->flag |= NODE_LINK_VALID; - oplink->flag &= ~NODE_LINK_TEST; - if (node_connected_to_output(bmain, snode->edittree, node)) { - oplink->flag |= NODE_LINK_TEST; - } - - BLI_addtail(&nldrag->links, linkdata); - } - } - - return nldrag; + bNode *node; + bNodeSocket *sock; + bNodeLink *link, *link_next, *oplink; + bNodeLinkDrag *nldrag = NULL; + LinkData *linkdata; + int num_links; + + /* output indicated? */ + if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_OUT)) { + nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); + + num_links = nodeCountSocketLinks(snode->edittree, sock); + if (num_links > 0 && (num_links >= sock->limit || detach)) { + /* dragged links are fixed on input side */ + nldrag->in_out = SOCK_IN; + /* detach current links and store them in the operator data */ + for (link = snode->edittree->links.first; link; link = link_next) { + link_next = link->next; + if (link->fromsock == sock) { + linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); + linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); + *oplink = *link; + oplink->next = oplink->prev = NULL; + oplink->flag |= NODE_LINK_VALID; + + /* The link could be disconnected and in that case we + * wouldn't be able to check whether tag update is + * needed or not when releasing mouse button. So we + * cache whether the link affects output or not here + * using TEST flag. + */ + oplink->flag &= ~NODE_LINK_TEST; + if (node_connected_to_output(bmain, snode->edittree, link->tonode)) { + oplink->flag |= NODE_LINK_TEST; + } + + BLI_addtail(&nldrag->links, linkdata); + nodeRemLink(snode->edittree, link); + } + } + } + else { + /* dragged links are fixed on output side */ + nldrag->in_out = SOCK_OUT; + /* create a new link */ + linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); + linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); + oplink->fromnode = node; + oplink->fromsock = sock; + oplink->flag |= NODE_LINK_VALID; + oplink->flag &= ~NODE_LINK_TEST; + if (node_connected_to_output(bmain, snode->edittree, node)) { + oplink->flag |= NODE_LINK_TEST; + } + + BLI_addtail(&nldrag->links, linkdata); + } + } + /* or an input? */ + else if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN)) { + nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); + + num_links = nodeCountSocketLinks(snode->edittree, sock); + if (num_links > 0 && (num_links >= sock->limit || detach)) { + /* dragged links are fixed on output side */ + nldrag->in_out = SOCK_OUT; + /* detach current links and store them in the operator data */ + for (link = snode->edittree->links.first; link; link = link_next) { + link_next = link->next; + if (link->tosock == sock) { + linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); + linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); + *oplink = *link; + oplink->next = oplink->prev = NULL; + oplink->flag |= NODE_LINK_VALID; + oplink->flag &= ~NODE_LINK_TEST; + if (node_connected_to_output(bmain, snode->edittree, link->tonode)) { + oplink->flag |= NODE_LINK_TEST; + } + + BLI_addtail(&nldrag->links, linkdata); + nodeRemLink(snode->edittree, link); + + /* send changed event to original link->tonode */ + if (node) { + snode_update(snode, node); + } + } + } + } + else { + /* dragged links are fixed on input side */ + nldrag->in_out = SOCK_IN; + /* create a new link */ + linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); + linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); + oplink->tonode = node; + oplink->tosock = sock; + oplink->flag |= NODE_LINK_VALID; + oplink->flag &= ~NODE_LINK_TEST; + if (node_connected_to_output(bmain, snode->edittree, node)) { + oplink->flag |= NODE_LINK_TEST; + } + + BLI_addtail(&nldrag->links, linkdata); + } + } + + return nldrag; } static int node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - bNodeLinkDrag *nldrag; - float cursor[2]; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + bNodeLinkDrag *nldrag; + float cursor[2]; - bool detach = RNA_boolean_get(op->ptr, "detach"); + bool detach = RNA_boolean_get(op->ptr, "detach"); - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &cursor[0], &cursor[1]); + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - nldrag = node_link_init(bmain, snode, cursor, detach); + nldrag = node_link_init(bmain, snode, cursor, detach); - if (nldrag) { - op->customdata = nldrag; - BLI_addtail(&snode->linkdrag, nldrag); + if (nldrag) { + op->customdata = nldrag; + BLI_addtail(&snode->linkdrag, nldrag); - /* add modal handler */ - WM_event_add_modal_handler(C, op); + /* add modal handler */ + WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; - } - else { - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; - } + return OPERATOR_RUNNING_MODAL; + } + else { + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + } } static void node_link_cancel(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeLinkDrag *nldrag = op->customdata; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeLinkDrag *nldrag = op->customdata; - BLI_remlink(&snode->linkdrag, nldrag); + BLI_remlink(&snode->linkdrag, nldrag); - BLI_freelistN(&nldrag->links); - MEM_freeN(nldrag); + BLI_freelistN(&nldrag->links); + MEM_freeN(nldrag); } void NODE_OT_link(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Link Nodes"; - ot->idname = "NODE_OT_link"; - ot->description = "Use the mouse to create a link between two nodes"; - - /* api callbacks */ - ot->invoke = node_link_invoke; - ot->modal = node_link_modal; -// ot->exec = node_link_exec; - ot->poll = ED_operator_node_editable; - ot->cancel = node_link_cancel; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; - - RNA_def_boolean(ot->srna, "detach", false, "Detach", "Detach and redirect existing links"); + /* identifiers */ + ot->name = "Link Nodes"; + ot->idname = "NODE_OT_link"; + ot->description = "Use the mouse to create a link between two nodes"; + + /* api callbacks */ + ot->invoke = node_link_invoke; + ot->modal = node_link_modal; + // ot->exec = node_link_exec; + ot->poll = ED_operator_node_editable; + ot->cancel = node_link_cancel; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; + + RNA_def_boolean(ot->srna, "detach", false, "Detach", "Detach and redirect existing links"); } /* ********************** Make Link operator ***************** */ @@ -966,671 +958,668 @@ void NODE_OT_link(wmOperatorType *ot) /* makes a link between selected output and input sockets */ static int node_make_link_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - const bool replace = RNA_boolean_get(op->ptr, "replace"); + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + const bool replace = RNA_boolean_get(op->ptr, "replace"); - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - snode_autoconnect(bmain, snode, 1, replace); + snode_autoconnect(bmain, snode, 1, replace); - /* deselect sockets after linking */ - node_deselect_all_input_sockets(snode, 0); - node_deselect_all_output_sockets(snode, 0); + /* deselect sockets after linking */ + node_deselect_all_input_sockets(snode, 0); + node_deselect_all_output_sockets(snode, 0); - ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); + ntreeUpdateTree(CTX_data_main(C), snode->edittree); + snode_notify(C, snode); + snode_dag_update(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_link_make(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Make Links"; - ot->description = "Makes a link between selected output in input sockets"; - ot->idname = "NODE_OT_link_make"; + /* identifiers */ + ot->name = "Make Links"; + ot->description = "Makes a link between selected output in input sockets"; + ot->idname = "NODE_OT_link_make"; - /* callbacks */ - ot->exec = node_make_link_exec; - ot->poll = ED_operator_node_editable; // XXX we need a special poll which checks that there are selected input/output sockets + /* callbacks */ + ot->exec = node_make_link_exec; + ot->poll = + ED_operator_node_editable; // XXX we need a special poll which checks that there are selected input/output sockets - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_boolean(ot->srna, "replace", 0, "Replace", "Replace socket connections with the new links"); + RNA_def_boolean( + ot->srna, "replace", 0, "Replace", "Replace socket connections with the new links"); } /* ********************** Cut Link operator ***************** */ static bool cut_links_intersect(bNodeLink *link, float mcoords[][2], int tot) { - float coord_array[NODE_LINK_RESOL + 1][2]; - int i, b; - - if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { - - for (i = 0; i < tot - 1; i++) { - for (b = 0; b < NODE_LINK_RESOL; b++) { - if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { - return 1; - } - } - } - } - return 0; + float coord_array[NODE_LINK_RESOL + 1][2]; + int i, b; + + if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { + + for (i = 0; i < tot - 1; i++) { + for (b = 0; b < NODE_LINK_RESOL; b++) { + if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { + return 1; + } + } + } + } + return 0; } static int cut_links_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - float mcoords[256][2]; - int i = 0; - bool do_tag_update = false; - - RNA_BEGIN (op->ptr, itemptr, "path") - { - float loc[2]; - - RNA_float_get_array(&itemptr, "loc", loc); - UI_view2d_region_to_view(&ar->v2d, (int)loc[0], (int)loc[1], - &mcoords[i][0], &mcoords[i][1]); - i++; - if (i >= 256) { - break; - } - } - RNA_END; - - if (i > 1) { - bool found = false; - bNodeLink *link, *next; - - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - - for (link = snode->edittree->links.first; link; link = next) { - next = link->next; - if (nodeLinkIsHidden(link)) { - continue; - } - - if (cut_links_intersect(link, mcoords, i)) { - - if (found == false) { - /* TODO(sergey): Why did we kill jobs twice? */ - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); - found = true; - } - - do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, link->tonode)); - - snode_update(snode, link->tonode); - nodeRemLink(snode->edittree, link); - } - } - - if (found) { - ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); - if (do_tag_update) { - snode_dag_update(C, snode); - } - - return OPERATOR_FINISHED; - } - else { - return OPERATOR_CANCELLED; - } - - } - - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + float mcoords[256][2]; + int i = 0; + bool do_tag_update = false; + + RNA_BEGIN (op->ptr, itemptr, "path") { + float loc[2]; + + RNA_float_get_array(&itemptr, "loc", loc); + UI_view2d_region_to_view(&ar->v2d, (int)loc[0], (int)loc[1], &mcoords[i][0], &mcoords[i][1]); + i++; + if (i >= 256) { + break; + } + } + RNA_END; + + if (i > 1) { + bool found = false; + bNodeLink *link, *next; + + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + + for (link = snode->edittree->links.first; link; link = next) { + next = link->next; + if (nodeLinkIsHidden(link)) { + continue; + } + + if (cut_links_intersect(link, mcoords, i)) { + + if (found == false) { + /* TODO(sergey): Why did we kill jobs twice? */ + ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + found = true; + } + + do_tag_update |= (do_tag_update || + node_connected_to_output(bmain, snode->edittree, link->tonode)); + + snode_update(snode, link->tonode); + nodeRemLink(snode->edittree, link); + } + } + + if (found) { + ntreeUpdateTree(CTX_data_main(C), snode->edittree); + snode_notify(C, snode); + if (do_tag_update) { + snode_dag_update(C, snode); + } + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } + } + + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; } void NODE_OT_links_cut(wmOperatorType *ot) { - ot->name = "Cut Links"; - ot->idname = "NODE_OT_links_cut"; - ot->description = "Use the mouse to cut (remove) some links"; + ot->name = "Cut Links"; + ot->idname = "NODE_OT_links_cut"; + ot->description = "Use the mouse to cut (remove) some links"; - ot->invoke = WM_gesture_lines_invoke; - ot->modal = WM_gesture_lines_modal; - ot->exec = cut_links_exec; - ot->cancel = WM_gesture_lines_cancel; + ot->invoke = WM_gesture_lines_invoke; + ot->modal = WM_gesture_lines_modal; + ot->exec = cut_links_exec; + ot->cancel = WM_gesture_lines_cancel; - ot->poll = ED_operator_node_editable; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* properties */ - PropertyRNA *prop; - prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", ""); - RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); + /* properties */ + PropertyRNA *prop; + prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", ""); + RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); - /* internal */ - RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); + /* internal */ + RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); } /* ********************** Detach links operator ***************** */ static int detach_links_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *node; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *node; - ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); + ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - nodeInternalRelink(ntree, node); - } - } + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + nodeInternalRelink(ntree, node); + } + } - ntreeUpdateTree(CTX_data_main(C), ntree); + ntreeUpdateTree(CTX_data_main(C), ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(C, snode); + snode_dag_update(C, snode); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_links_detach(wmOperatorType *ot) { - ot->name = "Detach Links"; - ot->idname = "NODE_OT_links_detach"; - ot->description = "Remove all links to selected nodes, and try to connect neighbor nodes together"; + ot->name = "Detach Links"; + ot->idname = "NODE_OT_links_detach"; + ot->description = + "Remove all links to selected nodes, and try to connect neighbor nodes together"; - ot->exec = detach_links_exec; - ot->poll = ED_operator_node_editable; + ot->exec = detach_links_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } - /* ****************** Set Parent ******************* */ static int node_parent_set_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *frame = nodeGetActive(ntree), *node; - if (!frame || frame->type != NODE_FRAME) { - return OPERATOR_CANCELLED; - } - - for (node = ntree->nodes.first; node; node = node->next) { - if (node == frame) { - continue; - } - if (node->flag & NODE_SELECT) { - nodeDetachNode(node); - nodeAttachNode(node, frame); - } - } - - ED_node_sort(ntree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *frame = nodeGetActive(ntree), *node; + if (!frame || frame->type != NODE_FRAME) { + return OPERATOR_CANCELLED; + } + + for (node = ntree->nodes.first; node; node = node->next) { + if (node == frame) { + continue; + } + if (node->flag & NODE_SELECT) { + nodeDetachNode(node); + nodeAttachNode(node, frame); + } + } + + ED_node_sort(ntree); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; } void NODE_OT_parent_set(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Make Parent"; - ot->description = "Attach selected nodes"; - ot->idname = "NODE_OT_parent_set"; + /* identifiers */ + ot->name = "Make Parent"; + ot->description = "Attach selected nodes"; + ot->idname = "NODE_OT_parent_set"; - /* api callbacks */ - ot->exec = node_parent_set_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = node_parent_set_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Join Nodes ******************* */ /* tags for depth-first search */ -#define NODE_JOIN_DONE 1 +#define NODE_JOIN_DONE 1 #define NODE_JOIN_IS_DESCENDANT 2 static void node_join_attach_recursive(bNode *node, bNode *frame) { - node->done |= NODE_JOIN_DONE; - - if (node == frame) { - node->done |= NODE_JOIN_IS_DESCENDANT; - } - else if (node->parent) { - /* call recursively */ - if (!(node->parent->done & NODE_JOIN_DONE)) { - node_join_attach_recursive(node->parent, frame); - } - - /* in any case: if the parent is a descendant, so is the child */ - if (node->parent->done & NODE_JOIN_IS_DESCENDANT) { - node->done |= NODE_JOIN_IS_DESCENDANT; - } - else if (node->flag & NODE_TEST) { - /* if parent is not an descendant of the frame, reattach the node */ - nodeDetachNode(node); - nodeAttachNode(node, frame); - node->done |= NODE_JOIN_IS_DESCENDANT; - } - } - else if (node->flag & NODE_TEST) { - nodeAttachNode(node, frame); - node->done |= NODE_JOIN_IS_DESCENDANT; - } + node->done |= NODE_JOIN_DONE; + + if (node == frame) { + node->done |= NODE_JOIN_IS_DESCENDANT; + } + else if (node->parent) { + /* call recursively */ + if (!(node->parent->done & NODE_JOIN_DONE)) { + node_join_attach_recursive(node->parent, frame); + } + + /* in any case: if the parent is a descendant, so is the child */ + if (node->parent->done & NODE_JOIN_IS_DESCENDANT) { + node->done |= NODE_JOIN_IS_DESCENDANT; + } + else if (node->flag & NODE_TEST) { + /* if parent is not an descendant of the frame, reattach the node */ + nodeDetachNode(node); + nodeAttachNode(node, frame); + node->done |= NODE_JOIN_IS_DESCENDANT; + } + } + else if (node->flag & NODE_TEST) { + nodeAttachNode(node, frame); + node->done |= NODE_JOIN_IS_DESCENDANT; + } } static int node_join_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *node, *frame; - - /* XXX save selection: node_add_node call below sets the new frame as single - * active+selected node */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & NODE_SELECT) { - node->flag |= NODE_TEST; - } - else { - node->flag &= ~NODE_TEST; - } - } - - frame = node_add_node(C, NULL, NODE_FRAME, 0.0f, 0.0f); - - /* reset tags */ - for (node = ntree->nodes.first; node; node = node->next) { - node->done = 0; - } - - for (node = ntree->nodes.first; node; node = node->next) { - if (!(node->done & NODE_JOIN_DONE)) { - node_join_attach_recursive(node, frame); - } - } - - /* restore selection */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & NODE_TEST) { - node->flag |= NODE_SELECT; - } - } - - ED_node_sort(ntree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *node, *frame; + + /* XXX save selection: node_add_node call below sets the new frame as single + * active+selected node */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & NODE_SELECT) { + node->flag |= NODE_TEST; + } + else { + node->flag &= ~NODE_TEST; + } + } + + frame = node_add_node(C, NULL, NODE_FRAME, 0.0f, 0.0f); + + /* reset tags */ + for (node = ntree->nodes.first; node; node = node->next) { + node->done = 0; + } + + for (node = ntree->nodes.first; node; node = node->next) { + if (!(node->done & NODE_JOIN_DONE)) { + node_join_attach_recursive(node, frame); + } + } + + /* restore selection */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & NODE_TEST) { + node->flag |= NODE_SELECT; + } + } + + ED_node_sort(ntree); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; } void NODE_OT_join(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Join Nodes"; - ot->description = "Attach selected nodes to a new common frame"; - ot->idname = "NODE_OT_join"; + /* identifiers */ + ot->name = "Join Nodes"; + ot->description = "Attach selected nodes to a new common frame"; + ot->idname = "NODE_OT_join"; - /* api callbacks */ - ot->exec = node_join_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = node_join_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Attach ******************* */ static bNode *node_find_frame_to_attach(ARegion *ar, const bNodeTree *ntree, const int mouse_xy[2]) { - bNode *frame; - float cursor[2]; - - /* convert mouse coordinates to v2d space */ - UI_view2d_region_to_view(&ar->v2d, UNPACK2(mouse_xy), &cursor[0], &cursor[1]); - - /* check nodes front to back */ - for (frame = ntree->nodes.last; frame; frame = frame->prev) { - /* skip selected, those are the nodes we want to attach */ - if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT)) { - continue; - } - if (BLI_rctf_isect_pt_v(&frame->totr, cursor)) { - return frame; - } - } - - return NULL; + bNode *frame; + float cursor[2]; + + /* convert mouse coordinates to v2d space */ + UI_view2d_region_to_view(&ar->v2d, UNPACK2(mouse_xy), &cursor[0], &cursor[1]); + + /* check nodes front to back */ + for (frame = ntree->nodes.last; frame; frame = frame->prev) { + /* skip selected, those are the nodes we want to attach */ + if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT)) { + continue; + } + if (BLI_rctf_isect_pt_v(&frame->totr, cursor)) { + return frame; + } + } + + return NULL; } static int node_attach_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { - ARegion *ar = CTX_wm_region(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *frame = node_find_frame_to_attach(ar, ntree, event->mval); - - if (frame) { - bNode *node, *parent; - for (node = ntree->nodes.last; node; node = node->prev) { - if (node->flag & NODE_SELECT) { - if (node->parent == NULL) { - /* disallow moving a parent into its child */ - if (nodeAttachNodeCheck(frame, node) == false) { - /* attach all unparented nodes */ - nodeAttachNode(node, frame); - } - } - else { - /* attach nodes which share parent with the frame */ - for (parent = frame->parent; parent; parent = parent->parent) { - if (parent == node->parent) { - break; - } - } - - if (parent) { - /* disallow moving a parent into its child */ - if (nodeAttachNodeCheck(frame, node) == false) { - nodeDetachNode(node); - nodeAttachNode(node, frame); - } - } - } - } - } - } - - ED_node_sort(ntree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *frame = node_find_frame_to_attach(ar, ntree, event->mval); + + if (frame) { + bNode *node, *parent; + for (node = ntree->nodes.last; node; node = node->prev) { + if (node->flag & NODE_SELECT) { + if (node->parent == NULL) { + /* disallow moving a parent into its child */ + if (nodeAttachNodeCheck(frame, node) == false) { + /* attach all unparented nodes */ + nodeAttachNode(node, frame); + } + } + else { + /* attach nodes which share parent with the frame */ + for (parent = frame->parent; parent; parent = parent->parent) { + if (parent == node->parent) { + break; + } + } + + if (parent) { + /* disallow moving a parent into its child */ + if (nodeAttachNodeCheck(frame, node) == false) { + nodeDetachNode(node); + nodeAttachNode(node, frame); + } + } + } + } + } + } + + ED_node_sort(ntree); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; } - void NODE_OT_attach(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Attach Nodes"; - ot->description = "Attach active node to a frame"; - ot->idname = "NODE_OT_attach"; + /* identifiers */ + ot->name = "Attach Nodes"; + ot->description = "Attach active node to a frame"; + ot->idname = "NODE_OT_attach"; - /* api callbacks */ + /* api callbacks */ - ot->invoke = node_attach_invoke; - ot->poll = ED_operator_node_editable; + ot->invoke = node_attach_invoke; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****************** Detach ******************* */ /* tags for depth-first search */ -#define NODE_DETACH_DONE 1 -#define NODE_DETACH_IS_DESCENDANT 2 +#define NODE_DETACH_DONE 1 +#define NODE_DETACH_IS_DESCENDANT 2 static void node_detach_recursive(bNode *node) { - node->done |= NODE_DETACH_DONE; - - if (node->parent) { - /* call recursively */ - if (!(node->parent->done & NODE_DETACH_DONE)) { - node_detach_recursive(node->parent); - } - - /* in any case: if the parent is a descendant, so is the child */ - if (node->parent->done & NODE_DETACH_IS_DESCENDANT) { - node->done |= NODE_DETACH_IS_DESCENDANT; - } - else if (node->flag & NODE_SELECT) { - /* if parent is not a descendant of a selected node, detach */ - nodeDetachNode(node); - node->done |= NODE_DETACH_IS_DESCENDANT; - } - } - else if (node->flag & NODE_SELECT) { - node->done |= NODE_DETACH_IS_DESCENDANT; - } + node->done |= NODE_DETACH_DONE; + + if (node->parent) { + /* call recursively */ + if (!(node->parent->done & NODE_DETACH_DONE)) { + node_detach_recursive(node->parent); + } + + /* in any case: if the parent is a descendant, so is the child */ + if (node->parent->done & NODE_DETACH_IS_DESCENDANT) { + node->done |= NODE_DETACH_IS_DESCENDANT; + } + else if (node->flag & NODE_SELECT) { + /* if parent is not a descendant of a selected node, detach */ + nodeDetachNode(node); + node->done |= NODE_DETACH_IS_DESCENDANT; + } + } + else if (node->flag & NODE_SELECT) { + node->done |= NODE_DETACH_IS_DESCENDANT; + } } - /* detach the root nodes in the current selection */ static int node_detach_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *node; - - /* reset tags */ - for (node = ntree->nodes.first; node; node = node->next) { - node->done = 0; - } - /* detach nodes recursively - * relative order is preserved here! - */ - for (node = ntree->nodes.first; node; node = node->next) { - if (!(node->done & NODE_DETACH_DONE)) { - node_detach_recursive(node); - } - } - - ED_node_sort(ntree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *node; + + /* reset tags */ + for (node = ntree->nodes.first; node; node = node->next) { + node->done = 0; + } + /* detach nodes recursively + * relative order is preserved here! + */ + for (node = ntree->nodes.first; node; node = node->next) { + if (!(node->done & NODE_DETACH_DONE)) { + node_detach_recursive(node); + } + } + + ED_node_sort(ntree); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; } void NODE_OT_detach(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Detach Nodes"; - ot->description = "Detach selected nodes from parents"; - ot->idname = "NODE_OT_detach"; + /* identifiers */ + ot->name = "Detach Nodes"; + ot->description = "Detach selected nodes from parents"; + ot->idname = "NODE_OT_detach"; - /* api callbacks */ - ot->exec = node_detach_exec; - ot->poll = ED_operator_node_editable; + /* api callbacks */ + ot->exec = node_detach_exec; + ot->poll = ED_operator_node_editable; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ********************* automatic node insert on dragging ******************* */ - /* prevent duplicate testing code below */ static bool ed_node_link_conditions(ScrArea *sa, bool test, SpaceNode **r_snode, bNode **r_select) { - SpaceNode *snode = sa ? sa->spacedata.first : NULL; - bNode *node, *select = NULL; - bNodeLink *link; - - *r_snode = snode; - *r_select = NULL; - - /* no unlucky accidents */ - if (sa == NULL || sa->spacetype != SPACE_NODE) { - return false; - } - - if (!test) { - /* no need to look for a node */ - return true; - } - - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - if (select) { - break; - } - else { - select = node; - } - } - } - /* only one selected */ - if (node || select == NULL) { - return false; - } - - /* correct node */ - if (BLI_listbase_is_empty(&select->inputs) || BLI_listbase_is_empty(&select->outputs)) { - return false; - } - - /* test node for links */ - for (link = snode->edittree->links.first; link; link = link->next) { - if (nodeLinkIsHidden(link)) { - continue; - } - - if (link->tonode == select || link->fromnode == select) { - return false; - } - } - - *r_select = select; - return true; + SpaceNode *snode = sa ? sa->spacedata.first : NULL; + bNode *node, *select = NULL; + bNodeLink *link; + + *r_snode = snode; + *r_select = NULL; + + /* no unlucky accidents */ + if (sa == NULL || sa->spacetype != SPACE_NODE) { + return false; + } + + if (!test) { + /* no need to look for a node */ + return true; + } + + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + if (select) { + break; + } + else { + select = node; + } + } + } + /* only one selected */ + if (node || select == NULL) { + return false; + } + + /* correct node */ + if (BLI_listbase_is_empty(&select->inputs) || BLI_listbase_is_empty(&select->outputs)) { + return false; + } + + /* test node for links */ + for (link = snode->edittree->links.first; link; link = link->next) { + if (nodeLinkIsHidden(link)) { + continue; + } + + if (link->tonode == select || link->fromnode == select) { + return false; + } + } + + *r_select = select; + return true; } /* test == 0, clear all intersect flags */ void ED_node_link_intersect_test(ScrArea *sa, int test) { - bNode *select; - SpaceNode *snode; - bNodeLink *link, *selink = NULL; - float dist_best = FLT_MAX; - - if (!ed_node_link_conditions(sa, test, &snode, &select)) { - return; - } - - /* clear flags */ - for (link = snode->edittree->links.first; link; link = link->next) { - link->flag &= ~NODE_LINKFLAG_HILITE; - } - - if (test == 0) { - return; - } - - /* find link to select/highlight */ - for (link = snode->edittree->links.first; link; link = link->next) { - float coord_array[NODE_LINK_RESOL + 1][2]; - - if (nodeLinkIsHidden(link)) { - continue; - } - - if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { - float dist = FLT_MAX; - int i; - - /* loop over link coords to find shortest dist to - * upper left node edge of a intersected line segment */ - for (i = 0; i < NODE_LINK_RESOL; i++) { - /* check if the node rect intersetcts the line from this point to next one */ - if (BLI_rctf_isect_segment(&select->totr, coord_array[i], coord_array[i + 1])) { - /* store the shortest distance to the upper left edge - * of all intersections found so far */ - const float node_xy[] = {select->totr.xmin, select->totr.ymax}; - - /* to be precise coord_array should be clipped by select->totr, - * but not done since there's no real noticeable difference */ - dist = min_ff(dist_squared_to_line_segment_v2(node_xy, coord_array[i], coord_array[i + 1]), - dist); - } - } - - /* we want the link with the shortest distance to node center */ - if (dist < dist_best) { - dist_best = dist; - selink = link; - } - } - } - - if (selink) { - selink->flag |= NODE_LINKFLAG_HILITE; - } + bNode *select; + SpaceNode *snode; + bNodeLink *link, *selink = NULL; + float dist_best = FLT_MAX; + + if (!ed_node_link_conditions(sa, test, &snode, &select)) { + return; + } + + /* clear flags */ + for (link = snode->edittree->links.first; link; link = link->next) { + link->flag &= ~NODE_LINKFLAG_HILITE; + } + + if (test == 0) { + return; + } + + /* find link to select/highlight */ + for (link = snode->edittree->links.first; link; link = link->next) { + float coord_array[NODE_LINK_RESOL + 1][2]; + + if (nodeLinkIsHidden(link)) { + continue; + } + + if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { + float dist = FLT_MAX; + int i; + + /* loop over link coords to find shortest dist to + * upper left node edge of a intersected line segment */ + for (i = 0; i < NODE_LINK_RESOL; i++) { + /* check if the node rect intersetcts the line from this point to next one */ + if (BLI_rctf_isect_segment(&select->totr, coord_array[i], coord_array[i + 1])) { + /* store the shortest distance to the upper left edge + * of all intersections found so far */ + const float node_xy[] = {select->totr.xmin, select->totr.ymax}; + + /* to be precise coord_array should be clipped by select->totr, + * but not done since there's no real noticeable difference */ + dist = min_ff( + dist_squared_to_line_segment_v2(node_xy, coord_array[i], coord_array[i + 1]), dist); + } + } + + /* we want the link with the shortest distance to node center */ + if (dist < dist_best) { + dist_best = dist; + selink = link; + } + } + } + + if (selink) { + selink->flag |= NODE_LINKFLAG_HILITE; + } } /* assumes sockets in list */ static bNodeSocket *socket_best_match(ListBase *sockets) { - bNodeSocket *sock; - int type, maxtype = 0; - - /* find type range */ - for (sock = sockets->first; sock; sock = sock->next) { - maxtype = max_ii(sock->type, maxtype); - } - - /* try all types, starting from 'highest' (i.e. colors, vectors, values) */ - for (type = maxtype; type >= 0; --type) { - for (sock = sockets->first; sock; sock = sock->next) { - if (!nodeSocketIsHidden(sock) && type == sock->type) { - return sock; - } - } - } - - /* no visible sockets, unhide first of highest type */ - for (type = maxtype; type >= 0; --type) { - for (sock = sockets->first; sock; sock = sock->next) { - if (type == sock->type) { - sock->flag &= ~SOCK_HIDDEN; - return sock; - } - } - } - - return NULL; + bNodeSocket *sock; + int type, maxtype = 0; + + /* find type range */ + for (sock = sockets->first; sock; sock = sock->next) { + maxtype = max_ii(sock->type, maxtype); + } + + /* try all types, starting from 'highest' (i.e. colors, vectors, values) */ + for (type = maxtype; type >= 0; --type) { + for (sock = sockets->first; sock; sock = sock->next) { + if (!nodeSocketIsHidden(sock) && type == sock->type) { + return sock; + } + } + } + + /* no visible sockets, unhide first of highest type */ + for (type = maxtype; type >= 0; --type) { + for (sock = sockets->first; sock; sock = sock->next) { + if (type == sock->type) { + sock->flag &= ~SOCK_HIDDEN; + return sock; + } + } + } + + return NULL; } static bool node_parents_offset_flag_enable_cb(bNode *parent, void *UNUSED(userdata)) { - /* NODE_TEST is used to flag nodes that shouldn't be offset (again) */ - parent->flag |= NODE_TEST; + /* NODE_TEST is used to flag nodes that shouldn't be offset (again) */ + parent->flag |= NODE_TEST; - return true; + return true; } static void node_offset_apply(bNode *node, const float offset_x) { - /* NODE_TEST is used to flag nodes that shouldn't be offset (again) */ - if ((node->flag & NODE_TEST) == 0) { - node->anim_init_locx = node->locx; - node->anim_ofsx = (offset_x / UI_DPI_FAC); - node->flag |= NODE_TEST; - } + /* NODE_TEST is used to flag nodes that shouldn't be offset (again) */ + if ((node->flag & NODE_TEST) == 0) { + node->anim_init_locx = node->locx; + node->anim_ofsx = (offset_x / UI_DPI_FAC); + node->flag |= NODE_TEST; + } } static void node_parent_offset_apply(NodeInsertOfsData *data, bNode *parent, const float offset_x) { - bNode *node; - - node_offset_apply(parent, offset_x); - - /* flag all childs as offset to prevent them from being offset - * separately (they've already moved with the parent) */ - for (node = data->ntree->nodes.first; node; node = node->next) { - if (nodeIsChildOf(parent, node)) { - /* NODE_TEST is used to flag nodes that shouldn't be offset (again) */ - node->flag |= NODE_TEST; - } - } + bNode *node; + + node_offset_apply(parent, offset_x); + + /* flag all childs as offset to prevent them from being offset + * separately (they've already moved with the parent) */ + for (node = data->ntree->nodes.first; node; node = node->next) { + if (nodeIsChildOf(parent, node)) { + /* NODE_TEST is used to flag nodes that shouldn't be offset (again) */ + node->flag |= NODE_TEST; + } + } } #define NODE_INSOFS_ANIM_DURATION 0.25f @@ -1639,193 +1628,190 @@ static void node_parent_offset_apply(NodeInsertOfsData *data, bNode *parent, con * Callback that applies NodeInsertOfsData.offset_x to a node or its parent, similar * to node_link_insert_offset_output_chain_cb below, but with slightly different logic */ -static bool node_link_insert_offset_frame_chain_cb( - bNode *fromnode, bNode *tonode, - void *userdata, - const bool reversed) +static bool node_link_insert_offset_frame_chain_cb(bNode *fromnode, + bNode *tonode, + void *userdata, + const bool reversed) { - NodeInsertOfsData *data = userdata; - bNode *ofs_node = reversed ? fromnode : tonode; + NodeInsertOfsData *data = userdata; + bNode *ofs_node = reversed ? fromnode : tonode; - if (ofs_node->parent && ofs_node->parent != data->insert_parent) { - node_offset_apply(ofs_node->parent, data->offset_x); - } - else { - node_offset_apply(ofs_node, data->offset_x); - } + if (ofs_node->parent && ofs_node->parent != data->insert_parent) { + node_offset_apply(ofs_node->parent, data->offset_x); + } + else { + node_offset_apply(ofs_node, data->offset_x); + } - return true; + return true; } /** * Applies NodeInsertOfsData.offset_x to all childs of \a parent */ -static void node_link_insert_offset_frame_chains( - const bNodeTree *ntree, const bNode *parent, - NodeInsertOfsData *data, - const bool reversed) +static void node_link_insert_offset_frame_chains(const bNodeTree *ntree, + const bNode *parent, + NodeInsertOfsData *data, + const bool reversed) { - bNode *node; + bNode *node; - for (node = ntree->nodes.first; node; node = node->next) { - if (nodeIsChildOf(parent, node)) { - nodeChainIter(ntree, node, node_link_insert_offset_frame_chain_cb, data, reversed); - } - } + for (node = ntree->nodes.first; node; node = node->next) { + if (nodeIsChildOf(parent, node)) { + nodeChainIter(ntree, node, node_link_insert_offset_frame_chain_cb, data, reversed); + } + } } /** * Callback that applies NodeInsertOfsData.offset_x to a node or its parent, * considering the logic needed for offsetting nodes after link insert */ -static bool node_link_insert_offset_chain_cb( - bNode *fromnode, bNode *tonode, - void *userdata, - const bool reversed) +static bool node_link_insert_offset_chain_cb(bNode *fromnode, + bNode *tonode, + void *userdata, + const bool reversed) { - NodeInsertOfsData *data = userdata; - bNode *ofs_node = reversed ? fromnode : tonode; - - if (data->insert_parent) { - if (ofs_node->parent && (ofs_node->parent->flag & NODE_TEST) == 0) { - node_parent_offset_apply(data, ofs_node->parent, data->offset_x); - node_link_insert_offset_frame_chains(data->ntree, ofs_node->parent, data, reversed); - } - else { - node_offset_apply(ofs_node, data->offset_x); - } - - if (nodeIsChildOf(data->insert_parent, ofs_node) == false) { - data->insert_parent = NULL; - } - } - else if (ofs_node->parent) { - bNode *node = nodeFindRootParent(ofs_node); - node_offset_apply(node, data->offset_x); - } - else { - node_offset_apply(ofs_node, data->offset_x); - } - - return true; + NodeInsertOfsData *data = userdata; + bNode *ofs_node = reversed ? fromnode : tonode; + + if (data->insert_parent) { + if (ofs_node->parent && (ofs_node->parent->flag & NODE_TEST) == 0) { + node_parent_offset_apply(data, ofs_node->parent, data->offset_x); + node_link_insert_offset_frame_chains(data->ntree, ofs_node->parent, data, reversed); + } + else { + node_offset_apply(ofs_node, data->offset_x); + } + + if (nodeIsChildOf(data->insert_parent, ofs_node) == false) { + data->insert_parent = NULL; + } + } + else if (ofs_node->parent) { + bNode *node = nodeFindRootParent(ofs_node); + node_offset_apply(node, data->offset_x); + } + else { + node_offset_apply(ofs_node, data->offset_x); + } + + return true; } -static void node_link_insert_offset_ntree( - NodeInsertOfsData *iofsd, ARegion *ar, - const int mouse_xy[2], const bool right_alignment) +static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, + ARegion *ar, + const int mouse_xy[2], + const bool right_alignment) { - bNodeTree *ntree = iofsd->ntree; - bNode *insert = iofsd->insert; - bNode *prev = iofsd->prev, *next = iofsd->next; - bNode *init_parent = insert->parent; /* store old insert->parent for restoring later */ - rctf totr_insert; - - const float min_margin = U.node_margin * UI_DPI_FAC; - const float width = NODE_WIDTH(insert); - const bool needs_alignment = (next->totr.xmin - prev->totr.xmax) < (width + (min_margin * 2.0f)); - - float margin = width; - float dist, addval; - - - /* NODE_TEST will be used later, so disable for all nodes */ - ntreeNodeFlagSet(ntree, NODE_TEST, false); - - /* insert->totr isn't updated yet, - * so totr_insert is used to get the correct worldspace coords */ - node_to_updated_rect(insert, &totr_insert); - - /* frame attachment wasn't handled yet - * so we search the frame that the node will be attached to later */ - insert->parent = node_find_frame_to_attach(ar, ntree, mouse_xy); - - /* this makes sure nodes are also correctly offset when inserting a node on top of a frame - * without actually making it a part of the frame (because mouse isn't intersecting it) - * - logic here is similar to node_find_frame_to_attach */ - if (!insert->parent || - (prev->parent && (prev->parent == next->parent) && (prev->parent != insert->parent))) - { - bNode *frame; - rctf totr_frame; - - /* check nodes front to back */ - for (frame = ntree->nodes.last; frame; frame = frame->prev) { - /* skip selected, those are the nodes we want to attach */ - if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT)) { - continue; - } - - /* for some reason frame y coords aren't correct yet */ - node_to_updated_rect(frame, &totr_frame); - - if (BLI_rctf_isect_x(&totr_frame, totr_insert.xmin) && - BLI_rctf_isect_x(&totr_frame, totr_insert.xmax)) - { - if (BLI_rctf_isect_y(&totr_frame, totr_insert.ymin) || - BLI_rctf_isect_y(&totr_frame, totr_insert.ymax)) - { - /* frame isn't insert->parent actually, but this is needed to make offsetting - * nodes work correctly for above checked cases (it is restored later) */ - insert->parent = frame; - break; - } - } - } - } - - - /* *** ensure offset at the left (or right for right_alignment case) of insert_node *** */ - - dist = right_alignment ? totr_insert.xmin - prev->totr.xmax : next->totr.xmin - totr_insert.xmax; - /* distance between insert_node and prev is smaller than min margin */ - if (dist < min_margin) { - addval = (min_margin - dist) * (right_alignment ? 1.0f : -1.0f); - - node_offset_apply(insert, addval); - - totr_insert.xmin += addval; - totr_insert.xmax += addval; - margin += min_margin; - } - - /* *** ensure offset at the right (or left for right_alignment case) of insert_node *** */ - - dist = right_alignment ? next->totr.xmin - totr_insert.xmax : totr_insert.xmin - prev->totr.xmax; - /* distance between insert_node and next is smaller than min margin */ - if (dist < min_margin) { - addval = (min_margin - dist) * (right_alignment ? 1.0f : -1.0f); - if (needs_alignment) { - bNode *offs_node = right_alignment ? next : prev; - if (!offs_node->parent || - offs_node->parent == insert->parent || - nodeIsChildOf(offs_node->parent, insert)) - { - node_offset_apply(offs_node, addval); - } - else if (!insert->parent && offs_node->parent) { - node_offset_apply(nodeFindRootParent(offs_node), addval); - } - margin = addval; - } - /* enough room is available, but we want to ensure the min margin at the right */ - else { - /* offset inserted node so that min margin is kept at the right */ - node_offset_apply(insert, -addval); - } - } - - - if (needs_alignment) { - iofsd->insert_parent = insert->parent; - iofsd->offset_x = margin; - - /* flag all parents of insert as offset to prevent them from being offset */ - nodeParentsIter(insert, node_parents_offset_flag_enable_cb, NULL); - /* iterate over entire chain and apply offsets */ - nodeChainIter(ntree, right_alignment ? next : prev, node_link_insert_offset_chain_cb, iofsd, !right_alignment); - } - - insert->parent = init_parent; + bNodeTree *ntree = iofsd->ntree; + bNode *insert = iofsd->insert; + bNode *prev = iofsd->prev, *next = iofsd->next; + bNode *init_parent = insert->parent; /* store old insert->parent for restoring later */ + rctf totr_insert; + + const float min_margin = U.node_margin * UI_DPI_FAC; + const float width = NODE_WIDTH(insert); + const bool needs_alignment = (next->totr.xmin - prev->totr.xmax) < (width + (min_margin * 2.0f)); + + float margin = width; + float dist, addval; + + /* NODE_TEST will be used later, so disable for all nodes */ + ntreeNodeFlagSet(ntree, NODE_TEST, false); + + /* insert->totr isn't updated yet, + * so totr_insert is used to get the correct worldspace coords */ + node_to_updated_rect(insert, &totr_insert); + + /* frame attachment wasn't handled yet + * so we search the frame that the node will be attached to later */ + insert->parent = node_find_frame_to_attach(ar, ntree, mouse_xy); + + /* this makes sure nodes are also correctly offset when inserting a node on top of a frame + * without actually making it a part of the frame (because mouse isn't intersecting it) + * - logic here is similar to node_find_frame_to_attach */ + if (!insert->parent || + (prev->parent && (prev->parent == next->parent) && (prev->parent != insert->parent))) { + bNode *frame; + rctf totr_frame; + + /* check nodes front to back */ + for (frame = ntree->nodes.last; frame; frame = frame->prev) { + /* skip selected, those are the nodes we want to attach */ + if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT)) { + continue; + } + + /* for some reason frame y coords aren't correct yet */ + node_to_updated_rect(frame, &totr_frame); + + if (BLI_rctf_isect_x(&totr_frame, totr_insert.xmin) && + BLI_rctf_isect_x(&totr_frame, totr_insert.xmax)) { + if (BLI_rctf_isect_y(&totr_frame, totr_insert.ymin) || + BLI_rctf_isect_y(&totr_frame, totr_insert.ymax)) { + /* frame isn't insert->parent actually, but this is needed to make offsetting + * nodes work correctly for above checked cases (it is restored later) */ + insert->parent = frame; + break; + } + } + } + } + + /* *** ensure offset at the left (or right for right_alignment case) of insert_node *** */ + + dist = right_alignment ? totr_insert.xmin - prev->totr.xmax : next->totr.xmin - totr_insert.xmax; + /* distance between insert_node and prev is smaller than min margin */ + if (dist < min_margin) { + addval = (min_margin - dist) * (right_alignment ? 1.0f : -1.0f); + + node_offset_apply(insert, addval); + + totr_insert.xmin += addval; + totr_insert.xmax += addval; + margin += min_margin; + } + + /* *** ensure offset at the right (or left for right_alignment case) of insert_node *** */ + + dist = right_alignment ? next->totr.xmin - totr_insert.xmax : totr_insert.xmin - prev->totr.xmax; + /* distance between insert_node and next is smaller than min margin */ + if (dist < min_margin) { + addval = (min_margin - dist) * (right_alignment ? 1.0f : -1.0f); + if (needs_alignment) { + bNode *offs_node = right_alignment ? next : prev; + if (!offs_node->parent || offs_node->parent == insert->parent || + nodeIsChildOf(offs_node->parent, insert)) { + node_offset_apply(offs_node, addval); + } + else if (!insert->parent && offs_node->parent) { + node_offset_apply(nodeFindRootParent(offs_node), addval); + } + margin = addval; + } + /* enough room is available, but we want to ensure the min margin at the right */ + else { + /* offset inserted node so that min margin is kept at the right */ + node_offset_apply(insert, -addval); + } + } + + if (needs_alignment) { + iofsd->insert_parent = insert->parent; + iofsd->offset_x = margin; + + /* flag all parents of insert as offset to prevent them from being offset */ + nodeParentsIter(insert, node_parents_offset_flag_enable_cb, NULL); + /* iterate over entire chain and apply offsets */ + nodeChainIter(ntree, + right_alignment ? next : prev, + node_link_insert_offset_chain_cb, + iofsd, + !right_alignment); + } + + insert->parent = init_parent; } /** @@ -1833,147 +1819,146 @@ static void node_link_insert_offset_ntree( */ static int node_insert_offset_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { - SpaceNode *snode = CTX_wm_space_node(C); - NodeInsertOfsData *iofsd = snode->iofsd; - bNode *node; - float duration; - bool redraw = false; - - if (!snode || event->type != TIMER || iofsd == NULL || iofsd->anim_timer != event->customdata) { - return OPERATOR_PASS_THROUGH; - } - - duration = (float)iofsd->anim_timer->duration; - - /* handle animation - do this before possibly aborting due to duration, since - * main thread might be so busy that node hasn't reached final position yet */ - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (UNLIKELY(node->anim_ofsx)) { - const float endval = node->anim_init_locx + node->anim_ofsx; - if (IS_EQF(node->locx, endval) == false) { - node->locx = BLI_easing_cubic_ease_in_out(duration, node->anim_init_locx, node->anim_ofsx, - NODE_INSOFS_ANIM_DURATION); - if (node->anim_ofsx < 0) { - CLAMP_MIN(node->locx, endval); - } - else { - CLAMP_MAX(node->locx, endval); - } - redraw = true; - } - } - } - if (redraw) { - ED_region_tag_redraw(CTX_wm_region(C)); - } - - /* end timer + free insert offset data */ - if (duration > NODE_INSOFS_ANIM_DURATION) { - WM_event_remove_timer(CTX_wm_manager(C), NULL, iofsd->anim_timer); - - for (node = snode->edittree->nodes.first; node; node = node->next) { - node->anim_init_locx = node->anim_ofsx = 0.0f; - } - - snode->iofsd = NULL; - MEM_freeN(iofsd); - - return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH); - } - - return OPERATOR_RUNNING_MODAL; + SpaceNode *snode = CTX_wm_space_node(C); + NodeInsertOfsData *iofsd = snode->iofsd; + bNode *node; + float duration; + bool redraw = false; + + if (!snode || event->type != TIMER || iofsd == NULL || iofsd->anim_timer != event->customdata) { + return OPERATOR_PASS_THROUGH; + } + + duration = (float)iofsd->anim_timer->duration; + + /* handle animation - do this before possibly aborting due to duration, since + * main thread might be so busy that node hasn't reached final position yet */ + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (UNLIKELY(node->anim_ofsx)) { + const float endval = node->anim_init_locx + node->anim_ofsx; + if (IS_EQF(node->locx, endval) == false) { + node->locx = BLI_easing_cubic_ease_in_out( + duration, node->anim_init_locx, node->anim_ofsx, NODE_INSOFS_ANIM_DURATION); + if (node->anim_ofsx < 0) { + CLAMP_MIN(node->locx, endval); + } + else { + CLAMP_MAX(node->locx, endval); + } + redraw = true; + } + } + } + if (redraw) { + ED_region_tag_redraw(CTX_wm_region(C)); + } + + /* end timer + free insert offset data */ + if (duration > NODE_INSOFS_ANIM_DURATION) { + WM_event_remove_timer(CTX_wm_manager(C), NULL, iofsd->anim_timer); + + for (node = snode->edittree->nodes.first; node; node = node->next) { + node->anim_init_locx = node->anim_ofsx = 0.0f; + } + + snode->iofsd = NULL; + MEM_freeN(iofsd); + + return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH); + } + + return OPERATOR_RUNNING_MODAL; } #undef NODE_INSOFS_ANIM_DURATION static int node_insert_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - const SpaceNode *snode = CTX_wm_space_node(C); - NodeInsertOfsData *iofsd = snode->iofsd; + const SpaceNode *snode = CTX_wm_space_node(C); + NodeInsertOfsData *iofsd = snode->iofsd; - if (!iofsd || !iofsd->insert) { - return OPERATOR_CANCELLED; - } + if (!iofsd || !iofsd->insert) { + return OPERATOR_CANCELLED; + } - BLI_assert((snode->flag & SNODE_SKIP_INSOFFSET) == 0); + BLI_assert((snode->flag & SNODE_SKIP_INSOFFSET) == 0); - iofsd->ntree = snode->edittree; - iofsd->anim_timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.02); + iofsd->ntree = snode->edittree; + iofsd->anim_timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.02); - node_link_insert_offset_ntree( - iofsd, CTX_wm_region(C), - event->mval, (snode->insert_ofs_dir == SNODE_INSERTOFS_DIR_RIGHT)); + node_link_insert_offset_ntree( + iofsd, CTX_wm_region(C), event->mval, (snode->insert_ofs_dir == SNODE_INSERTOFS_DIR_RIGHT)); - /* add temp handler */ - WM_event_add_modal_handler(C, op); + /* add temp handler */ + WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; + return OPERATOR_RUNNING_MODAL; } void NODE_OT_insert_offset(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Insert Offset"; - ot->description = "Automatically offset nodes on insertion"; - ot->idname = "NODE_OT_insert_offset"; - - /* callbacks */ - ot->invoke = node_insert_offset_invoke; - ot->modal = node_insert_offset_modal; - ot->poll = ED_operator_node_editable; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; + /* identifiers */ + ot->name = "Insert Offset"; + ot->description = "Automatically offset nodes on insertion"; + ot->idname = "NODE_OT_insert_offset"; + + /* callbacks */ + ot->invoke = node_insert_offset_invoke; + ot->modal = node_insert_offset_modal; + ot->poll = ED_operator_node_editable; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; } /* assumes link with NODE_LINKFLAG_HILITE set */ void ED_node_link_insert(Main *bmain, ScrArea *sa) { - bNode *node, *select; - SpaceNode *snode; - bNodeLink *link; - bNodeSocket *sockto; - - if (!ed_node_link_conditions(sa, true, &snode, &select)) { - return; - } - - /* get the link */ - for (link = snode->edittree->links.first; link; link = link->next) { - if (link->flag & NODE_LINKFLAG_HILITE) { - break; - } - } - - if (link) { - bNodeSocket *best_input = socket_best_match(&select->inputs); - bNodeSocket *best_output = socket_best_match(&select->outputs); - - if (best_input && best_output) { - node = link->tonode; - sockto = link->tosock; - - link->tonode = select; - link->tosock = best_input; - node_remove_extra_links(snode, link); - link->flag &= ~NODE_LINKFLAG_HILITE; - - nodeAddLink(snode->edittree, select, best_output, node, sockto); - - /* set up insert offset data, it needs stuff from here */ - if ((snode->flag & SNODE_SKIP_INSOFFSET) == 0) { - NodeInsertOfsData *iofsd = MEM_callocN(sizeof(NodeInsertOfsData), __func__); - - iofsd->insert = select; - iofsd->prev = link->fromnode; - iofsd->next = node; - - snode->iofsd = iofsd; - } - - ntreeUpdateTree(bmain, snode->edittree); /* needed for pointers */ - snode_update(snode, select); - ED_node_tag_update_id(snode->id); - } - } + bNode *node, *select; + SpaceNode *snode; + bNodeLink *link; + bNodeSocket *sockto; + + if (!ed_node_link_conditions(sa, true, &snode, &select)) { + return; + } + + /* get the link */ + for (link = snode->edittree->links.first; link; link = link->next) { + if (link->flag & NODE_LINKFLAG_HILITE) { + break; + } + } + + if (link) { + bNodeSocket *best_input = socket_best_match(&select->inputs); + bNodeSocket *best_output = socket_best_match(&select->outputs); + + if (best_input && best_output) { + node = link->tonode; + sockto = link->tosock; + + link->tonode = select; + link->tosock = best_input; + node_remove_extra_links(snode, link); + link->flag &= ~NODE_LINKFLAG_HILITE; + + nodeAddLink(snode->edittree, select, best_output, node, sockto); + + /* set up insert offset data, it needs stuff from here */ + if ((snode->flag & SNODE_SKIP_INSOFFSET) == 0) { + NodeInsertOfsData *iofsd = MEM_callocN(sizeof(NodeInsertOfsData), __func__); + + iofsd->insert = select; + iofsd->prev = link->fromnode; + iofsd->next = node; + + snode->iofsd = iofsd; + } + + ntreeUpdateTree(bmain, snode->edittree); /* needed for pointers */ + snode_update(snode, select); + ED_node_tag_update_id(snode->id); + } + } } diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index a027481ff27..58531ec32b1 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -36,7 +36,7 @@ #include "BKE_main.h" #include "BKE_node.h" -#include "ED_node.h" /* own include */ +#include "ED_node.h" /* own include */ #include "ED_screen.h" #include "ED_select_utils.h" @@ -52,7 +52,7 @@ #include "MEM_guardedalloc.h" -#include "node_intern.h" /* own include */ +#include "node_intern.h" /* own include */ /* -------------------------------------------------------------------- */ /** \name Public Node Selection API @@ -60,182 +60,182 @@ static bNode *node_under_mouse_select(bNodeTree *ntree, int mx, int my) { - bNode *node; - - for (node = ntree->nodes.last; node; node = node->prev) { - if (node->typeinfo->select_area_func) { - if (node->typeinfo->select_area_func(node, mx, my)) { - return node; - } - } - } - return NULL; + bNode *node; + + for (node = ntree->nodes.last; node; node = node->prev) { + if (node->typeinfo->select_area_func) { + if (node->typeinfo->select_area_func(node, mx, my)) { + return node; + } + } + } + return NULL; } static bNode *node_under_mouse_tweak(bNodeTree *ntree, int mx, int my) { - bNode *node; - - for (node = ntree->nodes.last; node; node = node->prev) { - if (node->typeinfo->tweak_area_func) { - if (node->typeinfo->tweak_area_func(node, mx, my)) { - return node; - } - } - } - return NULL; + bNode *node; + + for (node = ntree->nodes.last; node; node = node->prev) { + if (node->typeinfo->tweak_area_func) { + if (node->typeinfo->tweak_area_func(node, mx, my)) { + return node; + } + } + } + return NULL; } static bool is_position_over_node_or_socket(SpaceNode *snode, float mouse[2]) { - if (node_under_mouse_tweak(snode->edittree, mouse[0], mouse[1])) { - return true; - } + if (node_under_mouse_tweak(snode->edittree, mouse[0], mouse[1])) { + return true; + } - bNode *node; - bNodeSocket *sock; - if (node_find_indicated_socket(snode, &node, &sock, mouse, SOCK_IN | SOCK_OUT)) { - return true; - } + bNode *node; + bNodeSocket *sock; + if (node_find_indicated_socket(snode, &node, &sock, mouse, SOCK_IN | SOCK_OUT)) { + return true; + } - return false; + return false; } static bool is_event_over_node_or_socket(bContext *C, const wmEvent *event) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - float mouse[2]; - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mouse[0], &mouse[1]); - return is_position_over_node_or_socket(snode, mouse); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + float mouse[2]; + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mouse[0], &mouse[1]); + return is_position_over_node_or_socket(snode, mouse); } static void node_toggle(bNode *node) { - nodeSetSelected(node, !(node->flag & SELECT)); + nodeSetSelected(node, !(node->flag & SELECT)); } void node_socket_select(bNode *node, bNodeSocket *sock) { - sock->flag |= SELECT; + sock->flag |= SELECT; - /* select node too */ - if (node) { - node->flag |= SELECT; - } + /* select node too */ + if (node) { + node->flag |= SELECT; + } } void node_socket_deselect(bNode *node, bNodeSocket *sock, const bool deselect_node) { - sock->flag &= ~SELECT; - - if (node && deselect_node) { - bool sel = 0; - - /* if no selected sockets remain, also deselect the node */ - for (sock = node->inputs.first; sock; sock = sock->next) { - if (sock->flag & SELECT) { - sel = 1; - break; - } - } - for (sock = node->outputs.first; sock; sock = sock->next) { - if (sock->flag & SELECT) { - sel = 1; - break; - } - } - - if (!sel) { - node->flag &= ~SELECT; - } - } + sock->flag &= ~SELECT; + + if (node && deselect_node) { + bool sel = 0; + + /* if no selected sockets remain, also deselect the node */ + for (sock = node->inputs.first; sock; sock = sock->next) { + if (sock->flag & SELECT) { + sel = 1; + break; + } + } + for (sock = node->outputs.first; sock; sock = sock->next) { + if (sock->flag & SELECT) { + sel = 1; + break; + } + } + + if (!sel) { + node->flag &= ~SELECT; + } + } } static void node_socket_toggle(bNode *node, bNodeSocket *sock, int deselect_node) { - if (sock->flag & SELECT) { - node_socket_deselect(node, sock, deselect_node); - } - else { - node_socket_select(node, sock); - } + if (sock->flag & SELECT) { + node_socket_deselect(node, sock, deselect_node); + } + else { + node_socket_select(node, sock); + } } /* no undo here! */ void node_deselect_all(SpaceNode *snode) { - bNode *node; + bNode *node; - for (node = snode->edittree->nodes.first; node; node = node->next) { - nodeSetSelected(node, false); - } + for (node = snode->edittree->nodes.first; node; node = node->next) { + nodeSetSelected(node, false); + } } void node_deselect_all_input_sockets(SpaceNode *snode, const bool deselect_nodes) { - bNode *node; - bNodeSocket *sock; - - /* XXX not calling node_socket_deselect here each time, because this does iteration - * over all node sockets internally to check if the node stays selected. - * We can do that more efficiently here. - */ - - for (node = snode->edittree->nodes.first; node; node = node->next) { - int sel = 0; - - for (sock = node->inputs.first; sock; sock = sock->next) { - sock->flag &= ~SELECT; - } - - /* if no selected sockets remain, also deselect the node */ - if (deselect_nodes) { - for (sock = node->outputs.first; sock; sock = sock->next) { - if (sock->flag & SELECT) { - sel = 1; - break; - } - } - - if (!sel) { - node->flag &= ~SELECT; - } - } - } + bNode *node; + bNodeSocket *sock; + + /* XXX not calling node_socket_deselect here each time, because this does iteration + * over all node sockets internally to check if the node stays selected. + * We can do that more efficiently here. + */ + + for (node = snode->edittree->nodes.first; node; node = node->next) { + int sel = 0; + + for (sock = node->inputs.first; sock; sock = sock->next) { + sock->flag &= ~SELECT; + } + + /* if no selected sockets remain, also deselect the node */ + if (deselect_nodes) { + for (sock = node->outputs.first; sock; sock = sock->next) { + if (sock->flag & SELECT) { + sel = 1; + break; + } + } + + if (!sel) { + node->flag &= ~SELECT; + } + } + } } void node_deselect_all_output_sockets(SpaceNode *snode, const bool deselect_nodes) { - bNode *node; - bNodeSocket *sock; - - /* XXX not calling node_socket_deselect here each time, because this does iteration - * over all node sockets internally to check if the node stays selected. - * We can do that more efficiently here. - */ - - for (node = snode->edittree->nodes.first; node; node = node->next) { - bool sel = false; - - for (sock = node->outputs.first; sock; sock = sock->next) { - sock->flag &= ~SELECT; - } - - /* if no selected sockets remain, also deselect the node */ - if (deselect_nodes) { - for (sock = node->inputs.first; sock; sock = sock->next) { - if (sock->flag & SELECT) { - sel = 1; - break; - } - } - - if (!sel) { - node->flag &= ~SELECT; - } - } - } + bNode *node; + bNodeSocket *sock; + + /* XXX not calling node_socket_deselect here each time, because this does iteration + * over all node sockets internally to check if the node stays selected. + * We can do that more efficiently here. + */ + + for (node = snode->edittree->nodes.first; node; node = node->next) { + bool sel = false; + + for (sock = node->outputs.first; sock; sock = sock->next) { + sock->flag &= ~SELECT; + } + + /* if no selected sockets remain, also deselect the node */ + if (deselect_nodes) { + for (sock = node->inputs.first; sock; sock = sock->next) { + if (sock->flag & SELECT) { + sel = 1; + break; + } + } + + if (!sel) { + node->flag &= ~SELECT; + } + } + } } /** \} */ @@ -248,152 +248,158 @@ void node_deselect_all_output_sockets(SpaceNode *snode, const bool deselect_node static bool node_select_grouped_type(SpaceNode *snode, bNode *node_act) { - bNode *node; - bool changed = false; - - for (node = snode->edittree->nodes.first; node; node = node->next) { - if ((node->flag & SELECT) == 0) { - if (node->type == node_act->type) { - nodeSetSelected(node, true); - changed = true; - } - } - } - - return changed; + bNode *node; + bool changed = false; + + for (node = snode->edittree->nodes.first; node; node = node->next) { + if ((node->flag & SELECT) == 0) { + if (node->type == node_act->type) { + nodeSetSelected(node, true); + changed = true; + } + } + } + + return changed; } static bool node_select_grouped_color(SpaceNode *snode, bNode *node_act) { - bNode *node; - bool changed = false; - - for (node = snode->edittree->nodes.first; node; node = node->next) { - if ((node->flag & SELECT) == 0) { - if (compare_v3v3(node->color, node_act->color, 0.005f)) { - nodeSetSelected(node, true); - changed = true; - } - } - } - - return changed; + bNode *node; + bool changed = false; + + for (node = snode->edittree->nodes.first; node; node = node->next) { + if ((node->flag & SELECT) == 0) { + if (compare_v3v3(node->color, node_act->color, 0.005f)) { + nodeSetSelected(node, true); + changed = true; + } + } + } + + return changed; } static bool node_select_grouped_name(SpaceNode *snode, bNode *node_act, const bool from_right) { - bNode *node; - bool changed = false; - const unsigned int delims[] = {'.', '-', '_', '\0'}; - size_t pref_len_act, pref_len_curr; - const char *sep, *suf_act, *suf_curr; - - pref_len_act = BLI_str_partition_ex_utf8(node_act->name, NULL, delims, &sep, &suf_act, from_right); - - /* Note: in case we are searching for suffix, and found none, use whole name as suffix. */ - if (from_right && !(sep && suf_act)) { - pref_len_act = 0; - suf_act = node_act->name; - } - - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - continue; - } - pref_len_curr = BLI_str_partition_ex_utf8(node->name, NULL, delims, &sep, &suf_curr, from_right); - - /* Same as with active node name! */ - if (from_right && !(sep && suf_curr)) { - pref_len_curr = 0; - suf_curr = node->name; - } - - if ((from_right && STREQ(suf_act, suf_curr)) || - (!from_right && (pref_len_act == pref_len_curr) && STREQLEN(node_act->name, node->name, pref_len_act))) - { - nodeSetSelected(node, true); - changed = true; - } - } - - return changed; + bNode *node; + bool changed = false; + const unsigned int delims[] = {'.', '-', '_', '\0'}; + size_t pref_len_act, pref_len_curr; + const char *sep, *suf_act, *suf_curr; + + pref_len_act = BLI_str_partition_ex_utf8( + node_act->name, NULL, delims, &sep, &suf_act, from_right); + + /* Note: in case we are searching for suffix, and found none, use whole name as suffix. */ + if (from_right && !(sep && suf_act)) { + pref_len_act = 0; + suf_act = node_act->name; + } + + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + continue; + } + pref_len_curr = BLI_str_partition_ex_utf8( + node->name, NULL, delims, &sep, &suf_curr, from_right); + + /* Same as with active node name! */ + if (from_right && !(sep && suf_curr)) { + pref_len_curr = 0; + suf_curr = node->name; + } + + if ((from_right && STREQ(suf_act, suf_curr)) || + (!from_right && (pref_len_act == pref_len_curr) && + STREQLEN(node_act->name, node->name, pref_len_act))) { + nodeSetSelected(node, true); + changed = true; + } + } + + return changed; } enum { - NODE_SELECT_GROUPED_TYPE = 0, - NODE_SELECT_GROUPED_COLOR = 1, - NODE_SELECT_GROUPED_PREFIX = 2, - NODE_SELECT_GROUPED_SUFIX = 3, + NODE_SELECT_GROUPED_TYPE = 0, + NODE_SELECT_GROUPED_COLOR = 1, + NODE_SELECT_GROUPED_PREFIX = 2, + NODE_SELECT_GROUPED_SUFIX = 3, }; static int node_select_grouped_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node_act = nodeGetActive(snode->edittree); - bNode *node; - bool changed = false; - const bool extend = RNA_boolean_get(op->ptr, "extend"); - const int type = RNA_enum_get(op->ptr, "type"); - - if (!extend) { - for (node = snode->edittree->nodes.first; node; node = node->next) { - nodeSetSelected(node, false); - } - } - nodeSetSelected(node_act, true); - - switch (type) { - case NODE_SELECT_GROUPED_TYPE: - changed = node_select_grouped_type(snode, node_act); - break; - case NODE_SELECT_GROUPED_COLOR: - changed = node_select_grouped_color(snode, node_act); - break; - case NODE_SELECT_GROUPED_PREFIX: - changed = node_select_grouped_name(snode, node_act, false); - break; - case NODE_SELECT_GROUPED_SUFIX: - changed = node_select_grouped_name(snode, node_act, true); - break; - default: - break; - } - - if (changed) { - ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); - return OPERATOR_FINISHED; - } - - return OPERATOR_CANCELLED; + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node_act = nodeGetActive(snode->edittree); + bNode *node; + bool changed = false; + const bool extend = RNA_boolean_get(op->ptr, "extend"); + const int type = RNA_enum_get(op->ptr, "type"); + + if (!extend) { + for (node = snode->edittree->nodes.first; node; node = node->next) { + nodeSetSelected(node, false); + } + } + nodeSetSelected(node_act, true); + + switch (type) { + case NODE_SELECT_GROUPED_TYPE: + changed = node_select_grouped_type(snode, node_act); + break; + case NODE_SELECT_GROUPED_COLOR: + changed = node_select_grouped_color(snode, node_act); + break; + case NODE_SELECT_GROUPED_PREFIX: + changed = node_select_grouped_name(snode, node_act, false); + break; + case NODE_SELECT_GROUPED_SUFIX: + changed = node_select_grouped_name(snode, node_act, true); + break; + default: + break; + } + + if (changed) { + ED_node_sort(snode->edittree); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); + return OPERATOR_FINISHED; + } + + return OPERATOR_CANCELLED; } void NODE_OT_select_grouped(wmOperatorType *ot) { - static const EnumPropertyItem prop_select_grouped_types[] = { - {NODE_SELECT_GROUPED_TYPE, "TYPE", 0, "Type", ""}, - {NODE_SELECT_GROUPED_COLOR, "COLOR", 0, "Color", ""}, - {NODE_SELECT_GROUPED_PREFIX, "PREFIX", 0, "Prefix", ""}, - {NODE_SELECT_GROUPED_SUFIX, "SUFFIX", 0, "Suffix", ""}, - {0, NULL, 0, NULL, NULL}, - }; - - /* identifiers */ - ot->name = "Select Grouped"; - ot->description = "Select nodes with similar properties"; - ot->idname = "NODE_OT_select_grouped"; - - /* api callbacks */ - ot->invoke = WM_menu_invoke; - ot->exec = node_select_grouped_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection instead of deselecting everything first"); - ot->prop = RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", ""); + static const EnumPropertyItem prop_select_grouped_types[] = { + {NODE_SELECT_GROUPED_TYPE, "TYPE", 0, "Type", ""}, + {NODE_SELECT_GROUPED_COLOR, "COLOR", 0, "Color", ""}, + {NODE_SELECT_GROUPED_PREFIX, "PREFIX", 0, "Prefix", ""}, + {NODE_SELECT_GROUPED_SUFIX, "SUFFIX", 0, "Suffix", ""}, + {0, NULL, 0, NULL, NULL}, + }; + + /* identifiers */ + ot->name = "Select Grouped"; + ot->description = "Select nodes with similar properties"; + ot->idname = "NODE_OT_select_grouped"; + + /* api callbacks */ + ot->invoke = WM_menu_invoke; + ot->exec = node_select_grouped_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + RNA_def_boolean(ot->srna, + "extend", + false, + "Extend", + "Extend selection instead of deselecting everything first"); + ot->prop = RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", ""); } /** \} */ @@ -404,175 +410,175 @@ void NODE_OT_select_grouped(wmOperatorType *ot) void node_select_single(bContext *C, bNode *node) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNode *tnode; + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNode *tnode; - for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) { - if (tnode != node) { - nodeSetSelected(tnode, false); - } - } - nodeSetSelected(node, true); + for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) { + if (tnode != node) { + nodeSetSelected(tnode, false); + } + } + nodeSetSelected(node, true); - ED_node_set_active(bmain, snode->edittree, node); - ED_node_set_active_viewer_key(snode); + ED_node_set_active(bmain, snode->edittree, node); + ED_node_set_active_viewer_key(snode); - ED_node_sort(snode->edittree); + ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); } -static int node_mouse_select(Main *bmain, SpaceNode *snode, ARegion *ar, const int mval[2], bool extend, bool socket_select) +static int node_mouse_select( + Main *bmain, SpaceNode *snode, ARegion *ar, const int mval[2], bool extend, bool socket_select) { - bNode *node, *tnode; - bNodeSocket *sock = NULL; - bNodeSocket *tsock; - float cursor[2]; - bool selected = false; - - /* get mouse coordinates in view2d space */ - UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &cursor[0], &cursor[1]); - - /* first do socket selection, these generally overlap with nodes. */ - if (socket_select) { - if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN)) { - node_socket_toggle(node, sock, 1); - selected = true; - } - else if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_OUT)) { - if (sock->flag & SELECT) { - if (extend) { - node_socket_deselect(node, sock, 1); - } - else { - selected = true; - } - } - else { - /* only allow one selected output per node, for sensible linking. - * allows selecting outputs from different nodes though. */ - if (node) { - for (tsock = node->outputs.first; tsock; tsock = tsock->next) { - node_socket_deselect(node, tsock, 1); - } - } - if (extend) { - /* only allow one selected output per node, for sensible linking. - * allows selecting outputs from different nodes though. */ - for (tsock = node->outputs.first; tsock; tsock = tsock->next) { - if (tsock != sock) { - node_socket_deselect(node, tsock, 1); - } - } - } - node_socket_select(node, sock); - selected = true; - } - } - } - - if (!sock) { - if (extend) { - /* find the closest visible node */ - node = node_under_mouse_select(snode->edittree, cursor[0], cursor[1]); - - if (node) { - if ((node->flag & SELECT) && (node->flag & NODE_ACTIVE) == 0) { - /* if node is selected but not active make it active */ - ED_node_set_active(bmain, snode->edittree, node); - } - else { - node_toggle(node); - ED_node_set_active(bmain, snode->edittree, node); - } - selected = true; - } - } - else { - /* find the closest visible node */ - node = node_under_mouse_select(snode->edittree, cursor[0], cursor[1]); - - if (node) { - for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) { - nodeSetSelected(tnode, false); - } - nodeSetSelected(node, true); - ED_node_set_active(bmain, snode->edittree, node); - selected = true; - } - } - } - - /* update node order */ - if (selected) { - ED_node_set_active_viewer_key(snode); - ED_node_sort(snode->edittree); - } - - return selected; + bNode *node, *tnode; + bNodeSocket *sock = NULL; + bNodeSocket *tsock; + float cursor[2]; + bool selected = false; + + /* get mouse coordinates in view2d space */ + UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &cursor[0], &cursor[1]); + + /* first do socket selection, these generally overlap with nodes. */ + if (socket_select) { + if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN)) { + node_socket_toggle(node, sock, 1); + selected = true; + } + else if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_OUT)) { + if (sock->flag & SELECT) { + if (extend) { + node_socket_deselect(node, sock, 1); + } + else { + selected = true; + } + } + else { + /* only allow one selected output per node, for sensible linking. + * allows selecting outputs from different nodes though. */ + if (node) { + for (tsock = node->outputs.first; tsock; tsock = tsock->next) { + node_socket_deselect(node, tsock, 1); + } + } + if (extend) { + /* only allow one selected output per node, for sensible linking. + * allows selecting outputs from different nodes though. */ + for (tsock = node->outputs.first; tsock; tsock = tsock->next) { + if (tsock != sock) { + node_socket_deselect(node, tsock, 1); + } + } + } + node_socket_select(node, sock); + selected = true; + } + } + } + + if (!sock) { + if (extend) { + /* find the closest visible node */ + node = node_under_mouse_select(snode->edittree, cursor[0], cursor[1]); + + if (node) { + if ((node->flag & SELECT) && (node->flag & NODE_ACTIVE) == 0) { + /* if node is selected but not active make it active */ + ED_node_set_active(bmain, snode->edittree, node); + } + else { + node_toggle(node); + ED_node_set_active(bmain, snode->edittree, node); + } + selected = true; + } + } + else { + /* find the closest visible node */ + node = node_under_mouse_select(snode->edittree, cursor[0], cursor[1]); + + if (node) { + for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) { + nodeSetSelected(tnode, false); + } + nodeSetSelected(node, true); + ED_node_set_active(bmain, snode->edittree, node); + selected = true; + } + } + } + + /* update node order */ + if (selected) { + ED_node_set_active_viewer_key(snode); + ED_node_sort(snode->edittree); + } + + return selected; } static int node_select_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - int mval[2]; - short extend; - bool socket_select; - - /* get settings from RNA properties for operator */ - mval[0] = RNA_int_get(op->ptr, "mouse_x"); - mval[1] = RNA_int_get(op->ptr, "mouse_y"); - - extend = RNA_boolean_get(op->ptr, "extend"); - /* always do socket_select when extending selection. */ - socket_select = extend || RNA_boolean_get(op->ptr, "socket_select"); - - /* perform the select */ - if (node_mouse_select(bmain, snode, ar, mval, extend, socket_select)) { - /* send notifiers */ - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); - - /* allow tweak event to work too */ - return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; - } - else { - /* allow tweak event to work too */ - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; - } + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + int mval[2]; + short extend; + bool socket_select; + + /* get settings from RNA properties for operator */ + mval[0] = RNA_int_get(op->ptr, "mouse_x"); + mval[1] = RNA_int_get(op->ptr, "mouse_y"); + + extend = RNA_boolean_get(op->ptr, "extend"); + /* always do socket_select when extending selection. */ + socket_select = extend || RNA_boolean_get(op->ptr, "socket_select"); + + /* perform the select */ + if (node_mouse_select(bmain, snode, ar, mval, extend, socket_select)) { + /* send notifiers */ + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); + + /* allow tweak event to work too */ + return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; + } + else { + /* allow tweak event to work too */ + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + } } static int node_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - RNA_int_set(op->ptr, "mouse_x", event->mval[0]); - RNA_int_set(op->ptr, "mouse_y", event->mval[1]); + RNA_int_set(op->ptr, "mouse_x", event->mval[0]); + RNA_int_set(op->ptr, "mouse_y", event->mval[1]); - return node_select_exec(C, op); + return node_select_exec(C, op); } - void NODE_OT_select(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Select"; - ot->idname = "NODE_OT_select"; - ot->description = "Select the node under the cursor"; - - /* api callbacks */ - ot->invoke = node_select_invoke; - ot->exec = node_select_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - RNA_def_int(ot->srna, "mouse_x", 0, INT_MIN, INT_MAX, "Mouse X", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "mouse_y", 0, INT_MIN, INT_MAX, "Mouse Y", "", INT_MIN, INT_MAX); - RNA_def_boolean(ot->srna, "extend", false, "Extend", ""); - RNA_def_boolean(ot->srna, "socket_select", false, "Socket Select", ""); + /* identifiers */ + ot->name = "Select"; + ot->idname = "NODE_OT_select"; + ot->description = "Select the node under the cursor"; + + /* api callbacks */ + ot->invoke = node_select_invoke; + ot->exec = node_select_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + RNA_def_int(ot->srna, "mouse_x", 0, INT_MIN, INT_MAX, "Mouse X", "", INT_MIN, INT_MAX); + RNA_def_int(ot->srna, "mouse_y", 0, INT_MIN, INT_MAX, "Mouse Y", "", INT_MIN, INT_MAX); + RNA_def_boolean(ot->srna, "extend", false, "Extend", ""); + RNA_def_boolean(ot->srna, "socket_select", false, "Socket Select", ""); } /** \} */ @@ -583,74 +589,78 @@ void NODE_OT_select(wmOperatorType *ot) static int node_box_select_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - rctf rectf; - - WM_operator_properties_border_to_rctf(op, &rectf); - UI_view2d_region_to_view_rctf(&ar->v2d, &rectf, &rectf); - - const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); - const bool select = (sel_op != SEL_OP_SUB); - if (SEL_OP_USE_PRE_DESELECT(sel_op)) { - ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT); - } - - for (bNode *node = snode->edittree->nodes.first; node; node = node->next) { - bool is_inside; - if (node->type == NODE_FRAME) { - is_inside = BLI_rctf_inside_rctf(&rectf, &node->totr); - } - else { - is_inside = BLI_rctf_isect(&rectf, &node->totr, NULL); - } - - if (is_inside) { - nodeSetSelected(node, select); - } - } - - ED_node_sort(snode->edittree); - - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + rctf rectf; + + WM_operator_properties_border_to_rctf(op, &rectf); + UI_view2d_region_to_view_rctf(&ar->v2d, &rectf, &rectf); + + const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); + const bool select = (sel_op != SEL_OP_SUB); + if (SEL_OP_USE_PRE_DESELECT(sel_op)) { + ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT); + } + + for (bNode *node = snode->edittree->nodes.first; node; node = node->next) { + bool is_inside; + if (node->type == NODE_FRAME) { + is_inside = BLI_rctf_inside_rctf(&rectf, &node->totr); + } + else { + is_inside = BLI_rctf_isect(&rectf, &node->totr, NULL); + } + + if (is_inside) { + nodeSetSelected(node, select); + } + } + + ED_node_sort(snode->edittree); + + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); + + return OPERATOR_FINISHED; } static int node_box_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - const bool tweak = RNA_boolean_get(op->ptr, "tweak"); + const bool tweak = RNA_boolean_get(op->ptr, "tweak"); - if (tweak && is_event_over_node_or_socket(C, event)) { - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; - } + if (tweak && is_event_over_node_or_socket(C, event)) { + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + } - return WM_gesture_box_invoke(C, op, event); + return WM_gesture_box_invoke(C, op, event); } void NODE_OT_select_box(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Box Select"; - ot->idname = "NODE_OT_select_box"; - ot->description = "Use box selection to select nodes"; - - /* api callbacks */ - ot->invoke = node_box_select_invoke; - ot->exec = node_box_select_exec; - ot->modal = WM_gesture_box_modal; - ot->cancel = WM_gesture_box_cancel; - - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - /* properties */ - RNA_def_boolean(ot->srna, "tweak", 0, "Tweak", "Only activate when mouse is not over a node - useful for tweak gesture"); - - WM_operator_properties_gesture_box(ot); - WM_operator_properties_select_operation_simple(ot); + /* identifiers */ + ot->name = "Box Select"; + ot->idname = "NODE_OT_select_box"; + ot->description = "Use box selection to select nodes"; + + /* api callbacks */ + ot->invoke = node_box_select_invoke; + ot->exec = node_box_select_exec; + ot->modal = WM_gesture_box_modal; + ot->cancel = WM_gesture_box_cancel; + + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + RNA_def_boolean(ot->srna, + "tweak", + 0, + "Tweak", + "Only activate when mouse is not over a node - useful for tweak gesture"); + + WM_operator_properties_gesture_box(ot); + WM_operator_properties_select_operation_simple(ot); } /** \} */ @@ -661,60 +671,60 @@ void NODE_OT_select_box(wmOperatorType *ot) static int node_circleselect_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - bNode *node; + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + bNode *node; - int x, y, radius; - float offset[2]; + int x, y, radius; + float offset[2]; - float zoom = (float)(BLI_rcti_size_x(&ar->winrct)) / (float)(BLI_rctf_size_x(&ar->v2d.cur)); + float zoom = (float)(BLI_rcti_size_x(&ar->winrct)) / (float)(BLI_rctf_size_x(&ar->v2d.cur)); - const eSelectOp sel_op = ED_select_op_modal( - RNA_enum_get(op->ptr, "mode"), WM_gesture_is_modal_first(op->customdata)); - const bool select = (sel_op != SEL_OP_SUB); - if (SEL_OP_USE_PRE_DESELECT(sel_op)) { - ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT); - } + const eSelectOp sel_op = ED_select_op_modal(RNA_enum_get(op->ptr, "mode"), + WM_gesture_is_modal_first(op->customdata)); + const bool select = (sel_op != SEL_OP_SUB); + if (SEL_OP_USE_PRE_DESELECT(sel_op)) { + ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT); + } - /* get operator properties */ - x = RNA_int_get(op->ptr, "x"); - y = RNA_int_get(op->ptr, "y"); - radius = RNA_int_get(op->ptr, "radius"); + /* get operator properties */ + x = RNA_int_get(op->ptr, "x"); + y = RNA_int_get(op->ptr, "y"); + radius = RNA_int_get(op->ptr, "radius"); - UI_view2d_region_to_view(&ar->v2d, x, y, &offset[0], &offset[1]); + UI_view2d_region_to_view(&ar->v2d, x, y, &offset[0], &offset[1]); - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (BLI_rctf_isect_circle(&node->totr, offset, radius / zoom)) { - nodeSetSelected(node, select); - } - } + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (BLI_rctf_isect_circle(&node->totr, offset, radius / zoom)) { + nodeSetSelected(node, select); + } + } - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_select_circle(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Circle Select"; - ot->idname = "NODE_OT_select_circle"; - ot->description = "Use circle selection to select nodes"; + /* identifiers */ + ot->name = "Circle Select"; + ot->idname = "NODE_OT_select_circle"; + ot->description = "Use circle selection to select nodes"; - /* api callbacks */ - ot->invoke = WM_gesture_circle_invoke; - ot->exec = node_circleselect_exec; - ot->modal = WM_gesture_circle_modal; + /* api callbacks */ + ot->invoke = WM_gesture_circle_invoke; + ot->exec = node_circleselect_exec; + ot->modal = WM_gesture_circle_modal; - ot->poll = ED_operator_node_active; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* properties */ - WM_operator_properties_gesture_circle(ot); - WM_operator_properties_select_operation_simple(ot); + /* properties */ + WM_operator_properties_gesture_circle(ot); + WM_operator_properties_select_operation_simple(ot); } /** \} */ @@ -725,101 +735,103 @@ void NODE_OT_select_circle(wmOperatorType *ot) static int node_lasso_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - const bool tweak = RNA_boolean_get(op->ptr, "tweak"); + const bool tweak = RNA_boolean_get(op->ptr, "tweak"); - if (tweak && is_event_over_node_or_socket(C, event)) { - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; - } + if (tweak && is_event_over_node_or_socket(C, event)) { + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + } - return WM_gesture_lasso_invoke(C, op, event); + return WM_gesture_lasso_invoke(C, op, event); } static bool do_lasso_select_node(bContext *C, const int mcords[][2], short moves, eSelectOp sel_op) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; - ARegion *ar = CTX_wm_region(C); + ARegion *ar = CTX_wm_region(C); - rcti rect; - bool changed = false; + rcti rect; + bool changed = false; - const bool select = (sel_op != SEL_OP_SUB); - if (SEL_OP_USE_PRE_DESELECT(sel_op)) { - ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT); - changed = true; - } + const bool select = (sel_op != SEL_OP_SUB); + if (SEL_OP_USE_PRE_DESELECT(sel_op)) { + ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT); + changed = true; + } - /* get rectangle from operator */ - BLI_lasso_boundbox(&rect, mcords, moves); + /* get rectangle from operator */ + BLI_lasso_boundbox(&rect, mcords, moves); - /* do actual selection */ - for (node = snode->edittree->nodes.first; node; node = node->next) { + /* do actual selection */ + for (node = snode->edittree->nodes.first; node; node = node->next) { - if (select && (node->flag & NODE_SELECT)) { - continue; - } + if (select && (node->flag & NODE_SELECT)) { + continue; + } - int screen_co[2]; - const float cent[2] = {BLI_rctf_cent_x(&node->totr), - BLI_rctf_cent_y(&node->totr)}; + int screen_co[2]; + const float cent[2] = {BLI_rctf_cent_x(&node->totr), BLI_rctf_cent_y(&node->totr)}; - /* marker in screen coords */ - if (UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_co[0], &screen_co[1]) && - BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) && - BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX)) - { - nodeSetSelected(node, select); - changed = true; - } - } + /* marker in screen coords */ + if (UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_co[0], &screen_co[1]) && + BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) && + BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX)) { + nodeSetSelected(node, select); + changed = true; + } + } - if (changed) { - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); - } + if (changed) { + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); + } - return changed; + return changed; } static int node_lasso_select_exec(bContext *C, wmOperator *op) { - int mcords_tot; - const int (*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot); + int mcords_tot; + const int(*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot); - if (mcords) { - const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); + if (mcords) { + const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); - do_lasso_select_node(C, mcords, mcords_tot, sel_op); + do_lasso_select_node(C, mcords, mcords_tot, sel_op); - MEM_freeN((void *)mcords); + MEM_freeN((void *)mcords); - return OPERATOR_FINISHED; - } - return OPERATOR_PASS_THROUGH; + return OPERATOR_FINISHED; + } + return OPERATOR_PASS_THROUGH; } void NODE_OT_select_lasso(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Lasso Select"; - ot->description = "Select nodes using lasso selection"; - ot->idname = "NODE_OT_select_lasso"; - - /* api callbacks */ - ot->invoke = node_lasso_select_invoke; - ot->modal = WM_gesture_lasso_modal; - ot->exec = node_lasso_select_exec; - ot->poll = ED_operator_node_active; - ot->cancel = WM_gesture_lasso_cancel; - - /* flags */ - ot->flag = OPTYPE_UNDO; - - /* properties */ - RNA_def_boolean(ot->srna, "tweak", 0, "Tweak", "Only activate when mouse is not over a node - useful for tweak gesture"); - - WM_operator_properties_gesture_lasso(ot); - WM_operator_properties_select_operation_simple(ot); + /* identifiers */ + ot->name = "Lasso Select"; + ot->description = "Select nodes using lasso selection"; + ot->idname = "NODE_OT_select_lasso"; + + /* api callbacks */ + ot->invoke = node_lasso_select_invoke; + ot->modal = WM_gesture_lasso_modal; + ot->exec = node_lasso_select_exec; + ot->poll = ED_operator_node_active; + ot->cancel = WM_gesture_lasso_cancel; + + /* flags */ + ot->flag = OPTYPE_UNDO; + + /* properties */ + RNA_def_boolean(ot->srna, + "tweak", + 0, + "Tweak", + "Only activate when mouse is not over a node - useful for tweak gesture"); + + WM_operator_properties_gesture_lasso(ot); + WM_operator_properties_select_operation_simple(ot); } /** \} */ @@ -830,33 +842,33 @@ void NODE_OT_select_lasso(wmOperatorType *ot) static int node_select_all_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - ListBase *node_lb = &snode->edittree->nodes; - int action = RNA_enum_get(op->ptr, "action"); + SpaceNode *snode = CTX_wm_space_node(C); + ListBase *node_lb = &snode->edittree->nodes; + int action = RNA_enum_get(op->ptr, "action"); - ED_node_select_all(node_lb, action); + ED_node_select_all(node_lb, action); - ED_node_sort(snode->edittree); + ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); - return OPERATOR_FINISHED; + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); + return OPERATOR_FINISHED; } void NODE_OT_select_all(wmOperatorType *ot) { - /* identifiers */ - ot->name = "(De)select All"; - ot->description = "(De)select all nodes"; - ot->idname = "NODE_OT_select_all"; + /* identifiers */ + ot->name = "(De)select All"; + ot->description = "(De)select all nodes"; + ot->idname = "NODE_OT_select_all"; - /* api callbacks */ - ot->exec = node_select_all_exec; - ot->poll = ED_operator_node_active; + /* api callbacks */ + ot->exec = node_select_all_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - WM_operator_properties_select_all(ot); + WM_operator_properties_select_all(ot); } /** \} */ @@ -867,48 +879,48 @@ void NODE_OT_select_all(wmOperatorType *ot) static int node_select_linked_to_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeLink *link; - bNode *node; - - for (node = snode->edittree->nodes.first; node; node = node->next) { - node->flag &= ~NODE_TEST; - } - - for (link = snode->edittree->links.first; link; link = link->next) { - if (nodeLinkIsHidden(link)) { - continue; - } - if (link->fromnode && link->tonode && (link->fromnode->flag & NODE_SELECT)) { - link->tonode->flag |= NODE_TEST; - } - } - - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->flag & NODE_TEST) { - nodeSetSelected(node, true); - } - } - - ED_node_sort(snode->edittree); - - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeLink *link; + bNode *node; + + for (node = snode->edittree->nodes.first; node; node = node->next) { + node->flag &= ~NODE_TEST; + } + + for (link = snode->edittree->links.first; link; link = link->next) { + if (nodeLinkIsHidden(link)) { + continue; + } + if (link->fromnode && link->tonode && (link->fromnode->flag & NODE_SELECT)) { + link->tonode->flag |= NODE_TEST; + } + } + + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & NODE_TEST) { + nodeSetSelected(node, true); + } + } + + ED_node_sort(snode->edittree); + + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); + return OPERATOR_FINISHED; } void NODE_OT_select_linked_to(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Select Linked To"; - ot->description = "Select nodes linked to the selected ones"; - ot->idname = "NODE_OT_select_linked_to"; + /* identifiers */ + ot->name = "Select Linked To"; + ot->description = "Select nodes linked to the selected ones"; + ot->idname = "NODE_OT_select_linked_to"; - /* api callbacks */ - ot->exec = node_select_linked_to_exec; - ot->poll = ED_operator_node_active; + /* api callbacks */ + ot->exec = node_select_linked_to_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /** \} */ @@ -919,48 +931,48 @@ void NODE_OT_select_linked_to(wmOperatorType *ot) static int node_select_linked_from_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeLink *link; - bNode *node; - - for (node = snode->edittree->nodes.first; node; node = node->next) { - node->flag &= ~NODE_TEST; - } - - for (link = snode->edittree->links.first; link; link = link->next) { - if (nodeLinkIsHidden(link)) { - continue; - } - if (link->fromnode && link->tonode && (link->tonode->flag & NODE_SELECT)) { - link->fromnode->flag |= NODE_TEST; - } - } - - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->flag & NODE_TEST) { - nodeSetSelected(node, true); - } - } - - ED_node_sort(snode->edittree); - - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeLink *link; + bNode *node; + + for (node = snode->edittree->nodes.first; node; node = node->next) { + node->flag &= ~NODE_TEST; + } + + for (link = snode->edittree->links.first; link; link = link->next) { + if (nodeLinkIsHidden(link)) { + continue; + } + if (link->fromnode && link->tonode && (link->tonode->flag & NODE_SELECT)) { + link->fromnode->flag |= NODE_TEST; + } + } + + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & NODE_TEST) { + nodeSetSelected(node, true); + } + } + + ED_node_sort(snode->edittree); + + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); + return OPERATOR_FINISHED; } void NODE_OT_select_linked_from(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Select Linked From"; - ot->description = "Select nodes linked from the selected ones"; - ot->idname = "NODE_OT_select_linked_from"; + /* identifiers */ + ot->name = "Select Linked From"; + ot->description = "Select nodes linked from the selected ones"; + ot->idname = "NODE_OT_select_linked_from"; - /* api callbacks */ - ot->exec = node_select_linked_from_exec; - ot->poll = ED_operator_node_active; + /* api callbacks */ + ot->exec = node_select_linked_from_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /** \} */ @@ -971,106 +983,104 @@ void NODE_OT_select_linked_from(wmOperatorType *ot) static int node_select_same_type_step_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - bNode **node_array; - bNode *active = nodeGetActive(snode->edittree); - int totnodes; - const bool revert = RNA_boolean_get(op->ptr, "prev"); - const bool same_type = 1; - - ntreeGetDependencyList(snode->edittree, &node_array, &totnodes); - - if (totnodes > 1) { - int a; - - for (a = 0; a < totnodes; a++) { - if (node_array[a] == active) { - break; - } - } - - if (same_type) { - bNode *node = NULL; - - while (node == NULL) { - if (revert) { - a--; - } - else { - a++; - } - - if (a < 0 || a >= totnodes) { - break; - } - - node = node_array[a]; - - if (node->type == active->type) { - break; - } - else { - node = NULL; - } - } - if (node) { - active = node; - } - } - else { - if (revert) { - if (a == 0) { - active = node_array[totnodes - 1]; - } - else { - active = node_array[a - 1]; - } - } - else { - if (a == totnodes - 1) { - active = node_array[0]; - } - else { - active = node_array[a + 1]; - } - } - } - - node_select_single(C, active); - - /* is note outside view? */ - if (active->totr.xmax < ar->v2d.cur.xmin || active->totr.xmin > ar->v2d.cur.xmax || - active->totr.ymax < ar->v2d.cur.ymin || active->totr.ymin > ar->v2d.cur.ymax) - { - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - space_node_view_flag(C, snode, ar, NODE_SELECT, smooth_viewtx); - } - } - - if (node_array) { - MEM_freeN(node_array); - } - - return OPERATOR_FINISHED; + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + bNode **node_array; + bNode *active = nodeGetActive(snode->edittree); + int totnodes; + const bool revert = RNA_boolean_get(op->ptr, "prev"); + const bool same_type = 1; + + ntreeGetDependencyList(snode->edittree, &node_array, &totnodes); + + if (totnodes > 1) { + int a; + + for (a = 0; a < totnodes; a++) { + if (node_array[a] == active) { + break; + } + } + + if (same_type) { + bNode *node = NULL; + + while (node == NULL) { + if (revert) { + a--; + } + else { + a++; + } + + if (a < 0 || a >= totnodes) { + break; + } + + node = node_array[a]; + + if (node->type == active->type) { + break; + } + else { + node = NULL; + } + } + if (node) { + active = node; + } + } + else { + if (revert) { + if (a == 0) { + active = node_array[totnodes - 1]; + } + else { + active = node_array[a - 1]; + } + } + else { + if (a == totnodes - 1) { + active = node_array[0]; + } + else { + active = node_array[a + 1]; + } + } + } + + node_select_single(C, active); + + /* is note outside view? */ + if (active->totr.xmax < ar->v2d.cur.xmin || active->totr.xmin > ar->v2d.cur.xmax || + active->totr.ymax < ar->v2d.cur.ymin || active->totr.ymin > ar->v2d.cur.ymax) { + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + space_node_view_flag(C, snode, ar, NODE_SELECT, smooth_viewtx); + } + } + + if (node_array) { + MEM_freeN(node_array); + } + + return OPERATOR_FINISHED; } void NODE_OT_select_same_type_step(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Activate Same Type Next/Prev"; - ot->description = "Activate and view same node type, step by step"; - ot->idname = "NODE_OT_select_same_type_step"; - - /* api callbacks */ - ot->exec = node_select_same_type_step_exec; - ot->poll = ED_operator_node_active; + /* identifiers */ + ot->name = "Activate Same Type Next/Prev"; + ot->description = "Activate and view same node type, step by step"; + ot->idname = "NODE_OT_select_same_type_step"; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* api callbacks */ + ot->exec = node_select_same_type_step_exec; + ot->poll = ED_operator_node_active; - RNA_def_boolean(ot->srna, "prev", 0, "Previous", ""); + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + RNA_def_boolean(ot->srna, "prev", 0, "Previous", ""); } /** \} */ @@ -1080,96 +1090,108 @@ void NODE_OT_select_same_type_step(wmOperatorType *ot) * \{ */ /* generic search invoke */ -static void node_find_cb(const struct bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items) +static void node_find_cb(const struct bContext *C, + void *UNUSED(arg), + const char *str, + uiSearchItems *items) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - - for (node = snode->edittree->nodes.first; node; node = node->next) { - - if (BLI_strcasestr(node->name, str) || BLI_strcasestr(node->label, str)) { - char name[256]; - - if (node->label[0]) { - BLI_snprintf(name, 256, "%s (%s)", node->name, node->label); - } - else { - BLI_strncpy(name, node->name, 256); - } - if (false == UI_search_item_add(items, name, node, 0)) { - break; - } - } - } + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + + for (node = snode->edittree->nodes.first; node; node = node->next) { + + if (BLI_strcasestr(node->name, str) || BLI_strcasestr(node->label, str)) { + char name[256]; + + if (node->label[0]) { + BLI_snprintf(name, 256, "%s (%s)", node->name, node->label); + } + else { + BLI_strncpy(name, node->name, 256); + } + if (false == UI_search_item_add(items, name, node, 0)) { + break; + } + } + } } static void node_find_call_cb(struct bContext *C, void *UNUSED(arg1), void *arg2) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *active = arg2; - - if (active) { - ARegion *ar = CTX_wm_region(C); - node_select_single(C, active); - - /* is note outside view? */ - if (active->totr.xmax < ar->v2d.cur.xmin || active->totr.xmin > ar->v2d.cur.xmax || - active->totr.ymax < ar->v2d.cur.ymin || active->totr.ymin > ar->v2d.cur.ymax) - { - space_node_view_flag(C, snode, ar, NODE_SELECT, U.smooth_viewtx); - } - - } + SpaceNode *snode = CTX_wm_space_node(C); + bNode *active = arg2; + + if (active) { + ARegion *ar = CTX_wm_region(C); + node_select_single(C, active); + + /* is note outside view? */ + if (active->totr.xmax < ar->v2d.cur.xmin || active->totr.xmin > ar->v2d.cur.xmax || + active->totr.ymax < ar->v2d.cur.ymin || active->totr.ymin > ar->v2d.cur.ymax) { + space_node_view_flag(C, snode, ar, NODE_SELECT, U.smooth_viewtx); + } + } } static uiBlock *node_find_menu(bContext *C, ARegion *ar, void *arg_op) { - static char search[256] = ""; - uiBlock *block; - uiBut *but; - wmOperator *op = (wmOperator *)arg_op; - - block = UI_block_begin(C, ar, "_popup", UI_EMBOSS); - UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU); - UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); - - but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, 9 * UI_UNIT_X, UI_UNIT_Y, 0, 0, ""); - UI_but_func_search_set(but, NULL, node_find_cb, op->type, false, node_find_call_cb, NULL); - UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT); - - /* fake button, it holds space for search items */ - uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 10 - UI_searchbox_size_y(), UI_searchbox_size_x(), UI_searchbox_size_y(), NULL, 0, 0, 0, 0, NULL); - - /* Move it downwards, mouse over button. */ - UI_block_bounds_set_popup(block, 6, (const int[2]){0, -UI_UNIT_Y}); - - return block; + static char search[256] = ""; + uiBlock *block; + uiBut *but; + wmOperator *op = (wmOperator *)arg_op; + + block = UI_block_begin(C, ar, "_popup", UI_EMBOSS); + UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU); + UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); + + but = uiDefSearchBut( + block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, 9 * UI_UNIT_X, UI_UNIT_Y, 0, 0, ""); + UI_but_func_search_set(but, NULL, node_find_cb, op->type, false, node_find_call_cb, NULL); + UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT); + + /* fake button, it holds space for search items */ + uiDefBut(block, + UI_BTYPE_LABEL, + 0, + "", + 10, + 10 - UI_searchbox_size_y(), + UI_searchbox_size_x(), + UI_searchbox_size_y(), + NULL, + 0, + 0, + 0, + 0, + NULL); + + /* Move it downwards, mouse over button. */ + UI_block_bounds_set_popup(block, 6, (const int[2]){0, -UI_UNIT_Y}); + + return block; } - static int node_find_node_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - UI_popup_block_invoke(C, node_find_menu, op); - return OPERATOR_CANCELLED; + UI_popup_block_invoke(C, node_find_menu, op); + return OPERATOR_CANCELLED; } - void NODE_OT_find_node(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Find Node"; - ot->description = "Search for named node and allow to select and activate it"; - ot->idname = "NODE_OT_find_node"; - - /* api callbacks */ - ot->invoke = node_find_node_invoke; - ot->poll = ED_operator_node_active; + /* identifiers */ + ot->name = "Find Node"; + ot->description = "Search for named node and allow to select and activate it"; + ot->idname = "NODE_OT_find_node"; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* api callbacks */ + ot->invoke = node_find_node_invoke; + ot->poll = ED_operator_node_active; - RNA_def_boolean(ot->srna, "prev", 0, "Previous", ""); + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + RNA_def_boolean(ot->srna, "prev", 0, "Previous", ""); } /** \} */ diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index aa6fb770c56..8cc57a82fe0 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -42,24 +42,23 @@ #include "NOD_socket.h" #include "UI_interface.h" -#include "../interface/interface_intern.h" /* XXX bad level */ +#include "../interface/interface_intern.h" /* XXX bad level */ -#include "ED_node.h" /* own include */ +#include "ED_node.h" /* own include */ #include "ED_undo.h" - /************************* Node Socket Manipulation **************************/ /* describes an instance of a node type and a specific socket to link */ typedef struct NodeLinkItem { - int socket_index; /* index for linking */ - int socket_type; /* socket type for compatibility check */ - const char *socket_name; /* ui label of the socket */ - const char *node_name; /* ui label of the node */ + int socket_index; /* index for linking */ + int socket_type; /* socket type for compatibility check */ + const char *socket_name; /* ui label of the socket */ + const char *node_name; /* ui label of the node */ - /* extra settings */ - bNodeTree *ngroup; /* group node tree */ + /* extra settings */ + bNodeTree *ngroup; /* group node tree */ } NodeLinkItem; /* Compare an existing node to a link item to see if it can be reused. @@ -68,731 +67,799 @@ typedef struct NodeLinkItem { */ static bool node_link_item_compare(bNode *node, NodeLinkItem *item) { - if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { - return (node->id == (ID *)item->ngroup); - } - else { - return true; - } + if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { + return (node->id == (ID *)item->ngroup); + } + else { + return true; + } } static void node_link_item_apply(Main *bmain, bNode *node, NodeLinkItem *item) { - if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { - node->id = (ID *)item->ngroup; - ntreeUpdateTree(bmain, item->ngroup); - } - else { - /* nothing to do for now */ - } - - if (node->id) { - id_us_plus(node->id); - } + if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { + node->id = (ID *)item->ngroup; + ntreeUpdateTree(bmain, item->ngroup); + } + else { + /* nothing to do for now */ + } + + if (node->id) { + id_us_plus(node->id); + } } static void node_tag_recursive(bNode *node) { - bNodeSocket *input; + bNodeSocket *input; - if (!node || (node->flag & NODE_TEST)) { - return; /* in case of cycles */ - } + if (!node || (node->flag & NODE_TEST)) { + return; /* in case of cycles */ + } - node->flag |= NODE_TEST; + node->flag |= NODE_TEST; - for (input = node->inputs.first; input; input = input->next) { - if (input->link) { - node_tag_recursive(input->link->fromnode); - } - } + for (input = node->inputs.first; input; input = input->next) { + if (input->link) { + node_tag_recursive(input->link->fromnode); + } + } } static void node_clear_recursive(bNode *node) { - bNodeSocket *input; + bNodeSocket *input; - if (!node || !(node->flag & NODE_TEST)) { - return; /* in case of cycles */ - } + if (!node || !(node->flag & NODE_TEST)) { + return; /* in case of cycles */ + } - node->flag &= ~NODE_TEST; + node->flag &= ~NODE_TEST; - for (input = node->inputs.first; input; input = input->next) { - if (input->link) { - node_clear_recursive(input->link->fromnode); - } - } + for (input = node->inputs.first; input; input = input->next) { + if (input->link) { + node_clear_recursive(input->link->fromnode); + } + } } static void node_remove_linked(Main *bmain, bNodeTree *ntree, bNode *rem_node) { - bNode *node, *next; - bNodeSocket *sock; - - if (!rem_node) { - return; - } - - /* tag linked nodes to be removed */ - for (node = ntree->nodes.first; node; node = node->next) { - node->flag &= ~NODE_TEST; - } - - node_tag_recursive(rem_node); - - /* clear tags on nodes that are still used by other nodes */ - for (node = ntree->nodes.first; node; node = node->next) { - if (!(node->flag & NODE_TEST)) { - for (sock = node->inputs.first; sock; sock = sock->next) { - if (sock->link && sock->link->fromnode != rem_node) { - node_clear_recursive(sock->link->fromnode); - } - } - } - } - - /* remove nodes */ - for (node = ntree->nodes.first; node; node = next) { - next = node->next; - - if (node->flag & NODE_TEST) { - nodeRemoveNode(bmain, ntree, node, true); - } - } + bNode *node, *next; + bNodeSocket *sock; + + if (!rem_node) { + return; + } + + /* tag linked nodes to be removed */ + for (node = ntree->nodes.first; node; node = node->next) { + node->flag &= ~NODE_TEST; + } + + node_tag_recursive(rem_node); + + /* clear tags on nodes that are still used by other nodes */ + for (node = ntree->nodes.first; node; node = node->next) { + if (!(node->flag & NODE_TEST)) { + for (sock = node->inputs.first; sock; sock = sock->next) { + if (sock->link && sock->link->fromnode != rem_node) { + node_clear_recursive(sock->link->fromnode); + } + } + } + } + + /* remove nodes */ + for (node = ntree->nodes.first; node; node = next) { + next = node->next; + + if (node->flag & NODE_TEST) { + nodeRemoveNode(bmain, ntree, node, true); + } + } } /* disconnect socket from the node it is connected to */ -static void node_socket_disconnect(Main *bmain, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to) +static void node_socket_disconnect(Main *bmain, + bNodeTree *ntree, + bNode *node_to, + bNodeSocket *sock_to) { - if (!sock_to->link) { - return; - } + if (!sock_to->link) { + return; + } - nodeRemLink(ntree, sock_to->link); - sock_to->flag |= SOCK_COLLAPSED; + nodeRemLink(ntree, sock_to->link); + sock_to->flag |= SOCK_COLLAPSED; - nodeUpdate(ntree, node_to); - ntreeUpdateTree(bmain, ntree); + nodeUpdate(ntree, node_to); + ntreeUpdateTree(bmain, ntree); - ED_node_tag_update_nodetree(bmain, ntree, node_to); + ED_node_tag_update_nodetree(bmain, ntree, node_to); } /* remove all nodes connected to this socket, if they aren't connected to other nodes */ static void node_socket_remove(Main *bmain, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to) { - if (!sock_to->link) { - return; - } + if (!sock_to->link) { + return; + } - node_remove_linked(bmain, ntree, sock_to->link->fromnode); - sock_to->flag |= SOCK_COLLAPSED; + node_remove_linked(bmain, ntree, sock_to->link->fromnode); + sock_to->flag |= SOCK_COLLAPSED; - nodeUpdate(ntree, node_to); - ntreeUpdateTree(bmain, ntree); + nodeUpdate(ntree, node_to); + ntreeUpdateTree(bmain, ntree); - ED_node_tag_update_nodetree(bmain, ntree, node_to); + ED_node_tag_update_nodetree(bmain, ntree, node_to); } /* add new node connected to this socket, or replace an existing one */ -static void node_socket_add_replace(const bContext *C, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to, - int type, NodeLinkItem *item) +static void node_socket_add_replace(const bContext *C, + bNodeTree *ntree, + bNode *node_to, + bNodeSocket *sock_to, + int type, + NodeLinkItem *item) { - Main *bmain = CTX_data_main(C); - bNode *node_from; - bNodeSocket *sock_from_tmp; - bNode *node_prev = NULL; - - /* unlink existing node */ - if (sock_to->link) { - node_prev = sock_to->link->fromnode; - nodeRemLink(ntree, sock_to->link); - } - - /* find existing node that we can use */ - for (node_from = ntree->nodes.first; node_from; node_from = node_from->next) { - if (node_from->type == type) { - break; - } - } - - if (node_from) { - if (node_from->inputs.first || node_from->typeinfo->draw_buttons || node_from->typeinfo->draw_buttons_ex) { - node_from = NULL; - } - } - - if (node_prev && node_prev->type == type && node_link_item_compare(node_prev, item)) { - /* keep the previous node if it's the same type */ - node_from = node_prev; - } - else if (!node_from) { - node_from = nodeAddStaticNode(C, ntree, type); - if (node_prev != NULL) { - /* If we're replacing existing node, use its location. */ - node_from->locx = node_prev->locx; - node_from->locy = node_prev->locy; - node_from->offsetx = node_prev->offsetx; - node_from->offsety = node_prev->offsety; - } - else { - sock_from_tmp = BLI_findlink(&node_from->outputs, item->socket_index); - nodePositionRelative(node_from, node_to, sock_from_tmp, sock_to); - } - - node_link_item_apply(bmain, node_from, item); - } - - nodeSetActive(ntree, node_from); - - /* add link */ - sock_from_tmp = BLI_findlink(&node_from->outputs, item->socket_index); - nodeAddLink(ntree, node_from, sock_from_tmp, node_to, sock_to); - sock_to->flag &= ~SOCK_COLLAPSED; - - /* copy input sockets from previous node */ - if (node_prev && node_from != node_prev) { - bNodeSocket *sock_prev, *sock_from; - - for (sock_prev = node_prev->inputs.first; sock_prev; sock_prev = sock_prev->next) { - for (sock_from = node_from->inputs.first; sock_from; sock_from = sock_from->next) { - if (nodeCountSocketLinks(ntree, sock_from) >= sock_from->limit) { - continue; - } - - if (STREQ(sock_prev->name, sock_from->name) && sock_prev->type == sock_from->type) { - bNodeLink *link = sock_prev->link; - - if (link && link->fromnode) { - nodeAddLink(ntree, link->fromnode, link->fromsock, node_from, sock_from); - nodeRemLink(ntree, link); - } - - node_socket_copy_default_value(sock_from, sock_prev); - } - } - } - - /* also preserve mapping for texture nodes */ - if (node_from->typeinfo->nclass == NODE_CLASS_TEXTURE && - node_prev->typeinfo->nclass == NODE_CLASS_TEXTURE) - { - memcpy(node_from->storage, node_prev->storage, sizeof(NodeTexBase)); - } - - /* remove node */ - node_remove_linked(bmain, ntree, node_prev); - } - - nodeUpdate(ntree, node_from); - nodeUpdate(ntree, node_to); - ntreeUpdateTree(CTX_data_main(C), ntree); - - ED_node_tag_update_nodetree(CTX_data_main(C), ntree, node_to); + Main *bmain = CTX_data_main(C); + bNode *node_from; + bNodeSocket *sock_from_tmp; + bNode *node_prev = NULL; + + /* unlink existing node */ + if (sock_to->link) { + node_prev = sock_to->link->fromnode; + nodeRemLink(ntree, sock_to->link); + } + + /* find existing node that we can use */ + for (node_from = ntree->nodes.first; node_from; node_from = node_from->next) { + if (node_from->type == type) { + break; + } + } + + if (node_from) { + if (node_from->inputs.first || node_from->typeinfo->draw_buttons || + node_from->typeinfo->draw_buttons_ex) { + node_from = NULL; + } + } + + if (node_prev && node_prev->type == type && node_link_item_compare(node_prev, item)) { + /* keep the previous node if it's the same type */ + node_from = node_prev; + } + else if (!node_from) { + node_from = nodeAddStaticNode(C, ntree, type); + if (node_prev != NULL) { + /* If we're replacing existing node, use its location. */ + node_from->locx = node_prev->locx; + node_from->locy = node_prev->locy; + node_from->offsetx = node_prev->offsetx; + node_from->offsety = node_prev->offsety; + } + else { + sock_from_tmp = BLI_findlink(&node_from->outputs, item->socket_index); + nodePositionRelative(node_from, node_to, sock_from_tmp, sock_to); + } + + node_link_item_apply(bmain, node_from, item); + } + + nodeSetActive(ntree, node_from); + + /* add link */ + sock_from_tmp = BLI_findlink(&node_from->outputs, item->socket_index); + nodeAddLink(ntree, node_from, sock_from_tmp, node_to, sock_to); + sock_to->flag &= ~SOCK_COLLAPSED; + + /* copy input sockets from previous node */ + if (node_prev && node_from != node_prev) { + bNodeSocket *sock_prev, *sock_from; + + for (sock_prev = node_prev->inputs.first; sock_prev; sock_prev = sock_prev->next) { + for (sock_from = node_from->inputs.first; sock_from; sock_from = sock_from->next) { + if (nodeCountSocketLinks(ntree, sock_from) >= sock_from->limit) { + continue; + } + + if (STREQ(sock_prev->name, sock_from->name) && sock_prev->type == sock_from->type) { + bNodeLink *link = sock_prev->link; + + if (link && link->fromnode) { + nodeAddLink(ntree, link->fromnode, link->fromsock, node_from, sock_from); + nodeRemLink(ntree, link); + } + + node_socket_copy_default_value(sock_from, sock_prev); + } + } + } + + /* also preserve mapping for texture nodes */ + if (node_from->typeinfo->nclass == NODE_CLASS_TEXTURE && + node_prev->typeinfo->nclass == NODE_CLASS_TEXTURE) { + memcpy(node_from->storage, node_prev->storage, sizeof(NodeTexBase)); + } + + /* remove node */ + node_remove_linked(bmain, ntree, node_prev); + } + + nodeUpdate(ntree, node_from); + nodeUpdate(ntree, node_to); + ntreeUpdateTree(CTX_data_main(C), ntree); + + ED_node_tag_update_nodetree(CTX_data_main(C), ntree, node_to); } /****************************** Node Link Menu *******************************/ // #define UI_NODE_LINK_ADD 0 #define UI_NODE_LINK_DISCONNECT -1 -#define UI_NODE_LINK_REMOVE -2 +#define UI_NODE_LINK_REMOVE -2 typedef struct NodeLinkArg { - Main *bmain; - Scene *scene; - bNodeTree *ntree; - bNode *node; - bNodeSocket *sock; + Main *bmain; + Scene *scene; + bNodeTree *ntree; + bNode *node; + bNodeSocket *sock; - bNodeType *node_type; - NodeLinkItem item; + bNodeType *node_type; + NodeLinkItem item; - uiLayout *layout; + uiLayout *layout; } NodeLinkArg; -static void ui_node_link_items(NodeLinkArg *arg, int in_out, NodeLinkItem **r_items, int *r_totitems) +static void ui_node_link_items(NodeLinkArg *arg, + int in_out, + NodeLinkItem **r_items, + int *r_totitems) { - /* XXX this should become a callback for node types! */ - NodeLinkItem *items = NULL; - int totitems = 0; - - if (arg->node_type->type == NODE_GROUP) { - bNodeTree *ngroup; - int i; - - for (ngroup = arg->bmain->nodetrees.first; ngroup; ngroup = ngroup->id.next) { - ListBase *lb = ((in_out == SOCK_IN) ? &ngroup->inputs : &ngroup->outputs); - totitems += BLI_listbase_count(lb); - } - - if (totitems > 0) { - items = MEM_callocN(sizeof(NodeLinkItem) * totitems, "ui node link items"); - - i = 0; - for (ngroup = arg->bmain->nodetrees.first; ngroup; ngroup = ngroup->id.next) { - ListBase *lb = (in_out == SOCK_IN ? &ngroup->inputs : &ngroup->outputs); - bNodeSocket *stemp; - int index; - for (stemp = lb->first, index = 0; stemp; stemp = stemp->next, ++index, ++i) { - NodeLinkItem *item = &items[i]; - - item->socket_index = index; - /* note: int stemp->type is not fully reliable, not used for node group - * interface sockets. use the typeinfo->type instead. - */ - item->socket_type = stemp->typeinfo->type; - item->socket_name = stemp->name; - item->node_name = ngroup->id.name + 2; - item->ngroup = ngroup; - } - } - } - } - else { - bNodeSocketTemplate *socket_templates = (in_out == SOCK_IN ? arg->node_type->inputs : arg->node_type->outputs); - bNodeSocketTemplate *stemp; - int i; - - for (stemp = socket_templates; stemp && stemp->type != -1; ++stemp) { - ++totitems; - } - - if (totitems > 0) { - items = MEM_callocN(sizeof(NodeLinkItem) * totitems, "ui node link items"); - - i = 0; - for (stemp = socket_templates; stemp && stemp->type != -1; ++stemp, ++i) { - NodeLinkItem *item = &items[i]; - - item->socket_index = i; - item->socket_type = stemp->type; - item->socket_name = stemp->name; - item->node_name = arg->node_type->ui_name; - } - } - } - - *r_items = items; - *r_totitems = totitems; + /* XXX this should become a callback for node types! */ + NodeLinkItem *items = NULL; + int totitems = 0; + + if (arg->node_type->type == NODE_GROUP) { + bNodeTree *ngroup; + int i; + + for (ngroup = arg->bmain->nodetrees.first; ngroup; ngroup = ngroup->id.next) { + ListBase *lb = ((in_out == SOCK_IN) ? &ngroup->inputs : &ngroup->outputs); + totitems += BLI_listbase_count(lb); + } + + if (totitems > 0) { + items = MEM_callocN(sizeof(NodeLinkItem) * totitems, "ui node link items"); + + i = 0; + for (ngroup = arg->bmain->nodetrees.first; ngroup; ngroup = ngroup->id.next) { + ListBase *lb = (in_out == SOCK_IN ? &ngroup->inputs : &ngroup->outputs); + bNodeSocket *stemp; + int index; + for (stemp = lb->first, index = 0; stemp; stemp = stemp->next, ++index, ++i) { + NodeLinkItem *item = &items[i]; + + item->socket_index = index; + /* note: int stemp->type is not fully reliable, not used for node group + * interface sockets. use the typeinfo->type instead. + */ + item->socket_type = stemp->typeinfo->type; + item->socket_name = stemp->name; + item->node_name = ngroup->id.name + 2; + item->ngroup = ngroup; + } + } + } + } + else { + bNodeSocketTemplate *socket_templates = (in_out == SOCK_IN ? arg->node_type->inputs : + arg->node_type->outputs); + bNodeSocketTemplate *stemp; + int i; + + for (stemp = socket_templates; stemp && stemp->type != -1; ++stemp) { + ++totitems; + } + + if (totitems > 0) { + items = MEM_callocN(sizeof(NodeLinkItem) * totitems, "ui node link items"); + + i = 0; + for (stemp = socket_templates; stemp && stemp->type != -1; ++stemp, ++i) { + NodeLinkItem *item = &items[i]; + + item->socket_index = i; + item->socket_type = stemp->type; + item->socket_name = stemp->name; + item->node_name = arg->node_type->ui_name; + } + } + } + + *r_items = items; + *r_totitems = totitems; } static void ui_node_link(bContext *C, void *arg_p, void *event_p) { - NodeLinkArg *arg = (NodeLinkArg *)arg_p; - Main *bmain = arg->bmain; - bNode *node_to = arg->node; - bNodeSocket *sock_to = arg->sock; - bNodeTree *ntree = arg->ntree; - int event = POINTER_AS_INT(event_p); - - if (event == UI_NODE_LINK_DISCONNECT) { - node_socket_disconnect(bmain, ntree, node_to, sock_to); - } - else if (event == UI_NODE_LINK_REMOVE) { - node_socket_remove(bmain, ntree, node_to, sock_to); - } - else { - node_socket_add_replace(C, ntree, node_to, sock_to, arg->node_type->type, &arg->item); - } - - ED_undo_push(C, "Node input modify"); + NodeLinkArg *arg = (NodeLinkArg *)arg_p; + Main *bmain = arg->bmain; + bNode *node_to = arg->node; + bNodeSocket *sock_to = arg->sock; + bNodeTree *ntree = arg->ntree; + int event = POINTER_AS_INT(event_p); + + if (event == UI_NODE_LINK_DISCONNECT) { + node_socket_disconnect(bmain, ntree, node_to, sock_to); + } + else if (event == UI_NODE_LINK_REMOVE) { + node_socket_remove(bmain, ntree, node_to, sock_to); + } + else { + node_socket_add_replace(C, ntree, node_to, sock_to, arg->node_type->type, &arg->item); + } + + ED_undo_push(C, "Node input modify"); } static void ui_node_sock_name(bNodeTree *ntree, bNodeSocket *sock, char name[UI_MAX_NAME_STR]) { - if (sock->link && sock->link->fromnode) { - bNode *node = sock->link->fromnode; - char node_name[UI_MAX_NAME_STR]; - - nodeLabel(ntree, node, node_name, sizeof(node_name)); - - if (BLI_listbase_is_empty(&node->inputs) && - node->outputs.first != node->outputs.last) - { - BLI_snprintf(name, UI_MAX_NAME_STR, "%s | %s", IFACE_(node_name), IFACE_(sock->link->fromsock->name)); - } - else { - BLI_strncpy(name, IFACE_(node_name), UI_MAX_NAME_STR); - } - } - else if (sock->type == SOCK_SHADER) { - BLI_strncpy(name, IFACE_("None"), UI_MAX_NAME_STR); - } - else { - BLI_strncpy(name, IFACE_("Default"), UI_MAX_NAME_STR); - } + if (sock->link && sock->link->fromnode) { + bNode *node = sock->link->fromnode; + char node_name[UI_MAX_NAME_STR]; + + nodeLabel(ntree, node, node_name, sizeof(node_name)); + + if (BLI_listbase_is_empty(&node->inputs) && node->outputs.first != node->outputs.last) { + BLI_snprintf( + name, UI_MAX_NAME_STR, "%s | %s", IFACE_(node_name), IFACE_(sock->link->fromsock->name)); + } + else { + BLI_strncpy(name, IFACE_(node_name), UI_MAX_NAME_STR); + } + } + else if (sock->type == SOCK_SHADER) { + BLI_strncpy(name, IFACE_("None"), UI_MAX_NAME_STR); + } + else { + BLI_strncpy(name, IFACE_("Default"), UI_MAX_NAME_STR); + } } static int ui_compatible_sockets(int typeA, int typeB) { - return (typeA == typeB); + return (typeA == typeB); } static int ui_node_item_name_compare(const void *a, const void *b) { - const bNodeType *type_a = *(const bNodeType **)a; - const bNodeType *type_b = *(const bNodeType **)b; - return BLI_natstrcmp(type_a->ui_name, type_b->ui_name); + const bNodeType *type_a = *(const bNodeType **)a; + const bNodeType *type_b = *(const bNodeType **)b; + return BLI_natstrcmp(type_a->ui_name, type_b->ui_name); } -static bool ui_node_item_special_poll(const bNodeTree *UNUSED(ntree), - const bNodeType *ntype) +static bool ui_node_item_special_poll(const bNodeTree *UNUSED(ntree), const bNodeType *ntype) { - if (STREQ(ntype->idname, "ShaderNodeUVAlongStroke")) { - /* TODO(sergey): Currently we don't have Freestyle nodes edited from - * the buttons context, so can ignore it's nodes completely. - * - * However, we might want to do some extra checks here later. - */ - return false; - } - return true; + if (STREQ(ntype->idname, "ShaderNodeUVAlongStroke")) { + /* TODO(sergey): Currently we don't have Freestyle nodes edited from + * the buttons context, so can ignore it's nodes completely. + * + * However, we might want to do some extra checks here later. + */ + return false; + } + return true; } static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname) { - bNodeTree *ntree = arg->ntree; - bNodeSocket *sock = arg->sock; - uiLayout *layout = arg->layout; - uiLayout *column = NULL; - uiBlock *block = uiLayoutGetBlock(layout); - uiBut *but; - NodeLinkArg *argN; - int first = 1; - - /* generate array of node types sorted by UI name */ - bNodeType **sorted_ntypes = NULL; - BLI_array_declare(sorted_ntypes); - - NODE_TYPES_BEGIN(ntype) { - if (!(ntype->poll && ntype->poll(ntype, ntree))) { - continue; - } - - if (ntype->nclass != nclass) { - continue; - } - - if (!ui_node_item_special_poll(ntree, ntype)) { - continue; - } - - BLI_array_append(sorted_ntypes, ntype); - } NODE_TYPES_END; - - qsort(sorted_ntypes, BLI_array_len(sorted_ntypes), sizeof(bNodeType *), ui_node_item_name_compare); - - /* generate UI */ - for (int j = 0; j < BLI_array_len(sorted_ntypes); j++) { - bNodeType *ntype = sorted_ntypes[j]; - NodeLinkItem *items; - int totitems; - char name[UI_MAX_NAME_STR]; - const char *cur_node_name = NULL; - int i, num = 0; - int icon = ICON_NONE; - - arg->node_type = ntype; - - ui_node_link_items(arg, SOCK_OUT, &items, &totitems); - - for (i = 0; i < totitems; ++i) { - if (ui_compatible_sockets(items[i].socket_type, sock->type)) { - num++; - } - } - - for (i = 0; i < totitems; ++i) { - if (!ui_compatible_sockets(items[i].socket_type, sock->type)) { - continue; - } - - if (first) { - column = uiLayoutColumn(layout, 0); - UI_block_layout_set_current(block, column); - - uiItemL(column, IFACE_(cname), ICON_NODE); - but = block->buttons.last; - - first = 0; - } - - if (num > 1) { - if (!cur_node_name || !STREQ(cur_node_name, items[i].node_name)) { - cur_node_name = items[i].node_name; - /* XXX Do not use uiItemL here, - * it would add an empty icon as we are in a menu! */ - uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_(cur_node_name), 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, - NULL, 0.0, 0.0, 0.0, 0.0, ""); - } - - BLI_snprintf(name, UI_MAX_NAME_STR, "%s", IFACE_(items[i].socket_name)); - icon = ICON_BLANK1; - } - else { - BLI_strncpy(name, IFACE_(items[i].node_name), UI_MAX_NAME_STR); - icon = ICON_NONE; - } - - but = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, icon, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, - NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Add node to input")); - - argN = MEM_dupallocN(arg); - argN->item = items[i]; - UI_but_funcN_set(but, ui_node_link, argN, NULL); - } - - if (items) { - MEM_freeN(items); - } - } - - BLI_array_free(sorted_ntypes); + bNodeTree *ntree = arg->ntree; + bNodeSocket *sock = arg->sock; + uiLayout *layout = arg->layout; + uiLayout *column = NULL; + uiBlock *block = uiLayoutGetBlock(layout); + uiBut *but; + NodeLinkArg *argN; + int first = 1; + + /* generate array of node types sorted by UI name */ + bNodeType **sorted_ntypes = NULL; + BLI_array_declare(sorted_ntypes); + + NODE_TYPES_BEGIN (ntype) { + if (!(ntype->poll && ntype->poll(ntype, ntree))) { + continue; + } + + if (ntype->nclass != nclass) { + continue; + } + + if (!ui_node_item_special_poll(ntree, ntype)) { + continue; + } + + BLI_array_append(sorted_ntypes, ntype); + } + NODE_TYPES_END; + + qsort( + sorted_ntypes, BLI_array_len(sorted_ntypes), sizeof(bNodeType *), ui_node_item_name_compare); + + /* generate UI */ + for (int j = 0; j < BLI_array_len(sorted_ntypes); j++) { + bNodeType *ntype = sorted_ntypes[j]; + NodeLinkItem *items; + int totitems; + char name[UI_MAX_NAME_STR]; + const char *cur_node_name = NULL; + int i, num = 0; + int icon = ICON_NONE; + + arg->node_type = ntype; + + ui_node_link_items(arg, SOCK_OUT, &items, &totitems); + + for (i = 0; i < totitems; ++i) { + if (ui_compatible_sockets(items[i].socket_type, sock->type)) { + num++; + } + } + + for (i = 0; i < totitems; ++i) { + if (!ui_compatible_sockets(items[i].socket_type, sock->type)) { + continue; + } + + if (first) { + column = uiLayoutColumn(layout, 0); + UI_block_layout_set_current(block, column); + + uiItemL(column, IFACE_(cname), ICON_NODE); + but = block->buttons.last; + + first = 0; + } + + if (num > 1) { + if (!cur_node_name || !STREQ(cur_node_name, items[i].node_name)) { + cur_node_name = items[i].node_name; + /* XXX Do not use uiItemL here, + * it would add an empty icon as we are in a menu! */ + uiDefBut(block, + UI_BTYPE_LABEL, + 0, + IFACE_(cur_node_name), + 0, + 0, + UI_UNIT_X * 4, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + ""); + } + + BLI_snprintf(name, UI_MAX_NAME_STR, "%s", IFACE_(items[i].socket_name)); + icon = ICON_BLANK1; + } + else { + BLI_strncpy(name, IFACE_(items[i].node_name), UI_MAX_NAME_STR); + icon = ICON_NONE; + } + + but = uiDefIconTextBut(block, + UI_BTYPE_BUT, + 0, + icon, + name, + 0, + 0, + UI_UNIT_X * 4, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + TIP_("Add node to input")); + + argN = MEM_dupallocN(arg); + argN->item = items[i]; + UI_but_funcN_set(but, ui_node_link, argN, NULL); + } + + if (items) { + MEM_freeN(items); + } + } + + BLI_array_free(sorted_ntypes); } static void node_menu_column_foreach_cb(void *calldata, int nclass, const char *name) { - NodeLinkArg *arg = (NodeLinkArg *)calldata; + NodeLinkArg *arg = (NodeLinkArg *)calldata; - if (!ELEM(nclass, NODE_CLASS_GROUP, NODE_CLASS_LAYOUT)) { - ui_node_menu_column(arg, nclass, name); - } + if (!ELEM(nclass, NODE_CLASS_GROUP, NODE_CLASS_LAYOUT)) { + ui_node_menu_column(arg, nclass, name); + } } static void ui_template_node_link_menu(bContext *C, uiLayout *layout, void *but_p) { - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - uiBlock *block = uiLayoutGetBlock(layout); - uiBut *but = (uiBut *)but_p; - uiLayout *split, *column; - NodeLinkArg *arg = (NodeLinkArg *)but->func_argN; - bNodeSocket *sock = arg->sock; - bNodeTreeType *ntreetype = arg->ntree->typeinfo; - - UI_block_flag_enable(block, UI_BLOCK_NO_FLIP | UI_BLOCK_IS_FLIP); - UI_block_layout_set_current(block, layout); - split = uiLayoutSplit(layout, 0.0f, false); - - arg->bmain = bmain; - arg->scene = scene; - arg->layout = split; - - if (ntreetype && ntreetype->foreach_nodeclass) { - ntreetype->foreach_nodeclass(scene, arg, node_menu_column_foreach_cb); - } - - column = uiLayoutColumn(split, false); - UI_block_layout_set_current(block, column); - - if (sock->link) { - uiItemL(column, IFACE_("Link"), ICON_NONE); - but = block->buttons.last; - but->drawflag = UI_BUT_TEXT_LEFT; - - but = uiDefBut(block, UI_BTYPE_BUT, 0, IFACE_("Remove"), 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, - NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Remove nodes connected to the input")); - UI_but_funcN_set(but, ui_node_link, MEM_dupallocN(arg), POINTER_FROM_INT(UI_NODE_LINK_REMOVE)); - - but = uiDefBut(block, UI_BTYPE_BUT, 0, IFACE_("Disconnect"), 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, - NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Disconnect nodes connected to the input")); - UI_but_funcN_set(but, ui_node_link, MEM_dupallocN(arg), POINTER_FROM_INT(UI_NODE_LINK_DISCONNECT)); - } - - ui_node_menu_column(arg, NODE_CLASS_GROUP, N_("Group")); + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + uiBlock *block = uiLayoutGetBlock(layout); + uiBut *but = (uiBut *)but_p; + uiLayout *split, *column; + NodeLinkArg *arg = (NodeLinkArg *)but->func_argN; + bNodeSocket *sock = arg->sock; + bNodeTreeType *ntreetype = arg->ntree->typeinfo; + + UI_block_flag_enable(block, UI_BLOCK_NO_FLIP | UI_BLOCK_IS_FLIP); + UI_block_layout_set_current(block, layout); + split = uiLayoutSplit(layout, 0.0f, false); + + arg->bmain = bmain; + arg->scene = scene; + arg->layout = split; + + if (ntreetype && ntreetype->foreach_nodeclass) { + ntreetype->foreach_nodeclass(scene, arg, node_menu_column_foreach_cb); + } + + column = uiLayoutColumn(split, false); + UI_block_layout_set_current(block, column); + + if (sock->link) { + uiItemL(column, IFACE_("Link"), ICON_NONE); + but = block->buttons.last; + but->drawflag = UI_BUT_TEXT_LEFT; + + but = uiDefBut(block, + UI_BTYPE_BUT, + 0, + IFACE_("Remove"), + 0, + 0, + UI_UNIT_X * 4, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + TIP_("Remove nodes connected to the input")); + UI_but_funcN_set(but, ui_node_link, MEM_dupallocN(arg), POINTER_FROM_INT(UI_NODE_LINK_REMOVE)); + + but = uiDefBut(block, + UI_BTYPE_BUT, + 0, + IFACE_("Disconnect"), + 0, + 0, + UI_UNIT_X * 4, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + TIP_("Disconnect nodes connected to the input")); + UI_but_funcN_set( + but, ui_node_link, MEM_dupallocN(arg), POINTER_FROM_INT(UI_NODE_LINK_DISCONNECT)); + } + + ui_node_menu_column(arg, NODE_CLASS_GROUP, N_("Group")); } void uiTemplateNodeLink(uiLayout *layout, bNodeTree *ntree, bNode *node, bNodeSocket *sock) { - uiBlock *block = uiLayoutGetBlock(layout); - NodeLinkArg *arg; - uiBut *but; - - arg = MEM_callocN(sizeof(NodeLinkArg), "NodeLinkArg"); - arg->ntree = ntree; - arg->node = node; - arg->sock = sock; - - UI_block_layout_set_current(block, layout); - - if (sock->link || sock->type == SOCK_SHADER || (sock->flag & SOCK_HIDE_VALUE)) { - char name[UI_MAX_NAME_STR]; - ui_node_sock_name(ntree, sock, name); - but = uiDefMenuBut(block, ui_template_node_link_menu, NULL, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, ""); - } - else { - but = uiDefIconMenuBut(block, ui_template_node_link_menu, NULL, ICON_NONE, 0, 0, UI_UNIT_X, UI_UNIT_Y, ""); - } - - UI_but_type_set_menu_from_pulldown(but); - - but->flag |= UI_BUT_NODE_LINK; - but->poin = (char *)but; - but->func_argN = arg; - - if (sock->link && sock->link->fromnode) { - if (sock->link->fromnode->flag & NODE_ACTIVE_TEXTURE) { - but->flag |= UI_BUT_NODE_ACTIVE; - } - } + uiBlock *block = uiLayoutGetBlock(layout); + NodeLinkArg *arg; + uiBut *but; + + arg = MEM_callocN(sizeof(NodeLinkArg), "NodeLinkArg"); + arg->ntree = ntree; + arg->node = node; + arg->sock = sock; + + UI_block_layout_set_current(block, layout); + + if (sock->link || sock->type == SOCK_SHADER || (sock->flag & SOCK_HIDE_VALUE)) { + char name[UI_MAX_NAME_STR]; + ui_node_sock_name(ntree, sock, name); + but = uiDefMenuBut( + block, ui_template_node_link_menu, NULL, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, ""); + } + else { + but = uiDefIconMenuBut( + block, ui_template_node_link_menu, NULL, ICON_NONE, 0, 0, UI_UNIT_X, UI_UNIT_Y, ""); + } + + UI_but_type_set_menu_from_pulldown(but); + + but->flag |= UI_BUT_NODE_LINK; + but->poin = (char *)but; + but->func_argN = arg; + + if (sock->link && sock->link->fromnode) { + if (sock->link->fromnode->flag & NODE_ACTIVE_TEXTURE) { + but->flag |= UI_BUT_NODE_ACTIVE; + } + } } /**************************** Node Tree Layout *******************************/ -static void ui_node_draw_input(uiLayout *layout, bContext *C, - bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth); +static void ui_node_draw_input( + uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth); -static void ui_node_draw_node(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, int depth) +static void ui_node_draw_node( + uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, int depth) { - bNodeSocket *input; - uiLayout *col, *split; - PointerRNA nodeptr; + bNodeSocket *input; + uiLayout *col, *split; + PointerRNA nodeptr; - RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr); + RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr); - if (node->typeinfo->draw_buttons) { - if (node->type != NODE_GROUP) { - split = uiLayoutSplit(layout, 0.5f, false); - col = uiLayoutColumn(split, false); - col = uiLayoutColumn(split, false); + if (node->typeinfo->draw_buttons) { + if (node->type != NODE_GROUP) { + split = uiLayoutSplit(layout, 0.5f, false); + col = uiLayoutColumn(split, false); + col = uiLayoutColumn(split, false); - node->typeinfo->draw_buttons(col, C, &nodeptr); - } - } + node->typeinfo->draw_buttons(col, C, &nodeptr); + } + } - for (input = node->inputs.first; input; input = input->next) { - ui_node_draw_input(layout, C, ntree, node, input, depth + 1); - } + for (input = node->inputs.first; input; input = input->next) { + ui_node_draw_input(layout, C, ntree, node, input, depth + 1); + } } -static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth) +static void ui_node_draw_input( + uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth) { - PointerRNA inputptr, nodeptr; - uiBlock *block = uiLayoutGetBlock(layout); - uiBut *bt; - uiLayout *split, *row, *col; - bNode *lnode; - char label[UI_MAX_NAME_STR]; - int i, indent = (depth > 1) ? 2 * (depth - 1) : 0; - int dependency_loop; - - if (input->flag & SOCK_UNAVAIL) { - return; - } - - /* to avoid eternal loops on cyclic dependencies */ - node->flag |= NODE_TEST; - lnode = (input->link) ? input->link->fromnode : NULL; - - dependency_loop = (lnode && (lnode->flag & NODE_TEST)); - if (dependency_loop) { - lnode = NULL; - } - - /* socket RNA pointer */ - RNA_pointer_create(&ntree->id, &RNA_NodeSocket, input, &inputptr); - RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr); - - /* indented label */ - for (i = 0; i < indent; i++) { - label[i] = ' '; - } - label[indent] = '\0'; - BLI_snprintf(label + indent, UI_MAX_NAME_STR - indent, "%s", IFACE_(input->name)); - - /* split in label and value */ - split = uiLayoutSplit(layout, 0.5f, false); - - row = uiLayoutRow(split, true); - - if (depth > 0) { - UI_block_emboss_set(block, UI_EMBOSS_NONE); - - if (lnode && (lnode->inputs.first || (lnode->typeinfo->draw_buttons && lnode->type != NODE_GROUP))) { - int icon = (input->flag & SOCK_COLLAPSED) ? ICON_DISCLOSURE_TRI_RIGHT : ICON_DISCLOSURE_TRI_DOWN; - uiItemR(row, &inputptr, "show_expanded", UI_ITEM_R_ICON_ONLY, "", icon); - } - else { - uiItemL(row, "", ICON_BLANK1); - } - - bt = block->buttons.last; - bt->rect.xmax = UI_UNIT_X / 2; - - UI_block_emboss_set(block, UI_EMBOSS); - } - - uiItemL(row, label, ICON_NONE); - bt = block->buttons.last; - bt->drawflag = UI_BUT_TEXT_RIGHT; - - if (dependency_loop) { - row = uiLayoutRow(split, false); - uiItemL(row, IFACE_("Dependency Loop"), ICON_ERROR); - } - else if (lnode) { - /* input linked to a node */ - uiTemplateNodeLink(split, ntree, node, input); - - if (depth == 0 || !(input->flag & SOCK_COLLAPSED)) { - if (depth == 0) { - uiItemS(layout); - } - - ui_node_draw_node(layout, C, ntree, lnode, depth); - } - } - else { - /* input not linked, show value */ - if (!(input->flag & SOCK_HIDE_VALUE)) { - switch (input->type) { - case SOCK_FLOAT: - case SOCK_INT: - case SOCK_BOOLEAN: - case SOCK_RGBA: - case SOCK_STRING: - row = uiLayoutRow(split, true); - uiItemR(row, &inputptr, "default_value", 0, "", ICON_NONE); - break; - case SOCK_VECTOR: - row = uiLayoutRow(split, false); - col = uiLayoutColumn(row, false); - uiItemR(col, &inputptr, "default_value", 0, "", ICON_NONE); - break; - - default: - row = uiLayoutRow(split, false); - break; - } - } - else { - row = uiLayoutRow(split, false); - } - - uiTemplateNodeLink(row, ntree, node, input); - } - - /* clear */ - node->flag &= ~NODE_TEST; + PointerRNA inputptr, nodeptr; + uiBlock *block = uiLayoutGetBlock(layout); + uiBut *bt; + uiLayout *split, *row, *col; + bNode *lnode; + char label[UI_MAX_NAME_STR]; + int i, indent = (depth > 1) ? 2 * (depth - 1) : 0; + int dependency_loop; + + if (input->flag & SOCK_UNAVAIL) { + return; + } + + /* to avoid eternal loops on cyclic dependencies */ + node->flag |= NODE_TEST; + lnode = (input->link) ? input->link->fromnode : NULL; + + dependency_loop = (lnode && (lnode->flag & NODE_TEST)); + if (dependency_loop) { + lnode = NULL; + } + + /* socket RNA pointer */ + RNA_pointer_create(&ntree->id, &RNA_NodeSocket, input, &inputptr); + RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr); + + /* indented label */ + for (i = 0; i < indent; i++) { + label[i] = ' '; + } + label[indent] = '\0'; + BLI_snprintf(label + indent, UI_MAX_NAME_STR - indent, "%s", IFACE_(input->name)); + + /* split in label and value */ + split = uiLayoutSplit(layout, 0.5f, false); + + row = uiLayoutRow(split, true); + + if (depth > 0) { + UI_block_emboss_set(block, UI_EMBOSS_NONE); + + if (lnode && + (lnode->inputs.first || (lnode->typeinfo->draw_buttons && lnode->type != NODE_GROUP))) { + int icon = (input->flag & SOCK_COLLAPSED) ? ICON_DISCLOSURE_TRI_RIGHT : + ICON_DISCLOSURE_TRI_DOWN; + uiItemR(row, &inputptr, "show_expanded", UI_ITEM_R_ICON_ONLY, "", icon); + } + else { + uiItemL(row, "", ICON_BLANK1); + } + + bt = block->buttons.last; + bt->rect.xmax = UI_UNIT_X / 2; + + UI_block_emboss_set(block, UI_EMBOSS); + } + + uiItemL(row, label, ICON_NONE); + bt = block->buttons.last; + bt->drawflag = UI_BUT_TEXT_RIGHT; + + if (dependency_loop) { + row = uiLayoutRow(split, false); + uiItemL(row, IFACE_("Dependency Loop"), ICON_ERROR); + } + else if (lnode) { + /* input linked to a node */ + uiTemplateNodeLink(split, ntree, node, input); + + if (depth == 0 || !(input->flag & SOCK_COLLAPSED)) { + if (depth == 0) { + uiItemS(layout); + } + + ui_node_draw_node(layout, C, ntree, lnode, depth); + } + } + else { + /* input not linked, show value */ + if (!(input->flag & SOCK_HIDE_VALUE)) { + switch (input->type) { + case SOCK_FLOAT: + case SOCK_INT: + case SOCK_BOOLEAN: + case SOCK_RGBA: + case SOCK_STRING: + row = uiLayoutRow(split, true); + uiItemR(row, &inputptr, "default_value", 0, "", ICON_NONE); + break; + case SOCK_VECTOR: + row = uiLayoutRow(split, false); + col = uiLayoutColumn(row, false); + uiItemR(col, &inputptr, "default_value", 0, "", ICON_NONE); + break; + + default: + row = uiLayoutRow(split, false); + break; + } + } + else { + row = uiLayoutRow(split, false); + } + + uiTemplateNodeLink(row, ntree, node, input); + } + + /* clear */ + node->flag &= ~NODE_TEST; } -void uiTemplateNodeView(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input) +void uiTemplateNodeView( + uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input) { - bNode *tnode; - - if (!ntree) { - return; - } - - /* clear for cycle check */ - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { - tnode->flag &= ~NODE_TEST; - } - - if (input) { - ui_node_draw_input(layout, C, ntree, node, input, 0); - } - else { - ui_node_draw_node(layout, C, ntree, node, 0); - } + bNode *tnode; + + if (!ntree) { + return; + } + + /* clear for cycle check */ + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { + tnode->flag &= ~NODE_TEST; + } + + if (input) { + ui_node_draw_input(layout, C, ntree, node, input, 0); + } + else { + ui_node_draw_node(layout, C, ntree, node, 0); + } } diff --git a/source/blender/editors/space_node/node_toolbar.c b/source/blender/editors/space_node/node_toolbar.c index dae8024611a..bc7119fa4ab 100644 --- a/source/blender/editors/space_node/node_toolbar.c +++ b/source/blender/editors/space_node/node_toolbar.c @@ -33,8 +33,7 @@ #include "ED_screen.h" -#include "node_intern.h" /* own include */ - +#include "node_intern.h" /* own include */ /* ******************* node toolbar registration ************** */ @@ -46,32 +45,32 @@ void node_toolbar_register(ARegionType *UNUSED(art)) static int node_toolbar_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { - ScrArea *sa = CTX_wm_area(C); - ARegion *ar = node_has_tools_region(sa); + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = node_has_tools_region(sa); - if (ar) { - ED_region_toggle_hidden(C, ar); - } + if (ar) { + ED_region_toggle_hidden(C, ar); + } - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } /* non-standard poll operator which doesn't care if there are any nodes */ static bool node_toolbar_poll(bContext *C) { - ScrArea *sa = CTX_wm_area(C); - return (sa && (sa->spacetype == SPACE_NODE)); + ScrArea *sa = CTX_wm_area(C); + return (sa && (sa->spacetype == SPACE_NODE)); } void NODE_OT_toolbar(wmOperatorType *ot) { - ot->name = "Tool Shelf"; - ot->description = "Toggles tool shelf display"; - ot->idname = "NODE_OT_toolbar"; + ot->name = "Tool Shelf"; + ot->description = "Toggles tool shelf display"; + ot->idname = "NODE_OT_toolbar"; - ot->exec = node_toolbar_toggle_exec; - ot->poll = node_toolbar_poll; + ot->exec = node_toolbar_toggle_exec; + ot->poll = node_toolbar_poll; - /* flags */ - ot->flag = 0; + /* flags */ + ot->flag = 0; } diff --git a/source/blender/editors/space_node/node_view.c b/source/blender/editors/space_node/node_view.c index 9d4b9d18c2a..15eb12ecf39 100644 --- a/source/blender/editors/space_node/node_view.c +++ b/source/blender/editors/space_node/node_view.c @@ -33,7 +33,7 @@ #include "BKE_node.h" #include "BKE_screen.h" -#include "ED_node.h" /* own include */ +#include "ED_node.h" /* own include */ #include "ED_screen.h" #include "ED_space_api.h" #include "ED_image.h" @@ -52,587 +52,593 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" -#include "node_intern.h" /* own include */ +#include "node_intern.h" /* own include */ #include "NOD_composite.h" - /* **************** View All Operator ************** */ -int space_node_view_flag(bContext *C, SpaceNode *snode, ARegion *ar, - const int node_flag, const int smooth_viewtx) +int space_node_view_flag( + bContext *C, SpaceNode *snode, ARegion *ar, const int node_flag, const int smooth_viewtx) { - bNode *node; - rctf cur_new; - float oldwidth, oldheight, width, height; - float oldasp, asp; - int tot = 0; - bool has_frame = false; - - oldwidth = BLI_rctf_size_x(&ar->v2d.cur); - oldheight = BLI_rctf_size_y(&ar->v2d.cur); - - oldasp = oldwidth / oldheight; - - BLI_rctf_init_minmax(&cur_new); - - if (snode->edittree) { - for (node = snode->edittree->nodes.first; node; node = node->next) { - if ((node->flag & node_flag) == node_flag) { - BLI_rctf_union(&cur_new, &node->totr); - tot++; - - if (node->type == NODE_FRAME) { - has_frame = true; - } - } - } - } - - if (tot) { - width = BLI_rctf_size_x(&cur_new); - height = BLI_rctf_size_y(&cur_new); - asp = width / height; - - /* for single non-frame nodes, don't zoom in, just pan view, - * but do allow zooming out, this allows for big nodes to be zoomed out */ - if ((tot == 1) && - (has_frame == false) && - ((oldwidth * oldheight) > (width * height))) - { - /* center, don't zoom */ - BLI_rctf_resize(&cur_new, oldwidth, oldheight); - } - else { - if (oldasp < asp) { - const float height_new = width / oldasp; - cur_new.ymin = cur_new.ymin - height_new / 2.0f; - cur_new.ymax = cur_new.ymax + height_new / 2.0f; - } - else { - const float width_new = height * oldasp; - cur_new.xmin = cur_new.xmin - width_new / 2.0f; - cur_new.xmax = cur_new.xmax + width_new / 2.0f; - } - - /* add some padding */ - BLI_rctf_scale(&cur_new, 1.1f); - } - - UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx); - } - - return (tot != 0); + bNode *node; + rctf cur_new; + float oldwidth, oldheight, width, height; + float oldasp, asp; + int tot = 0; + bool has_frame = false; + + oldwidth = BLI_rctf_size_x(&ar->v2d.cur); + oldheight = BLI_rctf_size_y(&ar->v2d.cur); + + oldasp = oldwidth / oldheight; + + BLI_rctf_init_minmax(&cur_new); + + if (snode->edittree) { + for (node = snode->edittree->nodes.first; node; node = node->next) { + if ((node->flag & node_flag) == node_flag) { + BLI_rctf_union(&cur_new, &node->totr); + tot++; + + if (node->type == NODE_FRAME) { + has_frame = true; + } + } + } + } + + if (tot) { + width = BLI_rctf_size_x(&cur_new); + height = BLI_rctf_size_y(&cur_new); + asp = width / height; + + /* for single non-frame nodes, don't zoom in, just pan view, + * but do allow zooming out, this allows for big nodes to be zoomed out */ + if ((tot == 1) && (has_frame == false) && ((oldwidth * oldheight) > (width * height))) { + /* center, don't zoom */ + BLI_rctf_resize(&cur_new, oldwidth, oldheight); + } + else { + if (oldasp < asp) { + const float height_new = width / oldasp; + cur_new.ymin = cur_new.ymin - height_new / 2.0f; + cur_new.ymax = cur_new.ymax + height_new / 2.0f; + } + else { + const float width_new = height * oldasp; + cur_new.xmin = cur_new.xmin - width_new / 2.0f; + cur_new.xmax = cur_new.xmax + width_new / 2.0f; + } + + /* add some padding */ + BLI_rctf_scale(&cur_new, 1.1f); + } + + UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx); + } + + return (tot != 0); } static int node_view_all_exec(bContext *C, wmOperator *op) { - ARegion *ar = CTX_wm_region(C); - SpaceNode *snode = CTX_wm_space_node(C); - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - /* is this really needed? */ - snode->xof = 0; - snode->yof = 0; - - if (space_node_view_flag(C, snode, ar, 0, smooth_viewtx)) { - return OPERATOR_FINISHED; - } - else { - return OPERATOR_CANCELLED; - } + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + /* is this really needed? */ + snode->xof = 0; + snode->yof = 0; + + if (space_node_view_flag(C, snode, ar, 0, smooth_viewtx)) { + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } } void NODE_OT_view_all(wmOperatorType *ot) { - /* identifiers */ - ot->name = "View All"; - ot->idname = "NODE_OT_view_all"; - ot->description = "Resize view so you can see all nodes"; + /* identifiers */ + ot->name = "View All"; + ot->idname = "NODE_OT_view_all"; + ot->description = "Resize view so you can see all nodes"; - /* api callbacks */ - ot->exec = node_view_all_exec; - ot->poll = ED_operator_node_active; + /* api callbacks */ + ot->exec = node_view_all_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int node_view_selected_exec(bContext *C, wmOperator *op) { - ARegion *ar = CTX_wm_region(C); - SpaceNode *snode = CTX_wm_space_node(C); - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - if (space_node_view_flag(C, snode, ar, NODE_SELECT, smooth_viewtx)) { - return OPERATOR_FINISHED; - } - else { - return OPERATOR_CANCELLED; - } + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + if (space_node_view_flag(C, snode, ar, NODE_SELECT, smooth_viewtx)) { + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } } void NODE_OT_view_selected(wmOperatorType *ot) { - /* identifiers */ - ot->name = "View Selected"; - ot->idname = "NODE_OT_view_selected"; - ot->description = "Resize view so you can see selected nodes"; + /* identifiers */ + ot->name = "View Selected"; + ot->idname = "NODE_OT_view_selected"; + ot->description = "Resize view so you can see selected nodes"; - /* api callbacks */ - ot->exec = node_view_selected_exec; - ot->poll = ED_operator_node_active; + /* api callbacks */ + ot->exec = node_view_selected_exec; + ot->poll = ED_operator_node_active; - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* **************** Background Image Operators ************** */ typedef struct NodeViewMove { - int mvalo[2]; - int xmin, ymin, xmax, ymax; + int mvalo[2]; + int xmin, ymin, xmax, ymax; } NodeViewMove; static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - NodeViewMove *nvm = op->customdata; - - switch (event->type) { - case MOUSEMOVE: - - snode->xof -= (nvm->mvalo[0] - event->mval[0]); - snode->yof -= (nvm->mvalo[1] - event->mval[1]); - nvm->mvalo[0] = event->mval[0]; - nvm->mvalo[1] = event->mval[1]; - - /* prevent dragging image outside of the window and losing it! */ - CLAMP(snode->xof, nvm->xmin, nvm->xmax); - CLAMP(snode->yof, nvm->ymin, nvm->ymax); - - ED_region_tag_redraw(ar); - WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL); - - break; - - case LEFTMOUSE: - case MIDDLEMOUSE: - case RIGHTMOUSE: - if (event->val == KM_RELEASE) { - MEM_freeN(nvm); - op->customdata = NULL; - return OPERATOR_FINISHED; - } - break; - } - - return OPERATOR_RUNNING_MODAL; + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + NodeViewMove *nvm = op->customdata; + + switch (event->type) { + case MOUSEMOVE: + + snode->xof -= (nvm->mvalo[0] - event->mval[0]); + snode->yof -= (nvm->mvalo[1] - event->mval[1]); + nvm->mvalo[0] = event->mval[0]; + nvm->mvalo[1] = event->mval[1]; + + /* prevent dragging image outside of the window and losing it! */ + CLAMP(snode->xof, nvm->xmin, nvm->xmax); + CLAMP(snode->yof, nvm->ymin, nvm->ymax); + + ED_region_tag_redraw(ar); + WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL); + + break; + + case LEFTMOUSE: + case MIDDLEMOUSE: + case RIGHTMOUSE: + if (event->val == KM_RELEASE) { + MEM_freeN(nvm); + op->customdata = NULL; + return OPERATOR_FINISHED; + } + break; + } + + return OPERATOR_RUNNING_MODAL; } static int snode_bg_viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - NodeViewMove *nvm; - Image *ima; - ImBuf *ibuf; - const float pad = 32.0f; /* better be bigger then scrollbars */ + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + NodeViewMove *nvm; + Image *ima; + ImBuf *ibuf; + const float pad = 32.0f; /* better be bigger then scrollbars */ - void *lock; + void *lock; - ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - if (ibuf == NULL) { - BKE_image_release_ibuf(ima, ibuf, lock); - return OPERATOR_CANCELLED; - } + if (ibuf == NULL) { + BKE_image_release_ibuf(ima, ibuf, lock); + return OPERATOR_CANCELLED; + } - nvm = MEM_callocN(sizeof(NodeViewMove), "NodeViewMove struct"); - op->customdata = nvm; - nvm->mvalo[0] = event->mval[0]; - nvm->mvalo[1] = event->mval[1]; + nvm = MEM_callocN(sizeof(NodeViewMove), "NodeViewMove struct"); + op->customdata = nvm; + nvm->mvalo[0] = event->mval[0]; + nvm->mvalo[1] = event->mval[1]; - nvm->xmin = -(ar->winx / 2) - (ibuf->x * (0.5f * snode->zoom)) + pad; - nvm->xmax = (ar->winx / 2) + (ibuf->x * (0.5f * snode->zoom)) - pad; - nvm->ymin = -(ar->winy / 2) - (ibuf->y * (0.5f * snode->zoom)) + pad; - nvm->ymax = (ar->winy / 2) + (ibuf->y * (0.5f * snode->zoom)) - pad; + nvm->xmin = -(ar->winx / 2) - (ibuf->x * (0.5f * snode->zoom)) + pad; + nvm->xmax = (ar->winx / 2) + (ibuf->x * (0.5f * snode->zoom)) - pad; + nvm->ymin = -(ar->winy / 2) - (ibuf->y * (0.5f * snode->zoom)) + pad; + nvm->ymax = (ar->winy / 2) + (ibuf->y * (0.5f * snode->zoom)) - pad; - BKE_image_release_ibuf(ima, ibuf, lock); + BKE_image_release_ibuf(ima, ibuf, lock); - /* add modal handler */ - WM_event_add_modal_handler(C, op); + /* add modal handler */ + WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; + return OPERATOR_RUNNING_MODAL; } static void snode_bg_viewmove_cancel(bContext *UNUSED(C), wmOperator *op) { - MEM_freeN(op->customdata); - op->customdata = NULL; + MEM_freeN(op->customdata); + op->customdata = NULL; } void NODE_OT_backimage_move(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Background Image Move"; - ot->description = "Move Node backdrop"; - ot->idname = "NODE_OT_backimage_move"; - - /* api callbacks */ - ot->invoke = snode_bg_viewmove_invoke; - ot->modal = snode_bg_viewmove_modal; - ot->poll = composite_node_active; - ot->cancel = snode_bg_viewmove_cancel; - - /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR; + /* identifiers */ + ot->name = "Background Image Move"; + ot->description = "Move Node backdrop"; + ot->idname = "NODE_OT_backimage_move"; + + /* api callbacks */ + ot->invoke = snode_bg_viewmove_invoke; + ot->modal = snode_bg_viewmove_modal; + ot->poll = composite_node_active; + ot->cancel = snode_bg_viewmove_cancel; + + /* flags */ + ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR; } static int backimage_zoom_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - float fac = RNA_float_get(op->ptr, "factor"); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + float fac = RNA_float_get(op->ptr, "factor"); - snode->zoom *= fac; - ED_region_tag_redraw(ar); - WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL); + snode->zoom *= fac; + ED_region_tag_redraw(ar); + WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } - void NODE_OT_backimage_zoom(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Background Image Zoom"; - ot->idname = "NODE_OT_backimage_zoom"; - ot->description = "Zoom in/out the background image"; + /* identifiers */ + ot->name = "Background Image Zoom"; + ot->idname = "NODE_OT_backimage_zoom"; + ot->description = "Zoom in/out the background image"; - /* api callbacks */ - ot->exec = backimage_zoom_exec; - ot->poll = composite_node_active; + /* api callbacks */ + ot->exec = backimage_zoom_exec; + ot->poll = composite_node_active; - /* flags */ - ot->flag = OPTYPE_BLOCKING; + /* flags */ + ot->flag = OPTYPE_BLOCKING; - /* internal */ - RNA_def_float(ot->srna, "factor", 1.2f, 0.0f, 10.0f, "Factor", "", 0.0f, 10.0f); + /* internal */ + RNA_def_float(ot->srna, "factor", 1.2f, 0.0f, 10.0f, "Factor", "", 0.0f, 10.0f); } static int backimage_fit_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); - Image *ima; - ImBuf *ibuf; + Image *ima; + ImBuf *ibuf; - const float pad = 32.0f; + const float pad = 32.0f; - void *lock; + void *lock; - float facx, facy; + float facx, facy; - ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - if ((ibuf == NULL) || (ibuf->x == 0) || (ibuf->y == 0)) { - BKE_image_release_ibuf(ima, ibuf, lock); - return OPERATOR_CANCELLED; - } + if ((ibuf == NULL) || (ibuf->x == 0) || (ibuf->y == 0)) { + BKE_image_release_ibuf(ima, ibuf, lock); + return OPERATOR_CANCELLED; + } - facx = 1.0f * (ar->sizex - pad) / (ibuf->x * snode->zoom); - facy = 1.0f * (ar->sizey - pad) / (ibuf->y * snode->zoom); + facx = 1.0f * (ar->sizex - pad) / (ibuf->x * snode->zoom); + facy = 1.0f * (ar->sizey - pad) / (ibuf->y * snode->zoom); - BKE_image_release_ibuf(ima, ibuf, lock); + BKE_image_release_ibuf(ima, ibuf, lock); - snode->zoom *= min_ff(facx, facy); + snode->zoom *= min_ff(facx, facy); - snode->xof = 0; - snode->yof = 0; + snode->xof = 0; + snode->yof = 0; - ED_region_tag_redraw(ar); - WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL); + ED_region_tag_redraw(ar); + WM_main_add_notifier(NC_NODE | ND_DISPLAY, NULL); - return OPERATOR_FINISHED; + return OPERATOR_FINISHED; } void NODE_OT_backimage_fit(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Background Image Fit"; - ot->idname = "NODE_OT_backimage_fit"; - ot->description = "Fit the background image to the view"; - - /* api callbacks */ - ot->exec = backimage_fit_exec; - ot->poll = composite_node_active; + /* identifiers */ + ot->name = "Background Image Fit"; + ot->idname = "NODE_OT_backimage_fit"; + ot->description = "Fit the background image to the view"; - /* flags */ - ot->flag = OPTYPE_BLOCKING; + /* api callbacks */ + ot->exec = backimage_fit_exec; + ot->poll = composite_node_active; + /* flags */ + ot->flag = OPTYPE_BLOCKING; } /******************** sample backdrop operator ********************/ typedef struct ImageSampleInfo { - ARegionType *art; - void *draw_handle; - int x, y; - int channels; + ARegionType *art; + void *draw_handle; + int x, y; + int channels; - unsigned char col[4]; - float colf[4]; - float linearcol[4]; + unsigned char col[4]; + float colf[4]; + float linearcol[4]; - int z; - float zf; + int z; + float zf; - int *zp; - float *zfp; + int *zp; + float *zfp; - int draw; - int color_manage; + int draw; + int color_manage; } ImageSampleInfo; static void sample_draw(const bContext *C, ARegion *ar, void *arg_info) { - Scene *scene = CTX_data_scene(C); - ImageSampleInfo *info = arg_info; - - if (info->draw) { - ED_image_draw_info(scene, ar, info->color_manage, false, info->channels, - info->x, info->y, info->col, info->colf, info->linearcol, - info->zp, info->zfp); - } + Scene *scene = CTX_data_scene(C); + ImageSampleInfo *info = arg_info; + + if (info->draw) { + ED_image_draw_info(scene, + ar, + info->color_manage, + false, + info->channels, + info->x, + info->y, + info->col, + info->colf, + info->linearcol, + info->zp, + info->zfp); + } } /* Returns color in linear space, matching ED_space_image_color_sample(). * And here we've got recursion in the comments tips... */ -bool ED_space_node_color_sample(Main *bmain, SpaceNode *snode, ARegion *ar, int mval[2], float r_col[3]) +bool ED_space_node_color_sample( + Main *bmain, SpaceNode *snode, ARegion *ar, int mval[2], float r_col[3]) { - void *lock; - Image *ima; - ImBuf *ibuf; - float fx, fy, bufx, bufy; - bool ret = false; - - if (!ED_node_is_compositor(snode) || (snode->flag & SNODE_BACKDRAW) == 0) { - /* use viewer image for color sampling only if we're in compositor tree - * with backdrop enabled - */ - return false; - } - - ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - if (!ibuf) { - return false; - } - - /* map the mouse coords to the backdrop image space */ - bufx = ibuf->x * snode->zoom; - bufy = ibuf->y * snode->zoom; - fx = (bufx > 0.0f ? ((float)mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); - fy = (bufy > 0.0f ? ((float)mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); - - if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { - const float *fp; - unsigned char *cp; - int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); - - CLAMP(x, 0, ibuf->x - 1); - CLAMP(y, 0, ibuf->y - 1); - - if (ibuf->rect_float) { - fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); - /* IB_PROFILE_NONE is default but infact its linear */ - copy_v3_v3(r_col, fp); - ret = true; - } - else if (ibuf->rect) { - cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); - rgb_uchar_to_float(r_col, cp); - IMB_colormanagement_colorspace_to_scene_linear_v3(r_col, ibuf->rect_colorspace); - ret = true; - } - } - - BKE_image_release_ibuf(ima, ibuf, lock); - - return ret; + void *lock; + Image *ima; + ImBuf *ibuf; + float fx, fy, bufx, bufy; + bool ret = false; + + if (!ED_node_is_compositor(snode) || (snode->flag & SNODE_BACKDRAW) == 0) { + /* use viewer image for color sampling only if we're in compositor tree + * with backdrop enabled + */ + return false; + } + + ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + if (!ibuf) { + return false; + } + + /* map the mouse coords to the backdrop image space */ + bufx = ibuf->x * snode->zoom; + bufy = ibuf->y * snode->zoom; + fx = (bufx > 0.0f ? ((float)mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); + fy = (bufy > 0.0f ? ((float)mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); + + if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { + const float *fp; + unsigned char *cp; + int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); + + CLAMP(x, 0, ibuf->x - 1); + CLAMP(y, 0, ibuf->y - 1); + + if (ibuf->rect_float) { + fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); + /* IB_PROFILE_NONE is default but infact its linear */ + copy_v3_v3(r_col, fp); + ret = true; + } + else if (ibuf->rect) { + cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); + rgb_uchar_to_float(r_col, cp); + IMB_colormanagement_colorspace_to_scene_linear_v3(r_col, ibuf->rect_colorspace); + ret = true; + } + } + + BKE_image_release_ibuf(ima, ibuf, lock); + + return ret; } static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - ImageSampleInfo *info = op->customdata; - void *lock; - Image *ima; - ImBuf *ibuf; - float fx, fy, bufx, bufy; - - ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - if (!ibuf) { - info->draw = 0; - return; - } - - if (!ibuf->rect) { - IMB_rect_from_float(ibuf); - } - - /* map the mouse coords to the backdrop image space */ - bufx = ibuf->x * snode->zoom; - bufy = ibuf->y * snode->zoom; - fx = (bufx > 0.0f ? ((float)event->mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); - fy = (bufy > 0.0f ? ((float)event->mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); - - if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { - const float *fp; - unsigned char *cp; - int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); - - CLAMP(x, 0, ibuf->x - 1); - CLAMP(y, 0, ibuf->y - 1); - - info->x = x; - info->y = y; - info->draw = 1; - info->channels = ibuf->channels; - - info->zp = NULL; - info->zfp = NULL; - - if (ibuf->rect) { - cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); - - info->col[0] = cp[0]; - info->col[1] = cp[1]; - info->col[2] = cp[2]; - info->col[3] = cp[3]; - - info->colf[0] = (float)cp[0] / 255.0f; - info->colf[1] = (float)cp[1] / 255.0f; - info->colf[2] = (float)cp[2] / 255.0f; - info->colf[3] = (float)cp[3] / 255.0f; - - copy_v4_v4(info->linearcol, info->colf); - IMB_colormanagement_colorspace_to_scene_linear_v4(info->linearcol, false, ibuf->rect_colorspace); - - info->color_manage = true; - } - if (ibuf->rect_float) { - fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); - - info->colf[0] = fp[0]; - info->colf[1] = fp[1]; - info->colf[2] = fp[2]; - info->colf[3] = fp[3]; - - info->color_manage = true; - } - - if (ibuf->zbuf) { - info->z = ibuf->zbuf[y * ibuf->x + x]; - info->zp = &info->z; - } - if (ibuf->zbuf_float) { - info->zf = ibuf->zbuf_float[y * ibuf->x + x]; - info->zfp = &info->zf; - } - - ED_node_sample_set(info->colf); - } - else { - info->draw = 0; - ED_node_sample_set(NULL); - } - - BKE_image_release_ibuf(ima, ibuf, lock); - - ED_area_tag_redraw(CTX_wm_area(C)); + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + ImageSampleInfo *info = op->customdata; + void *lock; + Image *ima; + ImBuf *ibuf; + float fx, fy, bufx, bufy; + + ima = BKE_image_verify_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + if (!ibuf) { + info->draw = 0; + return; + } + + if (!ibuf->rect) { + IMB_rect_from_float(ibuf); + } + + /* map the mouse coords to the backdrop image space */ + bufx = ibuf->x * snode->zoom; + bufy = ibuf->y * snode->zoom; + fx = (bufx > 0.0f ? ((float)event->mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); + fy = (bufy > 0.0f ? ((float)event->mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); + + if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { + const float *fp; + unsigned char *cp; + int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); + + CLAMP(x, 0, ibuf->x - 1); + CLAMP(y, 0, ibuf->y - 1); + + info->x = x; + info->y = y; + info->draw = 1; + info->channels = ibuf->channels; + + info->zp = NULL; + info->zfp = NULL; + + if (ibuf->rect) { + cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x); + + info->col[0] = cp[0]; + info->col[1] = cp[1]; + info->col[2] = cp[2]; + info->col[3] = cp[3]; + + info->colf[0] = (float)cp[0] / 255.0f; + info->colf[1] = (float)cp[1] / 255.0f; + info->colf[2] = (float)cp[2] / 255.0f; + info->colf[3] = (float)cp[3] / 255.0f; + + copy_v4_v4(info->linearcol, info->colf); + IMB_colormanagement_colorspace_to_scene_linear_v4( + info->linearcol, false, ibuf->rect_colorspace); + + info->color_manage = true; + } + if (ibuf->rect_float) { + fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); + + info->colf[0] = fp[0]; + info->colf[1] = fp[1]; + info->colf[2] = fp[2]; + info->colf[3] = fp[3]; + + info->color_manage = true; + } + + if (ibuf->zbuf) { + info->z = ibuf->zbuf[y * ibuf->x + x]; + info->zp = &info->z; + } + if (ibuf->zbuf_float) { + info->zf = ibuf->zbuf_float[y * ibuf->x + x]; + info->zfp = &info->zf; + } + + ED_node_sample_set(info->colf); + } + else { + info->draw = 0; + ED_node_sample_set(NULL); + } + + BKE_image_release_ibuf(ima, ibuf, lock); + + ED_area_tag_redraw(CTX_wm_area(C)); } static void sample_exit(bContext *C, wmOperator *op) { - ImageSampleInfo *info = op->customdata; + ImageSampleInfo *info = op->customdata; - ED_node_sample_set(NULL); - ED_region_draw_cb_exit(info->art, info->draw_handle); - ED_area_tag_redraw(CTX_wm_area(C)); - MEM_freeN(info); + ED_node_sample_set(NULL); + ED_region_draw_cb_exit(info->art, info->draw_handle); + ED_area_tag_redraw(CTX_wm_area(C)); + MEM_freeN(info); } static int sample_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - ImageSampleInfo *info; + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + ImageSampleInfo *info; - if (!ED_node_is_compositor(snode) || !(snode->flag & SNODE_BACKDRAW)) { - return OPERATOR_CANCELLED; - } + if (!ED_node_is_compositor(snode) || !(snode->flag & SNODE_BACKDRAW)) { + return OPERATOR_CANCELLED; + } - info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo"); - info->art = ar->type; - info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL); - op->customdata = info; + info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo"); + info->art = ar->type; + info->draw_handle = ED_region_draw_cb_activate( + ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL); + op->customdata = info; - sample_apply(C, op, event); + sample_apply(C, op, event); - WM_event_add_modal_handler(C, op); + WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; + return OPERATOR_RUNNING_MODAL; } static int sample_modal(bContext *C, wmOperator *op, const wmEvent *event) { - switch (event->type) { - case LEFTMOUSE: - case RIGHTMOUSE: // XXX hardcoded - if (event->val == KM_RELEASE) { - sample_exit(C, op); - return OPERATOR_CANCELLED; - } - break; - case MOUSEMOVE: - sample_apply(C, op, event); - break; - } - - return OPERATOR_RUNNING_MODAL; + switch (event->type) { + case LEFTMOUSE: + case RIGHTMOUSE: // XXX hardcoded + if (event->val == KM_RELEASE) { + sample_exit(C, op); + return OPERATOR_CANCELLED; + } + break; + case MOUSEMOVE: + sample_apply(C, op, event); + break; + } + + return OPERATOR_RUNNING_MODAL; } static void sample_cancel(bContext *C, wmOperator *op) { - sample_exit(C, op); + sample_exit(C, op); } void NODE_OT_backimage_sample(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Backimage Sample"; - ot->idname = "NODE_OT_backimage_sample"; - ot->description = "Use mouse to sample background image"; - - /* api callbacks */ - ot->invoke = sample_invoke; - ot->modal = sample_modal; - ot->cancel = sample_cancel; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_BLOCKING; + /* identifiers */ + ot->name = "Backimage Sample"; + ot->idname = "NODE_OT_backimage_sample"; + ot->description = "Use mouse to sample background image"; + + /* api callbacks */ + ot->invoke = sample_invoke; + ot->modal = sample_modal; + ot->cancel = sample_cancel; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_BLOCKING; } diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index 22564061aed..52dab2a44a8 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -53,1030 +53,1032 @@ #include "WM_api.h" #include "WM_types.h" -#include "node_intern.h" /* own include */ - +#include "node_intern.h" /* own include */ /* ******************** tree path ********************* */ void ED_node_tree_start(SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from) { - bNodeTreePath *path, *path_next; - for (path = snode->treepath.first; path; path = path_next) { - path_next = path->next; - MEM_freeN(path); - } - BLI_listbase_clear(&snode->treepath); + bNodeTreePath *path, *path_next; + for (path = snode->treepath.first; path; path = path_next) { + path_next = path->next; + MEM_freeN(path); + } + BLI_listbase_clear(&snode->treepath); - if (ntree) { - path = MEM_callocN(sizeof(bNodeTreePath), "node tree path"); - path->nodetree = ntree; - path->parent_key = NODE_INSTANCE_KEY_BASE; + if (ntree) { + path = MEM_callocN(sizeof(bNodeTreePath), "node tree path"); + path->nodetree = ntree; + path->parent_key = NODE_INSTANCE_KEY_BASE; - /* copy initial offset from bNodeTree */ - copy_v2_v2(path->view_center, ntree->view_center); + /* copy initial offset from bNodeTree */ + copy_v2_v2(path->view_center, ntree->view_center); - if (id) { - BLI_strncpy(path->node_name, id->name + 2, sizeof(path->node_name)); - } + if (id) { + BLI_strncpy(path->node_name, id->name + 2, sizeof(path->node_name)); + } - BLI_addtail(&snode->treepath, path); + BLI_addtail(&snode->treepath, path); - id_us_ensure_real(&ntree->id); - } + id_us_ensure_real(&ntree->id); + } - /* update current tree */ - snode->nodetree = snode->edittree = ntree; - snode->id = id; - snode->from = from; + /* update current tree */ + snode->nodetree = snode->edittree = ntree; + snode->id = id; + snode->from = from; - ED_node_set_active_viewer_key(snode); + ED_node_set_active_viewer_key(snode); - WM_main_add_notifier(NC_SCENE | ND_NODES, NULL); + WM_main_add_notifier(NC_SCENE | ND_NODES, NULL); } void ED_node_tree_push(SpaceNode *snode, bNodeTree *ntree, bNode *gnode) { - bNodeTreePath *path = MEM_callocN(sizeof(bNodeTreePath), "node tree path"); - bNodeTreePath *prev_path = snode->treepath.last; - path->nodetree = ntree; - if (gnode) { - if (prev_path) { - path->parent_key = BKE_node_instance_key(prev_path->parent_key, prev_path->nodetree, gnode); - } - else { - path->parent_key = NODE_INSTANCE_KEY_BASE; - } + bNodeTreePath *path = MEM_callocN(sizeof(bNodeTreePath), "node tree path"); + bNodeTreePath *prev_path = snode->treepath.last; + path->nodetree = ntree; + if (gnode) { + if (prev_path) { + path->parent_key = BKE_node_instance_key(prev_path->parent_key, prev_path->nodetree, gnode); + } + else { + path->parent_key = NODE_INSTANCE_KEY_BASE; + } - BLI_strncpy(path->node_name, gnode->name, sizeof(path->node_name)); - } - else { - path->parent_key = NODE_INSTANCE_KEY_BASE; - } + BLI_strncpy(path->node_name, gnode->name, sizeof(path->node_name)); + } + else { + path->parent_key = NODE_INSTANCE_KEY_BASE; + } - /* copy initial offset from bNodeTree */ - copy_v2_v2(path->view_center, ntree->view_center); + /* copy initial offset from bNodeTree */ + copy_v2_v2(path->view_center, ntree->view_center); - BLI_addtail(&snode->treepath, path); + BLI_addtail(&snode->treepath, path); - id_us_ensure_real(&ntree->id); + id_us_ensure_real(&ntree->id); - /* update current tree */ - snode->edittree = ntree; + /* update current tree */ + snode->edittree = ntree; - ED_node_set_active_viewer_key(snode); + ED_node_set_active_viewer_key(snode); - WM_main_add_notifier(NC_SCENE | ND_NODES, NULL); + WM_main_add_notifier(NC_SCENE | ND_NODES, NULL); } void ED_node_tree_pop(SpaceNode *snode) { - bNodeTreePath *path = snode->treepath.last; + bNodeTreePath *path = snode->treepath.last; - /* don't remove root */ - if (path == snode->treepath.first) { - return; - } + /* don't remove root */ + if (path == snode->treepath.first) { + return; + } - BLI_remlink(&snode->treepath, path); - MEM_freeN(path); + BLI_remlink(&snode->treepath, path); + MEM_freeN(path); - /* update current tree */ - path = snode->treepath.last; - snode->edittree = path->nodetree; + /* update current tree */ + path = snode->treepath.last; + snode->edittree = path->nodetree; - ED_node_set_active_viewer_key(snode); + ED_node_set_active_viewer_key(snode); - /* listener updates the View2D center from edittree */ - WM_main_add_notifier(NC_SCENE | ND_NODES, NULL); + /* listener updates the View2D center from edittree */ + WM_main_add_notifier(NC_SCENE | ND_NODES, NULL); } int ED_node_tree_depth(SpaceNode *snode) { - return BLI_listbase_count(&snode->treepath); + return BLI_listbase_count(&snode->treepath); } bNodeTree *ED_node_tree_get(SpaceNode *snode, int level) { - bNodeTreePath *path; - int i; - for (path = snode->treepath.last, i = 0; path; path = path->prev, ++i) { - if (i == level) { - return path->nodetree; - } - } - return NULL; + bNodeTreePath *path; + int i; + for (path = snode->treepath.last, i = 0; path; path = path->prev, ++i) { + if (i == level) { + return path->nodetree; + } + } + return NULL; } int ED_node_tree_path_length(SpaceNode *snode) { - bNodeTreePath *path; - int length = 0; - int i; - for (path = snode->treepath.first, i = 0; path; path = path->next, ++i) { - length += strlen(path->node_name); - if (i > 0) { - length += 1; /* for separator char */ - } - } - return length; + bNodeTreePath *path; + int length = 0; + int i; + for (path = snode->treepath.first, i = 0; path; path = path->next, ++i) { + length += strlen(path->node_name); + if (i > 0) { + length += 1; /* for separator char */ + } + } + return length; } void ED_node_tree_path_get(SpaceNode *snode, char *value) { - bNodeTreePath *path; - int i; - - value[0] = '\0'; - for (path = snode->treepath.first, i = 0; path; path = path->next, ++i) { - if (i == 0) { - strcpy(value, path->node_name); - value += strlen(path->node_name); - } - else { - sprintf(value, "/%s", path->node_name); - value += strlen(path->node_name) + 1; - } - } + bNodeTreePath *path; + int i; + + value[0] = '\0'; + for (path = snode->treepath.first, i = 0; path; path = path->next, ++i) { + if (i == 0) { + strcpy(value, path->node_name); + value += strlen(path->node_name); + } + else { + sprintf(value, "/%s", path->node_name); + value += strlen(path->node_name) + 1; + } + } } void ED_node_tree_path_get_fixedbuf(SpaceNode *snode, char *value, int max_length) { - bNodeTreePath *path; - int size, i; - - value[0] = '\0'; - for (path = snode->treepath.first, i = 0; path; path = path->next, ++i) { - if (i == 0) { - size = BLI_strncpy_rlen(value, path->node_name, max_length); - } - else { - size = BLI_snprintf_rlen(value, max_length, "/%s", path->node_name); - } - max_length -= size; - if (max_length <= 0) { - break; - } - value += size; - } + bNodeTreePath *path; + int size, i; + + value[0] = '\0'; + for (path = snode->treepath.first, i = 0; path; path = path->next, ++i) { + if (i == 0) { + size = BLI_strncpy_rlen(value, path->node_name, max_length); + } + else { + size = BLI_snprintf_rlen(value, max_length, "/%s", path->node_name); + } + max_length -= size; + if (max_length <= 0) { + break; + } + value += size; + } } void ED_node_set_active_viewer_key(SpaceNode *snode) { - bNodeTreePath *path = snode->treepath.last; - if (snode->nodetree && path) { - snode->nodetree->active_viewer_key = path->parent_key; - } + bNodeTreePath *path = snode->treepath.last; + if (snode->nodetree && path) { + snode->nodetree->active_viewer_key = path->parent_key; + } } void snode_group_offset(SpaceNode *snode, float *x, float *y) { - bNodeTreePath *path = snode->treepath.last; - - if (path && path->prev) { - float dcenter[2]; - sub_v2_v2v2(dcenter, path->view_center, path->prev->view_center); - *x = dcenter[0]; - *y = dcenter[1]; - } - else { - *x = *y = 0.0f; - } + bNodeTreePath *path = snode->treepath.last; + + if (path && path->prev) { + float dcenter[2]; + sub_v2_v2v2(dcenter, path->view_center, path->prev->view_center); + *x = dcenter[0]; + *y = dcenter[1]; + } + else { + *x = *y = 0.0f; + } } /* ******************** manage regions ********************* */ ARegion *node_has_buttons_region(ScrArea *sa) { - ARegion *ar, *arnew; + ARegion *ar, *arnew; - ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) { - return ar; - } + ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); + if (ar) { + return ar; + } - /* add subdiv level; after header */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); + /* add subdiv level; after header */ + ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); - /* is error! */ - if (ar == NULL) { - return NULL; - } + /* is error! */ + if (ar == NULL) { + return NULL; + } - arnew = MEM_callocN(sizeof(ARegion), "buttons for node"); + arnew = MEM_callocN(sizeof(ARegion), "buttons for node"); - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_UI; - arnew->alignment = RGN_ALIGN_RIGHT; + BLI_insertlinkafter(&sa->regionbase, ar, arnew); + arnew->regiontype = RGN_TYPE_UI; + arnew->alignment = RGN_ALIGN_RIGHT; - arnew->flag = RGN_FLAG_HIDDEN; + arnew->flag = RGN_FLAG_HIDDEN; - return arnew; + return arnew; } ARegion *node_has_tools_region(ScrArea *sa) { - ARegion *ar, *arnew; + ARegion *ar, *arnew; - ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS); - if (ar) { - return ar; - } + ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS); + if (ar) { + return ar; + } - /* add subdiv level; after header */ - ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); + /* add subdiv level; after header */ + ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); - /* is error! */ - if (ar == NULL) { - return NULL; - } + /* is error! */ + if (ar == NULL) { + return NULL; + } - arnew = MEM_callocN(sizeof(ARegion), "node tools"); + arnew = MEM_callocN(sizeof(ARegion), "node tools"); - BLI_insertlinkafter(&sa->regionbase, ar, arnew); - arnew->regiontype = RGN_TYPE_TOOLS; - arnew->alignment = RGN_ALIGN_LEFT; + BLI_insertlinkafter(&sa->regionbase, ar, arnew); + arnew->regiontype = RGN_TYPE_TOOLS; + arnew->alignment = RGN_ALIGN_LEFT; - arnew->flag = RGN_FLAG_HIDDEN; + arnew->flag = RGN_FLAG_HIDDEN; - return arnew; + return arnew; } /* ******************** default callbacks for node space ***************** */ static SpaceLink *node_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene)) { - ARegion *ar; - SpaceNode *snode; + ARegion *ar; + SpaceNode *snode; - snode = MEM_callocN(sizeof(SpaceNode), "initnode"); - snode->spacetype = SPACE_NODE; + snode = MEM_callocN(sizeof(SpaceNode), "initnode"); + snode->spacetype = SPACE_NODE; - snode->flag = SNODE_SHOW_GPENCIL | SNODE_USE_ALPHA; + snode->flag = SNODE_SHOW_GPENCIL | SNODE_USE_ALPHA; - /* backdrop */ - snode->zoom = 1.0f; + /* backdrop */ + snode->zoom = 1.0f; - /* select the first tree type for valid type */ - NODE_TREE_TYPES_BEGIN (treetype) - { - strcpy(snode->tree_idname, treetype->idname); - break; - } - NODE_TREE_TYPES_END; + /* select the first tree type for valid type */ + NODE_TREE_TYPES_BEGIN (treetype) { + strcpy(snode->tree_idname, treetype->idname); + break; + } + NODE_TREE_TYPES_END; - /* header */ - ar = MEM_callocN(sizeof(ARegion), "header for node"); + /* header */ + ar = MEM_callocN(sizeof(ARegion), "header for node"); - BLI_addtail(&snode->regionbase, ar); - ar->regiontype = RGN_TYPE_HEADER; - ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; + BLI_addtail(&snode->regionbase, ar); + ar->regiontype = RGN_TYPE_HEADER; + ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; - /* buttons/list view */ - ar = MEM_callocN(sizeof(ARegion), "buttons for node"); + /* buttons/list view */ + ar = MEM_callocN(sizeof(ARegion), "buttons for node"); - BLI_addtail(&snode->regionbase, ar); - ar->regiontype = RGN_TYPE_UI; - ar->alignment = RGN_ALIGN_RIGHT; + BLI_addtail(&snode->regionbase, ar); + ar->regiontype = RGN_TYPE_UI; + ar->alignment = RGN_ALIGN_RIGHT; - /* toolbar */ - ar = MEM_callocN(sizeof(ARegion), "node tools"); + /* toolbar */ + ar = MEM_callocN(sizeof(ARegion), "node tools"); - BLI_addtail(&snode->regionbase, ar); - ar->regiontype = RGN_TYPE_TOOLS; - ar->alignment = RGN_ALIGN_LEFT; + BLI_addtail(&snode->regionbase, ar); + ar->regiontype = RGN_TYPE_TOOLS; + ar->alignment = RGN_ALIGN_LEFT; - ar->flag = RGN_FLAG_HIDDEN; + ar->flag = RGN_FLAG_HIDDEN; - /* main region */ - ar = MEM_callocN(sizeof(ARegion), "main region for node"); + /* main region */ + ar = MEM_callocN(sizeof(ARegion), "main region for node"); - BLI_addtail(&snode->regionbase, ar); - ar->regiontype = RGN_TYPE_WINDOW; + BLI_addtail(&snode->regionbase, ar); + ar->regiontype = RGN_TYPE_WINDOW; - ar->v2d.tot.xmin = -12.8f * U.widget_unit; - ar->v2d.tot.ymin = -12.8f * U.widget_unit; - ar->v2d.tot.xmax = 38.4f * U.widget_unit; - ar->v2d.tot.ymax = 38.4f * U.widget_unit; + ar->v2d.tot.xmin = -12.8f * U.widget_unit; + ar->v2d.tot.ymin = -12.8f * U.widget_unit; + ar->v2d.tot.xmax = 38.4f * U.widget_unit; + ar->v2d.tot.ymax = 38.4f * U.widget_unit; - ar->v2d.cur = ar->v2d.tot; + ar->v2d.cur = ar->v2d.tot; - ar->v2d.min[0] = 1.0f; - ar->v2d.min[1] = 1.0f; + ar->v2d.min[0] = 1.0f; + ar->v2d.min[1] = 1.0f; - ar->v2d.max[0] = 32000.0f; - ar->v2d.max[1] = 32000.0f; + ar->v2d.max[0] = 32000.0f; + ar->v2d.max[1] = 32000.0f; - ar->v2d.minzoom = 0.09f; - ar->v2d.maxzoom = 2.31f; + ar->v2d.minzoom = 0.09f; + ar->v2d.maxzoom = 2.31f; - ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM); - ar->v2d.keepzoom = V2D_LIMITZOOM | V2D_KEEPASPECT; - ar->v2d.keeptot = 0; + ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM); + ar->v2d.keepzoom = V2D_LIMITZOOM | V2D_KEEPASPECT; + ar->v2d.keeptot = 0; - return (SpaceLink *)snode; + return (SpaceLink *)snode; } static void node_free(SpaceLink *sl) { - SpaceNode *snode = (SpaceNode *)sl; - bNodeTreePath *path, *path_next; + SpaceNode *snode = (SpaceNode *)sl; + bNodeTreePath *path, *path_next; - for (path = snode->treepath.first; path; path = path_next) { - path_next = path->next; - MEM_freeN(path); - } + for (path = snode->treepath.first; path; path = path_next) { + path_next = path->next; + MEM_freeN(path); + } } - /* spacetype; init callback */ static void node_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa)) { - } -static void node_area_listener(wmWindow *UNUSED(win), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene)) +static void node_area_listener(wmWindow *UNUSED(win), + ScrArea *sa, + wmNotifier *wmn, + Scene *UNUSED(scene)) { - /* note, ED_area_tag_refresh will re-execute compositor */ - SpaceNode *snode = sa->spacedata.first; - /* shaderfrom is only used for new shading nodes, otherwise all shaders are from objects */ - short shader_type = snode->shaderfrom; - - /* preview renders */ - switch (wmn->category) { - case NC_SCENE: - switch (wmn->data) { - case ND_NODES: - { - ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); - bNodeTreePath *path = snode->treepath.last; - /* shift view to node tree center */ - if (ar && path) { - UI_view2d_center_set(&ar->v2d, path->view_center[0], path->view_center[1]); - } - - ED_area_tag_refresh(sa); - break; - } - case ND_FRAME: - ED_area_tag_refresh(sa); - break; - case ND_COMPO_RESULT: - ED_area_tag_redraw(sa); - break; - case ND_TRANSFORM_DONE: - if (ED_node_is_compositor(snode)) { - if (snode->flag & SNODE_AUTO_RENDER) { - snode->recalc = 1; - ED_area_tag_refresh(sa); - } - } - break; - case ND_LAYER_CONTENT: - ED_area_tag_refresh(sa); - break; - } - break; - - /* future: add ID checks? */ - case NC_MATERIAL: - if (ED_node_is_shader(snode)) { - if (wmn->data == ND_SHADING) { - ED_area_tag_refresh(sa); - } - else if (wmn->data == ND_SHADING_DRAW) { - ED_area_tag_refresh(sa); - } - else if (wmn->data == ND_SHADING_LINKS) { - ED_area_tag_refresh(sa); - } - else if (wmn->action == NA_ADDED && snode->edittree) { - nodeSetActiveID(snode->edittree, ID_MA, wmn->reference); - } - - } - break; - case NC_TEXTURE: - if (ED_node_is_shader(snode) || ED_node_is_texture(snode)) { - if (wmn->data == ND_NODES) { - ED_area_tag_refresh(sa); - } - } - break; - case NC_WORLD: - if (ED_node_is_shader(snode) && shader_type == SNODE_SHADER_WORLD) { - ED_area_tag_refresh(sa); - } - break; - case NC_OBJECT: - if (ED_node_is_shader(snode)) { - if (wmn->data == ND_OB_SHADING) { - ED_area_tag_refresh(sa); - } - } - break; - case NC_SPACE: - if (wmn->data == ND_SPACE_NODE) { - ED_area_tag_refresh(sa); - } - else if (wmn->data == ND_SPACE_NODE_VIEW) { - ED_area_tag_redraw(sa); - } - break; - case NC_NODE: - if (wmn->action == NA_EDITED) { - ED_area_tag_refresh(sa); - } - else if (wmn->action == NA_SELECTED) { - ED_area_tag_redraw(sa); - } - break; - case NC_SCREEN: - switch (wmn->data) { - case ND_ANIMPLAY: - ED_area_tag_refresh(sa); - break; - } - break; - case NC_MASK: - if (wmn->action == NA_EDITED) { - if (snode->nodetree && snode->nodetree->type == NTREE_COMPOSIT) { - ED_area_tag_refresh(sa); - } - } - break; - - case NC_IMAGE: - if (wmn->action == NA_EDITED) { - if (ED_node_is_compositor(snode)) { - /* note that nodeUpdateID is already called by BKE_image_signal() on all - * scenes so really this is just to know if the images is used in the compo else - * painting on images could become very slow when the compositor is open. */ - if (nodeUpdateID(snode->nodetree, wmn->reference)) { - ED_area_tag_refresh(sa); - } - } - } - break; - - case NC_MOVIECLIP: - if (wmn->action == NA_EDITED) { - if (ED_node_is_compositor(snode)) { - if (nodeUpdateID(snode->nodetree, wmn->reference)) { - ED_area_tag_refresh(sa); - } - } - } - break; - - case NC_LINESTYLE: - if (ED_node_is_shader(snode) && shader_type == SNODE_SHADER_LINESTYLE) { - ED_area_tag_refresh(sa); - } - break; - case NC_WM: - if (wmn->data == ND_UNDO) { - ED_area_tag_refresh(sa); - } - break; - case NC_GPENCIL: - if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) { - ED_area_tag_redraw(sa); - } - break; - } + /* note, ED_area_tag_refresh will re-execute compositor */ + SpaceNode *snode = sa->spacedata.first; + /* shaderfrom is only used for new shading nodes, otherwise all shaders are from objects */ + short shader_type = snode->shaderfrom; + + /* preview renders */ + switch (wmn->category) { + case NC_SCENE: + switch (wmn->data) { + case ND_NODES: { + ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + bNodeTreePath *path = snode->treepath.last; + /* shift view to node tree center */ + if (ar && path) { + UI_view2d_center_set(&ar->v2d, path->view_center[0], path->view_center[1]); + } + + ED_area_tag_refresh(sa); + break; + } + case ND_FRAME: + ED_area_tag_refresh(sa); + break; + case ND_COMPO_RESULT: + ED_area_tag_redraw(sa); + break; + case ND_TRANSFORM_DONE: + if (ED_node_is_compositor(snode)) { + if (snode->flag & SNODE_AUTO_RENDER) { + snode->recalc = 1; + ED_area_tag_refresh(sa); + } + } + break; + case ND_LAYER_CONTENT: + ED_area_tag_refresh(sa); + break; + } + break; + + /* future: add ID checks? */ + case NC_MATERIAL: + if (ED_node_is_shader(snode)) { + if (wmn->data == ND_SHADING) { + ED_area_tag_refresh(sa); + } + else if (wmn->data == ND_SHADING_DRAW) { + ED_area_tag_refresh(sa); + } + else if (wmn->data == ND_SHADING_LINKS) { + ED_area_tag_refresh(sa); + } + else if (wmn->action == NA_ADDED && snode->edittree) { + nodeSetActiveID(snode->edittree, ID_MA, wmn->reference); + } + } + break; + case NC_TEXTURE: + if (ED_node_is_shader(snode) || ED_node_is_texture(snode)) { + if (wmn->data == ND_NODES) { + ED_area_tag_refresh(sa); + } + } + break; + case NC_WORLD: + if (ED_node_is_shader(snode) && shader_type == SNODE_SHADER_WORLD) { + ED_area_tag_refresh(sa); + } + break; + case NC_OBJECT: + if (ED_node_is_shader(snode)) { + if (wmn->data == ND_OB_SHADING) { + ED_area_tag_refresh(sa); + } + } + break; + case NC_SPACE: + if (wmn->data == ND_SPACE_NODE) { + ED_area_tag_refresh(sa); + } + else if (wmn->data == ND_SPACE_NODE_VIEW) { + ED_area_tag_redraw(sa); + } + break; + case NC_NODE: + if (wmn->action == NA_EDITED) { + ED_area_tag_refresh(sa); + } + else if (wmn->action == NA_SELECTED) { + ED_area_tag_redraw(sa); + } + break; + case NC_SCREEN: + switch (wmn->data) { + case ND_ANIMPLAY: + ED_area_tag_refresh(sa); + break; + } + break; + case NC_MASK: + if (wmn->action == NA_EDITED) { + if (snode->nodetree && snode->nodetree->type == NTREE_COMPOSIT) { + ED_area_tag_refresh(sa); + } + } + break; + + case NC_IMAGE: + if (wmn->action == NA_EDITED) { + if (ED_node_is_compositor(snode)) { + /* note that nodeUpdateID is already called by BKE_image_signal() on all + * scenes so really this is just to know if the images is used in the compo else + * painting on images could become very slow when the compositor is open. */ + if (nodeUpdateID(snode->nodetree, wmn->reference)) { + ED_area_tag_refresh(sa); + } + } + } + break; + + case NC_MOVIECLIP: + if (wmn->action == NA_EDITED) { + if (ED_node_is_compositor(snode)) { + if (nodeUpdateID(snode->nodetree, wmn->reference)) { + ED_area_tag_refresh(sa); + } + } + } + break; + + case NC_LINESTYLE: + if (ED_node_is_shader(snode) && shader_type == SNODE_SHADER_LINESTYLE) { + ED_area_tag_refresh(sa); + } + break; + case NC_WM: + if (wmn->data == ND_UNDO) { + ED_area_tag_refresh(sa); + } + break; + case NC_GPENCIL: + if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) { + ED_area_tag_redraw(sa); + } + break; + } } static void node_area_refresh(const struct bContext *C, ScrArea *sa) { - /* default now: refresh node is starting preview */ - SpaceNode *snode = sa->spacedata.first; - - snode_set_context(C); - - if (snode->nodetree) { - if (snode->nodetree->type == NTREE_SHADER) { - if (GS(snode->id->name) == ID_MA) { - Material *ma = (Material *)snode->id; - if (ma->use_nodes) { - ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); - } - } - else if (GS(snode->id->name) == ID_LA) { - Light *la = (Light *)snode->id; - if (la->use_nodes) { - ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); - } - } - else if (GS(snode->id->name) == ID_WO) { - World *wo = (World *)snode->id; - if (wo->use_nodes) { - ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); - } - } - } - else if (snode->nodetree->type == NTREE_COMPOSIT) { - Scene *scene = (Scene *)snode->id; - if (scene->use_nodes) { - /* recalc is set on 3d view changes for auto compo */ - if (snode->recalc) { - snode->recalc = 0; - node_render_changed_exec((struct bContext *)C, NULL); - } - else { - ED_node_composite_job(C, snode->nodetree, scene); - } - } - } - else if (snode->nodetree->type == NTREE_TEXTURE) { - Tex *tex = (Tex *)snode->id; - if (tex->use_nodes) { - ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); - } - } - } + /* default now: refresh node is starting preview */ + SpaceNode *snode = sa->spacedata.first; + + snode_set_context(C); + + if (snode->nodetree) { + if (snode->nodetree->type == NTREE_SHADER) { + if (GS(snode->id->name) == ID_MA) { + Material *ma = (Material *)snode->id; + if (ma->use_nodes) { + ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); + } + } + else if (GS(snode->id->name) == ID_LA) { + Light *la = (Light *)snode->id; + if (la->use_nodes) { + ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); + } + } + else if (GS(snode->id->name) == ID_WO) { + World *wo = (World *)snode->id; + if (wo->use_nodes) { + ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); + } + } + } + else if (snode->nodetree->type == NTREE_COMPOSIT) { + Scene *scene = (Scene *)snode->id; + if (scene->use_nodes) { + /* recalc is set on 3d view changes for auto compo */ + if (snode->recalc) { + snode->recalc = 0; + node_render_changed_exec((struct bContext *)C, NULL); + } + else { + ED_node_composite_job(C, snode->nodetree, scene); + } + } + } + else if (snode->nodetree->type == NTREE_TEXTURE) { + Tex *tex = (Tex *)snode->id; + if (tex->use_nodes) { + ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100, PR_NODE_RENDER); + } + } + } } static SpaceLink *node_duplicate(SpaceLink *sl) { - SpaceNode *snode = (SpaceNode *)sl; - SpaceNode *snoden = MEM_dupallocN(snode); + SpaceNode *snode = (SpaceNode *)sl; + SpaceNode *snoden = MEM_dupallocN(snode); - BLI_duplicatelist(&snoden->treepath, &snode->treepath); + BLI_duplicatelist(&snoden->treepath, &snode->treepath); - /* clear or remove stuff from old */ - BLI_listbase_clear(&snoden->linkdrag); + /* clear or remove stuff from old */ + BLI_listbase_clear(&snoden->linkdrag); - /* Note: no need to set node tree user counts, - * the editor only keeps at least 1 (id_us_ensure_real), - * which is already done by the original SpaceNode. - */ + /* Note: no need to set node tree user counts, + * the editor only keeps at least 1 (id_us_ensure_real), + * which is already done by the original SpaceNode. + */ - return (SpaceLink *)snoden; + return (SpaceLink *)snoden; } - /* add handlers, stuff you only do once or on area/region changes */ static void node_buttons_region_init(wmWindowManager *wm, ARegion *ar) { - wmKeyMap *keymap; + wmKeyMap *keymap; - ED_region_panels_init(wm, ar); + ED_region_panels_init(wm, ar); - keymap = WM_keymap_ensure(wm->defaultconf, "Node Generic", SPACE_NODE, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); + keymap = WM_keymap_ensure(wm->defaultconf, "Node Generic", SPACE_NODE, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); } static void node_buttons_region_draw(const bContext *C, ARegion *ar) { - ED_region_panels(C, ar); + ED_region_panels(C, ar); } /* add handlers, stuff you only do once or on area/region changes */ static void node_toolbar_region_init(wmWindowManager *wm, ARegion *ar) { - wmKeyMap *keymap; + wmKeyMap *keymap; - ED_region_panels_init(wm, ar); + ED_region_panels_init(wm, ar); - keymap = WM_keymap_ensure(wm->defaultconf, "Node Generic", SPACE_NODE, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); + keymap = WM_keymap_ensure(wm->defaultconf, "Node Generic", SPACE_NODE, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); } static void node_toolbar_region_draw(const bContext *C, ARegion *ar) { - ED_region_panels(C, ar); + ED_region_panels(C, ar); } static void node_cursor(wmWindow *win, ScrArea *sa, ARegion *ar) { - SpaceNode *snode = sa->spacedata.first; - - /* convert mouse coordinates to v2d space */ - UI_view2d_region_to_view(&ar->v2d, win->eventstate->x - ar->winrct.xmin, win->eventstate->y - ar->winrct.ymin, - &snode->cursor[0], &snode->cursor[1]); + SpaceNode *snode = sa->spacedata.first; - /* here snode->cursor is used to detect the node edge for sizing */ - node_set_cursor(win, snode, snode->cursor); + /* convert mouse coordinates to v2d space */ + UI_view2d_region_to_view(&ar->v2d, + win->eventstate->x - ar->winrct.xmin, + win->eventstate->y - ar->winrct.ymin, + &snode->cursor[0], + &snode->cursor[1]); - /* XXX snode->cursor is in placing new nodes space */ - snode->cursor[0] /= UI_DPI_FAC; - snode->cursor[1] /= UI_DPI_FAC; + /* here snode->cursor is used to detect the node edge for sizing */ + node_set_cursor(win, snode, snode->cursor); + /* XXX snode->cursor is in placing new nodes space */ + snode->cursor[0] /= UI_DPI_FAC; + snode->cursor[1] /= UI_DPI_FAC; } /* Initialize main region, setting handlers. */ static void node_main_region_init(wmWindowManager *wm, ARegion *ar) { - wmKeyMap *keymap; - ListBase *lb; + wmKeyMap *keymap; + ListBase *lb; - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); + UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); - /* own keymaps */ - keymap = WM_keymap_ensure(wm->defaultconf, "Node Generic", SPACE_NODE, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); + /* own keymaps */ + keymap = WM_keymap_ensure(wm->defaultconf, "Node Generic", SPACE_NODE, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); - keymap = WM_keymap_ensure(wm->defaultconf, "Node Editor", SPACE_NODE, 0); - WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + keymap = WM_keymap_ensure(wm->defaultconf, "Node Editor", SPACE_NODE, 0); + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); - /* add drop boxes */ - lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW); + /* add drop boxes */ + lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW); - WM_event_add_dropbox_handler(&ar->handlers, lb); + WM_event_add_dropbox_handler(&ar->handlers, lb); } static void node_main_region_draw(const bContext *C, ARegion *ar) { - drawnodespace(C, ar); + drawnodespace(C, ar); } - /* ************* dropboxes ************* */ -static bool node_ima_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip)) +static bool node_ima_drop_poll(bContext *UNUSED(C), + wmDrag *drag, + const wmEvent *UNUSED(event), + const char **UNUSED(tooltip)) { - if (drag->type == WM_DRAG_PATH) { - /* rule might not work? */ - return (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE)); - } - else { - return WM_drag_ID(drag, ID_IM) != NULL; - } + if (drag->type == WM_DRAG_PATH) { + /* rule might not work? */ + return (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE)); + } + else { + return WM_drag_ID(drag, ID_IM) != NULL; + } } -static bool node_mask_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip)) +static bool node_mask_drop_poll(bContext *UNUSED(C), + wmDrag *drag, + const wmEvent *UNUSED(event), + const char **UNUSED(tooltip)) { - return WM_drag_ID(drag, ID_MSK) != NULL; + return WM_drag_ID(drag, ID_MSK) != NULL; } static void node_id_drop_copy(wmDrag *drag, wmDropBox *drop) { - ID *id = WM_drag_ID(drag, 0); + ID *id = WM_drag_ID(drag, 0); - RNA_string_set(drop->ptr, "name", id->name + 2); + RNA_string_set(drop->ptr, "name", id->name + 2); } static void node_id_path_drop_copy(wmDrag *drag, wmDropBox *drop) { - ID *id = WM_drag_ID(drag, 0); - - if (id) { - RNA_string_set(drop->ptr, "name", id->name + 2); - RNA_struct_property_unset(drop->ptr, "filepath"); - } - else if (drag->path[0]) { - RNA_string_set(drop->ptr, "filepath", drag->path); - RNA_struct_property_unset(drop->ptr, "name"); - } + ID *id = WM_drag_ID(drag, 0); + + if (id) { + RNA_string_set(drop->ptr, "name", id->name + 2); + RNA_struct_property_unset(drop->ptr, "filepath"); + } + else if (drag->path[0]) { + RNA_string_set(drop->ptr, "filepath", drag->path); + RNA_struct_property_unset(drop->ptr, "name"); + } } /* this region dropbox definition */ static void node_dropboxes(void) { - ListBase *lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW); - - WM_dropbox_add(lb, "NODE_OT_add_file", node_ima_drop_poll, node_id_path_drop_copy); - WM_dropbox_add(lb, "NODE_OT_add_mask", node_mask_drop_poll, node_id_drop_copy); + ListBase *lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW); + WM_dropbox_add(lb, "NODE_OT_add_file", node_ima_drop_poll, node_id_path_drop_copy); + WM_dropbox_add(lb, "NODE_OT_add_mask", node_mask_drop_poll, node_id_drop_copy); } /* ************* end drop *********** */ - /* add handlers, stuff you only do once or on area/region changes */ static void node_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar) { - ED_region_header_init(ar); + ED_region_header_init(ar); } static void node_header_region_draw(const bContext *C, ARegion *ar) { - /* find and set the context */ - snode_set_context(C); + /* find and set the context */ + snode_set_context(C); - ED_region_header(C, ar); + ED_region_header(C, ar); } /* used for header + main region */ -static void node_region_listener( - wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar, - wmNotifier *wmn, const Scene *UNUSED(scene)) +static void node_region_listener(wmWindow *UNUSED(win), + ScrArea *UNUSED(sa), + ARegion *ar, + wmNotifier *wmn, + const Scene *UNUSED(scene)) { - wmGizmoMap *gzmap = ar->gizmo_map; - - /* context changes */ - switch (wmn->category) { - case NC_SPACE: - switch (wmn->data) { - case ND_SPACE_NODE: - ED_region_tag_redraw(ar); - break; - case ND_SPACE_NODE_VIEW: - WM_gizmomap_tag_refresh(gzmap); - break; - } - break; - case NC_SCREEN: - if (wmn->data == ND_LAYOUTSET || wmn->action == NA_EDITED) { - WM_gizmomap_tag_refresh(gzmap); - } - switch (wmn->data) { - case ND_ANIMPLAY: - case ND_LAYER: - ED_region_tag_redraw(ar); - break; - } - break; - case NC_WM: - if (wmn->data == ND_JOB) { - ED_region_tag_redraw(ar); - } - break; - case NC_SCENE: - ED_region_tag_redraw(ar); - if (wmn->data == ND_RENDER_RESULT) { - WM_gizmomap_tag_refresh(gzmap); - } - break; - case NC_NODE: - ED_region_tag_redraw(ar); - if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) { - WM_gizmomap_tag_refresh(gzmap); - } - break; - case NC_MATERIAL: - case NC_TEXTURE: - case NC_WORLD: - case NC_LINESTYLE: - ED_region_tag_redraw(ar); - break; - case NC_OBJECT: - if (wmn->data == ND_OB_SHADING) { - ED_region_tag_redraw(ar); - } - break; - case NC_ID: - if (wmn->action == NA_RENAME) { - ED_region_tag_redraw(ar); - } - break; - case NC_GPENCIL: - if (wmn->action == NA_EDITED) { - ED_region_tag_redraw(ar); - } - else if (wmn->data & ND_GPENCIL_EDITMODE) { - ED_region_tag_redraw(ar); - } - break; - } + wmGizmoMap *gzmap = ar->gizmo_map; + + /* context changes */ + switch (wmn->category) { + case NC_SPACE: + switch (wmn->data) { + case ND_SPACE_NODE: + ED_region_tag_redraw(ar); + break; + case ND_SPACE_NODE_VIEW: + WM_gizmomap_tag_refresh(gzmap); + break; + } + break; + case NC_SCREEN: + if (wmn->data == ND_LAYOUTSET || wmn->action == NA_EDITED) { + WM_gizmomap_tag_refresh(gzmap); + } + switch (wmn->data) { + case ND_ANIMPLAY: + case ND_LAYER: + ED_region_tag_redraw(ar); + break; + } + break; + case NC_WM: + if (wmn->data == ND_JOB) { + ED_region_tag_redraw(ar); + } + break; + case NC_SCENE: + ED_region_tag_redraw(ar); + if (wmn->data == ND_RENDER_RESULT) { + WM_gizmomap_tag_refresh(gzmap); + } + break; + case NC_NODE: + ED_region_tag_redraw(ar); + if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) { + WM_gizmomap_tag_refresh(gzmap); + } + break; + case NC_MATERIAL: + case NC_TEXTURE: + case NC_WORLD: + case NC_LINESTYLE: + ED_region_tag_redraw(ar); + break; + case NC_OBJECT: + if (wmn->data == ND_OB_SHADING) { + ED_region_tag_redraw(ar); + } + break; + case NC_ID: + if (wmn->action == NA_RENAME) { + ED_region_tag_redraw(ar); + } + break; + case NC_GPENCIL: + if (wmn->action == NA_EDITED) { + ED_region_tag_redraw(ar); + } + else if (wmn->data & ND_GPENCIL_EDITMODE) { + ED_region_tag_redraw(ar); + } + break; + } } const char *node_context_dir[] = { - "selected_nodes", "active_node", "light", "material", "world", NULL -}; + "selected_nodes", "active_node", "light", "material", "world", NULL}; static int node_context(const bContext *C, const char *member, bContextDataResult *result) { - SpaceNode *snode = CTX_wm_space_node(C); - - if (CTX_data_dir(member)) { - CTX_data_dir_set(result, node_context_dir); - return 1; - } - else if (CTX_data_equals(member, "selected_nodes")) { - bNode *node; - - if (snode->edittree) { - for (node = snode->edittree->nodes.last; node; node = node->prev) { - if (node->flag & NODE_SELECT) { - CTX_data_list_add(result, &snode->edittree->id, &RNA_Node, node); - } - } - } - CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); - return 1; - } - else if (CTX_data_equals(member, "active_node")) { - if (snode->edittree) { - bNode *node = nodeGetActive(snode->edittree); - CTX_data_pointer_set(result, &snode->edittree->id, &RNA_Node, node); - } - - CTX_data_type_set(result, CTX_DATA_TYPE_POINTER); - return 1; - } - else if (CTX_data_equals(member, "node_previews")) { - if (snode->nodetree) { - CTX_data_pointer_set(result, &snode->nodetree->id, &RNA_NodeInstanceHash, snode->nodetree->previews); - } - - CTX_data_type_set(result, CTX_DATA_TYPE_POINTER); - return 1; - } - else if (CTX_data_equals(member, "material")) { - if (snode->id && GS(snode->id->name) == ID_MA) { - CTX_data_id_pointer_set(result, snode->id); - } - return 1; - } - else if (CTX_data_equals(member, "light")) { - if (snode->id && GS(snode->id->name) == ID_LA) { - CTX_data_id_pointer_set(result, snode->id); - } - return 1; - } - else if (CTX_data_equals(member, "world")) { - if (snode->id && GS(snode->id->name) == ID_WO) { - CTX_data_id_pointer_set(result, snode->id); - } - return 1; - } - - return 0; + SpaceNode *snode = CTX_wm_space_node(C); + + if (CTX_data_dir(member)) { + CTX_data_dir_set(result, node_context_dir); + return 1; + } + else if (CTX_data_equals(member, "selected_nodes")) { + bNode *node; + + if (snode->edittree) { + for (node = snode->edittree->nodes.last; node; node = node->prev) { + if (node->flag & NODE_SELECT) { + CTX_data_list_add(result, &snode->edittree->id, &RNA_Node, node); + } + } + } + CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); + return 1; + } + else if (CTX_data_equals(member, "active_node")) { + if (snode->edittree) { + bNode *node = nodeGetActive(snode->edittree); + CTX_data_pointer_set(result, &snode->edittree->id, &RNA_Node, node); + } + + CTX_data_type_set(result, CTX_DATA_TYPE_POINTER); + return 1; + } + else if (CTX_data_equals(member, "node_previews")) { + if (snode->nodetree) { + CTX_data_pointer_set( + result, &snode->nodetree->id, &RNA_NodeInstanceHash, snode->nodetree->previews); + } + + CTX_data_type_set(result, CTX_DATA_TYPE_POINTER); + return 1; + } + else if (CTX_data_equals(member, "material")) { + if (snode->id && GS(snode->id->name) == ID_MA) { + CTX_data_id_pointer_set(result, snode->id); + } + return 1; + } + else if (CTX_data_equals(member, "light")) { + if (snode->id && GS(snode->id->name) == ID_LA) { + CTX_data_id_pointer_set(result, snode->id); + } + return 1; + } + else if (CTX_data_equals(member, "world")) { + if (snode->id && GS(snode->id->name) == ID_WO) { + CTX_data_id_pointer_set(result, snode->id); + } + return 1; + } + + return 0; } static void node_widgets(void) { - /* create the widgetmap for the area here */ - wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure( - &(const struct wmGizmoMapType_Params){SPACE_NODE, RGN_TYPE_WINDOW}); - WM_gizmogrouptype_append_and_link(gzmap_type, NODE_GGT_backdrop_transform); - WM_gizmogrouptype_append_and_link(gzmap_type, NODE_GGT_backdrop_crop); - WM_gizmogrouptype_append_and_link(gzmap_type, NODE_GGT_backdrop_sun_beams); - WM_gizmogrouptype_append_and_link(gzmap_type, NODE_GGT_backdrop_corner_pin); + /* create the widgetmap for the area here */ + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure( + &(const struct wmGizmoMapType_Params){SPACE_NODE, RGN_TYPE_WINDOW}); + WM_gizmogrouptype_append_and_link(gzmap_type, NODE_GGT_backdrop_transform); + WM_gizmogrouptype_append_and_link(gzmap_type, NODE_GGT_backdrop_crop); + WM_gizmogrouptype_append_and_link(gzmap_type, NODE_GGT_backdrop_sun_beams); + WM_gizmogrouptype_append_and_link(gzmap_type, NODE_GGT_backdrop_corner_pin); } static void node_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id) { - SpaceNode *snode = (SpaceNode *)slink; - - if (GS(old_id->name) == ID_SCE) { - if (snode->id == old_id) { - /* nasty DNA logic for SpaceNode: - * ideally should be handled by editor code, but would be bad level call - */ - BLI_freelistN(&snode->treepath); - - /* XXX Untested in case new_id != NULL... */ - snode->id = new_id; - snode->from = NULL; - snode->nodetree = NULL; - snode->edittree = NULL; - } - } - else if (GS(old_id->name) == ID_OB) { - if (snode->from == old_id) { - if (new_id == NULL) { - snode->flag &= ~SNODE_PIN; - } - snode->from = new_id; - } - } - else if (GS(old_id->name) == ID_GD) { - if ((ID *)snode->gpd == old_id) { - snode->gpd = (bGPdata *)new_id; - id_us_min(old_id); - id_us_plus(new_id); - } - } - else if (GS(old_id->name) == ID_NT) { - bNodeTreePath *path, *path_next; - - for (path = snode->treepath.first; path; path = path->next) { - if ((ID *)path->nodetree == old_id) { - path->nodetree = (bNodeTree *)new_id; - id_us_min(old_id); - id_us_plus(new_id); - } - if (path == snode->treepath.first) { - /* first nodetree in path is same as snode->nodetree */ - snode->nodetree = path->nodetree; - } - if (path->nodetree == NULL) { - break; - } - } - - /* remaining path entries are invalid, remove */ - for (; path; path = path_next) { - path_next = path->next; - - BLI_remlink(&snode->treepath, path); - MEM_freeN(path); - } - - /* edittree is just the last in the path, - * set this directly since the path may have been shortened above */ - if (snode->treepath.last) { - path = snode->treepath.last; - snode->edittree = path->nodetree; - } - else { - snode->edittree = NULL; - } - } + SpaceNode *snode = (SpaceNode *)slink; + + if (GS(old_id->name) == ID_SCE) { + if (snode->id == old_id) { + /* nasty DNA logic for SpaceNode: + * ideally should be handled by editor code, but would be bad level call + */ + BLI_freelistN(&snode->treepath); + + /* XXX Untested in case new_id != NULL... */ + snode->id = new_id; + snode->from = NULL; + snode->nodetree = NULL; + snode->edittree = NULL; + } + } + else if (GS(old_id->name) == ID_OB) { + if (snode->from == old_id) { + if (new_id == NULL) { + snode->flag &= ~SNODE_PIN; + } + snode->from = new_id; + } + } + else if (GS(old_id->name) == ID_GD) { + if ((ID *)snode->gpd == old_id) { + snode->gpd = (bGPdata *)new_id; + id_us_min(old_id); + id_us_plus(new_id); + } + } + else if (GS(old_id->name) == ID_NT) { + bNodeTreePath *path, *path_next; + + for (path = snode->treepath.first; path; path = path->next) { + if ((ID *)path->nodetree == old_id) { + path->nodetree = (bNodeTree *)new_id; + id_us_min(old_id); + id_us_plus(new_id); + } + if (path == snode->treepath.first) { + /* first nodetree in path is same as snode->nodetree */ + snode->nodetree = path->nodetree; + } + if (path->nodetree == NULL) { + break; + } + } + + /* remaining path entries are invalid, remove */ + for (; path; path = path_next) { + path_next = path->next; + + BLI_remlink(&snode->treepath, path); + MEM_freeN(path); + } + + /* edittree is just the last in the path, + * set this directly since the path may have been shortened above */ + if (snode->treepath.last) { + path = snode->treepath.last; + snode->edittree = path->nodetree; + } + else { + snode->edittree = NULL; + } + } } - static int node_space_subtype_get(ScrArea *sa) { - SpaceNode *snode = sa->spacedata.first; - return rna_node_tree_idname_to_enum(snode->tree_idname); + SpaceNode *snode = sa->spacedata.first; + return rna_node_tree_idname_to_enum(snode->tree_idname); } static void node_space_subtype_set(ScrArea *sa, int value) { - SpaceNode *snode = sa->spacedata.first; - ED_node_set_tree_type(snode, rna_node_tree_type_from_enum(value)); + SpaceNode *snode = sa->spacedata.first; + ED_node_set_tree_type(snode, rna_node_tree_type_from_enum(value)); } -static void node_space_subtype_item_extend( - bContext *C, EnumPropertyItem **item, int *totitem) +static void node_space_subtype_item_extend(bContext *C, EnumPropertyItem **item, int *totitem) { - bool free; - const EnumPropertyItem *item_src = RNA_enum_node_tree_types_itemf_impl(C, &free); - for (const EnumPropertyItem *item_iter = item_src; item_iter->identifier; item_iter++) { - RNA_enum_item_add(item, totitem, item_iter); - } - if (free) { - MEM_freeN((void *)item_src); - } + bool free; + const EnumPropertyItem *item_src = RNA_enum_node_tree_types_itemf_impl(C, &free); + for (const EnumPropertyItem *item_iter = item_src; item_iter->identifier; item_iter++) { + RNA_enum_item_add(item, totitem, item_iter); + } + if (free) { + MEM_freeN((void *)item_src); + } } /* only called once, from space/spacetypes.c */ void ED_spacetype_node(void) { - SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype node"); - ARegionType *art; - - st->spaceid = SPACE_NODE; - strncpy(st->name, "Node", BKE_ST_MAXNAME); - - st->new = node_new; - st->free = node_free; - st->init = node_init; - st->duplicate = node_duplicate; - st->operatortypes = node_operatortypes; - st->keymap = node_keymap; - st->listener = node_area_listener; - st->refresh = node_area_refresh; - st->context = node_context; - st->dropboxes = node_dropboxes; - st->gizmos = node_widgets; - st->id_remap = node_id_remap; - st->space_subtype_item_extend = node_space_subtype_item_extend; - st->space_subtype_get = node_space_subtype_get; - st->space_subtype_set = node_space_subtype_set; - - /* regions: main window */ - art = MEM_callocN(sizeof(ARegionType), "spacetype node region"); - art->regionid = RGN_TYPE_WINDOW; - art->init = node_main_region_init; - art->draw = node_main_region_draw; - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_GIZMO | ED_KEYMAP_TOOL | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL; - art->listener = node_region_listener; - art->cursor = node_cursor; - art->event_cursor = true; - - BLI_addhead(&st->regiontypes, art); - - /* regions: header */ - art = MEM_callocN(sizeof(ARegionType), "spacetype node region"); - art->regionid = RGN_TYPE_HEADER; - art->prefsizey = HEADERY; - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; - art->listener = node_region_listener; - art->init = node_header_region_init; - art->draw = node_header_region_draw; - - BLI_addhead(&st->regiontypes, art); - - /* regions: listview/buttons */ - art = MEM_callocN(sizeof(ARegionType), "spacetype node region"); - art->regionid = RGN_TYPE_UI; - art->prefsizex = 180; // XXX - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; - art->listener = node_region_listener; - art->init = node_buttons_region_init; - art->draw = node_buttons_region_draw; - BLI_addhead(&st->regiontypes, art); - - node_buttons_register(art); - - /* regions: toolbar */ - art = MEM_callocN(sizeof(ARegionType), "spacetype view3d tools region"); - art->regionid = RGN_TYPE_TOOLS; - art->prefsizex = 58; /* XXX */ - art->prefsizey = 50; /* XXX */ - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; - art->listener = node_region_listener; - art->message_subscribe = ED_region_generic_tools_region_message_subscribe; - art->snap_size = ED_region_generic_tools_region_snap_size; - art->init = node_toolbar_region_init; - art->draw = node_toolbar_region_draw; - BLI_addhead(&st->regiontypes, art); - - node_toolbar_register(art); - - BKE_spacetype_register(st); + SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype node"); + ARegionType *art; + + st->spaceid = SPACE_NODE; + strncpy(st->name, "Node", BKE_ST_MAXNAME); + + st->new = node_new; + st->free = node_free; + st->init = node_init; + st->duplicate = node_duplicate; + st->operatortypes = node_operatortypes; + st->keymap = node_keymap; + st->listener = node_area_listener; + st->refresh = node_area_refresh; + st->context = node_context; + st->dropboxes = node_dropboxes; + st->gizmos = node_widgets; + st->id_remap = node_id_remap; + st->space_subtype_item_extend = node_space_subtype_item_extend; + st->space_subtype_get = node_space_subtype_get; + st->space_subtype_set = node_space_subtype_set; + + /* regions: main window */ + art = MEM_callocN(sizeof(ARegionType), "spacetype node region"); + art->regionid = RGN_TYPE_WINDOW; + art->init = node_main_region_init; + art->draw = node_main_region_draw; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_GIZMO | ED_KEYMAP_TOOL | ED_KEYMAP_VIEW2D | + ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL; + art->listener = node_region_listener; + art->cursor = node_cursor; + art->event_cursor = true; + + BLI_addhead(&st->regiontypes, art); + + /* regions: header */ + art = MEM_callocN(sizeof(ARegionType), "spacetype node region"); + art->regionid = RGN_TYPE_HEADER; + art->prefsizey = HEADERY; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; + art->listener = node_region_listener; + art->init = node_header_region_init; + art->draw = node_header_region_draw; + + BLI_addhead(&st->regiontypes, art); + + /* regions: listview/buttons */ + art = MEM_callocN(sizeof(ARegionType), "spacetype node region"); + art->regionid = RGN_TYPE_UI; + art->prefsizex = 180; // XXX + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; + art->listener = node_region_listener; + art->init = node_buttons_region_init; + art->draw = node_buttons_region_draw; + BLI_addhead(&st->regiontypes, art); + + node_buttons_register(art); + + /* regions: toolbar */ + art = MEM_callocN(sizeof(ARegionType), "spacetype view3d tools region"); + art->regionid = RGN_TYPE_TOOLS; + art->prefsizex = 58; /* XXX */ + art->prefsizey = 50; /* XXX */ + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; + art->listener = node_region_listener; + art->message_subscribe = ED_region_generic_tools_region_message_subscribe; + art->snap_size = ED_region_generic_tools_region_snap_size; + art->init = node_toolbar_region_init; + art->draw = node_toolbar_region_draw; + BLI_addhead(&st->regiontypes, art); + + node_toolbar_register(art); + + BKE_spacetype_register(st); } |