Pixel-Composer/scripts/node_padding/node_padding.gml

115 lines
3.3 KiB
Plaintext
Raw Normal View History

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-07 11:48:39 +02:00
inputs[| 0] = nodeValue_Surface("Surface in", self);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Padding", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [0, 0, 0, 0])
2022-12-27 04:00:50 +01:00
.setDisplay(VALUE_DISPLAY.padding)
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); });
2022-01-13 05:24:03 +01:00
2024-08-07 11:48:39 +02:00
inputs[| 2] = nodeValue_Enum_Scroll("Fill method", self, 0, [ "Empty", "Solid" ]);
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Fill color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_black);
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 4] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
active_index = 4;
2024-08-07 11:48:39 +02:00
inputs[| 5] = nodeValue_Enum_Button("Pad mode", self, 0, [ "Pad out", "Pad to size" ]);
2023-04-05 20:13:27 +02:00
2023-07-21 12:40:20 +02:00
inputs[| 6] = nodeValue("Target dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
2023-04-05 20:13:27 +02:00
.setDisplay(VALUE_DISPLAY.vector)
2024-08-07 11:48:39 +02:00
inputs[| 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-07 11:48:39 +02:00
inputs[| 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
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-02-14 05:32:32 +01:00
input_display_list = [ 4,
["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() {
var mode = getInputData(5);
2023-04-05 20:13:27 +02:00
inputs[| 1].setVisible(mode == 0);
inputs[| 6].setVisible(mode == 1);
inputs[| 7].setVisible(mode == 1);
inputs[| 8].setVisible(mode == 1);
}
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];
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
inputs[| 3].setVisible(fill);
2022-01-13 05:24:03 +01:00
2023-09-08 21:37:36 +02:00
var ww = surface_get_width_safe(_data[0]);
var hh = surface_get_height_safe(_data[0]);
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
2023-04-05 20:13:27 +02:00
draw_surface_safe(_data[0], padding[2], padding[1]);
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;
}
draw_surface_safe(_data[0], sx, sy);
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;
}
}