[Bf-blender-cvs] [2d8606b3607] master: Cleanup: Use references in node editor, other improvements
Hans Goudey
noreply at git.blender.org
Fri Dec 3 22:25:29 CET 2021
Commit: 2d8606b36071dd14290aa8852451535a49d3096d
Author: Hans Goudey
Date: Fri Dec 3 16:25:17 2021 -0500
Branches: master
https://developer.blender.org/rB2d8606b36071dd14290aa8852451535a49d3096d
Cleanup: Use references in node editor, other improvements
This helps to tell when a pointer is expected to be null, and avoid
overly verbose code when dereferencing. This commit also includes
a few other cleanups in this area:
- Use const in a few places
- Use `float2` instead of `float[2]`
- Remove some unnecessary includes and old code
The change can be continued further in the future.
===================================================================
M source/blender/blenkernel/BKE_node.h
M source/blender/blenkernel/intern/node.cc
M source/blender/editors/space_node/drawnode.cc
M source/blender/editors/space_node/node_add.cc
M source/blender/editors/space_node/node_draw.cc
M source/blender/editors/space_node/node_edit.cc
M source/blender/editors/space_node/node_geometry_attribute_search.cc
M source/blender/editors/space_node/node_group.cc
M source/blender/editors/space_node/node_intern.hh
M source/blender/editors/space_node/node_relationships.cc
M source/blender/editors/space_node/node_select.cc
M source/blender/editors/space_node/node_templates.cc
M source/blender/editors/space_node/node_view.cc
M source/blender/editors/space_node/space_node.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 776845b4c99..85699e4c28d 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -285,7 +285,7 @@ typedef struct bNodeType {
*/
void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
/** Optional custom resize handle polling. */
- NodeResizeDirection (*resize_area_func)(struct bNode *node, int x, int y);
+ NodeResizeDirection (*resize_area_func)(const struct bNode *node, int x, int y);
/** Optional selection area polling. */
int (*select_area_func)(struct bNode *node, int x, int y);
/** Optional tweak area polling (for grabbing). */
@@ -555,7 +555,7 @@ void ntreeInterfaceTypeUpdate(struct bNodeTree *ntree);
struct bNodeType *nodeTypeFind(const char *idname);
void nodeRegisterType(struct bNodeType *ntype);
void nodeUnregisterType(struct bNodeType *ntype);
-bool nodeTypeUndefined(struct bNode *node);
+bool nodeTypeUndefined(const struct bNode *node);
struct GHashIterator *nodeTypeGetIterator(void);
/* Helper macros for iterating over node types. */
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 4178e7577d8..359dbaab12b 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -1455,7 +1455,7 @@ void nodeUnregisterType(bNodeType *nt)
BLI_ghash_remove(nodetypes_hash, nt->idname, nullptr, node_free_type);
}
-bool nodeTypeUndefined(bNode *node)
+bool nodeTypeUndefined(const bNode *node)
{
return (node->typeinfo == &NodeTypeUndefined) ||
((ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) && node->id &&
diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index 0602bc7e124..cdce876f57a 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -22,8 +22,6 @@
* \brief lower level node drawing for nodes (boarders, headers etc), also node layout.
*/
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
#include "BLI_system.h"
#include "BLI_threads.h"
@@ -79,6 +77,8 @@
#include "NOD_texture.h"
#include "node_intern.hh" /* own include */
+using blender::float2;
+
/* Default flags for uiItemR(). Name is kept short since this is used a lot in this file. */
#define DEFAULT_FLAGS UI_ITEM_R_SPLIT_EMPTY_NAME
@@ -250,7 +250,7 @@ static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *pt
uiItemR(layout, ptr, "use_clamp", DEFAULT_FLAGS, nullptr, ICON_NONE);
}
-static NodeResizeDirection node_resize_area_default(bNode *node, const int x, const int y)
+static NodeResizeDirection node_resize_area_default(const bNode *node, const int x, const int y)
{
if (node->flag & NODE_HIDDEN) {
rctf totr = node->totr;
@@ -264,7 +264,7 @@ static NodeResizeDirection node_resize_area_default(bNode *node, const int x, co
}
const float size = NODE_RESIZE_MARGIN;
- rctf totr = node->totr;
+ const rctf &totr = node->totr;
NodeResizeDirection dir = NODE_RESIZE_NONE;
if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax) {
@@ -295,9 +295,9 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree,
/* init rect from current frame size */
rctf rect;
- node_to_view(node, node->offsetx, node->offsety, &rect.xmin, &rect.ymax);
+ node_to_view(*node, node->offsetx, node->offsety, &rect.xmin, &rect.ymax);
node_to_view(
- node, node->offsetx + node->width, node->offsety - node->height, &rect.xmax, &rect.ymin);
+ *node, node->offsetx + node->width, node->offsety - node->height, &rect.xmax, &rect.ymin);
/* frame can be resized manually only if shrinking is disabled or no children are attached */
data->flag |= NODE_FRAME_RESIZEABLE;
@@ -328,25 +328,25 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree,
}
/* now adjust the frame size from view-space bounding box */
- node_from_view(node, rect.xmin, rect.ymax, &node->offsetx, &node->offsety);
+ node_from_view(*node, rect.xmin, rect.ymax, &node->offsetx, &node->offsety);
float xmax, ymax;
- node_from_view(node, rect.xmax, rect.ymin, &xmax, &ymax);
+ node_from_view(*node, rect.xmax, rect.ymin, &xmax, &ymax);
node->width = xmax - node->offsetx;
node->height = -ymax + node->offsety;
node->totr = rect;
}
-static void node_draw_frame_label(bNodeTree *ntree, bNode *node, SpaceNode *snode)
+static void node_draw_frame_label(bNodeTree &ntree, bNode &node, SpaceNode &snode)
{
- const float aspect = snode->runtime->aspect;
+ const float aspect = snode.runtime->aspect;
/* XXX font id is crap design */
const int fontid = UI_style_get()->widgetlabel.uifont_id;
- NodeFrame *data = (NodeFrame *)node->storage;
+ NodeFrame *data = (NodeFrame *)node.storage;
const float font_size = data->label_size / aspect;
char label[MAX_NAME];
- nodeLabel(ntree, node, label, sizeof(label));
+ nodeLabel(&ntree, &node, label, sizeof(label));
BLF_enable(fontid, BLF_ASPECT);
BLF_aspect(fontid, aspect, aspect, 1.0f);
@@ -365,39 +365,39 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, SpaceNode *snod
const int label_height = ((margin / aspect) + (ascender * aspect));
/* 'x' doesn't need aspect correction */
- rctf *rct = &node->totr;
+ const rctf &rct = node.totr;
/* XXX a bit hacky, should use separate align values for x and y */
- float x = BLI_rctf_cent_x(rct) - (0.5f * width);
- float y = rct->ymax - label_height;
+ float x = BLI_rctf_cent_x(&rct) - (0.5f * width);
+ float y = rct.ymax - label_height;
/* label */
- const bool has_label = node->label[0] != '\0';
+ const bool has_label = node.label[0] != '\0';
if (has_label) {
BLF_position(fontid, x, y, 0);
BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX);
}
/* draw text body */
- if (node->id) {
- Text *text = (Text *)node->id;
+ if (node.id) {
+ Text *text = (Text *)node.id;
const int line_height_max = BLF_height_max(fontid);
const float line_spacing = (line_height_max * aspect);
- const float line_width = (BLI_rctf_size_x(rct) - margin) / aspect;
+ const float line_width = (BLI_rctf_size_x(&rct) - margin) / aspect;
/* 'x' doesn't need aspect correction */
- x = rct->xmin + margin;
- y = rct->ymax - label_height - (has_label ? line_spacing : 0);
+ x = rct.xmin + margin;
+ y = rct.ymax - label_height - (has_label ? line_spacing : 0);
/* early exit */
- int y_min = y + ((margin * 2) - (y - rct->ymin));
+ int y_min = y + ((margin * 2) - (y - rct.ymin));
BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP);
BLF_clipping(fontid,
- rct->xmin,
+ rct.xmin,
/* round to avoid clipping half-way through a line */
- y - (floorf(((y - rct->ymin) - (margin * 2)) / line_spacing) * line_spacing),
- rct->xmin + line_width,
- rct->ymax);
+ y - (floorf(((y - rct.ymin) - (margin * 2)) / line_spacing) * line_spacing),
+ rct.xmin + line_width,
+ rct.ymax);
BLF_wordwrap(fontid, line_width);
@@ -442,7 +442,7 @@ static void node_draw_frame(const bContext *C,
const float alpha = color[3];
/* shadow */
- node_draw_shadow(snode, node, BASIS_RAD, alpha);
+ node_draw_shadow(*snode, *node, BASIS_RAD, alpha);
/* body */
if (node->flag & NODE_CUSTOM_COLOR) {
@@ -452,9 +452,9 @@ static void node_draw_frame(const bContext *C,
UI_GetThemeColor4fv(TH_NODE_FRAME, color);
}
- const rctf *rct = &node->totr;
+ const rctf &rct = node->totr;
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_4fv(rct, true, BASIS_RAD, color);
+ UI_draw_roundbox_4fv(&rct, true, BASIS_RAD, color);
/* outline active and selected emphasis */
if (node->flag & SELECT) {
@@ -465,20 +465,20 @@ static void node_draw_frame(const bContext *C,
UI_GetThemeColorShadeAlpha4fv(TH_SELECT, 0, -40, color);
}
- UI_draw_roundbox_aa(rct, false, BASIS_RAD, color);
+ UI_draw_roundbox_aa(&rct, false, BASIS_RAD, color);
}
/* label and text */
- node_draw_frame_label(ntree, node, snode);
+ node_draw_frame_label(*ntree, *node, *snode);
- node_draw_extra_info_panel(snode, node);
+ node_draw_extra_info_panel(*snode, *node);
UI_block_end(C, node->block);
UI_block_draw(C, node->block);
node->block = nullptr;
}
-static NodeResizeDirection node_resize_area_frame(bNode *node, const int x, const int y)
+static NodeResizeDirection node_resize_area_frame(const bNode *node, const int x, const int y)
{
const float size = 10.0f;
NodeFrame *data = (NodeFrame *)node->storage;
@@ -522,7 +522,7 @@ static void node_draw_reroute_prepare(const bContext *UNUSED(C),
{
/* get "global" coords */
float locx, locy;
- node_to_view(node, 0.0f, 0.0f, &locx, &locy);
+ node_to_view(*node, 0.0f, 0.0f, &locx, &locy);
/* reroute node has exactly one input and one output, both in the same place */
bNodeSocket *nsock = (bNodeSocket *)node->outputs.first;
@@ -549,46 +549,16 @@ static void node_draw_reroute(const bContext *C,
bNodeInstanceKey UNUSED(key))
{
char showname[128]; /* 128 used below */
- rctf *rct = &node->totr;
+ const rctf &rct = node->totr;
/* skip if out of view */
- if (node->totr.xmax < region->v2d.cur.xmin || node->totr.xmin > region->v2d.cur.xmax ||
- node->totr.ymax < region->v2d.cur.ymin || node->totr.ymin > region->v2d.cur.ymax) {
+ if (rct.xmax < region->v2d.cur.xmin || rct.xmin > region->v2d.cur.xmax ||
+ rct.ymax < region->v2d.cur.ymin || node->totr.ymin > region->v2d.cur.ymax) {
UI_block_end(C, node->block);
node->block = nullptr;
return;
}
- /* XXX only kept for debugging
- * selection state is indicated by socket outline below!
- */
-#if 0
- float size = NODE_REROUTE_SIZE;
-
- /* body */
- float debug_color[4];
- UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_GetThemeColor4fv(TH_NODE, debug_color);
- U
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list