2023-02-28 09:43:01 +01:00
|
|
|
function Node_Palette(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Palette";
|
|
|
|
previewable = false;
|
|
|
|
|
|
|
|
w = 96;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
inputs[| 0] = nodeValue("Palette", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE)
|
2022-01-19 03:05:13 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.palette);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 1] = nodeValue("Trim range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ])
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider_range);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0] = nodeValue("Palette", self, JUNCTION_CONNECT.output, VALUE_TYPE.color, [])
|
2022-12-23 04:45:52 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.palette);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
input_display_list = [0,
|
|
|
|
["Trim", true], 1
|
|
|
|
];
|
|
|
|
|
2023-08-17 16:56:54 +02:00
|
|
|
static processData = function(_outSurf, _data, _output_index, _array_index) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var pal = _data[0];
|
|
|
|
var ran = _data[1];
|
|
|
|
|
|
|
|
var st = floor(clamp(min(ran[0], ran[1]), 0, 1) * array_length(pal));
|
|
|
|
var en = floor(clamp(max(ran[0], ran[1]), 0, 1) * array_length(pal));
|
|
|
|
var ar = [];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
for( var i = st; i < en; i++ )
|
2023-03-07 14:29:47 +01:00
|
|
|
ar[i - st] = array_safe_get(pal, i);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
return ar;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01: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-02-14 05:32:32 +01:00
|
|
|
var pal = outputs[| 0].getValue();
|
|
|
|
if(array_length(pal) && is_array(pal[0])) return;
|
|
|
|
|
|
|
|
drawPalette(pal, bbox.x0, bbox.y0, bbox.w, bbox.h);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|