Blender  V2.93
node_fn_boolean_math.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #include "BLI_listbase.h"
18 #include "BLI_string.h"
19 
20 #include "RNA_enum_types.h"
21 
22 #include "UI_interface.h"
23 #include "UI_resources.h"
24 
25 #include "node_function_util.hh"
26 
28  {SOCK_BOOLEAN, N_("Boolean")},
29  {SOCK_BOOLEAN, N_("Boolean")},
30  {-1, ""},
31 };
32 
34  {SOCK_BOOLEAN, N_("Boolean")},
35  {-1, ""},
36 };
37 
39 {
40  uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
41 }
42 
44 {
45  bNodeSocket *sockB = (bNodeSocket *)BLI_findlink(&node->inputs, 1);
46 
49 }
50 
51 static void node_boolean_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
52 {
53  const char *name;
54  bool enum_label = RNA_enum_name(rna_enum_node_boolean_math_items, node->custom1, &name);
55  if (!enum_label) {
56  name = "Unknown";
57  }
58  BLI_strncpy(label, IFACE_(name), maxlen);
59 }
60 
62 {
64  "And", [](bool a, bool b) { return a && b; }};
66  "Or", [](bool a, bool b) { return a || b; }};
67  static blender::fn::CustomMF_SI_SO<bool, bool> not_fn{"Not", [](bool a) { return !a; }};
68 
69  switch (bnode.custom1) {
71  return and_fn;
73  return or_fn;
75  return not_fn;
76  }
77 
78  BLI_assert(false);
80 }
81 
83 {
85  builder.set_matching_fn(fn);
86 }
87 
89 {
90  static bNodeType ntype;
91 
92  fn_node_type_base(&ntype, FN_NODE_BOOLEAN_MATH, "Boolean Math", NODE_CLASS_CONVERTOR, 0);
98  nodeRegisterType(&ntype);
99 }
void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3726
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4623
#define NODE_CLASS_CONVERTOR
Definition: BKE_node.h:341
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
void node_type_label(struct bNodeType *ntype, void(*labelfunc)(struct bNodeTree *ntree, struct bNode *, char *label, int maxlen))
#define BLI_assert(a)
Definition: BLI_assert.h:58
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
#define UNUSED(x)
#define ELEM(...)
#define IFACE_(msgid)
#define N_(msgid)
@ NODE_BOOLEAN_MATH_AND
@ NODE_BOOLEAN_MATH_NOT
@ NODE_BOOLEAN_MATH_OR
@ SOCK_BOOLEAN
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC FN_NODE_BOOLEAN_MATH
#define C
Definition: RandGen.cpp:39
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void set_matching_fn(const fn::MultiFunction &function)
OperationNode * node
const char * label
bNodeTree * ntree
static unsigned a[3]
Definition: RandGen.cpp:92
const MultiFunction & dummy_multi_function
static void node_boolean_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
static void node_boolean_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
static bNodeSocketTemplate fn_node_boolean_math_in[]
void register_node_type_fn_boolean_math()
static bNodeSocketTemplate fn_node_boolean_math_out[]
static const blender::fn::MultiFunction & get_multi_function(bNode &bnode)
static void fn_node_boolean_math_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_boolean_math_update(bNodeTree *UNUSED(ntree), bNode *node)
void fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
Definition: rna_access.c:1854
const EnumPropertyItem rna_enum_node_boolean_math_items[]
Definition: rna_nodetree.c:266
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
NodeExpandInMFNetworkFunction expand_in_mf_network
Definition: BKE_node.h:324
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:253
short custom1
PointerRNA * ptr
Definition: wm_files.c:3157