2023-02-28 09:43:01 +01:00
|
|
|
function Node_Padding(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Padding";
|
2022-12-27 13:30:02 +01:00
|
|
|
dimension_index = -1;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Surface("Surface in", self));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(1, nodeValue_Padding("Padding", self, [0, 0, 0, 0]))
|
2022-12-27 13:30:02 +01:00
|
|
|
.setUnitRef(function(index) { return getDimension(index); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(2, nodeValue_Enum_Scroll("Fill method", self, 0, [ "Empty", "Solid" ]));
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-11-23 08:31:15 +01:00
|
|
|
newInput(3, nodeValue_Color("Fill color", self, cola(c_black)));
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(4, nodeValue_Bool("Active", self, true));
|
2023-02-14 05:32:32 +01:00
|
|
|
active_index = 4;
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(5, nodeValue_Enum_Button("Pad mode", self, 0, [ "Pad out", "Pad to size" ]));
|
2023-04-05 20:13:27 +02:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(6, nodeValue_Vec2("Target dimension", self, DEF_SURF))
|
2023-04-05 20:13:27 +02:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(7, nodeValue_Enum_Button("Horizontal alignment", self, 0 , [ THEME.inspector_surface_halign, THEME.inspector_surface_halign, THEME.inspector_surface_halign]));
|
2023-04-05 20:13:27 +02:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(8, nodeValue_Enum_Button("Vertical alignment", self, 0 , [ THEME.inspector_surface_valign, THEME.inspector_surface_valign, THEME.inspector_surface_valign ]));
|
2023-04-05 20:13:27 +02:00
|
|
|
|
2024-09-04 03:57:11 +02:00
|
|
|
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
input_display_list = [ 4,
|
2023-11-08 14:37:51 +01:00
|
|
|
["Surfaces", true], 0,
|
2023-04-05 20:13:27 +02:00
|
|
|
["Padding", false], 5, 1, 6, 7, 8,
|
|
|
|
["Filling", false], 2, 3,
|
2023-01-17 08:11:55 +01:00
|
|
|
];
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2023-04-05 20:13:27 +02:00
|
|
|
static step = function() {
|
2023-10-02 08:57:44 +02:00
|
|
|
var mode = getInputData(5);
|
2023-04-05 20:13:27 +02:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[1].setVisible(mode == 0);
|
2023-04-05 20:13:27 +02:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[6].setVisible(mode == 1);
|
|
|
|
inputs[7].setVisible(mode == 1);
|
|
|
|
inputs[8].setVisible(mode == 1);
|
2023-04-05 20:13:27 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2023-04-05 20:13:27 +02:00
|
|
|
var mode = _data[5];
|
|
|
|
|
2024-08-14 09:55:53 +02:00
|
|
|
var surf = _data[0];
|
2022-01-13 05:24:03 +01:00
|
|
|
var padding = _data[1];
|
2023-04-05 20:13:27 +02:00
|
|
|
|
|
|
|
var dim = _data[6];
|
|
|
|
var halign = _data[7];
|
|
|
|
var valign = _data[8];
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
var fill = _data[2];
|
|
|
|
var fillClr = _data[3];
|
2023-03-19 09:17:39 +01:00
|
|
|
var cDep = attrDepth();
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[3].setVisible(fill);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-14 09:55:53 +02:00
|
|
|
var ww = surface_get_width_safe(surf);
|
|
|
|
var hh = surface_get_height_safe(surf);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-04-05 20:13:27 +02:00
|
|
|
if(mode == 0) {
|
|
|
|
var sw = ww + padding[0] + padding[2];
|
|
|
|
var sh = hh + padding[1] + padding[3];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-04-05 20:13:27 +02:00
|
|
|
if(sw > 1 && sh > 1) {
|
|
|
|
_outSurf = surface_verify(_outSurf, sw, sh, cDep);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-04-05 20:13:27 +02:00
|
|
|
surface_set_target(_outSurf);
|
|
|
|
if(fill == 0) {
|
|
|
|
DRAW_CLEAR
|
|
|
|
BLEND_OVERRIDE;
|
|
|
|
} else if(fill == 1)
|
|
|
|
draw_clear_alpha(fillClr, 1);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-08-14 09:55:53 +02:00
|
|
|
draw_surface_safe(surf, padding[2], padding[1]);
|
2023-04-05 20:13:27 +02:00
|
|
|
BLEND_NORMAL;
|
|
|
|
surface_reset_target();
|
|
|
|
}
|
|
|
|
} else if(mode == 1) {
|
|
|
|
_outSurf = surface_verify(_outSurf, dim[0], dim[1], cDep);
|
|
|
|
|
|
|
|
surface_set_target(_outSurf);
|
|
|
|
if(fill == 0) {
|
|
|
|
DRAW_CLEAR
|
|
|
|
BLEND_OVERRIDE;
|
|
|
|
} else if(fill == 1)
|
2024-01-08 08:10:50 +01:00
|
|
|
draw_clear(fillClr);
|
2023-04-05 20:13:27 +02:00
|
|
|
|
|
|
|
var sx = 0;
|
|
|
|
var sy = 0;
|
|
|
|
|
|
|
|
switch(halign) {
|
|
|
|
case fa_left : sx = 0; break;
|
|
|
|
case fa_center : sx = (dim[0] - ww) / 2; break;
|
|
|
|
case fa_right : sx = dim[0] - ww; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(valign) {
|
|
|
|
case fa_top : sy = 0; break;
|
|
|
|
case fa_center : sy = (dim[1] - hh) / 2; break;
|
|
|
|
case fa_bottom: sy = dim[1] - hh; break;
|
|
|
|
}
|
|
|
|
|
2024-08-14 09:55:53 +02:00
|
|
|
draw_surface_safe(surf, sx, sy);
|
2023-04-05 20:13:27 +02:00
|
|
|
BLEND_NORMAL;
|
2022-01-13 05:24:03 +01:00
|
|
|
surface_reset_target();
|
|
|
|
}
|
2023-04-05 20:13:27 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
return _outSurf;
|
|
|
|
}
|
|
|
|
}
|