diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-26 13:16:47 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-26 13:16:47 +0300 |
commit | ce3b78c73a7ccc16fdccf7decedb5d1578dfdf0a (patch) | |
tree | 87f1a9c41ebe6f74806f1ae76206f1d328c85700 /source/blender/editors/space_node | |
parent | 5279d118c2ddee0e6fef66aaf78452c1b302dd42 (diff) |
Cleanup: style, use braces for editor/spaces
Diffstat (limited to 'source/blender/editors/space_node')
-rw-r--r-- | source/blender/editors/space_node/drawnode.c | 199 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_add.c | 28 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_buttons.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_draw.c | 207 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 322 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_group.c | 96 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_relationships.c | 254 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_select.c | 114 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_templates.c | 138 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_toolbar.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_view.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_node/space_node.c | 106 |
12 files changed, 993 insertions, 486 deletions
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 60dcdaebb08..be26f67b936 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -115,8 +115,9 @@ static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA col = uiLayoutColumn(layout, false); row = uiLayoutRow(col, true); uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE); - if (ELEM(ntree->type, NTREE_COMPOSIT, NTREE_TEXTURE)) + 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); } @@ -257,20 +258,24 @@ static int node_resize_area_default(bNode *node, int x, int y) rctf totr = node->totr; /* right part of node */ totr.xmin = node->totr.xmax - 20.0f; - if (BLI_rctf_isect_pt(&totr, x, y)) + if (BLI_rctf_isect_pt(&totr, x, y)) { return NODE_RESIZE_RIGHT; - else + } + 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) + 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) + } + if (x >= totr.xmin && x < totr.xmin + size && y >= totr.ymin && y < totr.ymax) { dir |= NODE_RESIZE_LEFT; + } return dir; } } @@ -306,8 +311,9 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree, 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) + if (tnode->parent != node) { continue; + } /* add margin to node rect */ noderect = tnode->totr; @@ -322,8 +328,9 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree, rect = noderect; data->flag &= ~NODE_FRAME_RESIZEABLE; } - else + else { BLI_rctf_union(&rect, &noderect); + } } /* now adjust the frame size from view-space bounding box */ @@ -445,18 +452,21 @@ static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode, if (node->flag & NODE_CUSTOM_COLOR) { rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], alpha); } - else + 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) + if (node->flag & NODE_ACTIVE) { UI_GetThemeColorShadeAlpha4fv(TH_ACTIVE, 0, -40, color); - else + } + else { UI_GetThemeColorShadeAlpha4fv(TH_SELECT, 0, -40, color); + } UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color); } @@ -479,17 +489,22 @@ static int node_resize_area_frame(bNode *node, int x, int y) int dir = 0; /* shrinking frame size is determined by child nodes */ - if (!(data->flag & NODE_FRAME_RESIZEABLE)) + if (!(data->flag & NODE_FRAME_RESIZEABLE)) { return 0; + } - if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax) + 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) + } + 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) + } + 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) + } + if (x >= totr.xmin && x < totr.xmax && y >= totr.ymin && y < totr.ymin + size) { dir |= NODE_RESIZE_BOTTOM; + } return dir; } @@ -636,8 +651,9 @@ static void node_buts_image_user(uiLayout *layout, bContext *C, PointerRNA *ptr, uiLayout *col; int source; - if (!imaptr->data) + if (!imaptr->data) { return; + } col = uiLayoutColumn(layout, false); @@ -790,8 +806,9 @@ static void node_shader_buts_tex_environment_ex(uiLayout *layout, bContext *C, P layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (!ima) + if (!ima) { return; + } uiItemR(layout, &imaptr, "source", 0, IFACE_("Source"), ICON_NONE); @@ -799,10 +816,12 @@ static void node_shader_buts_tex_environment_ex(uiLayout *layout, bContext *C, P uiLayout *row = uiLayoutRow(layout, true); const bool is_packed = BKE_image_has_packedfile(ima); - if (is_packed) + if (is_packed) { uiItemO(row, "", ICON_PACKAGE, "image.unpack"); - else + } + else { uiItemO(row, "", ICON_UGLYPACKAGE, "image.pack"); + } row = uiLayoutRow(row, true); uiLayoutSetEnabled(row, !is_packed); @@ -829,8 +848,9 @@ static void node_shader_buts_tex_sky(uiLayout *layout, bContext *UNUSED(C), Poin 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) + 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) @@ -903,12 +923,14 @@ static void node_shader_buts_tex_pointdensity(uiLayout *layout, bContext *UNUSED 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) + 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) + if (obdata_ptr.data) { uiItemPointerR(layout, ptr, "vertex_attribute_name", &obdata_ptr, "vertex_colors", "", ICON_NONE); + } } } } @@ -954,8 +976,9 @@ static void node_shader_buts_normal_map(uiLayout *layout, bContext *C, PointerRN PointerRNA dataptr = RNA_pointer_get(&obptr, "data"); uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE); } - else + else { uiItemR(layout, ptr, "uv_map", 0, "", 0); + } } } @@ -981,11 +1004,13 @@ static void node_shader_buts_tangent(uiLayout *layout, bContext *C, PointerRNA * PointerRNA dataptr = RNA_pointer_get(&obptr, "data"); uiItemPointerR(row, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE); } - else + else { uiItemR(row, ptr, "uv_map", 0, "", 0); + } } - else + else { uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, NULL, 0); + } } static void node_shader_buts_glossy(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) @@ -1034,10 +1059,12 @@ static void node_shader_buts_ies(uiLayout *layout, bContext *UNUSED(C), PointerR row = uiLayoutRow(layout, true); - if (RNA_enum_get(ptr, "mode") == NODE_IES_INTERNAL) + if (RNA_enum_get(ptr, "mode") == NODE_IES_INTERNAL) { uiItemR(row, ptr, "ies", 0, "", ICON_NONE); - else + } + else { uiItemR(row, ptr, "filepath", 0, "", ICON_NONE); + } } static void node_shader_buts_script(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) @@ -1049,10 +1076,12 @@ static void node_shader_buts_script(uiLayout *layout, bContext *UNUSED(C), Point row = uiLayoutRow(layout, true); - if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_INTERNAL) + if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_INTERNAL) { uiItemR(row, ptr, "script", 0, "", ICON_NONE); - else + } + else { uiItemR(row, ptr, "filepath", 0, "", ICON_NONE); + } uiItemO(row, "", ICON_FILE_REFRESH, "node.shader_script_update"); } @@ -1247,16 +1276,19 @@ static void node_buts_image_views(uiLayout *layout, bContext *UNUSED(C), Pointer { uiLayout *col; - if (!imaptr->data) + if (!imaptr->data) { return; + } col = uiLayoutColumn(layout, false); if (RNA_boolean_get(ptr, "has_views")) { - if (RNA_enum_get(ptr, "view") == 0) + if (RNA_enum_get(ptr, "view") == 0) { uiItemR(col, ptr, "view", 0, NULL, ICON_CAMERA_STEREO); - else + } + else { uiItemR(col, ptr, "view", 0, NULL, ICON_SCENE); + } } } @@ -1270,7 +1302,9 @@ static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA * uiTemplateID( layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (!node->id) return; + if (!node->id) { + return; + } imaptr = RNA_pointer_get(ptr, "image"); @@ -1301,15 +1335,18 @@ static void node_composit_buts_viewlayers(uiLayout *layout, bContext *C, Pointer 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); prop = RNA_struct_find_property(ptr, "layer"); - if (!(RNA_property_enum_identifier(C, ptr, prop, RNA_property_enum_get(ptr, prop), &layer_name))) + 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); @@ -1431,8 +1468,9 @@ static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), Poin if (RNA_enum_get(ptr, "glare_type") != 1) { uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "glare_type") != 0) + 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); @@ -1445,8 +1483,9 @@ static void node_composit_buts_glare(uiLayout *layout, bContext *UNUSED(C), Poin 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) + 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); @@ -1754,10 +1793,12 @@ static void node_composit_buts_file_output(uiLayout *layout, bContext *UNUSED(C) PointerRNA imfptr = RNA_pointer_get(ptr, "format"); const bool multilayer = RNA_enum_get(&imfptr, "file_format") == R_IMF_IMTYPE_MULTILAYER; - if (multilayer) + if (multilayer) { uiItemL(layout, IFACE_("Path:"), ICON_NONE); - else + } + 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) @@ -1776,8 +1817,9 @@ static void node_composit_buts_file_output_ex(uiLayout *layout, bContext *C, Poi /* 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) + if (is_multiview) { uiTemplateImageFormatViews(layout, &imfptr, NULL); + } uiItemS(layout); @@ -1841,8 +1883,9 @@ static void node_composit_buts_file_output_ex(uiLayout *layout, bContext *C, Poi uiLayoutSetActive(col, RNA_boolean_get(&active_input_ptr, "use_node_format") == false); uiTemplateImageSettings(col, &imfptr, false); - if (is_multiview) + if (is_multiview) { uiTemplateImageFormatViews(layout, &imfptr, NULL); + } } } } @@ -1991,8 +2034,9 @@ static void node_composit_buts_movieclip_ex(uiLayout *layout, bContext *C, Point uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (!node->id) + if (!node->id) { return; + } clipptr = RNA_pointer_get(ptr, "clip"); @@ -2005,8 +2049,9 @@ static void node_composit_buts_stabilize2d(uiLayout *layout, bContext *C, Pointe uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (!node->id) + if (!node->id) { return; + } uiItemR(layout, ptr, "filter_type", 0, "", ICON_NONE); uiItemR(layout, ptr, "invert", 0, NULL, ICON_NONE); @@ -2029,8 +2074,9 @@ static void node_composit_buts_moviedistortion(uiLayout *layout, bContext *C, Po uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); - if (!node->id) + if (!node->id) { return; + } uiItemR(layout, ptr, "distortion_type", 0, "", ICON_NONE); } @@ -2913,8 +2959,9 @@ static void node_socket_template_properties_update(bNodeType *ntype, bNodeSocket StructRNA *srna = ntype->ext.srna; PropertyRNA *prop = RNA_struct_type_find_property(srna, stemp->identifier); - if (prop) + if (prop) { RNA_def_property_update_runtime(prop, node_property_update_default); + } } static void node_template_properties_update(bNodeType *ntype) @@ -2922,12 +2969,14 @@ static void node_template_properties_update(bNodeType *ntype) bNodeSocketTemplate *stemp; if (ntype->inputs) { - for (stemp = ntype->inputs; stemp->type >= 0; ++stemp) + 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) + for (stemp = ntype->outputs; stemp->type >= 0; ++stemp) { node_socket_template_properties_update(ntype, stemp); + } } } @@ -3077,8 +3126,9 @@ static void node_file_output_socket_draw(bContext *C, uiLayout *layout, PointerR uiItemL(row, input->path, ICON_NONE); - if (!RNA_boolean_get(&inputptr, "use_node_format")) + 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, @@ -3206,11 +3256,13 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b void *lock; ImBuf *ibuf; - if (!(snode->flag & SNODE_BACKDRAW) || !ED_node_is_compositor(snode)) + if (!(snode->flag & SNODE_BACKDRAW) || !ED_node_is_compositor(snode)) { return; + } - if (parent_key.value != active_viewer_key.value) + 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); @@ -3234,14 +3286,18 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); - if (snode->flag & SNODE_SHOW_R) + if (snode->flag & SNODE_SHOW_R) { shuffle[0] = 1.0f; - else if (snode->flag & SNODE_SHOW_G) + } + else if (snode->flag & SNODE_SHOW_G) { shuffle[1] = 1.0f; - else if (snode->flag & SNODE_SHOW_B) + } + else if (snode->flag & SNODE_SHOW_B) { shuffle[2] = 1.0f; - else + } + 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); @@ -3263,8 +3319,9 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom); } - if (cache_handle) + if (cache_handle) { IMB_display_buffer_release(cache_handle); + } } /** \note draw selected info on backdrop */ @@ -3330,7 +3387,9 @@ static bool node_link_bezier_handles(View2D *v2d, SpaceNode *snode, bNodeLink *l fromreroute = (link->fromnode && link->fromnode->type == NODE_REROUTE); } else { - if (snode == NULL) return 0; + if (snode == NULL) { + return 0; + } copy_v2_v2(vec[0], cursor); fromreroute = 0; } @@ -3340,7 +3399,9 @@ static bool node_link_bezier_handles(View2D *v2d, SpaceNode *snode, bNodeLink *l toreroute = (link->tonode && link->tonode->type == NODE_REROUTE); } else { - if (snode == NULL) return 0; + if (snode == NULL) { + return 0; + } copy_v2_v2(vec[3], cursor); toreroute = 0; } @@ -3477,8 +3538,9 @@ static void nodelink_batch_init(void) float exp[2] = {0.0f, 1.0f}; /* restart */ - if (k == 1) + 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) { @@ -3508,8 +3570,9 @@ static void nodelink_batch_init(void) } /* restart */ - if (k == 0) + 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); @@ -3548,8 +3611,9 @@ static char nodelink_get_color_id(int th_col) static void nodelink_batch_draw(SpaceNode *snode) { - if (g_batch_link.count == 0) + if (g_batch_link.count == 0) { return; + } GPU_blend(true); @@ -3655,8 +3719,9 @@ 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) + if (link->fromsock == NULL && link->tosock == NULL) { return; + } /* new connection */ if (!link->fromsock || !link->tosock) { @@ -3664,10 +3729,12 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) } else { /* going to give issues once... */ - if (link->tosock->flag & SOCK_UNAVAIL) + if (link->tosock->flag & SOCK_UNAVAIL) { return; - if (link->fromsock->flag & SOCK_UNAVAIL) + } + if (link->fromsock->flag & SOCK_UNAVAIL) { return; + } if (link->flag & NODE_LINK_VALID) { /* special indicated link, on drop-node */ @@ -3676,10 +3743,12 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) } else { /* regular link */ - if (link->fromnode && link->fromnode->flag & SELECT) + if (link->fromnode && link->fromnode->flag & SELECT) { th_col1 = TH_EDGE_SELECT; - if (link->tonode && link->tonode->flag & SELECT) + } + if (link->tonode && link->tonode->flag & SELECT) { th_col2 = TH_EDGE_SELECT; + } } } else { diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c index 6cb45f8d318..814496cf59e 100644 --- a/source/blender/editors/space_node/node_add.c +++ b/source/blender/editors/space_node/node_add.c @@ -65,10 +65,12 @@ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx node_deselect_all(snode); - if (idname) + if (idname) { node = nodeAddNode(C, snode->edittree, idname); - else + } + else { node = nodeAddStaticNode(C, snode->edittree, type); + } BLI_assert(node && node->typeinfo); /* Position mouse in node header. */ @@ -128,8 +130,9 @@ static bNodeSocketLink *add_reroute_insert_socket_link(ListBase *lb, bNodeSocket copy_v2_v2(socklink->point, point); for (prev = lb->last; prev; prev = prev->prev) { - if (prev->sock == sock) + if (prev->sock == sock) { break; + } } BLI_insertlinkafter(lb, prev, socklink); return socklink; @@ -208,7 +211,9 @@ static int add_reroute_exec(bContext *C, wmOperator *op) UI_view2d_region_to_view(&ar->v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]); i++; - if (i >= 256) break; + if (i >= 256) { + break; + } } RNA_END; @@ -228,8 +233,9 @@ static int add_reroute_exec(bContext *C, wmOperator *op) BLI_listbase_clear(&input_links); for (link = ntree->links.first; link; link = link->next) { - if (nodeLinkIsHidden(link)) + 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); @@ -356,10 +362,12 @@ static int node_add_file_invoke(bContext *C, wmOperator *op, const wmEvent *even 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")) + 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 + } + else { return WM_operator_filesel(C, op, event); + } } void NODE_OT_add_file(wmOperatorType *ot) @@ -460,10 +468,12 @@ static int new_node_tree_exec(bContext *C, wmOperator *op) 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) + else if (snode) { idname = snode->tree_idname; - else + } + else { return OPERATOR_CANCELLED; + } if (RNA_struct_property_is_set(op->ptr, "name")) { RNA_string_get(op->ptr, "name", treename_buf); diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c index da0be280f2c..13f8eb0729e 100644 --- a/source/blender/editors/space_node/node_buttons.c +++ b/source/blender/editors/space_node/node_buttons.c @@ -76,8 +76,9 @@ static void node_sockets_panel(const bContext *C, Panel *pa) uiLayout *layout = pa->layout, *split; char name[UI_MAX_NAME_STR]; - if (ELEM(NULL, ntree, node)) + if (ELEM(NULL, ntree, node)) { return; + } for (sock = node->inputs.first; sock; sock = sock->next) { BLI_snprintf(name, sizeof(name), "%s:", sock->name); @@ -128,8 +129,9 @@ static void node_tree_interface_panel(const bContext *C, Panel *pa) PointerRNA ptr, sockptr, opptr; wmOperatorType *ot; - if (!ntree) + if (!ntree) { return; + } RNA_id_pointer_create((ID *)ntree, &ptr); @@ -204,8 +206,9 @@ static int node_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) ScrArea *sa = CTX_wm_area(C); ARegion *ar = node_has_buttons_region(sa); - if (ar) + if (ar) { ED_region_toggle_hidden(C, ar); + } return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index afef027f7e1..2d25c067d69 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -120,8 +120,9 @@ static bNodeTree *node_tree_from_ID(ID *id) void ED_node_tag_update_id(ID *id) { bNodeTree *ntree = node_tree_from_ID(id); - if (id == NULL || ntree == NULL) + if (id == NULL || ntree == NULL) { return; + } /* TODO(sergey): With the new dependency graph it * should be just enough to only tag ntree itself, @@ -133,12 +134,15 @@ void ED_node_tag_update_id(ID *id) if (ntree->type == NTREE_SHADER) { DEG_id_tag_update(id, 0); - if (GS(id->name) == ID_MA) + if (GS(id->name) == ID_MA) { WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id); - else if (GS(id->name) == ID_LA) + } + else if (GS(id->name) == ID_LA) { WM_main_add_notifier(NC_LAMP | ND_LIGHTING, id); - else if (GS(id->name) == ID_WO) + } + 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); @@ -155,8 +159,9 @@ void ED_node_tag_update_id(ID *id) void ED_node_tag_update_nodetree(Main *bmain, bNodeTree *ntree, bNode *node) { - if (!ntree) + if (!ntree) { return; + } bool do_tag_update = true; if (node != NULL) { @@ -169,13 +174,15 @@ void ED_node_tag_update_nodetree(Main *bmain, bNodeTree *ntree, bNode *node) if (do_tag_update) { FOREACH_NODETREE_BEGIN(bmain, tntree, id) { /* check if nodetree uses the group */ - if (ntreeHasTree(tntree, ntree)) + if (ntreeHasTree(tntree, ntree)) { ED_node_tag_update_id(id); + } } FOREACH_NODETREE_END; } - if (ntree->type == NTREE_TEXTURE) + if (ntree->type == NTREE_TEXTURE) { ntreeTexCheckCyclics(ntree); + } } static bool compare_nodes(const bNode *a, const bNode *b) @@ -192,36 +199,46 @@ static bool compare_nodes(const bNode *a, const bNode *b) * 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) + if (parent == b) { return 1; + } /* any selected ancestor moves the node forward */ - if (parent->flag & NODE_ACTIVE) + if (parent->flag & NODE_ACTIVE) { a_active = 1; - if (parent->flag & NODE_SELECT) + } + 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) + if (parent == a) { return 0; + } /* any selected ancestor moves the node forward */ - if (parent->flag & NODE_ACTIVE) + if (parent->flag & NODE_ACTIVE) { b_active = 1; - if (parent->flag & NODE_SELECT) + } + 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)) + if ((a->flag & NODE_BACKGROUND) && !(b->flag & NODE_BACKGROUND)) { return 0; - else if (!(a->flag & NODE_BACKGROUND) && (b->flag & NODE_BACKGROUND)) + } + 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) + if (!b_active && a_active) { return 1; - else if (!b_select && (a_active || a_select)) + } + else if (!b_select && (a_active || a_select)) { return 1; + } return 0; } @@ -246,8 +263,9 @@ void ED_node_sort(bNodeTree *ntree) first_b = first_b->next; } /* all batches merged? */ - if (first_b == NULL) + if (first_b == NULL) { break; + } /* merge batches */ node_a = first_a; @@ -271,8 +289,9 @@ void ED_node_sort(bNodeTree *ntree) first_b = node_b; for (; b < k; ++b) { /* all nodes sorted? */ - if (first_b == NULL) + if (first_b == NULL) { break; + } first_b = first_b->next; } first_a = first_b; @@ -287,8 +306,9 @@ static void do_node_internal_buttons(bContext *C, void *UNUSED(node_v), int even { if (event == B_NODE_EXEC) { SpaceNode *snode = CTX_wm_space_node(C); - if (snode && snode->id) + if (snode && snode->id) { ED_node_tag_update_id(snode->id); + } } } @@ -351,15 +371,17 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) dy -= NODE_DY; /* little bit space in top */ - if (node->outputs.first) + 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)) + if (nodeSocketIsHidden(nsock)) { continue; + } RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr); @@ -387,8 +409,9 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) nsock->locy = 0.5f * (dy + buty); dy = buty; - if (nsock->next) + if (nsock->next) { dy -= NODE_SOCKDY; + } add_output_space = true; } @@ -404,14 +427,16 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) if (node->flag & NODE_PREVIEW) { float aspect = 1.0f; - if (node->preview_xsize && node->preview_ysize) + 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) + if (aspect <= 1.0f) { node->prvr.ymin = dy - aspect * (NODE_WIDTH(node) - NODE_DY); + } else { /* width correction of image */ /* XXX huh? (ton) */ @@ -426,8 +451,12 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) 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); + 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? */ @@ -456,8 +485,9 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) /* input sockets */ for (nsock = node->inputs.first; nsock; nsock = nsock->next) { - if (nodeSocketIsHidden(nsock)) + if (nodeSocketIsHidden(nsock)) { continue; + } RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr); @@ -483,13 +513,15 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) nsock->locy = 0.5f * (dy + buty); dy = buty; - if (nsock->next) + if (nsock->next) { dy -= NODE_SOCKDY; + } } /* little bit space in end */ - if (node->inputs.first || (node->flag & (NODE_OPTIONS | NODE_PREVIEW)) == 0) + 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); @@ -519,12 +551,16 @@ static void node_update_hidden(bNode *node) 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)) + 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)) + } + } + for (nsock = node->outputs.first; nsock; nsock = nsock->next) { + if (!nodeSocketIsHidden(nsock)) { totout++; + } + } tot = MAX2(totin, totout); if (tot > 4) { @@ -571,10 +607,12 @@ static void node_update_hidden(bNode *node) void node_update_default(const bContext *C, bNodeTree *ntree, bNode *node) { - if (node->flag & NODE_HIDDEN) + if (node->flag & NODE_HIDDEN) { node_update_hidden(node); - else + } + else { node_update_basis(C, ntree, node); + } } int node_select_area_default(bNode *node, int x, int y) @@ -618,8 +656,9 @@ static void node_draw_mute_line(View2D *v2d, SpaceNode *snode, bNode *node) GPU_blend(true); - for (link = node->internal_links.first; link; link = link->next) + 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); } @@ -656,10 +695,12 @@ static void node_draw_preview_background(float tile, rctf *rect) for (x = rect->xmin; x < rect->xmax; x += tile * 2) { float tilex = tile, tiley = tile; - if (x + tile > rect->xmax) + if (x + tile > rect->xmax) { tilex = rect->xmax - x; - if (y + tile > rect->ymax) + } + if (y + tile > rect->ymax) { tiley = rect->ymax - y; + } immRectf(pos, x, y, x + tilex, y + tiley); } @@ -668,10 +709,12 @@ static void node_draw_preview_background(float tile, rctf *rect) for (x = rect->xmin + tile; x < rect->xmax; x += tile * 2) { float tilex = tile, tiley = tile; - if (x + tile > rect->xmax) + if (x + tile > rect->xmax) { tilex = rect->xmax - x; - if (y + tile > rect->ymax) + } + if (y + tile > rect->ymax) { tiley = rect->ymax - y; + } immRectf(pos, x, y, x + tilex, y + tiley); } @@ -740,8 +783,9 @@ 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) + if (node->parent == NULL) { ui_draw_dropshadow(rct, radius, snode->aspect, alpha, node->flag & SELECT); + } else { const float margin = 3.0f; @@ -790,8 +834,9 @@ void node_draw_sockets(View2D *v2d, const bContext *C, bNodeTree *ntree, bNode * short selected_input_len = 0; bNodeSocket *sock; for (sock = node->inputs.first; sock; sock = sock->next) { - if (nodeSocketIsHidden(sock)) + if (nodeSocketIsHidden(sock)) { continue; + } if (select_all || (sock->flag & SELECT)) { ++selected_input_len; continue; @@ -804,8 +849,9 @@ void node_draw_sockets(View2D *v2d, const bContext *C, bNodeTree *ntree, bNode * short selected_output_len = 0; if (draw_outputs) { for (sock = node->outputs.first; sock; sock = sock->next) { - if (nodeSocketIsHidden(sock)) + if (nodeSocketIsHidden(sock)) { continue; + } if (select_all || (sock->flag & SELECT)) { ++selected_output_len; continue; @@ -832,12 +878,14 @@ void node_draw_sockets(View2D *v2d, const bContext *C, bNodeTree *ntree, bNode * if (selected_input_len) { /* socket inputs */ for (sock = node->inputs.first; sock; sock = sock->next) { - if (nodeSocketIsHidden(sock)) + 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) + if (--selected_input_len == 0) { break; /* stop as soon as last one is drawn */ + } } } } @@ -845,12 +893,14 @@ void node_draw_sockets(View2D *v2d, const bContext *C, bNodeTree *ntree, bNode * if (selected_output_len) { /* socket outputs */ for (sock = node->outputs.first; sock; sock = sock->next) { - if (nodeSocketIsHidden(sock)) + 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) + if (--selected_output_len == 0) { break; /* stop as soon as last one is drawn */ + } } } } @@ -979,8 +1029,9 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN else if (node->flag & NODE_CUSTOM_COLOR) { rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], 1.0f); } - else + else { UI_GetThemeColor4fv(TH_NODE, color); + } 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); @@ -994,8 +1045,9 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN } /* disable lines */ - if (node->flag & NODE_MUTED) + if (node->flag & NODE_MUTED) { node_draw_mute_line(v2d, snode, node); + } node_draw_sockets(v2d, C, ntree, node, true, false); @@ -1033,10 +1085,12 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b node_draw_shadow(snode, node, hiddenrad, 1.0f); /* body */ - if (node->flag & NODE_MUTED) + if (node->flag & NODE_MUTED) { UI_GetThemeColorBlendShade4fv(color_id, TH_REDALERT, 0.5f, 0, color); - else + } + else { UI_GetThemeColor4fv(color_id, color); + } UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad, color); @@ -1084,8 +1138,9 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b } /* disable lines */ - if (node->flag & NODE_MUTED) + if (node->flag & NODE_MUTED) { node_draw_mute_line(&ar->v2d, snode, node); + } if (node->miniwidth > 0.0f) { nodeLabel(ntree, node, showname, sizeof(showname)); @@ -1137,14 +1192,18 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b int node_get_resize_cursor(int directions) { - if (directions == 0) + if (directions == 0) { return CURSOR_STD; - else if ((directions & ~(NODE_RESIZE_TOP | NODE_RESIZE_BOTTOM)) == 0) + } + else if ((directions & ~(NODE_RESIZE_TOP | NODE_RESIZE_BOTTOM)) == 0) { return CURSOR_Y_MOVE; - else if ((directions & ~(NODE_RESIZE_RIGHT | NODE_RESIZE_LEFT)) == 0) + } + else if ((directions & ~(NODE_RESIZE_RIGHT | NODE_RESIZE_LEFT)) == 0) { return CURSOR_X_MOVE; - else + } + else { return CURSOR_EDIT; + } } void node_set_cursor(wmWindow *win, SpaceNode *snode, float cursor[2]) @@ -1161,8 +1220,9 @@ void node_set_cursor(wmWindow *win, SpaceNode *snode, float cursor[2]) 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])) + 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]); @@ -1176,16 +1236,19 @@ void node_set_cursor(wmWindow *win, SpaceNode *snode, float cursor[2]) void node_draw_default(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey key) { - if (node->flag & NODE_HIDDEN) + if (node->flag & NODE_HIDDEN) { node_draw_hidden(C, ar, snode, ntree, node, key); - else + } + 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) + if (node->typeinfo->draw_nodetype_prepare) { node->typeinfo->draw_nodetype_prepare(C, ntree, node); + } } void node_update_nodetree(const bContext *C, bNodeTree *ntree) @@ -1203,8 +1266,9 @@ void node_update_nodetree(const bContext *C, bNodeTree *ntree) static void node_draw(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey key) { - if (node->typeinfo->draw_nodetype) + if (node->typeinfo->draw_nodetype) { node->typeinfo->draw_nodetype(C, ar, snode, ntree, node, key); + } } #define USE_DRAW_TOT_UPDATE @@ -1215,7 +1279,9 @@ void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeT bNodeLink *link; int a; - if (ntree == NULL) return; /* groups... */ + if (ntree == NULL) { + return; /* groups... */ + } #ifdef USE_DRAW_TOT_UPDATE if (ntree->nodes.first) { @@ -1233,8 +1299,9 @@ void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeT BLI_rctf_union(&ar->v2d.tot, &node->totr); #endif - if (!(node->flag & NODE_BACKGROUND)) + 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 */ @@ -1245,8 +1312,9 @@ void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeT GPU_blend(true); nodelink_batch_start(snode); for (link = ntree->links.first; link; link = link->next) { - if (!nodeLinkIsHidden(link)) + if (!nodeLinkIsHidden(link)) { node_draw_link(&ar->v2d, snode, link); + } } nodelink_batch_end(snode); GPU_blend(false); @@ -1254,8 +1322,9 @@ void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeT /* 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) + 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 */ @@ -1370,8 +1439,9 @@ void drawnodespace(const bContext *C, ARegion *ar) /* store new view center in path and current edittree */ copy_v2_v2(path->view_center, center); - if (snode->edittree) + if (snode->edittree) { copy_v2_v2(snode->edittree->view_center, center); + } depth = 0; while (path->prev && depth < max_depth) { @@ -1424,8 +1494,9 @@ void drawnodespace(const bContext *C, ARegion *ar) 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) + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { node_draw_link(v2d, snode, (bNodeLink *)linkdata->data); + } } GPU_line_smooth(false); GPU_blend(false); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index eb20f4e7175..0c7b3daf611 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -97,16 +97,19 @@ static void compo_tag_output_nodes(bNodeTree *nodetree, int recalc_flags) for (node = nodetree->nodes.first; node; node = node->next) { if (node->type == CMP_NODE_COMPOSITE) { - if (recalc_flags & COM_RECALC_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) + if (recalc_flags & COM_RECALC_VIEWER) { node->flag |= NODE_DO_OUTPUT_RECALC; + } } else if (node->type == NODE_GROUP) { - if (node->id) + if (node->id) { compo_tag_output_nodes((bNodeTree *)node->id, recalc_flags); + } } } } @@ -125,16 +128,19 @@ static int compo_get_recalc_flags(const bContext *C) if (sa->spacetype == SPACE_IMAGE) { SpaceImage *sima = sa->spacedata.first; if (sima->image) { - if (sima->image->type == IMA_TYPE_R_RESULT) + if (sima->image->type == IMA_TYPE_R_RESULT) { recalc_flags |= COM_RECALC_COMPOSITE; - else if (sima->image->type == IMA_TYPE_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) + if (snode->flag & SNODE_BACKDRAW) { recalc_flags |= COM_RECALC_VIEWER; + } } } } @@ -190,8 +196,9 @@ static void compo_initjob(void *cjv) cj->localtree = ntreeLocalize(cj->ntree); - if (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 */ @@ -215,8 +222,9 @@ static void compo_startjob(void *cjv, short *stop, short *do_update, float *prog Scene *scene = cj->scene; SceneRenderView *srv; - if (scene->use_nodes == false) + if (scene->use_nodes == false) { return; + } cj->stop = stop; cj->do_update = do_update; @@ -239,7 +247,9 @@ static void compo_startjob(void *cjv, short *stop, short *do_update, float *prog } else { for (srv = scene->r.views.first; srv; srv = srv->next) { - if (BKE_scene_multiview_is_render_view_active(&scene->r, srv) == false) continue; + 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); } } @@ -300,8 +310,9 @@ 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)) + if (ED_node_is_compositor(snode)) { return 1; + } } return 0; } @@ -311,8 +322,9 @@ 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)) + if (ED_node_is_compositor(snode)) { return 1; + } } return 0; } @@ -324,8 +336,9 @@ void snode_dag_update(bContext *C, SpaceNode *snode) /* for groups, update all ID's using this */ if (snode->edittree != snode->nodetree) { FOREACH_NODETREE_BEGIN(bmain, tntree, id) { - if (ntreeHasTree(tntree, snode->edittree)) + if (ntreeHasTree(tntree, snode->edittree)) { DEG_id_tag_update(id, 0); + } } FOREACH_NODETREE_END; } @@ -339,25 +352,32 @@ void snode_notify(bContext *C, SpaceNode *snode) WM_event_add_notifier(C, NC_NODE | NA_EDITED, NULL); if (ED_node_is_shader(snode)) { - if (GS(id->name) == ID_MA) + if (GS(id->name) == ID_MA) { WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id); - else if (GS(id->name) == ID_LA) + } + else if (GS(id->name) == ID_LA) { WM_main_add_notifier(NC_LAMP | ND_LIGHTING, id); - else if (GS(id->name) == ID_WO) + } + else if (GS(id->name) == ID_WO) { WM_main_add_notifier(NC_WORLD | ND_WORLD, id); + } } - else if (ED_node_is_compositor(snode)) + else if (ED_node_is_compositor(snode)) { WM_event_add_notifier(C, NC_SCENE | ND_NODES, id); - else if (ED_node_is_texture(snode)) + } + 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) + if (typeinfo) { BLI_strncpy(snode->tree_idname, typeinfo->idname, sizeof(snode->tree_idname)); - else + } + else { snode->tree_idname[0] = '\0'; + } } bool ED_node_is_compositor(struct SpaceNode *snode) @@ -421,10 +441,12 @@ void ED_node_shader_default(const bContext *C, ID *id) shader_type = SH_NODE_EMISSION; copy_v3_v3(color, &la->r); - if (la->type == LA_LOCAL || la->type == LA_SPOT || la->type == LA_AREA) + if (la->type == LA_LOCAL || la->type == LA_SPOT || la->type == LA_AREA) { strength = 100.0f; - else + } + else { strength = 1.0f; + } break; } default: @@ -469,8 +491,9 @@ void ED_node_composit_default(const bContext *C, struct Scene *sce) /* but lets check it anyway */ if (sce->nodetree) { - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("error in composite initialize\n"); + } return; } @@ -504,8 +527,9 @@ void ED_node_texture_default(const bContext *C, Tex *tx) /* but lets check it anyway */ if (tx->nodetree) { - if (G.debug & G_DEBUG) + if (G.debug & G_DEBUG) { printf("error in texture initialize\n"); + } return; } @@ -588,8 +612,9 @@ void snode_update(SpaceNode *snode, bNode *node) } } - if (node) + if (node) { nodeUpdate(snode->edittree, node); + } } void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node) @@ -605,49 +630,61 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node) /* 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) + 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) + 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)) + 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) + 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) + if (was_output == 0) { ED_node_tag_update_nodetree(bmain, ntree, node); + } } - else if (do_update) + 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)) + 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)) + 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); @@ -661,13 +698,16 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node) bNode *tnode; - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) - if (ELEM(tnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) + 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) + 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"); @@ -676,16 +716,19 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node) if (was_output == 0) { bNode *tnode; - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) - if (tnode->type == CMP_NODE_COMPOSITE) + 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) + else if (do_update) { ED_node_tag_update_nodetree(bmain, ntree, node); + } } else if (ntree->type == NTREE_TEXTURE) { // XXX @@ -780,8 +823,9 @@ static bNode *visible_node(SpaceNode *snode, const rctf *rct) bNode *node; for (node = snode->edittree->nodes.last; node; node = node->prev) { - if (BLI_rctf_isect(&node->totr, rct, NULL)) + if (BLI_rctf_isect(&node->totr, rct, NULL)) { break; + } } return node; } @@ -986,12 +1030,16 @@ int node_has_hidden_sockets(bNode *node) { bNodeSocket *sock; - for (sock = node->inputs.first; sock; sock = sock->next) - if (sock->flag & SOCK_HIDDEN) + 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) + } + } + for (sock = node->outputs.first; sock; sock = sock->next) { + if (sock->flag & SOCK_HIDDEN) { return 1; + } + } return 0; } @@ -1000,20 +1048,24 @@ 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) + for (sock = node->inputs.first; sock; sock = sock->next) { sock->flag &= ~SOCK_HIDDEN; - for (sock = node->outputs.first; sock; sock = sock->next) + } + 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) + if (sock->link == NULL) { sock->flag |= SOCK_HIDDEN; + } } for (sock = node->outputs.first; sock; sock = sock->next) { - if (nodeCountSocketLinks(snode->edittree, sock) == 0) + if (nodeCountSocketLinks(snode->edittree, sock) == 0) { sock->flag |= SOCK_HIDDEN; + } } } } @@ -1089,8 +1141,9 @@ static void node_duplicate_reparent_recursive(bNode *node) /* find first selected parent */ for (parent = node->parent; parent; parent = parent->parent) { if (parent->flag & SELECT) { - if (!(parent->flag & NODE_TEST)) + if (!(parent->flag & NODE_TEST)) { node_duplicate_reparent_recursive(parent); + } break; } } @@ -1123,8 +1176,9 @@ static int node_duplicate_exec(bContext *C, wmOperator *op) } /* make sure we don't copy new nodes again! */ - if (node == lastnode) + if (node == lastnode) { break; + } } /* copy links between selected nodes @@ -1156,21 +1210,25 @@ static int node_duplicate_exec(bContext *C, wmOperator *op) } /* make sure we don't copy new links again! */ - if (link == lastlink) + if (link == lastlink) { break; + } } /* clear flags for recursive depth-first iteration */ - for (node = ntree->nodes.first; node; node = node->next) + 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)) + if ((node->flag & SELECT) && !(node->flag & NODE_TEST)) { node_duplicate_reparent_recursive(node); + } /* only has to check old nodes */ - if (node == lastnode) + if (node == lastnode) { break; + } } /* deselect old nodes, select the copies instead */ @@ -1187,8 +1245,9 @@ static int node_duplicate_exec(bContext *C, wmOperator *op) } /* make sure we don't copy new nodes again! */ - if (node == lastnode) + if (node == lastnode) { break; + } } ntreeUpdateTree(CTX_data_main(C), snode->edittree); @@ -1232,10 +1291,12 @@ bool ED_node_select_check(ListBase *lb) void ED_node_select_all(ListBase *lb, int action) { if (action == SEL_TOGGLE) { - if (ED_node_select_check(lb)) + if (ED_node_select_check(lb)) { action = SEL_DESELECT; - else + } + else { action = SEL_SELECT; + } } for (bNode *node = lb->first; node; node = node->next) { @@ -1268,8 +1329,9 @@ static int node_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op)) ED_preview_kill_jobs(CTX_wm_manager(C), bmain); /* first tag scenes unread */ - for (scene = bmain->scenes.first; scene; scene = scene->id.next) + 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) { @@ -1365,29 +1427,37 @@ static void node_flag_toggle_exec(SpaceNode *snode, int toggle_flag) 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) + 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)) + } + if (toggle_flag == NODE_OPTIONS && !(node->typeinfo->draw_buttons || node->typeinfo->draw_buttons_ex)) { continue; + } - if (node->flag & toggle_flag) + if (node->flag & toggle_flag) { tot_eq++; - else + } + 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) + 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)) + } + if (toggle_flag == NODE_OPTIONS && !(node->typeinfo->draw_buttons || node->typeinfo->draw_buttons_ex)) { continue; + } - if ((tot_eq && tot_neq) || tot_eq == 0) + if ((tot_eq && tot_neq) || tot_eq == 0) { node->flag |= toggle_flag; - else + } + else { node->flag &= ~toggle_flag; + } } } } @@ -1397,8 +1467,9 @@ static int node_hide_toggle_exec(bContext *C, wmOperator *UNUSED(op)) SpaceNode *snode = CTX_wm_space_node(C); /* sanity checking (poll callback checks this already) */ - if ((snode == NULL) || (snode->edittree == NULL)) + if ((snode == NULL) || (snode->edittree == NULL)) { return OPERATOR_CANCELLED; + } node_flag_toggle_exec(snode, NODE_HIDDEN); @@ -1427,8 +1498,9 @@ static int node_preview_toggle_exec(bContext *C, wmOperator *UNUSED(op)) SpaceNode *snode = CTX_wm_space_node(C); /* sanity checking (poll callback checks this already) */ - if ((snode == NULL) || (snode->edittree == NULL)) + if ((snode == NULL) || (snode->edittree == NULL)) { return OPERATOR_CANCELLED; + } ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); @@ -1459,8 +1531,9 @@ static int node_options_toggle_exec(bContext *C, wmOperator *UNUSED(op)) SpaceNode *snode = CTX_wm_space_node(C); /* sanity checking (poll callback checks this already) */ - if ((snode == NULL) || (snode->edittree == NULL)) + if ((snode == NULL) || (snode->edittree == NULL)) { return OPERATOR_CANCELLED; + } node_flag_toggle_exec(snode, NODE_OPTIONS); @@ -1491,8 +1564,9 @@ static int node_socket_toggle_exec(bContext *C, wmOperator *UNUSED(op)) int hidden; /* sanity checking (poll callback checks this already) */ - if ((snode == NULL) || (snode->edittree == NULL)) + if ((snode == NULL) || (snode->edittree == NULL)) { return OPERATOR_CANCELLED; + } ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); @@ -1628,8 +1702,9 @@ static bool node_switch_view_poll(bContext *C) { SpaceNode *snode = CTX_wm_space_node(C); - if (snode && snode->edittree) + if (snode && snode->edittree) { return true; + } return false; } @@ -1731,8 +1806,9 @@ static int node_output_file_add_socket_exec(bContext *C, wmOperator *op) node = nodeGetActive(snode->edittree); } - if (!node || node->type != CMP_NODE_OUTPUT_FILE) + 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); @@ -1777,11 +1853,13 @@ static int node_output_file_remove_active_socket_exec(bContext *C, wmOperator *U node = nodeGetActive(snode->edittree); } - if (!node || node->type != CMP_NODE_OUTPUT_FILE) + if (!node || node->type != CMP_NODE_OUTPUT_FILE) { return OPERATOR_CANCELLED; + } - if (!ntreeCompositOutputFileRemoveActiveSocket(ntree, node)) + if (!ntreeCompositOutputFileRemoveActiveSocket(ntree, node)) { return OPERATOR_CANCELLED; + } snode_notify(C, snode); @@ -1814,34 +1892,40 @@ static int node_output_file_move_active_socket_exec(bContext *C, wmOperator *op) bNodeSocket *sock; int direction; - if (ptr.data) + if (ptr.data) { node = ptr.data; - else if (snode && snode->edittree) + } + else if (snode && snode->edittree) { node = nodeGetActive(snode->edittree); + } - if (!node || node->type != CMP_NODE_OUTPUT_FILE) + if (!node || node->type != CMP_NODE_OUTPUT_FILE) { return OPERATOR_CANCELLED; + } nimf = node->storage; sock = BLI_findlink(&node->inputs, nimf->active_input); - if (!sock) + if (!sock) { return OPERATOR_CANCELLED; + } direction = RNA_enum_get(op->ptr, "direction"); if (direction == 1) { bNodeSocket *before = sock->prev; - if (!before) + 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) + if (!after) { return OPERATOR_CANCELLED; + } BLI_remlink(&node->inputs, sock); BLI_insertlinkafter(&node->inputs, after, sock); nimf->active_input++; @@ -1883,11 +1967,13 @@ static int node_copy_color_exec(bContext *C, wmOperator *UNUSED(op)) bNodeTree *ntree = snode->edittree; bNode *node, *tnode; - if (!ntree) + if (!ntree) { return OPERATOR_CANCELLED; + } node = nodeGetActive(ntree); - if (!node) + if (!node) { return OPERATOR_CANCELLED; + } for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { if (tnode->flag & NODE_SELECT && tnode != node) { @@ -1895,8 +1981,9 @@ static int node_copy_color_exec(bContext *C, wmOperator *UNUSED(op)) tnode->flag |= NODE_CUSTOM_COLOR; copy_v3_v3(tnode->color, node->color); } - else + else { tnode->flag &= ~NODE_CUSTOM_COLOR; + } } } @@ -2041,8 +2128,9 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op) BKE_reportf(op->reports, RPT_ERROR, "Cannot add node %s into node tree %s", node->name, ntree->id.name + 2); } } - if (!all_nodes_valid) + if (!all_nodes_valid) { return OPERATOR_CANCELLED; + } ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); @@ -2068,8 +2156,9 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op) /* reparent copied nodes */ for (node = clipboard_nodes_lb->first; node; node = node->next) { bNode *new_node = node->new_node; - if (new_node->parent) + if (new_node->parent) { new_node->parent = new_node->parent->new_node; + } } for (link = clipboard_links_lb->first; link; link = link->next) { @@ -2105,9 +2194,11 @@ void NODE_OT_clipboard_paste(wmOperatorType *ot) static bNodeSocket *ntree_get_active_interface_socket(ListBase *lb) { bNodeSocket *sock; - for (sock = lb->first; sock; sock = sock->next) - if (sock->flag & SELECT) + for (sock = lb->first; sock; sock = sock->next) { + if (sock->flag & SELECT) { return sock; + } + } return NULL; } @@ -2143,10 +2234,12 @@ static int ntree_socket_add_exec(bContext *C, wmOperator *op) } /* deactivate sockets (has to check both lists) */ - for (tsock = ntree->inputs.first; tsock; tsock = tsock->next) + for (tsock = ntree->inputs.first; tsock; tsock = tsock->next) { tsock->flag &= ~SELECT; - for (tsock = ntree->outputs.first; tsock; tsock = tsock->next) + } + for (tsock = ntree->outputs.first; tsock; tsock = tsock->next) { tsock->flag &= ~SELECT; + } /* make the new socket active */ sock->flag |= SELECT; @@ -2183,18 +2276,21 @@ static int ntree_socket_remove_exec(bContext *C, wmOperator *UNUSED(op)) bNodeSocket *iosock, *active_sock; iosock = ntree_get_active_interface_socket(&ntree->inputs); - if (!iosock) + if (!iosock) { iosock = ntree_get_active_interface_socket(&ntree->outputs); - if (!iosock) + } + 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); /* set active socket */ - if (active_sock) + if (active_sock) { active_sock->flag |= SELECT; + } ntreeUpdateTree(CTX_data_main(C), ntree); @@ -2240,28 +2336,33 @@ static int ntree_socket_move_exec(bContext *C, wmOperator *op) lb = &ntree->outputs; iosock = ntree_get_active_interface_socket(lb); } - if (!iosock) + if (!iosock) { return OPERATOR_CANCELLED; + } switch (direction) { case 1: { /* up */ bNodeSocket *before = iosock->prev; BLI_remlink(lb, iosock); - if (before) + if (before) { BLI_insertlinkbefore(lb, before, iosock); - else + } + else { BLI_addhead(lb, iosock); + } break; } case 2: { /* down */ bNodeSocket *after = iosock->next; BLI_remlink(lb, iosock); - if (after) + if (after) { BLI_insertlinkafter(lb, after, iosock); - else + } + else { BLI_addtail(lb, iosock); + } break; } } @@ -2301,14 +2402,16 @@ static bool node_shader_script_update_poll(bContext *C) Text *text; /* test if we have a render engine that supports shaders scripts */ - if (!(type && type->update_script_node)) + 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; - if (!node && snode && snode->edittree) + if (!node && snode && snode->edittree) { node = nodeGetActive(snode->edittree); + } if (node && node->type == SH_NODE_SCRIPT) { NodeShaderScript *nss = node->storage; @@ -2320,8 +2423,9 @@ static bool node_shader_script_update_poll(bContext *C) /* see if we have a text datablock in context */ text = CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data; - if (text) + if (text) { return 1; + } /* we don't check if text datablock is actually in use, too slow for poll */ @@ -2340,8 +2444,9 @@ static bool node_shader_script_update_text_recursive(RenderEngine *engine, Rende for (node = ntree->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP) { bNodeTree *ngroup = (bNodeTree *)node->id; - if (ngroup && !ngroup->done) + 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); @@ -2392,19 +2497,22 @@ static int node_shader_script_update_exec(bContext *C, wmOperator *op) if (text) { /* clear flags for recursion check */ FOREACH_NODETREE_BEGIN(bmain, ntree, id) { - if (ntree->type == NTREE_SHADER) + 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) + if (!ntree->done) { found |= node_shader_script_update_text_recursive(engine, type, ntree, text); + } } } FOREACH_NODETREE_END; - if (!found) + if (!found) { BKE_report(op->reports, RPT_INFO, "Text not used by any node, no update done"); + } } } diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c index 808d9375d22..3de389dca7c 100644 --- a/source/blender/editors/space_node/node_group.c +++ b/source/blender/editors/space_node/node_group.c @@ -106,12 +106,15 @@ static const char *group_node_idname(bContext *C) { SpaceNode *snode = CTX_wm_space_node(C); - if (ED_node_is_shader(snode)) + if (ED_node_is_shader(snode)) { return "ShaderNodeGroup"; - else if (ED_node_is_compositor(snode)) + } + else if (ED_node_is_compositor(snode)) { return "CompositorNodeGroup"; - else if (ED_node_is_texture(snode)) + } + else if (ED_node_is_texture(snode)) { return "TextureNodeGroup"; + } return ""; } @@ -121,10 +124,12 @@ 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)) + if (node && STREQ(node->idname, node_idname)) { return node; - else + } + else { return NULL; + } } /* ***************** Edit Group operator ************* */ @@ -143,11 +148,13 @@ static int node_group_edit_exec(bContext *C, wmOperator *op) if (gnode && !exit) { bNodeTree *ngroup = (bNodeTree *)gnode->id; - if (ngroup) + if (ngroup) { ED_node_tree_push(snode, ngroup, gnode); + } } - else + else { ED_node_tree_pop(snode); + } WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL); @@ -185,8 +192,9 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) ngroup = (bNodeTree *)gnode->id; /* clear new pointers, set in copytree */ - for (node = ntree->nodes.first; node; node = node->next) + 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 @@ -217,8 +225,9 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) RNA_pointer_create(&wgroup->id, &RNA_Node, node, &ptr); path = RNA_path_from_ID_to_struct(&ptr); - if (path) + if (path) { BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } } /* migrate node */ @@ -359,8 +368,9 @@ static int node_group_ungroup_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(CTX_wm_manager(C), bmain); gnode = node_group_get_active(C, node_idname); - if (!gnode) + if (!gnode) { return OPERATOR_CANCELLED; + } if (gnode->id && node_group_ungroup(bmain, snode->edittree, gnode)) { ntreeUpdateTree(bmain, snode->nodetree); @@ -402,18 +412,21 @@ static int node_group_separate_selected( ListBase anim_basepaths = {NULL, NULL}; /* deselect all nodes in the target tree */ - for (node = ntree->nodes.first; node; node = node->next) + 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) + 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)) + if (!(node->flag & NODE_SELECT)) { continue; + } /* ignore interface nodes */ if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) { @@ -440,13 +453,15 @@ static int node_group_separate_selected( RNA_pointer_create(&ngroup->id, &RNA_Node, newnode, &ptr); path = RNA_path_from_ID_to_struct(&ptr); - if (path) + 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)) + if (newnode->parent && !(newnode->parent->flag & NODE_SELECT)) { nodeDetachNode(newnode); + } /* migrate node */ BLI_remlink(&ngroup->nodes, newnode); @@ -469,8 +484,9 @@ static int node_group_separate_selected( if (make_copy) { /* make a copy of internal links */ - if (fromselect && toselect) + 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 */ @@ -502,8 +518,9 @@ static int node_group_separate_selected( } ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - if (!make_copy) + if (!make_copy) { ngroup->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + } return 1; } @@ -633,16 +650,19 @@ static bool node_group_make_test_selected(bNodeTree *ntree, bNode *gnode, const /* free local pseudo node tree again */ ntreeFreeTree(ngroup); MEM_freeN(ngroup); - if (!ok) + 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)) + if (node_group_make_use_node(link->fromnode, gnode)) { link->tonode->done |= 1; - if (node_group_make_use_node(link->tonode, gnode)) + } + 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) && @@ -696,16 +716,18 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, static const float offsety = 0.0f; /* deselect all nodes in the target tree */ - for (node = ngroup->nodes.first; node; node = node->next) + 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) + if (totselect == 1) { expose_all = true; + } /* move nodes over */ for (node = ntree->nodes.first; node; node = nextn) { @@ -721,13 +743,15 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); path = RNA_path_from_ID_to_struct(&ptr); - if (path) + 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)) + if (node->parent && !(node->parent->flag & NODE_SELECT)) { nodeDetachNode(node); + } /* change node-collection membership */ BLI_remlink(&ntree->nodes, node); @@ -857,8 +881,9 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, break; } } - if (skip) + if (skip) { continue; + } iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock); @@ -872,11 +897,14 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, 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) + for (link = ngroup->links.first; link; link = link->next) { + if (link->fromsock == sock) { skip = true; - if (skip) + } + } + if (skip) { continue; + } iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock); @@ -906,8 +934,9 @@ static bNode *node_group_make_from_selected(const bContext *C, bNodeTree *ntree, totselect = node_get_selected_minmax(ntree, NULL, min, max); /* don't make empty group */ - if (totselect == 0) + if (totselect == 0) { return NULL; + } /* new nodetree */ ngroup = ntreeAddTree(bmain, "NodeGroup", ntreetype); @@ -939,8 +968,9 @@ static int node_group_make_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - if (!node_group_make_test_selected(ntree, NULL, ntree_idname, op->reports)) + 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); @@ -995,12 +1025,14 @@ static int node_group_insert_exec(bContext *C, wmOperator *op) gnode = node_group_get_active(C, node_idname); - if (!gnode || !gnode->id) + if (!gnode || !gnode->id) { return OPERATOR_CANCELLED; + } ngroup = (bNodeTree *)gnode->id; - if (!node_group_make_test_selected(ntree, gnode, ngroup->idname, op->reports)) + if (!node_group_make_test_selected(ntree, gnode, ngroup->idname, op->reports)) { return OPERATOR_CANCELLED; + } node_group_make_insert_selected(C, ntree, gnode); diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index 1aaf0baae6d..55a3da6f77c 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -200,19 +200,23 @@ static int sort_nodes_locx(const void *a, const void *b) const bNode *node1 = nli1->node; const bNode *node2 = nli2->node; - if (node1->locx > node2->locx) + if (node1->locx > node2->locx) { return 1; - else + } + else { return 0; + } } static bool socket_is_available(bNodeTree *UNUSED(ntree), bNodeSocket *sock, const bool allow_used) { - if (nodeSocketIsHidden(sock)) + if (nodeSocketIsHidden(sock)) { return 0; + } - if (!allow_used && (sock->flag & SOCK_IN_USE)) + if (!allow_used && (sock->flag & SOCK_IN_USE)) { return 0; + } return 1; } @@ -223,30 +227,35 @@ static bNodeSocket *best_socket_output(bNodeTree *ntree, bNode *node, bNodeSocke /* first look for selected output */ for (sock = node->outputs.first; sock; sock = sock->next) { - if (!socket_is_available(ntree, sock, allow_multiple)) + if (!socket_is_available(ntree, sock, allow_multiple)) { continue; + } - if (sock->flag & SELECT) + 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)) + 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)) + 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)) + if (!socket_is_available(ntree, sock, allow_multiple)) { continue; + } /* check for same types */ if (sock->type == sock_target->type) { @@ -282,8 +291,9 @@ static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, in /* increment to make sure we don't keep finding * the same socket on every attempt running this function */ a++; - if (a > num) + if (a > num) { return sock; + } } } } @@ -296,8 +306,9 @@ static bool snode_autoconnect_input(SpaceNode *snode, bNode *node_fr, bNodeSocke bNodeTree *ntree = snode->edittree; /* then we can connect */ - if (replace) + if (replace) { nodeRemSocketLinks(ntree, sock_to); + } nodeAddLink(ntree, node_fr, sock_fr, node_to, sock_to); return true; @@ -327,7 +338,9 @@ static void snode_autoconnect(Main *bmain, SpaceNode *snode, const bool allow_mu bNodeSocket *sock_fr, *sock_to; bool has_selected_inputs = false; - if (nli->next == NULL) break; + if (nli->next == NULL) { + break; + } node_fr = nli->node; node_to = nli->next->node; @@ -341,13 +354,15 @@ static void snode_autoconnect(Main *bmain, SpaceNode *snode, const bool allow_mu if (sock_to->flag & SELECT) { has_selected_inputs = 1; - if (!socket_is_available(ntree, sock_to, replace)) + 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) + if (!sock_fr) { continue; + } if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) { numlinks++; @@ -363,13 +378,15 @@ static void snode_autoconnect(Main *bmain, SpaceNode *snode, const bool allow_mu /* find the best guess input socket */ sock_to = best_socket_input(ntree, node_to, i, replace); - if (!sock_to) + 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) + if (!sock_fr) { continue; + } if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) { numlinks++; @@ -397,16 +414,21 @@ static int node_link_viewer(const bContext *C, bNode *tonode) bNodeSocket *sock; /* context check */ - if (tonode == NULL || BLI_listbase_is_empty(&tonode->outputs)) + if (tonode == NULL || BLI_listbase_is_empty(&tonode->outputs)) { return OPERATOR_CANCELLED; - if (ELEM(tonode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) + } + 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) + 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) { @@ -422,19 +444,24 @@ static int node_link_viewer(const bContext *C, bNode *tonode) /* 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) + 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)) + for (sock = sock->next; sock; sock = sock->next) { + if (!nodeSocketIsHidden(sock)) { break; + } + } } } @@ -451,9 +478,11 @@ static int node_link_viewer(const bContext *C, bNode *tonode) /* find a socket starting from the first socket */ if (!sock) { - for (sock = tonode->outputs.first; sock; sock = sock->next) - if (!nodeSocketIsHidden(sock)) + for (sock = tonode->outputs.first; sock; sock = sock->next) { + if (!nodeSocketIsHidden(sock)) { break; + } + } } if (sock) { @@ -461,16 +490,19 @@ static int node_link_viewer(const bContext *C, bNode *tonode) 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) + 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) + for (link = snode->edittree->links.first; link; link = link->next) { + if (link->tonode == node && link->tosock == node->inputs.first) { break; + } + } } if (link == NULL) { @@ -497,13 +529,15 @@ static int node_active_link_viewer_exec(bContext *C, wmOperator *UNUSED(op)) node = nodeGetActive(snode->edittree); - if (!node) + if (!node) { return OPERATOR_CANCELLED; + } ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - if (node_link_viewer(C, node) == OPERATOR_CANCELLED) + if (node_link_viewer(C, node) == OPERATOR_CANCELLED) { return OPERATOR_CANCELLED; + } snode_notify(C, snode); @@ -542,10 +576,12 @@ 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) + if (link->fromsock == sock) { ++count; - if (link->tosock == sock) + } + if (link->tosock == sock) { ++count; + } } return count; } @@ -560,8 +596,9 @@ static void node_remove_extra_links(SpaceNode *snode, bNodeLink *link) for (tlink = ntree->links.first; tlink; tlink = tlink_next) { tlink_next = tlink->next; - if (tlink == link) + if (tlink == link) { continue; + } if (tlink && tlink->fromsock == from) { if (from_count > from->limit) { @@ -605,10 +642,12 @@ static void node_link_exit(bContext *C, wmOperator *op, bool apply_links) /* before actually adding the link, * let nodes perform special link insertion handling */ - if (link->fromnode->typeinfo->insert_link) + if (link->fromnode->typeinfo->insert_link) { link->fromnode->typeinfo->insert_link(ntree, link->fromnode, link); - if (link->tonode->typeinfo->insert_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); @@ -657,11 +696,13 @@ static void node_link_find_socket(bContext *C, wmOperator *op, float cursor[2]) bNodeLink *link = linkdata->data; /* skip if this is already the target socket */ - if (link->tosock == tsock) + if (link->tosock == tsock) { continue; + } /* skip if socket is on the same node as the fromsock */ - if (tnode && link->fromnode == tnode) + if (tnode && link->fromnode == tnode) { continue; + } /* attach links to the socket */ link->tonode = tnode; @@ -683,11 +724,13 @@ static void node_link_find_socket(bContext *C, wmOperator *op, float cursor[2]) bNodeLink *link = linkdata->data; /* skip if this is already the target socket */ - if (link->fromsock == tsock) + if (link->fromsock == tsock) { continue; + } /* skip if socket is on the same node as the fromsock */ - if (tnode && link->tonode == tnode) + if (tnode && link->tonode == tnode) { continue; + } /* attach links to the socket */ link->fromnode = tnode; @@ -829,8 +872,9 @@ static bNodeLinkDrag *node_link_init(Main *bmain, SpaceNode *snode, float cursor nodeRemLink(snode->edittree, link); /* send changed event to original link->tonode */ - if (node) + if (node) { snode_update(snode, node); + } } } } @@ -881,8 +925,9 @@ static int node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_RUNNING_MODAL; } - else + else { return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + } } static void node_link_cancel(bContext *C, wmOperator *op) @@ -965,10 +1010,13 @@ static bool cut_links_intersect(bNodeLink *link, float mcoords[][2], int tot) 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) + 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; } @@ -990,7 +1038,9 @@ static int cut_links_exec(bContext *C, wmOperator *op) UI_view2d_region_to_view(&ar->v2d, (int)loc[0], (int)loc[1], &mcoords[i][0], &mcoords[i][1]); i++; - if (i >= 256) break; + if (i >= 256) { + break; + } } RNA_END; @@ -1002,8 +1052,9 @@ static int cut_links_exec(bContext *C, wmOperator *op) for (link = snode->edittree->links.first; link; link = next) { next = link->next; - if (nodeLinkIsHidden(link)) + if (nodeLinkIsHidden(link)) { continue; + } if (cut_links_intersect(link, mcoords, i)) { @@ -1108,12 +1159,14 @@ 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) + if (!frame || frame->type != NODE_FRAME) { return OPERATOR_CANCELLED; + } for (node = ntree->nodes.first; node; node = node->next) { - if (node == frame) + if (node == frame) { continue; + } if (node->flag & NODE_SELECT) { nodeDetachNode(node); nodeAttachNode(node, frame); @@ -1156,12 +1209,14 @@ static void node_join_attach_recursive(bNode *node, bNode *frame) } else if (node->parent) { /* call recursively */ - if (!(node->parent->done & NODE_JOIN_DONE)) + 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) + 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); @@ -1184,27 +1239,32 @@ static int node_join_exec(bContext *C, wmOperator *UNUSED(op)) /* 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) + if (node->flag & NODE_SELECT) { node->flag |= NODE_TEST; - else + } + 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) + 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)) + 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) + if (node->flag & NODE_TEST) { node->flag |= NODE_SELECT; + } } ED_node_sort(ntree); @@ -1241,10 +1301,12 @@ static bNode *node_find_frame_to_attach(ARegion *ar, const bNodeTree *ntree, con /* 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)) + if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT)) { continue; - if (BLI_rctf_isect_pt_v(&frame->totr, cursor)) + } + if (BLI_rctf_isect_pt_v(&frame->totr, cursor)) { return frame; + } } return NULL; @@ -1323,12 +1385,14 @@ static void node_detach_recursive(bNode *node) if (node->parent) { /* call recursively */ - if (!(node->parent->done & NODE_DETACH_DONE)) + 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) + 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); @@ -1349,14 +1413,16 @@ static int node_detach_exec(bContext *C, wmOperator *UNUSED(op)) bNode *node; /* reset tags */ - for (node = ntree->nodes.first; node; node = node->next) + 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)) + if (!(node->done & NODE_DETACH_DONE)) { node_detach_recursive(node); + } } ED_node_sort(ntree); @@ -1394,8 +1460,9 @@ static bool ed_node_link_conditions(ScrArea *sa, bool test, SpaceNode **r_snode, *r_select = NULL; /* no unlucky accidents */ - if (sa == NULL || sa->spacetype != SPACE_NODE) + if (sa == NULL || sa->spacetype != SPACE_NODE) { return false; + } if (!test) { /* no need to look for a node */ @@ -1404,27 +1471,33 @@ static bool ed_node_link_conditions(ScrArea *sa, bool test, SpaceNode **r_snode, for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & SELECT) { - if (select) + if (select) { break; - else + } + else { select = node; + } } } /* only one selected */ - if (node || select == NULL) + if (node || select == NULL) { return false; + } /* correct node */ - if (BLI_listbase_is_empty(&select->inputs) || BLI_listbase_is_empty(&select->outputs)) + 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)) + if (nodeLinkIsHidden(link)) { continue; + } - if (link->tonode == select || link->fromnode == select) + if (link->tonode == select || link->fromnode == select) { return false; + } } *r_select = select; @@ -1439,20 +1512,26 @@ void ED_node_link_intersect_test(ScrArea *sa, int test) bNodeLink *link, *selink = NULL; float dist_best = FLT_MAX; - if (!ed_node_link_conditions(sa, test, &snode, &select)) return; + if (!ed_node_link_conditions(sa, test, &snode, &select)) { + return; + } /* clear flags */ - for (link = snode->edittree->links.first; link; link = link->next) + for (link = snode->edittree->links.first; link; link = link->next) { link->flag &= ~NODE_LINKFLAG_HILITE; + } - if (test == 0) return; + 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)) + if (nodeLinkIsHidden(link)) { continue; + } if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { float dist = FLT_MAX; @@ -1482,8 +1561,9 @@ void ED_node_link_intersect_test(ScrArea *sa, int test) } } - if (selink) + if (selink) { selink->flag |= NODE_LINKFLAG_HILITE; + } } /* assumes sockets in list */ @@ -1493,8 +1573,9 @@ static bNodeSocket *socket_best_match(ListBase *sockets) int type, maxtype = 0; /* find type range */ - for (sock = sockets->first; sock; sock = sock->next) + 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) { @@ -1670,8 +1751,9 @@ static void node_link_insert_offset_ntree( /* 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)) + 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); @@ -1757,8 +1839,9 @@ static int node_insert_offset_modal(bContext *C, wmOperator *UNUSED(op), const w float duration; bool redraw = false; - if (!snode || event->type != TIMER || iofsd == NULL || iofsd->anim_timer != event->customdata) + if (!snode || event->type != TIMER || iofsd == NULL || iofsd->anim_timer != event->customdata) { return OPERATOR_PASS_THROUGH; + } duration = (float)iofsd->anim_timer->duration; @@ -1808,8 +1891,9 @@ static int node_insert_offset_invoke(bContext *C, wmOperator *op, const wmEvent const SpaceNode *snode = CTX_wm_space_node(C); NodeInsertOfsData *iofsd = snode->iofsd; - if (!iofsd || !iofsd->insert) + if (!iofsd || !iofsd->insert) { return OPERATOR_CANCELLED; + } BLI_assert((snode->flag & SNODE_SKIP_INSOFFSET) == 0); @@ -1850,12 +1934,16 @@ void ED_node_link_insert(Main *bmain, ScrArea *sa) bNodeLink *link; bNodeSocket *sockto; - if (!ed_node_link_conditions(sa, true, &snode, &select)) return; + 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) + 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); diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index a329958db5e..a027481ff27 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -64,8 +64,9 @@ static bNode *node_under_mouse_select(bNodeTree *ntree, int mx, int my) for (node = ntree->nodes.last; node; node = node->prev) { if (node->typeinfo->select_area_func) { - if (node->typeinfo->select_area_func(node, mx, my)) + if (node->typeinfo->select_area_func(node, mx, my)) { return node; + } } } return NULL; @@ -77,8 +78,9 @@ static bNode *node_under_mouse_tweak(bNodeTree *ntree, int mx, int my) for (node = ntree->nodes.last; node; node = node->prev) { if (node->typeinfo->tweak_area_func) { - if (node->typeinfo->tweak_area_func(node, mx, my)) + if (node->typeinfo->tweak_area_func(node, mx, my)) { return node; + } } } return NULL; @@ -118,8 +120,9 @@ void node_socket_select(bNode *node, bNodeSocket *sock) sock->flag |= SELECT; /* select node too */ - if (node) + if (node) { node->flag |= SELECT; + } } void node_socket_deselect(bNode *node, bNodeSocket *sock, const bool deselect_node) @@ -143,17 +146,20 @@ void node_socket_deselect(bNode *node, bNodeSocket *sock, const bool deselect_no } } - if (!sel) + if (!sel) { node->flag &= ~SELECT; + } } } static void node_socket_toggle(bNode *node, bNodeSocket *sock, int deselect_node) { - if (sock->flag & SELECT) + if (sock->flag & SELECT) { node_socket_deselect(node, sock, deselect_node); - else + } + else { node_socket_select(node, sock); + } } /* no undo here! */ @@ -161,8 +167,9 @@ void node_deselect_all(SpaceNode *snode) { bNode *node; - for (node = snode->edittree->nodes.first; node; node = node->next) + 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) @@ -178,8 +185,9 @@ void node_deselect_all_input_sockets(SpaceNode *snode, const bool deselect_nodes for (node = snode->edittree->nodes.first; node; node = node->next) { int sel = 0; - for (sock = node->inputs.first; sock; sock = sock->next) + for (sock = node->inputs.first; sock; sock = sock->next) { sock->flag &= ~SELECT; + } /* if no selected sockets remain, also deselect the node */ if (deselect_nodes) { @@ -190,8 +198,9 @@ void node_deselect_all_input_sockets(SpaceNode *snode, const bool deselect_nodes } } - if (!sel) + if (!sel) { node->flag &= ~SELECT; + } } } } @@ -209,8 +218,9 @@ void node_deselect_all_output_sockets(SpaceNode *snode, const bool deselect_node for (node = snode->edittree->nodes.first; node; node = node->next) { bool sel = false; - for (sock = node->outputs.first; sock; sock = sock->next) + for (sock = node->outputs.first; sock; sock = sock->next) { sock->flag &= ~SELECT; + } /* if no selected sockets remain, also deselect the node */ if (deselect_nodes) { @@ -221,8 +231,9 @@ void node_deselect_all_output_sockets(SpaceNode *snode, const bool deselect_node } } - if (!sel) + if (!sel) { node->flag &= ~SELECT; + } } } } @@ -397,9 +408,11 @@ void node_select_single(bContext *C, bNode *node) SpaceNode *snode = CTX_wm_space_node(C); bNode *tnode; - for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) - if (tnode != node) + 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); @@ -440,8 +453,9 @@ static int node_mouse_select(Main *bmain, SpaceNode *snode, ARegion *ar, const i /* 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) + 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. @@ -857,19 +871,23 @@ static int node_select_linked_to_exec(bContext *C, wmOperator *UNUSED(op)) bNodeLink *link; bNode *node; - for (node = snode->edittree->nodes.first; node; node = node->next) + 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)) + if (nodeLinkIsHidden(link)) { continue; - if (link->fromnode && link->tonode && (link->fromnode->flag & NODE_SELECT)) + } + 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) + if (node->flag & NODE_TEST) { nodeSetSelected(node, true); + } } ED_node_sort(snode->edittree); @@ -905,19 +923,23 @@ static int node_select_linked_from_exec(bContext *C, wmOperator *UNUSED(op)) bNodeLink *link; bNode *node; - for (node = snode->edittree->nodes.first; node; node = node->next) + 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)) + if (nodeLinkIsHidden(link)) { continue; - if (link->fromnode && link->tonode && (link->tonode->flag & NODE_SELECT)) + } + 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) + if (node->flag & NODE_TEST) { nodeSetSelected(node, true); + } } ED_node_sort(snode->edittree); @@ -963,41 +985,55 @@ static int node_select_same_type_step_exec(bContext *C, wmOperator *op) int a; for (a = 0; a < totnodes; a++) { - if (node_array[a] == active) + if (node_array[a] == active) { break; + } } if (same_type) { bNode *node = NULL; while (node == NULL) { - if (revert) a--; - else a++; + if (revert) { + a--; + } + else { + a++; + } - if (a < 0 || a >= totnodes) + if (a < 0 || a >= totnodes) { break; + } node = node_array[a]; - if (node->type == active->type) + if (node->type == active->type) { break; - else node = NULL; + } + else { + node = NULL; + } } - if (node) + if (node) { active = node; + } } else { if (revert) { - if (a == 0) + if (a == 0) { active = node_array[totnodes - 1]; - else + } + else { active = node_array[a - 1]; + } } else { - if (a == totnodes - 1) + if (a == totnodes - 1) { active = node_array[0]; - else + } + else { active = node_array[a + 1]; + } } } @@ -1012,8 +1048,9 @@ static int node_select_same_type_step_exec(bContext *C, wmOperator *op) } } - if (node_array) + if (node_array) { MEM_freeN(node_array); + } return OPERATOR_FINISHED; } @@ -1053,12 +1090,15 @@ static void node_find_cb(const struct bContext *C, void *UNUSED(arg), const char if (BLI_strcasestr(node->name, str) || BLI_strcasestr(node->label, str)) { char name[256]; - if (node->label[0]) + if (node->label[0]) { BLI_snprintf(name, 256, "%s (%s)", node->name, node->label); - else + } + else { BLI_strncpy(name, node->name, 256); - if (false == UI_search_item_add(items, name, node, 0)) + } + if (false == UI_search_item_add(items, name, node, 0)) { break; + } } } } diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index 10cb3ba8d99..aa6fb770c56 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -71,8 +71,9 @@ 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 + else { return true; + } } static void node_link_item_apply(Main *bmain, bNode *node, NodeLinkItem *item) @@ -85,36 +86,43 @@ static void node_link_item_apply(Main *bmain, bNode *node, NodeLinkItem *item) /* nothing to do for now */ } - if (node->id) + if (node->id) { id_us_plus(node->id); + } } static void node_tag_recursive(bNode *node) { bNodeSocket *input; - if (!node || (node->flag & NODE_TEST)) + if (!node || (node->flag & NODE_TEST)) { return; /* in case of cycles */ + } node->flag |= NODE_TEST; - for (input = node->inputs.first; input; input = input->next) - if (input->link) + 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; - if (!node || !(node->flag & NODE_TEST)) + if (!node || !(node->flag & NODE_TEST)) { return; /* in case of cycles */ + } node->flag &= ~NODE_TEST; - for (input = node->inputs.first; input; input = input->next) - if (input->link) + 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) @@ -122,21 +130,27 @@ static void node_remove_linked(Main *bmain, bNodeTree *ntree, bNode *rem_node) bNode *node, *next; bNodeSocket *sock; - if (!rem_node) + if (!rem_node) { return; + } /* tag linked nodes to be removed */ - for (node = ntree->nodes.first; node; node = node->next) + 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) + 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) { @@ -151,8 +165,9 @@ static void node_remove_linked(Main *bmain, bNodeTree *ntree, bNode *rem_node) /* disconnect socket from the node it is connected to */ static void node_socket_disconnect(Main *bmain, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to) { - if (!sock_to->link) + if (!sock_to->link) { return; + } nodeRemLink(ntree, sock_to->link); sock_to->flag |= SOCK_COLLAPSED; @@ -166,8 +181,9 @@ static void node_socket_disconnect(Main *bmain, bNodeTree *ntree, bNode *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) + if (!sock_to->link) { return; + } node_remove_linked(bmain, ntree, sock_to->link->fromnode); sock_to->flag |= SOCK_COLLAPSED; @@ -194,13 +210,17 @@ static void node_socket_add_replace(const bContext *C, bNodeTree *ntree, bNode * } /* 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) + 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) + 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 */ @@ -236,8 +256,9 @@ static void node_socket_add_replace(const bContext *C, bNodeTree *ntree, bNode * 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) + 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; @@ -332,8 +353,9 @@ static void ui_node_link_items(NodeLinkArg *arg, int in_out, NodeLinkItem **r_it bNodeSocketTemplate *stemp; int i; - for (stemp = socket_templates; stemp && stemp->type != -1; ++stemp) + for (stemp = socket_templates; stemp && stemp->type != -1; ++stemp) { ++totitems; + } if (totitems > 0) { items = MEM_callocN(sizeof(NodeLinkItem) * totitems, "ui node link items"); @@ -363,12 +385,15 @@ static void ui_node_link(bContext *C, void *arg_p, void *event_p) bNodeTree *ntree = arg->ntree; int event = POINTER_AS_INT(event_p); - if (event == UI_NODE_LINK_DISCONNECT) + if (event == UI_NODE_LINK_DISCONNECT) { node_socket_disconnect(bmain, ntree, node_to, sock_to); - else if (event == UI_NODE_LINK_REMOVE) + } + else if (event == UI_NODE_LINK_REMOVE) { node_socket_remove(bmain, ntree, node_to, sock_to); - else + } + else { node_socket_add_replace(C, ntree, node_to, sock_to, arg->node_type->type, &arg->item); + } ED_undo_push(C, "Node input modify"); } @@ -390,10 +415,12 @@ static void ui_node_sock_name(bNodeTree *ntree, bNodeSocket *sock, char name[UI_ BLI_strncpy(name, IFACE_(node_name), UI_MAX_NAME_STR); } } - else if (sock->type == SOCK_SHADER) + else if (sock->type == SOCK_SHADER) { BLI_strncpy(name, IFACE_("None"), UI_MAX_NAME_STR); - else + } + else { BLI_strncpy(name, IFACE_("Default"), UI_MAX_NAME_STR); + } } static int ui_compatible_sockets(int typeA, int typeB) @@ -469,13 +496,16 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname) 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)) + 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)) + if (!ui_compatible_sockets(items[i].socket_type, sock->type)) { continue; + } if (first) { column = uiLayoutColumn(layout, 0); @@ -512,8 +542,9 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname) UI_but_funcN_set(but, ui_node_link, argN, NULL); } - if (items) + if (items) { MEM_freeN(items); + } } BLI_array_free(sorted_ntypes); @@ -523,8 +554,9 @@ static void node_menu_column_foreach_cb(void *calldata, int nclass, const char * { NodeLinkArg *arg = (NodeLinkArg *)calldata; - if (!ELEM(nclass, NODE_CLASS_GROUP, NODE_CLASS_LAYOUT)) + 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) @@ -546,8 +578,9 @@ static void ui_template_node_link_menu(bContext *C, uiLayout *layout, void *but_ arg->scene = scene; arg->layout = split; - if (ntreetype && ntreetype->foreach_nodeclass) + 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); @@ -587,8 +620,9 @@ void uiTemplateNodeLink(uiLayout *layout, bNodeTree *ntree, bNode *node, bNodeSo 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 + 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); @@ -596,9 +630,11 @@ void uiTemplateNodeLink(uiLayout *layout, bNodeTree *ntree, bNode *node, bNodeSo but->poin = (char *)but; but->func_argN = arg; - if (sock->link && sock->link->fromnode) - if (sock->link->fromnode->flag & NODE_ACTIVE_TEXTURE) + if (sock->link && sock->link->fromnode) { + if (sock->link->fromnode->flag & NODE_ACTIVE_TEXTURE) { but->flag |= UI_BUT_NODE_ACTIVE; + } + } } /**************************** Node Tree Layout *******************************/ @@ -624,8 +660,9 @@ static void ui_node_draw_node(uiLayout *layout, bContext *C, bNodeTree *ntree, b } } - for (input = node->inputs.first; input; input = input->next) + 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) @@ -639,16 +676,18 @@ static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, int i, indent = (depth > 1) ? 2 * (depth - 1) : 0; int dependency_loop; - if (input->flag & SOCK_UNAVAIL) + 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) + if (dependency_loop) { lnode = NULL; + } /* socket RNA pointer */ RNA_pointer_create(&ntree->id, &RNA_NodeSocket, input, &inputptr); @@ -673,8 +712,9 @@ static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, 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 + else { uiItemL(row, "", ICON_BLANK1); + } bt = block->buttons.last; bt->rect.xmax = UI_UNIT_X / 2; @@ -695,8 +735,9 @@ static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, uiTemplateNodeLink(split, ntree, node, input); if (depth == 0 || !(input->flag & SOCK_COLLAPSED)) { - if (depth == 0) + if (depth == 0) { uiItemS(layout); + } ui_node_draw_node(layout, C, ntree, lnode, depth); } @@ -724,8 +765,9 @@ static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, break; } } - else + else { row = uiLayoutRow(split, false); + } uiTemplateNodeLink(row, ntree, node, input); } @@ -738,15 +780,19 @@ void uiTemplateNodeView(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode * { bNode *tnode; - if (!ntree) + if (!ntree) { return; + } /* clear for cycle check */ - for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { tnode->flag &= ~NODE_TEST; + } - if (input) + if (input) { ui_node_draw_input(layout, C, ntree, node, input, 0); - else + } + 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 e2effc84870..dae8024611a 100644 --- a/source/blender/editors/space_node/node_toolbar.c +++ b/source/blender/editors/space_node/node_toolbar.c @@ -49,8 +49,9 @@ static int node_toolbar_toggle_exec(bContext *C, wmOperator *UNUSED(op)) ScrArea *sa = CTX_wm_area(C); ARegion *ar = node_has_tools_region(sa); - if (ar) + if (ar) { ED_region_toggle_hidden(C, ar); + } return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_node/node_view.c b/source/blender/editors/space_node/node_view.c index d0e6c45bb07..9d4b9d18c2a 100644 --- a/source/blender/editors/space_node/node_view.c +++ b/source/blender/editors/space_node/node_view.c @@ -581,8 +581,9 @@ static int sample_invoke(bContext *C, wmOperator *op, const wmEvent *event) ARegion *ar = CTX_wm_region(C); ImageSampleInfo *info; - if (!ED_node_is_compositor(snode) || !(snode->flag & SNODE_BACKDRAW)) + if (!ED_node_is_compositor(snode) || !(snode->flag & SNODE_BACKDRAW)) { return OPERATOR_CANCELLED; + } info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo"); info->art = ar->type; diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index 1271bf51c5f..22564061aed 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -75,8 +75,9 @@ void ED_node_tree_start(SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from) /* copy initial offset from bNodeTree */ copy_v2_v2(path->view_center, ntree->view_center); - if (id) + if (id) { BLI_strncpy(path->node_name, id->name + 2, sizeof(path->node_name)); + } BLI_addtail(&snode->treepath, path); @@ -99,15 +100,18 @@ void ED_node_tree_push(SpaceNode *snode, bNodeTree *ntree, bNode *gnode) bNodeTreePath *prev_path = snode->treepath.last; path->nodetree = ntree; if (gnode) { - if (prev_path) + if (prev_path) { path->parent_key = BKE_node_instance_key(prev_path->parent_key, prev_path->nodetree, gnode); - else + } + else { path->parent_key = NODE_INSTANCE_KEY_BASE; + } BLI_strncpy(path->node_name, gnode->name, sizeof(path->node_name)); } - else + else { path->parent_key = NODE_INSTANCE_KEY_BASE; + } /* copy initial offset from bNodeTree */ copy_v2_v2(path->view_center, ntree->view_center); @@ -129,8 +133,9 @@ void ED_node_tree_pop(SpaceNode *snode) bNodeTreePath *path = snode->treepath.last; /* don't remove root */ - if (path == snode->treepath.first) + if (path == snode->treepath.first) { return; + } BLI_remlink(&snode->treepath, path); MEM_freeN(path); @@ -155,8 +160,9 @@ 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) + if (i == level) { return path->nodetree; + } } return NULL; } @@ -168,8 +174,9 @@ int ED_node_tree_path_length(SpaceNode *snode) int i; for (path = snode->treepath.first, i = 0; path; path = path->next, ++i) { length += strlen(path->node_name); - if (i > 0) + if (i > 0) { length += 1; /* for separator char */ + } } return length; } @@ -206,8 +213,9 @@ void ED_node_tree_path_get_fixedbuf(SpaceNode *snode, char *value, int max_lengt size = BLI_snprintf_rlen(value, max_length, "/%s", path->node_name); } max_length -= size; - if (max_length <= 0) + if (max_length <= 0) { break; + } value += size; } } @@ -230,8 +238,9 @@ void snode_group_offset(SpaceNode *snode, float *x, float *y) *x = dcenter[0]; *y = dcenter[1]; } - else + else { *x = *y = 0.0f; + } } /* ******************** manage regions ********************* */ @@ -241,13 +250,17 @@ ARegion *node_has_buttons_region(ScrArea *sa) ARegion *ar, *arnew; ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); - if (ar) return ar; + if (ar) { + return ar; + } /* add subdiv level; after header */ ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); /* is error! */ - if (ar == NULL) return NULL; + if (ar == NULL) { + return NULL; + } arnew = MEM_callocN(sizeof(ARegion), "buttons for node"); @@ -265,13 +278,17 @@ ARegion *node_has_tools_region(ScrArea *sa) ARegion *ar, *arnew; ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS); - if (ar) return ar; + if (ar) { + return ar; + } /* add subdiv level; after header */ ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); /* is error! */ - if (ar == NULL) return NULL; + if (ar == NULL) { + return NULL; + } arnew = MEM_callocN(sizeof(ARegion), "node tools"); @@ -393,8 +410,9 @@ static void node_area_listener(wmWindow *UNUSED(win), ScrArea *sa, wmNotifier *w 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) + if (ar && path) { UI_view2d_center_set(&ar->v2d, path->view_center[0], path->view_center[1]); + } ED_area_tag_refresh(sa); break; @@ -422,21 +440,26 @@ static void node_area_listener(wmWindow *UNUSED(win), ScrArea *sa, wmNotifier *w /* future: add ID checks? */ case NC_MATERIAL: if (ED_node_is_shader(snode)) { - if (wmn->data == ND_SHADING) + if (wmn->data == ND_SHADING) { ED_area_tag_refresh(sa); - else if (wmn->data == ND_SHADING_DRAW) + } + else if (wmn->data == ND_SHADING_DRAW) { ED_area_tag_refresh(sa); - else if (wmn->data == ND_SHADING_LINKS) + } + else if (wmn->data == ND_SHADING_LINKS) { ED_area_tag_refresh(sa); - else if (wmn->action == NA_ADDED && snode->edittree) + } + 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) + if (wmn->data == ND_NODES) { ED_area_tag_refresh(sa); + } } break; case NC_WORLD: @@ -446,21 +469,26 @@ static void node_area_listener(wmWindow *UNUSED(win), ScrArea *sa, wmNotifier *w break; case NC_OBJECT: if (ED_node_is_shader(snode)) { - if (wmn->data == ND_OB_SHADING) + if (wmn->data == ND_OB_SHADING) { ED_area_tag_refresh(sa); + } } break; case NC_SPACE: - if (wmn->data == ND_SPACE_NODE) + if (wmn->data == ND_SPACE_NODE) { ED_area_tag_refresh(sa); - else if (wmn->data == ND_SPACE_NODE_VIEW) + } + else if (wmn->data == ND_SPACE_NODE_VIEW) { ED_area_tag_redraw(sa); + } break; case NC_NODE: - if (wmn->action == NA_EDITED) + if (wmn->action == NA_EDITED) { ED_area_tag_refresh(sa); - else if (wmn->action == NA_SELECTED) + } + else if (wmn->action == NA_SELECTED) { ED_area_tag_redraw(sa); + } break; case NC_SCREEN: switch (wmn->data) { @@ -483,8 +511,9 @@ static void node_area_listener(wmWindow *UNUSED(win), ScrArea *sa, wmNotifier *w /* 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)) + if (nodeUpdateID(snode->nodetree, wmn->reference)) { ED_area_tag_refresh(sa); + } } } break; @@ -492,8 +521,9 @@ static void node_area_listener(wmWindow *UNUSED(win), ScrArea *sa, wmNotifier *w case NC_MOVIECLIP: if (wmn->action == NA_EDITED) { if (ED_node_is_compositor(snode)) { - if (nodeUpdateID(snode->nodetree, wmn->reference)) + if (nodeUpdateID(snode->nodetree, wmn->reference)) { ED_area_tag_refresh(sa); + } } } break; @@ -527,18 +557,21 @@ static void node_area_refresh(const struct bContext *C, ScrArea *sa) if (snode->nodetree->type == NTREE_SHADER) { if (GS(snode->id->name) == ID_MA) { Material *ma = (Material *)snode->id; - if (ma->use_nodes) + 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) + 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) + 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) { @@ -755,8 +788,9 @@ static void node_region_listener( } break; case NC_WM: - if (wmn->data == ND_JOB) + if (wmn->data == ND_JOB) { ED_region_tag_redraw(ar); + } break; case NC_SCENE: ED_region_tag_redraw(ar); @@ -777,18 +811,22 @@ static void node_region_listener( ED_region_tag_redraw(ar); break; case NC_OBJECT: - if (wmn->data == ND_OB_SHADING) + if (wmn->data == ND_OB_SHADING) { ED_region_tag_redraw(ar); + } break; case NC_ID: - if (wmn->action == NA_RENAME) + if (wmn->action == NA_RENAME) { ED_region_tag_redraw(ar); + } break; case NC_GPENCIL: - if (wmn->action == NA_EDITED) + if (wmn->action == NA_EDITED) { ED_region_tag_redraw(ar); - else if (wmn->data & ND_GPENCIL_EDITMODE) + } + else if (wmn->data & ND_GPENCIL_EDITMODE) { ED_region_tag_redraw(ar); + } break; } } |