2023-05-08 10:50:42 +02:00
|
|
|
function node_halign(nodeList, alignment = fa_center) {
|
2023-11-03 03:22:02 +01:00
|
|
|
var amo = array_length(nodeList);
|
2023-05-08 10:50:42 +02:00
|
|
|
|
|
|
|
switch(alignment) {
|
|
|
|
case fa_left:
|
|
|
|
var x0 = 999999;
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
x0 = min(x0, nodeList[i].x);
|
2023-05-08 10:50:42 +02:00
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
nodeList[i].x = x0;
|
2023-05-08 10:50:42 +02:00
|
|
|
break;
|
|
|
|
case fa_center:
|
|
|
|
var xc = 0;
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
xc += nodeList[i].x + nodeList[i].w / 2;
|
2023-05-08 10:50:42 +02:00
|
|
|
xc /= amo;
|
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
nodeList[i].x = xc - nodeList[i].w / 2;
|
2023-05-08 10:50:42 +02:00
|
|
|
break;
|
|
|
|
case fa_right:
|
|
|
|
var x0 = -999999;
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
x0 = max(x0, nodeList[i].x + nodeList[i].w);
|
2023-05-08 10:50:42 +02:00
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
nodeList[i].x = x0 - nodeList[i].w;
|
2023-05-08 10:50:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function node_valign(nodeList, alignment = fa_middle) {
|
2023-11-03 03:22:02 +01:00
|
|
|
var amo = array_length(nodeList);
|
2023-05-08 10:50:42 +02:00
|
|
|
|
|
|
|
switch(alignment) {
|
|
|
|
case fa_top:
|
|
|
|
var y0 = 999999;
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
y0 = min(y0, nodeList[i].y);
|
2023-05-08 10:50:42 +02:00
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
nodeList[i].y = y0;
|
2023-05-08 10:50:42 +02:00
|
|
|
break;
|
|
|
|
case fa_middle:
|
|
|
|
var yc = 0;
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
yc += nodeList[i].y + nodeList[i].h / 2;
|
2023-05-08 10:50:42 +02:00
|
|
|
yc /= amo;
|
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
nodeList[i].y = yc - nodeList[i].h / 2;
|
2023-05-08 10:50:42 +02:00
|
|
|
break;
|
|
|
|
case fa_bottom:
|
|
|
|
var y0 = -999999;
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
y0 = max(y0, nodeList[i].y + nodeList[i].h);
|
2023-05-08 10:50:42 +02:00
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ )
|
2023-11-03 03:22:02 +01:00
|
|
|
nodeList[i].y = y0 - nodeList[i].h;
|
2023-05-08 10:50:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function node_hdistribute(nodeList) {
|
2024-05-23 02:17:13 +02:00
|
|
|
var amo = array_length(nodeList);
|
2023-05-08 10:50:42 +02:00
|
|
|
var nodes = ds_priority_create();
|
|
|
|
|
|
|
|
var x0 = 999999;
|
|
|
|
var x1 = -999999;
|
|
|
|
for( var i = 0; i < amo; i++ ) {
|
2023-11-03 03:22:02 +01:00
|
|
|
var _x = nodeList[i].x + nodeList[i].w / 2;
|
2023-05-08 10:50:42 +02:00
|
|
|
x0 = min(x0, _x);
|
|
|
|
x1 = max(x1, _x);
|
|
|
|
|
2023-11-03 03:22:02 +01:00
|
|
|
ds_priority_add(nodes, nodeList[i], _x);
|
2023-05-08 10:50:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var sp = (x1 - x0) / (amo - 1);
|
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ ) {
|
2023-07-25 20:12:40 +02:00
|
|
|
var _node = ds_priority_delete_min(nodes);
|
|
|
|
_node.x = x0 + sp * i - _node.w / 2;
|
2023-05-08 10:50:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ds_priority_destroy(nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
function node_vdistribute(nodeList) {
|
2024-05-23 02:17:13 +02:00
|
|
|
var amo = array_length(nodeList);
|
2023-05-08 10:50:42 +02:00
|
|
|
var nodes = ds_priority_create();
|
|
|
|
|
|
|
|
var y0 = 999999;
|
|
|
|
var y1 = -999999;
|
|
|
|
for( var i = 0; i < amo; i++ ) {
|
2023-11-03 03:22:02 +01:00
|
|
|
var _y = nodeList[i].y + nodeList[i].h / 2;
|
2023-05-08 10:50:42 +02:00
|
|
|
y0 = min(y0, _y);
|
|
|
|
y1 = max(y1, _y);
|
|
|
|
|
2023-11-03 03:22:02 +01:00
|
|
|
ds_priority_add(nodes, nodeList[i], _y);
|
2023-05-08 10:50:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var sp = (y1 - y0) / (amo - 1);
|
|
|
|
|
|
|
|
for( var i = 0; i < amo; i++ ) {
|
2023-07-25 20:12:40 +02:00
|
|
|
var _node = ds_priority_delete_min(nodes);
|
|
|
|
_node.y = y0 + sp * i - _node.h / 2;
|
2023-05-08 10:50:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ds_priority_destroy(nodes);
|
|
|
|
}
|