Pixel-Composer/scripts/node_path_trim/node_path_trim.gml

82 lines
2.8 KiB
Text
Raw Normal View History

function Node_Path_Trim(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2024-01-22 14:23:35 +01:00
name = "Trim Path";
2025-01-01 02:12:36 +01:00
setDimension(96, 48);
2023-02-14 02:48:33 +01:00
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_PathNode("Path", self, noone))
2023-02-14 02:48:33 +01:00
.setVisible(true, true);
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Slider_Range("Range", self, [ 0, 1 ]));
2023-02-14 02:48:33 +01:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Path", self, VALUE_TYPE.pathnode, self));
2023-02-14 02:48:33 +01:00
function _trimmedPath() constructor {
curr_path = noone;
curr_range = noone;
is_path = false;
2024-01-22 14:23:35 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
if(curr_path && struct_has(curr_path, "drawOverlay"))
curr_path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
2024-01-22 14:23:35 +01:00
draw_set_color(COLORS._main_icon);
var _amo = getLineCount();
for( var i = 0; i < _amo; i++ ) {
var _len = getLength(_amo);
var _stp = 1 / clamp(_len * _s, 1, 64);
var ox, oy, nx, ny;
var _p = new __vec2P();
2024-01-22 14:23:35 +01:00
for( var j = 0; j < 1; j += _stp ) {
_p = getPointRatio(j, i, _p);
nx = _x + _p.x * _s;
ny = _y + _p.y * _s;
if(j > 0) draw_line_width(ox, oy, nx, ny, 3);
ox = nx;
oy = ny;
}
2024-01-22 14:23:35 +01:00
}
}
2025-01-16 04:39:54 +01:00
static getLineCount = function( ) /*=>*/ {return is_path? curr_path.getLineCount() : 1};
static getSegmentCount = function(i=0) /*=>*/ {return is_path? curr_path.getSegmentCount(i) : 0};
static getLength = function(i=0) /*=>*/ {return is_path? curr_path.getLength(i) : 0};
static getAccuLength = function(i=0) /*=>*/ {return is_path? curr_path.getAccuLength(i) : []};
static getBoundary = function(i=0) /*=>*/ {return is_path? curr_path.getBoundary(i) : new BoundingBox( 0, 0, 1, 1 )};
static getPointRatio = function(_rat, ind = 0, out = undefined) {
if(!is_path) return out;
_rat = lerp(curr_range[0], curr_range[1], _rat);
return curr_path.getPointRatio(_rat, ind, out);
}
2023-10-29 06:29:10 +01:00
static getPointDistance = function(_dist, ind = 0, out = undefined) { return getPointRatio(_dist / getLength(), ind, out); }
}
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _path = getSingleValue(0, preview_index, true);
if(struct_has(_path, "drawOverlay")) _path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
2025-01-15 07:55:00 +01:00
}
2023-03-19 09:17:39 +01:00
static processData = function(_outData, _data, _output_index, _array_index = 0) {
if(!is(_outData, _trimmedPath))
_outData = new _trimmedPath();
_outData.cached_pos = {};
_outData.curr_path = _data[0];
_outData.curr_range = _data[1];
_outData.is_path = struct_has(_outData.curr_path, "getPointRatio");
2025-01-16 04:39:54 +01:00
return _outData;
2025-01-16 04:39:54 +01:00
2025-01-15 07:55:00 +01:00
}
2023-02-14 02:48:33 +01:00
2025-01-15 07:55:00 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-02-14 02:48:33 +01:00
var bbox = drawGetBbox(xx, yy, _s);
2023-02-14 11:40:24 +01:00
draw_sprite_fit(s_node_path_trim, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
2025-01-15 07:55:00 +01:00
}
2023-02-14 02:48:33 +01:00
}