Pixel-Composer/scripts/node_composite/node_composite.gml

896 lines
27 KiB
Text
Raw Normal View History

2023-01-17 08:11:55 +01:00
enum NODE_COMPOSE_DRAG {
move,
rotate,
scale
}
2022-01-13 05:24:03 +01:00
enum COMPOSE_OUTPUT_SCALING {
first,
largest,
constant
}
2023-02-28 09:43:01 +01:00
function Node_Composite(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Composite";
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Padding", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 0, 0, 0, 0 ])
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.padding);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Output dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, COMPOSE_OUTPUT_SCALING.first)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "First surface", "Largest surface", "Constant" ]);
2022-01-13 05:24:03 +01:00
2023-07-21 12:40:20 +02:00
inputs[| 2] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
2022-09-23 13:28:42 +02:00
.setDisplay(VALUE_DISPLAY.vector)
.setVisible(false);
2022-01-13 05:24:03 +01:00
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-03-21 03:01:53 +01:00
attribute_interpolation();
2023-03-19 09:17:39 +01:00
2023-09-14 16:29:39 +02:00
attributes.layer_visible = [];
2023-06-13 14:42:06 +02:00
attributes.layer_selectable = [];
2024-03-14 14:35:19 +01:00
properties_expand = [];
2022-09-23 13:28:42 +02:00
hold_visibility = true;
hold_select = true;
layer_dragging = noone;
layer_remove = -1;
layer_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region
2022-09-23 13:28:42 +02:00
var amo = (ds_list_size(inputs) - input_fix_len) / data_length - 1;
2023-02-17 04:48:54 +01:00
if(array_length(current_data) != ds_list_size(inputs)) return 0;
2022-09-27 06:37:28 +02:00
2024-03-14 14:35:19 +01:00
var lh = 28;
var eh = 36;
properties_expand = array_verify(properties_expand, amo);
var _h = 4;
for(var i = 0; i < amo; i++)
_h += lh + 4 + properties_expand[i] * eh;
2022-09-23 13:28:42 +02:00
layer_renderer.h = _h;
2024-03-14 14:35:19 +01:00
2022-11-18 03:20:31 +01:00
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _h, COLORS.node_composite_bg_blend, 1);
2022-09-23 13:28:42 +02:00
2023-06-13 14:42:06 +02:00
var _vis = attributes.layer_visible;
var _sel = attributes.layer_selectable;
2024-03-14 14:35:19 +01:00
var ly = _y + 4;
var ssh = lh - 4;
2022-09-23 13:28:42 +02:00
var hoverIndex = noone;
2024-03-14 14:35:19 +01:00
var _cy = ly;
2022-09-23 13:28:42 +02:00
2022-09-27 06:37:28 +02:00
layer_remove = -1;
2022-09-23 13:28:42 +02:00
for(var i = 0; i < amo; i++) {
2023-09-14 16:29:39 +02:00
var ind = amo - i - 1;
2022-09-23 13:28:42 +02:00
var index = input_fix_len + ind * data_length;
var _surf = current_data[index + 0];
var _pos = current_data[index + 1];
2022-09-27 06:37:28 +02:00
var _bx = _x + _w - 24;
2024-03-14 14:35:19 +01:00
var aa = (ind != layer_dragging || layer_dragging == noone)? 1 : 0.5;
var vis = _vis[ind];
var sel = _sel[ind];
var _exp = properties_expand[i];
var _lh = lh + 4 + _exp * eh;
if(_exp) { #region extended
var _px = _x + 4;
var _py = _cy + lh + 4;
var _pw = _w - 8;
var _ph = eh - 4;
var _pww = (_pw - 8) / 2 - 8;
var _pwh = _ph - 8;
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, _px, _py, _pw, _ph, COLORS.node_composite_bg_blend, 1);
var jun = inputs[| index + 4];
var bl_wid = jun.editWidget;
var _param = new widgetParam(_px + 4, _py + 4, _pww, _pwh, jun.showValue(), jun.display_data, _m, layer_renderer.rx, layer_renderer.ry);
bl_wid.setFocusHover(_focus, _hover);
bl_wid.font = f_p2;
bl_wid.drawParam(_param);
bl_wid.font = f_p0;
var jun = inputs[| index + 5];
var bl_wid = jun.editWidget;
var _param = new widgetParam(_px + 4 + _pww + 8, _py + 4, _pww, _pwh, jun.showValue(), jun.display_data, _m, layer_renderer.rx, layer_renderer.ry);
bl_wid.setFocusHover(_focus, _hover);
bl_wid.drawParam(_param);
} #endregion
2022-09-27 06:37:28 +02:00
if(point_in_circle(_m[0], _m[1], _bx, _cy + lh / 2, 16)) {
2022-11-18 03:20:31 +01:00
draw_sprite_ui_uniform(THEME.icon_delete, 3, _bx, _cy + lh / 2, 1, COLORS._main_value_negative);
2022-09-27 06:37:28 +02:00
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left, _focus))
2022-09-27 06:37:28 +02:00
layer_remove = ind;
} else
2022-11-18 03:20:31 +01:00
draw_sprite_ui_uniform(THEME.icon_delete, 3, _bx, _cy + lh / 2, 1, COLORS._main_icon);
2022-09-27 06:37:28 +02:00
if(!is_surface(_surf)) continue;
2022-09-23 13:28:42 +02:00
2024-03-14 14:35:19 +01:00
var _bx = _x + 16 + 24;
2022-09-27 06:37:28 +02:00
if(point_in_circle(_m[0], _m[1], _bx, _cy + lh / 2, 12)) {
2022-11-18 03:20:31 +01:00
draw_sprite_ui_uniform(THEME.junc_visible, vis, _bx, _cy + lh / 2, 1, c_white);
2022-09-23 13:28:42 +02:00
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left, _focus))
2023-06-13 14:42:06 +02:00
hold_visibility = !_vis[ind];
2022-09-23 13:28:42 +02:00
2023-06-13 14:42:06 +02:00
if(mouse_click(mb_left, _focus) && _vis[ind] != hold_visibility) {
2023-09-14 16:29:39 +02:00
_vis[ind] = hold_visibility;
2023-03-28 06:58:28 +02:00
doUpdate();
2022-09-23 13:28:42 +02:00
}
} else
2023-01-17 08:11:55 +01:00
draw_sprite_ui_uniform(THEME.junc_visible, vis, _bx, _cy + lh / 2, 1, COLORS._main_icon, 0.5 + 0.5 * vis);
2024-03-14 14:35:19 +01:00
_bx += 12 + 1 + 12;
2023-01-17 08:11:55 +01:00
if(point_in_circle(_m[0], _m[1], _bx, _cy + lh / 2, 12)) {
draw_sprite_ui_uniform(THEME.cursor_select, sel, _bx, _cy + lh / 2, 1, c_white);
if(mouse_press(mb_left, _focus))
2023-06-13 14:42:06 +02:00
hold_select = !_sel[ind];
2023-01-17 08:11:55 +01:00
2023-06-13 14:42:06 +02:00
if(mouse_click(mb_left, _focus) && _sel[ind] != hold_select)
2023-09-14 16:29:39 +02:00
_sel[ind] = hold_select;
2023-01-17 08:11:55 +01:00
} else
draw_sprite_ui_uniform(THEME.cursor_select, sel, _bx, _cy + lh / 2, 1, COLORS._main_icon, 0.5 + 0.5 * sel);
2022-09-23 13:28:42 +02:00
2024-03-14 14:35:19 +01:00
var hover = point_in_rectangle(_m[0], _m[1], _bx + 12 + 6, _cy, _x + _w - 48, _cy + lh - 1);
var _sx0 = _bx + 12 + 6;
2022-09-23 13:28:42 +02:00
var _sx1 = _sx0 + ssh;
var _sy0 = _cy + 3;
var _sy1 = _sy0 + ssh;
2023-09-08 21:37:36 +02:00
var _ssw = surface_get_width_safe(_surf);
var _ssh = surface_get_height_safe(_surf);
2022-09-23 13:28:42 +02:00
var _sss = min(ssh / _ssw, ssh / _ssh);
2023-03-19 09:17:39 +01:00
draw_surface_ext_safe(_surf, _sx0, _sy0, _sss, _sss, 0, c_white, 1);
2022-09-23 13:28:42 +02:00
2024-03-14 14:35:19 +01:00
draw_set_text(f_p1, fa_left, fa_center, hover? COLORS._main_text_accent : COLORS._main_text);
2022-09-23 13:28:42 +02:00
draw_set_alpha(aa);
2024-03-14 14:35:19 +01:00
draw_text(_sx1 + 12, _cy + lh / 2 + 2, inputs[| index].name);
2022-09-23 13:28:42 +02:00
draw_set_alpha(1);
if(_hover && point_in_rectangle(_m[0], _m[1], _x, _cy, _x + _w, _cy + lh)) {
hoverIndex = ind;
if(layer_dragging != noone) {
2022-11-18 03:20:31 +01:00
draw_set_color(COLORS._main_accent);
2022-09-23 13:28:42 +02:00
if(layer_dragging > ind)
draw_line_width(_x + 16, _cy + lh + 2, _x + _w - 16, _cy + lh + 2, 2);
else if(layer_dragging < ind)
draw_line_width(_x + 16, _cy - 2, _x + _w - 16, _cy - 2, 2);
}
}
2024-03-14 14:35:19 +01:00
var _bx = _x + 8 + 8;
var cc = COLORS._main_icon;
if(point_in_rectangle(_m[0], _m[1], _bx - 8, _cy + 4, _bx + 8, _cy + lh - 4)) {
cc = c_white;
2022-09-23 13:28:42 +02:00
2024-03-14 14:35:19 +01:00
if(mouse_press(mb_left, _focus))
properties_expand[i] = !properties_expand[i];
2022-09-23 13:28:42 +02:00
}
2024-03-14 14:35:19 +01:00
draw_sprite_ui_uniform(THEME.arrow, _exp? 3 : 0, _bx, _cy + lh / 2 + _exp * 2, 1, cc);
if(hover && layer_dragging == noone || layer_dragging == ind) {
if(mouse_press(mb_left, _focus))
layer_dragging = ind;
}
_cy += _lh;
2022-09-23 13:28:42 +02:00
}
2022-12-10 05:06:01 +01:00
if(layer_dragging != noone && mouse_release(mb_left)) {
2022-09-23 13:28:42 +02:00
if(layer_dragging != hoverIndex && hoverIndex != noone) {
var index = input_fix_len + layer_dragging * data_length;
var targt = input_fix_len + hoverIndex * data_length;
2023-06-13 14:42:06 +02:00
var _vis = attributes.layer_visible;
var _sel = attributes.layer_selectable;
2022-09-23 13:28:42 +02:00
var ext = [];
2023-06-13 14:42:06 +02:00
var vis = _vis[layer_dragging];
array_delete(_vis, layer_dragging, 1);
array_insert(_vis, hoverIndex, vis);
2022-09-23 13:28:42 +02:00
2023-06-13 14:42:06 +02:00
var sel = _sel[layer_dragging];
array_delete(_sel, layer_dragging, 1);
array_insert(_sel, hoverIndex, sel);
2023-01-17 08:11:55 +01:00
2022-09-23 13:28:42 +02:00
for( var i = 0; i < data_length; i++ ) {
ext[i] = inputs[| index];
ds_list_delete(inputs, index);
}
2023-01-17 08:11:55 +01:00
2023-09-14 16:29:39 +02:00
for( var i = 0; i < data_length; i++ )
2022-09-23 13:28:42 +02:00
ds_list_insert(inputs, targt + i, ext[i]);
2023-03-28 06:58:28 +02:00
doUpdate();
2022-09-23 13:28:42 +02:00
}
2023-06-13 14:42:06 +02:00
2022-09-23 13:28:42 +02:00
layer_dragging = noone;
}
2023-01-09 03:14:20 +01:00
return _h;
2023-09-09 13:52:16 +02:00
}); #endregion
2022-09-23 13:28:42 +02:00
2022-01-13 05:24:03 +01:00
input_display_list = [
2023-05-03 21:42:17 +02:00
["Output", true], 0, 1, 2,
2022-09-23 13:28:42 +02:00
["Layers", false], layer_renderer,
2023-05-03 21:42:17 +02:00
["Surfaces", true],
2022-01-13 05:24:03 +01:00
];
2024-03-14 14:35:19 +01:00
2022-09-27 06:37:28 +02:00
input_display_list_len = array_length(input_display_list);
2024-03-14 14:35:19 +01:00
setIsDynamicInput(6);
2022-09-27 06:37:28 +02:00
2023-09-09 13:52:16 +02:00
function deleteLayer(index) { #region
2022-09-27 06:37:28 +02:00
var idx = input_fix_len + index * data_length;
2024-03-14 14:35:19 +01:00
2022-09-27 06:37:28 +02:00
for( var i = 0; i < data_length; i++ ) {
ds_list_delete(inputs, idx);
array_remove(input_display_list, idx + i);
}
2023-06-25 20:12:17 +02:00
2022-09-27 06:37:28 +02:00
for( var i = input_display_list_len; i < array_length(input_display_list); i++ ) {
if(input_display_list[i] > idx)
input_display_list[i] = input_display_list[i] - data_length;
}
2023-06-25 20:12:17 +02:00
if(ds_list_size(inputs) == input_fix_len)
2023-08-05 14:00:33 +02:00
createNewInput();
2023-03-28 06:58:28 +02:00
doUpdate();
2023-09-09 13:52:16 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-09-09 13:52:16 +02:00
static createNewInput = function() { #region
2022-01-13 05:24:03 +01:00
var index = ds_list_size(inputs);
var _s = floor((index - input_fix_len) / data_length);
2024-03-14 14:35:19 +01:00
inputs[| index + 0] = nodeValue(_s? ($"Surface {_s}") : "Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
2023-03-12 02:28:21 +01:00
inputs[| index + 0].hover_effect = 0;
2022-01-13 05:24:03 +01:00
2024-03-14 14:35:19 +01:00
inputs[| index + 1] = nodeValue($"Position {_s}", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0 ] )
2023-01-17 08:11:55 +01:00
.setDisplay(VALUE_DISPLAY.vector)
.setUnitRef(function(index) { return [ overlay_w, overlay_h ]; });
2022-01-13 05:24:03 +01:00
2024-03-14 14:35:19 +01:00
inputs[| index + 2] = nodeValue($"Rotation {_s}", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.rotation);
2022-01-13 05:24:03 +01:00
2024-03-14 14:35:19 +01:00
inputs[| index + 3] = nodeValue($"Scale {_s}", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ] )
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2022-01-13 05:24:03 +01:00
2024-03-14 14:35:19 +01:00
inputs[| index + 4] = nodeValue($"Blend {_s}", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, BLEND_TYPES );
inputs[| index + 5] = nodeValue($"Opacity {_s}", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider);
for( var i = 0; i < data_length; i++ ) {
array_push(input_display_list, index + i);
inputs[| index + i].surface_index = index;
}
2022-09-23 13:28:42 +02:00
2023-06-13 14:42:06 +02:00
while(_s >= array_length(attributes.layer_visible))
array_push(attributes.layer_visible, true);
2024-03-14 14:35:19 +01:00
2023-06-13 14:42:06 +02:00
while(_s >= array_length(attributes.layer_selectable))
array_push(attributes.layer_selectable, true);
2024-03-14 14:35:19 +01:00
} if(!LOADING && !APPENDING) createNewInput(); #endregion
2022-01-13 05:24:03 +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-10-06 11:51:11 +02:00
outputs[| 1] = nodeValue("Atlas data", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, [])
2023-05-28 20:00:51 +02:00
.rejectArrayProcess();
2023-04-16 15:26:52 +02:00
temp_surface = [ surface_create(1, 1), surface_create(1, 1), surface_create(1, 1) ];
blend_temp_surface = temp_surface[2];
2022-01-13 05:24:03 +01:00
surf_dragging = -1;
2022-01-13 05:24:03 +01:00
input_dragging = -1;
2024-03-14 14:35:19 +01:00
drag_type = 0;
dragging_sx = 0;
dragging_sy = 0;
dragging_mx = 0;
dragging_my = 0;
2022-01-13 05:24:03 +01:00
rot_anc_x = 0;
rot_anc_y = 0;
overlay_w = 0;
overlay_h = 0;
2023-04-16 15:26:52 +02:00
atlas_data = [];
2023-07-05 15:09:52 +02:00
surface_selecting = noone;
2024-03-14 14:35:19 +01:00
static getInputAmount = function() { INLINE return input_fix_len + (ds_list_size(inputs) - input_fix_len) / data_length; }
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
//static getInputIndex = function(index) { #region
// INLINE
2024-03-14 14:35:19 +01:00
2024-03-31 11:10:14 +02:00
// if(index < input_fix_len) return index;
// return input_fix_len + (index - input_fix_len) * data_length;
//} #endregion
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
//static setHeight = function() { #region
// var _hi = ui(32);
// var _ho = ui(32);
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// for( var i = 0; i < getInputAmount(); i++ )
// if(inputs[| getInputIndex(i)].isVisible())
// _hi += 24;
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// for( var i = 0; i < ds_list_size(outputs); i++ )
// if(outputs[| i].isVisible())
// _ho += 24;
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// h = max(min_h, (preview_surface && previewable)? 128 : 0, _hi, _ho);
//} #endregion
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
//static drawJunctions = function(_x, _y, _mx, _my, _s) { #region
// if(!active) return;
// var hover = noone;
// var amo = array_length(input_display_list);
// var hov = PANEL_GRAPH.value_focus;
// var ind = -1;
// if(hov != noone && struct_has(hov, "surface_index"))
// ind = hov.surface_index;
// for( var i = 0; i < getInputAmount(); i++ ) {
// var idx = getInputIndex(i);
// if(!inputs[| idx].isVisible()) continue;
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// if(inputs[| idx].drawJunction(_s, _mx, _my, 1.5))
// hover = inputs[| idx];
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// if(idx >= input_fix_len && inputs[| idx].hover_effect > 0) {
// var _px0 = 999999;
// var _py0 = 999999;
// var _px1 = -999999;
// var _py1 = -999999;
// var _drw = false;
// var _hov = inputs[| idx].hover_effect;
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// for( var j = 1; j < data_length; j++ ) {
// if(!inputs[| idx + j].isVisible()) continue;
// _px0 = min( _px0, inputs[| idx + j].x );
// _py0 = min( _py0, inputs[| idx + j].y );
// _px1 = max( _px1, inputs[| idx + j].x );
// _py1 = max( _py1, inputs[| idx + j].y );
// _drw = true;
// }
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// if(!_drw) continue;
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// //if(_hov > 0.5) {
// // var pilx = _px0 - 16 * _s;
// // var pily = _py0 - 16 * _s;
// // var pilw = _px1 - _px0 + 32 * _s;
// // var pilh = _py1 - _py0 + 32 * _s;
2023-04-08 20:06:27 +02:00
2024-03-31 11:10:14 +02:00
// // draw_sprite_stretched_ext(THEME.node_bg_pill, 0, pilx, pily, pilw, pilh, COLORS._main_icon_dark, (_hov - 0.5) * 2);
// //}
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// for( var j = 1; j < data_length; j++ ) {
// if(inputs[| idx + j].drawJunction(_s, _mx, _my, 1.5))
// hover = inputs[| idx + j];
// }
// }
// }
// for(var i = 0; i < ds_list_size(outputs); i++)
// if(outputs[| i].drawJunction(_s, _mx, _my))
// hover = outputs[| i];
// return hover;
//} #endregion
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
//static drawJunctionNames = function(_x, _y, _mx, _my, _s) { #region
// if(!active) return;
// var amo = input_display_list == -1? ds_list_size(inputs) : array_length(input_display_list);
// var jun;
// var xx = x * _s + _x;
// var yy = y * _s + _y;
// show_input_name = PANEL_GRAPH.pHOVER && point_in_rectangle(_mx, _my, xx - 8 * _s, yy + 20 * _s, xx + 8 * _s, yy + h * _s);
// show_output_name = PANEL_GRAPH.pHOVER && point_in_rectangle(_mx, _my, xx + (w - 8) * _s, yy + 20 * _s, xx + (w + 8) * _s, yy + h * _s);
// var hov = PANEL_GRAPH.value_focus;
// var ind = -1;
// if(hov != noone && struct_has(hov, "surface_index"))
// ind = hov.surface_index;
// if(ind != -1) {
// for( var j = 1; j < data_length; j++ ) {
// if(ind + j >= ds_list_size(inputs)) break;
// inputs[| ind + j].drawNameBG(_s);
// }
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// for( var j = 1; j < data_length; j++ ) {
// if(ind + j >= ds_list_size(inputs)) break;
// inputs[| ind + j].drawName(_s, _mx, _my);
// }
2023-04-05 20:13:27 +02:00
2024-03-31 11:10:14 +02:00
// } else if(show_input_name) {
// for( var i = 0; i < getInputAmount(); i++ ) {
// var idx = getInputIndex(i);
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// if(idx == ind) continue;
// inputs[| idx].drawNameBG(_s);
// }
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// for( var i = 0; i < getInputAmount(); i++ ) {
// var idx = getInputIndex(i);
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// if(idx == ind) continue;
// inputs[| idx].drawName(_s, _mx, _my);
// }
// }
// if(show_output_name) {
// for(var i = 0; i < ds_list_size(outputs); i++)
// outputs[| i].drawNameBG(_s);
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// for(var i = 0; i < ds_list_size(outputs); i++)
// outputs[| i].drawName(_s, _mx, _my);
// }
//} #endregion
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
//static preDraw = function(_x, _y, _s) { #region
// var xx = x * _s + _x;
// var yy = y * _s + _y;
// var jun;
// var inamo = input_display_list == -1? ds_list_size(inputs) : array_length(input_display_list);
// var _in = yy + ui(32) * _s;
// var hov = PANEL_GRAPH.value_focus;
// var ind = -1;
// if(hov != noone && struct_has(hov, "surface_index"))
// ind = hov.surface_index;
// for( var i = 0; i < getInputAmount(); i++ ) {
// var idx = getInputIndex(i);
// jun = ds_list_get(inputs, idx, noone);
// if(jun == noone || is_undefined(jun)) continue;
// jun.x = xx;
// jun.y = _in;
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// if(i >= input_fix_len) {
// jun.hover_effect = lerp_float(jun.hover_effect, ind == idx, 3);
// var sp = jun.hover_effect * 24;
// var sx = xx - sp * _s;
// var sy = _in;
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// for( var j = 1; j < data_length; j++ ) {
// var _jun = ds_list_get(inputs, idx + j, noone);
// _jun.x = sx;
// _jun.y = sy;
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// sy += sp * _s * _jun.isVisible();
// }
// }
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// _in += 24 * _s * jun.isVisible();
// }
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// var outamo = output_display_list == -1? ds_list_size(outputs) : array_length(output_display_list);
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// xx = xx + w * _s;
// _in = yy + ui(32) * _s;
// for(var i = 0; i < outamo; i++) {
// var idx = getOutputJunctionIndex(i);
// jun = outputs[| idx];
2023-03-12 02:28:21 +01:00
2024-03-31 11:10:14 +02:00
// jun.x = xx;
// jun.y = _in;
// _in += 24 * _s * jun.isVisible();
// }
//} #endregion
2023-03-12 02:28:21 +01:00
2023-09-09 13:52:16 +02:00
static onValueFromUpdate = function(index) { #region
2022-12-21 02:30:23 +01:00
if(LOADING || APPENDING) return;
2022-01-13 05:24:03 +01:00
if(index + data_length >= ds_list_size(inputs))
2023-08-05 14:00:33 +02:00
createNewInput();
2023-09-09 13:52:16 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
var pad = getInputData(0);
2022-01-13 05:24:03 +01:00
var ww = overlay_w;
var hh = overlay_h;
var x0 = _x + pad[2] * _s;
var x1 = _x + (ww - pad[0]) * _s;
var y0 = _y + pad[1] * _s;
var y1 = _y + (hh - pad[3]) * _s;
if(input_dragging > -1) {
2023-01-17 08:11:55 +01:00
if(drag_type == NODE_COMPOSE_DRAG.move) {
var _dx = (_mx - dragging_mx) / _s;
var _dy = (_my - dragging_my) / _s;
if(key_mod_press(SHIFT)) {
if(abs(_dx) > abs(_dy) + ui(16))
_dy = 0;
else if(abs(_dy) > abs(_dx) + ui(16))
_dx = 0;
else {
_dx = max(_dx, _dy);
_dy = _dx;
}
}
var pos_x = value_snap(dragging_sx + _dx, _snx);
var pos_y = value_snap(dragging_sy + _dy, _sny);
if(key_mod_press(ALT)) {
var _surf = current_data[input_dragging - 1];
2023-09-08 21:37:36 +02:00
var _sw = surface_get_width_safe(_surf);
var _sh = surface_get_height_safe(_surf);
2023-01-17 08:11:55 +01:00
var x0 = pos_x, x1 = pos_x + _sw;
var y0 = pos_y, y1 = pos_y + _sh;
var xc = (x0 + x1) / 2;
var yc = (y0 + y1) / 2;
var snap = 4;
draw_set_color(COLORS._main_accent);
if(abs(x0 - 0) < snap) {
pos_x = 0;
draw_line_width(_x + _s * 0, 0, _x + _s * 0, WIN_H, 2);
}
if(abs(y0 - 0) < snap) {
pos_y = 0;
draw_line_width(0, _y + _s * 0, WIN_W, _y + _s * 0, 2);
}
if(abs(x1 - ww) < snap) {
pos_x = ww - _sw;
draw_line_width(_x + _s * ww, 0, _x + _s * ww, WIN_H, 2);
}
if(abs(y1 - hh) < snap) {
pos_y = hh - _sh;
draw_line_width(0, _y + _s * hh, WIN_W, _y + _s * hh, 2);
}
if(abs(xc - ww / 2) < snap) {
pos_x = ww / 2 - _sw / 2;
draw_line_width(_x + _s * ww / 2, 0, _x + _s * ww / 2, WIN_H, 2);
}
if(abs(yc - hh / 2) < snap) {
pos_y = hh / 2 - _sh / 2;
draw_line_width(0, _y + _s * hh / 2, WIN_W, _y + _s * hh / 2, 2);
}
}
2022-12-19 13:35:30 +01:00
2022-01-13 05:24:03 +01:00
if(inputs[| input_dragging].setValue([ pos_x, pos_y ]))
UNDO_HOLDING = true;
2023-01-17 08:11:55 +01:00
} else if(drag_type == NODE_COMPOSE_DRAG.rotate) {
2022-01-13 05:24:03 +01:00
var aa = point_direction(rot_anc_x, rot_anc_y, _mx, _my);
var da = angle_difference(dragging_mx, aa);
var sa;
2022-12-22 03:09:55 +01:00
if(key_mod_press(CTRL))
2022-01-13 05:24:03 +01:00
sa = round((dragging_sx - da) / 15) * 15;
else
sa = dragging_sx - da;
if(inputs[| input_dragging].setValue(sa))
UNDO_HOLDING = true;
2023-01-17 08:11:55 +01:00
} else if(drag_type == NODE_COMPOSE_DRAG.scale) {
var _surf = getInputData(surf_dragging + 0);
var _rot = getInputData(surf_dragging + 2);
2023-09-08 21:37:36 +02:00
var _sw = surface_get_width_safe(_surf);
var _sh = surface_get_height_safe(_surf);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
var _p = point_rotate(_mx - dragging_mx, _my - dragging_my, 0, 0, -_rot);
var sca_x = _p[0] / _s / _sw * 2;
var sca_y = _p[1] / _s / _sh * 2;
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
if(key_mod_press(SHIFT)) {
2022-01-13 05:24:03 +01:00
sca_x = min(sca_x, sca_y);
sca_y = min(sca_x, sca_y);
}
if(inputs[| input_dragging].setValue([ sca_x, sca_y ]))
UNDO_HOLDING = true;
}
2022-12-10 05:06:01 +01:00
if(mouse_release(mb_left)) {
2022-01-13 05:24:03 +01:00
input_dragging = -1;
UNDO_HOLDING = false;
}
}
2023-09-14 16:29:39 +02:00
var hovering = noone;
2023-07-05 15:09:52 +02:00
var hovering_type = noone;
2023-06-13 14:42:06 +02:00
var _vis = attributes.layer_visible;
var _sel = attributes.layer_selectable;
2022-01-13 05:24:03 +01:00
var amo = (ds_list_size(inputs) - input_fix_len) / data_length;
2022-09-21 06:09:40 +02:00
if(array_length(current_data) < input_fix_len + amo * data_length)
return;
2023-07-05 15:09:52 +02:00
var anchors = array_create(ds_list_size(inputs));
2022-01-13 05:24:03 +01:00
for(var i = 0; i < amo; i++) {
2023-06-13 14:42:06 +02:00
var vis = _vis[i];
var sel = _sel[i];
2022-09-23 13:28:42 +02:00
2022-01-13 05:24:03 +01:00
var index = input_fix_len + i * data_length;
var _surf = current_data[index + 0];
var _pos = current_data[index + 1];
2023-02-14 05:32:32 +01:00
var _rot = current_data[index + 2];
var _sca = current_data[index + 3];
2022-01-13 05:24:03 +01:00
if(!_surf || is_array(_surf)) continue;
2023-09-08 21:37:36 +02:00
var _ww = surface_get_width_safe(_surf);
var _hh = surface_get_height_safe(_surf);
2023-02-14 05:32:32 +01:00
var _sw = _ww * _sca[0];
var _sh = _hh * _sca[1];
2023-07-05 15:09:52 +02:00
var _cx = _pos[0] + _ww / 2;
var _cy = _pos[1] + _hh / 2;
2023-02-14 05:32:32 +01:00
2023-07-05 15:09:52 +02:00
var _d0 = point_rotate(_cx - _sw / 2, _cy - _sh / 2, _cx, _cy, _rot);
var _d1 = point_rotate(_cx - _sw / 2, _cy + _sh / 2, _cx, _cy, _rot);
var _d2 = point_rotate(_cx + _sw / 2, _cy - _sh / 2, _cx, _cy, _rot);
var _d3 = point_rotate(_cx + _sw / 2, _cy + _sh / 2, _cx, _cy, _rot);
var _rr = point_rotate(_cx, _cy - _sh / 2 - 1, _cx, _cy, _rot);
2023-02-14 05:32:32 +01:00
_d0[0] = overlay_x(_d0[0], _x, _s); _d0[1] = overlay_y(_d0[1], _y, _s);
_d1[0] = overlay_x(_d1[0], _x, _s); _d1[1] = overlay_y(_d1[1], _y, _s);
_d2[0] = overlay_x(_d2[0], _x, _s); _d2[1] = overlay_y(_d2[1], _y, _s);
_d3[0] = overlay_x(_d3[0], _x, _s); _d3[1] = overlay_y(_d3[1], _y, _s);
_rr[0] = overlay_x(_rr[0], _x, _s); _rr[1] = overlay_y(_rr[1], _y, _s);
2022-01-13 05:24:03 +01:00
2023-07-05 15:09:52 +02:00
anchors[index] = {
cx: _cx,
cy: _cy,
d0: _d0,
d1: _d1,
d2: _d2,
d3: _d3,
rr: _rr,
rot: _rot,
}
}
for(var i = 0; i < amo; i++) {
var vis = _vis[i];
var sel = _sel[i];
if(!vis) continue;
2022-01-13 05:24:03 +01:00
2023-07-05 15:09:52 +02:00
var index = input_fix_len + i * data_length;
var _surf = current_data[index + 0];
var _pos = current_data[index + 1];
var _rot = current_data[index + 2];
var _sca = current_data[index + 3];
2022-01-13 05:24:03 +01:00
2023-07-05 15:09:52 +02:00
if(!_surf || is_array(_surf)) continue;
2023-01-17 08:11:55 +01:00
2023-07-05 15:09:52 +02:00
var a = anchors[index];
if(surface_selecting == index) {
var _ri = 0;
var _si = 0;
if(point_in_circle(_mx, _my, a.d3[0], a.d3[1], 12)) {
hovering = index;
hovering_type = NODE_COMPOSE_DRAG.scale;
_si = 1;
} else if(point_in_rectangle_points(_mx, _my, a.d0[0], a.d0[1], a.d1[0], a.d1[1], a.d2[0], a.d2[1], a.d3[0], a.d3[1])) {
hovering = index;
hovering_type = NODE_COMPOSE_DRAG.move;
} else if(point_in_circle(_mx, _my, a.rr[0], a.rr[1], 12)) {
hovering = index;
hovering_type = NODE_COMPOSE_DRAG.rotate;
_ri = 1;
}
draw_sprite_colored(THEME.anchor_rotate, _ri, a.rr[0], a.rr[1],, a.rot);
draw_sprite_colored(THEME.anchor_scale, _si, a.d3[0], a.d3[1],, a.rot);
2023-07-30 19:56:53 +02:00
} else if(point_in_rectangle_points(_mx, _my, a.d0[0], a.d0[1], a.d1[0], a.d1[1], a.d2[0], a.d2[1], a.d3[0], a.d3[1]) &&
(hovering != surface_selecting || surface_selecting == noone)) {
2022-01-13 05:24:03 +01:00
hovering = index;
2023-01-17 08:11:55 +01:00
hovering_type = NODE_COMPOSE_DRAG.move;
2022-01-13 05:24:03 +01:00
}
}
2023-07-05 15:09:52 +02:00
if(mouse_press(mb_left, active))
surface_selecting = hovering;
if(surface_selecting != noone) {
2024-03-31 05:36:11 +02:00
var a = array_safe_get_fast(anchors, surface_selecting, noone);
if(!is_struct(a)) surface_selecting = noone;
}
2023-07-05 15:09:52 +02:00
if(hovering != noone) {
var a = anchors[hovering];
draw_set_color(COLORS.node_composite_overlay_border);
draw_line(a.d0[0], a.d0[1], a.d1[0], a.d1[1]);
draw_line(a.d0[0], a.d0[1], a.d2[0], a.d2[1]);
draw_line(a.d3[0], a.d3[1], a.d1[0], a.d1[1]);
draw_line(a.d3[0], a.d3[1], a.d2[0], a.d2[1]);
}
if(surface_selecting != noone) {
var a = anchors[surface_selecting];
draw_set_color(COLORS._main_accent);
draw_line(a.d0[0], a.d0[1], a.d1[0], a.d1[1]);
draw_line(a.d0[0], a.d0[1], a.d2[0], a.d2[1]);
draw_line(a.d3[0], a.d3[1], a.d1[0], a.d1[1]);
draw_line(a.d3[0], a.d3[1], a.d2[0], a.d2[1]);
}
if(hovering != noone && mouse_press(mb_left, active)) {
var a = anchors[hovering];
2023-02-14 05:32:32 +01:00
2023-01-17 08:11:55 +01:00
if(hovering_type == NODE_COMPOSE_DRAG.move) {
2023-07-05 15:09:52 +02:00
surf_dragging = hovering;
input_dragging = hovering + 1;
drag_type = hovering_type;
dragging_sx = current_data[hovering + 1][0];
dragging_sy = current_data[hovering + 1][1];
dragging_mx = _mx;
dragging_my = _my;
2023-01-17 08:11:55 +01:00
} else if(hovering_type == NODE_COMPOSE_DRAG.rotate) { //rot
2023-07-05 15:09:52 +02:00
surf_dragging = hovering;
input_dragging = hovering + 2;
drag_type = hovering_type;
dragging_sx = current_data[hovering + 2];
rot_anc_x = overlay_x(a.cx, _x, _s);
rot_anc_y = overlay_y(a.cy, _y, _s);
dragging_mx = point_direction(rot_anc_x, rot_anc_y, _mx, _my);
2023-01-17 08:11:55 +01:00
} else if(hovering_type == NODE_COMPOSE_DRAG.scale) { //sca
2023-07-05 15:09:52 +02:00
surf_dragging = hovering;
input_dragging = hovering + 3;
drag_type = hovering_type;
dragging_sx = _sca[0];
dragging_sy = _sca[1];
dragging_mx = (a.d0[0] + a.d3[0]) / 2;
dragging_my = (a.d0[1] + a.d3[1]) / 2;
2022-01-13 05:24:03 +01:00
}
}
2022-09-27 06:37:28 +02:00
if(layer_remove > -1) {
deleteLayer(layer_remove);
layer_remove = -1;
}
2023-09-09 13:52:16 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-09-09 13:52:16 +02:00
static step = function() { #region
2023-06-01 10:32:21 +02:00
var _dim_type = getSingleValue(1);
inputs[| 2].setVisible(_dim_type == COMPOSE_OUTPUT_SCALING.constant);
2023-09-09 13:52:16 +02:00
} #endregion
2023-06-01 10:32:21 +02:00
2023-09-09 13:52:16 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
2023-04-16 15:26:52 +02:00
if(_output_index == 1) return atlas_data;
2023-05-28 20:00:51 +02:00
if(_output_index == 0 && _array_index == 0) atlas_data = [];
2023-04-16 15:26:52 +02:00
2024-03-14 14:35:19 +01:00
if(array_length(_data) <= input_fix_len) return _outSurf;
2023-03-19 09:17:39 +01:00
var _pad = _data[0];
2022-01-13 05:24:03 +01:00
var _dim_type = _data[1];
2023-03-19 09:17:39 +01:00
var _dim = _data[2];
var base = _data[3];
var cDep = attrDepth();
2022-01-13 05:24:03 +01:00
2024-03-14 14:35:19 +01:00
#region dimension
var ww = 0, hh = 0;
switch(_dim_type) {
case COMPOSE_OUTPUT_SCALING.first :
ww = surface_get_width_safe(base);
hh = surface_get_height_safe(base);
break;
case COMPOSE_OUTPUT_SCALING.largest :
for(var i = input_fix_len; i < array_length(_data) - data_length; i += data_length) {
var _s = _data[i];
ww = max(ww, surface_get_width_safe(_s));
hh = max(hh, surface_get_height_safe(_s));
}
break;
case COMPOSE_OUTPUT_SCALING.constant :
ww = _dim[0];
hh = _dim[1];
break;
}
ww += _pad[0] + _pad[2];
hh += _pad[1] + _pad[3];
overlay_w = ww;
overlay_h = hh;
#endregion
2023-08-05 14:00:33 +02:00
for(var i = 0; i < 3; i++) {
2023-08-05 14:00:33 +02:00
temp_surface[i] = surface_verify(temp_surface[i], ww, hh, cDep);
surface_clear(temp_surface[i]);
2022-01-13 05:24:03 +01:00
}
2024-03-14 14:35:19 +01:00
var res_index = 0;
var imageAmo = (ds_list_size(inputs) - input_fix_len) / data_length;
var _vis = attributes.layer_visible;
var bg = 0;
var _bg = 0;
blend_temp_surface = temp_surface[2];
2023-03-21 03:01:53 +01:00
for(var i = 0; i < imageAmo; i++) {
2023-06-13 14:42:06 +02:00
var vis = _vis[i];
2022-09-23 13:28:42 +02:00
if(!vis) continue;
2024-03-14 14:35:19 +01:00
var _ind = input_fix_len + i * data_length;
var _s = _data[_ind + 0];
var _pos = _data[_ind + 1];
var _rot = _data[_ind + 2];
var _sca = _data[_ind + 3];
var _bld = _data[_ind + 4];
var _alp = _data[_ind + 5];
2022-01-13 05:24:03 +01:00
if(!_s || is_array(_s)) continue;
2023-09-08 21:37:36 +02:00
var _ww = surface_get_width_safe(_s);
var _hh = surface_get_height_safe(_s);
2023-02-14 05:32:32 +01:00
var _sw = _ww * _sca[0];
var _sh = _hh * _sca[1];
var cx = _pos[0] + _ww / 2;
var cy = _pos[1] + _hh / 2;
var _d0 = point_rotate(cx - _sw / 2, cy - _sh / 2, cx, cy, _rot);
2022-01-13 05:24:03 +01:00
2023-10-06 11:51:11 +02:00
array_push(atlas_data, new SurfaceAtlas(_s, _d0[0], _d0[1], _rot, _sca[0], _sca[1]));
surface_set_shader(temp_surface[_bg], sh_sample, true, BLEND.over);
2024-03-14 14:35:19 +01:00
draw_surface_blend_ext(temp_surface[!_bg], _s, _d0[0], _d0[1], _sca[0], _sca[1], _rot, c_white, _alp, _bld, true);
surface_reset_shader();
_bg = !_bg;
2022-01-13 05:24:03 +01:00
}
_outSurf = surface_verify(_outSurf, ww, hh, cDep);
surface_set_shader(_outSurf);
draw_surface_safe(temp_surface[!_bg]);
2023-03-21 03:01:53 +01:00
surface_reset_shader();
2022-12-27 04:00:50 +01:00
return _outSurf;
2023-09-09 13:52:16 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-09-09 13:52:16 +02:00
static attributeSerialize = function() { #region
2023-06-13 14:42:06 +02:00
var att = {};
att.layer_visible = attributes.layer_visible;
att.layer_selectable = attributes.layer_selectable;
2023-01-17 08:11:55 +01:00
2022-09-23 13:28:42 +02:00
return att;
2023-09-09 13:52:16 +02:00
} #endregion
2022-09-23 13:28:42 +02:00
2023-09-09 13:52:16 +02:00
static attributeDeserialize = function(attr) { #region
struct_append(attributes, attr);
if(struct_has(attributes, "use_project_dimension") && !struct_has(attr, "use_project_dimension"))
attributes.use_project_dimension = false;
2023-06-13 14:42:06 +02:00
if(struct_has(attr, "layer_visible"))
attributes.layer_visible = attr.layer_visible;
2023-01-17 08:11:55 +01:00
2023-06-13 14:42:06 +02:00
if(struct_has(attr, "layer_selectable"))
attributes.layer_selectable = attr.layer_selectable;
2023-09-09 13:52:16 +02:00
} #endregion
2022-09-23 13:28:42 +02:00
}