Pixel-Composer/scripts/node_pin/node_pin.gml

109 lines
2.7 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-02-14 05:32:32 +01:00
name = "Pin";
2024-04-22 09:56:37 +02:00
setDimension(32, 32);
2023-01-17 08:11:55 +01:00
2023-10-27 13:55:31 +02:00
auto_height = false;
2022-01-13 05:24:03 +01:00
junction_shift_y = 16;
2022-01-26 06:57:34 +01:00
2023-10-27 13:55:31 +02:00
isHovering = false;
hover_scale = 0;
hover_scale_to = 0;
2023-10-27 13:55:31 +02:00
hover_alpha = 0;
2024-08-06 12:39:22 +02:00
hover_junction = noone;
2023-03-05 07:16:44 +01:00
bg_spr_add = 0;
2022-01-13 05:24:03 +01:00
2024-08-20 10:15:53 +02:00
newInput(0, nodeValue("In", self, CONNECT_TYPE.input, VALUE_TYPE.any, 0 ))
2022-01-13 05:24:03 +01:00
.setVisible(true, true);
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Out", self, VALUE_TYPE.any, 0);
2022-01-13 05:24:03 +01:00
static update = function() {
2024-08-08 06:57:51 +02:00
if(inputs[0].value_from != noone) {
2024-08-08 06:57:51 +02:00
inputs[0].setType(inputs[0].value_from.type);
outputs[0].setType(inputs[0].value_from.type);
2024-08-08 06:57:51 +02:00
inputs[0].color_display = inputs[0].value_from.color_display;
outputs[0].color_display = inputs[0].color_display;
}
2023-10-27 13:55:31 +02:00
var _val = getInputData(0);
2024-08-08 06:57:51 +02:00
outputs[0].setValue(_val);
}
2023-10-27 13:55:31 +02:00
static pointIn = function(_x, _y, _mx, _my, _s) {
2022-11-01 03:06:03 +01:00
var xx = x * _s + _x;
var yy = y * _s + _y;
2023-03-13 10:45:56 +01:00
return point_in_circle(_mx, _my, xx, yy, _s * 24);
}
2022-01-26 06:57:34 +01:00
static preDraw = function(_x, _y, _s) {
2022-01-26 06:57:34 +01:00
var xx = x * _s + _x;
var yy = y * _s + _y;
2024-08-08 06:57:51 +02:00
inputs[0].x = xx;
inputs[0].y = yy;
2022-01-26 06:57:34 +01:00
2024-08-08 06:57:51 +02:00
outputs[0].x = xx;
outputs[0].y = yy;
}
2022-01-26 06:57:34 +01:00
2024-04-21 12:06:54 +02:00
static drawBadge = function(_x, _y, _s) {}
static drawJunctionNames = function(_x, _y, _mx, _my, _s) {}
static drawJunctions = function(_x, _y, _mx, _my, _s) {
2024-04-21 15:02:10 +02:00
var _dval = PANEL_GRAPH.value_dragging;
2024-08-20 10:15:53 +02:00
var hover = _dval == noone || _dval.connect_type == CONNECT_TYPE.input? outputs[0] : inputs[0];
2023-03-05 07:16:44 +01:00
var xx = x * _s + _x;
var yy = y * _s + _y;
2024-08-06 12:39:22 +02:00
isHovering = point_in_circle(_mx, _my, xx, yy, _s * 24);
hover_junction = noone;
2023-03-05 07:16:44 +01:00
2024-04-22 08:08:37 +02:00
var jhov = hover.drawJunction(_s, _mx, _my);
2022-01-26 06:57:34 +01:00
2024-04-21 15:02:10 +02:00
if(!isHovering) return noone;
2022-01-26 06:57:34 +01:00
2024-08-06 12:39:22 +02:00
hover_junction = jhov? hover : noone;
2024-04-21 15:02:10 +02:00
hover_scale_to = 1;
2024-08-06 12:39:22 +02:00
return hover_junction;
}
2022-01-26 06:57:34 +01:00
static drawNode = function(_x, _y, _mx, _my, _s) {
2022-01-26 06:57:34 +01:00
var xx = x * _s + _x;
var yy = y * _s + _y;
hover_alpha = 0.5;
2024-08-06 12:39:22 +02:00
2022-01-26 06:57:34 +01:00
if(active_draw_index > -1) {
2024-04-21 15:02:10 +02:00
hover_alpha = 1;
hover_scale_to = 1;
active_draw_index = -1;
2024-08-06 12:39:22 +02:00
}
2022-01-26 06:57:34 +01:00
if(hover_scale > 0) {
2024-08-06 12:39:22 +02:00
var _r = _s * 16;
2024-04-22 08:08:37 +02:00
shader_set(sh_node_circle);
shader_set_color("color", COLORS._main_accent, hover_alpha);
2024-08-06 12:39:22 +02:00
shader_set_f("radius", .5 * hover_scale);
2024-04-22 08:08:37 +02:00
draw_sprite_stretched(s_fx_pixel, 0, xx - _r, yy - _r, _r * 2, _r * 2);
2024-08-06 12:39:22 +02:00
shader_set_f("radius", 0);
2024-04-22 08:08:37 +02:00
shader_reset();
}
hover_scale = lerp_float(hover_scale, hover_scale_to, 3);
hover_scale_to = 0;
2023-10-01 06:17:39 +02:00
if(renamed && display_name != "" && display_name != "Pin") {
2024-04-22 09:56:37 +02:00
draw_set_text(f_sdf, fa_center, fa_bottom, COLORS._main_text);
2024-04-23 11:53:16 +02:00
draw_text_transformed(xx, yy - 12 * _s, display_name, _s * 0.4, _s * 0.4, 0);
2023-01-25 06:49:00 +01:00
}
2022-01-26 06:57:34 +01:00
return drawJunctions(_x, _y, _mx, _my, _s);
}
2022-01-13 05:24:03 +01:00
}