Blender V4.5
node_composite_translate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_assert.h"
10#include "BLI_math_matrix.hh"
11
12#include "UI_interface.hh"
13#include "UI_resources.hh"
14
15#include "COM_node_operation.hh"
16#include "COM_utilities.hh"
17
19
20/* **************** Translate ******************** */
21
23
25
27{
28 b.add_input<decl::Color>("Image")
29 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
30 .compositor_domain_priority(0)
31 .compositor_realization_mode(CompositorInputRealizationMode::None);
32 b.add_input<decl::Float>("X")
33 .default_value(0.0f)
34 .min(-10000.0f)
35 .max(10000.0f)
36 .compositor_expects_single_value();
37 b.add_input<decl::Float>("Y")
38 .default_value(0.0f)
39 .min(-10000.0f)
40 .max(10000.0f)
41 .compositor_expects_single_value();
42 b.add_output<decl::Color>("Image");
43}
44
45static void node_composit_init_translate(bNodeTree * /*ntree*/, bNode *node)
46{
48 node->storage = data;
49}
50
52{
53 layout->prop(ptr, "interpolation", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
54 layout->prop(ptr, "wrap_axis", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
55}
56
57using namespace blender::compositor;
58
60 public:
62
63 void execute() override
64 {
65 const Result &input = this->get_input("Image");
66
67 float x = this->get_input("X").get_single_value_default(0.0f);
68 float y = this->get_input("Y").get_single_value_default(0.0f);
69 const float2 translation = float2(x, y);
70
71 Result &output = this->get_result("Image");
72 output.share_data(input);
73 output.transform(math::from_location<float3x3>(translation));
74 output.get_realization_options().interpolation = this->get_interpolation();
77 }
78
93
95 {
96 return ELEM(node_storage(bnode()).wrap_axis,
99 }
100
102 {
103 return ELEM(node_storage(bnode()).wrap_axis,
106 }
107};
108
110{
111 return new TranslateOperation(context, node);
112}
113
114} // namespace blender::nodes::node_composite_translate_cc
115
117{
119
120 static blender::bke::bNodeType ntype;
121
122 cmp_node_type_base(&ntype, "CompositorNodeTranslate", CMP_NODE_TRANSLATE);
123 ntype.ui_name = "Translate";
124 ntype.ui_description = "Offset an image";
125 ntype.enum_name_legacy = "TRANSLATE";
127 ntype.declare = file_ns::cmp_node_translate_declare;
128 ntype.draw_buttons = file_ns::node_composit_buts_translate;
129 ntype.initfunc = file_ns::node_composit_init_translate;
131 ntype, "NodeTranslateData", node_free_standard_storage, node_copy_standard_storage);
132 ntype.get_compositor_operation = file_ns::get_compositor_operation;
133
135}
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:441
#define CMP_NODE_TRANSLATE
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define ELEM(...)
@ CMP_NODE_INTERPOLATION_NEAREST
@ CMP_NODE_INTERPOLATION_BILINEAR
@ CMP_NODE_INTERPOLATION_BICUBIC
@ CMP_NODE_TRANSLATE_REPEAT_AXIS_XY
@ CMP_NODE_TRANSLATE_REPEAT_AXIS_Y
@ CMP_NODE_TRANSLATE_REPEAT_AXIS_X
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
BMesh const char void * data
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:39
Result & get_input(StringRef identifier) const
Definition operation.cc:138
void share_data(const Result &source)
Definition result.cc:401
RealizationOptions & get_realization_options()
Definition result.cc:494
T get_single_value_default(const T &default_value) const
#define input
#define output
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
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:5603
MatT from_location(const typename MatT::loc_type &location)
static void node_composit_init_translate(bNodeTree *, bNode *node)
static void node_composit_buts_translate(uiLayout *layout, bContext *, PointerRNA *ptr)
static void cmp_node_translate_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
VecBase< float, 2 > float2
static void register_node_type_cmp_translate()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
#define min(a, b)
Definition sort.cc:36
void * storage
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:336
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:355
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
max
Definition text_draw.cc:251
PointerRNA * ptr
Definition wm_files.cc:4226