Pixel-Composer/scripts/node_text/node_text.gml

129 lines
4.1 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Text(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-01-25 06:49:00 +01:00
name = "Draw Text";
2022-01-13 05:24:03 +01:00
font = f_p0;
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Text", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "")
2022-12-16 09:18:09 +01:00
.setVisible(true, true);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Font", self, JUNCTION_CONNECT.input, VALUE_TYPE.path, "")
2022-12-16 09:18:09 +01:00
.setDisplay(VALUE_DISPLAY.path_font);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("Size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 16);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Anti-Aliasing ", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 4] = nodeValue("Character range", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 32, 128 ])
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 5] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white);
2022-01-13 05:24:03 +01:00
2023-07-21 12:40:20 +02:00
inputs[| 6] = nodeValue("Fixed dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF )
2022-01-13 05:24:03 +01:00
.setDisplay(VALUE_DISPLAY.vector)
.setVisible(true, false);
2023-02-14 05:32:32 +01:00
inputs[| 7] = nodeValue("Horizontal alignment", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2022-11-18 03:20:31 +01:00
.setDisplay(VALUE_DISPLAY.enum_button, [ THEME.inspector_text_halign, THEME.inspector_text_halign, THEME.inspector_text_halign]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 8] = nodeValue("Vertical alignment", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
2022-11-18 03:20:31 +01:00
.setDisplay(VALUE_DISPLAY.enum_button, [ THEME.inspector_text_valign, THEME.inspector_text_valign, THEME.inspector_text_valign ]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 9] = nodeValue("Output dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1 )
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Fixed", "Dynamic" ]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 10] = nodeValue("Padding", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [0, 0, 0, 0])
2022-09-21 06:09:40 +02:00
.setDisplay(VALUE_DISPLAY.padding);
2022-01-13 05:24:03 +01:00
input_display_list = [
2022-09-21 06:09:40 +02:00
["Output", true], 9, 6, 10,
2022-01-13 05:24:03 +01:00
["Text", false], 0, 7, 8, 5,
["Font properties", false], 1, 2, 3,
2022-01-13 05:24:03 +01:00
];
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2022-01-13 05:24:03 +01:00
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2022-01-13 05:24:03 +01:00
_font_current = "";
_size_current = 0;
_aa_current = false;
static generateFont = function(_path, _size, _aa) {
2023-07-06 19:49:16 +02:00
if(PROJECT.animator.is_playing) return;
if(_path == _font_current && _size == _size_current && _aa == _aa_current) return;
2023-03-13 10:45:56 +01:00
2022-01-13 05:24:03 +01:00
_font_current = _path;
_size_current = _size;
_aa_current = _aa;
if(!file_exists(_path)) return;
if(font != f_p0 && font_exists(font))
font_delete(font);
2023-03-13 10:45:56 +01:00
font_add_enable_aa(_aa);
font = _font_add(_path, _size);
2022-01-13 05:24:03 +01:00
}
2023-08-17 16:56:54 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2022-01-13 05:24:03 +01:00
var str = _data[0];
var _font = _data[1];
var _size = _data[2];
var _aa = _data[3];
var _col = _data[5];
var _dim_type = _data[9];
2022-01-19 06:11:17 +01:00
inputs[| 6].setVisible(!_dim_type);
2022-09-21 06:09:40 +02:00
2022-01-13 05:24:03 +01:00
var _dim = _data[6];
2022-09-21 06:09:40 +02:00
var _padd = _data[10];
2022-01-13 05:24:03 +01:00
var ww, hh;
generateFont(_font, _size, _aa);
2022-01-13 05:24:03 +01:00
draw_set_font(font);
if(_dim_type == 0) {
ww = _dim[0];
hh = _dim[1];
} else {
ww = max(1, string_width(str));
hh = max(1, string_height(str));
}
2022-09-21 06:09:40 +02:00
ww += _padd[PADDING.left] + _padd[PADDING.right];
2023-03-19 09:17:39 +01:00
hh += _padd[PADDING.top] + _padd[PADDING.bottom];
_outSurf = surface_verify(_outSurf, ww, hh, attrDepth());
2022-01-13 05:24:03 +01:00
surface_set_target(_outSurf);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
BLEND_ALPHA
2022-01-13 05:24:03 +01:00
if(_dim[0] != 0 && _dim[1] != 0) {
var _hali = _data[7];
var _vali = _data[8];
var tx = 0, ty = 0;
draw_set_text(font, fa_left, fa_top, _col);
switch(_hali) {
case 0 : draw_set_halign(fa_left); tx = 0; break;
case 1 : draw_set_halign(fa_center); tx = ww / 2; break;
case 2 : draw_set_halign(fa_right); tx = ww; break;
}
switch(_vali) {
case 0 : draw_set_valign(fa_top); ty = 0; break;
case 1 : draw_set_valign(fa_middle); ty = hh / 2; break;
case 2 : draw_set_valign(fa_bottom); ty = hh; break;
}
2023-03-19 09:17:39 +01:00
draw_text(_padd[PADDING.left] + tx, _padd[PADDING.top] + ty, str);
2022-01-13 05:24:03 +01:00
} else {
draw_set_text(font, fa_left, fa_top, _col);
2023-03-19 09:17:39 +01:00
draw_text(_padd[PADDING.left], _padd[PADDING.top], str);
2022-01-13 05:24:03 +01:00
}
2023-02-14 05:32:32 +01:00
BLEND_NORMAL;
2022-01-13 05:24:03 +01:00
surface_reset_target();
2022-12-27 04:00:50 +01:00
return _outSurf;
2022-01-13 05:24:03 +01:00
}
}