diff options
author | Hans Goudey <h.goudey@me.com> | 2021-02-09 00:09:49 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-02-09 00:09:49 +0300 |
commit | cfa48c84d06ca8197f86b6d3ceef8a2c7c311a82 (patch) | |
tree | b841d7d8c27a8811317fc069a8581953fef5b736 /source/blender/nodes/function | |
parent | 13299a73675028c1d9bf3143ec808f9231e78e75 (diff) |
Cleanup: Register node property layout callbacks in files
This commit moves the property layout callbacks for node types to their
implementation files from `drawnode.c`. This was proposed a while ago in
T75724.
**Benefits**
- Fewer files need to be changed when adding a new node.
- Makes it possible to reuse functions from the node's implementation
in the layout code.
- Except for RNA, all of the node "inputs" are in the same place.
- Code gets shorter overall, avoids the large switch statements.
**Downsides**
- Requires including two UI headers.
- Requires adding an editors dependency to the nodes folder.
This commit only changes function nodes and geometry nodes, more can be
moved later.
Differential Revision: https://developer.blender.org/D10352
Diffstat (limited to 'source/blender/nodes/function')
4 files changed, 38 insertions, 1 deletions
diff --git a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc index 9148cef7805..7a83ff8e016 100644 --- a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc +++ b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc @@ -19,6 +19,9 @@ #include "RNA_enum_types.h" +#include "UI_interface.h" +#include "UI_resources.h" + #include "node_function_util.hh" static bNodeSocketTemplate fn_node_boolean_math_in[] = { @@ -32,6 +35,11 @@ static bNodeSocketTemplate fn_node_boolean_math_out[] = { {-1, ""}, }; +static void fn_node_boolean_math_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiItemR(layout, ptr, "operation", 0, "", ICON_NONE); +} + static void node_boolean_math_update(bNodeTree *UNUSED(ntree), bNode *node) { bNodeSocket *sockB = (bNodeSocket *)BLI_findlink(&node->inputs, 1); @@ -86,5 +94,6 @@ void register_node_type_fn_boolean_math() node_type_label(&ntype, node_boolean_math_label); node_type_update(&ntype, node_boolean_math_update); ntype.expand_in_mf_network = node_boolean_expand_in_mf_network; + ntype.draw_buttons = fn_node_boolean_math_layout; nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/function/nodes/node_fn_float_compare.cc b/source/blender/nodes/function/nodes/node_fn_float_compare.cc index 93c79a48571..6c8df8f2ea0 100644 --- a/source/blender/nodes/function/nodes/node_fn_float_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_float_compare.cc @@ -21,6 +21,9 @@ #include "RNA_enum_types.h" +#include "UI_interface.h" +#include "UI_resources.h" + #include "node_function_util.hh" static bNodeSocketTemplate fn_node_float_compare_in[] = { @@ -35,6 +38,11 @@ static bNodeSocketTemplate fn_node_float_compare_out[] = { {-1, ""}, }; +static void geo_node_float_compare_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiItemR(layout, ptr, "operation", 0, "", ICON_NONE); +} + static void node_float_compare_update(bNodeTree *UNUSED(ntree), bNode *node) { bNodeSocket *sockEpsilon = (bNodeSocket *)BLI_findlink(&node->inputs, 2); @@ -105,5 +113,6 @@ void register_node_type_fn_float_compare() node_type_label(&ntype, node_float_compare_label); node_type_update(&ntype, node_float_compare_update); ntype.expand_in_mf_network = node_float_compare_expand_in_mf_network; + ntype.draw_buttons = geo_node_float_compare_layout; nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/function/nodes/node_fn_input_vector.cc b/source/blender/nodes/function/nodes/node_fn_input_vector.cc index c2707f6307a..2cd4eb1d9df 100644 --- a/source/blender/nodes/function/nodes/node_fn_input_vector.cc +++ b/source/blender/nodes/function/nodes/node_fn_input_vector.cc @@ -18,11 +18,20 @@ #include "BLI_hash.h" +#include "UI_interface.h" +#include "UI_resources.h" + static bNodeSocketTemplate fn_node_input_vector_out[] = { {SOCK_VECTOR, N_("Vector")}, {-1, ""}, }; +static void fn_node_input_vector_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiLayout *col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "vector", UI_ITEM_R_EXPAND, "", ICON_NONE); +} + static void fn_node_vector_input_expand_in_mf_network( blender::nodes::NodeMFNetworkBuilder &builder) { @@ -50,6 +59,6 @@ void register_node_type_fn_input_vector() node_type_storage( &ntype, "NodeInputVector", node_free_standard_storage, node_copy_standard_storage); ntype.expand_in_mf_network = fn_node_vector_input_expand_in_mf_network; - + ntype.draw_buttons = fn_node_input_vector_layout; nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/function/nodes/node_fn_switch.cc b/source/blender/nodes/function/nodes/node_fn_switch.cc index 281ddb05c76..5187decbbe5 100644 --- a/source/blender/nodes/function/nodes/node_fn_switch.cc +++ b/source/blender/nodes/function/nodes/node_fn_switch.cc @@ -15,8 +15,17 @@ */ #include "BLI_listbase.h" + +#include "UI_interface.h" +#include "UI_resources.h" + #include "node_function_util.hh" +static void fn_node_switch_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE); +} + static bNodeSocketTemplate fn_node_switch_in[] = { {SOCK_BOOLEAN, N_("Switch")}, @@ -72,5 +81,6 @@ void register_node_type_fn_switch() fn_node_type_base(&ntype, FN_NODE_SWITCH, "Switch", 0, 0); node_type_socket_templates(&ntype, fn_node_switch_in, fn_node_switch_out); node_type_update(&ntype, fn_node_switch_update); + ntype.draw_buttons = fn_node_switch_layout; nodeRegisterType(&ntype); } |