2023-02-28 09:43:01 +01:00
|
|
|
function Node_Find_Pixel(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2023-02-14 02:48:33 +01:00
|
|
|
name = "Find pixel";
|
|
|
|
w = 96;
|
|
|
|
|
|
|
|
shader = sh_find_pixel;
|
|
|
|
shader_dim = shader_get_uniform(shader, "dimension");
|
|
|
|
shader_tex = shader_get_sampler_index(shader, "texture");
|
|
|
|
|
|
|
|
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
|
|
|
|
|
|
|
|
inputs[| 1] = nodeValue("Search color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_black);
|
|
|
|
|
|
|
|
outputs[| 0] = nodeValue("Position", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, [ 0, 0 ])
|
|
|
|
.setDisplay(VALUE_DISPLAY.vector);
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
static getPreviewValues = function() { return getInputData(0); }
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
temp_surface = [ surface_create(1, 1) ];
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_output, _data, _output_index, _array_index = 0) {
|
2023-02-14 02:48:33 +01:00
|
|
|
var _surf = _data[0];
|
|
|
|
var _col = _data[1];
|
|
|
|
|
|
|
|
if(!is_surface(_surf)) return [0, 0];
|
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
temp_surface[0] = surface_verify(temp_surface[0], 1, 1);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-02-23 07:02:19 +01:00
|
|
|
surface_set_target(temp_surface[0]);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
2023-02-14 02:48:33 +01:00
|
|
|
shader_set(shader);
|
|
|
|
texture_set_stage(shader_tex, surface_get_texture(_surf));
|
2023-09-08 21:37:36 +02:00
|
|
|
shader_set_uniform_f(shader_dim, surface_get_width_safe(_surf), surface_get_height_safe(_surf));
|
2023-02-14 02:48:33 +01:00
|
|
|
draw_sprite_ext(s_fx_pixel, 0, 0, 0, 1, 1, 0, _col, 1);
|
|
|
|
shader_reset();
|
|
|
|
surface_reset_target();
|
|
|
|
|
2023-03-31 06:59:08 +02:00
|
|
|
var pos = surface_get_pixel(temp_surface[0], 0, 0);
|
2023-09-08 21:37:36 +02:00
|
|
|
var _x = round(color_get_red(pos) / 255 * surface_get_width_safe(_surf));
|
|
|
|
var _y = round(color_get_green(pos) / 255 * surface_get_height_safe(_surf));
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
return [ _x, _y ];
|
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
2023-02-14 02:48:33 +01:00
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
|
|
|
|
|
|
|
if(bbox.h <= 0) return;
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
var col = getInputData(1);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
if(is_array(col)) {
|
|
|
|
drawPalette(col, bbox.x0, bbox.y0, bbox.w, bbox.h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_set_color(col);
|
|
|
|
draw_rectangle(bbox.x0, bbox.y0, bbox.x1, bbox.y1, 0);
|
|
|
|
}
|
|
|
|
}
|