2023-02-28 09:43:01 +01:00
|
|
|
function Node_Crop(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
name = "Crop";
|
2022-12-16 09:18:09 +01:00
|
|
|
preview_alpha = 0.5;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, 0);
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 1] = nodeValue("Crop", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 0, 0, 0, 0 ])
|
2022-12-27 04:00:50 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.padding)
|
2022-12-27 13:30:02 +01:00
|
|
|
.setUnitRef(function(index) { return getDimension(index); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 2] = nodeValue("Active", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
|
|
|
|
active_index = 2;
|
|
|
|
|
|
|
|
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
|
|
|
|
|
|
|
|
input_display_list = [ 2,
|
|
|
|
["Surface", false], 0, 1,
|
|
|
|
]
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
drag_side = -1;
|
|
|
|
drag_mx = 0;
|
|
|
|
drag_my = 0;
|
|
|
|
drag_sv = 0;
|
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
static getPreviewValue = function() { return inputs[| 0]; }
|
|
|
|
|
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
|
|
|
if(array_length(current_data) < 2) return;
|
|
|
|
|
2022-12-27 04:00:50 +01:00
|
|
|
var _inSurf = current_data[0];
|
|
|
|
var _splice = current_data[1];
|
|
|
|
for( var i = 0; i < array_length(_splice); i++ )
|
|
|
|
_splice[i] = round(_splice[i]);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
var dim = [ surface_get_width(_inSurf), surface_get_height(_inSurf) ]
|
|
|
|
|
|
|
|
var sp_r = _x + (dim[0] - _splice[0]) * _s;
|
|
|
|
var sp_l = _x + _splice[2] * _s;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
var sp_t = _y + _splice[1] * _s;
|
|
|
|
var sp_b = _y + (dim[1] - _splice[3]) * _s;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var ww = WIN_W;
|
|
|
|
var hh = WIN_H;
|
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
var _out = outputs[| 0].getValue();
|
|
|
|
draw_surface_ext_safe(_out, sp_l, sp_t, _s, _s);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS._main_accent);
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_line(sp_r, -hh, sp_r, hh);
|
|
|
|
draw_line(sp_l, -hh, sp_l, hh);
|
|
|
|
draw_line(-ww, sp_t, ww, sp_t);
|
|
|
|
draw_line(-ww, sp_b, ww, sp_b);
|
|
|
|
|
|
|
|
if(drag_side > -1) {
|
|
|
|
var vv;
|
|
|
|
|
2022-12-19 13:35:30 +01:00
|
|
|
if(drag_side == 0) vv = value_snap(drag_sv - (_mx - drag_mx) / _s, _snx);
|
|
|
|
else if(drag_side == 2) vv = value_snap(drag_sv + (_mx - drag_mx) / _s, _snx);
|
|
|
|
else if(drag_side == 1) vv = value_snap(drag_sv + (_my - drag_my) / _s, _sny);
|
|
|
|
else vv = value_snap(drag_sv - (_my - drag_my) / _s, _sny);
|
2022-12-16 09:18:09 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
_splice[drag_side] = vv;
|
|
|
|
if(inputs[| 1].setValue(_splice))
|
|
|
|
UNDO_HOLDING = true;
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_release(mb_left, active)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_side = -1;
|
|
|
|
UNDO_HOLDING = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(distance_to_line_infinite(_mx, _my, sp_r, -hh, sp_r, hh) < 12) {
|
|
|
|
draw_line_width(sp_r, -hh, sp_r, hh, 3);
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_side = 0;
|
|
|
|
drag_mx = _mx;
|
|
|
|
drag_my = _my;
|
|
|
|
drag_sv = _splice[0];
|
|
|
|
}
|
|
|
|
} else if(distance_to_line_infinite(_mx, _my, -ww, sp_t, ww, sp_t) < 12) {
|
|
|
|
draw_line_width(-ww, sp_t, ww, sp_t, 3);
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_side = 1;
|
|
|
|
drag_mx = _mx;
|
|
|
|
drag_my = _my;
|
|
|
|
drag_sv = _splice[1];
|
|
|
|
}
|
|
|
|
} else if(distance_to_line_infinite(_mx, _my, sp_l, -hh, sp_l, hh) < 12) {
|
|
|
|
draw_line_width(sp_l, -hh, sp_l, hh, 3);
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_side = 2;
|
|
|
|
drag_mx = _mx;
|
|
|
|
drag_my = _my;
|
|
|
|
drag_sv = _splice[2];
|
|
|
|
}
|
|
|
|
} else if(distance_to_line_infinite(_mx, _my, -ww, sp_b, ww, sp_b) < 12) {
|
|
|
|
draw_line_width(-ww, sp_b, ww, sp_b, 3);
|
2022-12-12 09:08:03 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
drag_side = 3;
|
|
|
|
drag_mx = _mx;
|
|
|
|
drag_my = _my;
|
|
|
|
drag_sv = _splice[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-01 02:06:02 +01:00
|
|
|
static process_data = function(_outSurf, _data, _output_index, _array_index) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var _inSurf = _data[0];
|
|
|
|
var _crop = _data[1];
|
|
|
|
var _dim = [ surface_get_width(_inSurf) - _crop[0] - _crop[2], surface_get_height(_inSurf) - _crop[1] - _crop[3] ];
|
|
|
|
|
2022-12-27 04:00:50 +01:00
|
|
|
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
surface_set_target(_outSurf);
|
|
|
|
draw_clear_alpha(0, 0);
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_OVERRIDE;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
draw_surface_safe(_inSurf, -_crop[2], -_crop[1]);
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
BLEND_NORMAL;
|
2022-01-13 05:24:03 +01:00
|
|
|
surface_reset_target();
|
2022-12-27 04:00:50 +01:00
|
|
|
|
|
|
|
return _outSurf;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|