Pixel-Composer/scripts/node_gradient_palette/node_gradient_palette.gml

74 lines
2.2 KiB
Text
Raw Normal View History

2023-03-02 07:59:14 +01:00
function Node_Gradient_Palette(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-12-10 02:48:10 +01:00
name = "Palette to Gradient";
setDimension(96);
2023-03-02 07:59:14 +01:00
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_Palette("Palette", self, array_clone(DEF_PALETTE)))
2023-03-02 07:59:14 +01:00
.setVisible(true, true);
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Bool("Custom positions", self, false));
2023-03-02 07:59:14 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Float("Positions", self, [], "Array of number indicating color position (0 - 1)."))
2023-03-02 07:59:14 +01:00
.setVisible(true, true);
2024-08-08 06:57:51 +02:00
inputs[2].array_depth = 1;
2023-03-02 07:59:14 +01:00
2024-08-18 06:16:20 +02:00
newInput(3, nodeValue_Enum_Button("Interpolation", self, 1, [ "None", "RGB", "HSV", "OKLAB", "sRGB" ]));
2023-03-02 07:59:14 +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-03-02 07:59:14 +01:00
_pal = -1;
2023-12-10 02:48:10 +01:00
static step = function() { #region
2024-03-31 05:36:11 +02:00
var usePos = array_safe_get_fast(current_data, 1);
2024-08-08 06:57:51 +02:00
inputs[2].setVisible(usePos, usePos);
2023-12-10 02:48:10 +01:00
} #endregion
2023-03-02 07:59:14 +01:00
2023-12-10 02:48:10 +01:00
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
2023-03-02 07:59:14 +01:00
var pal = _data[0];
var pos_use = _data[1];
var _pos = _data[2];
var type = _data[3];
var grad = new gradientObject();
2023-07-28 19:41:57 +02:00
var len = min(128, array_length(pal));
grad.keys = array_create(len);
2023-03-02 07:59:14 +01:00
var _stp = type == GRADIENT_INTER.none? 1 / (len - 1) : 1 / len;
2023-07-28 19:41:57 +02:00
for( var i = 0; i < len; i++ ) {
2023-03-02 07:59:14 +01:00
var clr = pal[i];
var pos = pos_use? array_safe_get_fast(_pos, i, 0) : i * _stp;
2023-03-02 07:59:14 +01:00
grad.keys[i] = new gradientKey(pos, clr);
}
2023-07-28 19:41:57 +02:00
2023-03-02 07:59:14 +01:00
switch(type) {
2024-02-10 07:03:50 +01:00
case 0 : grad.type = GRADIENT_INTER.none; break;
case 1 : grad.type = GRADIENT_INTER.smooth; break;
case 2 : grad.type = GRADIENT_INTER.hue; break;
case 3 : grad.type = GRADIENT_INTER.oklab; break;
2024-02-12 10:25:23 +01:00
case 4 : grad.type = GRADIENT_INTER.srgb; break;
2023-03-02 07:59:14 +01:00
}
return grad;
2023-12-10 02:48:10 +01:00
} #endregion
2023-03-02 07:59:14 +01:00
2023-12-10 02:48:10 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2023-03-02 07:59:14 +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;
2023-03-02 07:59:14 +01:00
}
2023-12-10 02:48:10 +01:00
if(_h != min_h) will_setHeight = true;
min_h = _h;
} #endregion
2023-03-02 07:59:14 +01:00
}