forked from LeenkxTeam/LNXSDK
93 lines
2.0 KiB
Haxe
93 lines
2.0 KiB
Haxe
package leenkx.logicnode;
|
|
|
|
import kha.Font;
|
|
import kha.Color;
|
|
import leenkx.renderpath.RenderToTexture;
|
|
import kha.graphics2.VerTextAlignment;
|
|
import kha.graphics2.HorTextAlignment;
|
|
|
|
#if lnx_ui
|
|
import leenkx.ui.Canvas;
|
|
|
|
using zui.GraphicsExtension;
|
|
#end
|
|
|
|
class DrawStringNode extends LogicNode {
|
|
var font: Font;
|
|
var lastFontName = "";
|
|
var string:String;
|
|
|
|
public var property1: String;
|
|
public var property2: String;
|
|
|
|
public function new(tree: LogicTree) {
|
|
super(tree);
|
|
}
|
|
|
|
#if lnx_ui
|
|
override function run(from: Int) {
|
|
RenderToTexture.ensure2DContext("DrawStringNode");
|
|
|
|
var horA = TextLeft;
|
|
var verA = TextTop;
|
|
|
|
string = Std.string(inputs[1].get());
|
|
var angle: Float = inputs[7].get();
|
|
|
|
var fontName = inputs[2].get();
|
|
if (fontName == "") {
|
|
#if lnx_ui
|
|
fontName = Canvas.defaultFontName;
|
|
#else
|
|
return; // No default font is exported, there is nothing we can do here
|
|
#end
|
|
}
|
|
|
|
if (fontName != lastFontName) {
|
|
// Load new font
|
|
lastFontName = fontName;
|
|
iron.data.Data.getFont(fontName, (f: Font) -> {
|
|
font = f;
|
|
});
|
|
}
|
|
|
|
if (font == null) {
|
|
runOutput(0);
|
|
return;
|
|
}
|
|
|
|
switch(property1){
|
|
case 'TextLeft': horA = TextLeft;
|
|
case 'TextCenter': horA = TextCenter;
|
|
case 'TextRight': horA = TextRight;
|
|
}
|
|
|
|
switch(property2){
|
|
case 'TextTop': verA = TextTop;
|
|
case 'TextMiddle': verA = TextMiddle;
|
|
case 'TextBottom': verA = TextBottom;
|
|
}
|
|
|
|
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);
|
|
|
|
RenderToTexture.g.fontSize = inputs[3].get();
|
|
RenderToTexture.g.font = font;
|
|
|
|
RenderToTexture.g.drawAlignedString(string, inputs[5].get(), inputs[6].get(), horA, verA);
|
|
|
|
RenderToTexture.g.rotate(-angle, inputs[5].get(), inputs[6].get());
|
|
|
|
runOutput(0);
|
|
}
|
|
|
|
override function get(from: Int): Dynamic {
|
|
|
|
return from == 1 ? RenderToTexture.g.font.width(RenderToTexture.g.fontSize, string) : RenderToTexture.g.font.height(RenderToTexture.g.fontSize);
|
|
|
|
}
|
|
#end
|
|
}
|