Blender V4.3
node_fn_input_string.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "UI_interface.hh"
8#include "UI_resources.hh"
9
11
13{
14 b.is_function_node();
15 b.add_output<decl::String>("String");
16}
17
18static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
19{
20 uiItemR(layout, ptr, "string", UI_ITEM_NONE, "", ICON_NONE);
21}
22
24{
25 const bNode &bnode = builder.node();
26 NodeInputString *node_storage = static_cast<NodeInputString *>(bnode.storage);
27 std::string string = std::string((node_storage->string) ? node_storage->string : "");
29}
30
31static void node_init(bNodeTree * /*tree*/, bNode *node)
32{
33 node->storage = MEM_callocN(sizeof(NodeInputString), __func__);
34}
35
36static void node_storage_free(bNode *node)
37{
38 NodeInputString *storage = (NodeInputString *)node->storage;
39 if (storage == nullptr) {
40 return;
41 }
42 if (storage->string != nullptr) {
43 MEM_freeN(storage->string);
44 }
45 MEM_freeN(storage);
46}
47
48static void node_storage_copy(bNodeTree * /*dst_ntree*/, bNode *dest_node, const bNode *src_node)
49{
50 NodeInputString *source_storage = (NodeInputString *)src_node->storage;
51 NodeInputString *destination_storage = (NodeInputString *)MEM_dupallocN(source_storage);
52
53 if (source_storage->string) {
54 destination_storage->string = (char *)MEM_dupallocN(source_storage->string);
55 }
56
57 dest_node->storage = destination_storage;
58}
59
60static void node_register()
61{
62 static blender::bke::bNodeType ntype;
63
64 fn_node_type_base(&ntype, FN_NODE_INPUT_STRING, "String", NODE_CLASS_INPUT);
65 ntype.declare = node_declare;
66 ntype.initfunc = node_init;
71}
73
74} // namespace blender::nodes::node_fn_input_string_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define UI_ITEM_NONE
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
local_group_size(16, 16) .push_constant(Type b
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
void *(* MEM_dupallocN)(const void *vmemh)
Definition mallocn.cc:39
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_init(bNodeTree *, bNode *node)
static void node_storage_copy(bNodeTree *, bNode *dest_node, const bNode *src_node)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_declare(NodeDeclarationBuilder &b)
void fn_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void * storage
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:336
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126