Pixel-Composer/scripts/node_boolean/node_boolean.gml

88 lines
2.7 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Boolean(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-12-03 05:02:04 +01:00
name = "Boolean";
2023-01-09 03:14:20 +01:00
color = COLORS.node_blend_number;
w = 64;
min_h = 64;
hover_state = 0;
hover_state_to = 0;
2023-01-09 03:14:20 +01:00
wd_checkBox = new checkBox( function() { inputs[| 0].setValue(!getInputData(0)); } );
2023-03-05 07:16:44 +01:00
wd_checkBox.spr = THEME.node_checkbox;
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false)
2023-01-09 03:14:20 +01:00
.setVisible(true, true);
inputs[| 1] = nodeValue("Hide Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
inputs[| 2] = nodeValue("Name location", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
.setDisplay(VALUE_DISPLAY.enum_button, [ "Top", "Bottom" ]);
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Boolean", self, JUNCTION_CONNECT.output, VALUE_TYPE.boolean, false);
2023-01-09 03:14:20 +01:00
input_display_list = [ 0,
["Display", false], 1, 2,
]
2023-08-17 16:56:54 +02:00
static processData = function(_output, _data, _output_index, _array_index = 0) {
2023-01-09 03:14:20 +01:00
return _data[0];
}
static pointIn = function(_x, _y, _mx, _my, _s) {
var align = getInputData(2);
var xx = x * _s + _x;
var yy = (y - (!align * 20)) * _s + _y;
return point_in_rectangle(_mx, _my, xx, yy, xx + w * _s, yy + (h + 20) * _s);
}
static onDrawHover = function(xx, yy, _mx, _my, _s, _hover = false, _focus = false) {
hover_state_to = 1;
}
static drawNodeBase = function(xx, yy, _s) {
if(!active) return;
var hid = getInputData(1);
if(hid) {
hover_state = lerp_float(hover_state, hover_state_to, 3);
hover_state_to = 0;
} else
hover_state = 1;
var aa = (0.25 + 0.5 * renderActive) * hover_state;
draw_sprite_stretched_ext(bg_spr, 0, xx, yy, w * _s, h * _s, color, aa);
}
static drawNodeName = function(xx, yy, _s) {
draw_name = false;
if(!active) return;
if(_s < 0.75) return;
var _name = renamed? display_name : name;
if(_name == "") return;
var hid = getInputData(1);
var align = getInputData(2);
if(align == 0) {
draw_set_text(f_p2, fa_center, fa_bottom, COLORS._main_text);
draw_text_ext_add(xx + w * _s / 2, yy - 2 + hid * ((1 - hover_state) * 8), _name, -1, 128 * _s);
} else if(align == 1) {
draw_set_text(f_p2, fa_center, fa_top, COLORS._main_text);
draw_text_ext_add(xx + w * _s / 2, yy + h * _s - hid * ((1 - hover_state) * 8), _name, -1, 128 * _s);
}
}
static drawDimension = function(xx, yy, _s) {}
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
var val = getInputData(0);
2023-01-09 03:14:20 +01:00
var bbox = drawGetBbox(xx, yy, _s);
2023-03-05 07:16:44 +01:00
2023-06-21 20:36:53 +02:00
wd_checkBox.setFocusHover(_focus, _hover);
wd_checkBox.draw(bbox.xc, bbox.yc, val, [ _mx, _my ], bbox.h - 8 * _s, fa_center, fa_center);
2023-01-09 03:14:20 +01:00
}
}