Blender V5.3
node_fn_input_menu.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6#include "node_shader_util.hh"
7
9#include "UI_resources.hh"
10
11#include "BKE_node_runtime.hh"
12
14
16{
17 b.add_output<decl::Menu>("Menu"_ustr).custom_draw([](CustomSocketDrawParams &params) {
19 ui::Layout &row = params.layout.row(true);
20
21 const bNodeSocketValueMenu *default_value =
22 params.node.output_socket(0).default_value_typed<bNodeSocketValueMenu>();
23 BLI_assert(default_value);
24
25 if (default_value->enum_items) {
26 if (default_value->enum_items->items.is_empty()) {
27 row.label(IFACE_("No Items"), ICON_NONE);
28 }
29 else {
30 row.prop(&params.node_ptr, "value", UI_ITEM_NONE, "", ICON_NONE);
31 }
32 return;
33 }
34
35 if (default_value->has_conflict()) {
36 row.label(IFACE_("Menu Error"), ICON_STATUS_ERROR);
37 }
38 else {
39 row.label(IFACE_("Menu Undefined"), ICON_QUESTION);
40 }
41 });
42}
43
45{
46 const bNode &bnode = builder.node();
47 const NodeInputMenu &node_storage = *static_cast<const NodeInputMenu *>(bnode.storage);
48 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<MenuValue>>(
49 MenuValue(node_storage.value));
50}
51
52static void node_init(bNodeTree * /*tree*/, bNode *node)
53{
54 NodeInputMenu *data = MEM_new<NodeInputMenu>(__func__);
55 node->storage = data;
56}
57
58static void node_register()
59{
60 static bke::bNodeType ntype;
61
62 common_node_type_base(&ntype, "FunctionNodeInputMenu"_ustr);
63 ntype.ui_name = "Menu";
64 ntype.ui_description = "Provide a menu value that can be connected to other nodes in the tree";
66 ntype.declare = node_declare;
67 ntype.initfunc = node_init;
72}
74
75} // namespace blender::nodes::node_fn_input_menu_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define IFACE_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define UI_ITEM_NONE
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_declare(NodeDeclarationBuilder &b)
static void node_init(bNodeTree *, bNode *node)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BMesh const char void * data
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const bke::RuntimeNodeEnumItems * enum_items
Vector< RuntimeNodeEnumItem > items
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
NodeDeclareFunction declare
Definition BKE_node.hh:393
void alignment_set(LayoutAlign alignment)
void label(StringRef name, int icon)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & row(bool align)