Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/function/nodes/node_fn_value_to_string.cc
| Show All 11 Lines | |||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| #include "node_function_util.hh" | #include "node_function_util.hh" | ||||
| #include <iomanip> | #include <iomanip> | ||||
| namespace blender::nodes { | namespace blender::nodes::node_fn_value_to_string_cc { | ||||
| static void fn_node_value_to_string_declare(NodeDeclarationBuilder &b) | static void fn_node_value_to_string_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Float>(N_("Value")); | b.add_input<decl::Float>(N_("Value")); | ||||
| b.add_input<decl::Int>(N_("Decimals")).min(0); | b.add_input<decl::Int>(N_("Decimals")).min(0); | ||||
| b.add_output<decl::String>(N_("String")); | b.add_output<decl::String>(N_("String")); | ||||
| }; | }; | ||||
| static void fn_node_value_to_string_build_multi_function(NodeMultiFunctionBuilder &builder) | static void fn_node_value_to_string_build_multi_function(NodeMultiFunctionBuilder &builder) | ||||
| { | { | ||||
| static fn::CustomMF_SI_SI_SO<float, int, std::string> to_str_fn{ | static fn::CustomMF_SI_SI_SO<float, int, std::string> to_str_fn{ | ||||
| "Value To String", [](float a, int b) { | "Value To String", [](float a, int b) { | ||||
| std::stringstream stream; | std::stringstream stream; | ||||
| stream << std::fixed << std::setprecision(std::max(0, b)) << a; | stream << std::fixed << std::setprecision(std::max(0, b)) << a; | ||||
| return stream.str(); | return stream.str(); | ||||
| }}; | }}; | ||||
| builder.set_matching_fn(&to_str_fn); | builder.set_matching_fn(&to_str_fn); | ||||
| } | } | ||||
| } // namespace blender::nodes | } // namespace blender::nodes::node_fn_value_to_string_cc | ||||
| void register_node_type_fn_value_to_string() | void register_node_type_fn_value_to_string() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_fn_value_to_string_cc; | |||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| fn_node_type_base(&ntype, FN_NODE_VALUE_TO_STRING, "Value to String", NODE_CLASS_CONVERTER, 0); | fn_node_type_base(&ntype, FN_NODE_VALUE_TO_STRING, "Value to String", NODE_CLASS_CONVERTER); | ||||
| ntype.declare = blender::nodes::fn_node_value_to_string_declare; | ntype.declare = file_ns::fn_node_value_to_string_declare; | ||||
| ntype.build_multi_function = blender::nodes::fn_node_value_to_string_build_multi_function; | ntype.build_multi_function = file_ns::fn_node_value_to_string_build_multi_function; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||