Blender  V3.3
COM_BoxMaskNode.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_BoxMaskNode.h"
5 #include "COM_BoxMaskOperation.h"
6 
7 #include "COM_ScaleOperation.h"
9 
10 namespace blender::compositor {
11 
12 BoxMaskNode::BoxMaskNode(bNode *editor_node) : Node(editor_node)
13 {
14  /* pass */
15 }
16 
18  const CompositorContext &context) const
19 {
20  NodeInput *input_socket = this->get_input_socket(0);
21  NodeOutput *output_socket = this->get_output_socket(0);
22 
23  BoxMaskOperation *operation;
24  operation = new BoxMaskOperation();
25  operation->set_data((NodeBoxMask *)this->get_bnode()->storage);
26  operation->set_mask_type(this->get_bnode()->custom1);
27  converter.add_operation(operation);
28 
29  if (input_socket->is_linked()) {
30  converter.map_input_socket(input_socket, operation->get_input_socket(0));
31  converter.map_output_socket(output_socket, operation->get_output_socket());
32  }
33  else {
34  /* Value operation to produce original transparent image */
35  SetValueOperation *value_operation = new SetValueOperation();
36  value_operation->set_value(0.0f);
37  converter.add_operation(value_operation);
38 
39  /* Scale that image up to render resolution */
40  const RenderData *rd = context.get_render_data();
41  const float render_size_factor = context.get_render_percentage_as_factor();
42  ScaleFixedSizeOperation *scale_operation = new ScaleFixedSizeOperation();
43 
44  scale_operation->set_is_aspect(false);
45  scale_operation->set_is_crop(false);
46  scale_operation->set_offset(0.0f, 0.0f);
47  scale_operation->set_new_width(rd->xsch * render_size_factor);
48  scale_operation->set_new_height(rd->ysch * render_size_factor);
50  converter.add_operation(scale_operation);
51 
52  converter.add_link(value_operation->get_output_socket(0),
53  scale_operation->get_input_socket(0));
54  converter.add_link(scale_operation->get_output_socket(0), operation->get_input_socket(0));
55  converter.map_output_socket(output_socket, operation->get_output_socket(0));
56  }
57 
58  converter.map_input_socket(get_input_socket(1), operation->get_input_socket(1));
59 }
60 
61 } // namespace blender::compositor
void convert_to_operations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
Overall context of the compositor.
void add_link(NodeOperationOutput *from, NodeOperationInput *to)
void map_output_socket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void add_operation(NodeOperation *operation)
void map_input_socket(NodeInput *node_socket, NodeOperationInput *operation_socket)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:190
void set_resize_mode(ResizeMode resize_mode)
NodeOperationOutput * get_output_socket(unsigned int index=0)
NodeOperationInput * get_input_socket(unsigned int index)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:238
NodeOutput * get_output_socket(unsigned int index=0) const
Definition: COM_Node.cc:84
bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:64
NodeInput * get_input_socket(unsigned int index) const
Definition: COM_Node.cc:89