2022-12-13 09:20:36 +01:00
|
|
|
function Node_create_Image_gif(_x, _y, _group = -1) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var path = "";
|
|
|
|
if(!LOADING && !APPENDING) {
|
|
|
|
path = get_open_filename(".gif", "");
|
|
|
|
if(path == "") return noone;
|
|
|
|
}
|
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
var node = new Node_Image_gif(_x, _y, _group);
|
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
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
//ds_list_add(PANEL_GRAPH.nodes_list, node);
|
2022-01-13 05:24:03 +01:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Node_create_Image_gif_path(_x, _y, path) {
|
|
|
|
if(!file_exists(path)) return noone;
|
|
|
|
|
|
|
|
var node = new Node_Image_gif(_x, _y);
|
|
|
|
node.inputs[| 0].setValue(path);
|
2022-01-16 14:28:57 +01:00
|
|
|
node.doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
//ds_list_add(PANEL_GRAPH.nodes_list, node);
|
2022-01-23 04:08:16 +01:00
|
|
|
return node;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
function Node_Image_gif(_x, _y, _group = -1) : Node(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "";
|
2022-11-18 03:20:31 +01:00
|
|
|
color = COLORS.node_blend_input;
|
2022-01-13 05:24:03 +01:00
|
|
|
update_on_frame = true;
|
|
|
|
always_output = true;
|
|
|
|
|
|
|
|
inputs[| 0] = nodeValue(0, "Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.path, "")
|
|
|
|
.setDisplay(VALUE_DISPLAY.path_load, ["*.gif", ""]);
|
|
|
|
|
|
|
|
inputs[| 1] = nodeValue(1, "Set animation length to gif", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
|
|
|
.setDisplay(VALUE_DISPLAY.button, [ function() {
|
|
|
|
if(!spr) return;
|
|
|
|
if(!sprite_exists(spr)) return;
|
|
|
|
ANIMATOR.frames_total = sprite_get_number(spr);
|
|
|
|
ANIMATOR.framerate = 12;
|
|
|
|
}, "Match length"] );
|
|
|
|
|
2022-09-21 06:09:40 +02:00
|
|
|
outputs[| 0] = nodeValue(0, "Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, PIXEL_SURFACE);
|
2022-01-13 05:24:03 +01:00
|
|
|
outputs[| 1] = nodeValue(1, "Path", self, JUNCTION_CONNECT.output, VALUE_TYPE.path, "")
|
2022-01-19 14:48:30 +01:00
|
|
|
.setVisible(true, true);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
spr = noone;
|
|
|
|
path_current = "";
|
|
|
|
loading = 0;
|
|
|
|
spr_builder = noone;
|
|
|
|
|
|
|
|
on_dragdrop_file = function(path) {
|
|
|
|
if(updatePaths(path)) {
|
2022-01-16 14:28:57 +01:00
|
|
|
doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePaths(path) {
|
|
|
|
if(path_current == path) return false;
|
|
|
|
|
|
|
|
path = try_get_path(path);
|
|
|
|
if(path == -1) return false;
|
|
|
|
|
|
|
|
var ext = filename_ext(path);
|
|
|
|
var _name = string_replace(filename_name(path), filename_ext(path), "");
|
|
|
|
|
|
|
|
switch(ext) {
|
|
|
|
case ".gif":
|
|
|
|
name = _name;
|
|
|
|
outputs[| 1].setValue(path);
|
|
|
|
|
|
|
|
if(spr) sprite_delete(spr);
|
|
|
|
sprite_add_gif(path, function(_spr) {
|
|
|
|
spr_builder = _spr;
|
|
|
|
loading = 2;
|
|
|
|
});
|
|
|
|
loading = 1;
|
|
|
|
|
|
|
|
if(path_current == "")
|
|
|
|
first_update = true;
|
|
|
|
path_current = path;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static step = function() {
|
|
|
|
if(loading == 2 && spr_builder != noone) {
|
|
|
|
if(spr_builder.building()) {
|
|
|
|
spr = spr_builder._spr;
|
2022-01-16 14:28:57 +01:00
|
|
|
doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
loading = 0;
|
|
|
|
delete spr_builder;
|
|
|
|
|
|
|
|
gc_collect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 05:31:19 +01:00
|
|
|
static update = function() {
|
2022-01-13 05:24:03 +01:00
|
|
|
var path = inputs[| 0].getValue();
|
|
|
|
if(path == "") return;
|
|
|
|
updatePaths(path);
|
|
|
|
|
|
|
|
if(!spr || !sprite_exists(spr)) return;
|
|
|
|
|
|
|
|
var ww = sprite_get_width(spr);
|
|
|
|
var hh = sprite_get_height(spr);
|
|
|
|
|
|
|
|
var _outsurf = outputs[| 0].getValue();
|
|
|
|
if(is_surface(_outsurf))
|
|
|
|
surface_size_to(_outsurf, ww, hh);
|
|
|
|
else {
|
2022-11-03 11:44:49 +01:00
|
|
|
_outsurf = surface_create_valid(ww, hh);
|
2022-01-13 05:24:03 +01:00
|
|
|
outputs[| 0].setValue(_outsurf);
|
|
|
|
}
|
|
|
|
|
|
|
|
surface_set_target(_outsurf);
|
|
|
|
draw_clear_alpha(0, 0);
|
|
|
|
BLEND_ADD
|
|
|
|
draw_sprite(spr, ANIMATOR.current_frame, 0, 0);
|
|
|
|
BLEND_NORMAL
|
|
|
|
surface_reset_target();
|
|
|
|
}
|
|
|
|
doUpdate();
|
|
|
|
|
|
|
|
function onDrawNode(xx, yy, _mx, _my, _s) {
|
|
|
|
if(loading) {
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui(THEME.loading, 0, xx + w * _s / 2, yy + h * _s / 2, _s, _s, current_time / 2, COLORS._main_icon, 1);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static onDestroy = function() {
|
|
|
|
if(sprite_exists(spr))
|
|
|
|
sprite_flush(spr);
|
|
|
|
}
|
|
|
|
}
|