Pixel-Composer/scripts/node_gradient_out/node_gradient_out.gml

48 lines
1.4 KiB
Text
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-08-18 06:16:20 +02:00
newInput(0, nodeValue_Gradient("Gradient", self, new gradientObject([ cola(c_black), cola(c_white) ])));
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_Float("Sample", self, 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-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Gradient", self, VALUE_TYPE.gradient, new gradientObject(cola(c_white)) ));
2022-01-13 05:24:03 +01:00
2024-09-04 03:57:11 +02:00
newOutput(1, nodeValue_Output("Color", self, 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
2024-08-08 06:57:51 +02:00
var grad = outputs[0].getValue();
2023-12-10 02:48:10 +01:00
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
}