Pixel-Composer/scripts/node_transform/node_transform.gml

626 lines
18 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
enum OUTPUT_SCALING {
same_as_input,
constant,
2023-04-16 11:53:46 +02:00
relative,
scale
2022-01-13 05:24:03 +01:00
}
2023-02-28 09:43:01 +01:00
function Node_Transform(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Transform";
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Surface("Surface in", self));
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(1, nodeValue_Vec2("Output dimension", self, [ 1, 1 ]))
2022-01-19 03:05:13 +01:00
.setVisible(false);
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Vec2("Position", self, [ 0.5, 0.5 ]))
2022-12-27 13:30:02 +01:00
.setUnitRef(function(index) { return getDimension(index); }, VALUE_UNIT.reference);
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Vec2("Anchor", self, [ 0.5, 0.5 ]))
2024-08-07 11:48:39 +02:00
.setDisplay(VALUE_DISPLAY.vector, {
2023-11-07 06:01:38 +01:00
side_button : new buttonAnchor(function(ind) {
switch(ind) {
2024-08-08 06:57:51 +02:00
case 0 : inputs[3].setValue([ 0.0, 0.0 ]); break;
case 1 : inputs[3].setValue([ 0.5, 0.0 ]); break;
case 2 : inputs[3].setValue([ 1.0, 0.0 ]); break;
2023-11-07 06:01:38 +01:00
2024-08-08 06:57:51 +02:00
case 3 : inputs[3].setValue([ 0.0, 0.5 ]); break;
case 4 : inputs[3].setValue([ 0.5, 0.5 ]); break;
case 5 : inputs[3].setValue([ 1.0, 0.5 ]); break;
2023-11-07 06:01:38 +01:00
2024-08-08 06:57:51 +02:00
case 6 : inputs[3].setValue([ 0.0, 1.0 ]); break;
case 7 : inputs[3].setValue([ 0.5, 1.0 ]); break;
case 8 : inputs[3].setValue([ 1.0, 1.0 ]); break;
2023-11-07 06:01:38 +01:00
}
})
2024-08-07 11:48:39 +02:00
});
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(4, nodeValue_Bool("Relative anchor", self, true));
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(5, nodeValue_Rotation("Rotation", self, 0));
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(6, nodeValue_Vec2("Scale", self, [ 1, 1 ]));
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(7, nodeValue_Enum_Button("Render Mode", self, 0, [ "Normal", "Tile", "Wrap" ]));
2022-01-13 05:24:03 +01:00
2024-08-18 09:13:41 +02:00
newInput(8, nodeValue_Float("Rotate by velocity", self, 0, "Make the surface rotates to follow its movement."))
.setDisplay(VALUE_DISPLAY.slider);
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(9, nodeValue_Enum_Scroll("Output dimension type", self, OUTPUT_SCALING.same_as_input, [ "Same as input", "Constant", "Relative to input", "Transformed" ]));
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(10, nodeValue_Bool("Round position", self, false, "Round position to the nearest integer value to avoid jittering."));
2022-01-13 05:24:03 +01:00
2024-08-18 06:16:20 +02:00
newInput(11, nodeValue_Bool("Active", self, true));
2023-02-14 05:32:32 +01:00
active_index = 11;
2023-06-13 14:42:06 +02:00
2024-08-18 06:16:20 +02:00
newInput(12, nodeValue_Bool("Echo", self, false));
2024-01-12 05:03:35 +01:00
2024-08-18 06:16:20 +02:00
newInput(13, nodeValue_Int("Echo amount", self, 8));
2024-01-12 05:03:35 +01:00
2024-08-18 09:13:41 +02:00
newInput(14, nodeValue_Float("Alpha", self, 1))
2024-02-01 05:26:02 +01:00
.setDisplay(VALUE_DISPLAY.slider);
2024-06-06 09:54:13 +02:00
input_display_list = [ 11, 0,
2024-01-12 05:03:35 +01:00
["Output", true], 9, 1, 7,
2022-12-27 04:00:50 +01:00
["Position", false], 2, 10,
["Rotation", false], 3, 5, 8,
2024-01-12 05:03:35 +01:00
["Scale", false], 6,
2024-02-01 05:26:02 +01:00
["Render", false], 14,
2024-01-12 05:03:35 +01:00
["Echo", true, 12], 13,
2022-01-13 05:24:03 +01:00
];
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
2022-01-13 05:24:03 +01:00
2024-08-08 06:57:51 +02:00
outputs[1] = nodeValue_Output("Dimension", self, VALUE_TYPE.integer, [ 1, 1 ])
2024-06-06 09:54:13 +02:00
.setDisplay(VALUE_DISPLAY.vector)
.setVisible(false);
2023-03-19 09:17:39 +01:00
attribute_surface_depth();
2023-03-21 03:01:53 +01:00
attribute_interpolation();
2024-02-01 05:26:02 +01:00
vel = 0;
prev_pos = [ 0, 0 ];
2024-01-12 05:03:35 +01:00
prev_data = noone;
2022-01-13 05:24:03 +01:00
2024-08-07 11:48:39 +02:00
static getDimension = function(arr = 0) {
2022-12-27 13:30:02 +01:00
var _surf = getSingleValue(0, arr);
var _out_type = getSingleValue(9, arr);
var _out = getSingleValue(1, arr);
var _rotate = getSingleValue(5, arr);
2023-04-16 11:53:46 +02:00
var _scale = getSingleValue(6, arr);
2022-12-27 04:00:50 +01:00
var ww, hh;
var sw = surface_get_width_safe(_surf);
var sh = surface_get_height_safe(_surf);
2022-12-27 04:00:50 +01:00
switch(_out_type) {
case OUTPUT_SCALING.same_as_input :
ww = sw;
hh = sh;
2022-12-27 04:00:50 +01:00
break;
case OUTPUT_SCALING.relative :
ww = sw * _out[0];
hh = sh * _out[1];
2022-12-27 04:00:50 +01:00
break;
case OUTPUT_SCALING.constant :
ww = _out[0];
hh = _out[1];
2022-12-27 04:00:50 +01:00
break;
2023-04-16 11:53:46 +02:00
case OUTPUT_SCALING.scale :
ww = sw * _scale[0];
hh = sh * _scale[1];
var p0 = point_rotate( 0, 0, ww / 2, hh / 2, _rotate);
var p1 = point_rotate(ww, 0, ww / 2, hh / 2, _rotate);
var p2 = point_rotate( 0, hh, ww / 2, hh / 2, _rotate);
var p3 = point_rotate(ww, hh, ww / 2, hh / 2, _rotate);
var minx = min(p0[0], p1[0], p2[0], p3[0]);
var maxx = max(p0[0], p1[0], p2[0], p3[0]);
var miny = min(p0[1], p1[1], p2[1], p3[1]);
var maxy = max(p0[1], p1[1], p2[1], p3[1]);
ww = maxx - minx;
hh = maxy - miny;
2023-04-16 11:53:46 +02:00
break;
2022-12-27 04:00:50 +01:00
}
2022-12-27 13:30:02 +01:00
2023-09-14 16:29:39 +02:00
return [ ww, hh ];
2024-08-07 11:48:39 +02:00
}
2022-12-27 04:00:50 +01:00
2024-08-07 11:48:39 +02:00
static centerAnchor = function() {
var _surf = getInputData(0);
2022-01-13 05:24:03 +01:00
var _out_type = getInputData(9);
var _out = getInputData(1);
var _sca = getInputData(6);
2022-01-13 05:24:03 +01:00
if(is_array(_surf)) {
if(array_length(_surf) == 0) return;
_surf = _surf[preview_index];
2022-01-13 05:24:03 +01:00
}
2024-08-08 06:57:51 +02:00
inputs[3].setValue([ 0.5, 0.5 ]);
inputs[2].setValue([ surface_get_width_safe(_surf) / 2, surface_get_height_safe(_surf) / 2 ]);
2024-08-07 11:48:39 +02:00
}
2022-01-13 05:24:03 +01:00
2024-08-07 11:48:39 +02:00
static step = function() {
2023-11-17 06:24:31 +01:00
var pos = getSingleValue(2);
var anc = getSingleValue(3);
2023-11-07 06:01:38 +01:00
2024-08-08 06:57:51 +02:00
var _b = inputs[3].editWidget.side_button;
2023-11-07 06:01:38 +01:00
var _a = anc[0] * 2 + anc[1] * 20;
2023-11-30 10:55:37 +01:00
2023-11-07 06:01:38 +01:00
switch(_a) {
case 0 : _b.index = 0; break;
case 1 : _b.index = 1; break;
case 2 : _b.index = 2; break;
case 10 : _b.index = 3; break;
case 11 : _b.index = 4; break;
case 12 : _b.index = 5; break;
case 20 : _b.index = 6; break;
case 21 : _b.index = 7; break;
case 22 : _b.index = 8; break;
default : _b.index = -1;
}
2022-01-13 05:24:03 +01:00
2023-07-06 19:49:16 +02:00
if(!PROJECT.animator.frame_progress) return;
2022-12-27 13:30:02 +01:00
2024-01-19 09:33:37 +01:00
if(IS_FIRST_FRAME) {
2022-12-27 13:30:02 +01:00
vel = 0;
prev_pos[0] = pos[0];
prev_pos[1] = pos[1];
2024-08-07 11:48:39 +02:00
2022-12-27 13:30:02 +01:00
} else {
vel = point_direction(prev_pos[0], prev_pos[1], pos[0], pos[1]);
2022-01-13 05:24:03 +01:00
2022-12-27 13:30:02 +01:00
prev_pos[0] = pos[0];
prev_pos[1] = pos[1];
2022-01-13 05:24:03 +01:00
}
2024-08-07 11:48:39 +02:00
}
2022-01-13 05:24:03 +01:00
2024-08-07 11:48:39 +02:00
static processData = function(_outData, _data, _output_index, _array_index) {
2022-01-13 05:24:03 +01:00
var ins = _data[0];
2023-12-06 05:09:39 +01:00
var out_type = _data[9];
var out = _data[1];
2023-10-03 11:27:36 +02:00
var pos = [ _data[2][0], _data[2][1] ];
2022-01-13 05:24:03 +01:00
var pos_exact = _data[10];
2023-12-06 05:09:39 +01:00
var anc = [ _data[3][0], _data[3][1] ];
var rot_vel = vel * _data[8];
var rot = _data[5] + rot_vel;
var sca = _data[6];
var mode = _data[7];
2022-01-13 05:24:03 +01:00
2024-01-12 05:03:35 +01:00
var echo = _data[12];
var echo_amo = _data[13];
2024-02-01 05:26:02 +01:00
var alp = _data[14];
2024-01-12 05:03:35 +01:00
2024-06-06 09:54:13 +02:00
var _outSurf = _outData[0];
2024-08-08 06:57:51 +02:00
var _outRes = array_create(array_length(outputs));
2024-06-06 09:54:13 +02:00
2023-03-19 09:17:39 +01:00
var cDep = attrDepth();
2023-09-08 21:37:36 +02:00
var ww = surface_get_width_safe(ins);
var hh = surface_get_height_safe(ins);
2023-11-26 13:16:38 +01:00
var _ww = ww;
var _hh = hh;
2024-06-06 09:54:13 +02:00
if(!is_surface(ins)) {
surface_free(_outSurf);
_outSurf = noone;
}
2024-06-06 09:54:13 +02:00
_outRes[0] = _outSurf;
_outRes[1] = [ ww, hh ];
if(_ww <= 1 && _hh <= 1) return _outRes;
2022-12-27 13:30:02 +01:00
2023-12-06 05:09:39 +01:00
switch(out_type) { #region output dimension
2022-01-13 05:24:03 +01:00
case OUTPUT_SCALING.same_as_input :
2024-08-08 06:57:51 +02:00
inputs[1].setVisible(false);
2022-01-13 05:24:03 +01:00
break;
case OUTPUT_SCALING.constant :
2024-08-08 06:57:51 +02:00
inputs[1].setVisible(true);
2022-01-13 05:24:03 +01:00
_ww = out[0];
_hh = out[1];
break;
case OUTPUT_SCALING.relative :
2024-08-08 06:57:51 +02:00
inputs[1].setVisible(true);
2022-01-13 05:24:03 +01:00
_ww = ww * out[0];
_hh = hh * out[1];
break;
2023-04-16 11:53:46 +02:00
case OUTPUT_SCALING.scale :
2024-08-08 06:57:51 +02:00
inputs[1].setVisible(false);
2023-04-16 11:53:46 +02:00
_ww = ww * sca[0];
_hh = hh * sca[1];
var p0 = point_rotate( 0, 0, _ww / 2, _hh / 2, rot);
var p1 = point_rotate(_ww, 0, _ww / 2, _hh / 2, rot);
var p2 = point_rotate( 0, _hh, _ww / 2, _hh / 2, rot);
var p3 = point_rotate(_ww, _hh, _ww / 2, _hh / 2, rot);
var minx = min(p0[0], p1[0], p2[0], p3[0]);
var maxx = max(p0[0], p1[0], p2[0], p3[0]);
var miny = min(p0[1], p1[1], p2[1], p3[1]);
var maxy = max(p0[1], p1[1], p2[1], p3[1]);
_ww = maxx - minx;
_hh = maxy - miny;
2023-04-16 11:53:46 +02:00
break;
2023-12-06 05:09:39 +01:00
} #endregion
2024-06-06 09:54:13 +02:00
_outRes[1] = [ ww, hh ];
if(_ww <= 0 || _hh <= 0) return _outRes;
2023-03-19 09:17:39 +01:00
_outSurf = surface_verify(_outSurf, _ww, _hh, cDep);
2024-06-06 09:54:13 +02:00
_outRes[0] = _outSurf;
2022-01-13 05:24:03 +01:00
2022-12-27 13:30:02 +01:00
anc[0] *= ww * sca[0];
anc[1] *= hh * sca[1];
2022-01-13 05:24:03 +01:00
pos[0] -= anc[0];
pos[1] -= anc[1];
pos = point_rotate(pos[0], pos[1], pos[0] + anc[0], pos[1] + anc[1], rot);
2024-01-28 09:53:41 +01:00
var draw_x, draw_y;
draw_x = pos[0];
draw_y = pos[1];
2022-01-13 05:24:03 +01:00
2024-01-28 09:53:41 +01:00
if(pos_exact) {
draw_x = round(draw_x);
draw_y = round(draw_y);
}
2022-01-13 05:24:03 +01:00
2024-08-07 11:48:39 +02:00
if(mode == 1) { // Tile
2023-03-21 03:01:53 +01:00
surface_set_shader(_outSurf);
2024-01-28 09:53:41 +01:00
shader_set_interpolation(ins);
2022-01-13 05:24:03 +01:00
2024-02-01 05:26:02 +01:00
draw_surface_tiled_ext_safe(ins, draw_x, draw_y, sca[0], sca[1], rot, c_white, alp);
2022-01-13 05:24:03 +01:00
2024-01-28 09:53:41 +01:00
surface_reset_shader();
2024-08-07 11:48:39 +02:00
} else { // Normal or wrap
2023-06-13 14:42:06 +02:00
surface_set_shader(_outSurf);
2023-11-26 13:16:38 +01:00
shader_set_interpolation(ins);
2024-01-12 05:03:35 +01:00
if(echo && CURRENT_FRAME && prev_data != noone) {
var _pre = prev_data[_array_index];
for( var i = 0; i <= echo_amo; i++ ) {
var rat = i / echo_amo;
2024-03-23 07:26:11 +01:00
var _px = lerp(_pre[0][0], draw_x, rat);
var _py = lerp(_pre[0][1], draw_y, rat);
2024-01-12 05:03:35 +01:00
var _rt = lerp(_pre[1], rot, rat);
var _sx = lerp(_pre[2][0], sca[0], rat);
var _sy = lerp(_pre[2][1], sca[1], rat);
if(pos_exact) {
2024-03-23 07:26:11 +01:00
_px = round(_px);
_py = round(_py);
2024-01-12 05:03:35 +01:00
}
2024-03-23 07:26:11 +01:00
draw_surface_ext_safe(ins, _px, _py, _sx, _sy, _rt, c_white, alp);
2024-01-12 05:03:35 +01:00
}
} else
2024-02-01 05:26:02 +01:00
draw_surface_ext_safe(ins, draw_x, draw_y, sca[0], sca[1], rot, c_white, alp);
2023-06-13 14:42:06 +02:00
if(mode == 2) {
2024-02-01 05:26:02 +01:00
draw_surface_ext_safe(ins, draw_x - _ww, draw_y - _hh, sca[0], sca[1], rot, c_white, alp);
draw_surface_ext_safe(ins, draw_x, draw_y - _hh, sca[0], sca[1], rot, c_white, alp);
draw_surface_ext_safe(ins, draw_x + _ww, draw_y - _hh, sca[0], sca[1], rot, c_white, alp);
2023-06-13 14:42:06 +02:00
2024-02-01 05:26:02 +01:00
draw_surface_ext_safe(ins, draw_x - _ww, draw_y, sca[0], sca[1], rot, c_white, alp);
draw_surface_ext_safe(ins, draw_x + _ww, draw_y, sca[0], sca[1], rot, c_white, alp);
2023-06-13 14:42:06 +02:00
2024-02-01 05:26:02 +01:00
draw_surface_ext_safe(ins, draw_x - _ww, draw_y + _hh, sca[0], sca[1], rot, c_white, alp);
draw_surface_ext_safe(ins, draw_x, draw_y + _hh, sca[0], sca[1], rot, c_white, alp);
draw_surface_ext_safe(ins, draw_x + _ww, draw_y + _hh, sca[0], sca[1], rot, c_white, alp);
2023-06-13 14:42:06 +02:00
}
2023-03-21 03:01:53 +01:00
surface_reset_shader();
2024-08-07 11:48:39 +02:00
2022-01-13 05:24:03 +01:00
}
2024-01-12 05:03:35 +01:00
prev_data[_array_index] = [
2024-03-23 07:26:11 +01:00
[ draw_x, draw_y ],
2024-01-12 05:03:35 +01:00
rot,
[ sca[0], sca[1] ],
];
2024-06-06 09:54:13 +02:00
return _outRes;
2024-08-07 11:48:39 +02:00
}
2022-01-13 05:24:03 +01:00
overlay_dragging = 0;
2022-12-27 13:30:02 +01:00
corner_dragging = 0;
2022-01-13 05:24:03 +01:00
overlay_drag_mx = 0;
overlay_drag_my = 0;
overlay_drag_sx = 0;
overlay_drag_sy = 0;
2023-01-17 08:11:55 +01:00
overlay_drag_px = 0;
overlay_drag_py = 0;
2022-01-13 05:24:03 +01:00
overlay_drag_ma = 0;
overlay_drag_sa = 0;
2024-08-07 11:48:39 +02:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
2023-09-09 13:52:16 +02:00
PROCESSOR_OVERLAY_CHECK
2022-01-13 05:24:03 +01:00
var _surf = current_data[0];
2022-01-13 05:24:03 +01:00
if(is_array(_surf)) {
if(array_length(_surf) == 0) return;
_surf = _surf[preview_index];
2022-01-13 05:24:03 +01:00
}
2024-08-08 06:57:51 +02:00
var _surf_out = outputs[0].getValue();
2022-01-13 05:24:03 +01:00
if(is_array(_surf_out)) {
if(array_length(_surf_out) == 0) return;
_surf_out = _surf_out[preview_index];
2022-01-13 05:24:03 +01:00
}
var __pos = current_data[2];
2023-10-03 11:27:36 +02:00
var pos = [ __pos[0], __pos[1] ];
var _pos = [ __pos[0], __pos[1] ];
2022-01-13 05:24:03 +01:00
var __anc = current_data[3];
2023-10-03 11:27:36 +02:00
var anc = [ __anc[0], __anc[1] ];
var _anc = [ __anc[0], __anc[1] ];
2022-01-13 05:24:03 +01:00
var rot = current_data[5];
var sca = current_data[6];
2022-01-13 05:24:03 +01:00
2023-09-08 21:37:36 +02:00
var srw = surface_get_width_safe(_surf);
var srh = surface_get_height_safe(_surf);
2022-01-13 05:24:03 +01:00
2023-09-08 21:37:36 +02:00
var ow = surface_get_width_safe(_surf_out);
var oh = surface_get_height_safe(_surf_out);
2022-01-13 05:24:03 +01:00
var ww = srw * sca[0];
var hh = srh * sca[1];
2022-12-27 13:30:02 +01:00
anc[0] *= ww;
anc[1] *= hh;
2022-01-13 05:24:03 +01:00
pos[0] -= anc[0];
pos[1] -= anc[1];
#region bounding box
var bx0 = _x + pos[0] * _s;
var by0 = _y + pos[1] * _s;
2023-11-07 06:01:38 +01:00
var bx1 = _x + (pos[0] + ww) * _s;
var by1 = _y + (pos[1] + hh) * _s;
var bx2 = _x + (pos[0] + ww) * _s + 18;
var by2 = _y + (pos[1] + hh) * _s + 18;
2022-12-27 04:00:50 +01:00
2022-01-13 05:24:03 +01:00
var bax = _x + (pos[0] + anc[0]) * _s;
var bay = _y + (pos[1] + anc[1]) * _s;
var tl = point_rotate(bx0, by0, bax, bay, rot);
var tr = point_rotate(bx1, by0, bax, bay, rot);
var bl = point_rotate(bx0, by1, bax, bay, rot);
var br = point_rotate(bx1, by1, bax, bay, rot);
2023-11-07 06:01:38 +01:00
var sz = point_rotate(bx2, by2, bax, bay, rot);
2022-01-13 05:24:03 +01:00
var rth = point_rotate((bx0 + bx1) / 2, by0 - 16, bax, bay, rot);
2023-11-07 06:01:38 +01:00
var a_index = 0;
var r_index = 0;
var tl_index = 0;
var tr_index = 0;
var bl_index = 0;
var br_index = 0;
var sz_index = 0;
2022-01-13 05:24:03 +01:00
2023-11-07 06:01:38 +01:00
draw_set_color(COLORS._main_accent);
2022-01-13 05:24:03 +01:00
draw_line(tl[0], tl[1], tr[0], tr[1]);
draw_line(tl[0], tl[1], bl[0], bl[1]);
draw_line(tr[0], tr[1], br[0], br[1]);
draw_line(bl[0], bl[1], br[0], br[1]);
2023-11-07 06:01:38 +01:00
if(point_in_circle(_mx, _my, bax, bay, 8)) a_index = 1;
else if(point_in_circle(_mx, _my, rth[0], rth[1], 8)) r_index = 1;
else if(point_in_circle(_mx, _my, tl[0], tl[1], 8)) tl_index = 1;
else if(point_in_circle(_mx, _my, tr[0], tr[1], 8)) tr_index = 1;
else if(point_in_circle(_mx, _my, bl[0], bl[1], 8)) bl_index = 1;
else if(point_in_circle(_mx, _my, br[0], br[1], 8)) br_index = 1;
else if(point_in_circle(_mx, _my, sz[0], sz[1], 8)) sz_index = 1;
draw_sprite_colored(THEME.anchor, a_index, bax, bay);
draw_sprite_colored(THEME.anchor_selector, tl_index, tl[0], tl[1]);
draw_sprite_colored(THEME.anchor_selector, tr_index, tr[0], tr[1]);
draw_sprite_colored(THEME.anchor_selector, bl_index, bl[0], bl[1]);
draw_sprite_colored(THEME.anchor_selector, br_index, br[0], br[1]);
draw_sprite_colored(THEME.anchor_scale, sz_index, sz[0], sz[1], 1, rot);
draw_sprite_colored(THEME.anchor_rotate, r_index, rth[0], rth[1], 1, rot);
2022-01-13 05:24:03 +01:00
#endregion
2023-02-14 05:32:32 +01:00
if(overlay_dragging && overlay_dragging < 3) { //Transform
2022-01-13 05:24:03 +01:00
var px = _mx - overlay_drag_mx;
var py = _my - overlay_drag_my;
var pos_x, pos_y;
2023-02-14 05:32:32 +01:00
if(key_mod_press(SHIFT)) {
2022-01-13 05:24:03 +01:00
var ang = round(point_direction(overlay_drag_mx, overlay_drag_my, _mx, _my) / 45) * 45;
var dist = point_distance(overlay_drag_mx, overlay_drag_my, _mx, _my) / _s;
pos_x = overlay_drag_sx + lengthdir_x(dist, ang);
pos_y = overlay_drag_sy + lengthdir_y(dist, ang);
} else {
pos_x = overlay_drag_sx + px / _s;
pos_y = overlay_drag_sy + py / _s;
}
2022-12-19 13:35:30 +01:00
pos_x = value_snap(pos_x, _snx);
pos_y = value_snap(pos_y, _sny);
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
if(overlay_dragging == 1) { //Move
2024-08-08 06:57:51 +02:00
if(inputs[2].setValue([ pos_x, pos_y ]))
2022-01-13 05:24:03 +01:00
UNDO_HOLDING = true;
2023-01-17 08:11:55 +01:00
} else if(overlay_dragging == 2) { //Move anchor
var nanx = pos_x / ww;
var nany = pos_y / hh;
2023-02-14 05:32:32 +01:00
if(key_mod_press(ALT)) {
var modi = false;
2024-08-08 06:57:51 +02:00
modi |= inputs[3].setValue([ nanx, nany ]);
modi |= inputs[2].setValue([ overlay_drag_px + pos_x, overlay_drag_py + pos_y ]);
2023-01-17 08:11:55 +01:00
2023-02-14 05:32:32 +01:00
if(modi)
2023-01-17 08:11:55 +01:00
UNDO_HOLDING = true;
} else {
2024-08-08 06:57:51 +02:00
if(inputs[3].setValue([ nanx, nany ]))
2023-01-17 08:11:55 +01:00
UNDO_HOLDING = true;
}
2022-01-13 05:24:03 +01:00
}
2022-12-10 05:06:01 +01:00
if(mouse_release(mb_left)) {
2022-01-13 05:24:03 +01:00
overlay_dragging = 0;
UNDO_HOLDING = false;
}
2023-01-17 08:11:55 +01:00
} else if(overlay_dragging == 3) { //Angle
2022-01-13 05:24:03 +01:00
var aa = point_direction(bax, bay, _mx, _my);
var da = angle_difference(overlay_drag_ma, aa);
var sa;
2023-11-07 06:01:38 +01:00
if(key_mod_press(CTRL)) sa = round((overlay_drag_sa - da) / 15) * 15;
else sa = overlay_drag_sa - da;
2022-01-13 05:24:03 +01:00
2024-08-08 06:57:51 +02:00
if(inputs[5].setValue(sa))
2022-01-13 05:24:03 +01:00
UNDO_HOLDING = true;
2022-12-10 05:06:01 +01:00
if(mouse_release(mb_left)) {
2022-01-13 05:24:03 +01:00
overlay_dragging = 0;
UNDO_HOLDING = false;
}
2023-01-17 08:11:55 +01:00
} else if(overlay_dragging == 4) { //Scale
2023-11-07 06:01:38 +01:00
var ol_x = (overlay_drag_mx - _x) / _s;
var ol_y = (overlay_drag_my - _y) / _s;
var ml_x = (_mx - _x) / _s;
var ml_y = (_my - _y) / _s;
2022-01-13 05:24:03 +01:00
2023-11-07 06:01:38 +01:00
var os_x = value_snap(ol_x, _snx);
var os_y = value_snap(ol_y, _sny);
var ms_x = value_snap(ml_x, _snx);
var ms_y = value_snap(ml_y, _sny);
var _p = point_rotate(ms_x - os_x, ms_y - os_y, 0, 0, -rot);
var _sw = _p[0] / srw;
var _sh = _p[1] / srh;
2022-12-27 13:30:02 +01:00
var sw, sh;
2022-01-13 05:24:03 +01:00
2022-12-27 13:30:02 +01:00
if(corner_dragging == 0) {
sw = -_sw / _anc[0];
sh = -_sh / _anc[1];
} else if(corner_dragging == 1) {
sw = _sw / (1 - _anc[0]);
sh = -_sh / _anc[1];
} else if(corner_dragging == 2) {
sw = -_sw / _anc[0];
sh = _sh / (1 - _anc[1]);
} else if(corner_dragging == 3) {
sw = _sw / (1 - _anc[0]);
sh = _sh / (1 - _anc[1]);
2023-11-07 06:01:38 +01:00
} else if(corner_dragging == 4) {
sw = _sw / (1 - _anc[0]);
sh = _sh / (1 - _anc[1]);
2022-12-27 13:30:02 +01:00
}
2022-01-13 05:24:03 +01:00
2022-12-27 13:30:02 +01:00
var _sw = overlay_drag_sx + sw;
var _sh = overlay_drag_sy + sh;
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
if(key_mod_press(SHIFT)) {
2022-01-13 05:24:03 +01:00
_sw = max(_sw, _sh);
_sh = _sw;
}
2024-08-08 06:57:51 +02:00
if(inputs[6].setValue([ _sw, _sh ]))
2022-01-13 05:24:03 +01:00
UNDO_HOLDING = true;
2022-12-10 05:06:01 +01:00
if(mouse_release(mb_left)) {
2022-01-13 05:24:03 +01:00
overlay_dragging = 0;
UNDO_HOLDING = false;
}
2022-12-27 04:00:50 +01:00
}
2022-12-19 13:35:30 +01:00
if(overlay_dragging == 0 && mouse_press(mb_left, active)) {
if(point_in_circle(_mx, _my, bax, bay, 8)) {
overlay_dragging = 2;
overlay_drag_mx = _mx;
overlay_drag_my = _my;
overlay_drag_sx = anc[0];
overlay_drag_sy = anc[1];
2023-01-17 08:11:55 +01:00
overlay_drag_px = pos[0];
overlay_drag_py = pos[1];
2023-11-07 06:01:38 +01:00
} else if(point_in_circle(_mx, _my, tl[0], tl[1], 8) ||
point_in_circle(_mx, _my, tr[0], tr[1], 8) ||
point_in_circle(_mx, _my, bl[0], bl[1], 8) ||
point_in_circle(_mx, _my, br[0], br[1], 8) ||
point_in_circle(_mx, _my, sz[0], sz[1], 8)) {
2022-12-19 13:35:30 +01:00
overlay_dragging = 4;
2022-12-27 13:30:02 +01:00
if(point_in_circle(_mx, _my, tl[0], tl[1], 8)) corner_dragging = 0;
else if(point_in_circle(_mx, _my, tr[0], tr[1], 8)) corner_dragging = 1;
else if(point_in_circle(_mx, _my, bl[0], bl[1], 8)) corner_dragging = 2;
else if(point_in_circle(_mx, _my, br[0], br[1], 8)) corner_dragging = 3;
2023-11-07 06:01:38 +01:00
else if(point_in_circle(_mx, _my, sz[0], sz[1], 8)) corner_dragging = 4;
2022-12-27 13:30:02 +01:00
2022-12-19 13:35:30 +01:00
overlay_drag_mx = _mx;
overlay_drag_my = _my;
overlay_drag_sx = sca[0];
overlay_drag_sy = sca[1];
2022-12-19 13:35:30 +01:00
} else if(point_in_circle(_mx, _my, rth[0], rth[1], 8)) {
overlay_dragging = 3;
overlay_drag_ma = point_direction(bax, bay, _mx, _my);
overlay_drag_sa = rot;
2023-11-07 06:01:38 +01:00
} else if(point_in_triangle(_mx, _my, tl[0], tl[1], tr[0], tr[1], bl[0], bl[1]) ||
point_in_triangle(_mx, _my, tr[0], tr[1], bl[0], bl[1], br[0], br[1])) {
2022-12-19 13:35:30 +01:00
overlay_dragging = 1;
overlay_drag_mx = _mx;
overlay_drag_my = _my;
overlay_drag_sx = _pos[0];
overlay_drag_sy = _pos[1];
2022-01-13 05:24:03 +01:00
}
}
2022-12-27 04:00:50 +01:00
#region path
2024-08-08 06:57:51 +02:00
if(inputs[2].is_anim && inputs[2].value_from == noone && !inputs[2].sep_axis) {
var posInp = inputs[2];
2022-12-27 04:00:50 +01:00
var allPos = posInp.animator.values;
var ox, oy, nx, ny;
draw_set_color(COLORS._main_accent);
for( var i = 0; i < ds_list_size(allPos); i++ ) {
var pos = allPos[| i].value;
var _pos = [ pos[0], pos[1] ];
2022-12-27 04:00:50 +01:00
if(posInp.unit.mode == VALUE_UNIT.reference) {
_pos[0] *= ow;
_pos[1] *= oh;
}
nx = _x + _pos[0] * _s;
ny = _y + _pos[1] * _s;
draw_set_alpha(1);
2023-06-17 14:30:49 +02:00
draw_circle_prec(nx, ny, 4, false);
2022-12-27 04:00:50 +01:00
if(i) {
draw_set_alpha(0.5);
draw_line_dashed(ox, oy, nx, ny);
}
ox = nx;
oy = ny;
}
draw_set_alpha(1);
}
#endregion
2024-08-07 11:48:39 +02:00
}
2022-01-13 05:24:03 +01:00
}