From c0d0afa03ca61f510c6479e225cdb093553216a8 Mon Sep 17 00:00:00 2001 From: t3du <32546729+t3du@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:02:36 +0000 Subject: [PATCH] String angle and params --- Sources/armory/logicnode/DrawStringNode.hx | 15 ++++++++++++++- .../armory/logicnode/DrawTextAreaStringNode.hx | 18 +++++++++++++++--- .../logicnode/draw/LN_draw_Text_Area_string.py | 12 +++++++++++- blender/arm/logicnode/draw/LN_draw_string.py | 15 ++++++++++++++- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Sources/armory/logicnode/DrawStringNode.hx b/Sources/armory/logicnode/DrawStringNode.hx index e381f7817d..2fbdd95829 100644 --- a/Sources/armory/logicnode/DrawStringNode.hx +++ b/Sources/armory/logicnode/DrawStringNode.hx @@ -11,6 +11,7 @@ import armory.ui.Canvas; class DrawStringNode extends LogicNode { var font: Font; var lastFontName = ""; + var string:String; public function new(tree: LogicTree) { super(tree); @@ -19,7 +20,9 @@ class DrawStringNode extends LogicNode { override function run(from: Int) { RenderToTexture.ensure2DContext("DrawStringNode"); - var string:String = Std.string(inputs[1].get()); + string = Std.string(inputs[1].get()); + var angle: Float = inputs[7].get(); + var fontName = inputs[2].get(); if (fontName == "") { #if arm_ui @@ -42,6 +45,8 @@ class DrawStringNode extends LogicNode { return; } + RenderToTexture.g.rotate(angle, inputs[5].get(), inputs[6].get()); + final colorVec = inputs[4].get(); RenderToTexture.g.color = Color.fromFloats(colorVec.x, colorVec.y, colorVec.z, colorVec.w); @@ -50,6 +55,14 @@ class DrawStringNode extends LogicNode { RenderToTexture.g.drawString(string, inputs[5].get(), inputs[6].get()); + RenderToTexture.g.rotate(-angle, inputs[5].get(), inputs[6].get()); + runOutput(0); } + + override function get(from: Int): Dynamic { + + return from == 1 ? RenderToTexture.g.font.height(RenderToTexture.g.fontSize) : RenderToTexture.g.font.width(RenderToTexture.g.fontSize, string); + + } } diff --git a/Sources/armory/logicnode/DrawTextAreaStringNode.hx b/Sources/armory/logicnode/DrawTextAreaStringNode.hx index dd9a812623..db32a32f40 100644 --- a/Sources/armory/logicnode/DrawTextAreaStringNode.hx +++ b/Sources/armory/logicnode/DrawTextAreaStringNode.hx @@ -23,6 +23,7 @@ class DrawTextAreaStringNode extends LogicNode { var index: Int; var max: Int; + var ar_lines: Array; public function new(tree: LogicTree) { super(tree); @@ -34,11 +35,11 @@ class DrawTextAreaStringNode extends LogicNode { var string:String = Std.string(inputs[1].get()); var length:Int = inputs[3].get(); + var angle: Float = inputs[10].get(); var horA = TextLeft; var verA = TextTop; - var fontName = inputs[2].get(); if (fontName == "") { #if arm_ui @@ -63,7 +64,7 @@ class DrawTextAreaStringNode extends LogicNode { var len = string.length; - var ar_lines = []; + ar_lines = []; var ar_words = string.split(' '); @@ -115,6 +116,8 @@ class DrawTextAreaStringNode extends LogicNode { case 'TextRight': {horA = TextRight; xoffset = -width; } } + RenderToTexture.g.rotate(angle, inputs[8].get(), inputs[9].get()+(ar_lines.length-1)/2*height*spacing); + RenderToTexture.g.color = Color.fromFloats(colorVecB.x, colorVecB.y, colorVecB.z, colorVecB.w); RenderToTexture.g.fillRect(inputs[8].get()+xoffset, inputs[9].get()+yoffset+index*height*spacing, width, height); @@ -124,9 +127,18 @@ class DrawTextAreaStringNode extends LogicNode { RenderToTexture.g.drawAlignedString(line, inputs[8].get(), inputs[9].get()+index*height*spacing, horA, verA); ++index; + RenderToTexture.g.rotate(-angle, inputs[8].get(), inputs[9].get()+(ar_lines.length-1)/2*height*spacing); + } + #end runOutput(0); } -} + + override function get(from: Int): Dynamic { + + return ar_lines.length; + + } +} \ No newline at end of file diff --git a/blender/arm/logicnode/draw/LN_draw_Text_Area_string.py b/blender/arm/logicnode/draw/LN_draw_Text_Area_string.py index 2eb93b619c..5be8fbb31f 100644 --- a/blender/arm/logicnode/draw/LN_draw_Text_Area_string.py +++ b/blender/arm/logicnode/draw/LN_draw_Text_Area_string.py @@ -18,13 +18,15 @@ class DrawTextAreaStringNode(ArmLogicTreeNode): @input Color Font: The color of the string, supports alpha. @input Color Background: The color background of the text area, supports alpha, if no color is wanted used alpha 0. @input X/Y: Position of the string, in pixels from the top left corner. + @input Angle: Rotation angle in radians. Rectangle will be rotated cloclwiswe + at the anchor point. @see [`kha.graphics2.Graphics.drawString()`](http://kha.tech/api/kha/graphics2/Graphics.html#drawString). """ bl_idname = 'LNDrawTextAreaStringNode' bl_label = 'Draw Text Area String' arm_section = 'draw' - arm_version = 1 + arm_version = 3 property0: HaxeEnumProperty( 'property0', @@ -58,10 +60,18 @@ def arm_init(self, context): self.add_input('ArmColorSocket', 'Color Background', default_value=[0.0, 0.0, 0.0, 1.0]) self.add_input('ArmFloatSocket', 'X') self.add_input('ArmFloatSocket', 'Y') + self.add_input('ArmFloatSocket', 'Angle') self.add_output('ArmNodeSocketAction', 'Out') + self.add_output('ArmIntSocket', 'Lines') def draw_buttons(self, context, layout): layout.prop(self, 'property0') layout.prop(self, 'property1') layout.prop(self, 'property2') + + def get_replacement_node(self, node_tree: bpy.types.NodeTree): + if self.arm_version not in (0, 2): + raise LookupError() + + return NodeReplacement.Identity(self) \ No newline at end of file diff --git a/blender/arm/logicnode/draw/LN_draw_string.py b/blender/arm/logicnode/draw/LN_draw_string.py index 00763a11fd..1acc3298a2 100644 --- a/blender/arm/logicnode/draw/LN_draw_string.py +++ b/blender/arm/logicnode/draw/LN_draw_string.py @@ -13,15 +13,19 @@ class DrawStringNode(ArmLogicTreeNode): @input Font Size: The size of the font in pixels. @input Color: The color of the string. @input X/Y: Position of the string, in pixels from the top left corner. + @input Angle: Rotation angle in radians. Rectangle will be rotated cloclwiswe + at the anchor point. @output Out: Activated after the string has been drawn. + @output Height: String Height. + @output Width: String Width. @see [`kha.graphics2.Graphics.drawString()`](http://kha.tech/api/kha/graphics2/Graphics.html#drawString). """ bl_idname = 'LNDrawStringNode' bl_label = 'Draw String' arm_section = 'draw' - arm_version = 1 + arm_version = 2 def arm_init(self, context): self.add_input('ArmNodeSocketAction', 'Draw') @@ -31,5 +35,14 @@ def arm_init(self, context): self.add_input('ArmColorSocket', 'Color', default_value=[1.0, 1.0, 1.0, 1.0]) self.add_input('ArmFloatSocket', 'X') self.add_input('ArmFloatSocket', 'Y') + self.add_input('ArmFloatSocket', 'Angle') self.add_output('ArmNodeSocketAction', 'Out') + self.add_output('ArmFloatSocket', 'Height') + self.add_output('ArmFloatSocket', 'Width') + + def get_replacement_node(self, node_tree: bpy.types.NodeTree): + if self.arm_version not in (0, 1): + raise LookupError() + + return NodeReplacement.Identity(self)