diff options
author | Julian Eisel <julian@blender.org> | 2021-09-15 23:34:20 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-09-15 23:34:20 +0300 |
commit | da9be470b546928e3e4320003b333d0aad1c9073 (patch) | |
tree | 3879b762dc226f0b6a55d8e5bdafcfba7dc0c3b9 /source/blender/nodes/NOD_socket_declarations.hh | |
parent | ad7588600c35423b2908756afd694331f08aeb20 (diff) | |
parent | 28bd74c18650a8362bc791df602097967ff5efdf (diff) |
Merge branch 'master' into temp-cocoa-scroll-acceleration-fixtemp-cocoa-scroll-acceleration-fix
Diffstat (limited to 'source/blender/nodes/NOD_socket_declarations.hh')
-rw-r--r-- | source/blender/nodes/NOD_socket_declarations.hh | 220 |
1 files changed, 116 insertions, 104 deletions
diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh index 11352111356..3d0cfdb5d5d 100644 --- a/source/blender/nodes/NOD_socket_declarations.hh +++ b/source/blender/nodes/NOD_socket_declarations.hh @@ -25,6 +25,8 @@ namespace blender::nodes::decl { +class FloatBuilder; + class Float : public SocketDeclaration { private: float default_value_ = 0.0f; @@ -32,36 +34,45 @@ class Float : public SocketDeclaration { float soft_max_value_ = FLT_MAX; PropertySubType subtype_ = PROP_NONE; + friend FloatBuilder; + public: - Float &min(const float value) + using Builder = FloatBuilder; + + bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; + bool matches(const bNodeSocket &socket) const override; + bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override; +}; + +class FloatBuilder : public SocketDeclarationBuilder<Float> { + public: + FloatBuilder &min(const float value) { - soft_min_value_ = value; + decl_->soft_min_value_ = value; return *this; } - Float &max(const float value) + FloatBuilder &max(const float value) { - soft_max_value_ = value; + decl_->soft_max_value_ = value; return *this; } - Float &default_value(const float value) + FloatBuilder &default_value(const float value) { - default_value_ = value; + decl_->default_value_ = value; return *this; } - Float &subtype(PropertySubType subtype) + FloatBuilder &subtype(PropertySubType subtype) { - subtype_ = subtype; + decl_->subtype_ = subtype; return *this; } - - bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; - bool matches(const bNodeSocket &socket) const override; - bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override; }; +class IntBuilder; + class Int : public SocketDeclaration { private: int default_value_ = 0; @@ -69,36 +80,45 @@ class Int : public SocketDeclaration { int soft_max_value_ = INT32_MAX; PropertySubType subtype_ = PROP_NONE; + friend IntBuilder; + public: - Int &min(const int value) + using Builder = IntBuilder; + + bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; + bool matches(const bNodeSocket &socket) const override; + bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override; +}; + +class IntBuilder : public SocketDeclarationBuilder<Int> { + public: + IntBuilder &min(const int value) { - soft_min_value_ = value; + decl_->soft_min_value_ = value; return *this; } - Int &max(const int value) + IntBuilder &max(const int value) { - soft_max_value_ = value; + decl_->soft_max_value_ = value; return *this; } - Int &default_value(const int value) + IntBuilder &default_value(const int value) { - default_value_ = value; + decl_->default_value_ = value; return *this; } - Int &subtype(PropertySubType subtype) + IntBuilder &subtype(PropertySubType subtype) { - subtype_ = subtype; + decl_->subtype_ = subtype; return *this; } - - bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; - bool matches(const bNodeSocket &socket) const override; - bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override; }; +class VectorBuilder; + class Vector : public SocketDeclaration { private: float3 default_value_ = {0, 0, 0}; @@ -106,160 +126,152 @@ class Vector : public SocketDeclaration { float soft_max_value_ = FLT_MAX; PropertySubType subtype_ = PROP_NONE; + friend VectorBuilder; + + public: + using Builder = VectorBuilder; + + bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; + bool matches(const bNodeSocket &socket) const override; + bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override; +}; + +class VectorBuilder : public SocketDeclarationBuilder<Vector> { public: - Vector &default_value(const float3 value) + VectorBuilder &default_value(const float3 value) { - default_value_ = value; + decl_->default_value_ = value; return *this; } - Vector &subtype(PropertySubType subtype) + VectorBuilder &subtype(PropertySubType subtype) { - subtype_ = subtype; + decl_->subtype_ = subtype; return *this; } - Vector &min(const float min) + VectorBuilder &min(const float min) { - soft_min_value_ = min; + decl_->soft_min_value_ = min; return *this; } - Vector &max(const float max) + VectorBuilder &max(const float max) { - soft_max_value_ = max; + decl_->soft_max_value_ = max; return *this; } - - bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; - bool matches(const bNodeSocket &socket) const override; - bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override; }; +class BoolBuilder; + class Bool : public SocketDeclaration { private: bool default_value_ = false; + friend BoolBuilder; public: - Bool &default_value(const bool value) - { - default_value_ = value; - return *this; - } + using Builder = BoolBuilder; bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; bool matches(const bNodeSocket &socket) const override; }; +class BoolBuilder : public SocketDeclarationBuilder<Bool> { + public: + BoolBuilder &default_value(const bool value) + { + decl_->default_value_ = value; + return *this; + } +}; + +class ColorBuilder; + class Color : public SocketDeclaration { private: ColorGeometry4f default_value_; + friend ColorBuilder; + public: - Color &default_value(const ColorGeometry4f value) - { - default_value_ = value; - return *this; - } + using Builder = ColorBuilder; bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; bool matches(const bNodeSocket &socket) const override; }; +class ColorBuilder : public SocketDeclarationBuilder<Color> { + public: + ColorBuilder &default_value(const ColorGeometry4f value) + { + decl_->default_value_ = value; + return *this; + } +}; + class String : public SocketDeclaration { public: + using Builder = SocketDeclarationBuilder<String>; + bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; bool matches(const bNodeSocket &socket) const override; }; -namespace detail { -struct CommonIDSocketData { - const char *idname; - bool hide_label = false; -}; - -bNodeSocket &build_id_socket(bNodeTree &ntree, - bNode &node, - eNodeSocketInOut in_out, - const CommonIDSocketData &data, - StringRefNull name, - StringRefNull identifier); -bool matches_id_socket(const bNodeSocket &socket, - const CommonIDSocketData &data, - StringRefNull name, - StringRefNull identifier); - -template<typename Subtype> class IDSocketDeclaration : public SocketDeclaration { +class IDSocketDeclaration : public SocketDeclaration { private: - CommonIDSocketData data_; + const char *idname_; public: - IDSocketDeclaration(const char *idname) : data_({idname}) - { - } - - Subtype &hide_label(bool value) - { - data_.hide_label = value; - return *(Subtype *)this; - } - - bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override - { - return build_id_socket(ntree, node, in_out, data_, name_, identifier_); - } - - bool matches(const bNodeSocket &socket) const override + IDSocketDeclaration(const char *idname) : idname_(idname) { - return matches_id_socket(socket, data_, name_, identifier_); } - bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override - { - if (StringRef(socket.idname) != data_.idname) { - return this->build(ntree, node, (eNodeSocketInOut)socket.in_out); - } - if (data_.hide_label) { - socket.flag |= SOCK_HIDE_LABEL; - } - else { - socket.flag &= ~SOCK_HIDE_LABEL; - } - return socket; - } + bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; + bool matches(const bNodeSocket &socket) const override; + bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override; }; -} // namespace detail -class Object : public detail::IDSocketDeclaration<Object> { +class Object : public IDSocketDeclaration { public: - Object() : detail::IDSocketDeclaration<Object>("NodeSocketObject") + using Builder = SocketDeclarationBuilder<Object>; + + Object() : IDSocketDeclaration("NodeSocketObject") { } }; -class Material : public detail::IDSocketDeclaration<Material> { +class Material : public IDSocketDeclaration { public: - Material() : detail::IDSocketDeclaration<Material>("NodeSocketMaterial") + using Builder = SocketDeclarationBuilder<Material>; + + Material() : IDSocketDeclaration("NodeSocketMaterial") { } }; -class Collection : public detail::IDSocketDeclaration<Collection> { +class Collection : public IDSocketDeclaration { public: - Collection() : detail::IDSocketDeclaration<Collection>("NodeSocketCollection") + using Builder = SocketDeclarationBuilder<Collection>; + + Collection() : IDSocketDeclaration("NodeSocketCollection") { } }; -class Texture : public detail::IDSocketDeclaration<Texture> { +class Texture : public IDSocketDeclaration { public: - Texture() : detail::IDSocketDeclaration<Texture>("NodeSocketTexture") + using Builder = SocketDeclarationBuilder<Texture>; + + Texture() : IDSocketDeclaration("NodeSocketTexture") { } }; class Geometry : public SocketDeclaration { public: + using Builder = SocketDeclarationBuilder<Geometry>; + bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override; bool matches(const bNodeSocket &socket) const override; }; |