Cleanup: Nodes: Store node group idname in tree type

There was already a utility to retrieve the correct node group idname
from the context, `node_group_idname`, but often it's clearer to
use lower-level arguments, or the context isn't accessible.
Storing the group idname in the tree type makes it accessible
without rewriting it elsewhere.
This commit is contained in:
Hans Goudey 2022-07-28 16:34:17 -05:00
parent 4757a5ad33
commit 3d91a853b2
6 changed files with 16 additions and 4 deletions

View File

@ -374,6 +374,9 @@ typedef struct bNodeTreeType {
int type; /* type identifier */
char idname[64]; /* identifier name */
/* The ID name of group nodes for this type. */
char group_idname[64];
char ui_name[64];
char ui_description[256];
int ui_icon;

View File

@ -44,7 +44,12 @@
#include "UI_resources.h"
#include "NOD_common.h"
#include "NOD_composite.h"
#include "NOD_geometry.h"
#include "NOD_shader.h"
#include "NOD_socket.h"
#include "NOD_texture.h"
#include "node_intern.hh" /* own include */
namespace blender::ed::space_node {
@ -99,16 +104,16 @@ const char *node_group_idname(bContext *C)
SpaceNode *snode = CTX_wm_space_node(C);
if (ED_node_is_shader(snode)) {
return "ShaderNodeGroup";
return ntreeType_Shader->group_idname;
}
if (ED_node_is_compositor(snode)) {
return "CompositorNodeGroup";
return ntreeType_Composite->group_idname;
}
if (ED_node_is_texture(snode)) {
return "TextureNodeGroup";
return ntreeType_Texture->group_idname;
}
if (ED_node_is_geometry(snode)) {
return "GeometryNodeGroup";
return ntreeType_Geometry->group_idname;
}
return "";

View File

@ -183,6 +183,7 @@ void register_node_tree_type_cmp()
tt->type = NTREE_COMPOSIT;
strcpy(tt->idname, "CompositorNodeTree");
strcpy(tt->group_idname, "CompositorNodeGroup");
strcpy(tt->ui_name, N_("Compositor"));
tt->ui_icon = ICON_NODE_COMPOSITING;
strcpy(tt->ui_description, N_("Compositing nodes"));

View File

@ -109,6 +109,7 @@ void register_node_tree_type_geo()
MEM_callocN(sizeof(bNodeTreeType), "geometry node tree type"));
tt->type = NTREE_GEOMETRY;
strcpy(tt->idname, "GeometryNodeTree");
strcpy(tt->group_idname, "GeometryNodeGroup");
strcpy(tt->ui_name, N_("Geometry Node Editor"));
tt->ui_icon = ICON_GEOMETRY_NODES;
strcpy(tt->ui_description, N_("Geometry nodes"));

View File

@ -166,6 +166,7 @@ void register_node_tree_type_sh()
tt->type = NTREE_SHADER;
strcpy(tt->idname, "ShaderNodeTree");
strcpy(tt->group_idname, "ShaderNodeGroup");
strcpy(tt->ui_name, N_("Shader Editor"));
tt->ui_icon = ICON_NODE_MATERIAL;
strcpy(tt->ui_description, N_("Shader nodes"));

View File

@ -140,6 +140,7 @@ void register_node_tree_type_tex(void)
tt->type = NTREE_TEXTURE;
strcpy(tt->idname, "TextureNodeTree");
strcpy(tt->group_idname, "TextureNodeGroup");
strcpy(tt->ui_name, N_("Texture Node Editor"));
tt->ui_icon = ICON_NODE_TEXTURE; /* Defined in `drawnode.c`. */
strcpy(tt->ui_description, N_("Texture nodes"));