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
|
|
|
|
}
|
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
function Node_Composite(_x, _y, _group = -1) : Node_Processor(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Composite";
|
|
|
|
|
2022-12-21 02:30:23 +01:00
|
|
|
shader = sh_blend_normal_dim;
|
|
|
|
uniform_dim = shader_get_uniform(shader, "dimension");
|
|
|
|
uniform_pos = shader_get_uniform(shader, "position");
|
|
|
|
uniform_sca = shader_get_uniform(shader, "scale");
|
|
|
|
uniform_rot = shader_get_uniform(shader, "rotation");
|
|
|
|
uniform_for = shader_get_sampler_index(shader, "fore");
|
2022-01-13 05:24:03 +01:00
|
|
|
|
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-02-14 05:32:32 +01:00
|
|
|
inputs[| 2] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2)
|
2022-09-23 13:28:42 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.vector)
|
|
|
|
.setVisible(false);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
input_fix_len = ds_list_size(inputs);
|
|
|
|
data_length = 4;
|
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
attributes[? "layer_visible"] = ds_list_create();
|
2023-01-17 08:11:55 +01:00
|
|
|
attributes[? "layer_selectable"] = ds_list_create();
|
2022-09-23 13:28:42 +02:00
|
|
|
|
|
|
|
hold_visibility = true;
|
2023-01-17 08:11:55 +01:00
|
|
|
hold_select = true;
|
2022-09-23 13:28:42 +02:00
|
|
|
layer_dragging = noone;
|
2022-09-27 06:37:28 +02:00
|
|
|
layer_remove = -1;
|
2022-09-23 13:28:42 +02:00
|
|
|
layer_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
|
|
|
|
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
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
var lh = 32;
|
|
|
|
var _h = 8 + max(1, amo) * (lh + 4) + 8;
|
|
|
|
layer_renderer.h = _h;
|
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
|
|
|
|
|
|
|
var _vis = attributes[? "layer_visible"];
|
2023-01-17 08:11:55 +01:00
|
|
|
var _sel = attributes[? "layer_selectable"];
|
2022-09-23 13:28:42 +02:00
|
|
|
var ly = _y + 8;
|
|
|
|
var ssh = lh - 6;
|
|
|
|
var hoverIndex = noone;
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS.node_composite_separator);
|
2022-09-23 13:28:42 +02:00
|
|
|
draw_line(_x + 16, ly, _x + _w - 16, ly);
|
|
|
|
|
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++) {
|
|
|
|
var ind = amo - i - 1;
|
|
|
|
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;
|
|
|
|
var _cy = ly + i * (lh + 4);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
var aa = (ind != layer_dragging || layer_dragging == noone)? 1 : 0.5;
|
|
|
|
var vis = _vis[| ind];
|
2023-01-17 08:11:55 +01:00
|
|
|
var sel = _sel[| ind];
|
2022-09-23 13:28:42 +02:00
|
|
|
var hover = point_in_rectangle(_m[0], _m[1], _x, _cy, _x + _w, _cy + lh);
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS.node_composite_separator);
|
2022-09-23 13:28:42 +02:00
|
|
|
draw_line(_x + 16, _cy + lh + 2, _x + _w - 16, _cy + lh + 2);
|
|
|
|
|
2022-09-27 06:37:28 +02:00
|
|
|
var _bx = _x + 24 * 2 + 8;
|
|
|
|
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))
|
|
|
|
hold_visibility = !_vis[| ind];
|
2022-09-23 13:28:42 +02:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_click(mb_left, _focus) && _vis[| ind] != hold_visibility) {
|
|
|
|
_vis[| ind] = hold_visibility;
|
|
|
|
update();
|
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);
|
|
|
|
|
|
|
|
_bx += 24 + 8;
|
|
|
|
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))
|
|
|
|
hold_select = !_sel[| ind];
|
|
|
|
|
|
|
|
if(mouse_click(mb_left, _focus) && _sel[| ind] != hold_select)
|
|
|
|
_sel[| ind] = hold_select;
|
|
|
|
} 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
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS.node_composite_bg);
|
2023-01-17 08:11:55 +01:00
|
|
|
var _sx0 = _bx + 24;
|
2022-09-23 13:28:42 +02:00
|
|
|
var _sx1 = _sx0 + ssh;
|
|
|
|
var _sy0 = _cy + 3;
|
|
|
|
var _sy1 = _sy0 + ssh;
|
|
|
|
draw_rectangle(_sx0, _sy0, _sx1, _sy1, true);
|
|
|
|
|
|
|
|
var _ssw = surface_get_width(_surf);
|
|
|
|
var _ssh = surface_get_height(_surf);
|
|
|
|
var _sss = min(ssh / _ssw, ssh / _ssh);
|
|
|
|
draw_surface_ext(_surf, _sx0, _sy0, _sss, _sss, 0, c_white, 1);
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_text(f_p1, fa_left, fa_center, hover? COLORS._main_text : COLORS._main_text);
|
2022-09-23 13:28:42 +02:00
|
|
|
draw_set_alpha(aa);
|
|
|
|
draw_text(_sx1 + 12, _cy + lh / 2, inputs[| index].name);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(layer_dragging == noone || layer_dragging == ind) {
|
2022-09-27 06:37:28 +02:00
|
|
|
var _bx = _x + 24;
|
2022-09-23 13:28:42 +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.hamburger, 3, _bx, _cy + lh / 2, .75, c_white);
|
2022-09-23 13:28:42 +02:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_press(mb_left, _focus))
|
2022-09-23 13:28:42 +02:00
|
|
|
layer_dragging = ind;
|
|
|
|
} else
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.hamburger, 3, _bx, _cy + lh / 2, .75, COLORS._main_icon);
|
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;
|
|
|
|
var _vis = attributes[? "layer_visible"];
|
2023-01-17 08:11:55 +01:00
|
|
|
var _sel = attributes[? "layer_selectable"];
|
2022-09-23 13:28:42 +02:00
|
|
|
|
|
|
|
var ext = [];
|
|
|
|
var vis = _vis[| layer_dragging];
|
|
|
|
ds_list_delete(_vis, layer_dragging);
|
|
|
|
ds_list_insert(_vis, hoverIndex, vis);
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
var sel = _sel[| layer_dragging];
|
|
|
|
ds_list_delete(_sel, layer_dragging);
|
|
|
|
ds_list_insert(_sel, hoverIndex, sel);
|
|
|
|
|
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
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
for( var i = 0; i < data_length; i++ ) {
|
|
|
|
ds_list_insert(inputs, targt + i, ext[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
layer_dragging = noone;
|
|
|
|
}
|
2023-01-09 03:14:20 +01:00
|
|
|
|
|
|
|
return _h;
|
2022-09-23 13:28:42 +02:00
|
|
|
});
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
input_display_list = [
|
2022-09-23 13:28:42 +02:00
|
|
|
["Output", true], 0, 1, 2,
|
|
|
|
["Layers", false], layer_renderer,
|
|
|
|
["Surface", true],
|
2022-01-13 05:24:03 +01:00
|
|
|
];
|
2022-09-27 06:37:28 +02:00
|
|
|
input_display_list_len = array_length(input_display_list);
|
|
|
|
|
|
|
|
function deleteLayer(index) {
|
|
|
|
var idx = input_fix_len + index * data_length;
|
|
|
|
for( var i = 0; i < data_length; i++ ) {
|
|
|
|
ds_list_delete(inputs, idx);
|
|
|
|
array_remove(input_display_list, idx + i);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
function createNewSurface() {
|
|
|
|
var index = ds_list_size(inputs);
|
|
|
|
var _s = floor((index - input_fix_len) / data_length);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| index + 0] = nodeValue(_s? ("Surface " + string(_s)) : "Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| index + 1] = nodeValue("Position " + string(_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
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| index + 2] = nodeValue("Rotation " + string(_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
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| index + 3] = nodeValue("Scale " + string(_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
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
array_push(input_display_list, index + 0);
|
|
|
|
array_push(input_display_list, index + 1);
|
|
|
|
array_push(input_display_list, index + 2);
|
|
|
|
array_push(input_display_list, index + 3);
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
while(_s >= ds_list_size(attributes[? "layer_visible"]))
|
2022-09-23 13:28:42 +02:00
|
|
|
ds_list_add(attributes[? "layer_visible"], true);
|
2023-01-17 08:11:55 +01:00
|
|
|
while(_s >= ds_list_size(attributes[? "layer_selectable"]))
|
|
|
|
ds_list_add(attributes[? "layer_selectable"], true);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-12-21 02:30:23 +01:00
|
|
|
if(!LOADING && !APPENDING) createNewSurface();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
//function getInput() { return inputs[| ds_list_size(inputs) - data_length]; }
|
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-02-14 05:32:32 +01:00
|
|
|
temp_surf = [ surface_create(1, 1), surface_create(1, 1) ];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
surf_dragging = -1;
|
|
|
|
input_dragging = -1;
|
|
|
|
drag_type = 0;
|
|
|
|
dragging_sx = 0;
|
|
|
|
dragging_sy = 0;
|
|
|
|
dragging_mx = 0;
|
|
|
|
dragging_my = 0;
|
|
|
|
|
|
|
|
rot_anc_x = 0;
|
|
|
|
rot_anc_y = 0;
|
|
|
|
|
|
|
|
overlay_w = 0;
|
|
|
|
overlay_h = 0;
|
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
static onValueFromUpdate = function(index) {
|
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))
|
|
|
|
createNewSurface();
|
|
|
|
}
|
|
|
|
|
2022-12-19 13:35:30 +01:00
|
|
|
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var pad = inputs[| 0].getValue();
|
|
|
|
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];
|
|
|
|
var _sw = surface_get_width(_surf);
|
|
|
|
var _sh = surface_get_height(_surf);
|
|
|
|
|
|
|
|
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) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var _surf = inputs[| surf_dragging + 0].getValue();
|
|
|
|
var _rot = inputs[| surf_dragging + 2].getValue();
|
2022-01-13 05:24:03 +01:00
|
|
|
var _sw = surface_get_width(_surf);
|
|
|
|
var _sh = surface_get_width(_surf);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var hovering = -1;
|
|
|
|
var hovering_type = 0;
|
2022-09-23 13:28:42 +02:00
|
|
|
var _vis = attributes[? "layer_visible"];
|
2023-01-17 08:11:55 +01:00
|
|
|
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;
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < amo; i++) {
|
2022-09-23 13:28:42 +02:00
|
|
|
var vis = _vis[| i];
|
2023-01-17 08:11:55 +01:00
|
|
|
var sel = _sel[| i];
|
2022-09-23 13:28:42 +02:00
|
|
|
if(!vis) continue;
|
|
|
|
|
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-02-14 05:32:32 +01:00
|
|
|
var _ww = surface_get_width(_surf);
|
|
|
|
var _hh = surface_get_height(_surf);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
|
|
|
_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
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
var _borcol = COLORS.node_composite_overlay_border;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var _ri = 0;
|
|
|
|
var _si = 0;
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
if(!sel) continue;
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(point_in_circle(_mx, _my, _d3[0], _d3[1], 12)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
hovering = index;
|
2023-01-17 08:11:55 +01:00
|
|
|
hovering_type = NODE_COMPOSE_DRAG.scale;
|
2022-01-13 05:24:03 +01:00
|
|
|
_si = 1;
|
2023-02-14 05:32:32 +01:00
|
|
|
} else if(point_in_rectangle_points(_mx, _my, _d0[0], _d0[1], _d1[0], _d1[1], _d2[0], _d2[1], _d3[0], _d3[1])) {
|
2022-01-13 05:24:03 +01:00
|
|
|
hovering = index;
|
2023-01-17 08:11:55 +01:00
|
|
|
hovering_type = NODE_COMPOSE_DRAG.move;
|
2023-02-14 05:32:32 +01:00
|
|
|
} else if(point_in_circle(_mx, _my, _rr[0], _rr[1], 12)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
hovering = index;
|
2023-01-17 08:11:55 +01:00
|
|
|
hovering_type = NODE_COMPOSE_DRAG.rotate;
|
2022-01-13 05:24:03 +01:00
|
|
|
_ri = 1;
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.anchor_rotate, _ri, _rr[0], _rr[1],,,, _rot);
|
|
|
|
draw_sprite_ui_uniform(THEME.anchor_scale, _si, _d3[0], _d3[1],,,, _rot);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
draw_set_color(_borcol);
|
2023-02-14 05:32:32 +01:00
|
|
|
draw_line(_d0[0], _d0[1], _d1[0], _d1[1]);
|
|
|
|
draw_line(_d0[0], _d0[1], _d2[0], _d2[1]);
|
|
|
|
draw_line(_d3[0], _d3[1], _d1[0], _d1[1]);
|
|
|
|
draw_line(_d3[0], _d3[1], _d2[0], _d2[1]);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(hovering != -1) {
|
|
|
|
var _surf = current_data[hovering];
|
2023-01-17 08:11:55 +01:00
|
|
|
var _pos = current_data[hovering + 1];
|
|
|
|
var _rot = current_data[hovering + 2];
|
|
|
|
var _sca = current_data[hovering + 3];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var _ww = surface_get_width(_surf);
|
|
|
|
var _hh = surface_get_height(_surf);
|
|
|
|
var _dx0 = _x + _pos[0] * _s;
|
|
|
|
var _dy0 = _y + _pos[1] * _s;
|
|
|
|
var _dx1 = _dx0 + _ww * _s;
|
|
|
|
var _dy1 = _dy0 + _hh * _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);
|
|
|
|
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);
|
|
|
|
|
|
|
|
_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);
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
if(hovering_type == NODE_COMPOSE_DRAG.move) {
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS._main_accent);
|
2023-02-14 05:32:32 +01:00
|
|
|
draw_line_round(_d0[0], _d0[1], _d1[0], _d1[1], 2);
|
|
|
|
draw_line_round(_d0[0], _d0[1], _d2[0], _d2[1], 2);
|
|
|
|
draw_line_round(_d3[0], _d3[1], _d1[0], _d1[1], 2);
|
|
|
|
draw_line_round(_d3[0], _d3[1], _d2[0], _d2[1], 2);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2023-01-17 08:11:55 +01:00
|
|
|
surf_dragging = hovering;
|
|
|
|
input_dragging = hovering + 1;
|
|
|
|
drag_type = hovering_type;
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging_sx = _pos[0];
|
|
|
|
dragging_sy = _pos[1];
|
|
|
|
dragging_mx = _mx;
|
|
|
|
dragging_my = _my;
|
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
} else if(hovering_type == NODE_COMPOSE_DRAG.rotate) { //rot
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2023-01-17 08:11:55 +01:00
|
|
|
surf_dragging = hovering;
|
|
|
|
input_dragging = hovering + 2;
|
|
|
|
drag_type = hovering_type;
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging_sx = _rot;
|
2023-01-17 08:11:55 +01:00
|
|
|
rot_anc_x = _dx0 + _ww / 2 * _s;
|
|
|
|
rot_anc_y = _dy0 + _hh / 2 * _s;
|
2022-01-13 05:24:03 +01:00
|
|
|
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
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2023-01-17 08:11:55 +01:00
|
|
|
surf_dragging = hovering;
|
|
|
|
input_dragging = hovering + 3;
|
|
|
|
drag_type = hovering_type;
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging_sx = _sca[0];
|
|
|
|
dragging_sy = _sca[1];
|
2023-02-14 05:32:32 +01:00
|
|
|
dragging_mx = _dx0 + _ww / 2 * _s;
|
|
|
|
dragging_my = _dy0 + _hh / 2 * _s;
|
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;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-01-01 02:06:02 +01:00
|
|
|
static process_data = function(_outSurf, _data, _output_index, _array_index) {
|
2022-12-21 02:30:23 +01:00
|
|
|
if(array_length(_data) < 4) return _outSurf;
|
2022-01-13 05:24:03 +01:00
|
|
|
var _pad = _data[0];
|
|
|
|
var _dim_type = _data[1];
|
|
|
|
var _dim = _data[2];
|
|
|
|
var base = _data[3];
|
|
|
|
var ww = 0, hh = 0;
|
|
|
|
|
|
|
|
switch(_dim_type) {
|
|
|
|
case COMPOSE_OUTPUT_SCALING.first :
|
2022-01-19 06:11:17 +01:00
|
|
|
inputs[| 2].setVisible(false);
|
2022-01-13 05:24:03 +01:00
|
|
|
ww = surface_get_width(base);
|
|
|
|
hh = surface_get_height(base);
|
|
|
|
break;
|
|
|
|
case COMPOSE_OUTPUT_SCALING.largest :
|
2022-01-19 06:11:17 +01:00
|
|
|
inputs[| 2].setVisible(false);
|
2022-01-13 05:24:03 +01:00
|
|
|
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(_s));
|
|
|
|
hh = max(hh, surface_get_height(_s));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case COMPOSE_OUTPUT_SCALING.constant :
|
2022-01-19 06:11:17 +01:00
|
|
|
inputs[| 2].setVisible(true);
|
2022-01-13 05:24:03 +01:00
|
|
|
ww = _dim[0];
|
|
|
|
hh = _dim[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ww += _pad[0] + _pad[2];
|
|
|
|
hh += _pad[1] + _pad[3];
|
|
|
|
|
|
|
|
overlay_w = ww;
|
|
|
|
overlay_h = hh;
|
|
|
|
|
|
|
|
if(is_surface(base))
|
|
|
|
surface_size_to(_outSurf, ww, hh);
|
|
|
|
|
|
|
|
for(var i = 0; i < 2; i++) {
|
2022-12-27 04:00:50 +01:00
|
|
|
temp_surf[i] = surface_verify(temp_surf[i], surface_get_width(_outSurf), surface_get_height(_outSurf));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
surface_set_target(temp_surf[i]);
|
|
|
|
draw_clear_alpha(0, 0);
|
|
|
|
surface_reset_target();
|
|
|
|
}
|
|
|
|
|
|
|
|
var res_index = 0, bg = 0;
|
2022-05-17 14:39:12 +02:00
|
|
|
var imageAmo = (ds_list_size(inputs) - input_fix_len) / data_length;
|
2022-09-23 13:28:42 +02:00
|
|
|
var _vis = attributes[? "layer_visible"];
|
2022-05-17 14:39:12 +02:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
surface_set_target(_outSurf);
|
|
|
|
draw_clear_alpha(0, 0);
|
2023-02-19 02:13:19 +01:00
|
|
|
BLEND_ALPHA_MULP;
|
2022-05-17 14:39:12 +02:00
|
|
|
for(var i = 0; i < imageAmo; i++) {
|
2022-09-23 13:28:42 +02:00
|
|
|
var vis = _vis[| i];
|
|
|
|
if(!vis) continue;
|
|
|
|
|
2022-05-17 14:39:12 +02:00
|
|
|
var startDataIndex = input_fix_len + i * data_length;
|
|
|
|
var _s = _data[startDataIndex + 0];
|
|
|
|
var _pos = _data[startDataIndex + 1];
|
|
|
|
var _rot = _data[startDataIndex + 2];
|
|
|
|
var _sca = _data[startDataIndex + 3];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(!_s || is_array(_s)) continue;
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
var _ww = surface_get_width(_s);
|
|
|
|
var _hh = surface_get_height(_s);
|
|
|
|
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-02-14 05:32:32 +01:00
|
|
|
draw_surface_ext_safe(_s, _d0[0], _d0[1], _sca[0], _sca[1], _rot);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_NORMAL;
|
2022-01-13 05:24:03 +01:00
|
|
|
surface_reset_target();
|
2022-12-27 04:00:50 +01:00
|
|
|
|
|
|
|
return _outSurf;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-01-18 05:31:19 +01:00
|
|
|
static postDeserialize = function() {
|
|
|
|
var _inputs = load_map[? "inputs"];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-21 02:30:23 +01:00
|
|
|
for(var i = input_fix_len; i < ds_list_size(_inputs); i += data_length)
|
|
|
|
createNewSurface();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-09-23 13:28:42 +02:00
|
|
|
|
|
|
|
static attributeSerialize = function() {
|
|
|
|
var att = ds_map_create();
|
2022-09-27 06:37:28 +02:00
|
|
|
ds_map_add_list(att, "layer_visible", ds_list_clone(attributes[? "layer_visible"]));
|
2023-01-17 08:11:55 +01:00
|
|
|
ds_map_add_list(att, "layer_selectable", ds_list_clone(attributes[? "layer_selectable"]));
|
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
return att;
|
|
|
|
}
|
|
|
|
|
|
|
|
static attributeDeserialize = function(attr) {
|
2022-09-27 06:37:28 +02:00
|
|
|
if(ds_map_exists(attr, "layer_visible"))
|
|
|
|
attributes[? "layer_visible"] = ds_list_clone(attr[? "layer_visible"], true);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
if(ds_map_exists(attr, "layer_selectable"))
|
|
|
|
attributes[? "layer_selectable"] = ds_list_clone(attr[? "layer_selectable"], true);
|
2022-09-23 13:28:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|