2023-02-28 09:43:01 +01:00
|
|
|
function Node_create_Image_Sequence(_x, _y, _group = noone) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var path = "";
|
2023-01-17 08:11:55 +01:00
|
|
|
if(!LOADING && !APPENDING && !CLONING) {
|
2022-01-13 05:24:03 +01:00
|
|
|
path = get_open_filenames(".png", "");
|
2023-02-28 09:43:01 +01:00
|
|
|
key_release();
|
2022-01-13 05:24:03 +01:00
|
|
|
if(path == "") return noone;
|
|
|
|
}
|
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
var node = new Node_Image_Sequence(_x, _y, _group);
|
2023-02-14 05:32:32 +01:00
|
|
|
var paths = string_splice(path, "\n");
|
2022-01-13 05:24:03 +01:00
|
|
|
node.inputs[| 0].setValue(paths);
|
2022-01-16 14:28:57 +01:00
|
|
|
node.doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Node_create_Image_Sequence_path(_x, _y, _path) {
|
2023-01-17 08:11:55 +01:00
|
|
|
var node = new Node_Image_Sequence(_x, _y, PANEL_GRAPH.getCurrentContext());
|
2022-01-13 05:24:03 +01:00
|
|
|
node.inputs[| 0].setValue(_path);
|
2022-01-16 14:28:57 +01:00
|
|
|
node.doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum CANVAS_SIZE {
|
|
|
|
individual,
|
|
|
|
minimum,
|
|
|
|
maximum
|
|
|
|
}
|
|
|
|
|
|
|
|
enum CANVAS_SIZING {
|
|
|
|
padding,
|
|
|
|
scale
|
|
|
|
}
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
function Node_Image_Sequence(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-03-19 09:17:39 +01:00
|
|
|
name = "Image Array";
|
2022-01-13 05:24:03 +01:00
|
|
|
spr = [];
|
2022-11-18 03:20:31 +01:00
|
|
|
color = COLORS.node_blend_input;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.path, [])
|
2022-01-13 05:24:03 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.path_array, ["*.png", ""]);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 1] = nodeValue("Padding", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [0, 0, 0, 0])
|
|
|
|
.setDisplay(VALUE_DISPLAY.padding)
|
|
|
|
.rejectArray();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 2] = nodeValue("Canvas size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Individual", "Minimum", "Maximum" ])
|
|
|
|
.rejectArray();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 3] = nodeValue("Sizing method", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Padding / Crop", "Scale" ])
|
|
|
|
.rejectArray();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
input_display_list = [
|
2023-02-23 07:02:19 +01:00
|
|
|
["Array settings", false], 0, 1, 2, 3
|
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, []);
|
|
|
|
outputs[| 1] = nodeValue("Paths", self, JUNCTION_CONNECT.output, VALUE_TYPE.path, [] ).
|
2022-01-13 05:24:03 +01:00
|
|
|
setVisible(true, true);
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
attribute_surface_depth();
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
path_loaded = [];
|
|
|
|
|
2023-09-28 13:15:29 +02:00
|
|
|
on_drop_file = function(path) {
|
2022-01-13 05:24:03 +01:00
|
|
|
if(directory_exists(path)) {
|
|
|
|
with(dialogCall(o_dialog_drag_folder, WIN_W / 2, WIN_H / 2)) {
|
|
|
|
dir_paths = path;
|
|
|
|
target = other;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var paths = paths_to_array(path);
|
2023-09-28 13:15:29 +02:00
|
|
|
|
|
|
|
inputs[| 0].setValue(path);
|
2022-01-13 05:24:03 +01:00
|
|
|
if(updatePaths(paths)) {
|
2022-01-16 14:28:57 +01:00
|
|
|
doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-05 18:27:53 +02:00
|
|
|
insp1UpdateTooltip = __txt("Refresh");
|
2023-04-07 21:25:27 +02:00
|
|
|
insp1UpdateIcon = [ THEME.refresh, 1, COLORS._main_value_positive ];
|
|
|
|
|
2023-03-28 06:58:28 +02:00
|
|
|
static onInspector1Update = function() {
|
2023-01-17 08:11:55 +01:00
|
|
|
var path = inputs[| 0].getValue();
|
|
|
|
if(path == "") return;
|
|
|
|
updatePaths(path);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
function updatePaths(paths) {
|
|
|
|
for(var i = 0; i < array_length(spr); i++) {
|
|
|
|
if(spr[i] && sprite_exists(spr[i]))
|
|
|
|
sprite_delete(spr[i]);
|
|
|
|
}
|
|
|
|
spr = [];
|
|
|
|
|
|
|
|
path_loaded = array_create(array_length(paths));
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(paths); i < n; i++ ) {
|
2022-01-13 05:24:03 +01:00
|
|
|
path_loaded[i] = paths[i];
|
|
|
|
var path = try_get_path(paths[i]);
|
|
|
|
if(path == -1) continue;
|
2023-03-19 09:17:39 +01:00
|
|
|
var ext = string_lower(filename_ext(path));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
switch(ext) {
|
|
|
|
case ".png" :
|
|
|
|
case ".jpg" :
|
|
|
|
case ".jpeg" :
|
|
|
|
array_push(spr, sprite_add(path, 1, false, false, 0, 0));
|
|
|
|
break;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
outputs[| 1].setValue(paths);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-07-06 19:49:16 +02:00
|
|
|
static update = function(frame = PROJECT.animator.current_frame) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var path = inputs[| 0].getValue();
|
|
|
|
if(path == "") return;
|
2023-02-14 05:32:32 +01:00
|
|
|
if(!is_array(path)) path = [ path ];
|
2022-01-13 05:24:03 +01:00
|
|
|
if(!array_equals(path, path_loaded))
|
|
|
|
updatePaths(path);
|
|
|
|
|
|
|
|
var pad = inputs[| 1].getValue();
|
|
|
|
var can = inputs[| 2].getValue();
|
2022-01-19 06:11:17 +01:00
|
|
|
inputs[| 3].setVisible(can != CANVAS_SIZE.individual);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var siz = inputs[| 3].getValue();
|
|
|
|
|
|
|
|
var ww = -1, hh = -1;
|
|
|
|
var _ww = -1, _hh = -1;
|
|
|
|
|
|
|
|
var surfs = outputs[| 0].getValue();
|
2023-09-27 14:55:21 +02:00
|
|
|
var amo = array_length(spr);
|
|
|
|
for(var i = amo; i < array_length(surfs); i++)
|
|
|
|
surface_free(surfs[i]);
|
|
|
|
array_resize(surfs, amo);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
for(var i = 0; i < amo; i++) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var _spr = spr[i];
|
|
|
|
var _w = sprite_get_width(_spr);
|
|
|
|
var _h = sprite_get_height(_spr);
|
|
|
|
|
|
|
|
switch(can) {
|
|
|
|
case CANVAS_SIZE.minimum :
|
|
|
|
if(ww == -1) ww = _w;
|
|
|
|
else ww = min(ww, _w);
|
|
|
|
if(hh == -1) hh = _h;
|
|
|
|
else hh = min(hh, _h);
|
|
|
|
break;
|
|
|
|
case CANVAS_SIZE.maximum :
|
|
|
|
if(ww == -1) ww = _w;
|
|
|
|
else ww = max(ww, _w);
|
|
|
|
if(hh == -1) hh = _h;
|
|
|
|
else hh = max(hh, _h);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ww = ww;
|
|
|
|
_hh = hh;
|
|
|
|
ww += pad[0] + pad[2];
|
|
|
|
hh += pad[1] + pad[3];
|
|
|
|
|
|
|
|
for(var i = 0; i < array_length(spr); i++) {
|
|
|
|
var _spr = spr[i];
|
|
|
|
switch(can) {
|
|
|
|
case CANVAS_SIZE.individual :
|
|
|
|
ww = sprite_get_width(_spr) + pad[0] + pad[2];
|
|
|
|
hh = sprite_get_height(_spr) + pad[1] + pad[3];
|
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
surfs[i] = surface_verify(surfs[i], ww, hh, attrDepth());
|
2022-01-13 05:24:03 +01:00
|
|
|
surface_set_target(surfs[i]);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_OVERRIDE;
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_sprite(_spr, 0, pad[2], pad[1]);
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_NORMAL;
|
2022-01-13 05:24:03 +01:00
|
|
|
surface_reset_target();
|
|
|
|
break;
|
|
|
|
case CANVAS_SIZE.maximum :
|
|
|
|
case CANVAS_SIZE.minimum :
|
2023-09-27 14:55:21 +02:00
|
|
|
surfs[i] = surface_verify(surfs[i], ww, hh, attrDepth());
|
2022-01-13 05:24:03 +01:00
|
|
|
var _w = sprite_get_width(_spr);
|
|
|
|
var _h = sprite_get_height(_spr);
|
|
|
|
|
|
|
|
if(siz == CANVAS_SIZING.scale) {
|
|
|
|
var ss = min(_ww / _w, _hh / _h);
|
|
|
|
var sw = (ww - _w * ss) / 2;
|
|
|
|
var sh = (hh - _h * ss) / 2;
|
|
|
|
|
|
|
|
surface_set_target(surfs[i]);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_OVERRIDE;
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_sprite_ext(_spr, 0, sw, sh, ss, ss, 0, c_white, 1);
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_NORMAL;
|
2022-01-13 05:24:03 +01:00
|
|
|
surface_reset_target();
|
|
|
|
} else {
|
|
|
|
var xx = (ww - _w) / 2;
|
|
|
|
var yy = (hh - _h) / 2;
|
|
|
|
|
|
|
|
surface_set_target(surfs[i]);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_OVERRIDE;
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_sprite(_spr, 0, xx, yy);
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_NORMAL;
|
2022-01-13 05:24:03 +01:00
|
|
|
surface_reset_target();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
outputs[| 0].setValue(surfs);
|
|
|
|
}
|
|
|
|
}
|