2025-01-22 16:18:30 +01:00
|
|
|
from lnx.logicnode.lnx_nodes import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DrawStringNode(LnxLogicTreeNode):
|
|
|
|
|
"""Draws a string.
|
|
|
|
|
|
|
|
|
|
@input Draw: Activate to draw the string on this frame. The input must
|
|
|
|
|
be (indirectly) called from an `On Render2D` node.
|
|
|
|
|
@input String: The string to draw.
|
|
|
|
|
@input Font File: The filename of the font (including the extension).
|
|
|
|
|
If empty and Zui is _enabled_, the default font is used. If empty
|
|
|
|
|
and Zui is _disabled_, nothing is rendered.
|
|
|
|
|
@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 Width: String Width.
|
2025-08-14 19:03:28 +00:00
|
|
|
@output Height: String Height.
|
2025-01-22 16:18:30 +01:00
|
|
|
|
|
|
|
|
@see [`kha.graphics2.Graphics.drawString()`](http://kha.tech/api/kha/graphics2/Graphics.html#drawString).
|
|
|
|
|
"""
|
|
|
|
|
bl_idname = 'LNDrawStringNode'
|
|
|
|
|
bl_label = 'Draw String'
|
|
|
|
|
lnx_section = 'draw'
|
2025-08-14 19:03:28 +00:00
|
|
|
lnx_version = 3
|
2025-01-22 16:18:30 +01:00
|
|
|
|
2026-09-04 10:46:13 -07:00
|
|
|
property1: HaxeEnumProperty(
|
|
|
|
|
'property1',
|
|
|
|
|
items = [('TextLeft', 'Hor. Align. Left', 'Hor. Align. Left'),
|
|
|
|
|
('TextCenter', 'Hor. Align. Center', 'Hor. Align. Center'),
|
|
|
|
|
('TextRight', 'Hor. Align. Right', 'Hor. Align. Right'),],
|
|
|
|
|
name='', default='TextLeft')
|
|
|
|
|
|
|
|
|
|
property2: HaxeEnumProperty(
|
|
|
|
|
'property2',
|
|
|
|
|
items = [('TextTop', 'Ver. Align. Top', 'Ver. Align. Top'),
|
|
|
|
|
('TextMiddle', 'Ver. Align. Middle', 'Ver. Align. Middle'),
|
|
|
|
|
('TextBottom', 'Ver. Align. Bottom', 'Ver. Align. Bottom'),],
|
|
|
|
|
name='', default='TextTop')
|
|
|
|
|
|
2025-01-22 16:18:30 +01:00
|
|
|
def lnx_init(self, context):
|
|
|
|
|
self.add_input('LnxNodeSocketAction', 'Draw')
|
|
|
|
|
self.add_input('LnxStringSocket', 'String')
|
|
|
|
|
self.add_input('LnxStringSocket', 'Font File')
|
|
|
|
|
self.add_input('LnxIntSocket', 'Font Size', default_value=16)
|
|
|
|
|
self.add_input('LnxColorSocket', 'Color', default_value=[1.0, 1.0, 1.0, 1.0])
|
|
|
|
|
self.add_input('LnxFloatSocket', 'X')
|
|
|
|
|
self.add_input('LnxFloatSocket', 'Y')
|
|
|
|
|
self.add_input('LnxFloatSocket', 'Angle')
|
|
|
|
|
|
|
|
|
|
self.add_output('LnxNodeSocketAction', 'Out')
|
|
|
|
|
self.add_output('LnxFloatSocket', 'Width')
|
2025-08-14 19:03:28 +00:00
|
|
|
self.add_output('LnxFloatSocket', 'Height')
|
2025-01-22 16:18:30 +01:00
|
|
|
|
2026-09-04 10:46:13 -07:00
|
|
|
def draw_buttons(self, context, layout):
|
|
|
|
|
layout.prop(self, 'property1')
|
|
|
|
|
layout.prop(self, 'property2')
|
|
|
|
|
|
2025-01-22 16:18:30 +01:00
|
|
|
def get_replacement_node(self, node_tree: bpy.types.NodeTree):
|
2025-08-14 19:03:28 +00:00
|
|
|
if self.lnx_version not in (0, 1, 2):
|
2025-01-22 16:18:30 +01:00
|
|
|
raise LookupError()
|
|
|
|
|
|
|
|
|
|
return NodeReplacement.Identity(self)
|