Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc
| Show All 26 Lines | |||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "node_geometry_util.hh" | #include "node_geometry_util.hh" | ||||
| namespace blender::nodes::node_geo_string_to_curves_cc { | namespace blender::nodes::node_geo_string_to_curves_cc { | ||||
| static void geo_node_string_to_curves_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::String>(N_("String")); | b.add_input<decl::String>(N_("String")); | ||||
| b.add_input<decl::Float>(N_("Size")).default_value(1.0f).min(0.0f).subtype(PROP_DISTANCE); | b.add_input<decl::Float>(N_("Size")).default_value(1.0f).min(0.0f).subtype(PROP_DISTANCE); | ||||
| b.add_input<decl::Float>(N_("Character Spacing")) | b.add_input<decl::Float>(N_("Character Spacing")) | ||||
| .default_value(1.0f) | .default_value(1.0f) | ||||
| .min(0.0f) | .min(0.0f) | ||||
| .subtype(PROP_DISTANCE); | .subtype(PROP_DISTANCE); | ||||
| b.add_input<decl::Float>(N_("Word Spacing")) | b.add_input<decl::Float>(N_("Word Spacing")) | ||||
| Show All 11 Lines | static void node_declare(NodeDeclarationBuilder &b) | ||||
| b.add_input<decl::Float>(N_("Text Box Height")) | b.add_input<decl::Float>(N_("Text Box Height")) | ||||
| .default_value(0.0f) | .default_value(0.0f) | ||||
| .min(0.0f) | .min(0.0f) | ||||
| .subtype(PROP_DISTANCE); | .subtype(PROP_DISTANCE); | ||||
| b.add_output<decl::Geometry>(N_("Curves")); | b.add_output<decl::Geometry>(N_("Curves")); | ||||
| b.add_output<decl::String>(N_("Remainder")); | b.add_output<decl::String>(N_("Remainder")); | ||||
| } | } | ||||
| static void geo_node_string_to_curves_layout(uiLayout *layout, struct bContext *C, PointerRNA *ptr) | static void node_layout(uiLayout *layout, struct bContext *C, PointerRNA *ptr) | ||||
| { | { | ||||
| uiLayoutSetPropSep(layout, true); | uiLayoutSetPropSep(layout, true); | ||||
| uiLayoutSetPropDecorate(layout, false); | uiLayoutSetPropDecorate(layout, false); | ||||
| uiTemplateID(layout, | uiTemplateID(layout, | ||||
| C, | C, | ||||
| ptr, | ptr, | ||||
| "font", | "font", | ||||
| nullptr, | nullptr, | ||||
| "FONT_OT_open", | "FONT_OT_open", | ||||
| "FONT_OT_unlink", | "FONT_OT_unlink", | ||||
| UI_TEMPLATE_ID_FILTER_ALL, | UI_TEMPLATE_ID_FILTER_ALL, | ||||
| false, | false, | ||||
| nullptr); | nullptr); | ||||
| uiItemR(layout, ptr, "overflow", 0, "", ICON_NONE); | uiItemR(layout, ptr, "overflow", 0, "", ICON_NONE); | ||||
| uiItemR(layout, ptr, "align_x", 0, "", ICON_NONE); | uiItemR(layout, ptr, "align_x", 0, "", ICON_NONE); | ||||
| uiItemR(layout, ptr, "align_y", 0, "", ICON_NONE); | uiItemR(layout, ptr, "align_y", 0, "", ICON_NONE); | ||||
| } | } | ||||
| static void geo_node_string_to_curves_init(bNodeTree *UNUSED(ntree), bNode *node) | static void node_init(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| NodeGeometryStringToCurves *data = (NodeGeometryStringToCurves *)MEM_callocN( | NodeGeometryStringToCurves *data = (NodeGeometryStringToCurves *)MEM_callocN( | ||||
| sizeof(NodeGeometryStringToCurves), __func__); | sizeof(NodeGeometryStringToCurves), __func__); | ||||
| data->overflow = GEO_NODE_STRING_TO_CURVES_MODE_OVERFLOW; | data->overflow = GEO_NODE_STRING_TO_CURVES_MODE_OVERFLOW; | ||||
| data->align_x = GEO_NODE_STRING_TO_CURVES_ALIGN_X_LEFT; | data->align_x = GEO_NODE_STRING_TO_CURVES_ALIGN_X_LEFT; | ||||
| data->align_y = GEO_NODE_STRING_TO_CURVES_ALIGN_Y_TOP_BASELINE; | data->align_y = GEO_NODE_STRING_TO_CURVES_ALIGN_Y_TOP_BASELINE; | ||||
| node->storage = data; | node->storage = data; | ||||
| node->id = (ID *)BKE_vfont_builtin_get(); | node->id = (ID *)BKE_vfont_builtin_get(); | ||||
| } | } | ||||
| static void geo_node_string_to_curves_update(bNodeTree *ntree, bNode *node) | static void node_update(bNodeTree *ntree, bNode *node) | ||||
| { | { | ||||
| const NodeGeometryStringToCurves *storage = (const NodeGeometryStringToCurves *)node->storage; | const NodeGeometryStringToCurves *storage = (const NodeGeometryStringToCurves *)node->storage; | ||||
| const GeometryNodeStringToCurvesOverflowMode overflow = (GeometryNodeStringToCurvesOverflowMode) | const GeometryNodeStringToCurvesOverflowMode overflow = (GeometryNodeStringToCurvesOverflowMode) | ||||
| storage->overflow; | storage->overflow; | ||||
| bNodeSocket *socket_remainder = ((bNodeSocket *)node->outputs.first)->next; | bNodeSocket *socket_remainder = ((bNodeSocket *)node->outputs.first)->next; | ||||
| nodeSetSocketAvailability( | nodeSetSocketAvailability( | ||||
| ntree, socket_remainder, overflow == GEO_NODE_STRING_TO_CURVES_MODE_TRUNCATE); | ntree, socket_remainder, overflow == GEO_NODE_STRING_TO_CURVES_MODE_TRUNCATE); | ||||
| ▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | static void add_instances_from_handles(InstancesComponent &instances, | ||||
| threading::parallel_for(IndexRange(positions.size()), 256, [&](IndexRange range) { | threading::parallel_for(IndexRange(positions.size()), 256, [&](IndexRange range) { | ||||
| for (const int i : range) { | for (const int i : range) { | ||||
| handles[i] = char_handles.lookup(charcodes[i]); | handles[i] = char_handles.lookup(charcodes[i]); | ||||
| transforms[i] = float4x4::from_location({positions[i].x, positions[i].y, 0}); | transforms[i] = float4x4::from_location({positions[i].x, positions[i].y, 0}); | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| static void geo_node_string_to_curves_exec(GeoNodeExecParams params) | static void node_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| TextLayout layout = get_text_layout(params); | TextLayout layout = get_text_layout(params); | ||||
| const NodeGeometryStringToCurves &storage = | const NodeGeometryStringToCurves &storage = | ||||
| *(const NodeGeometryStringToCurves *)params.node().storage; | *(const NodeGeometryStringToCurves *)params.node().storage; | ||||
| if (storage.overflow == GEO_NODE_STRING_TO_CURVES_MODE_TRUNCATE) { | if (storage.overflow == GEO_NODE_STRING_TO_CURVES_MODE_TRUNCATE) { | ||||
| params.set_output("Remainder", std::move(layout.truncated_text)); | params.set_output("Remainder", std::move(layout.truncated_text)); | ||||
| } | } | ||||
| Show All 25 Lines | |||||
| void register_node_type_geo_string_to_curves() | void register_node_type_geo_string_to_curves() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_geo_string_to_curves_cc; | namespace file_ns = blender::nodes::node_geo_string_to_curves_cc; | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base( | geo_node_type_base( | ||||
| &ntype, GEO_NODE_STRING_TO_CURVES, "String to Curves", NODE_CLASS_GEOMETRY, 0); | &ntype, GEO_NODE_STRING_TO_CURVES, "String to Curves", NODE_CLASS_GEOMETRY, 0); | ||||
| ntype.declare = file_ns::geo_node_string_to_curves_declare; | ntype.declare = file_ns::node_declare; | ||||
| ntype.geometry_node_execute = file_ns::geo_node_string_to_curves_exec; | ntype.geometry_node_execute = file_ns::node_exec; | ||||
| node_type_init(&ntype, file_ns::geo_node_string_to_curves_init); | node_type_init(&ntype, file_ns::node_init); | ||||
| node_type_update(&ntype, file_ns::geo_node_string_to_curves_update); | node_type_update(&ntype, file_ns::node_update); | ||||
| node_type_size(&ntype, 190, 120, 700); | node_type_size(&ntype, 190, 120, 700); | ||||
| node_type_storage(&ntype, | node_type_storage(&ntype, | ||||
| "NodeGeometryStringToCurves", | "NodeGeometryStringToCurves", | ||||
| node_free_standard_storage, | node_free_standard_storage, | ||||
| node_copy_standard_storage); | node_copy_standard_storage); | ||||
| ntype.draw_buttons = file_ns::geo_node_string_to_curves_layout; | ntype.draw_buttons = file_ns::node_layout; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||