Blender V4.3
node_shader_script.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "node_shader_util.hh"
10
11#include "RNA_access.hh"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
17
19{
20 uiLayout *row;
21
22 row = uiLayoutRow(layout, false);
23 uiItemR(row, ptr, "mode", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
24
25 row = uiLayoutRow(layout, true);
26
27 if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_INTERNAL) {
28 uiItemR(row, ptr, "script", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
29 }
30 else {
31 uiItemR(row, ptr, "filepath", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
32 }
33
34 uiItemO(row, "", ICON_FILE_REFRESH, "node.shader_script_update");
35}
36
38{
39 uiItemS(layout);
40
41 node_shader_buts_script(layout, C, ptr);
42
43#if 0 /* not implemented yet */
44 if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_EXTERNAL) {
45 uiItemR(layout, ptr, "use_auto_update", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
46 }
47#endif
48}
49
50static void init(bNodeTree * /*ntree*/, bNode *node)
51{
52 NodeShaderScript *nss = MEM_cnew<NodeShaderScript>("shader script node");
53 node->storage = nss;
54}
55
56static void node_free_script(bNode *node)
57{
58 NodeShaderScript *nss = static_cast<NodeShaderScript *>(node->storage);
59
60 if (nss) {
61 if (nss->bytecode) {
62 MEM_freeN(nss->bytecode);
63 }
64
65 MEM_freeN(nss);
66 }
67}
68
69static void node_copy_script(bNodeTree * /*dst_ntree*/, bNode *dest_node, const bNode *src_node)
70{
71 NodeShaderScript *src_nss = static_cast<NodeShaderScript *>(src_node->storage);
72 NodeShaderScript *dest_nss = static_cast<NodeShaderScript *>(MEM_dupallocN(src_nss));
73
74 if (src_nss->bytecode) {
75 dest_nss->bytecode = static_cast<char *>(MEM_dupallocN(src_nss->bytecode));
76 }
77
78 dest_node->storage = dest_nss;
79}
80
81} // namespace blender::nodes::node_shader_script_cc
82
84{
85 namespace file_ns = blender::nodes::node_shader_script_cc;
86
87 static blender::bke::bNodeType ntype;
88
90 ntype.draw_buttons = file_ns::node_shader_buts_script;
91 ntype.draw_buttons_ex = file_ns::node_shader_buts_script_ex;
92 ntype.initfunc = file_ns::init;
94 &ntype, "NodeShaderScript", file_ns::node_free_script, file_ns::node_copy_script);
95
97}
#define SH_NODE_SCRIPT
Definition BKE_node.hh:954
#define NODE_CLASS_SCRIPT
Definition BKE_node.hh:415
@ NODE_SCRIPT_INTERNAL
@ NODE_SCRIPT_EXTERNAL
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemS(uiLayout *layout)
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
void init()
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
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_copy_script(bNodeTree *, bNode *dest_node, const bNode *src_node)
static void node_shader_buts_script_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void node_shader_buts_script(uiLayout *layout, bContext *, PointerRNA *ptr)
void register_node_type_sh_script()
void sh_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void * storage
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* draw_buttons_ex)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:240
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
PointerRNA * ptr
Definition wm_files.cc:4126