Pixel-Composer/scripts/node_blend/node_blend.gml

149 lines
4.9 KiB
Plaintext
Raw Normal View History

2022-12-13 14:11:39 +01:00
function Node_create_Blend(_x, _y, _group = -1, _param = "") {
2022-12-13 09:20:36 +01:00
var node = new Node_Blend(_x, _y, _group);
2022-01-26 06:57:34 +01:00
switch(_param) {
case "normal" : node.inputs[| 2].setValue(BLEND_MODE.normal) break;
case "add" : node.inputs[| 2].setValue(BLEND_MODE.add); break;
case "subtract" : node.inputs[| 2].setValue(BLEND_MODE.subtract); break;
case "multiply" : node.inputs[| 2].setValue(BLEND_MODE.multiply); break;
2022-12-27 04:00:50 +01:00
case "overlay" : node.inputs[| 2].setValue(BLEND_MODE.overlay); break;
2022-01-26 06:57:34 +01:00
case "screen" : node.inputs[| 2].setValue(BLEND_MODE.screen); break;
case "maxx" : node.inputs[| 2].setValue(BLEND_MODE.maxx); break;
case "minn" : node.inputs[| 2].setValue(BLEND_MODE.minn); break;
}
2022-01-13 05:24:03 +01:00
return node;
}
2022-12-13 09:20:36 +01:00
function Node_Blend(_x, _y, _group = -1) : Node_Processor(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Blend";
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, DEF_SURFACE);
inputs[| 1] = nodeValue("Foreground", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, DEF_SURFACE);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 2] = nodeValue("Blend mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, BLEND_TYPES );
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Opacity", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
2022-01-13 05:24:03 +01:00
.setDisplay(VALUE_DISPLAY.slider, [ 0, 1, 0.01]);
2023-02-14 05:32:32 +01:00
inputs[| 4] = nodeValue("Mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
2022-01-13 05:24:03 +01:00
2023-02-14 13:44:46 +01:00
inputs[| 5] = nodeValue("Fill mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "None", "Stretch", "Tile" ]);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 6] = nodeValue("Output dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Background", "Forground", "Mask", "Maximum", "Constant" ])
.rejectArray();
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 7] = nodeValue("Constant dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2)
2023-01-25 06:49:00 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2023-02-14 05:32:32 +01:00
inputs[| 8] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
active_index = 8;
inputs[| 9] = nodeValue("Preserve alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
2023-02-15 10:43:24 +01:00
inputs[| 10] = nodeValue("Horizontal Align", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ THEME.inspector_surface_halign, THEME.inspector_surface_halign, THEME.inspector_surface_halign]);
inputs[| 11] = nodeValue("Vertical Align", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_button, [ THEME.inspector_surface_valign, THEME.inspector_surface_valign, THEME.inspector_surface_valign]);
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 = [ 8,
2023-01-25 06:49:00 +01:00
["Surfaces", true], 0, 1, 4, 6, 7,
2023-02-14 05:32:32 +01:00
["Blend", false], 2, 3, 9,
2023-02-15 10:43:24 +01:00
["Transform", false], 5, 10, 11,
2023-01-17 08:11:55 +01:00
]
2023-02-15 10:43:24 +01:00
temp = surface_create(1, 1);
2023-01-01 02:06:02 +01:00
static process_data = function(_outSurf, _data, _output_index, _array_index) {
2023-01-17 08:11:55 +01:00
var _back = _data[0];
var _fore = _data[1];
var _type = _data[2];
var _opacity = _data[3];
var _mask = _data[4];
var _tile = _data[5];
2022-01-13 05:24:03 +01:00
2023-01-25 06:49:00 +01:00
var _outp = _data[6];
var _out_dim = _data[7];
2023-02-14 05:32:32 +01:00
var _pre_alp = _data[9];
2023-01-25 06:49:00 +01:00
2023-02-15 10:43:24 +01:00
var _halign = _data[10];
var _valign = _data[11];
2023-01-25 06:49:00 +01:00
inputs[| 7].setVisible(_outp == 4);
var ww = 1, hh = 1;
2023-02-15 10:43:24 +01:00
var _foreDraw = _fore;
inputs[| 10].setVisible(_tile == 0);
inputs[| 11].setVisible(_tile == 0);
if(_tile == 0) {
ww = surface_get_width(_back);
hh = surface_get_height(_back);
var fw = surface_get_width(_fore);
var fh = surface_get_height(_fore);
temp = surface_verify(temp, ww, hh);
_foreDraw = temp;
var sx = 0;
var sy = 0;
switch(_halign) {
case 0 : sx = 0; break;
case 1 : sx = ww / 2 - fw / 2; break;
case 2 : sx = ww - fw; break;
}
switch(_valign) {
case 0 : sy = 0; break;
case 1 : sy = hh / 2 - fh / 2; break;
case 2 : sy = hh - fh; break;
}
surface_set_target(temp);
draw_clear_alpha(0, 0);
BLEND_OVER_ALPHA
draw_surface(_fore, sx, sy);
BLEND_NORMAL
surface_reset_target();
}
2023-01-25 06:49:00 +01:00
switch(_outp) {
case 0 :
ww = surface_get_width(_back);
hh = surface_get_height(_back);
break;
case 1 :
2023-02-15 10:43:24 +01:00
ww = surface_get_width(_foreDraw);
hh = surface_get_height(_foreDraw);
2023-01-25 06:49:00 +01:00
break;
case 2 :
ww = surface_get_width(_mask);
hh = surface_get_height(_mask);
break;
case 3 :
2023-02-16 02:51:51 +01:00
ww = max(surface_get_width(_back), surface_get_width(_fore), surface_get_width(_mask));
hh = max(surface_get_height(_back), surface_get_height(_fore), surface_get_height(_mask));
2023-01-25 06:49:00 +01:00
break;
case 4 :
ww = _out_dim[0];
hh = _out_dim[1];
break;
}
_outSurf = surface_verify(_outSurf, ww, hh);
2022-01-13 05:24:03 +01:00
surface_set_target(_outSurf);
draw_clear_alpha(0, 0);
2023-02-15 10:43:24 +01:00
draw_surface_blend(_back, _foreDraw, _type, _opacity, _pre_alp, _mask, max(0, _tile - 1));
2022-01-13 05:24:03 +01:00
surface_reset_target();
return _outSurf;
}
}