Pixel-Composer/scripts/node_stack/node_stack.gml

153 lines
4.1 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Stack(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2024-01-09 03:39:40 +01:00
name = "Stack";
2022-12-27 04:00:50 +01:00
2024-08-20 10:15:53 +02:00
newInput(0, nodeValue_Enum_Scroll("Axis", self, 0, [ new scrollItem("Horizontal", s_node_alignment, 0),
new scrollItem("Vertical", s_node_alignment, 1),
new scrollItem("On top", s_node_alignment, 3), ]))
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-12-27 04:00:50 +01:00
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_Enum_Button("Align", self, 1, [ "Start", "Middle", "End"]))
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-12-27 04:00:50 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Int("Spacing", self, 0))
2023-02-14 05:32:32 +01:00
.rejectArray();
2022-12-27 04:00:50 +01:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Padding("Padding", self, [ 0, 0, 0, 0 ]))
2024-01-21 03:55:31 +01:00
.rejectArray();
2022-12-27 04:00:50 +01:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
2022-12-27 04:00:50 +01:00
2024-11-15 09:39:23 +01:00
newOutput(1, nodeValue_Output("Atlas data", self, VALUE_TYPE.atlas, []));
2023-04-16 15:26:52 +02:00
2023-12-15 12:56:36 +01:00
temp_surface = [ noone, noone ];
2024-05-23 10:59:39 +02:00
static createNewInput = function() {
2024-08-08 06:57:51 +02:00
var index = array_length(inputs);
2024-08-18 09:13:41 +02:00
newInput(index, nodeValue_Surface("Input", self))
2024-05-23 10:59:39 +02:00
.setVisible(true, true);
2024-08-08 06:57:51 +02:00
return inputs[index];
2024-05-23 10:59:39 +02:00
} setDynamicInput(1, true, VALUE_TYPE.surface);
2022-12-27 04:00:50 +01:00
2024-05-23 10:59:39 +02:00
attribute_surface_depth();
2023-01-09 03:14:20 +01:00
2023-09-14 16:29:39 +02:00
static step = function() { #region
var _axis = getInputData(0);
2023-01-01 02:06:02 +01:00
2024-08-08 06:57:51 +02:00
inputs[1].setVisible(_axis != 2);
inputs[2].setVisible(_axis != 2);
2023-09-14 16:29:39 +02:00
} #endregion
2023-01-01 02:06:02 +01:00
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) { #region
var _axis = getInputData(0);
var _alig = getInputData(1);
var _spac = getInputData(2);
2024-01-21 03:55:31 +01:00
var _padd = getInputData(3);
2022-12-27 04:00:50 +01:00
var ww = 0;
var hh = 0;
2024-08-08 06:57:51 +02:00
for( var i = input_fix_len; i < array_length(inputs); i++ ) {
var _surf = getInputData(i);
2023-02-14 05:32:32 +01:00
if(!is_array(_surf)) _surf = [ _surf ];
2022-12-27 04:00:50 +01:00
2023-02-14 05:32:32 +01:00
for( var j = 0; j < array_length(_surf); j++ ) {
if(!is_surface(_surf[j])) continue;
2023-09-08 21:37:36 +02:00
var sw = surface_get_width_safe(_surf[j]);
var sh = surface_get_height_safe(_surf[j]);
2023-02-14 05:32:32 +01:00
if(_axis == 0) {
2024-01-21 03:55:31 +01:00
ww += sw + _spac;
hh = max(hh, sh + _spac);
2023-02-14 05:32:32 +01:00
} else if(_axis == 1) {
2024-01-21 03:55:31 +01:00
ww = max(ww, sw + _spac);
hh += sh + _spac;
2023-02-14 05:32:32 +01:00
} else if(_axis == 2) {
ww = max(ww, sw);
hh = max(hh, sh);
}
2022-12-27 04:00:50 +01:00
}
}
2024-01-21 03:55:31 +01:00
ww -= _spac;
hh -= _spac;
var ow = ww + _padd[PADDING.left] + _padd[PADDING.right];
var oh = hh + _padd[PADDING.top] + _padd[PADDING.bottom];
2024-08-08 06:57:51 +02:00
var _outSurf = outputs[0].getValue();
2024-01-21 03:55:31 +01:00
_outSurf = surface_verify(_outSurf, ow, oh, attrDepth());
2023-12-15 12:56:36 +01:00
2024-01-21 03:55:31 +01:00
temp_surface[0] = surface_verify(temp_surface[0], ow, oh, attrDepth());
temp_surface[1] = surface_verify(temp_surface[1], ow, oh, attrDepth());
2023-12-15 12:56:36 +01:00
2024-01-21 03:55:31 +01:00
surface_clear(temp_surface[0]);
surface_clear(temp_surface[1]);
2023-02-14 05:32:32 +01:00
2023-04-16 15:26:52 +02:00
var atlas = [];
2023-12-15 12:56:36 +01:00
var ppind = 0;
var sx = 0, sy = 0;
2023-04-16 15:26:52 +02:00
2024-08-08 06:57:51 +02:00
for( var i = input_fix_len; i < array_length(inputs); i++ ) {
2023-12-15 12:56:36 +01:00
var _surf = getInputData(i);
if(!is_array(_surf)) _surf = [ _surf ];
2023-02-14 05:32:32 +01:00
2023-12-15 12:56:36 +01:00
for( var j = 0; j < array_length(_surf); j++ ) {
if(!is_surface(_surf[j])) continue;
var sw = surface_get_width_safe(_surf[j]);
var sh = surface_get_height_safe(_surf[j]);
2023-02-14 05:32:32 +01:00
2023-12-15 12:56:36 +01:00
if(_axis == 0) {
switch(_alig) {
case fa_left: sy = 0; break;
case fa_center: sy = hh / 2 - sh / 2; break;
case fa_right: sy = hh - sh; break;
2022-12-27 04:00:50 +01:00
}
2023-12-15 12:56:36 +01:00
} else if(_axis == 1) {
switch(_alig) {
case fa_left: sx = 0; break;
case fa_center: sx = ww / 2 - sw / 2; break;
case fa_right: sx = ww - sw; break;
}
} else if(_axis == 2) {
sx = ww / 2 - sw / 2;
sy = hh / 2 - sh / 2;
}
2023-04-16 15:26:52 +02:00
2023-12-15 12:56:36 +01:00
array_push(atlas, new SurfaceAtlas(_surf[j], sx, sy));
surface_set_shader(temp_surface[!ppind], sh_draw_surface);
DRAW_CLEAR
BLEND_OVERRIDE
2024-01-21 03:55:31 +01:00
shader_set_f("dimension", ow, oh);
2023-04-16 15:26:52 +02:00
2023-12-15 12:56:36 +01:00
shader_set_surface("fore", _surf[j]);
shader_set_f("fdimension", sw, sh);
2024-01-21 03:55:31 +01:00
shader_set_f("position", sx + _padd[PADDING.left], sy + _padd[PADDING.top]);
2023-12-15 12:56:36 +01:00
draw_surface_safe(temp_surface[ppind]);
2023-12-15 12:56:36 +01:00
BLEND_NORMAL
surface_reset_shader();
ppind = !ppind;
2024-01-21 03:55:31 +01:00
if(_axis == 0) sx += sw + _spac;
else if(_axis == 1) sy += sh + _spac;
2022-12-27 04:00:50 +01:00
}
2023-12-15 12:56:36 +01:00
}
surface_set_target(_outSurf);
DRAW_CLEAR
BLEND_OVERRIDE
draw_surface_safe(temp_surface[ppind]);
2022-12-27 04:00:50 +01:00
2023-12-15 12:56:36 +01:00
BLEND_NORMAL
2022-12-27 04:00:50 +01:00
surface_reset_target();
2023-04-16 15:26:52 +02:00
2024-08-08 06:57:51 +02:00
outputs[0].setValue(_outSurf);
outputs[1].setValue(atlas);
2023-09-14 16:29:39 +02:00
} #endregion
2022-12-27 04:00:50 +01:00
}