2023-03-02 07:59:14 +01:00
|
|
|
function Node_Gradient_Palette(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2023-05-28 20:00:51 +02:00
|
|
|
name = "Palette to Gradient";
|
2023-03-02 07:59:14 +01:00
|
|
|
previewable = false;
|
|
|
|
|
|
|
|
w = 96;
|
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
inputs[| 0] = nodeValue("Palette", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE )
|
2023-03-02 07:59:14 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.palette)
|
|
|
|
.setVisible(true, true);
|
|
|
|
|
|
|
|
inputs[| 1] = nodeValue("Custom positions", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
|
|
|
|
|
|
|
|
inputs[| 2] = nodeValue("Positions", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [], "Array of number indicating color position (0 - 1).")
|
|
|
|
.setVisible(true, true);
|
|
|
|
inputs[| 2].array_depth = 1;
|
|
|
|
|
|
|
|
inputs[| 3] = nodeValue("Blending", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
|
|
|
.setDisplay(VALUE_DISPLAY.enum_button, [ "RGB", "HSV", "Hard" ]);
|
|
|
|
|
2023-05-28 20:00:51 +02:00
|
|
|
outputs[| 0] = nodeValue("Gradient", self, JUNCTION_CONNECT.output, VALUE_TYPE.gradient, new gradientObject(c_white) )
|
2023-03-02 07:59:14 +01:00
|
|
|
|
|
|
|
_pal = -1;
|
|
|
|
|
|
|
|
static step = function() {
|
|
|
|
var usePos = array_safe_get(current_data, 1);
|
|
|
|
inputs[| 2].setVisible(usePos, usePos);
|
|
|
|
}
|
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
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
|
|
|
|
2023-07-28 19:41:57 +02:00
|
|
|
//print("Process gradient");
|
|
|
|
for( var i = 0; i < len; i++ ) {
|
2023-03-02 07:59:14 +01:00
|
|
|
var clr = pal[i];
|
2023-07-28 19:41:57 +02:00
|
|
|
var pos = pos_use? array_safe_get(_pos, i, 0) : i / len;
|
2023-03-02 07:59:14 +01:00
|
|
|
|
|
|
|
grad.keys[i] = new gradientKey(pos, clr);
|
2023-07-28 19:41:57 +02:00
|
|
|
//print($" {i} = {pos} : {clr}");
|
2023-03-02 07:59:14 +01:00
|
|
|
}
|
2023-07-28 19:41:57 +02:00
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
switch(type) {
|
|
|
|
case 0 : grad.type = GRADIENT_INTER.smooth; break;
|
|
|
|
case 1 : grad.type = GRADIENT_INTER.hue; break;
|
|
|
|
case 2 : grad.type = GRADIENT_INTER.none; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return grad;
|
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
2023-03-02 07:59:14 +01:00
|
|
|
var bbox = drawGetBbox(xx, yy, _s);
|
|
|
|
if(bbox.h < 1) return;
|
|
|
|
|
|
|
|
var grad = outputs[| 0].getValue();
|
|
|
|
if(is_array(grad)) {
|
|
|
|
if(array_length(grad) == 0) return;
|
|
|
|
grad = grad[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
grad.draw(bbox.x0, bbox.y0, bbox.w, bbox.h);
|
|
|
|
}
|
|
|
|
}
|