2023-11-08 14:37:51 +01:00
|
|
|
function Node_Active_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|
|
|
name = "Active Canvas";
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Dimension(self));
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(1, nodeValue_Surface("Texture", self));
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(2, nodeValue_Vec2("Position", self, [ 0, 0 ] ));
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(3, nodeValue_Rotation("Rotation", self, 0));
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(4, nodeValue_Vec2("Scale", self, [ 1, 1 ] ));
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-11-23 08:31:15 +01:00
|
|
|
newInput(5, nodeValue_Color("Color", self, cola(c_white) ));
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(6, nodeValue_Float("Alpha", self, 1 ))
|
2023-11-08 14:37:51 +01:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider);
|
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(7, nodeValue_Bool("Active", self, true ));
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(8, nodeValue_Range("Distance", self, [ 1, 1 ] , { linked : true }));
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-09-04 03:57:11 +02:00
|
|
|
newOutput(0, nodeValue_Output("Output", self, VALUE_TYPE.surface, noone ));
|
2023-11-08 14:37:51 +01:00
|
|
|
|
|
|
|
input_display_list = [ 0,
|
|
|
|
[ "Brush transform", false ], 7, 2, 3, 4,
|
2024-01-08 08:10:50 +01:00
|
|
|
[ "Brush properties", false ], 1, 5, 8,
|
2023-11-08 14:37:51 +01:00
|
|
|
];
|
|
|
|
|
2023-11-23 13:39:35 +01:00
|
|
|
brush_prev = noone;
|
2023-11-08 14:37:51 +01:00
|
|
|
brush_next_dist = 0;
|
|
|
|
|
2024-01-20 05:06:56 +01:00
|
|
|
temp_surface = [ surface_create(1, 1) ];
|
|
|
|
|
2024-03-14 14:35:19 +01:00
|
|
|
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
|
2024-01-20 05:06:56 +01:00
|
|
|
} #endregion
|
2023-11-08 14:37:51 +01:00
|
|
|
|
|
|
|
static step = function() { #region
|
|
|
|
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static brush_draw_surface = function(_surf, _x, _y, _sx, _sy, _rot, _clr, _alp) { #region
|
|
|
|
INLINE
|
|
|
|
|
|
|
|
var _bsw = surface_get_width_safe(_surf);
|
|
|
|
var _bsh = surface_get_height_safe(_surf);
|
|
|
|
var _p = point_rotate(-_bsw * _sx / 2, -_bsh * _sy / 2, 0, 0, _rot);
|
|
|
|
draw_surface_ext_safe(_surf, _x + _p[0], _y + _p[1], _sx, _sy, _rot, _clr, _alp);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static update = function() { #region
|
2024-08-08 06:57:51 +02:00
|
|
|
var _surf = outputs[0].getValue();
|
2023-11-08 14:37:51 +01:00
|
|
|
|
|
|
|
var _dim = getInputData(0);
|
|
|
|
var _bsurf = getInputData(1);
|
|
|
|
var _bpos = getInputData(2);
|
|
|
|
var _brot = getInputData(3);
|
|
|
|
var _bsca = getInputData(4);
|
|
|
|
var _bcol = getInputData(5);
|
2024-01-08 08:10:50 +01:00
|
|
|
var _balp = _color_get_alpha(_bcol);
|
2023-11-08 14:37:51 +01:00
|
|
|
var _bact = getInputData(7);
|
|
|
|
var _bdst = getInputData(8);
|
|
|
|
|
2024-01-20 05:06:56 +01:00
|
|
|
_surf = surface_verify(_surf, _dim[0], _dim[1]);
|
|
|
|
temp_surface[0] = surface_verify(temp_surface[0], _dim[0], _dim[1]);
|
|
|
|
|
2023-11-08 14:37:51 +01:00
|
|
|
var _bdense = _bdst[0] == _bdst[1] && _bdst[0] == 1;
|
2024-04-20 03:02:56 +02:00
|
|
|
_bdst[0] = max(0.01, _bdst[0]);
|
|
|
|
_bdst[1] = max(0.01, _bdst[1]);
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(_surf);
|
2024-01-20 05:06:56 +01:00
|
|
|
if(!_bact) return;
|
|
|
|
|
|
|
|
surface_set_target(temp_surface[0]);
|
|
|
|
DRAW_CLEAR
|
|
|
|
BLEND_OVERRIDE
|
|
|
|
|
|
|
|
if(!IS_FIRST_FRAME)
|
|
|
|
draw_surface_ext(_surf, 0, 0, 1, 1, 0, c_white, 1);
|
|
|
|
|
|
|
|
BLEND_NORMAL
|
|
|
|
surface_reset_target();
|
2023-11-23 13:39:35 +01:00
|
|
|
|
2023-11-08 14:37:51 +01:00
|
|
|
surface_set_target(_surf);
|
2024-01-20 05:06:56 +01:00
|
|
|
DRAW_CLEAR
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-07-10 03:45:25 +02:00
|
|
|
draw_surface_safe(temp_surface[0]);
|
2024-01-20 05:06:56 +01:00
|
|
|
|
|
|
|
if(!is_surface(_bsurf)) {
|
|
|
|
if(IS_FIRST_FRAME || brush_prev == noone)
|
|
|
|
draw_point_color(_bpos[0] - 1, _bpos[1] - 1, _bcol);
|
|
|
|
else
|
|
|
|
draw_line_color(brush_prev[2][0] - 1, brush_prev[2][1] - 1, _bpos[0] - 1, _bpos[1] - 1, brush_prev[5], _bcol);
|
|
|
|
} else {
|
|
|
|
BLEND_ALPHA
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-01-20 05:06:56 +01:00
|
|
|
if(IS_FIRST_FRAME || brush_prev == noone) {
|
|
|
|
brush_draw_surface(_bsurf, _bpos[0], _bpos[1], _bsca[0], _bsca[1], _brot, _bcol, _balp);
|
|
|
|
} else {
|
|
|
|
var _x0 = brush_prev[2][0];
|
|
|
|
var _y0 = brush_prev[2][1];
|
|
|
|
var diss = point_distance(_x0, _y0, _bpos[0], _bpos[1]);
|
|
|
|
var dirr = point_direction(_x0, _y0, _bpos[0], _bpos[1]);
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-01-20 05:06:56 +01:00
|
|
|
var st_x = lengthdir_x(1, dirr);
|
|
|
|
var st_y = lengthdir_y(1, dirr);
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-01-20 05:06:56 +01:00
|
|
|
var _draw = !brush_prev[7];
|
|
|
|
var _i = _draw? 0 : brush_next_dist;
|
|
|
|
var _dst = diss;
|
|
|
|
|
|
|
|
if(_i < diss) {
|
|
|
|
while(_i < diss) {
|
|
|
|
var _px = _x0 + st_x * _i;
|
|
|
|
var _py = _y0 + st_y * _i;
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-01-20 05:06:56 +01:00
|
|
|
brush_draw_surface(_bsurf, _px, _py, _bsca[0], _bsca[1], _brot, _bcol, _balp);
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-01-20 05:06:56 +01:00
|
|
|
brush_next_dist = random_range(_bdst[0], _bdst[1]);
|
|
|
|
_i += brush_next_dist;
|
|
|
|
_dst -= brush_next_dist;
|
|
|
|
}
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-01-20 05:06:56 +01:00
|
|
|
brush_next_dist -= _dst;
|
|
|
|
} else
|
|
|
|
brush_next_dist -= diss;
|
2023-11-08 14:37:51 +01:00
|
|
|
|
2024-01-20 05:06:56 +01:00
|
|
|
if(_bdense) brush_draw_surface(_bsurf, _bpos[0], _bpos[1], _bsca[0], _bsca[1], _brot, _bcol, _balp);
|
2023-11-08 14:37:51 +01:00
|
|
|
}
|
2024-01-20 05:06:56 +01:00
|
|
|
BLEND_NORMAL
|
2023-11-08 14:37:51 +01:00
|
|
|
}
|
|
|
|
surface_reset_target();
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(inputs_data); i < n; i++ )
|
|
|
|
brush_prev[i] = variable_clone(inputs_data[i], 1);
|
|
|
|
} #endregion
|
|
|
|
}
|