Pixel-Composer/scripts/node_gradient_out/node_gradient_out.gml

48 lines
1.5 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Gradient_Out(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-12-10 02:48:10 +01:00
name = "Gradient";
batch_output = false;
2024-03-28 14:18:02 +01:00
setDimension(96);
2022-01-13 05:24:03 +01:00
2024-01-08 08:10:50 +01:00
inputs[| 0] = nodeValue("Gradient", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject([ cola(c_black), cola(c_white) ]) );
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Sample", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0, "Position to sample a color from the gradient.")
.setDisplay(VALUE_DISPLAY.slider)
2023-01-25 06:49:00 +01:00
.rejectArray();
2022-01-13 05:24:03 +01:00
2024-07-27 07:10:34 +02:00
outputs[| 0] = nodeValue("Gradient", self, JUNCTION_CONNECT.output, VALUE_TYPE.gradient, new gradientObject(cola(c_white)) );
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
outputs[| 1] = nodeValue("Color", self, JUNCTION_CONNECT.output, VALUE_TYPE.color, c_white);
2022-01-13 05:24:03 +01:00
_pal = -1;
2023-02-14 05:32:32 +01:00
2024-07-27 07:10:34 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2023-02-14 05:32:32 +01:00
var pal = _data[0];
var pos = _data[1];
2022-01-13 05:24:03 +01:00
2023-08-24 11:59:05 +02:00
if(!is_instanceof(pal, gradientObject)) return 0;
2023-03-13 10:45:56 +01:00
2023-02-14 05:32:32 +01:00
if(_output_index == 0) return pal;
2023-03-02 07:59:14 +01:00
if(_output_index == 1) return pal.eval(pos);
2023-02-14 05:32:32 +01:00
return 0;
2024-07-27 07:10:34 +02:00
}
2022-01-13 05:24:03 +01:00
2024-07-27 07:10:34 +02:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-01-04 02:30:04 +01:00
var bbox = drawGetBbox(xx, yy, _s);
if(bbox.h < 1) return;
2022-01-13 05:24:03 +01:00
2023-12-10 02:48:10 +01:00
var grad = outputs[| 0].getValue();
if(!is_array(grad)) grad = [ grad ];
var _h = array_length(grad) * 32;
var _y = bbox.y0;
var gh = bbox.h / array_length(grad);
for( var i = 0, n = array_length(grad); i < n; i++ ) {
grad[i].draw(bbox.x0, _y, bbox.w, gh);
_y += gh;
}
if(_h != min_h) will_setHeight = true;
min_h = _h;
2024-07-27 07:10:34 +02:00
}
2022-01-13 05:24:03 +01:00
}