Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_node/node_add.cc')
-rw-r--r--source/blender/editors/space_node/node_add.cc93
1 files changed, 43 insertions, 50 deletions
diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc
index 2e3579caaa1..c6a5e8e68c0 100644
--- a/source/blender/editors/space_node/node_add.cc
+++ b/source/blender/editors/space_node/node_add.cc
@@ -28,7 +28,6 @@
#include "DNA_texture_types.h"
#include "BLI_listbase.h"
-#include "BLI_math.h"
#include "BLT_translation.h"
@@ -62,24 +61,19 @@
/** \name Utilities
* \{ */
-/**
- * XXX Does some additional initialization on top of #nodeAddNode
- * Can be used with both custom and static nodes,
- * if `idname == nullptr` the static int type will be used instead.
- */
-bNode *node_add_node(const bContext *C, const char *idname, int type, float locx, float locy)
+bNode *node_add_node(const bContext &C, const char *idname, int type, float locx, float locy)
{
- SpaceNode *snode = CTX_wm_space_node(C);
- Main *bmain = CTX_data_main(C);
+ SpaceNode &snode = *CTX_wm_space_node(&C);
+ Main &bmain = *CTX_data_main(&C);
bNode *node = nullptr;
node_deselect_all(snode);
if (idname) {
- node = nodeAddNode(C, snode->edittree, idname);
+ node = nodeAddNode(&C, snode.edittree, idname);
}
else {
- node = nodeAddStaticNode(C, snode->edittree, type);
+ node = nodeAddStaticNode(&C, snode.edittree, type);
}
BLI_assert(node && node->typeinfo);
@@ -89,13 +83,13 @@ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx
nodeSetSelected(node, true);
- ntreeUpdateTree(bmain, snode->edittree);
- ED_node_set_active(bmain, snode, snode->edittree, node, nullptr);
+ ntreeUpdateTree(&bmain, snode.edittree);
+ ED_node_set_active(&bmain, &snode, snode.edittree, node, nullptr);
snode_update(snode, node);
- if (snode->nodetree->type == NTREE_TEXTURE) {
- ntreeTexCheckCyclics(snode->edittree);
+ if (snode.nodetree->type == NTREE_TEXTURE) {
+ ntreeTexCheckCyclics(snode.edittree);
}
return node;
@@ -107,7 +101,7 @@ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx
/** \name Add Reroute Operator
* \{ */
-static bool add_reroute_intersect_check(bNodeLink *link,
+static bool add_reroute_intersect_check(const bNodeLink &link,
float mcoords[][2],
int tot,
float result[2])
@@ -224,9 +218,9 @@ static bNodeSocketLink *add_reroute_do_socket_section(bContext *C,
static int add_reroute_exec(bContext *C, wmOperator *op)
{
- SpaceNode *snode = CTX_wm_space_node(C);
- ARegion *region = CTX_wm_region(C);
- bNodeTree *ntree = snode->edittree;
+ SpaceNode &snode = *CTX_wm_space_node(C);
+ ARegion &region = *CTX_wm_region(C);
+ bNodeTree &ntree = *snode.edittree;
float mcoords[256][2];
int i = 0;
@@ -236,7 +230,7 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
RNA_float_get_array(&itemptr, "loc", loc);
UI_view2d_region_to_view(
- &region->v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]);
+ &region.v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]);
i++;
if (i >= 256) {
break;
@@ -246,7 +240,6 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
if (i > 1) {
ListBase output_links, input_links;
- bNodeLink *link;
bNodeSocketLink *socklink;
float insert_point[2];
@@ -259,11 +252,11 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
BLI_listbase_clear(&output_links);
BLI_listbase_clear(&input_links);
- for (link = (bNodeLink *)ntree->links.first; link; link = link->next) {
- if (node_link_is_hidden_or_dimmed(&region->v2d, link)) {
+ LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) {
+ if (node_link_is_hidden_or_dimmed(region.v2d, *link)) {
continue;
}
- if (add_reroute_intersect_check(link, mcoords, i, insert_point)) {
+ 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);
@@ -288,9 +281,9 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
BLI_freelistN(&input_links);
/* always last */
- ntreeUpdateTree(CTX_data_main(C), ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ ntreeUpdateTree(CTX_data_main(C), &ntree);
+ snode_notify(*C, snode);
+ snode_dag_update(*C, snode);
return OPERATOR_FINISHED;
}
@@ -377,7 +370,7 @@ static int node_add_group_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
- bNode *group_node = node_add_node(C,
+ bNode *group_node = node_add_node(*C,
node_group_idname(C),
(node_group->type == NTREE_CUSTOM) ? NODE_CUSTOM_GROUP :
NODE_GROUP,
@@ -395,8 +388,8 @@ static int node_add_group_exec(bContext *C, wmOperator *op)
ntreeUpdateTree(bmain, node_group);
ntreeUpdateTree(bmain, ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, *snode);
+ snode_dag_update(*C, *snode);
return OPERATOR_FINISHED;
}
@@ -469,7 +462,7 @@ static int node_add_object_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
bNode *object_node = node_add_node(
- C, nullptr, GEO_NODE_OBJECT_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]);
+ *C, nullptr, GEO_NODE_OBJECT_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]);
if (!object_node) {
BKE_report(op->reports, RPT_WARNING, "Could not add node object");
return OPERATOR_CANCELLED;
@@ -488,8 +481,8 @@ static int node_add_object_exec(bContext *C, wmOperator *op)
nodeSetActive(ntree, object_node);
ntreeUpdateTree(bmain, ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, *snode);
+ snode_dag_update(*C, *snode);
ED_node_tag_update_nodetree(bmain, ntree, object_node);
DEG_relations_tag_update(bmain);
@@ -580,7 +573,7 @@ static int node_add_texture_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
- bNode *texture_node = node_add_node(C,
+ bNode *texture_node = node_add_node(*C,
nullptr,
GEO_NODE_LEGACY_ATTRIBUTE_SAMPLE_TEXTURE,
snode->runtime->cursor[0],
@@ -596,8 +589,8 @@ static int node_add_texture_exec(bContext *C, wmOperator *op)
nodeSetActive(ntree, texture_node);
ntreeUpdateTree(bmain, ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, *snode);
+ snode_dag_update(*C, *snode);
DEG_relations_tag_update(bmain);
ED_node_tag_update_nodetree(bmain, ntree, texture_node);
@@ -680,8 +673,8 @@ static Collection *node_add_collection_get_and_poll_collection_node_tree(Main *b
static int node_add_collection_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- SpaceNode *snode = CTX_wm_space_node(C);
- bNodeTree *ntree = snode->edittree;
+ SpaceNode &snode = *CTX_wm_space_node(C);
+ bNodeTree *ntree = snode.edittree;
Collection *collection;
if (!(collection = node_add_collection_get_and_poll_collection_node_tree(bmain, op))) {
@@ -691,7 +684,7 @@ static int node_add_collection_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
bNode *collection_node = node_add_node(
- C, nullptr, GEO_NODE_COLLECTION_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]);
+ *C, nullptr, GEO_NODE_COLLECTION_INFO, snode.runtime->cursor[0], snode.runtime->cursor[1]);
if (!collection_node) {
BKE_report(op->reports, RPT_WARNING, "Could not add node collection");
return OPERATOR_CANCELLED;
@@ -710,8 +703,8 @@ static int node_add_collection_exec(bContext *C, wmOperator *op)
nodeSetActive(ntree, collection_node);
ntreeUpdateTree(bmain, ntree);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, snode);
+ snode_dag_update(*C, snode);
DEG_relations_tag_update(bmain);
ED_node_tag_update_nodetree(bmain, ntree, collection_node);
@@ -788,7 +781,7 @@ static bool node_add_file_poll(bContext *C)
static int node_add_file_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- SpaceNode *snode = CTX_wm_space_node(C);
+ SpaceNode &snode = *CTX_wm_space_node(C);
bNode *node;
Image *ima;
int type = 0;
@@ -798,7 +791,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- switch (snode->nodetree->type) {
+ switch (snode.nodetree->type) {
case NTREE_SHADER:
type = SH_NODE_TEX_IMAGE;
break;
@@ -817,7 +810,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
- node = node_add_node(C, nullptr, type, snode->runtime->cursor[0], snode->runtime->cursor[1]);
+ node = node_add_node(*C, nullptr, type, snode.runtime->cursor[0], snode.runtime->cursor[1]);
if (!node) {
BKE_report(op->reports, RPT_WARNING, "Could not add an image node");
@@ -841,8 +834,8 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
}
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, snode);
+ snode_dag_update(*C, snode);
DEG_relations_tag_update(bmain);
return OPERATOR_FINISHED;
@@ -923,7 +916,7 @@ static bool node_add_mask_poll(bContext *C)
static int node_add_mask_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- SpaceNode *snode = CTX_wm_space_node(C);
+ SpaceNode &snode = *CTX_wm_space_node(C);
bNode *node;
ID *mask = node_add_mask_get_and_poll_mask(bmain, op);
@@ -934,7 +927,7 @@ static int node_add_mask_exec(bContext *C, wmOperator *op)
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
node = node_add_node(
- C, nullptr, CMP_NODE_MASK, snode->runtime->cursor[0], snode->runtime->cursor[1]);
+ *C, nullptr, CMP_NODE_MASK, snode.runtime->cursor[0], snode.runtime->cursor[1]);
if (!node) {
BKE_report(op->reports, RPT_WARNING, "Could not add a mask node");
@@ -944,8 +937,8 @@ static int node_add_mask_exec(bContext *C, wmOperator *op)
node->id = mask;
id_us_plus(mask);
- snode_notify(C, snode);
- snode_dag_update(C, snode);
+ snode_notify(*C, snode);
+ snode_dag_update(*C, snode);
DEG_relations_tag_update(bmain);
return OPERATOR_FINISHED;