2022-12-13 09:20:36 +01:00
|
|
|
function Node_create_Image(_x, _y, _group = -1) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var path = "";
|
|
|
|
if(!LOADING && !APPENDING) {
|
|
|
|
path = get_open_filename(".png", "");
|
|
|
|
if(path == "") return noone;
|
|
|
|
}
|
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
var node = new Node_Image(_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_path(_x, _y, path) {
|
|
|
|
if(!file_exists(path)) return noone;
|
|
|
|
|
|
|
|
var node = new Node_Image(_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-13 05:24:03 +01:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
function Node_Image(_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
|
|
|
always_output = true;
|
|
|
|
|
|
|
|
inputs[| 0] = nodeValue(0, "Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.path, "")
|
|
|
|
.setDisplay(VALUE_DISPLAY.path_load, ["*.png", ""]);
|
2022-01-19 03:05:13 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
inputs[| 1] = nodeValue(1, "Padding", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [0, 0, 0, 0])
|
|
|
|
.setDisplay(VALUE_DISPLAY.padding);
|
2022-01-19 03:05:13 +01:00
|
|
|
|
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, "")
|
|
|
|
.setVisible(true, true);
|
|
|
|
|
|
|
|
spr = noone;
|
|
|
|
path_current = "";
|
|
|
|
|
|
|
|
first_update = false;
|
|
|
|
|
|
|
|
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 ".png":
|
|
|
|
case ".jpg":
|
|
|
|
case ".jpeg":
|
|
|
|
case ".gif":
|
2022-01-19 04:16:28 +01:00
|
|
|
name = _name;
|
2022-01-13 05:24:03 +01:00
|
|
|
outputs[| 1].setValue(path);
|
|
|
|
|
|
|
|
if(spr) sprite_delete(spr);
|
|
|
|
spr = sprite_add(path, 1, false, false, 0, 0);
|
|
|
|
|
|
|
|
if(path_current == "")
|
|
|
|
first_update = true;
|
2022-01-19 04:16:28 +01:00
|
|
|
path_current = path;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-01-18 05:31:19 +01:00
|
|
|
static update = function() {
|
2022-01-13 05:24:03 +01:00
|
|
|
var path = inputs[| 0].getValue();
|
|
|
|
var pad = inputs[| 1].getValue();
|
|
|
|
if(path == "") return;
|
|
|
|
updatePaths(path);
|
|
|
|
|
|
|
|
if(!spr || !sprite_exists(spr)) return;
|
|
|
|
|
|
|
|
var ww = sprite_get_width(spr) + pad[0] + pad[2];
|
|
|
|
var hh = sprite_get_height(spr) + pad[1] + pad[3];
|
|
|
|
|
|
|
|
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, 0, pad[2], pad[1]);
|
|
|
|
BLEND_NORMAL
|
|
|
|
surface_reset_target();
|
|
|
|
|
2022-11-21 06:38:44 +01:00
|
|
|
if(!first_update) return;
|
|
|
|
first_update = false;
|
|
|
|
|
|
|
|
if(string_pos("strip", name) == 0) return;
|
|
|
|
|
|
|
|
var sep_pos = string_pos("strip", name) + 5;
|
|
|
|
var sep = string_copy(name, sep_pos, string_length(name) - sep_pos + 1);
|
|
|
|
var amo = toNumber(sep);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-21 06:38:44 +01:00
|
|
|
if(amo) {
|
|
|
|
var ww = sprite_get_width(spr) / amo;
|
|
|
|
var hh = sprite_get_height(spr);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
var _splice = nodeBuild("Node_Image_Sheet", x + w + 64, y);
|
2022-11-21 06:38:44 +01:00
|
|
|
_splice.inputs[| 0].setFrom(outputs[| 0], false);
|
|
|
|
_splice.inputs[| 1].setValue([ww, hh]);
|
|
|
|
_splice.inputs[| 2].setValue(amo);
|
|
|
|
_splice.inputs[| 3].setValue(amo);
|
2022-09-27 06:37:28 +02:00
|
|
|
|
2022-11-21 06:38:44 +01:00
|
|
|
ds_list_add(PANEL_GRAPH.nodes_select_list, self);
|
|
|
|
ds_list_add(PANEL_GRAPH.nodes_select_list, _splice);
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
doUpdate();
|
|
|
|
}
|