Pixel-Composer/scripts/node_gradient_shift/node_gradient_shift.gml

66 lines
1.7 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Gradient_Shift(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-12-10 02:48:10 +01:00
name = "Gradient Shift";
2024-03-28 14:18:02 +01:00
setDimension(96);
2023-02-21 04:48:50 +01:00
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_Gradient("Gradient", self, new gradientObject(cola(c_white))))
.setVisible(true, true);
2023-02-21 04:48:50 +01:00
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_Float("Shift", self, 0))
.setDisplay(VALUE_DISPLAY.slider, { range: [-1, 1, 0.01] });
2023-02-21 04:48:50 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Bool("Wrap", self, false))
2023-02-21 04:48:50 +01:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Float("Scale", self, 1))
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 2, 0.01] });
2023-03-08 12:14:01 +01:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Gradient", self, VALUE_TYPE.gradient, new gradientObject(cola(c_white)) ));
2023-02-21 04:48:50 +01:00
_pal = -1;
2023-12-10 02:48:10 +01:00
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
2023-02-21 04:48:50 +01:00
var pal = _data[0];
var sft = _data[1];
var lop = _data[2];
2023-03-08 12:14:01 +01:00
var sca = _data[3];
2023-02-21 04:48:50 +01:00
2023-03-02 07:59:14 +01:00
_outSurf = new gradientObject();
2023-03-07 14:29:47 +01:00
_outSurf.keys = [];
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(pal.keys); i < n; i++ ) {
2023-03-02 07:59:14 +01:00
var k = pal.keys[i];
2023-03-08 12:14:01 +01:00
var key = new gradientKey((0.5 + (k.time - 0.5) * sca) + sft, k.value);
2023-03-07 14:29:47 +01:00
if(lop) {
var t = frac(key.time);
if(t < 0) t = 1 + t;
key.time = t;
}
_outSurf.add(key);
2023-02-21 04:48:50 +01:00
}
2023-03-02 07:59:14 +01:00
_outSurf.type = pal.type;
2023-02-21 04:48:50 +01:00
return _outSurf;
2023-12-10 02:48:10 +01:00
} #endregion
2023-02-21 04:48:50 +01:00
2023-12-10 02:48:10 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2023-02-21 04:48:50 +01:00
var bbox = drawGetBbox(xx, yy, _s);
if(bbox.h < 1) return;
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;
} #endregion
2023-02-21 04:48:50 +01:00
}