Pixel-Composer/scripts/node_palette/node_palette.gml

50 lines
1.3 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Palette(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-12-10 02:48:10 +01:00
name = "Palette";
2024-12-13 03:07:34 +01:00
setDimension(96, 48);
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Palette("Palette", self, array_clone(DEF_PALETTE)));
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Slider_Range("Trim range", self, [ 0, 1 ]));
2022-01-13 05:24:03 +01:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Palette", self, 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
];
2024-11-23 07:26:39 +01:00
static processData_prebatch = function() {
2024-12-13 03:07:34 +01:00
setDimension(96, 16 + process_length[0] * 32);
2024-11-23 07:26:39 +01: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++ )
2024-03-31 05:36:11 +02:00
ar[i - st] = array_safe_get_fast(pal, i);
2023-02-14 05:32:32 +01:00
return ar;
}
2022-01-13 05:24:03 +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
2024-08-08 06:57:51 +02:00
var pal = outputs[0].getValue();
2023-12-10 02:48:10 +01:00
if(array_empty(pal)) return;
if(!is_array(pal[0])) pal = [ pal ];
var _y = bbox.y0;
var gh = bbox.h / array_length(pal);
for( var i = 0, n = array_length(pal); i < n; i++ ) {
drawPalette(pal[i], bbox.x0, _y, bbox.w, gh);
_y += gh;
}
}
2022-01-13 05:24:03 +01:00
}