2023-06-13 14:42:06 +02:00
|
|
|
enum _ANCHOR {
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
c1x,
|
|
|
|
c1y,
|
|
|
|
c2x,
|
|
|
|
c2y,
|
|
|
|
|
|
|
|
ind,
|
|
|
|
}
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
function Node_Path(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Path";
|
|
|
|
previewable = false;
|
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
w = 96;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-04-04 09:49:33 +02:00
|
|
|
inputs[| 0] = nodeValue("Path progress", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0, "Sample position from path.")
|
2022-01-13 05:24:03 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 1] = nodeValue("Loop", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false)
|
|
|
|
.rejectArray();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 2] = nodeValue("Progress mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, ["Entire line", "Segment"])
|
|
|
|
.rejectArray();
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-03-11 01:40:17 +01:00
|
|
|
inputs[| 3] = nodeValue("Round anchor", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false)
|
|
|
|
.rejectArray();
|
2023-05-04 10:23:01 +02:00
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
input_display_list = [
|
2023-03-11 01:40:17 +01:00
|
|
|
["Path", false], 0, 2, 1, 3,
|
2023-01-25 06:49:00 +01:00
|
|
|
["Anchors", false],
|
2023-01-09 03:14:20 +01:00
|
|
|
];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
setIsDynamicInput(1);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
function createAnchor(_x = 0, _y = 0, _dxx = 0, _dxy = 0, _dyx = 0, _dyy = 0) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var index = ds_list_size(inputs);
|
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
inputs[| index] = nodeValue("Anchor", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ _x, _y, _dxx, _dxy, _dyx, _dyy, false ])
|
2022-01-19 14:48:30 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.vector);
|
2023-05-07 20:55:13 +02:00
|
|
|
|
|
|
|
recordAction(ACTION_TYPE.var_modify, self, [ array_clone(input_display_list), "input_display_list" ]);
|
|
|
|
recordAction(ACTION_TYPE.list_insert, inputs, [ inputs[| index], index, "add path anchor point" ]);
|
2023-01-25 06:49:00 +01:00
|
|
|
array_push(input_display_list, index);
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
return inputs[| index];
|
|
|
|
}
|
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
static createNewInput = function() { createAnchor(0, 0); }
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 0] = nodeValue("Position out", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, [ 0, 0 ])
|
2023-01-09 03:14:20 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.vector);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
outputs[| 1] = nodeValue("Path data", self, JUNCTION_CONNECT.output, VALUE_TYPE.pathnode, self);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
|
|
|
outputs[| 2] = nodeValue("Anchors", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, []);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-11 01:40:17 +01:00
|
|
|
tool_pathDrawer = new NodeTool( "Draw path", THEME.path_tools_draw )
|
|
|
|
.addSetting("Smoothness", VALUE_TYPE.float, function(val) { tool_pathDrawer.attribute.thres = val; }, "thres", 4)
|
|
|
|
.addSetting("Replace", VALUE_TYPE.boolean, function() { tool_pathDrawer.attribute.create = !tool_pathDrawer.attribute.create; }, "create", true);
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
tools = [
|
2023-03-19 09:17:39 +01:00
|
|
|
new NodeTool( "Transform", THEME.path_tools_transform ),
|
2023-03-11 01:40:17 +01:00
|
|
|
new NodeTool( "Anchor add / remove (+ Shift)", THEME.path_tools_add ),
|
|
|
|
new NodeTool( "Edit Control point", THEME.path_tools_anchor ),
|
|
|
|
tool_pathDrawer,
|
|
|
|
new NodeTool( "Rectangle path", THEME.path_tools_rectangle ),
|
|
|
|
new NodeTool( "Circle path", THEME.path_tools_circle ),
|
2022-01-13 05:24:03 +01:00
|
|
|
];
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
anchors = [];
|
|
|
|
lengths = [];
|
|
|
|
lengthAccs = [];
|
|
|
|
boundary = [];
|
|
|
|
lengthTotal = 0;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-18 17:51:40 +02:00
|
|
|
cached_pos = ds_map_create();
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_point = -1;
|
2023-03-11 01:40:17 +01:00
|
|
|
drag_points = [];
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_type = 0;
|
|
|
|
drag_point_mx = 0;
|
|
|
|
drag_point_my = 0;
|
|
|
|
drag_point_sx = 0;
|
|
|
|
drag_point_sy = 0;
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
transform_type = 0;
|
2023-06-13 14:42:06 +02:00
|
|
|
transform_minx = 0; transform_miny = 0;
|
|
|
|
transform_maxx = 0; transform_maxy = 0;
|
|
|
|
transform_cx = 0; transform_cy = 0;
|
|
|
|
transform_sx = 0; transform_sy = 0;
|
|
|
|
transform_mx = 0; transform_my = 0;
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
static onValueUpdate = function(index = 0) {
|
2023-01-09 03:14:20 +01:00
|
|
|
if(index == 2) {
|
|
|
|
var type = inputs[| 2].getValue();
|
|
|
|
if(type == 0)
|
|
|
|
inputs[| 0].setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
|
|
|
else if(type == 1)
|
|
|
|
inputs[| 0].setDisplay(VALUE_DISPLAY._default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 13:35:30 +01:00
|
|
|
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var sample = PREF_MAP[? "path_resolution"];
|
|
|
|
var loop = inputs[| 1].getValue();
|
2023-01-25 06:49:00 +01:00
|
|
|
var ansize = ds_list_size(inputs) - input_fix_len;
|
2023-05-03 21:42:17 +02:00
|
|
|
var _edited = false;
|
2023-03-11 01:40:17 +01:00
|
|
|
|
2023-07-15 20:01:29 +02:00
|
|
|
var pos = outputs[| 0].getValue();
|
|
|
|
|
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
draw_circle(_x + pos[0] * _s, _y + pos[1] * _s, 4, false);
|
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(transform_type > 0) {
|
2023-03-19 09:17:39 +01:00
|
|
|
var _transform_minx = transform_minx;
|
|
|
|
var _transform_miny = transform_miny;
|
|
|
|
var _transform_maxx = transform_maxx;
|
|
|
|
var _transform_maxy = transform_maxy;
|
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(transform_type == 5) { #region move
|
|
|
|
var mx = _mx, my = _my;
|
|
|
|
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
var dirr = point_direction(transform_sx, transform_sy, _mx, _my) + 360;
|
|
|
|
var diss = point_distance( transform_sx, transform_sy, _mx, _my);
|
|
|
|
var ang = round((dirr) / 45) * 45;
|
|
|
|
mx = transform_sx + lengthdir_x(diss, ang);
|
|
|
|
my = transform_sy + lengthdir_y(diss, ang);
|
|
|
|
}
|
|
|
|
|
|
|
|
//var _tsx = transform_sx;
|
|
|
|
//var _tsy = transform_sy;
|
|
|
|
//draw_set_color(COLORS._main_accent);
|
|
|
|
//draw_line(_tsx, _tsy, _tsx + lengthdir_x(1000, 0), _tsy + lengthdir_y(1000, 0));
|
|
|
|
//draw_line(_tsx, _tsy, _tsx + lengthdir_x(1000, 90), _tsy + lengthdir_y(1000, 90));
|
|
|
|
//draw_line(_tsx, _tsy, _tsx + lengthdir_x(1000, 180), _tsy + lengthdir_y(1000, 180));
|
|
|
|
//draw_line(_tsx, _tsy, _tsx + lengthdir_x(1000, 270), _tsy + lengthdir_y(1000, 270));
|
|
|
|
|
|
|
|
var dx = mx - transform_mx;
|
|
|
|
var dy = my - transform_my;
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
for( var i = input_fix_len; i < ds_list_size(inputs); i++ ) {
|
|
|
|
var p = inputs[| i].getValue();
|
|
|
|
|
|
|
|
p[0] += dx / _s;
|
|
|
|
p[1] += dy / _s;
|
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
if(inputs[| i].setValue(p))
|
|
|
|
_edited = true;
|
2023-03-19 09:17:39 +01:00
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
|
|
|
|
transform_mx = mx;
|
|
|
|
transform_my = my;
|
|
|
|
#endregion
|
|
|
|
} else { #region scale
|
|
|
|
var mx = (_mx - _x) / _s;
|
|
|
|
var my = (_my - _y) / _s;
|
|
|
|
|
|
|
|
switch(transform_type) {
|
|
|
|
case 1 :
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
var _dx = mx - _transform_maxx;
|
|
|
|
var _dy = my - _transform_maxy;
|
|
|
|
var _dd = max(abs(_dx), abs(_dy));
|
|
|
|
|
|
|
|
mx = _transform_maxx + _dd * sign(_dx);
|
|
|
|
my = _transform_maxy + _dd * sign(_dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
transform_minx = mx;
|
|
|
|
transform_miny = my;
|
|
|
|
|
|
|
|
if(key_mod_press(ALT)) {
|
|
|
|
transform_maxx = transform_cx - (mx - transform_cx);
|
|
|
|
transform_maxy = transform_cy - (my - transform_cy);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2 :
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
var _dx = mx - _transform_minx;
|
|
|
|
var _dy = my - _transform_maxy;
|
|
|
|
var _dd = max(abs(_dx), abs(_dy));
|
|
|
|
|
|
|
|
mx = _transform_minx + _dd * sign(_dx);
|
|
|
|
my = _transform_maxy + _dd * sign(_dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
transform_maxx = mx;
|
|
|
|
transform_miny = my;
|
|
|
|
|
|
|
|
if(key_mod_press(ALT)) {
|
|
|
|
transform_minx = transform_cx - (mx - transform_cx);
|
|
|
|
transform_maxy = transform_cy - (my - transform_cy);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3 :
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
var _dx = mx - _transform_maxx;
|
|
|
|
var _dy = my - _transform_miny;
|
|
|
|
var _dd = max(abs(_dx), abs(_dy));
|
|
|
|
|
|
|
|
mx = _transform_maxx + _dd * sign(_dx);
|
|
|
|
my = _transform_miny + _dd * sign(_dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
transform_minx = mx;
|
|
|
|
transform_maxy = my;
|
|
|
|
|
|
|
|
if(key_mod_press(ALT)) {
|
|
|
|
transform_maxx = transform_cx - (mx - transform_cx);
|
|
|
|
transform_miny = transform_cy - (my - transform_cy);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4 :
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
var _dx = mx - _transform_minx;
|
|
|
|
var _dy = my - _transform_miny;
|
|
|
|
var _dd = max(abs(_dx), abs(_dy));
|
|
|
|
|
|
|
|
mx = _transform_minx + _dd * sign(_dx);
|
|
|
|
my = _transform_miny + _dd * sign(_dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
transform_maxx = mx;
|
|
|
|
transform_maxy = my;
|
|
|
|
|
|
|
|
if(key_mod_press(ALT)) {
|
|
|
|
transform_minx = transform_cx - (mx - transform_cx);
|
|
|
|
transform_miny = transform_cy - (my - transform_cy);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tr_rx = transform_maxx - transform_minx;
|
|
|
|
var tr_ry = transform_maxy - transform_miny;
|
|
|
|
var _tr_rx = _transform_maxx - _transform_minx;
|
|
|
|
var _tr_ry = _transform_maxy - _transform_miny;
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
for( var i = input_fix_len; i < ds_list_size(inputs); i++ ) {
|
2023-06-13 14:42:06 +02:00
|
|
|
var p = inputs[| i].getValue();
|
|
|
|
|
|
|
|
var _p2 = p[_ANCHOR.x] + p[_ANCHOR.c1x];
|
|
|
|
var _p3 = p[_ANCHOR.y] + p[_ANCHOR.c1y];
|
|
|
|
var _p4 = p[_ANCHOR.x] + p[_ANCHOR.c2x];
|
|
|
|
var _p5 = p[_ANCHOR.y] + p[_ANCHOR.c2y];
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
p[_ANCHOR.x] = transform_minx + (p[_ANCHOR.x] - _transform_minx) / _tr_rx * tr_rx;
|
|
|
|
p[_ANCHOR.y] = transform_miny + (p[_ANCHOR.y] - _transform_miny) / _tr_ry * tr_ry;
|
|
|
|
|
|
|
|
_p2 = transform_minx + (_p2 - _transform_minx) / _tr_rx * tr_rx;
|
|
|
|
_p3 = transform_miny + (_p3 - _transform_miny) / _tr_ry * tr_ry;
|
|
|
|
_p4 = transform_minx + (_p4 - _transform_minx) / _tr_rx * tr_rx;
|
|
|
|
_p5 = transform_miny + (_p5 - _transform_miny) / _tr_ry * tr_ry;
|
|
|
|
|
|
|
|
p[_ANCHOR.c1x] = _p2 - p[_ANCHOR.x];
|
|
|
|
p[_ANCHOR.c1y] = _p3 - p[_ANCHOR.y];
|
|
|
|
p[_ANCHOR.c2x] = _p4 - p[_ANCHOR.x];
|
|
|
|
p[_ANCHOR.c2y] = _p5 - p[_ANCHOR.y];
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
if(inputs[| i].setValue(p))
|
|
|
|
_edited = true;
|
2023-03-19 09:17:39 +01:00
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
2023-03-19 09:17:39 +01:00
|
|
|
}
|
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
if(_edited)
|
|
|
|
UNDO_HOLDING = true;
|
2023-03-19 09:17:39 +01:00
|
|
|
|
|
|
|
if(mouse_release(mb_left)) {
|
|
|
|
transform_type = 0;
|
|
|
|
UPDATE |= RENDER_TYPE.full;
|
2023-05-03 21:42:17 +02:00
|
|
|
UNDO_HOLDING = false;
|
2023-03-19 09:17:39 +01:00
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
} else if(drag_point > -1) {
|
2022-12-19 13:35:30 +01:00
|
|
|
var dx = value_snap(drag_point_sx + (_mx - drag_point_mx) / _s, _snx);
|
|
|
|
var dy = value_snap(drag_point_sy + (_my - drag_point_my) / _s, _sny);
|
2023-05-05 08:58:56 +02:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(drag_type < 2) { #region move points
|
2023-01-25 06:49:00 +01:00
|
|
|
var inp = inputs[| input_fix_len + drag_point];
|
2022-12-12 09:08:03 +01:00
|
|
|
var anc = inp.getValue();
|
2023-05-03 21:42:17 +02:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(drag_type != 0 && SHIFT == KEYBOARD_STATUS.down)
|
|
|
|
anc[_ANCHOR.ind] = !anc[_ANCHOR.ind];
|
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
if(drag_type == 0) { //drag anchor point
|
2023-06-13 14:42:06 +02:00
|
|
|
anc[_ANCHOR.x] = dx;
|
|
|
|
anc[_ANCHOR.y] = dy;
|
2022-12-22 03:09:55 +01:00
|
|
|
if(key_mod_press(CTRL)) {
|
2023-06-13 14:42:06 +02:00
|
|
|
anc[_ANCHOR.x] = round(anc[0]);
|
|
|
|
anc[_ANCHOR.y] = round(anc[1]);
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
2023-03-29 15:02:03 +02:00
|
|
|
} else if(drag_type == 1) { //drag control 1
|
2023-06-13 14:42:06 +02:00
|
|
|
anc[_ANCHOR.c1x] = dx - anc[_ANCHOR.x];
|
|
|
|
anc[_ANCHOR.c1y] = dy - anc[_ANCHOR.y];
|
2023-03-29 15:02:03 +02:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(!anc[_ANCHOR.ind]) {
|
|
|
|
anc[_ANCHOR.c2x] = -anc[_ANCHOR.c1x];
|
|
|
|
anc[_ANCHOR.c2y] = -anc[_ANCHOR.c1y];
|
2023-03-29 15:02:03 +02:00
|
|
|
}
|
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
if(key_mod_press(CTRL)) {
|
2023-06-13 14:42:06 +02:00
|
|
|
anc[_ANCHOR.c1x] = round(anc[_ANCHOR.c1x]);
|
|
|
|
anc[_ANCHOR.c1y] = round(anc[_ANCHOR.c1y]);
|
2023-03-29 15:02:03 +02:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(!anc[_ANCHOR.ind]) {
|
|
|
|
anc[_ANCHOR.c2x] = round(anc[_ANCHOR.c2x]);
|
|
|
|
anc[_ANCHOR.c2y] = round(anc[_ANCHOR.c2y]);
|
2023-03-29 15:02:03 +02:00
|
|
|
}
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
2023-03-29 15:02:03 +02:00
|
|
|
} else if(drag_type == -1) { //drag control 2
|
2023-06-13 14:42:06 +02:00
|
|
|
anc[_ANCHOR.c2x] = dx - anc[_ANCHOR.x];
|
|
|
|
anc[_ANCHOR.c2y] = dy - anc[_ANCHOR.y];
|
2023-03-29 15:02:03 +02:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(!anc[_ANCHOR.ind]) {
|
|
|
|
anc[_ANCHOR.c1x] = -anc[4];
|
|
|
|
anc[_ANCHOR.c1y] = -anc[5];
|
2023-03-29 15:02:03 +02:00
|
|
|
}
|
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
if(key_mod_press(CTRL)) {
|
2023-06-13 14:42:06 +02:00
|
|
|
anc[_ANCHOR.c2x] = round(anc[_ANCHOR.c2x]);
|
|
|
|
anc[_ANCHOR.c2y] = round(anc[_ANCHOR.c2y]);
|
2023-03-29 15:02:03 +02:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(!anc[_ANCHOR.ind]) {
|
|
|
|
anc[_ANCHOR.c1x] = round(anc[_ANCHOR.c1x]);
|
|
|
|
anc[_ANCHOR.c1y] = round(anc[_ANCHOR.c1y]);
|
2023-03-29 15:02:03 +02:00
|
|
|
}
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
if(inp.setValue(anc))
|
|
|
|
_edited = true;
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
|
|
|
} else if(drag_type == 2) { #region pen tools
|
2023-03-11 01:40:17 +01:00
|
|
|
var ox, oy, nx, ny;
|
|
|
|
var pxx = (_mx - _x) / _s;
|
|
|
|
var pxy = (_my - _y) / _s;
|
|
|
|
|
|
|
|
draw_set_color(COLORS._main_accent);
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(drag_points); i < n; i++ ) {
|
2023-03-11 01:40:17 +01:00
|
|
|
var _p = drag_points[i];
|
2023-06-13 14:42:06 +02:00
|
|
|
nx = _x + _p[_ANCHOR.x] * _s;
|
|
|
|
ny = _y + _p[_ANCHOR.y] * _s;
|
2023-03-11 01:40:17 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(i) draw_line(ox, oy, nx, ny);
|
2023-03-11 01:40:17 +01:00
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
}
|
|
|
|
|
2023-03-13 10:45:56 +01:00
|
|
|
if(point_distance(drag_point_mx, drag_point_my, pxx, pxy) > 4 / _s) {
|
2023-03-11 01:40:17 +01:00
|
|
|
array_push(drag_points, [ pxx, pxy ]);
|
|
|
|
|
|
|
|
drag_point_mx = pxx;
|
|
|
|
drag_point_my = pxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mouse_release(mb_left)) {
|
|
|
|
var amo = array_length(drag_points);
|
|
|
|
var _p = 0;
|
|
|
|
var points = [];
|
|
|
|
var thres = tool_pathDrawer.attribute.thres;
|
|
|
|
var replace = tool_pathDrawer.attribute.create;
|
|
|
|
var asize = ds_list_size(inputs) - input_fix_len;
|
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ ) {
|
|
|
|
var pT = drag_points[i];
|
|
|
|
|
|
|
|
if(i == 0 || i == amo - 1) {
|
|
|
|
array_push(points, i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var maxT = 0;
|
|
|
|
var pF = drag_points[_p];
|
|
|
|
|
|
|
|
for( var j = _p; j < i; j++ ) {
|
|
|
|
var pP = drag_points[j];
|
|
|
|
|
|
|
|
maxT = max(maxT, distance_to_line(pP[0], pP[1], pF[0], pF[1], pT[0], pT[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(maxT >= thres) {
|
|
|
|
array_push(points, i);
|
|
|
|
_p = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var amo = array_length(points);
|
|
|
|
if(!replace) amo = min(amo, asize);
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
var anc = [];
|
|
|
|
|
|
|
|
for( i = 0; i < amo; i++ ) {
|
2023-03-13 10:45:56 +01:00
|
|
|
var ind = replace? i : clamp(i / amo * array_length(points), 0, array_length(points) - 1);
|
|
|
|
var _ind = points[ind];
|
2023-03-11 01:40:17 +01:00
|
|
|
var _p = drag_points[_ind];
|
|
|
|
var dxx = 0;
|
|
|
|
var dxy = 0;
|
|
|
|
var dyx = 0;
|
|
|
|
var dyy = 0;
|
|
|
|
|
|
|
|
if(i > 0 && i < amo - 1) {
|
|
|
|
var _p0 = drag_points[points[i - 1]];
|
|
|
|
var _p1 = drag_points[points[i + 1]];
|
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
var d0 = point_direction(_p0[_ANCHOR.x], _p0[_ANCHOR.y], _p[_ANCHOR.x], _p[_ANCHOR.y]);
|
|
|
|
var d1 = point_direction( _p[_ANCHOR.x], _p[_ANCHOR.y], _p1[_ANCHOR.x], _p1[_ANCHOR.y]);
|
2023-03-11 01:40:17 +01:00
|
|
|
|
|
|
|
var dd = d0 + angle_difference(d1, d0) / 2;
|
2023-06-13 14:42:06 +02:00
|
|
|
var ds0 = point_distance(_p0[_ANCHOR.x], _p0[_ANCHOR.y], _p[_ANCHOR.x], _p[_ANCHOR.y]);
|
|
|
|
var ds1 = point_distance( _p[_ANCHOR.x], _p[_ANCHOR.y], _p1[_ANCHOR.x], _p1[_ANCHOR.y]);
|
2023-03-11 01:40:17 +01:00
|
|
|
|
|
|
|
dxx = lengthdir_x(ds0 / 3, dd + 180);
|
|
|
|
dxy = lengthdir_y(ds0 / 3, dd + 180);
|
|
|
|
dyx = lengthdir_x(ds1 / 3, dd);
|
|
|
|
dyy = lengthdir_y(ds1 / 3, dd);
|
|
|
|
}
|
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
anc = [_p[_ANCHOR.x], _p[_ANCHOR.y], dxx, dxy, dyx, dyy];
|
2023-03-11 01:40:17 +01:00
|
|
|
if(input_fix_len + i >= ds_list_size(inputs))
|
2023-06-13 14:42:06 +02:00
|
|
|
createAnchor(_p[_ANCHOR.x], _p[_ANCHOR.y], dxx, dxy, dyx, dyy);
|
2023-03-11 01:40:17 +01:00
|
|
|
else
|
|
|
|
inputs[| input_fix_len + i].setValue(anc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!replace) {
|
2023-05-03 21:42:17 +02:00
|
|
|
for(; i < asize; i++ )
|
2023-03-11 01:40:17 +01:00
|
|
|
inputs[| input_fix_len + i].setValue(anc);
|
|
|
|
}
|
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
|
|
|
} else if(drag_type == 3) { #region draw rectangle
|
2022-12-12 09:08:03 +01:00
|
|
|
var minx = min((_mx - _x) / _s, (drag_point_mx - _x) / _s);
|
|
|
|
var maxx = max((_mx - _x) / _s, (drag_point_mx - _x) / _s);
|
|
|
|
var miny = min((_my - _y) / _s, (drag_point_my - _y) / _s);
|
|
|
|
var maxy = max((_my - _y) / _s, (drag_point_my - _y) / _s);
|
|
|
|
|
2022-12-19 13:35:30 +01:00
|
|
|
minx = value_snap(minx, _snx);
|
|
|
|
maxx = value_snap(maxx, _snx);
|
|
|
|
miny = value_snap(miny, _sny);
|
|
|
|
maxy = value_snap(maxy, _sny);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(key_mod_press(SHIFT)) {
|
2023-07-25 20:12:40 +02:00
|
|
|
var _n = max(maxx - minx, maxy - miny);
|
|
|
|
maxx = minx + _n;
|
|
|
|
maxy = miny + _n;
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
var a = [];
|
|
|
|
for( var i = 0; i < 4; i++ )
|
2023-01-25 06:49:00 +01:00
|
|
|
a[i] = inputs[| input_fix_len + i].getValue();
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
a[0][_ANCHOR.x] = minx;
|
|
|
|
a[0][_ANCHOR.y] = miny;
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
a[1][_ANCHOR.x] = maxx;
|
|
|
|
a[1][_ANCHOR.y] = miny;
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
a[2][_ANCHOR.x] = maxx;
|
|
|
|
a[2][_ANCHOR.y] = maxy;
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
a[3][_ANCHOR.x] = minx;
|
|
|
|
a[3][_ANCHOR.y] = maxy;
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
for( var i = 0; i < 4; i++ ) {
|
|
|
|
if(inputs[| input_fix_len + i].setValue(a[i]))
|
|
|
|
_edited = true;
|
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
|
|
|
} else if(drag_type == 4) { #region draw circle
|
2022-12-12 09:08:03 +01:00
|
|
|
var minx = min((_mx - _x) / _s, (drag_point_mx - _x) / _s);
|
|
|
|
var maxx = max((_mx - _x) / _s, (drag_point_mx - _x) / _s);
|
|
|
|
var miny = min((_my - _y) / _s, (drag_point_my - _y) / _s);
|
|
|
|
var maxy = max((_my - _y) / _s, (drag_point_my - _y) / _s);
|
|
|
|
|
2022-12-19 13:35:30 +01:00
|
|
|
minx = value_snap(minx, _snx);
|
|
|
|
maxx = value_snap(maxx, _snx);
|
|
|
|
miny = value_snap(miny, _sny);
|
|
|
|
maxy = value_snap(maxy, _sny);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(key_mod_press(SHIFT)) {
|
2023-07-25 20:12:40 +02:00
|
|
|
var _n = max(maxx - minx, maxy - miny);
|
|
|
|
maxx = minx + _n;
|
|
|
|
maxy = miny + _n;
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
var a = [];
|
|
|
|
for( var i = 0; i < 4; i++ )
|
2023-01-25 06:49:00 +01:00
|
|
|
a[i] = inputs[| input_fix_len + i].getValue();
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
a[0][_ANCHOR.x ] = (minx + maxx) / 2;
|
|
|
|
a[0][_ANCHOR.y ] = miny;
|
|
|
|
a[0][_ANCHOR.c1x] = -(maxx - minx) * 0.27614;
|
|
|
|
a[0][_ANCHOR.c1y] = 0;
|
|
|
|
a[0][_ANCHOR.c2x] = (maxx - minx) * 0.27614;
|
|
|
|
a[0][_ANCHOR.c2y] = 0;
|
|
|
|
|
|
|
|
a[1][_ANCHOR.x ] = maxx;
|
|
|
|
a[1][_ANCHOR.y ] = (miny + maxy) / 2;
|
|
|
|
a[1][_ANCHOR.c1x] = 0;
|
|
|
|
a[1][_ANCHOR.c1y] = -(maxy - miny) * 0.27614;
|
|
|
|
a[1][_ANCHOR.c2x] = 0;
|
|
|
|
a[1][_ANCHOR.c2y] = (maxy - miny) * 0.27614;
|
|
|
|
|
|
|
|
a[2][_ANCHOR.x ] = (minx + maxx) / 2;
|
|
|
|
a[2][_ANCHOR.y ] = maxy;
|
|
|
|
a[2][_ANCHOR.c1x] = (maxx - minx) * 0.27614;
|
|
|
|
a[2][_ANCHOR.c1y] = 0;
|
|
|
|
a[2][_ANCHOR.c2x] = -(maxx - minx) * 0.27614;
|
|
|
|
a[2][_ANCHOR.c2y] = 0;
|
|
|
|
|
|
|
|
a[3][_ANCHOR.x ] = minx;
|
|
|
|
a[3][_ANCHOR.y ] = (miny + maxy) / 2;
|
|
|
|
a[3][_ANCHOR.c1x] = 0;
|
|
|
|
a[3][_ANCHOR.c1y] = (maxy - miny) * 0.27614;
|
|
|
|
a[3][_ANCHOR.c2x] = 0;
|
|
|
|
a[3][_ANCHOR.c2y] = -(maxy - miny) * 0.27614;
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
for( var i = 0; i < 4; i++ ) {
|
|
|
|
if(inputs[| input_fix_len + i].setValue(a[i]))
|
|
|
|
_edited = true;
|
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
|
|
|
|
2023-05-05 08:58:56 +02:00
|
|
|
if(_edited) UNDO_HOLDING = true;
|
2023-05-03 21:42:17 +02:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
if(mouse_release(mb_left)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_point = -1;
|
2023-03-19 09:17:39 +01:00
|
|
|
UPDATE |= RENDER_TYPE.full;
|
2023-05-03 21:42:17 +02:00
|
|
|
UNDO_HOLDING = false;
|
2023-03-19 09:17:39 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
#region check line hover
|
2023-05-05 08:58:56 +02:00
|
|
|
var line_hover = -1;
|
|
|
|
var points = [];
|
|
|
|
var _a0, _a1;
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
var minx = 99999, miny = 99999;
|
|
|
|
var maxx = -99999, maxy = -99999;
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-05-05 08:58:56 +02:00
|
|
|
for(var i = loop? 0 : 1; i < ansize; i++) {
|
|
|
|
if(i) {
|
|
|
|
_a0 = inputs[| input_fix_len + i - 1].getValue();
|
|
|
|
_a1 = inputs[| input_fix_len + i].getValue();
|
|
|
|
} else {
|
|
|
|
_a0 = inputs[| input_fix_len + ansize - 1].getValue();
|
|
|
|
_a1 = inputs[| input_fix_len + 0].getValue();
|
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
|
2023-05-05 08:58:56 +02:00
|
|
|
var _ox = 0, _oy = 0, _nx = 0, _ny = 0, p = 0, pnt = [];
|
|
|
|
for(var j = 0; j < sample; j++) {
|
|
|
|
if(array_length(_a0) < 6) continue;
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
p = eval_bezier(j / (sample - 1), _a0[_ANCHOR.x], _a0[_ANCHOR.y],
|
|
|
|
_a1[_ANCHOR.x], _a1[_ANCHOR.y],
|
|
|
|
_a0[_ANCHOR.x] + _a0[_ANCHOR.c2x], _a0[_ANCHOR.y] + _a0[_ANCHOR.c2y],
|
|
|
|
_a1[_ANCHOR.x] + _a1[_ANCHOR.c1x], _a1[_ANCHOR.y] + _a1[_ANCHOR.c1y]);
|
2023-05-05 08:58:56 +02:00
|
|
|
_nx = _x + p[0] * _s;
|
|
|
|
_ny = _y + p[1] * _s;
|
2023-06-13 14:42:06 +02:00
|
|
|
|
2023-05-05 08:58:56 +02:00
|
|
|
minx = min(minx, _nx); miny = min(miny, _ny);
|
|
|
|
maxx = max(maxx, _nx); maxy = max(maxy, _ny);
|
2023-06-13 14:42:06 +02:00
|
|
|
|
2023-05-05 08:58:56 +02:00
|
|
|
array_push(pnt, [ _nx, _ny ]);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-05-05 08:58:56 +02:00
|
|
|
if(j && (key_mod_press(CTRL) || isUsingTool(1)) && distance_to_line(_mx, _my, _ox, _oy, _nx, _ny) < 4)
|
|
|
|
line_hover = i;
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2023-05-05 08:58:56 +02:00
|
|
|
_ox = _nx;
|
|
|
|
_oy = _ny;
|
|
|
|
}
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-05-05 08:58:56 +02:00
|
|
|
array_push(points, pnt);
|
|
|
|
}
|
|
|
|
#endregion
|
2023-06-13 14:42:06 +02:00
|
|
|
#region draw path
|
|
|
|
draw_set_color(isUsingTool(0)? c_white : COLORS._main_accent);
|
|
|
|
var ind = 0;
|
|
|
|
for(var i = loop? 0 : 1; i < ansize; i++) {
|
|
|
|
for(var j = 0; j < sample; j++) {
|
|
|
|
_nx = points[ind][j][_ANCHOR.x];
|
|
|
|
_ny = points[ind][j][_ANCHOR.y];
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(j) draw_line_width(_ox, _oy, _nx, _ny, 1 + 2 * (line_hover == i));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
_ox = _nx;
|
|
|
|
_oy = _ny;
|
|
|
|
}
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
ind++;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-07-31 20:06:44 +02:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
var anchor_hover = -1;
|
|
|
|
var hover_type = 0;
|
|
|
|
|
|
|
|
if(!isUsingTool(0))
|
|
|
|
for(var i = 0; i < ansize; i++) {
|
|
|
|
var _a = inputs[| input_fix_len + i].getValue();
|
|
|
|
var xx = _x + _a[0] * _s;
|
|
|
|
var yy = _y + _a[1] * _s;
|
|
|
|
var cont = false;
|
|
|
|
var _ax0 = 0, _ay0 = 0;
|
|
|
|
var _ax1 = 0, _ay1 = 0;
|
|
|
|
|
|
|
|
if(array_length(_a) < 6) continue;
|
|
|
|
|
|
|
|
if(_a[2] != 0 || _a[3] != 0 || _a[4] != 0 || _a[5] != 0) {
|
|
|
|
_ax0 = _x + (_a[0] + _a[2]) * _s;
|
|
|
|
_ay0 = _y + (_a[1] + _a[3]) * _s;
|
|
|
|
_ax1 = _x + (_a[0] + _a[4]) * _s;
|
|
|
|
_ay1 = _y + (_a[1] + _a[5]) * _s;
|
|
|
|
cont = true;
|
|
|
|
|
|
|
|
draw_set_color(COLORS.node_path_overlay_control_line);
|
|
|
|
draw_line(_ax0, _ay0, xx, yy);
|
|
|
|
draw_line(_ax1, _ay1, xx, yy);
|
|
|
|
|
|
|
|
draw_sprite_colored(THEME.anchor_selector, 2, _ax0, _ay0);
|
|
|
|
draw_sprite_colored(THEME.anchor_selector, 2, _ax1, _ay1);
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
draw_sprite_colored(THEME.anchor_selector, 0, xx, yy);
|
|
|
|
|
|
|
|
if(drag_point == i) {
|
|
|
|
draw_sprite_colored(THEME.anchor_selector, 1, xx, yy);
|
|
|
|
} else if(point_in_circle(_mx, _my, xx, yy, 8)) {
|
|
|
|
draw_sprite_colored(THEME.anchor_selector, 1, xx, yy);
|
|
|
|
anchor_hover = i;
|
|
|
|
hover_type = 0;
|
|
|
|
} else if(cont && point_in_circle(_mx, _my, _ax0, _ay0, 8)) {
|
|
|
|
draw_sprite_colored(THEME.anchor_selector, 0, _ax0, _ay0);
|
|
|
|
anchor_hover = i;
|
|
|
|
hover_type = 1;
|
|
|
|
} else if(cont && point_in_circle(_mx, _my, _ax1, _ay1, 8)) {
|
|
|
|
draw_sprite_colored(THEME.anchor_selector, 0, _ax1, _ay1);
|
|
|
|
anchor_hover = i;
|
|
|
|
hover_type = -1;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
2023-03-11 01:40:17 +01:00
|
|
|
|
2023-06-13 14:42:06 +02:00
|
|
|
if(isUsingTool(0)) { #region transform tools
|
2023-03-19 09:17:39 +01:00
|
|
|
var hov = 0;
|
|
|
|
if(point_in_circle(_mx, _my, minx, miny, 8)) hov = 1;
|
|
|
|
else if(point_in_circle(_mx, _my, maxx, miny, 8)) hov = 2;
|
|
|
|
else if(point_in_circle(_mx, _my, minx, maxy, 8)) hov = 3;
|
|
|
|
else if(point_in_circle(_mx, _my, maxx, maxy, 8)) hov = 4;
|
|
|
|
else if(point_in_rectangle(_mx, _my, minx, miny, maxx, maxy)) hov = 5;
|
|
|
|
|
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
draw_rectangle_border(minx, miny, maxx, maxy, 1 + (hov == 5));
|
|
|
|
|
2023-04-08 20:06:27 +02:00
|
|
|
draw_sprite_colored(THEME.anchor_selector, hov == 1, minx, miny);
|
|
|
|
draw_sprite_colored(THEME.anchor_selector, hov == 2, maxx, miny);
|
|
|
|
draw_sprite_colored(THEME.anchor_selector, hov == 3, minx, maxy);
|
|
|
|
draw_sprite_colored(THEME.anchor_selector, hov == 4, maxx, maxy);
|
2023-03-19 09:17:39 +01:00
|
|
|
|
|
|
|
if(hov && mouse_press(mb_left, active)) {
|
|
|
|
transform_type = hov;
|
2023-06-13 14:42:06 +02:00
|
|
|
transform_minx = (minx - _x) / _s; transform_maxx = (maxx - _x) / _s;
|
|
|
|
transform_miny = (miny - _y) / _s; transform_maxy = (maxy - _y) / _s;
|
|
|
|
transform_mx = _mx; transform_my = _my;
|
|
|
|
transform_sx = _mx; transform_sy = _my;
|
|
|
|
|
|
|
|
transform_cx = (transform_minx + transform_maxx) / 2;
|
|
|
|
transform_cy = (transform_miny + transform_maxy) / 2;
|
2023-03-19 09:17:39 +01:00
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
|
|
|
} else if(isUsingTool(3)) { #region pen tools
|
2023-03-11 01:40:17 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.path_tools_draw, 0, _mx + 16, _my + 16);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-11 01:40:17 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
|
|
|
var replace = tool_pathDrawer.attribute.create;
|
|
|
|
if(replace) {
|
|
|
|
while(ds_list_size(inputs) > input_fix_len)
|
|
|
|
ds_list_delete(inputs, input_fix_len);
|
2023-08-05 14:00:33 +02:00
|
|
|
array_resize(input_display_list, input_display_len);
|
2023-03-11 01:40:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
drag_point = 0;
|
|
|
|
drag_type = 2;
|
|
|
|
drag_points = [ [ (_mx - _x) / _s, (_my - _y) / _s ] ];
|
|
|
|
drag_point_mx = (_mx - _x) / _s;
|
|
|
|
drag_point_my = (_my - _y) / _s;
|
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
|
|
|
} else if(isUsingTool(4) || isUsingTool(5)) { #region shape tools
|
2023-03-11 01:40:17 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.cursor_path_add, 0, _mx + 16, _my + 16);
|
|
|
|
|
|
|
|
if(mouse_press(mb_left, active)) {
|
|
|
|
while(ds_list_size(inputs) > input_fix_len)
|
|
|
|
ds_list_delete(inputs, input_fix_len);
|
2023-08-05 14:00:33 +02:00
|
|
|
array_resize(input_display_list, input_display_len);
|
2023-03-11 01:40:17 +01:00
|
|
|
|
|
|
|
drag_point = 0;
|
2023-03-19 09:17:39 +01:00
|
|
|
drag_type = isUsingTool(4)? 3 : 4;
|
2023-03-11 01:40:17 +01:00
|
|
|
drag_point_mx = _mx;
|
|
|
|
drag_point_my = _my;
|
|
|
|
inputs[| 1].setValue(true);
|
|
|
|
|
|
|
|
repeat(4)
|
|
|
|
createAnchor(value_snap((_mx - _x) / _s, _snx), value_snap((_my - _y) / _s, _sny));
|
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
|
|
|
} else if(anchor_hover != -1) { #region no tool, dragging existing point
|
2023-01-25 06:49:00 +01:00
|
|
|
var _a = inputs[| input_fix_len + anchor_hover].getValue();
|
2023-06-13 14:42:06 +02:00
|
|
|
if(isUsingTool(2) && hover_type == 0) {
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.cursor_path_anchor, 0, _mx + 16, _my + 16);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
if(_a[2] != 0 || _a[3] != 0 || _a[4] != 0 || _a[5] != 0) {
|
|
|
|
_a[2] = 0;
|
|
|
|
_a[3] = 0;
|
|
|
|
_a[4] = 0;
|
|
|
|
_a[5] = 0;
|
2023-06-13 14:42:06 +02:00
|
|
|
_a[6] = false;
|
2023-01-25 06:49:00 +01:00
|
|
|
inputs[| input_fix_len + anchor_hover].setValue(_a);
|
2022-01-13 05:24:03 +01:00
|
|
|
} else {
|
|
|
|
_a[2] = -8;
|
|
|
|
_a[3] = 0;
|
|
|
|
_a[4] = 8;
|
|
|
|
_a[5] = 0;
|
2023-06-13 14:42:06 +02:00
|
|
|
_a[6] = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
drag_point = anchor_hover;
|
|
|
|
drag_type = 1;
|
|
|
|
drag_point_mx = _mx;
|
|
|
|
drag_point_my = _my;
|
|
|
|
drag_point_sx = _a[0];
|
|
|
|
drag_point_sy = _a[1];
|
|
|
|
}
|
|
|
|
}
|
2023-05-07 20:55:13 +02:00
|
|
|
} else if(hover_type == 0 && key_mod_press(SHIFT)) { //remove
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.cursor_path_remove, 0, _mx + 16, _my + 16);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2023-05-07 20:55:13 +02:00
|
|
|
recordAction(ACTION_TYPE.var_modify, self, [ array_clone(input_display_list), "input_display_list" ]);
|
|
|
|
recordAction(ACTION_TYPE.list_delete, inputs, [ inputs[| input_fix_len + anchor_hover], input_fix_len + anchor_hover, "remove path anchor point" ]);
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
ds_list_delete(inputs, input_fix_len + anchor_hover);
|
|
|
|
array_remove(input_display_list, input_fix_len + anchor_hover);
|
2022-01-16 14:28:57 +01:00
|
|
|
doUpdate();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.cursor_path_move, 0, _mx + 16, _my + 16);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2023-06-13 14:42:06 +02:00
|
|
|
if(isUsingTool(2)) {
|
|
|
|
_a[_ANCHOR.ind] = true;
|
|
|
|
inputs[| input_fix_len + anchor_hover].setValue(_a);
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_point = anchor_hover;
|
|
|
|
drag_type = hover_type;
|
|
|
|
drag_point_mx = _mx;
|
|
|
|
drag_point_my = _my;
|
|
|
|
drag_point_sx = _a[0];
|
|
|
|
drag_point_sy = _a[1];
|
|
|
|
|
|
|
|
if(hover_type == 1) {
|
|
|
|
drag_point_sx = _a[0] + _a[2];
|
|
|
|
drag_point_sy = _a[1] + _a[3];
|
|
|
|
} else if(hover_type == -1) {
|
|
|
|
drag_point_sx = _a[0] + _a[4];
|
|
|
|
drag_point_sy = _a[1] + _a[5];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
|
|
|
} else if(key_mod_press(CTRL) || isUsingTool(1)) { #region anchor edit
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.cursor_path_add, 0, _mx + 16, _my + 16);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var anc = createAnchor(value_snap((_mx - _x) / _s, _snx), value_snap((_my - _y) / _s, _sny));
|
2023-05-05 08:58:56 +02:00
|
|
|
UNDO_HOLDING = true;
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
if(line_hover == -1) {
|
|
|
|
drag_point = ds_list_size(inputs) - input_fix_len - 1;
|
|
|
|
} else {
|
|
|
|
ds_list_remove(inputs, anc);
|
|
|
|
ds_list_insert(inputs, input_fix_len + line_hover, anc);
|
|
|
|
drag_point = line_hover;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-21 06:38:44 +01:00
|
|
|
drag_type = -1;
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_point_mx = _mx;
|
|
|
|
drag_point_my = _my;
|
|
|
|
drag_point_sx = (_mx - _x) / _s;
|
|
|
|
drag_point_sy = (_my - _y) / _s;
|
2023-03-19 09:17:39 +01:00
|
|
|
|
|
|
|
UPDATE |= RENDER_TYPE.full;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-06-13 14:42:06 +02:00
|
|
|
#endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static updateLength = function() {
|
2023-03-19 09:17:39 +01:00
|
|
|
boundary = new BoundingBox();
|
|
|
|
lengthTotal = 0;
|
|
|
|
var loop = inputs[| 1].getValue();
|
|
|
|
var rond = inputs[| 3].getValue();
|
2023-06-17 18:59:20 +02:00
|
|
|
if(!is_real(rond)) rond = false;
|
2023-03-19 09:17:39 +01:00
|
|
|
var ansize = ds_list_size(inputs) - input_fix_len;
|
2022-01-13 05:24:03 +01:00
|
|
|
if(ansize < 2) {
|
|
|
|
lengths = [];
|
2023-02-19 13:49:20 +01:00
|
|
|
anchors = [];
|
2022-01-13 05:24:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var sample = PREF_MAP[? "path_resolution"];
|
|
|
|
|
2023-04-09 21:24:16 +02:00
|
|
|
var con = loop? ansize : ansize - 1;
|
2023-03-19 09:17:39 +01:00
|
|
|
lengths = [];
|
|
|
|
lengthAccs = [];
|
2023-02-19 13:49:20 +01:00
|
|
|
array_resize(anchors, ansize);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
for(var i = 0; i < con; i++) {
|
2023-01-25 06:49:00 +01:00
|
|
|
var index_0 = input_fix_len + i;
|
|
|
|
var index_1 = input_fix_len + i + 1;
|
|
|
|
if(index_1 >= ds_list_size(inputs)) index_1 = input_fix_len;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var _a0 = inputs[| index_0].getValue();
|
|
|
|
var _a1 = inputs[| index_1].getValue();
|
2023-03-19 09:17:39 +01:00
|
|
|
anchors[i + 0] = _a0;
|
2023-02-19 13:49:20 +01:00
|
|
|
anchors[i + 1] = _a1;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-11 01:40:17 +01:00
|
|
|
if(rond) {
|
|
|
|
_a0[0] = round(_a0[0]); _a0[1] = round(_a0[1]);
|
|
|
|
_a1[0] = round(_a1[0]); _a1[1] = round(_a1[1]);
|
|
|
|
}
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
var l = 0, _ox = 0, _oy = 0, _nx = 0, _ny = 0, p = 0;
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var j = 0; j < sample; j++) {
|
|
|
|
p = eval_bezier(j / sample, _a0[0], _a0[1], _a1[0], _a1[1], _a0[0] + _a0[4], _a0[1] + _a0[5], _a1[0] + _a1[2], _a1[1] + _a1[3]);
|
|
|
|
_nx = p[0];
|
|
|
|
_ny = p[1];
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
boundary.addPoint(_nx, _ny);
|
2022-01-13 05:24:03 +01:00
|
|
|
if(j) l += point_distance(_nx, _ny, _ox, _oy);
|
|
|
|
|
|
|
|
_ox = _nx;
|
|
|
|
_oy = _ny;
|
|
|
|
}
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
lengths[i] = l;
|
|
|
|
lengthTotal += l;
|
|
|
|
lengthAccs[i] = lengthTotal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static getLineCount = function() { return 1; }
|
|
|
|
static getSegmentCount = function() { return array_length(lengths); }
|
|
|
|
static getBoundary = function() { return boundary; }
|
|
|
|
|
|
|
|
static getLength = function() { return lengthTotal; }
|
|
|
|
static getAccuLength = function() { return lengthAccs; }
|
|
|
|
|
|
|
|
static getPointDistance = function(_dist) {
|
2023-07-18 17:51:40 +02:00
|
|
|
if(ds_map_exists(cached_pos, _dist))
|
|
|
|
return cached_pos[? _dist];
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
var loop = inputs[| 1].getValue();
|
|
|
|
var rond = inputs[| 3].getValue();
|
2023-06-17 18:59:20 +02:00
|
|
|
if(!is_real(rond)) rond = false;
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
var ansize = array_length(lengths);
|
|
|
|
var amo = ds_list_size(inputs) - input_fix_len;
|
|
|
|
|
|
|
|
if(ansize == 0) return new Point();
|
|
|
|
|
|
|
|
var _a0, _a1;
|
|
|
|
|
|
|
|
for(var i = 0; i < ansize; i++) {
|
|
|
|
_a0 = anchors[safe_mod(i + 0, amo)];
|
|
|
|
_a1 = anchors[safe_mod(i + 1, amo)];
|
|
|
|
|
|
|
|
if(rond) {
|
|
|
|
_a0[0] = round(_a0[0]); _a0[1] = round(_a0[1]);
|
|
|
|
_a1[0] = round(_a1[0]); _a1[1] = round(_a1[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_dist > lengths[i]) {
|
|
|
|
_dist -= lengths[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var _t = _dist / lengths[i];
|
|
|
|
|
|
|
|
if(!is_array(_a0) || !is_array(_a1))
|
|
|
|
return new Point();
|
|
|
|
|
|
|
|
var _p = eval_bezier(_t, _a0[0], _a0[1], _a1[0], _a1[1], _a0[0] + _a0[4], _a0[1] + _a0[5], _a1[0] + _a1[2], _a1[1] + _a1[3]);
|
2023-07-18 17:51:40 +02:00
|
|
|
var _point = new Point(_p);
|
|
|
|
cached_pos[? _dist] = _point;
|
|
|
|
return _point;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-03-19 09:17:39 +01:00
|
|
|
|
|
|
|
return new Point();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
static getPointRatio = function(_rat) {
|
|
|
|
var pix = frac(_rat) * lengthTotal;
|
|
|
|
return getPointDistance(pix);
|
|
|
|
}
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
static getPointSegment = function(_rat) {
|
2023-01-09 03:14:20 +01:00
|
|
|
var loop = inputs[| 1].getValue();
|
2023-03-11 01:40:17 +01:00
|
|
|
var rond = inputs[| 3].getValue();
|
2023-06-17 18:59:20 +02:00
|
|
|
if(!is_real(rond)) rond = false;
|
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
var ansize = array_length(lengths);
|
2023-01-25 06:49:00 +01:00
|
|
|
var amo = ds_list_size(inputs) - input_fix_len;
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
if(amo < 1) return new Point(0, 0);
|
2023-01-09 03:14:20 +01:00
|
|
|
if(_rat < 0) {
|
2023-01-25 06:49:00 +01:00
|
|
|
var _p0 = inputs[| input_fix_len].getValue();
|
2023-03-11 01:40:17 +01:00
|
|
|
if(rond)
|
2023-03-19 09:17:39 +01:00
|
|
|
return new Point(round(_p0[0]), round(_p0[1]));
|
|
|
|
return new Point(_p0[0], _p0[1]);
|
2023-01-09 03:14:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_rat = safe_mod(_rat, ansize);
|
|
|
|
var _i0 = clamp(floor(_rat), 0, amo - 1);
|
|
|
|
var _t = frac(_rat);
|
|
|
|
var _i1 = _i0 + 1;
|
|
|
|
|
|
|
|
if(_i1 >= amo) {
|
|
|
|
if(!loop) {
|
|
|
|
var _p1 = inputs[| ds_list_size(inputs) - 1].getValue()
|
2023-03-11 01:40:17 +01:00
|
|
|
if(rond)
|
2023-03-19 09:17:39 +01:00
|
|
|
return new Point(round(_p1[0]), round(_p1[1]));
|
|
|
|
return new Point(_p1[0], _p1[1]);
|
2023-01-09 03:14:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_i1 = 0;
|
|
|
|
}
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
var _a0 = inputs[| input_fix_len + _i0].getValue();
|
|
|
|
var _a1 = inputs[| input_fix_len + _i1].getValue();
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-03-11 01:40:17 +01:00
|
|
|
if(rond) {
|
|
|
|
_a0[0] = round(_a0[0]); _a0[1] = round(_a0[1]);
|
|
|
|
_a1[0] = round(_a1[0]); _a1[1] = round(_a1[1]);
|
|
|
|
}
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
var p = eval_bezier(_t, _a0[0], _a0[1], _a1[0], _a1[1], _a0[0] + _a0[4], _a0[1] + _a0[5], _a1[0] + _a1[2], _a1[1] + _a1[3]);
|
|
|
|
return new Point(p[0], p[1]);
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
|
|
|
|
2023-07-06 19:49:16 +02:00
|
|
|
static update = function(frame = PROJECT.animator.current_frame) {
|
2023-07-18 17:51:40 +02:00
|
|
|
ds_map_clear(cached_pos);
|
2022-01-13 05:24:03 +01:00
|
|
|
updateLength();
|
2023-03-19 09:17:39 +01:00
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
var _rat = inputs[| 0].getValue();
|
|
|
|
var _typ = inputs[| 2].getValue();
|
2023-07-31 20:06:44 +02:00
|
|
|
var _rnd = inputs[| 3].getValue();
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
var anchors = [];
|
2023-07-31 20:06:44 +02:00
|
|
|
for(var i = input_fix_len; i < ds_list_size(inputs); i++) {
|
|
|
|
var _anc = inputs[| i].getValue();
|
|
|
|
if(_rnd) {
|
|
|
|
_anc[0] = round(_anc[0]);
|
|
|
|
_anc[1] = round(_anc[2]);
|
|
|
|
}
|
|
|
|
array_push(anchors, _anc);
|
|
|
|
}
|
2023-03-19 09:17:39 +01:00
|
|
|
outputs[| 2].setValue(anchors);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(is_array(_rat)) {
|
|
|
|
var _out = array_create(array_length(_rat));
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(_rat); i < n; i++ ) {
|
2023-02-14 05:32:32 +01:00
|
|
|
if(_typ == 0) _out[i] = getPointRatio(_rat[i]);
|
2023-03-19 09:17:39 +01:00
|
|
|
else if(_typ == 1) _out[i] = getPointSegment(_rat[i]);
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
outputs[| 0].setValue(_out);
|
|
|
|
} else {
|
|
|
|
var _out = [0, 0];
|
|
|
|
|
|
|
|
if(_typ == 0) _out = getPointRatio(_rat);
|
2023-03-19 09:17:39 +01:00
|
|
|
else if(_typ == 1) _out = getPointSegment(_rat);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
outputs[| 0].setValue(_out.toArray());
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
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);
|
|
|
|
draw_sprite_fit(THEME.node_draw_path, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|