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:
authorHans Goudey <h.goudey@me.com>2021-02-09 00:09:49 +0300
committerHans Goudey <h.goudey@me.com>2021-02-09 00:09:49 +0300
commitcfa48c84d06ca8197f86b6d3ceef8a2c7c311a82 (patch)
treeb841d7d8c27a8811317fc069a8581953fef5b736 /source/blender/editors/space_node/drawnode.c
parent13299a73675028c1d9bf3143ec808f9231e78e75 (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/editors/space_node/drawnode.c')
-rw-r--r--source/blender/editors/space_node/drawnode.c391
1 files changed, 0 insertions, 391 deletions
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 132dcd8a9fb..2d65302c656 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3126,393 +3126,6 @@ static void node_texture_set_butfunc(bNodeType *ntype)
}
}
-/* ****************** BUTTON CALLBACKS FOR GEOMETRY NODES ***************** */
-
-static void node_geometry_buts_boolean_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
-}
-
-static void node_geometry_buts_attribute_compare(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
- uiItemR(layout, ptr, "input_type_a", DEFAULT_FLAGS, IFACE_("Type A"), ICON_NONE);
- uiItemR(layout, ptr, "input_type_b", DEFAULT_FLAGS, IFACE_("Type B"), ICON_NONE);
-}
-
-static void node_geometry_buts_subdivision_surface(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *UNUSED(ptr))
-{
-#ifndef WITH_OPENSUBDIV
- uiItemL(layout, IFACE_("Disabled, built without OpenSubdiv"), ICON_ERROR);
-#else
- UNUSED_VARS(layout);
-#endif
-}
-
-static void node_geometry_buts_triangulate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "quad_method", DEFAULT_FLAGS, "", ICON_NONE);
- uiItemR(layout, ptr, "ngon_method", DEFAULT_FLAGS, "", ICON_NONE);
-}
-
-static void node_geometry_buts_random_attribute(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "data_type", DEFAULT_FLAGS, "", ICON_NONE);
-}
-
-static bool node_attribute_math_operation_use_input_b(const NodeMathOperation operation)
-{
- switch (operation) {
- case NODE_MATH_ADD:
- case NODE_MATH_SUBTRACT:
- case NODE_MATH_MULTIPLY:
- case NODE_MATH_DIVIDE:
- case NODE_MATH_POWER:
- case NODE_MATH_LOGARITHM:
- case NODE_MATH_MINIMUM:
- case NODE_MATH_MAXIMUM:
- case NODE_MATH_LESS_THAN:
- case NODE_MATH_GREATER_THAN:
- case NODE_MATH_MODULO:
- case NODE_MATH_ARCTAN2:
- case NODE_MATH_SNAP:
- case NODE_MATH_WRAP:
- case NODE_MATH_COMPARE:
- case NODE_MATH_MULTIPLY_ADD:
- case NODE_MATH_PINGPONG:
- case NODE_MATH_SMOOTH_MIN:
- case NODE_MATH_SMOOTH_MAX:
- return true;
- case NODE_MATH_SINE:
- case NODE_MATH_COSINE:
- case NODE_MATH_TANGENT:
- case NODE_MATH_ARCSINE:
- case NODE_MATH_ARCCOSINE:
- case NODE_MATH_ARCTANGENT:
- case NODE_MATH_ROUND:
- case NODE_MATH_ABSOLUTE:
- case NODE_MATH_FLOOR:
- case NODE_MATH_CEIL:
- case NODE_MATH_FRACTION:
- case NODE_MATH_SQRT:
- case NODE_MATH_INV_SQRT:
- case NODE_MATH_SIGN:
- case NODE_MATH_EXPONENT:
- case NODE_MATH_RADIANS:
- case NODE_MATH_DEGREES:
- case NODE_MATH_SINH:
- case NODE_MATH_COSH:
- case NODE_MATH_TANH:
- case NODE_MATH_TRUNC:
- return false;
- }
- BLI_assert(false);
- return false;
-}
-
-static void node_geometry_buts_attribute_math(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- bNode *node = (bNode *)ptr->data;
- NodeAttributeMath *node_storage = (NodeAttributeMath *)node->storage;
- NodeMathOperation operation = (NodeMathOperation)node_storage->operation;
-
- uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
- uiItemR(layout, ptr, "input_type_a", DEFAULT_FLAGS, IFACE_("Type A"), ICON_NONE);
-
- /* These "use input b / c" checks are copied from the node's code.
- * They could be de-duplicated if the drawing code was moved to the node's file. */
- if (node_attribute_math_operation_use_input_b(operation)) {
- uiItemR(layout, ptr, "input_type_b", DEFAULT_FLAGS, IFACE_("Type B"), ICON_NONE);
- }
- if (ELEM(operation,
- NODE_MATH_MULTIPLY_ADD,
- NODE_MATH_SMOOTH_MIN,
- NODE_MATH_SMOOTH_MAX,
- NODE_MATH_WRAP,
- NODE_MATH_COMPARE)) {
- uiItemR(layout, ptr, "input_type_c", DEFAULT_FLAGS, IFACE_("Type C"), ICON_NONE);
- }
-}
-
-static void node_geometry_buts_attribute_vector_math(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- bNode *node = (bNode *)ptr->data;
- NodeAttributeVectorMath *node_storage = (NodeAttributeVectorMath *)node->storage;
-
- uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
- uiItemR(layout, ptr, "input_type_a", DEFAULT_FLAGS, IFACE_("Type A"), ICON_NONE);
-
- /* These "use input b / c" checks are copied from the node's code.
- * They could be de-duplicated if the drawing code was moved to the node's file. */
- if (!ELEM(node_storage->operation,
- NODE_VECTOR_MATH_NORMALIZE,
- NODE_VECTOR_MATH_FLOOR,
- NODE_VECTOR_MATH_CEIL,
- NODE_VECTOR_MATH_FRACTION,
- NODE_VECTOR_MATH_ABSOLUTE,
- NODE_VECTOR_MATH_SINE,
- NODE_VECTOR_MATH_COSINE,
- NODE_VECTOR_MATH_TANGENT,
- NODE_VECTOR_MATH_LENGTH)) {
- uiItemR(layout, ptr, "input_type_b", DEFAULT_FLAGS, IFACE_("Type B"), ICON_NONE);
- }
- if (ELEM(node_storage->operation, NODE_VECTOR_MATH_WRAP)) {
- uiItemR(layout, ptr, "input_type_c", DEFAULT_FLAGS, IFACE_("Type C"), ICON_NONE);
- }
-}
-
-static void node_geometry_buts_point_instance(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "instance_type", DEFAULT_FLAGS | UI_ITEM_R_EXPAND, NULL, ICON_NONE);
- if (RNA_enum_get(ptr, "instance_type") == GEO_NODE_POINT_INSTANCE_TYPE_COLLECTION) {
- uiItemR(layout, ptr, "use_whole_collection", DEFAULT_FLAGS, NULL, ICON_NONE);
- }
-}
-
-static void node_geometry_buts_attribute_fill(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "data_type", DEFAULT_FLAGS, "", ICON_NONE);
- // uiItemR(layout, ptr, "domain", DEFAULT_FLAGS, "", ICON_NONE);
-}
-
-static void node_geometry_buts_attribute_mix(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "blend_type", DEFAULT_FLAGS, "", ICON_NONE);
- uiLayout *col = uiLayoutColumn(layout, false);
- uiItemR(col, ptr, "input_type_factor", DEFAULT_FLAGS, IFACE_("Factor"), ICON_NONE);
- uiItemR(col, ptr, "input_type_a", DEFAULT_FLAGS, IFACE_("A"), ICON_NONE);
- uiItemR(col, ptr, "input_type_b", DEFAULT_FLAGS, IFACE_("B"), ICON_NONE);
-}
-
-static void node_geometry_buts_attribute_point_distribute(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "distribute_method", DEFAULT_FLAGS, "", ICON_NONE);
-}
-
-static void node_geometry_buts_attribute_color_ramp(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiTemplateColorRamp(layout, ptr, "color_ramp", 0);
-}
-
-static void node_geometry_buts_point_rotate(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- NodeGeometryRotatePoints *storage = (NodeGeometryRotatePoints *)((bNode *)ptr->data)->storage;
-
- uiItemR(layout, ptr, "type", DEFAULT_FLAGS | UI_ITEM_R_EXPAND, NULL, ICON_NONE);
- uiItemR(layout, ptr, "space", DEFAULT_FLAGS | UI_ITEM_R_EXPAND, NULL, ICON_NONE);
-
- uiLayout *col = uiLayoutColumn(layout, false);
- if (storage->type == GEO_NODE_POINT_ROTATE_TYPE_AXIS_ANGLE) {
- uiItemR(col, ptr, "input_type_axis", DEFAULT_FLAGS, IFACE_("Axis"), ICON_NONE);
- uiItemR(col, ptr, "input_type_angle", DEFAULT_FLAGS, IFACE_("Angle"), ICON_NONE);
- }
- else {
- uiItemR(col, ptr, "input_type_rotation", DEFAULT_FLAGS, IFACE_("Rotation"), ICON_NONE);
- }
-}
-
-static void node_geometry_buts_align_rotation_to_vector(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "axis", DEFAULT_FLAGS | UI_ITEM_R_EXPAND, NULL, ICON_NONE);
- uiItemR(layout, ptr, "pivot_axis", DEFAULT_FLAGS, IFACE_("Pivot"), ICON_NONE);
- uiLayout *col = uiLayoutColumn(layout, false);
- uiItemR(col, ptr, "input_type_factor", DEFAULT_FLAGS, IFACE_("Factor"), ICON_NONE);
- uiItemR(col, ptr, "input_type_vector", DEFAULT_FLAGS, IFACE_("Vector"), ICON_NONE);
-}
-static void node_geometry_buts_point_translate(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "input_type", DEFAULT_FLAGS, IFACE_("Type"), ICON_NONE);
-}
-
-static void node_geometry_buts_point_scale(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "input_type", DEFAULT_FLAGS, IFACE_("Type"), ICON_NONE);
-}
-
-static void node_geometry_buts_object_info(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "transform_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
-}
-
-static void node_geometry_buts_attribute_sample_texture(uiLayout *layout,
- bContext *C,
- PointerRNA *ptr)
-{
- uiTemplateID(layout, C, ptr, "texture", "texture.new", NULL, NULL, 0, ICON_NONE, NULL);
-}
-
-static void node_geometry_buts_points_to_volume(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiLayoutSetPropSep(layout, true);
- uiLayoutSetPropDecorate(layout, false);
- uiItemR(layout, ptr, "resolution_mode", DEFAULT_FLAGS, IFACE_("Resolution"), ICON_NONE);
- uiItemR(layout, ptr, "input_type_radius", DEFAULT_FLAGS, IFACE_("Radius"), ICON_NONE);
-}
-
-static void node_geometry_buts_collection_info(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "transform_space", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
-}
-
-static void node_geometry_buts_attribute_proximity(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "target_geometry_element", DEFAULT_FLAGS, "", ICON_NONE);
-}
-
-static void node_geometry_buts_volume_to_mesh(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiLayoutSetPropSep(layout, true);
- uiLayoutSetPropDecorate(layout, false);
- uiItemR(layout, ptr, "resolution_mode", DEFAULT_FLAGS, IFACE_("Resolution"), ICON_NONE);
-}
-
-static void node_geometry_set_butfunc(bNodeType *ntype)
-{
- switch (ntype->type) {
- case GEO_NODE_BOOLEAN:
- ntype->draw_buttons = node_geometry_buts_boolean_math;
- break;
- case GEO_NODE_SUBDIVISION_SURFACE:
- ntype->draw_buttons = node_geometry_buts_subdivision_surface;
- break;
- case GEO_NODE_TRIANGULATE:
- ntype->draw_buttons = node_geometry_buts_triangulate;
- break;
- case GEO_NODE_ATTRIBUTE_RANDOMIZE:
- ntype->draw_buttons = node_geometry_buts_random_attribute;
- break;
- case GEO_NODE_ATTRIBUTE_MATH:
- ntype->draw_buttons = node_geometry_buts_attribute_math;
- break;
- case GEO_NODE_ATTRIBUTE_COMPARE:
- ntype->draw_buttons = node_geometry_buts_attribute_compare;
- break;
- case GEO_NODE_POINT_INSTANCE:
- ntype->draw_buttons = node_geometry_buts_point_instance;
- break;
- case GEO_NODE_ATTRIBUTE_FILL:
- ntype->draw_buttons = node_geometry_buts_attribute_fill;
- break;
- case GEO_NODE_ATTRIBUTE_MIX:
- ntype->draw_buttons = node_geometry_buts_attribute_mix;
- break;
- case GEO_NODE_ATTRIBUTE_VECTOR_MATH:
- ntype->draw_buttons = node_geometry_buts_attribute_vector_math;
- break;
- case GEO_NODE_POINT_DISTRIBUTE:
- ntype->draw_buttons = node_geometry_buts_attribute_point_distribute;
- break;
- case GEO_NODE_ATTRIBUTE_COLOR_RAMP:
- ntype->draw_buttons = node_geometry_buts_attribute_color_ramp;
- break;
- case GEO_NODE_POINT_ROTATE:
- ntype->draw_buttons = node_geometry_buts_point_rotate;
- break;
- case GEO_NODE_ALIGN_ROTATION_TO_VECTOR:
- ntype->draw_buttons = node_geometry_buts_align_rotation_to_vector;
- break;
- case GEO_NODE_POINT_TRANSLATE:
- ntype->draw_buttons = node_geometry_buts_point_translate;
- break;
- case GEO_NODE_POINT_SCALE:
- ntype->draw_buttons = node_geometry_buts_point_scale;
- break;
- case GEO_NODE_OBJECT_INFO:
- ntype->draw_buttons = node_geometry_buts_object_info;
- break;
- case GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE:
- ntype->draw_buttons = node_geometry_buts_attribute_sample_texture;
- break;
- case GEO_NODE_POINTS_TO_VOLUME:
- ntype->draw_buttons = node_geometry_buts_points_to_volume;
- break;
- case GEO_NODE_COLLECTION_INFO:
- ntype->draw_buttons = node_geometry_buts_collection_info;
- break;
- case GEO_NODE_ATTRIBUTE_PROXIMITY:
- ntype->draw_buttons = node_geometry_buts_attribute_proximity;
- break;
- case GEO_NODE_VOLUME_TO_MESH:
- ntype->draw_buttons = node_geometry_buts_volume_to_mesh;
- break;
- }
-}
-
-/* ****************** BUTTON CALLBACKS FOR FUNCTION NODES ***************** */
-
-static void node_function_buts_boolean_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
-}
-
-static void node_function_buts_float_compare(uiLayout *layout,
- bContext *UNUSED(C),
- PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
-}
-
-static void node_function_buts_switch(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "data_type", DEFAULT_FLAGS, "", ICON_NONE);
-}
-
-static void node_function_buts_input_vector(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- uiLayout *col = uiLayoutColumn(layout, true);
- uiItemR(col, ptr, "vector", UI_ITEM_R_EXPAND, "", ICON_NONE);
-}
-
-static void node_function_set_butfunc(bNodeType *ntype)
-{
- switch (ntype->type) {
- case FN_NODE_BOOLEAN_MATH:
- ntype->draw_buttons = node_function_buts_boolean_math;
- break;
- case FN_NODE_FLOAT_COMPARE:
- ntype->draw_buttons = node_function_buts_float_compare;
- break;
- case FN_NODE_SWITCH:
- ntype->draw_buttons = node_function_buts_switch;
- break;
- case FN_NODE_INPUT_VECTOR:
- ntype->draw_buttons = node_function_buts_input_vector;
- break;
- }
-}
-
/* ****** init draw callbacks for all tree types, only called in usiblender.c, once ************ */
static void node_property_update_default(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
@@ -3612,8 +3225,6 @@ void ED_node_init_butfuncs(void)
ntype->draw_nodetype_prepare = node_update_default;
ntype->select_area_func = node_select_area_default;
ntype->tweak_area_func = node_tweak_area_default;
- ntype->draw_buttons = NULL;
- ntype->draw_buttons_ex = NULL;
ntype->resize_area_func = node_resize_area_default;
node_common_set_butfunc(ntype);
@@ -3621,8 +3232,6 @@ void ED_node_init_butfuncs(void)
node_composit_set_butfunc(ntype);
node_shader_set_butfunc(ntype);
node_texture_set_butfunc(ntype);
- node_geometry_set_butfunc(ntype);
- node_function_set_butfunc(ntype);
/* define update callbacks for socket properties */
node_template_properties_update(ntype);