2024-02-16 07:44:36 +01:00
|
|
|
#region create
|
|
|
|
global.node_blend_keys = [
|
|
|
|
"normal", "add", "subtract", "multiply", "screen",
|
|
|
|
"overlay", "hue", "saturation", "luminosity", "maximum",
|
|
|
|
"minimum", "replace", "difference"
|
|
|
|
];
|
|
|
|
|
|
|
|
function Node_create_Blend(_x, _y, _group = noone, _param = {}) {
|
|
|
|
var node = new Node_Blend(_x, _y, _group);
|
|
|
|
var query = struct_try_get(_param, "query", "");
|
|
|
|
var ind = -1;
|
|
|
|
|
|
|
|
switch(query) {
|
|
|
|
default : ind = array_find(global.node_blend_keys, query);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ind >= 0) node.inputs[| 2].setValue(ind);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
#endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
function Node_Blend(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Blend";
|
2023-10-06 11:51:11 +02:00
|
|
|
atlas_index = 1;
|
|
|
|
manage_atlas = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-28 06:58:28 +02:00
|
|
|
inputs[| 0] = nodeValue("Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
|
|
|
|
inputs[| 1] = nodeValue("Foreground", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
|
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)
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
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-07-21 12:40:20 +02:00
|
|
|
inputs[| 7] = nodeValue("Constant dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
|
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;
|
|
|
|
|
2023-02-19 13:49:20 +01:00
|
|
|
inputs[| 9] = nodeValue("Preserve alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
|
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
|
|
|
|
2023-11-24 10:41:53 +01:00
|
|
|
inputs[| 12] = nodeValue("Invert mask", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
|
|
|
|
|
|
|
|
inputs[| 13] = nodeValue("Mask feather", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
|
|
|
|
.setDisplay(VALUE_DISPLAY.slider, { range: [1, 16, 1] });
|
2023-12-15 12:56:36 +01:00
|
|
|
|
|
|
|
inputs[| 14] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0.5, 0.5 ])
|
|
|
|
.setDisplay(VALUE_DISPLAY.vector);
|
2023-11-24 10:41:53 +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-02-14 05:32:32 +01:00
|
|
|
input_display_list = [ 8,
|
2023-11-24 10:41:53 +01:00
|
|
|
["Surfaces", true], 0, 1, 4, 12, 13, 6, 7,
|
2023-02-14 05:32:32 +01:00
|
|
|
["Blend", false], 2, 3, 9,
|
2023-12-15 12:56:36 +01:00
|
|
|
["Transform", false], 5, 14,
|
2023-01-17 08:11:55 +01:00
|
|
|
]
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2023-10-06 11:51:11 +02:00
|
|
|
temp_surface = [ surface_create(1, 1), surface_create(1, 1) ];
|
|
|
|
blend_temp_surface = temp_surface[1];
|
|
|
|
|
2023-12-15 12:56:36 +01:00
|
|
|
dragging = false;
|
|
|
|
drag_sx = 0;
|
|
|
|
drag_sy = 0;
|
|
|
|
drag_mx = 0;
|
|
|
|
drag_my = 0;
|
|
|
|
|
|
|
|
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
|
|
|
|
var _surf = outputs[| 0].getValue();
|
|
|
|
if(is_array(_surf)) _surf = array_safe_get(_surf, preview_index);
|
|
|
|
if(is_struct(_surf)) return;
|
|
|
|
if(!surface_exists(_surf)) return;
|
|
|
|
|
|
|
|
var _fore = getSingleValue( 1);
|
|
|
|
var _fill = getSingleValue( 5);
|
|
|
|
var _posi = getSingleValue(14);
|
|
|
|
if(_fill) return;
|
|
|
|
|
|
|
|
var sw = surface_get_width_safe( _surf);
|
|
|
|
var sh = surface_get_height_safe(_surf);
|
|
|
|
var fw = surface_get_width_safe( _fore);
|
|
|
|
var fh = surface_get_height_safe(_fore);
|
|
|
|
|
|
|
|
var _rx = _posi[0] * sw - fw / 2;
|
|
|
|
var _ry = _posi[1] * sh - fh / 2;
|
|
|
|
_rx = _x + _rx * _s;
|
|
|
|
_ry = _y + _ry * _s;
|
|
|
|
var _rw = fw * _s;
|
|
|
|
var _rh = fh * _s;
|
|
|
|
|
|
|
|
if(dragging) {
|
|
|
|
var px = drag_sx + (_mx - drag_mx) / _s;
|
|
|
|
var py = drag_sy + (_my - drag_my) / _s;
|
|
|
|
|
|
|
|
px /= sw;
|
|
|
|
py /= sh;
|
|
|
|
|
|
|
|
if(inputs[| 14].setValue([ px, py ]))
|
|
|
|
UNDO_HOLDING = true;
|
|
|
|
|
|
|
|
if(mouse_release(mb_left)) {
|
|
|
|
UNDO_HOLDING = false;
|
|
|
|
dragging = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
if(dragging || (active && point_in_rectangle(_mx, _my, _rx, _ry, _rx + _rw, _ry + _rh))) {
|
|
|
|
draw_rectangle_width(_rx, _ry, _rx + _rw, _ry + _rh, 2);
|
|
|
|
|
|
|
|
if(mouse_press(mb_left)) {
|
|
|
|
dragging = true;
|
|
|
|
drag_sx = _posi[0] * sw;
|
|
|
|
drag_sy = _posi[1] * sh;
|
|
|
|
drag_mx = _mx;
|
|
|
|
drag_my = _my;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
draw_rectangle(_rx, _ry, _rx + _rw, _ry + _rh, true);
|
|
|
|
} #endregion
|
|
|
|
|
2023-10-06 11:51:11 +02:00
|
|
|
static step = function() { #region
|
|
|
|
var _back = getSingleValue(0);
|
|
|
|
var _fore = getSingleValue(1);
|
|
|
|
var _fill = getSingleValue(5);
|
|
|
|
var _outp = getSingleValue(6);
|
|
|
|
|
|
|
|
var _atlas = is_instanceof(_fore, SurfaceAtlas);
|
|
|
|
|
2023-10-07 09:09:18 +02:00
|
|
|
inputs[| 5].setVisible(!_atlas);
|
2023-10-06 11:51:11 +02:00
|
|
|
inputs[| 6].editWidget.data_list = _atlas? [ "Background", "Forground" ] : [ "Background", "Forground", "Mask", "Maximum", "Constant" ];
|
|
|
|
inputs[| 7].setVisible(_outp == 4);
|
|
|
|
|
2023-12-15 12:56:36 +01:00
|
|
|
inputs[| 14].setVisible(_fill == 0 && !_atlas);
|
2023-11-24 10:41:53 +01:00
|
|
|
|
|
|
|
var _msk = is_surface(getSingleValue(4));
|
|
|
|
inputs[| 12].setVisible(_msk);
|
|
|
|
inputs[| 12].setVisible(_msk);
|
2023-10-06 11:51:11 +02:00
|
|
|
} #endregion
|
2023-02-15 10:43:24 +01:00
|
|
|
|
2023-09-14 16:29:39 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
|
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];
|
2023-10-06 11:51:11 +02:00
|
|
|
var _fill = _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-12-15 12:56:36 +01:00
|
|
|
var _posit = _data[14];
|
2023-11-24 10:41:53 +01:00
|
|
|
|
|
|
|
var _mskInv = _data[12];
|
|
|
|
var _mskFea = _data[13];
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
var cDep = attrDepth();
|
2023-02-15 10:43:24 +01:00
|
|
|
|
2023-12-19 14:30:34 +01:00
|
|
|
#region dimension
|
|
|
|
var ww = 1;
|
|
|
|
var hh = 1;
|
|
|
|
var _atlas = is_instanceof(_fore, SurfaceAtlas);
|
2023-02-15 10:43:24 +01:00
|
|
|
|
2023-12-19 14:30:34 +01:00
|
|
|
switch(_outp) {
|
|
|
|
case 0 :
|
|
|
|
ww = surface_get_width_safe(_back);
|
|
|
|
hh = surface_get_height_safe(_back);
|
|
|
|
break;
|
|
|
|
case 1 :
|
|
|
|
ww = surface_get_width_safe(_fore);
|
|
|
|
hh = surface_get_height_safe(_fore);
|
|
|
|
break;
|
|
|
|
case 2 :
|
|
|
|
ww = surface_get_width_safe(_mask);
|
|
|
|
hh = surface_get_height_safe(_mask);
|
|
|
|
break;
|
|
|
|
case 3 :
|
|
|
|
ww = max(surface_get_width_safe(_back), surface_get_width_safe(_fore), surface_get_width_safe(_mask));
|
|
|
|
hh = max(surface_get_height_safe(_back), surface_get_height_safe(_fore), surface_get_height_safe(_mask));
|
|
|
|
break;
|
|
|
|
case 4 :
|
|
|
|
ww = _out_dim[0];
|
|
|
|
hh = _out_dim[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endregion
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-12-19 14:30:34 +01:00
|
|
|
for( var i = 0; i < 2; i++ )
|
|
|
|
temp_surface[i] = surface_verify(temp_surface[i], ww, hh, cDep);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-12-19 14:30:34 +01:00
|
|
|
var _backDraw = temp_surface[0];
|
|
|
|
var _foreDraw = temp_surface[1];
|
|
|
|
|
2024-02-03 13:11:50 +01:00
|
|
|
surface_set_shader(_backDraw, noone,, BLEND.over);
|
|
|
|
draw_surface_safe(_back);
|
|
|
|
surface_reset_shader();
|
|
|
|
|
|
|
|
if(_fill == 0 || _atlas) {
|
2023-10-06 11:51:11 +02:00
|
|
|
if(_atlas) {
|
|
|
|
if(_outp == 0) {
|
|
|
|
surface_set_shader(_foreDraw, noone,, BLEND.over);
|
|
|
|
draw_surface_safe(_fore.getSurface(), _fore.x, _fore.y);
|
|
|
|
surface_reset_shader();
|
|
|
|
|
2023-12-19 14:30:34 +01:00
|
|
|
_backDraw = _back;
|
|
|
|
} else if(_outp == 1) {
|
2023-10-06 11:51:11 +02:00
|
|
|
surface_set_shader(_foreDraw, noone,, BLEND.over);
|
|
|
|
draw_surface_safe(_fore, 0, 0);
|
|
|
|
surface_reset_shader();
|
|
|
|
|
|
|
|
surface_set_shader(_backDraw, noone,, BLEND.over);
|
|
|
|
draw_surface_safe(_back, -_fore.x, -_fore.y);
|
|
|
|
surface_reset_shader();
|
|
|
|
}
|
|
|
|
} else if(is_surface(_fore)) {
|
|
|
|
var sx = 0;
|
|
|
|
var sy = 0;
|
|
|
|
|
|
|
|
var fw = surface_get_width_safe(_fore);
|
|
|
|
var fh = surface_get_height_safe(_fore);
|
|
|
|
|
2023-12-15 12:56:36 +01:00
|
|
|
var px = _posit[0] * ww;
|
|
|
|
var py = _posit[1] * hh;
|
|
|
|
|
2023-10-06 11:51:11 +02:00
|
|
|
surface_set_shader(_foreDraw, noone,, BLEND.over);
|
2023-12-15 12:56:36 +01:00
|
|
|
draw_surface_safe(_fore, px - fw / 2, py - fh / 2);
|
2023-10-06 11:51:11 +02:00
|
|
|
surface_reset_shader();
|
2023-12-19 14:30:34 +01:00
|
|
|
|
|
|
|
_backDraw = _back;
|
2023-10-06 11:51:11 +02:00
|
|
|
}
|
2024-02-03 13:11:50 +01:00
|
|
|
} else if(_fill == 1) {
|
|
|
|
surface_set_shader(_foreDraw, noone,, BLEND.over);
|
|
|
|
draw_surface_stretched(_fore, 0, 0, ww, hh);
|
|
|
|
surface_reset_shader();
|
|
|
|
} else if(_fill == 2) {
|
|
|
|
surface_set_shader(_foreDraw, noone,, BLEND.over);
|
|
|
|
draw_surface_tiled(_fore, 0, 0);
|
|
|
|
surface_reset_shader();
|
|
|
|
}
|
2023-10-06 11:51:11 +02:00
|
|
|
|
2023-12-19 14:30:34 +01:00
|
|
|
var _osurf = is_instanceof(_outSurf, SurfaceAtlas)? _outSurf.surface.surface : _outSurf;
|
|
|
|
var _output = surface_verify(_osurf, ww, hh, cDep);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-11-24 10:41:53 +01:00
|
|
|
_mask = mask_modify(_mask, _mskInv, _mskFea);
|
|
|
|
|
2023-10-06 11:51:11 +02:00
|
|
|
surface_set_shader(_output, noone);
|
2023-12-19 14:30:34 +01:00
|
|
|
if(is_surface(_fore)) {
|
2024-02-03 13:11:50 +01:00
|
|
|
draw_surface_blend(_backDraw, _foreDraw, _type, _opacity, _pre_alp, _mask);
|
2023-12-19 14:30:34 +01:00
|
|
|
} else {
|
|
|
|
BLEND_OVERRIDE
|
|
|
|
draw_surface(_backDraw, 0, 0);
|
|
|
|
BLEND_NORMAL
|
|
|
|
}
|
2023-10-06 11:51:11 +02:00
|
|
|
surface_reset_shader();
|
|
|
|
|
|
|
|
if(_atlas) {
|
|
|
|
var _newAtl = _fore.clone();
|
2023-10-07 09:09:18 +02:00
|
|
|
|
|
|
|
if(_outp == 0) {
|
|
|
|
_newAtl.x = 0;
|
|
|
|
_newAtl.y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_newAtl.setSurface(_output);
|
2023-10-06 11:51:11 +02:00
|
|
|
return _newAtl;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
return _outSurf;
|
2023-09-14 16:29:39 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|