This commit is contained in:
Tanasart 2024-04-14 12:36:45 +07:00
parent 6b6bda0576
commit 3174d74402
27 changed files with 5268 additions and 0 deletions

View file

@ -0,0 +1,91 @@
// 2024-04-14 10:09:02
function canvas_brush() constructor {
brush_sizing = false;
brush_sizing_s = 0;
brush_sizing_mx = 0;
brush_sizing_my = 0;
brush_sizing_dx = 0;
brush_sizing_dy = 0;
brush_use_surface = false;
brush_surface = noone;
brush_size = 1;
brush_dist_min = 1;
brush_dist_max = 1;
brush_direction = 0;
brush_rand_dir = [ 0, 0, 0, 0, 0 ];
brush_seed = irandom_range(100000, 999999);
brush_next_dist = 0;
mouse_pre_dir_x = undefined;
mouse_pre_dir_y = undefined;
node = noone;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _brushSurf = node.getInputData(6);
var _brushDist = node.getInputData(15);
var _brushRotD = node.getInputData(16);
var _brushRotR = node.getInputData(17);
var attr = node.tool_attribute;
var _col = attr.color;
var _siz = attr.size;
brush_size = _siz;
if(brush_size = PEN_USE && attr.pressure)
brush_size = round(lerp(attr.pressure_size[0], attr.pressure_size[1], power(PEN_PRESSURE / 1024, 2)));
brush_dist_min = max(1, _brushDist[0]);
brush_dist_max = max(1, _brushDist[1]);
if(brush_use_surface) {
if(!is_surface(brush_surface)) {
brush_surface = noone;
brush_use_surface = false;
}
} else
brush_surface = is_surface(_brushSurf)? _brushSurf : noone;
if(!_brushRotD)
brush_direction = 0;
else if(mouse_pre_dir_x == undefined) {
mouse_pre_dir_x = _mx;
mouse_pre_dir_y = _my;
} else if(point_distance(mouse_pre_dir_x, mouse_pre_dir_y, _mx, _my) > _s) {
brush_direction = point_direction(mouse_pre_dir_x, mouse_pre_dir_y, _mx, _my);
mouse_pre_dir_x = _mx;
mouse_pre_dir_y = _my;
}
brush_rand_dir = _brushRotR;
}
function sizing(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var attr = node.tool_attribute;
var _siz = attr.size;
if(brush_sizing) {
var s = brush_sizing_s + (_mx - brush_sizing_mx) / 16;
s = max(1, s);
attr.size = s;
if(mouse_release(mb_right))
brush_sizing = false;
} else if(mouse_press(mb_right, active) && key_mod_press(SHIFT) && brush_surface == noone) {
brush_sizing = true;
brush_sizing_s = _siz;
brush_sizing_mx = _mx;
brush_sizing_my = _my;
brush_sizing_dx = round((_mx - _x) / _s - 0.5);
brush_sizing_dy = round((_my - _y) / _s - 0.5);
}
}
}

View file

@ -0,0 +1,91 @@
// 2024-04-14 10:09:00
function canvas_brush() constructor {
brush_sizing = false;
brush_sizing_s = 0;
brush_sizing_mx = 0;
brush_sizing_my = 0;
brush_sizing_dx = 0;
brush_sizing_dy = 0;
brush_use_surface = false;
brush_surface = noone;
brush_size = 1;
brush_dist_min = 1;
brush_dist_max = 1;
brush_direction = 0;
brush_rand_dir = [ 0, 0, 0, 0, 0 ];
brush_seed = irandom_range(100000, 999999);
brush_next_dist = 0;
mouse_pre_dir_x = undefined;
mouse_pre_dir_y = undefined;
node = noone;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _brushSurf = node.getInputData(6);
var _brushDist = node.getInputData(15);
var _brushRotD = node.getInputData(16);
var _brushRotR = node.getInputData(17);
var attr = node.tool_attribute;
var _col = attr.color;
var _siz = attr.size;
brush_size = _siz;
if(brush_size = PEN_USE && attr.pressure)
brush_size = round(lerp(attr.pressure_size[0], attr.pressure_size[1], power(PEN_PRESSURE / 1024, 2)));
brush_dist_min = max(1, _brushDist[0]);
brush_dist_max = max(1, _brushDist[1]);
if(brush_use_surface) {
if(!is_surface(brush_surface)) {
brush_surface = noone;
brush_use_surface = false;
}
} else
brush_surface = is_surface(_brushSurf)? _brushSurf : noone;
if(!_brushRotD)
brush_direction = 0;
else if(mouse_pre_dir_x == undefined) {
mouse_pre_dir_x = _mx;
mouse_pre_dir_y = _my;
} else if(point_distance(mouse_pre_dir_x, mouse_pre_dir_y, _mx, _my) > _s) {
brush_direction = point_direction(mouse_pre_dir_x, mouse_pre_dir_y, _mx, _my);
mouse_pre_dir_x = _mx;
mouse_pre_dir_y = _my;
}
brush_rand_dir = _brushRotR;
}
function sizing(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var attr = node.tool_attribute;
var _siz = attr.size;
if(brush_sizing) {
var s = brush_sizing_s + (_mx - brush_sizing_mx) / 16;
s = max(1, s);
attr.size = s;
if(mouse_release(mb_right))
brush_sizing = false;
} else if(mouse_press(mb_right, active) && key_mod_press(SHIFT) && brush_surface == noone) {
brush_sizing = true;
brush_sizing_s = _siz;
brush_sizing_mx = _mx;
brush_sizing_my = _my;
brush_sizing_dx = round((_mx - _x) / _s - 0.5);
brush_sizing_dy = round((_my - _y) / _s - 0.5);
}
}
}

View file

@ -0,0 +1,31 @@
// 2024-04-14 10:20:09
function canvas_tool() constructor {
node = noone;
rightTools = [];
override = false;
relative = false;
relative_position = [ 0, 0 ];
drawing_surface = noone;
_canvas_surface = noone;
apply_draw_surface = noone;
brush_resizable = false;
mouse_holding = false;
subtool = 0;
function init() {}
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {}
function drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {}
function drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {}
function drawPostOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {}
function drawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {}
}

View file

@ -0,0 +1,89 @@
// 2024-04-14 10:04:07
function canvas_tool_brush(brush, eraser = false) : canvas_tool() constructor {
self.brush = brush;
isEraser = eraser;
brush_resizable = true;
mouse_cur_x = 0;
mouse_cur_y = 0;
mouse_pre_x = 0;
mouse_pre_y = 0;
mouse_pre_draw_x = undefined;
mouse_pre_draw_y = undefined;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_press(SHIFT) && key_mod_press(CTRL)) {
var aa = point_direction(mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
var dd = point_distance(mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
var _a = round(aa / 45) * 45;
dd = dd * cos(degtorad(_a - aa));
mouse_cur_x = mouse_pre_draw_x + lengthdir_x(dd, _a);
mouse_cur_y = mouse_pre_draw_y + lengthdir_y(dd, _a);
}
if(mouse_press(mb_left, active)) {
brush_next_dist = 0;
surface_set_shader(drawing_surface, noone);
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y, true);
surface_reset_shader();
mouse_holding = true;
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_press(SHIFT)) { ///////////////// shift line
surface_set_shader(drawing_surface, noone, true, BLEND.alpha);
brush_next_dist = 0;
canvas_draw_line_size(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y, true);
surface_reset_shader();
mouse_holding = false;
apply_draw_surface();
}
node.tool_pick_color(mouse_cur_x, mouse_cur_y);
mouse_pre_draw_x = mouse_cur_x;
mouse_pre_draw_y = mouse_cur_y;
}
if(mouse_holding) {
var _move = mouse_pre_draw_x != mouse_cur_x || mouse_pre_draw_y != mouse_cur_y;
var _1stp = brush.brush_dist_min == brush.brush_dist_max && brush.brush_dist_min == 1;
if(_move || !_1stp) {
surface_set_shader(drawing_surface, noone, false, BLEND.alpha);
if(_1stp) canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y, true);
canvas_draw_line_size(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y, true);
surface_reset_shader();
}
mouse_pre_draw_x = mouse_cur_x;
mouse_pre_draw_y = mouse_cur_y;
if(mouse_release(mb_left)) {
mouse_holding = false;
apply_draw_surface();
}
}
BLEND_NORMAL;
mouse_pre_x = mouse_cur_x;
mouse_pre_y = mouse_cur_y;
}
function drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
if(isEraser) draw_set_color(c_white);
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_press(SHIFT))
canvas_draw_line_size(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
else
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,90 @@
// 2024-04-14 10:03:44
function canvas_tool_brush(brush, eraser = false) : canvas_tool() constructor {
self.brush = brush;
isEraser = eraser;
brush_resizable = true;
mouse_cur_x = 0;
mouse_cur_y = 0;
mouse_pre_x = 0;
mouse_pre_y = 0;
mouse_pre_draw_x = undefined;
mouse_pre_draw_y = undefined;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
print(brush.brush_surface);
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_press(SHIFT) && key_mod_press(CTRL)) {
var aa = point_direction(mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
var dd = point_distance(mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
var _a = round(aa / 45) * 45;
dd = dd * cos(degtorad(_a - aa));
mouse_cur_x = mouse_pre_draw_x + lengthdir_x(dd, _a);
mouse_cur_y = mouse_pre_draw_y + lengthdir_y(dd, _a);
}
if(mouse_press(mb_left, active)) {
brush_next_dist = 0;
surface_set_shader(drawing_surface, noone);
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y, true);
surface_reset_shader();
mouse_holding = true;
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_press(SHIFT)) { ///////////////// shift line
surface_set_shader(drawing_surface, noone, true, BLEND.alpha);
brush_next_dist = 0;
canvas_draw_line_size(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y, true);
surface_reset_shader();
mouse_holding = false;
apply_draw_surface();
}
node.tool_pick_color(mouse_cur_x, mouse_cur_y);
mouse_pre_draw_x = mouse_cur_x;
mouse_pre_draw_y = mouse_cur_y;
}
if(mouse_holding) {
var _move = mouse_pre_draw_x != mouse_cur_x || mouse_pre_draw_y != mouse_cur_y;
var _1stp = brush.brush_dist_min == brush.brush_dist_max && brush.brush_dist_min == 1;
if(_move || !_1stp) {
surface_set_shader(drawing_surface, noone, false, BLEND.alpha);
if(_1stp) canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y, true);
canvas_draw_line_size(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y, true);
surface_reset_shader();
}
mouse_pre_draw_x = mouse_cur_x;
mouse_pre_draw_y = mouse_cur_y;
if(mouse_release(mb_left)) {
mouse_holding = false;
apply_draw_surface();
}
}
BLEND_NORMAL;
mouse_pre_x = mouse_cur_x;
mouse_pre_y = mouse_cur_y;
}
function drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
if(isEraser) draw_set_color(c_white);
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_press(SHIFT))
canvas_draw_line_size(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
else
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,4 @@
// 2024-04-14 12:31:27
function canvas_tool_curve() : canvas_tool() constructor {
}

View file

@ -0,0 +1,4 @@
// 2024-04-14 12:31:12
function canvas_tool_curve() : canvas_tool() constructor {
}

View file

@ -0,0 +1,135 @@
// 2024-04-14 12:22:33
function canvas_tool_node(canvas, node) : canvas_tool() constructor {
self.canvas = canvas;
self.node = node;
override = true;
applySelection = canvas.tool_selection.is_selected;
destiSurface = applySelection? canvas.tool_selection.selection_surface : canvas.getCanvasSurface();
if(!is_surface(destiSurface)) {
canvas.nodeTool = noone;
return;
}
sw = surface_get_width(destiSurface);
sh = surface_get_height(destiSurface);
targetSurface = surface_create(sw, sh);
maskedSurface = surface_create(sw, sh);
surface_set_shader(targetSurface, noone);
draw_surface_safe(destiSurface);
surface_reset_shader();
static destroy = function() {
noti_warning("Selected node has no surface output.");
if(applySelection) canvas.tool_selection.apply();
canvas.nodeTool = noone;
surface_free(targetSurface);
surface_free(maskedSurface);
}
nodeObject = node.build(0, 0);
if(nodeObject == noone || !is_instanceof(nodeObject, Node)) {
destroy();
return;
}
inputJunction = noone;
outputJunction = noone;
for( var i = 0, n = ds_list_size(nodeObject.inputs); i < n; i++ ) {
var _in = nodeObject.inputs[| i];
if(_in.type == VALUE_TYPE.surface || _in.name == "Dimension") {
inputJunction = _in;
break;
}
}
for( var i = 0, n = ds_list_size(nodeObject.outputs); i < n; i++ ) {
var _in = nodeObject.outputs[| i];
if(_in.type == VALUE_TYPE.surface) {
outputJunction = _in;
break;
}
}
if(outputJunction == noone) {
destroy();
return;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function apply() {
if(applySelection) {
surface_free(canvas.tool_selection.selection_surface);
canvas.tool_selection.selection_surface = maskedSurface;
canvas.tool_selection.apply();
} else {
canvas.storeAction();
canvas.setCanvasSurface(maskedSurface);
canvas.surface_store_buffer();
}
PANEL_PREVIEW.tool_current = noone;
canvas.nodeTool = noone;
surface_free_safe(targetSurface);
}
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _px, _py, _pw, _ph;
if(applySelection) {
_px = canvas.tool_selection.selection_position[0];
_py = canvas.tool_selection.selection_position[1];
_pw = canvas.tool_selection.selection_size[0];
_ph = canvas.tool_selection.selection_size[1];
} else {
_px = 0;
_py = 0;
_pw = canvas.attributes.dimension[0];
_ph = canvas.attributes.dimension[1];
}
var _dx = _x + _px * _s;
var _dy = _y + _py * _s;
if(inputJunction) {
if(inputJunction.type == VALUE_TYPE.surface)
inputJunction.setValue(targetSurface);
else if(inputJunction.name == "Dimension")
inputJunction.setValue([ sw, sh ]);
}
nodeObject.update();
var _surf = outputJunction.getValue();
if(applySelection) {
maskedSurface = surface_verify(maskedSurface, sw, sh);
surface_set_shader(maskedSurface);
draw_surface(_surf, 0, 0);
BLEND_MULTIPLY
draw_surface(canvas.tool_selection.selection_mask, 0, 0);
BLEND_NORMAL
surface_reset_shader();
} else
maskedSurface = _surf;
draw_surface_ext_safe(maskedSurface, _dx, _dy, _s, _s);
if(mouse_press(mb_left, active)) { apply(); MOUSE_BLOCK = true; }
else if(mouse_press(mb_right, active)) { destroy(); MOUSE_BLOCK = true; }
}
}

View file

@ -0,0 +1,135 @@
// 2024-04-14 12:22:32
function canvas_tool_node(canvas, node) : canvas_tool() constructor {
self.canvas = canvas;
self.node = node;
override = true;
applySelection = canvas.tool_selection.is_selected;
destiSurface = applySelection? canvas.tool_selection.selection_surface : canvas.getCanvasSurface();
if(!is_surface(destiSurface)) {
canvas.nodeTool = noone;
return;
}
sw = surface_get_width(destiSurface);
sh = surface_get_height(destiSurface);
targetSurface = surface_create(sw, sh);
maskedSurface = surface_create(sw, sh);
surface_set_shader(targetSurface, noone);
draw_surface_safe(destiSurface);
surface_reset_shader();
static destroy = function() {
noti_warning("Selected node has no surface output.");
if(applySelection) canvas.tool_selection.apply();
canvas.nodeTool = noone;
surface_free(targetSurface);
surface_free(maskedSurface);
}
nodeObject = node.build(0, 0);
if(nodeObject == noone || !is_instanceof(nodeObject, Node)) {
destroy();
return;
}
inputJunction = noone;
outputJunction = noone;
for( var i = 0, n = ds_list_size(nodeObject.inputs); i < n; i++ ) {
var _in = nodeObject.inputs[| i];
if(_in.type == VALUE_TYPE.surface || _in.name == "Dimension") {
inputJunction = _in;
break;
}
}
for( var i = 0, n = ds_list_size(nodeObject.outputs); i < n; i++ ) {
var _in = nodeObject.outputs[| i];
if(_in.type == VALUE_TYPE.surface) {
outputJunction = _in;
break;
}
}
if(outputJunction == noone) {
destroy();
return;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function apply() {
if(applySelection) {
surface_free(canvas.tool_selection.selection_surface);
canvas.tool_selection.selection_surface = maskedSurface;
canvas.tool_selection.apply();
} else {
canvas.storeAction();
canvas.setCanvasSurface(maskedSurface);
canvas.surface_store_buffer();
}
PANEL_PREVIEW.tool_current = noone;
canvas.nodeTool = noone;
surface_free_safe(targetSurface);
}
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _px, _py, _pw, _ph;
if(applySelection) {
_px = canvas.tool_selection.selection_position[0];
_py = canvas.tool_selection.selection_position[1];
_pw = canvas.tool_selection.selection_size[0];
_ph = canvas.tool_selection.selection_size[1];
} else {
_px = 0;
_py = 0;
_pw = canvas.attributes.dimension[0];
_ph = canvas.attributes.dimension[1];
}
var _dx = _x + _px * _s;
var _dy = _y + _py * _s;
if(inputJunction) {
if(inputJunction.type == VALUE_TYPE.surface)
inputJunction.setValue(targetSurface);
else if(inputJunction.name == "Dimension")
inputJunction.setValue([ sw, sh ]);
}
nodeObject.update();
var _surf = outputJunction.getValue();
if(applySelection) {
maskedSurface = surface_verify(maskedSurface, sw, sh);
surface_set_shader(maskedSurface);
draw_surface(_surf, 0, 0);
BLEND_MULTIPLY
draw_surface(canvas.tool_selection.selection_mask, 0, 0);
BLEND_NORMAL
surface_reset_shader();
} else
maskedSurface = _surf;
draw_surface_ext_safe(maskedSurface, _dx, _dy, _s, _s);
if(mouse_press(mb_left, active)) { apply(); MOUSE_BLOCK = true; }
else if(mouse_press(mb_right, active)) { destroy(); MOUSE_BLOCK = true; }
}
}

View file

@ -0,0 +1,134 @@
// 2024-04-14 12:31:10
function canvas_tool_resize() : canvas_tool() constructor {
override = true;
dragging = -1;
drag_mx = 0;
drag_my = 0;
drag_sw = 0;
drag_sh = 0;
drag_display = [ 0, 0, 0, 0 ];
__hover_anim = array_create(4);
overlay_surface = noone;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _sw = node.attributes.dimension[0];
var _sh = node.attributes.dimension[1];
var x0, y0, x1, y1;
if(dragging >= 0) {
x0 = _x + drag_display[0] * _s;
y0 = _y + drag_display[1] * _s;
x1 = _x + drag_display[2] * _s;
y1 = _y + drag_display[3] * _s;
} else {
x0 = _x;
y0 = _y;
x1 = _x + _sw * _s;
y1 = _y + _sh * _s;
}
var _r = 10;
var _sr = surface_get_target();
var _srw = surface_get_width(_sr);
var _srh = surface_get_height(_sr);
overlay_surface = surface_verify(overlay_surface, _srw, _srh);
surface_set_target(overlay_surface);
draw_clear_alpha(0, 0.3);
BLEND_SUBTRACT
draw_set_color(c_white);
draw_rectangle(x0, y0, x1, y1, false);
BLEND_NORMAL
surface_reset_target();
draw_surface(overlay_surface, 0, 0);
draw_set_color(c_black);
draw_rectangle(x0, y0, x1, y1, true);
draw_set_color(c_white);
draw_rectangle_dashed(x0, y0, x1, y1, true, 6, current_time / 100);
var _hovering = -1;
if(point_in_circle(_mx, _my, x0, y0, _r)) _hovering = 0;
else if(point_in_circle(_mx, _my, x1, y0, _r)) _hovering = 1;
else if(point_in_circle(_mx, _my, x0, y1, _r)) _hovering = 2;
else if(point_in_circle(_mx, _my, x1, y1, _r)) _hovering = 3;
for( var i = 0; i < 4; i++ ) __hover_anim[i] = lerp_float(__hover_anim[i], i == _hovering, 4);
draw_anchor(__hover_anim[0], x0, y0, _r);
draw_anchor(__hover_anim[1], x1, y0, _r);
draw_anchor(__hover_anim[2], x0, y1, _r);
draw_anchor(__hover_anim[3], x1, y1, _r);
if(dragging >= 0) {
var _dx = (_mx - drag_mx) / _s;
var _dy = (_my - drag_my) / _s;
var _sw = drag_sw;
var _sh = drag_sh;
if(key_mod_press(SHIFT)) _dy = _dx * (drag_sh / drag_sw);
switch(dragging) {
case 0 : drag_display = [ round(_dx), round(_dy), _sw, _sh ]; break;
case 1 : drag_display = [ 0, round(_dy), _sw + round(_dx), _sh ]; break;
case 2 : drag_display = [ round(_dx), 0, _sw, _sh + round(_dy) ]; break;
case 3 : drag_display = [ 0, 0, _sw + round(_dx), _sh + round(_dy) ]; break;
}
if(mouse_release(mb_left)) {
dragging = -1;
var _sw = drag_display[2] - drag_display[0];
var _sh = drag_display[3] - drag_display[1];
if(_sw > 0 && _sh > 0) {
node.storeAction();
node.attributes.dimension = [ _sw, _sh ];
for( var i = 0; i < node.attributes.frames; i++ ) {
var _canvas_surface = node.getCanvasSurface(i);
var _cbuff = array_safe_get_fast(node.canvas_buffer, i);
if(buffer_exists(_cbuff)) buffer_delete(_cbuff);
node.canvas_buffer[i] = buffer_create(_sw * _sh * 4, buffer_fixed, 4);
var _newCanvas = surface_create(_sw, _sh);
surface_set_shader(_newCanvas, noone);
draw_surface(_canvas_surface, -drag_display[0], -drag_display[1]);
surface_reset_shader();
node.setCanvasSurface(_newCanvas, i);
surface_free(_canvas_surface);
}
node.inputs[| 0].setValue([_sw, _sh]);
}
}
} else if(_hovering >= 0 && mouse_click(mb_left, active)) {
dragging = _hovering;
drag_mx = _mx;
drag_my = _my;
drag_sw = _sw;
drag_sh = _sh;
drag_display = [ 0, 0, _sw, _sh ];
}
}
}

View file

@ -0,0 +1,134 @@
// 2024-04-14 12:30:55
function canvas_tool_resize() : canvas_tool() constructor {
override = true;
dragging = -1;
drag_mx = 0;
drag_my = 0;
drag_sw = 0;
drag_sh = 0;
drag_display = [ 0, 0, 0, 0 ];
__hover_anim = array_create(4);
overlay_surface = noone;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _sw = node.attributes.dimension[0];
var _sh = node.attributes.dimension[1];
var x0, y0, x1, y1;
if(dragging >= 0) {
x0 = _x + drag_display[0] * _s;
y0 = _y + drag_display[1] * _s;
x1 = _x + drag_display[2] * _s;
y1 = _y + drag_display[3] * _s;
} else {
x0 = _x;
y0 = _y;
x1 = _x + _sw * _s;
y1 = _y + _sh * _s;
}
var _r = 10;
var _sr = surface_get_target();
var _srw = surface_get_width(_sr);
var _srh = surface_get_height(_sr);
overlay_surface = surface_verify(overlay_surface, _srw, _srh);
surface_set_target(overlay_surface);
draw_clear_alpha(0, 0.3);
BLEND_SUBTRACT
draw_set_color(c_white);
draw_rectangle(x0, y0, x1, y1, false);
BLEND_NORMAL
surface_reset_target();
draw_surface(overlay_surface, 0, 0);
draw_set_color(c_black);
draw_rectangle(x0, y0, x1, y1, true);
draw_set_color(c_white);
draw_rectangle_dashed(x0, y0, x1, y1, true, 6, current_time / 100);
var _hovering = -1;
if(point_in_circle(_mx, _my, x0, y0, _r)) _hovering = 0;
else if(point_in_circle(_mx, _my, x1, y0, _r)) _hovering = 1;
else if(point_in_circle(_mx, _my, x0, y1, _r)) _hovering = 2;
else if(point_in_circle(_mx, _my, x1, y1, _r)) _hovering = 3;
for( var i = 0; i < 4; i++ ) __hover_anim[i] = lerp_float(__hover_anim[i], i == _hovering, 4);
draw_anchor(__hover_anim[0], x0, y0, _r);
draw_anchor(__hover_anim[1], x1, y0, _r);
draw_anchor(__hover_anim[2], x0, y1, _r);
draw_anchor(__hover_anim[3], x1, y1, _r);
if(dragging >= 0) {
var _dx = (_mx - drag_mx) / _s;
var _dy = (_my - drag_my) / _s;
var _sw = drag_sw;
var _sh = drag_sh;
if(key_mod_press(SHIFT)) _dy = _dx * (drag_sh / drag_sw);
switch(dragging) {
case 0 : drag_display = [ round(_dx), round(_dy), _sw, _sh ]; break;
case 1 : drag_display = [ 0, round(_dy), _sw + round(_dx), _sh ]; break;
case 2 : drag_display = [ round(_dx), 0, _sw, _sh + round(_dy) ]; break;
case 3 : drag_display = [ 0, 0, _sw + round(_dx), _sh + round(_dy) ]; break;
}
if(mouse_release(mb_left)) {
dragging = -1;
var _sw = drag_display[2] - drag_display[0];
var _sh = drag_display[3] - drag_display[1];
if(_sw > 0 && _sh > 0) {
node.storeAction();
node.attributes.dimension = [ _sw, _sh ];
for( var i = 0; i < node.attributes.frames; i++ ) {
var _canvas_surface = node.getCanvasSurface(i);
var _cbuff = array_safe_get_fast(node.canvas_buffer, i);
if(buffer_exists(_cbuff)) buffer_delete(_cbuff);
node.canvas_buffer[i] = buffer_create(_sw * _sh * 4, buffer_fixed, 4);
var _newCanvas = surface_create(_sw, _sh);
surface_set_shader(_newCanvas, noone);
draw_surface(_canvas_surface, -drag_display[0], -drag_display[1]);
surface_reset_shader();
node.setCanvasSurface(_newCanvas, i);
surface_free(_canvas_surface);
}
node.inputs[| 0].setValue([_sw, _sh]);
}
}
} else if(_hovering >= 0 && mouse_click(mb_left, active)) {
dragging = _hovering;
drag_mx = _mx;
drag_my = _my;
drag_sw = _sw;
drag_sh = _sh;
drag_display = [ 0, 0, _sw, _sh ];
}
}
}

View file

@ -0,0 +1,339 @@
// 2024-04-14 11:51:21
function canvas_tool_selection(selector = noone) : canvas_tool() constructor {
self.selector = selector;
selection_surface = surface_create_empty(1, 1);
selection_mask = surface_create_empty(1, 1);
selection_position = [ 0, 0 ];
selection_size = [ 0, 0 ];
is_selecting = false;
is_selected = false;
is_select_drag = false;
selection_sx = 0;
selection_sy = 0;
selection_mx = 0;
selection_my = 0;
mouse_cur_x = 0;
mouse_cur_y = 0;
mouse_pre_x = 0;
mouse_pre_y = 0;
function createSelection(_mask, sel_x0, sel_y0, sel_w, sel_h) { #region
if(is_selected)
apply();
if(key_mod_press(SHIFT))
modifySelection(_mask, sel_x0, sel_y0, sel_w, sel_h, true);
else if(key_mod_press(ALT))
modifySelection(_mask, sel_x0, sel_y0, sel_w, sel_h, false);
else
createNewSelection(_mask, sel_x0, sel_y0, sel_w, sel_h);
} #endregion
function modifySelection(_mask, sel_x0, sel_y0, sel_w, sel_h, _add) { #region
if(sel_w == 1 && sel_h == 1) return;
var _x0, _y0, _x1, _y1;
if(_add) {
_x0 = min(sel_x0, selection_position[0]);
_y0 = min(sel_y0, selection_position[1]);
_x1 = max(sel_x0 + sel_w, selection_position[0] + selection_size[0]);
_y1 = max(sel_y0 + sel_h, selection_position[1] + selection_size[1]);
} else {
var __nx0 = sel_x0;
var __ny0 = sel_y0;
var __nx1 = sel_x0 + sel_w;
var __ny1 = sel_y0 + sel_h;
_x0 = selection_position[0];
_y0 = selection_position[1];
_x1 = selection_position[0] + selection_size[0];
_y1 = selection_position[1] + selection_size[1];
if(__nx0 <= _x0 && __nx1 >= _x1) {
if(__ny0 <= _y0) _y0 = max(_y0, __ny1);
if(__ny1 >= _y1) _y1 = min(_y1, __ny0);
}
if(__ny0 <= _y0 && __ny1 >= _y1) {
if(__nx0 <= _x0) _x0 = max(_x0, __nx1);
if(__nx1 >= _x1) _x1 = min(_x1, __nx0);
}
}
if(_x1 - _x0 <= 0 || _y1 - _y0 <= 0) return;
var _ox = selection_position[0] - _x0;
var _oy = selection_position[1] - _y0;
var _nx = sel_x0 - _x0;
var _ny = sel_y0 - _y0;
var _nw = _x1 - _x0;
var _nh = _y1 - _y0;
var _selection_surface = surface_create(_nw, _nh);
var _selection_mask = surface_create(_nw, _nh);
surface_set_target(_selection_mask);
DRAW_CLEAR
BLEND_OVERRIDE
draw_surface_safe(selection_mask, _ox, _oy);
if(_add) BLEND_ADD
else BLEND_SUBTRACT
draw_surface_safe(_mask, _nx, _ny);
BLEND_NORMAL
surface_reset_target();
surface_set_target(_selection_surface);
DRAW_CLEAR
draw_surface_safe(_canvas_surface, -_x0, -_y0);
BLEND_MULTIPLY
draw_surface_safe(_selection_mask, 0, 0);
BLEND_NORMAL
surface_reset_target();
surface_free(selection_surface);
surface_free(selection_mask);
selection_surface = _selection_surface;
selection_mask = _selection_mask;
node.storeAction();
surface_set_target(_canvas_surface);
gpu_set_blendmode(bm_subtract);
draw_surface_safe(selection_surface, _x0, _y0);
gpu_set_blendmode(bm_normal);
surface_reset_target();
node.surface_store_buffer();
selection_position = [ _x0, _y0 ];
selection_size = [ _nw, _nh ];
is_selected = true;
} #endregion
function createNewSelection(_mask, sel_x0, sel_y0, sel_w, sel_h) { #region
if(sel_w == 1 && sel_h == 1) return;
selection_surface = surface_verify(selection_surface, sel_w, sel_h);
selection_mask = surface_verify(selection_mask, sel_w, sel_h);
surface_set_target(selection_surface);
DRAW_CLEAR
draw_surface_safe(_canvas_surface, -sel_x0, -sel_y0);
BLEND_MULTIPLY
draw_surface_safe(_mask, 0, 0);
BLEND_NORMAL
surface_reset_target();
surface_set_target(selection_mask);
DRAW_CLEAR
draw_surface_safe(_mask, 0, 0);
surface_reset_target();
node.storeAction();
surface_set_target(_canvas_surface);
gpu_set_blendmode(bm_subtract);
draw_surface_safe(selection_surface, sel_x0, sel_y0);
gpu_set_blendmode(bm_normal);
surface_reset_target();
node.surface_store_buffer();
selection_position = [ sel_x0, sel_y0 ];
selection_size = [ sel_w, sel_h ];
is_selected = true;
} #endregion
function copySelection() { #region
var s = surface_encode(selection_surface);
clipboard_set_text(s);
} #endregion
function apply() { #region
var _drawLay = node.tool_attribute.drawLayer;
var _sw = surface_get_width(_canvas_surface);
var _sh = surface_get_height(_canvas_surface);
var _selectionSurf = surface_create(_sw, _sh);
var _drawnSurface = surface_create(_sw, _sh);
surface_set_shader(_selectionSurf, noone);
draw_surface(selection_surface, selection_position[0], selection_position[1]);
surface_reset_shader();
surface_set_shader(_drawnSurface, sh_canvas_apply_draw);
shader_set_i("drawLayer", _drawLay);
shader_set_i("eraser", 0);
shader_set_f("channels", node.tool_attribute.channel);
shader_set_f("alpha", 1);
shader_set_surface("back", _canvas_surface);
shader_set_surface("fore", _selectionSurf);
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _sw, _sh);
surface_reset_shader();
node.setCanvasSurface(_drawnSurface);
surface_free(_canvas_surface);
_canvas_surface = _drawnSurface;
node.surface_store_buffer();
is_selected = false;
} #endregion
function onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
if(!is_surface(selection_surface)) {
is_selected = false;
return;
}
if(is_select_drag) {
var px = selection_sx + (mouse_cur_x - selection_mx);
var py = selection_sy + (mouse_cur_y - selection_my);
selection_position[0] = px;
selection_position[1] = py;
if(mouse_release(mb_left))
is_select_drag = false;
}
if(mouse_press(mb_left, active)) {
var pos_x = selection_position[0];
var pos_y = selection_position[1];
var sel_w = surface_get_width_safe(selection_surface);
var sel_h = surface_get_height_safe(selection_surface);
if(point_in_rectangle(mouse_cur_x, mouse_cur_y, pos_x, pos_y, pos_x + sel_w, pos_y + sel_h) && surface_get_pixel_ext(selection_mask, mouse_cur_x, mouse_cur_y)) {
is_select_drag = true;
selection_sx = pos_x;
selection_sy = pos_y;
selection_mx = mouse_cur_x;
selection_my = mouse_cur_y;
}
}
if(key_press(vk_delete)) {
is_selected = false;
surface_free(selection_surface);
}
if(key_press(ord("C"), MOD_KEY.ctrl)) copySelection();
} #endregion
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(is_selected) { onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); return; }
else if(is_surface(selection_surface)) { apply(); }
} #endregion
function onDrawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {}
function drawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
var sel_x0, sel_y0;
if(is_selecting) {
sel_x0 = min(selection_sx, mouse_cur_x);
sel_y0 = min(selection_sy, mouse_cur_y);
} else {
sel_x0 = selection_position[0];
sel_y0 = selection_position[1];
}
var _dx = _x + sel_x0 * _s;
var _dy = _y + sel_y0 * _s;
draw_surface_ext_safe(selection_mask, _dx, _dy, _s, _s);
onDrawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
} #endregion
function drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
if(!is_selected) return;
var pos_x = _x + selection_position[0] * _s;
var pos_y = _y + selection_position[1] * _s;
var sel_w = surface_get_width_safe(selection_surface) * _s;
var sel_h = surface_get_height_safe(selection_surface) * _s;
draw_surface_ext_safe(selection_surface, pos_x, pos_y, _s, _s, 0, c_white, 1);
draw_set_color(c_black);
draw_rectangle(pos_x, pos_y, pos_x + sel_w, pos_y + sel_h, true);
draw_set_color(c_white);
draw_rectangle_dashed(pos_x, pos_y, pos_x + sel_w, pos_y + sel_h, true, 6, current_time / 100);
} #endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function rotate90cw() { #region
var _sw = surface_get_width(selection_surface);
var _sh = surface_get_height(selection_surface);
var _newS = surface_create(_sh, _sw);
surface_set_shader(_newS, noone);
draw_surface_ext(selection_surface, _sh, 0, 1, 1, -90, c_white, 1);
surface_reset_shader();
surface_free(selection_surface);
selection_surface = _newS;
} #endregion
function rotate90ccw() { #region
var _sw = surface_get_width(selection_surface);
var _sh = surface_get_height(selection_surface);
var _newS = surface_create(_sh, _sw);
surface_set_shader(_newS, noone);
draw_surface_ext(selection_surface, 0, _sw, 1, 1, 90, c_white, 1);
surface_reset_shader();
surface_free(selection_surface);
selection_surface = _newS;
} #endregion
function flipH() { #region
var _sw = surface_get_width(selection_surface);
var _sh = surface_get_height(selection_surface);
var _newS = surface_create(_sw, _sh);
surface_set_shader(_newS, noone);
draw_surface_ext(selection_surface, _sw, 0, -1, 1, 0, c_white, 1);
surface_reset_shader();
surface_free(selection_surface);
selection_surface = _newS;
} #endregion
function flipV() { #region
var _sw = surface_get_width(selection_surface);
var _sh = surface_get_height(selection_surface);
var _newS = surface_create(_sw, _sh);
surface_set_shader(_newS, noone);
draw_surface_ext(selection_surface, 0, _sh, 1, -1, 0, c_white, 1);
surface_reset_shader();
surface_free(selection_surface);
selection_surface = _newS;
} #endregion
}

View file

@ -0,0 +1,339 @@
// 2024-04-14 11:51:18
function canvas_tool_selection(selector = noone) : canvas_tool() constructor {
self.selector = selector;
selection_surface = surface_create_empty(1, 1);
selection_mask = surface_create_empty(1, 1);
selection_position = [ 0, 0 ];
selection_size = [ 0, 0 ];
is_selecting = false;
is_selected = false;
is_select_drag = false;
selection_sx = 0;
selection_sy = 0;
selection_mx = 0;
selection_my = 0;
mouse_cur_x = 0;
mouse_cur_y = 0;
mouse_pre_x = 0;
mouse_pre_y = 0;
function createSelection(_mask, sel_x0, sel_y0, sel_w, sel_h) { #region
if(is_selected)
apply();
if(key_mod_press(SHIFT))
modifySelection(_mask, sel_x0, sel_y0, sel_w, sel_h, true);
else if(key_mod_press(ALT))
modifySelection(_mask, sel_x0, sel_y0, sel_w, sel_h, false);
else
createNewSelection(_mask, sel_x0, sel_y0, sel_w, sel_h);
} #endregion
function modifySelection(_mask, sel_x0, sel_y0, sel_w, sel_h, _add) { #region
if(sel_w == 1 && sel_h == 1) return;
var _x0, _y0, _x1, _y1;
if(_add) {
_x0 = min(sel_x0, selection_position[0]);
_y0 = min(sel_y0, selection_position[1]);
_x1 = max(sel_x0 + sel_w, selection_position[0] + selection_size[0]);
_y1 = max(sel_y0 + sel_h, selection_position[1] + selection_size[1]);
} else {
var __nx0 = sel_x0;
var __ny0 = sel_y0;
var __nx1 = sel_x0 + sel_w;
var __ny1 = sel_y0 + sel_h;
_x0 = selection_position[0];
_y0 = selection_position[1];
_x1 = selection_position[0] + selection_size[0];
_y1 = selection_position[1] + selection_size[1];
if(__nx0 <= _x0 && __nx1 >= _x1) {
if(__ny0 <= _y0) _y0 = max(_y0, __ny1);
if(__ny1 >= _y1) _y1 = min(_y1, __ny0);
}
if(__ny0 <= _y0 && __ny1 >= _y1) {
if(__nx0 <= _x0) _x0 = max(_x0, __nx1);
if(__nx1 >= _x1) _x1 = min(_x1, __nx0);
}
}
if(_x1 - _x0 <= 0 || _y1 - _y0 <= 0) return;
var _ox = selection_position[0] - _x0;
var _oy = selection_position[1] - _y0;
var _nx = sel_x0 - _x0;
var _ny = sel_y0 - _y0;
var _nw = _x1 - _x0;
var _nh = _y1 - _y0;
var _selection_surface = surface_create(_nw, _nh);
var _selection_mask = surface_create(_nw, _nh);
surface_set_target(_selection_mask);
DRAW_CLEAR
BLEND_OVERRIDE
draw_surface_safe(selection_mask, _ox, _oy);
if(_add) BLEND_ADD
else BLEND_SUBTRACT
draw_surface_safe(_mask, _nx, _ny);
BLEND_NORMAL
surface_reset_target();
surface_set_target(_selection_surface);
DRAW_CLEAR
draw_surface_safe(_canvas_surface, -_x0, -_y0);
BLEND_MULTIPLY
draw_surface_safe(_selection_mask, 0, 0);
BLEND_NORMAL
surface_reset_target();
surface_free(selection_surface);
surface_free(selection_mask);
selection_surface = _selection_surface;
selection_mask = _selection_mask;
node.storeAction();
surface_set_target(_canvas_surface);
gpu_set_blendmode(bm_subtract);
draw_surface_safe(selection_surface, _x0, _y0);
gpu_set_blendmode(bm_normal);
surface_reset_target();
node.surface_store_buffer();
selection_position = [ _x0, _y0 ];
selection_size = [ _nw, _nh ];
is_selected = true;
} #endregion
function createNewSelection(_mask, sel_x0, sel_y0, sel_w, sel_h) { #region
if(sel_w == 1 && sel_h == 1) return;
selection_surface = surface_verify(selection_surface, sel_w, sel_h);
selection_mask = surface_verify(selection_mask, sel_w, sel_h);
surface_set_target(selection_surface);
DRAW_CLEAR
draw_surface_safe(_canvas_surface, -sel_x0, -sel_y0);
BLEND_MULTIPLY
draw_surface_safe(_mask, 0, 0);
BLEND_NORMAL
surface_reset_target();
surface_set_target(selection_mask);
DRAW_CLEAR
draw_surface_safe(_mask, 0, 0);
surface_reset_target();
node.storeAction();
surface_set_target(_canvas_surface);
gpu_set_blendmode(bm_subtract);
draw_surface_safe(selection_surface, sel_x0, sel_y0);
gpu_set_blendmode(bm_normal);
surface_reset_target();
node.surface_store_buffer();
selection_position = [ sel_x0, sel_y0 ];
selection_size = [ sel_w, sel_h ];
is_selected = true;
} #endregion
function copySelection() { #region
var s = surface_encode(selection_surface);
clipboard_set_text(s);
} #endregion
function apply() { #region
var _drawLay = node.tool_attribute.drawLayer;
var _sw = surface_get_width(_canvas_surface);
var _sh = surface_get_height(_canvas_surface);
var _selectionSurf = surface_create(_sw, _sh);
var _drawnSurface = surface_create(_sw, _sh);
surface_set_shader(_selectionSurf, noone);
draw_surface(selection_surface, selection_position[0], selection_position[1]);
surface_reset_shader();
surface_set_shader(_drawnSurface, sh_canvas_apply_draw);
shader_set_i("drawLayer", _drawLay);
shader_set_i("eraser", 0);
shader_set_f("channels", node.tool_attribute.channel);
shader_set_f("alpha", 1);
shader_set_surface("back", _canvas_surface);
shader_set_surface("fore", _selectionSurf);
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _sw, _sh);
surface_reset_shader();
node.setCanvasSurface(_drawnSurface);
surface_free(_canvas_surface);
_canvas_surface = _drawnSurface;
node.surface_store_buffer();
is_selected = false;
} #endregion
function onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
if(!is_surface(selection_surface)) {
is_selected = false;
return;
}
if(is_select_drag) {
var px = selection_sx + (mouse_cur_x - selection_mx);
var py = selection_sy + (mouse_cur_y - selection_my);
selection_position[0] = px;
selection_position[1] = py;
if(mouse_release(mb_left))
is_select_drag = false;
}
if(mouse_press(mb_left, active)) {
var pos_x = selection_position[0];
var pos_y = selection_position[1];
var sel_w = surface_get_width_safe(selection_surface);
var sel_h = surface_get_height_safe(selection_surface);
if(point_in_rectangle(mouse_cur_x, mouse_cur_y, pos_x, pos_y, pos_x + sel_w, pos_y + sel_h) && surface_get_pixel_ext(selection_mask, mouse_cur_x, mouse_cur_y)) {
is_select_drag = true;
selection_sx = pos_x;
selection_sy = pos_y;
selection_mx = mouse_cur_x;
selection_my = mouse_cur_y;
}
}
if(key_press(vk_delete)) {
is_selected = false;
surface_free(selection_surface);
}
if(key_press(ord("C"), MOD_KEY.ctrl)) copySelection();
} #endregion
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(is_selected) { onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); return; }
else if(is_surface(selection_surface)) { apply(); }
} #endregion
function onDrawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {}
function drawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
var sel_x0, sel_y0;
if(is_selecting) {
sel_x0 = min(selection_sx, mouse_cur_x);
sel_y0 = min(selection_sy, mouse_cur_y);
} else {
sel_x0 = selection_position[0];
sel_y0 = selection_position[1];
}
var _dx = _x + sel_x0 * _s;
var _dy = _y + sel_y0 * _s;
draw_surface_ext_safe(selection_mask, _dx, _dy, _s, _s);
onDrawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
} #endregion
function drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
if(!is_selected) return;
var pos_x = _x + selection_position[0] * _s;
var pos_y = _y + selection_position[1] * _s;
var sel_w = surface_get_width_safe(selection_surface) * _s;
var sel_h = surface_get_height_safe(selection_surface) * _s;
draw_surface_ext_safe(selection_surface, pos_x, pos_y, _s, _s, 0, c_white, 1);
draw_set_color(c_black);
draw_rectangle(pos_x, pos_y, pos_x + sel_w, pos_y + sel_h, true);
draw_set_color(c_white);
draw_rectangle_dashed(pos_x, pos_y, pos_x + sel_w, pos_y + sel_h, true, 6, current_time / 100);
} #endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function rotate90cw() { #region
var _sw = surface_get_width(selection_surface);
var _sh = surface_get_height(selection_surface);
var _newS = surface_create(_sh, _sw);
surface_set_shader(_newS, noone);
draw_surface_ext(selection_surface, _sh, 0, 1, 1, -90, c_white, 1);
surface_reset_shader();
surface_free(selection_surface);
selection_surface = _newS;
} #endregion
function rotate90ccw() { #region
var _sw = surface_get_width(selection_surface);
var _sh = surface_get_height(selection_surface);
var _newS = surface_create(_sh, _sw);
surface_set_shader(_newS, noone);
draw_surface_ext(selection_surface, 0, _sw, 1, 1, 90, c_white, 1);
surface_reset_shader();
surface_free(selection_surface);
selection_surface = _newS;
} #endregion
function flipH() { #region
var _sw = surface_get_width(selection_surface);
var _sh = surface_get_height(selection_surface);
var _newS = surface_create(_sw, _sh);
surface_set_shader(_newS, noone);
draw_surface_ext(selection_surface, _sw, 0, -1, 1, 0, c_white, 1);
surface_reset_shader();
surface_free(selection_surface);
selection_surface = _newS;
} #endregion
function flipV() { #region
var _sw = surface_get_width(selection_surface);
var _sh = surface_get_height(selection_surface);
var _newS = surface_create(_sw, _sh);
surface_set_shader(_newS, noone);
draw_surface_ext(selection_surface, 0, _sh, 1, -1, 0, c_white, 1);
surface_reset_shader();
surface_free(selection_surface);
selection_surface = _newS;
} #endregion
}

View file

@ -0,0 +1,92 @@
// 2024-04-14 12:16:19
function canvas_tool_selection_brush(selector, brush) : canvas_tool_selection(selector) constructor {
self.brush = brush;
brush_resizable = true;
mouse_cur_x = 0;
mouse_cur_y = 0;
mouse_pre_x = 0;
mouse_pre_y = 0;
mouse_pre_draw_x = undefined;
mouse_pre_draw_y = undefined;
sel_x0 = 0;
sel_y0 = 0;
sel_x1 = 0;
sel_y1 = 0;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
attributes = node.attributes;
var _dim = attributes.dimension;
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(!selector.is_select_drag && mouse_press(mb_left, active)) {
selection_mask = surface_verify(selection_mask, _dim[0], _dim[1]);
surface_set_shader(selection_mask, noone);
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y, true);
surface_reset_shader();
is_selecting = true;
mouse_pre_draw_x = mouse_cur_x;
mouse_pre_draw_y = mouse_cur_y;
sel_x0 = mouse_cur_x - brush.brush_size;
sel_y0 = mouse_cur_y - brush.brush_size;
sel_x1 = mouse_cur_x + brush.brush_size;
sel_y1 = mouse_cur_y + brush.brush_size;
}
if(is_selecting) {
var _move = mouse_pre_draw_x != mouse_cur_x || mouse_pre_draw_y != mouse_cur_y;
var _1stp = brush.brush_dist_min == brush.brush_dist_max && brush.brush_dist_min == 1;
if(_move || !_1stp) {
surface_set_target(selection_mask);
BLEND_ADD
if(_1stp) canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y, true);
canvas_draw_line_size(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y, true);
BLEND_NORMAL
surface_reset_target();
}
mouse_pre_draw_x = mouse_cur_x;
mouse_pre_draw_y = mouse_cur_y;
sel_x0 = min(sel_x0, mouse_cur_x - brush.brush_size);
sel_y0 = min(sel_y0, mouse_cur_y - brush.brush_size);
sel_x1 = max(sel_x1, mouse_cur_x + brush.brush_size);
sel_y1 = max(sel_y1, mouse_cur_y + brush.brush_size);
if(mouse_release(mb_left)) {
var _sel_w = sel_x1 - sel_x0;
var _sel_h = sel_y1 - sel_y0;
var _sel = surface_create(_sel_w, _sel_h);
surface_set_shader(_sel);
draw_surface(selection_mask, -sel_x0, -sel_y0);
surface_reset_shader();
is_selecting = false;
selector.createSelection(_sel, sel_x0, sel_y0, _sel_w, _sel_h);
surface_free_safe(selection_mask);
}
}
BLEND_NORMAL;
mouse_pre_x = mouse_cur_x;
mouse_pre_y = mouse_cur_y;
}
function drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,92 @@
// 2024-04-14 12:16:16
function canvas_tool_selection_brush(selector, brush) : canvas_tool_selection(selector) constructor {
self.brush = brush;
brush_resizable = true;
mouse_cur_x = 0;
mouse_cur_y = 0;
mouse_pre_x = 0;
mouse_pre_y = 0;
mouse_pre_draw_x = undefined;
mouse_pre_draw_y = undefined;
sel_x0 = 0;
sel_y0 = 0;
sel_x1 = 0;
sel_y1 = 0;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
attributes = node.attributes;
var _dim = attributes.dimension;
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(!selector.is_select_drag && mouse_press(mb_left, active)) {
selection_mask = surface_verify(selection_mask, _dim[0], _dim[1]);
surface_set_shader(selection_mask, noone);
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y, true);
surface_reset_shader();
is_selecting = true;
mouse_pre_draw_x = mouse_cur_x;
mouse_pre_draw_y = mouse_cur_y;
sel_x0 = mouse_cur_x - brush.brush_size;
sel_y0 = mouse_cur_y - brush.brush_size;
sel_x1 = mouse_cur_x + brush.brush_size;
sel_y1 = mouse_cur_y + brush.brush_size;
}
if(is_selecting) {
var _move = mouse_pre_draw_x != mouse_cur_x || mouse_pre_draw_y != mouse_cur_y;
var _1stp = brush.brush_dist_min == brush.brush_dist_max && brush.brush_dist_min == 1;
if(_move || !_1stp) {
surface_set_target(selection_mask);
BLEND_ADD
if(_1stp) canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y, true);
canvas_draw_line_size(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y, true);
BLEND_NORMAL
surface_reset_target();
}
mouse_pre_draw_x = mouse_cur_x;
mouse_pre_draw_y = mouse_cur_y;
sel_x0 = min(sel_x0, mouse_cur_x - brush.brush_size);
sel_y0 = min(sel_y0, mouse_cur_y - brush.brush_size);
sel_x1 = max(sel_x1, mouse_cur_x + brush.brush_size);
sel_y1 = max(sel_y1, mouse_cur_y + brush.brush_size);
if(mouse_release(mb_left)) {
var _sel_w = sel_x1 - sel_x0;
var _sel_h = sel_y1 - sel_y0;
var _sel = surface_create(_sel_w, _sel_h);
surface_set_shader(_sel);
draw_surface(selection_mask, -sel_x0, -sel_y0);
surface_reset_shader();
is_selecting = false;
selector.createSelection(_sel, sel_x0, sel_y0, _sel_w, _sel_h);
surface_free_safe(selection_mask);
}
}
BLEND_NORMAL;
mouse_pre_x = mouse_cur_x;
mouse_pre_y = mouse_cur_y;
}
function drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,93 @@
// 2024-04-14 12:16:16
function canvas_tool_selection_freeform(selector, brush) : canvas_tool_selection(selector) constructor {
self.brush = brush;
mouse_pre_x = 0;
mouse_pre_y = 0;
freeform_shape = [];
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
attributes = node.attributes;
var _dim = attributes.dimension;
if(is_selected) { onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); return; }
if(!selector.is_select_drag && mouse_press(mb_left, active)) {
is_selecting = true;
selection_sx = mouse_cur_x;
selection_sy = mouse_cur_y;
surface_free_safe(selection_mask);
}
if(is_selecting) {
var sel_x0, sel_y0, sel_x1, sel_y1;
var sel_w = 1, sel_h = 1;
draw_set_color(c_white);
canvas_freeform_step(active, _x, _y, _s, _mx, _my, false);
if(mouse_release(mb_left)) {
is_selecting = false;
sel_x0 = _dim[0];
sel_y0 = _dim[1];
sel_x1 = 0;
sel_y1 = 0;
for( var i = 0, n = array_length(freeform_shape); i < n; i++ ) {
var _f = freeform_shape[i];
sel_x0 = min(sel_x0, round(_f.x - 0.5));
sel_y0 = min(sel_y0, round(_f.y - 0.5));
sel_x1 = max(sel_x1, round(_f.x - 0.5));
sel_y1 = max(sel_y1, round(_f.y - 0.5));
}
sel_w = sel_x1 - sel_x0 + 1;
sel_h = sel_y1 - sel_y0 + 1;
if(sel_w > 1 && sel_h > 1) {
selection_mask = surface_verify(selection_mask, sel_w, sel_h);
surface_set_target(selection_mask);
DRAW_CLEAR
draw_surface(drawing_surface, -sel_x0, -sel_y0);
surface_reset_target();
}
surface_clear(drawing_surface);
selector.createSelection(selection_mask, sel_x0, sel_y0, sel_w, sel_h);
surface_free_safe(selection_mask);
}
}
}
function drawPostOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
if(!is_selecting) return;
var ox, oy, nx, ny;
draw_set_color(c_white);
for( var i = 0, n = array_length(freeform_shape); i < n; i++ ) {
nx = _x + freeform_shape[i].x * _s;
ny = _y + freeform_shape[i].y * _s;
if(i) draw_line(ox, oy, nx, ny);
ox = nx;
oy = ny;
}
}
function drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,93 @@
// 2024-04-14 12:14:09
function canvas_tool_selection_freeform(selector, brush) : canvas_tool_selection(selector) constructor {
self.brush = brush;
mouse_pre_x = 0;
mouse_pre_y = 0;
freeform_shape = [];
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
attributes = node.attributes;
var _dim = attributes.dimension;
if(is_selected) { onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); return; }
if(!selector.is_select_drag && mouse_press(mb_left, active)) {
is_selecting = true;
selection_sx = mouse_cur_x;
selection_sy = mouse_cur_y;
surface_free_safe(selection_mask);
}
if(is_selecting) {
var sel_x0, sel_y0, sel_x1, sel_y1;
var sel_w = 1, sel_h = 1;
draw_set_color(c_white);
canvas_freeform_step(active, _x, _y, _s, _mx, _my, false);
if(mouse_release(mb_left)) {
is_selecting = false;
sel_x0 = _dim[0];
sel_y0 = _dim[1];
sel_x1 = 0;
sel_y1 = 0;
for( var i = 0, n = array_length(freeform_shape); i < n; i++ ) {
var _f = freeform_shape[i];
sel_x0 = min(sel_x0, round(_f.x - 0.5));
sel_y0 = min(sel_y0, round(_f.y - 0.5));
sel_x1 = max(sel_x1, round(_f.x - 0.5));
sel_y1 = max(sel_y1, round(_f.y - 0.5));
}
sel_w = sel_x1 - sel_x0 + 1;
sel_h = sel_y1 - sel_y0 + 1;
if(sel_w > 1 && sel_h > 1) {
selection_mask = surface_verify(selection_mask, sel_w, sel_h);
surface_set_target(selection_mask);
DRAW_CLEAR
draw_surface(drawing_surface, -sel_x0, -sel_y0);
surface_reset_target();
}
surface_clear(drawing_surface);
selector.createSelection(selection_mask, sel_x0, sel_y0, sel_w, sel_h);
surface_free_safe(selection_mask);
}
}
}
function drawPostOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
if(!is_selecting) return;
var ox, oy, nx, ny;
draw_set_color(c_white);
for( var i = 0, n = array_length(freeform_shape); i < n; i++ ) {
nx = _x + freeform_shape[i].x * _s;
ny = _y + freeform_shape[i].y * _s;
if(i) draw_line(ox, oy, nx, ny);
ox = nx;
oy = ny;
}
}
function onDrawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,64 @@
// 2024-04-14 12:16:16
function canvas_tool_selection_magic(selector, toolAttr) : canvas_tool_selection(selector) constructor {
self.tool_attribute = toolAttr;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(is_selected) { onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); return; }
var _thr = tool_attribute.thres;
var _fill_type = tool_attribute.fill8;
if(!selector.is_select_drag && mouse_press(mb_left, active)) {
canvas_buffer = node.canvas_buffer;
preview_index = node.preview_index;
surface_w = surface_get_width(_canvas_surface);
surface_h = surface_get_height(_canvas_surface);
if(point_in_rectangle(mouse_cur_x, mouse_cur_y, 0, 0, surface_w - 1, surface_h - 1)) {
var bb = [ 0, 0, surface_w, surface_h ];
var _temp_surface = surface_create(surface_w, surface_h);
draw_set_color(c_white);
surface_set_target(_temp_surface);
DRAW_CLEAR
switch(_fill_type) {
case 0 : bb = canvas_magic_selection_scanline(_canvas_surface, mouse_cur_x, mouse_cur_y, _thr, false); break;
case 1 : bb = canvas_magic_selection_scanline(_canvas_surface, mouse_cur_x, mouse_cur_y, _thr, true); break;
}
surface_reset_target();
var sel_x0 = bb[0];
var sel_y0 = bb[1];
var sel_x1 = bb[2];
var sel_y1 = bb[3];
var sel_w = 1, sel_h = 1;
sel_w = sel_x1 - sel_x0 + 1;
sel_h = sel_y1 - sel_y0 + 1;
selection_mask = surface_verify(selection_mask, sel_w, sel_h);
surface_set_target(selection_mask);
DRAW_CLEAR
draw_surface(_temp_surface, -sel_x0, -sel_y0);
surface_reset_target();
surface_free(_temp_surface);
selector.createSelection(selection_mask, sel_x0, sel_y0, sel_w, sel_h);
surface_free_safe(selection_mask);
}
}
}
function drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,64 @@
// 2024-04-14 12:14:14
function canvas_tool_selection_magic(selector, toolAttr) : canvas_tool_selection(selector) constructor {
self.tool_attribute = toolAttr;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(is_selected) { onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); return; }
var _thr = tool_attribute.thres;
var _fill_type = tool_attribute.fill8;
if(!selector.is_select_drag && mouse_press(mb_left, active)) {
canvas_buffer = node.canvas_buffer;
preview_index = node.preview_index;
surface_w = surface_get_width(_canvas_surface);
surface_h = surface_get_height(_canvas_surface);
if(point_in_rectangle(mouse_cur_x, mouse_cur_y, 0, 0, surface_w - 1, surface_h - 1)) {
var bb = [ 0, 0, surface_w, surface_h ];
var _temp_surface = surface_create(surface_w, surface_h);
draw_set_color(c_white);
surface_set_target(_temp_surface);
DRAW_CLEAR
switch(_fill_type) {
case 0 : bb = canvas_magic_selection_scanline(_canvas_surface, mouse_cur_x, mouse_cur_y, _thr, false); break;
case 1 : bb = canvas_magic_selection_scanline(_canvas_surface, mouse_cur_x, mouse_cur_y, _thr, true); break;
}
surface_reset_target();
var sel_x0 = bb[0];
var sel_y0 = bb[1];
var sel_x1 = bb[2];
var sel_y1 = bb[3];
var sel_w = 1, sel_h = 1;
sel_w = sel_x1 - sel_x0 + 1;
sel_h = sel_y1 - sel_y0 + 1;
selection_mask = surface_verify(selection_mask, sel_w, sel_h);
surface_set_target(selection_mask);
DRAW_CLEAR
draw_surface(_temp_surface, -sel_x0, -sel_y0);
surface_reset_target();
surface_free(_temp_surface);
selector.createSelection(selection_mask, sel_x0, sel_y0, sel_w, sel_h);
surface_free_safe(selection_mask);
}
}
}
function onDrawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,58 @@
// 2024-04-14 12:16:16
function canvas_tool_selection_shape(selector, shape) : canvas_tool_selection(selector) constructor {
self.shape = shape;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(is_selected) { onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); return; }
if(is_selecting) {
var sel_x0, sel_y0, sel_x1, sel_y1;
var sel_w = 1, sel_h = 1;
sel_x0 = min(selection_sx, mouse_cur_x);
sel_y0 = min(selection_sy, mouse_cur_y);
sel_x1 = max(selection_sx, mouse_cur_x);
sel_y1 = max(selection_sy, mouse_cur_y);
sel_w = sel_x1 - sel_x0 + 1;
sel_h = sel_y1 - sel_y0 + 1;
selection_mask = surface_verify(selection_mask, sel_w, sel_h);
surface_set_target(selection_mask);
DRAW_CLEAR
draw_set_color(c_white);
if(shape == CANVAS_TOOL_SHAPE.rectangle)
draw_rectangle(0, 0, sel_w, sel_h, false);
else if(shape == CANVAS_TOOL_SHAPE.ellipse) {
draw_set_circle_precision(32);
draw_ellipse(0, 0, sel_w - 1, sel_h - 1, false);
}
surface_reset_target();
if(mouse_release(mb_left)) {
is_selecting = false;
selector.createSelection(selection_mask, sel_x0, sel_y0, sel_w, sel_h);
surface_free_safe(selection_mask);
}
} else if(!selector.is_select_drag && mouse_press(mb_left, active)) {
is_selecting = true;
selection_sx = mouse_cur_x;
selection_sy = mouse_cur_y;
surface_free_safe(selection_mask);
}
}
function drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,58 @@
// 2024-04-14 12:15:58
function canvas_tool_selection_shape(selector, shape) : canvas_tool_selection(selector) constructor {
self.shape = shape;
function step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
mouse_cur_x = round((_mx - _x) / _s - 0.5);
mouse_cur_y = round((_my - _y) / _s - 0.5);
if(is_selected) { onSelected(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); return; }
if(is_selecting) {
var sel_x0, sel_y0, sel_x1, sel_y1;
var sel_w = 1, sel_h = 1;
sel_x0 = min(selection_sx, mouse_cur_x);
sel_y0 = min(selection_sy, mouse_cur_y);
sel_x1 = max(selection_sx, mouse_cur_x);
sel_y1 = max(selection_sy, mouse_cur_y);
sel_w = sel_x1 - sel_x0 + 1;
sel_h = sel_y1 - sel_y0 + 1;
selection_mask = surface_verify(selection_mask, sel_w, sel_h);
surface_set_target(selection_mask);
DRAW_CLEAR
draw_set_color(c_white);
if(shape == CANVAS_TOOL_SHAPE.rectangle)
draw_rectangle(0, 0, sel_w, sel_h, false);
else if(shape == CANVAS_TOOL_SHAPE.ellipse) {
draw_set_circle_precision(32);
draw_ellipse(0, 0, sel_w - 1, sel_h - 1, false);
}
surface_reset_target();
if(mouse_release(mb_left)) {
is_selecting = false;
selector.createSelection(selection_mask, sel_x0, sel_y0, sel_w, sel_h);
surface_free_safe(selection_mask);
}
} else if(!selector.is_select_drag && mouse_press(mb_left, active)) {
is_selecting = true;
selection_sx = mouse_cur_x;
selection_sy = mouse_cur_y;
surface_free_safe(selection_mask);
}
}
function drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
canvas_draw_point_size(brush, mouse_cur_x, mouse_cur_y);
}
}

View file

@ -0,0 +1,948 @@
// 2024-04-14 12:32:26
function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Canvas";
color = COLORS.node_blend_canvas;
inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF )
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 1] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white );
inputs[| 2] = nodeValue("Brush size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1 )
.setDisplay(VALUE_DISPLAY.slider, { range: [1, 32, 0.1] });
inputs[| 3] = nodeValue("Fill threshold", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.)
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 4] = nodeValue("Fill type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, ["4 connect", "8 connect", "Entire canvas"]);
inputs[| 5] = nodeValue("Draw preview overlay", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 6] = nodeValue("Brush", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone)
.setVisible(true, false);
inputs[| 7] = nodeValue("Surface amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1);
inputs[| 8] = nodeValue("Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, -1);
inputs[| 9] = nodeValue("Background alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1.)
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 10] = nodeValue("Render background", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 11] = nodeValue("Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 )
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 12] = nodeValue("Frames animation", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );
inputs[| 13] = nodeValue("Animation speed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 );
inputs[| 14] = nodeValue("Use background dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true );
inputs[| 15] = nodeValue("Brush distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ] )
.setDisplay(VALUE_DISPLAY.range, { linked : true });
inputs[| 16] = nodeValue("Rotate brush by direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );
inputs[| 17] = nodeValue("Random direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0, 0, 0 ] )
.setDisplay(VALUE_DISPLAY.rotation_random);
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
frame_renderer_x = 0;
frame_renderer_x_to = 0;
frame_renderer_x_max = 0;
frame_renderer_content = surface_create(1, 1);
frame_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region
var _h = 64;
_y += 8;
var _cnt_hover = false;
draw_sprite_stretched(THEME.button_def, 0, _x, _y, _w, _h);
if(_hover && frame_renderer.parent != noone && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h)) {
frame_renderer.parent.scroll_lock = true;
_cnt_hover = _hover;
}
var _ww = _w - 4 - 40;
var _hh = _h - 4 - 4;
var _x0 = _x + 4;
var _y0 = _y + 4;
var _x1 = _x0 + _ww;
var _y1 = _y0 + _hh;
draw_sprite_stretched(THEME.ui_panel_bg, 1, _x0, _y0, _ww, _hh);
frame_renderer_x_max = 0;
frame_renderer_content = surface_verify(frame_renderer_content, _ww, _hh);
surface_set_shader(frame_renderer_content);
var _msx = _m[0] - _x0;
var _msy = _m[1] - _y0;
var _fr_h = _hh - 8;
var _fr_w = _fr_h;
var _fr_x = 8 - frame_renderer_x;
var _fr_y = 4;
var surfs = output_surface;
var _del = noone;
for( var i = 0, n = attributes.frames; i < n; i++ ) {
var _surf = surfs[i];
if(!is_surface(_surf)) continue;
var _sw = surface_get_width(_surf);
var _sh = surface_get_height(_surf);
var _ss = min(_fr_w / _sw, _fr_h / _sh);
var _sx = _fr_x;
var _sy = _fr_y + _fr_h / 2 - _sh * _ss / 2;
draw_surface_ext(_surf, _sx, _sy, _ss, _ss, 0, c_white, 0.75);
draw_set_color(i == preview_index? COLORS._main_accent : COLORS.panel_toolbar_outline);
draw_rectangle(_sx, _sy, _sx + _sw * _ss, _sy + _sh * _ss, true);
var _del_x = _sx + _sw * _ss - 8;
var _del_y = _sy + 8;
var _del_a = 0;
if(_hover) {
if(point_in_circle(_msx, _msy, _del_x, _del_y, 8)) {
_del_a = 1;
if(mouse_press(mb_left, _focus))
_del = i;
} else if(point_in_rectangle(_msx, _msy, _sx, _sy, _sx + _sw * _ss, _sy + _sh * _ss)) {
if(mouse_press(mb_left, _focus)) preview_index = i;
}
}
draw_sprite(THEME.close_16, _del_a, _del_x, _del_y);
_fr_x += _sw * _ss + 8;
frame_renderer_x_max += _sw * _ss + 8;
}
if(_del > noone) removeFrame(_del);
surface_reset_shader();
draw_surface(frame_renderer_content, _x0, _y0);
frame_renderer_x_max = max(0, frame_renderer_x_max - 200);
frame_renderer_x = lerp_float(frame_renderer_x, frame_renderer_x_to, 3);
if(_cnt_hover) {
if(mouse_wheel_down()) frame_renderer_x_to = clamp(frame_renderer_x_to + 80, 0, frame_renderer_x_max);
if(mouse_wheel_up()) frame_renderer_x_to = clamp(frame_renderer_x_to - 80, 0, frame_renderer_x_max);
}
var _bs = 32;
var _bx = _x1 + ui(20) - _bs / 2;
var _by = _y + _h / 2 - _bs / 2;
if(buttonInstant(THEME.button_hide, _bx, _by, _bs, _bs, _m, _focus, _hover,, THEME.add,, COLORS._main_value_positive) == 2) {
attributes.frames++;
refreshFrames();
update();
}
return 8 + _h;
}); #endregion
temp_surface = array_create(1);
input_display_list = [
["Output", false], 0, frame_renderer, 12, 13,
["Brush", true], 6, 15, 17, 16,
["Background", true, 10], 8, 14, 9,
];
#region ++++ data ++++
attributes.frames = 1;
attribute_surface_depth();
attributes.dimension = [ 1, 1 ];
output_surface = [ surface_create_empty(1, 1) ];
canvas_surface = [ surface_create_empty(1, 1) ];
canvas_buffer = [ buffer_create(1 * 1 * 4, buffer_fixed, 2) ];
drawing_surface = surface_create_empty(1, 1);
_drawing_surface = surface_create_empty(1, 1);
surface_w = 1;
surface_h = 1;
prev_surface = surface_create_empty(1, 1);
preview_draw_surface = surface_create_empty(1, 1);
preview_draw_mask = surface_create_empty(1, 1);
draw_stack = ds_list_create();
brush = new canvas_brush();
#endregion
#region ++++ tools ++++
tool_attribute.color = cola(c_white);
tool_attribute.channel = [ true, true, true, true ];
tool_channel_edit = new checkBoxGroup(THEME.tools_canvas_channel, function(ind, val) { tool_attribute.channel[ind] = val; });
tool_attribute.drawLayer = 0;
tool_attribute.pickColor = c_white;
tool_drawLayer_edit = new buttonGroup( [ THEME.canvas_draw_layer, THEME.canvas_draw_layer, THEME.canvas_draw_layer ], function(val) { tool_attribute.drawLayer = val; });
tool_attribute.mirror = [ false, false ];
tool_mirror_edit = new checkBoxGroup( THEME.canvas_mirror, function(ind, val) { tool_attribute.mirror[ind] = val; });
tool_settings = [ [ "", tool_channel_edit, "channel", tool_attribute ],
[ "", tool_drawLayer_edit, "drawLayer", tool_attribute ],
[ "", tool_mirror_edit, "mirror", tool_attribute ],
];
tool_attribute.size = 1;
tool_size_edit = new textBox(TEXTBOX_INPUT.number, function(val) { tool_attribute.size = max(1, round(val)); }).setSlidable(0.1, true, [ 1, 999999 ])
.setFont(f_p3)
.setSideButton(button(function() { dialogPanelCall(new Panel_Node_Canvas_Pressure(self), mouse_mx, mouse_my, { anchor: ANCHOR.top | ANCHOR.left }) })
.setIcon(THEME.pen_pressure, 0, COLORS._main_icon));
tool_size = [ "Size", tool_size_edit, "size", tool_attribute ];
tool_attribute.pressure = false;
tool_attribute.pressure_size = [ 1, 1 ];
tool_attribute.thres = 0;
tool_thrs_edit = new textBox(TEXTBOX_INPUT.number, function(val) { tool_attribute.thres = clamp(val, 0, 1); }).setSlidable(0.01, false, [ 0, 1 ]).setFont(f_p3);
tool_thrs = [ "Threshold", tool_thrs_edit, "thres", tool_attribute ];
tool_attribute.fill8 = false;
tool_fil8_edit = new checkBox(function() { tool_attribute.fill8 = !tool_attribute.fill8; });
tool_fil8 = [ "Diagonal", tool_fil8_edit, "fill8", tool_attribute ];
tools = [
new NodeTool( "Selection", [ THEME.canvas_tools_selection_rectangle, THEME.canvas_tools_selection_circle, THEME.canvas_tools_freeform_selection, THEME.canvas_tools_selection_brush ]),
new NodeTool( "Magic Selection", THEME.canvas_tools_magic_selection )
.setSetting(tool_thrs)
.setSetting(tool_fil8),
new NodeTool( "Pencil", THEME.canvas_tools_pencil)
.setSetting(tool_size),
new NodeTool( "Eraser", THEME.canvas_tools_eraser)
.setSetting(tool_size),
new NodeTool( "Rectangle", [ THEME.canvas_tools_rect, THEME.canvas_tools_rect_fill ])
.setSetting(tool_size),
new NodeTool( "Ellipse", [ THEME.canvas_tools_ellip, THEME.canvas_tools_ellip_fill ])
.setSetting(tool_size),
new NodeTool( "Freeform", THEME.canvas_tools_freeform)
.setSetting(tool_size),
new NodeTool( "Fill", THEME.canvas_tools_bucket)
.setSetting(tool_thrs)
.setSetting(tool_fil8),
];
tool_selection = new canvas_tool_selection();
tool_brush = new canvas_tool_brush(brush, false);
tool_eraser = new canvas_tool_brush(brush, true);
tool_rectangle = new canvas_tool_shape(brush, CANVAS_TOOL_SHAPE.rectangle);
tool_ellipse = new canvas_tool_shape(brush, CANVAS_TOOL_SHAPE.ellipse);
tool_fill = new canvas_tool_fill(tool_attribute);
tool_freeform = new canvas_tool_draw_freeform(brush);
tool_sel_rectangle = new canvas_tool_selection_shape(tool_selection, CANVAS_TOOL_SHAPE.rectangle);
tool_sel_ellipse = new canvas_tool_selection_shape(tool_selection, CANVAS_TOOL_SHAPE.ellipse);
tool_sel_freeform = new canvas_tool_selection_freeform(tool_selection, brush);
tool_sel_magic = new canvas_tool_selection_magic(tool_selection, tool_attribute);
tool_sel_brush = new canvas_tool_selection_brush(tool_selection, brush);
#endregion
#region ++++ right tools ++++
__action_rotate_90_cw = method(self, function() { if(tool_selection.is_selected) tool_selection.rotate90cw() else canvas_action_rotate(-90); });
__action_rotate_90_ccw = method(self, function() { if(tool_selection.is_selected) tool_selection.rotate90ccw() else canvas_action_rotate( 90); });
__action_flip_h = method(self, function() { if(tool_selection.is_selected) tool_selection.flipH() else canvas_action_flip(1); });
__action_flip_v = method(self, function() { if(tool_selection.is_selected) tool_selection.flipV() else canvas_action_flip(0); });
__action_add_node = method(self, function(ctx) { dialogCall(o_dialog_add_node, mouse_mx + 8, mouse_my + 8, { context: ctx }); });
__action_make_brush = method(self, function() {
if(brush.brush_use_surface) {
brush.brush_surface = noone;
brush.brush_use_surface = false;
return;
}
var _surf = tool_selection.selection_surface;
var _bsurf = surface_create(surface_get_width(_surf) + 2, surface_get_height(_surf) + 2);
surface_set_target(_bsurf);
DRAW_CLEAR
draw_surface(_surf, 1, 1);
surface_reset_target();
brush.brush_use_surface = true;
brush.brush_surface = _bsurf;
tool_selection.apply();
PANEL_PREVIEW.tool_current = tools[2];
});
nodeTool = noone;
nodeToolPreview = new NodeTool( "Apply Node", THEME.canvas_tools_node, self ).setToolFn( __action_add_node );
rightTools_general = [
nodeToolPreview,
-1,
new NodeTool( "Resize Canvas", THEME.canvas_resize ).setToolObject( new canvas_tool_resize() ),
new NodeTool( [ "Rotate 90 CW", "Rotate 90 CCW" ],
[ THEME.canvas_rotate_cw, THEME.canvas_rotate_ccw ] )
.setToolFn( [ __action_rotate_90_cw, __action_rotate_90_ccw ] ),
new NodeTool( [ "Flip H", "Flip V" ],
[ THEME.canvas_flip_h, THEME.canvas_flip_v ] )
.setToolFn( [ __action_flip_h, __action_flip_v ] ),
];
rightTools_selection = [
-1,
new NodeTool( "Make/Reset Brush", THEME.canvas_tools_pencil ).setToolFn( __action_make_brush ),
-1,
new NodeTool( "Outline", THEME.canvas_tools_outline ).setToolObject( new canvas_tool_outline() ),
new NodeTool( [ "Extrude", "Inset" ],
[ THEME.canvas_tools_extrude, THEME.canvas_tools_inset ] )
.setToolObject( [ new canvas_tool_extrude(), new canvas_tool_inset() ] ),
];
rightTools_brush = [
-1,
new NodeTool( "Make/Reset Brush", THEME.canvas_tools_pencil ).setToolFn( __action_make_brush ),
];
rightTools = rightTools_general;
tool_brush.rightTools = rightTools_brush;
tool_eraser.rightTools = rightTools_brush;
tool_rectangle.rightTools = rightTools_brush;
tool_ellipse.rightTools = rightTools_brush;
#endregion
function setToolColor(color) { tool_attribute.color = color; }
function getToolColor() { return tool_attribute.color; }
static drawTools = function(_mx, _my, xx, yy, tool_size, hover, focus) { #region
var _sx0 = xx - tool_size / 2;
var _sx1 = xx + tool_size / 2;
var hh = ui(8);
yy += ui(4);
draw_set_color(COLORS._main_icon_dark);
draw_line_round(_sx0 + ui(8), yy, _sx1 - ui(8), yy, 2);
yy += ui(4);
var _cx = _sx0 + ui(8);
var _cw = tool_size - ui(16);
var _ch = ui(12);
var _pd = ui(5);
yy += ui(8);
hh += ui(8);
drawColor(tool_attribute.color, _cx, yy, _cw, _cw);
draw_sprite_stretched_ext(THEME.palette_selecting, 0, _cx - _pd, yy - _pd, _cw + _pd * 2, _cw + _pd * 2, c_white, 1);
if(point_in_rectangle(_mx, _my, _cx, yy, _cx + _cw, yy + _ch) && mouse_press(mb_left, focus))
colorSelectorCall(tool_attribute.color, setToolColor);
yy += _cw + ui(8);
hh += _cw + ui(8);
var _sel = noone;
for( var i = 0, n = array_length(DEF_PALETTE); i < n; i++ ) {
var _c = DEF_PALETTE[i];
var ii = 0;
if(i == 0) ii = 4;
if(i == n - 1) ii = 5;
draw_sprite_stretched_ext(THEME.palette_mask, ii, _cx, yy, _cw, _ch, _c, 1);
if(_c == tool_attribute.color)
_sel = [ _cx, yy ];
if(hover && point_in_rectangle(_mx, _my, _cx, yy, _cx + _cw, yy + _ch)) {
if(mouse_click(mb_left, focus))
tool_attribute.color = _c;
}
yy += _ch;
hh += _ch;
}
if(_sel != noone)
draw_sprite_stretched_ext(THEME.palette_selecting, 0, _sel[0] - _pd, _sel[1] - _pd, _cw + _pd * 2, _ch + _pd * 2, c_white, 1);
return hh + ui(4);
} #endregion
function removeFrame(index = 0) { #region
if(attributes.frames <= 1) return;
if(preview_index == attributes.frames)
preview_index--;
attributes.frames--;
array_delete(canvas_surface, index, 1);
array_delete(canvas_buffer, index, 1);
update();
} #endregion
function refreshFrames() { #region
var fr = attributes.frames;
var _dim = attributes.dimension;
if(array_length(canvas_surface) < fr) {
for( var i = array_length(canvas_surface); i < fr; i++ ) {
canvas_surface[i] = surface_create(_dim[0], _dim[1]);
surface_set_target(canvas_surface[i]);
DRAW_CLEAR
surface_reset_target();
}
} else
array_resize(canvas_surface, fr);
if(array_length(canvas_buffer) < fr) {
for( var i = array_length(canvas_buffer); i < fr; i++ ) {
canvas_buffer[i] = buffer_create(1 * 1 * 4, buffer_fixed, 2);
}
} else
array_resize(canvas_buffer, fr);
} #endregion
function getCanvasSurface(index = preview_index) { INLINE return array_safe_get_fast(canvas_surface, index); }
function setCanvasSurface(surface, index = preview_index) { INLINE canvas_surface[index] = surface; }
function storeAction() { #region
var action = recordAction(ACTION_TYPE.custom, function(data) {
is_selected = false;
var _canvas = surface_clone(getCanvasSurface(data.index));
if(is_surface(data.surface))
setCanvasSurface(surface_clone(data.surface), data.index);
surface_store_buffer(data.index);
surface_free(data.surface);
data.surface = _canvas;
data.index = preview_index;
}, { surface: surface_clone(getCanvasSurface()), tooltip: "Modify canvas", index: preview_index });
action.clear_action = function(data) { surface_free_safe(data.surface); };
} #endregion
function apply_surfaces() { #region
for( var i = 0; i < attributes.frames; i++ )
apply_surface(i);
} #endregion
function apply_surface(index = preview_index) { #region
var _dim = attributes.dimension;
var cDep = attrDepth();
var _canvas_surface = getCanvasSurface(index);
if(!is_surface(_canvas_surface)) { // recover surface from bufffer in case of VRAM refresh
setCanvasSurface(surface_create_from_buffer(_dim[0], _dim[1], canvas_buffer[index]), index);
} else if(surface_get_width_safe(_canvas_surface) != _dim[0] || surface_get_height_safe(_canvas_surface) != _dim[1]) { // resize surface
var _cbuff = array_safe_get_fast(canvas_buffer, index);
if(buffer_exists(_cbuff)) buffer_delete(_cbuff);
canvas_buffer[index] = buffer_create(_dim[0] * _dim[1] * 4, buffer_fixed, 4);
var _newCanvas = surface_create(_dim[0], _dim[1]);
surface_set_target(_newCanvas);
DRAW_CLEAR
draw_surface(_canvas_surface, 0, 0);
surface_reset_target();
setCanvasSurface(_newCanvas, index);
surface_free(_canvas_surface);
}
drawing_surface = surface_verify(drawing_surface, _dim[0], _dim[1], cDep);
surface_clear(drawing_surface);
} #endregion
function surface_store_buffers(index = preview_index) { #region
for( var i = 0; i < attributes.frames; i++ )
surface_store_buffer(i);
} #endregion
function surface_store_buffer(index = preview_index) { #region
if(index >= attributes.frames) return;
buffer_delete(canvas_buffer[index]);
var _canvas_surface = getCanvasSurface(index);
surface_w = surface_get_width_safe(_canvas_surface);
surface_h = surface_get_height_safe(_canvas_surface);
canvas_buffer[index] = buffer_create(surface_w * surface_h * 4, buffer_fixed, 4);
buffer_get_surface(canvas_buffer[index], _canvas_surface, 0);
triggerRender();
apply_surface(index);
} #endregion
function tool_pick_color(_x, _y) { #region
if(tool_selection.is_selected)
tool_attribute.pickColor = surface_get_pixel(tool_selection.selection_surface, _x - tool_selection.selection_position[0], _y - tool_selection.selection_position[1]);
else
tool_attribute.pickColor = surface_get_pixel(getCanvasSurface(), _x, _y);
} #endregion
function apply_draw_surface() { #region
var _can = getCanvasSurface();
var _drw = drawing_surface;
var _dim = attributes.dimension;
var _tmp;
storeAction();
if(tool_selection.is_selected) {
var _tmp = surface_create(surface_get_width(tool_selection.selection_mask), surface_get_height(tool_selection.selection_mask));
var _spx = tool_selection.selection_position[0];
var _spy = tool_selection.selection_position[1];
var _spw = tool_selection.selection_size[0];
var _sph = tool_selection.selection_size[1];
surface_set_target(_tmp);
DRAW_CLEAR
draw_surface(drawing_surface, -_spx, -_spy);
BLEND_ALPHA
if(tool_attribute.mirror[0]) draw_surface_ext_safe(drawing_surface, _spx * 2 + _spw - _spx, -_spy, -1, 1);
if(tool_attribute.mirror[1]) draw_surface_ext_safe(drawing_surface, -_spx, _spy * 2 + _sph - _spy, 1, -1);
if(tool_attribute.mirror[0] && tool_attribute.mirror[1]) draw_surface_ext_safe(drawing_surface, _spx * 2 + _spw - _spx, _spy * 2 + _sph - _spy, -1, -1);
BLEND_NORMAL
BLEND_MULTIPLY
draw_surface(tool_selection.selection_mask, 0, 0);
BLEND_NORMAL
surface_reset_target();
_can = tool_selection.selection_surface;
} else {
var _tmp = surface_create(_dim[0], _dim[1]);
surface_set_target(_tmp);
DRAW_CLEAR
BLEND_OVERRIDE
draw_surface(drawing_surface, 0, 0);
BLEND_ALPHA
if(tool_attribute.mirror[0]) draw_surface_ext_safe(drawing_surface, _dim[0], 0, -1, 1);
if(tool_attribute.mirror[1]) draw_surface_ext_safe(drawing_surface, 0, _dim[1], 1, -1);
if(tool_attribute.mirror[0] && tool_attribute.mirror[1]) draw_surface_ext_safe(drawing_surface, _dim[0], _dim[1], -1, -1);
BLEND_NORMAL
surface_reset_target();
}
var _sw = surface_get_width(_can);
var _sh = surface_get_height(_can);
var _drawnSurface = surface_create(_sw, _sh);
surface_set_shader(_drawnSurface, sh_canvas_apply_draw);
shader_set_i("drawLayer", tool_attribute.drawLayer);
shader_set_i("eraser", isUsingTool("Eraser"));
shader_set_f("channels", tool_attribute.channel);
shader_set_f("alpha", _color_get_alpha(tool_attribute.color));
shader_set_f("mirror", tool_attribute.mirror);
shader_set_color("pickColor", tool_attribute.pickColor);
shader_set_surface("back", _can);
shader_set_surface("fore", _tmp);
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _sw, _sh);
surface_reset_shader();
surface_free(_can);
surface_clear(drawing_surface);
surface_free(_tmp);
if(tool_selection.is_selected) {
tool_selection.selection_surface = _drawnSurface;
} else {
setCanvasSurface(_drawnSurface);
surface_store_buffer();
}
} #endregion
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
if(instance_exists(o_dialog_color_picker)) return;
COLORS_GLOBAL_GET = getToolColor;
COLORS_GLOBAL_SET = setToolColor;
brush.node = self;
brush.step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
if(!tool_selection.is_selected && active && key_mod_press(ALT)) { #region color selector
var dialog = instance_create(0, 0, o_dialog_color_picker);
dialog.onApply = setToolColor;
dialog.def_c = tool_attribute.color;
} #endregion
var _canvas_surface = getCanvasSurface();
if(!surface_exists(_canvas_surface)) return;
#region surfaces
var _dim = attributes.dimension;
_drawing_surface = surface_verify(_drawing_surface, _dim[0], _dim[1]);
drawing_surface = surface_verify( drawing_surface, _dim[0], _dim[1], attrDepth());
surface_set_target(_drawing_surface);
DRAW_CLEAR
draw_surface_safe(drawing_surface);
surface_reset_target();
var __s = surface_get_target();
var _sw = surface_get_width(__s);
var _sh = surface_get_height(__s);
prev_surface = surface_verify(prev_surface, _dim[0], _dim[1]);
preview_draw_surface = surface_verify(preview_draw_surface, _dim[0], _dim[1]);
preview_draw_mask = surface_verify(preview_draw_mask, _sw, _sh);
#endregion
#region tool
var _currTool = PANEL_PREVIEW.tool_current;
var _tool = noone;
rightTools = [];
array_append(rightTools, rightTools_general);
if(tool_selection.is_selected) array_append(rightTools, rightTools_selection);
if(nodeTool != noone)
_tool = nodeTool;
else if(_currTool != noone) {
_tool = _currTool.getToolObject();
switch(_currTool.getName()) {
case "Pencil" : _tool = tool_brush; break;
case "Eraser" : _tool = tool_eraser; break;
case "Fill" : _tool = tool_fill; break;
case "Freeform" : _tool = tool_freeform; break;
case "Rectangle" :
_tool = tool_rectangle;
_tool.fill = _currTool.selecting == 1;
break;
case "Ellipse" :
_tool = tool_ellipse;
_tool.fill = _currTool.selecting == 1;
break;
case "Selection" :
switch(_currTool.selecting) {
case 0 : _tool = tool_sel_rectangle; break;
case 1 : _tool = tool_sel_ellipse; break;
case 2 : _tool = tool_sel_freeform; break;
case 3 : _tool = tool_sel_brush; break;
}
break;
case "Magic Selection" : _tool = tool_sel_magic; break;
}
if(_tool) {
_tool.subtool = _currTool.selecting;
array_append(rightTools, _tool.rightTools);
}
tool_selection.node = self;
tool_selection.drawing_surface = drawing_surface;
tool_selection._canvas_surface = _canvas_surface;
tool_selection.apply_draw_surface = apply_draw_surface;
if(is_instanceof(_tool, canvas_tool_selection) && tool_selection.is_selected) tool_selection.step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
}
if(_tool && _tool.override) {
_tool.node = self;
_tool.step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
_tool.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_set_shader(preview_draw_surface, noone);
_tool.drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_reset_shader();
draw_surface_ext_safe(preview_draw_surface, _x, _y, _s);
surface_set_target(preview_draw_mask);
DRAW_CLEAR
_tool.drawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_reset_target();
shader_set(sh_brush_outline);
shader_set_f("dimension", _sw, _sh);
draw_surface_ext_safe(preview_draw_mask);
shader_reset();
_tool.drawPostOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
return;
}
#endregion
draw_set_color(tool_attribute.color);
if(_tool) { #region tool step
_tool.drawing_surface = drawing_surface;
_tool._canvas_surface = _canvas_surface;
_tool.apply_draw_surface = apply_draw_surface;
_tool.brush = brush;
_tool.node = self;
if(_tool.relative && tool_selection.is_selected) {
_tool._canvas_surface = tool_selection.selection_surface;
var _px = tool_selection.selection_position[0];
var _py = tool_selection.selection_position[1];
var _rx = _x + _px * _s;
var _ry = _y + _py * _s;
_tool.step(hover, active, _rx, _ry, _s, _mx, _my, _snx, _sny);
} else
_tool.step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
if(_tool.brush_resizable) {
if(hover && key_mod_press(CTRL)) {
if(mouse_wheel_down()) tool_attribute.size = max( 1, tool_attribute.size - 1);
if(mouse_wheel_up()) tool_attribute.size = min(64, tool_attribute.size + 1);
}
brush.sizing(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
}
} #endregion
draw_set_alpha(1);
#region preview
var _alp = _color_get_alpha(tool_attribute.color);
if(tool_selection.is_selected) tool_selection.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
if(_tool) _tool.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_set_shader(preview_draw_surface, noone,, BLEND.alpha);
draw_surface_safe(_drawing_surface, 0, 0);
if(tool_selection.is_selected) {
var _spx = tool_selection.selection_position[0];
var _spy = tool_selection.selection_position[1];
var _spw = tool_selection.selection_size[0];
var _sph = tool_selection.selection_size[1];
if(tool_attribute.mirror[0]) draw_surface_ext_safe(_drawing_surface, _spx * 2 + _spw, 0, -1, 1);
if(tool_attribute.mirror[1]) draw_surface_ext_safe(_drawing_surface, 0, _spy * 2 + _sph, 1, -1);
if(tool_attribute.mirror[0] && tool_attribute.mirror[1]) draw_surface_ext_safe(_drawing_surface, _spx * 2 + _spw, _spy * 2 + _sph, -1, -1);
} else {
if(tool_attribute.mirror[0]) draw_surface_ext_safe(_drawing_surface, _dim[0], 0, -1, 1);
if(tool_attribute.mirror[1]) draw_surface_ext_safe(_drawing_surface, 0, _dim[1], 1, -1);
if(tool_attribute.mirror[0] && tool_attribute.mirror[1]) draw_surface_ext_safe(_drawing_surface, _dim[0], _dim[1], -1, -1);
}
draw_set_color(tool_attribute.color);
if(brush.brush_sizing)
canvas_draw_point_size(brush, brush.brush_sizing_dx, brush.brush_sizing_dy);
else if(_tool)
_tool.drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_reset_shader();
draw_surface_ext_safe(preview_draw_surface, _x, _y, _s, _s, 0, isUsingTool("Eraser")? c_red : c_white, isUsingTool("Eraser")? 0.2 : _alp);
surface_set_target(preview_draw_mask);
DRAW_CLEAR
if(tool_selection.is_selected) tool_selection.drawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
if(_tool) _tool.drawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_reset_target();
shader_set(sh_brush_outline);
shader_set_f("dimension", _sw, _sh);
draw_surface_ext_safe(preview_draw_mask, 0, 0, 1, 1, 0, c_white, 1);
shader_reset();
if(_tool) _tool.drawPostOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
#endregion
var _x0 = _x;
var _y0 = _y;
var _x1 = _x0 + _dim[0] * _s;
var _y1 = _y0 + _dim[1] * _s;
draw_set_color(COLORS.panel_preview_surface_outline);
draw_rectangle(_x0, _y0, _x1 - 1, _y1 - 1, true);
draw_set_alpha(1);
previewing = 1;
if((_tool == noone || !_tool.mouse_holding) && key_press(ord("V"), MOD_KEY.ctrl)) { #region
var _str = json_try_parse(clipboard_get_text(), noone);
print(clipboard_get_text())
if(is_struct(_str) && struct_has(_str, "buffer")) {
var _surf = surface_decode(_str);
if(is_surface(_surf)) {
tool_selection.selection_surface = _surf;
tool_selection.is_selected = true;
tool_selection.selection_position = [ 0, 0 ];
}
}
} #endregion
} #endregion
static step = function() { #region
var fram = attributes.frames;
var brush = getInputData(6);
var anim = getInputData(12);
var anims = getInputData(13);
inputs[| 12].setVisible(fram > 1);
inputs[| 13].setVisible(fram > 1 && anim);
inputs[| 15].setVisible(is_surface(brush));
inputs[| 16].setVisible(is_surface(brush));
update_on_frame = fram > 1 && anim;
if(update_on_frame)
preview_index = safe_mod(CURRENT_FRAME * anims, fram);
} #endregion
static update = function(frame = CURRENT_FRAME) { #region
var _dim = getInputData(0);
var _bg = getInputData(8);
var _bga = getInputData(9);
var _bgr = getInputData(10);
var _anim = getInputData(12);
var _anims = getInputData(13);
var _bgDim = getInputData(14);
var cDep = attrDepth();
if(_bgDim && is_surface(_bg)) _dim = [ surface_get_width_safe(_bg), surface_get_height_safe(_bg) ];
attributes.dimension = _dim;
apply_surfaces();
var _frames = attributes.frames;
if(!is_array(output_surface)) output_surface = array_create(_frames);
else if(array_length(output_surface) != _frames)
array_resize(output_surface, _frames);
if(_frames == 1) {
var _canvas_surface = getCanvasSurface(0);
output_surface[0] = surface_verify(output_surface[0], _dim[0], _dim[1], cDep);
surface_set_shader(output_surface[0], noone,, BLEND.alpha);
if(_bgr && is_surface(_bg))
draw_surface_stretched_ext(_bg, 0, 0, _dim[0], _dim[1], c_white, _bga);
draw_surface_safe(_canvas_surface, 0, 0);
surface_reset_shader();
outputs[| 0].setValue(output_surface[0]);
} else {
for( var i = 0; i < _frames; i++ ) {
var _canvas_surface = getCanvasSurface(i);
output_surface[i] = surface_verify(output_surface[i], _dim[0], _dim[1], cDep);
surface_set_shader(output_surface[i], noone,, BLEND.alpha);
if(_bgr && is_surface(_bg))
draw_surface_stretched_ext(_bg, 0, 0, _dim[0], _dim[1], c_white, _bga);
draw_surface_safe(_canvas_surface, 0, 0);
surface_reset_shader();
}
if(_anim) {
var _fr_index = safe_mod(CURRENT_FRAME * _anims, _frames);
outputs[| 0].setValue(output_surface[_fr_index]);
} else
outputs[| 0].setValue(output_surface);
}
} #endregion
static getPreviewValues = function() { return nodeTool == noone || nodeTool.applySelection? output_surface : noone; }
static doSerialize = function(_map) { #region
surface_store_buffers();
var _buff = array_create(attributes.frames);
for( var i = 0; i < attributes.frames; i++ ) {
var comp = buffer_compress(canvas_buffer[i], 0, buffer_get_size(canvas_buffer[i]));
_buff[i] = buffer_base64_encode(comp, 0, buffer_get_size(comp));
}
_map.surfaces = _buff;
} #endregion
static doApplyDeserialize = function() { #region
var _dim = struct_has(attributes, "dimension")? attributes.dimension : getInputData(0);
if(!struct_has(load_map, "surfaces")) {
if(struct_has(load_map, "surface")) {
var buff = buffer_base64_decode(load_map.surface);
canvas_buffer[0] = buffer_decompress(buff);
canvas_surface[0] = surface_create_from_buffer(_dim[0], _dim[1], canvas_buffer[0]);
}
return;
}
canvas_buffer = array_create(array_length(load_map.surfaces));
canvas_surface = array_create(array_length(load_map.surfaces));
for( var i = 0, n = array_length(load_map.surfaces); i < n; i++ ) {
var buff = buffer_base64_decode(load_map.surfaces[i]);
canvas_buffer[i] = buffer_decompress(buff);
canvas_surface[i] = surface_create_from_buffer(_dim[0], _dim[1], canvas_buffer[i]);
}
apply_surfaces();
} #endregion
static onCleanUp = function() { #region
surface_array_free(canvas_surface);
} #endregion
}

View file

@ -0,0 +1,948 @@
// 2024-04-14 12:27:33
function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Canvas";
color = COLORS.node_blend_canvas;
inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF )
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 1] = nodeValue("Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white );
inputs[| 2] = nodeValue("Brush size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1 )
.setDisplay(VALUE_DISPLAY.slider, { range: [1, 32, 0.1] });
inputs[| 3] = nodeValue("Fill threshold", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.)
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 4] = nodeValue("Fill type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, ["4 connect", "8 connect", "Entire canvas"]);
inputs[| 5] = nodeValue("Draw preview overlay", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 6] = nodeValue("Brush", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone)
.setVisible(true, false);
inputs[| 7] = nodeValue("Surface amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1);
inputs[| 8] = nodeValue("Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, -1);
inputs[| 9] = nodeValue("Background alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1.)
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 10] = nodeValue("Render background", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true);
inputs[| 11] = nodeValue("Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 )
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 12] = nodeValue("Frames animation", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );
inputs[| 13] = nodeValue("Animation speed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 );
inputs[| 14] = nodeValue("Use background dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true );
inputs[| 15] = nodeValue("Brush distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1 ] )
.setDisplay(VALUE_DISPLAY.range, { linked : true });
inputs[| 16] = nodeValue("Rotate brush by direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );
inputs[| 17] = nodeValue("Random direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0, 0, 0 ] )
.setDisplay(VALUE_DISPLAY.rotation_random);
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
frame_renderer_x = 0;
frame_renderer_x_to = 0;
frame_renderer_x_max = 0;
frame_renderer_content = surface_create(1, 1);
frame_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region
var _h = 64;
_y += 8;
var _cnt_hover = false;
draw_sprite_stretched(THEME.button_def, 0, _x, _y, _w, _h);
if(_hover && frame_renderer.parent != noone && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h)) {
frame_renderer.parent.scroll_lock = true;
_cnt_hover = _hover;
}
var _ww = _w - 4 - 40;
var _hh = _h - 4 - 4;
var _x0 = _x + 4;
var _y0 = _y + 4;
var _x1 = _x0 + _ww;
var _y1 = _y0 + _hh;
draw_sprite_stretched(THEME.ui_panel_bg, 1, _x0, _y0, _ww, _hh);
frame_renderer_x_max = 0;
frame_renderer_content = surface_verify(frame_renderer_content, _ww, _hh);
surface_set_shader(frame_renderer_content);
var _msx = _m[0] - _x0;
var _msy = _m[1] - _y0;
var _fr_h = _hh - 8;
var _fr_w = _fr_h;
var _fr_x = 8 - frame_renderer_x;
var _fr_y = 4;
var surfs = output_surface;
var _del = noone;
for( var i = 0, n = attributes.frames; i < n; i++ ) {
var _surf = surfs[i];
if(!is_surface(_surf)) continue;
var _sw = surface_get_width(_surf);
var _sh = surface_get_height(_surf);
var _ss = min(_fr_w / _sw, _fr_h / _sh);
var _sx = _fr_x;
var _sy = _fr_y + _fr_h / 2 - _sh * _ss / 2;
draw_surface_ext(_surf, _sx, _sy, _ss, _ss, 0, c_white, 0.75);
draw_set_color(i == preview_index? COLORS._main_accent : COLORS.panel_toolbar_outline);
draw_rectangle(_sx, _sy, _sx + _sw * _ss, _sy + _sh * _ss, true);
var _del_x = _sx + _sw * _ss - 8;
var _del_y = _sy + 8;
var _del_a = 0;
if(_hover) {
if(point_in_circle(_msx, _msy, _del_x, _del_y, 8)) {
_del_a = 1;
if(mouse_press(mb_left, _focus))
_del = i;
} else if(point_in_rectangle(_msx, _msy, _sx, _sy, _sx + _sw * _ss, _sy + _sh * _ss)) {
if(mouse_press(mb_left, _focus)) preview_index = i;
}
}
draw_sprite(THEME.close_16, _del_a, _del_x, _del_y);
_fr_x += _sw * _ss + 8;
frame_renderer_x_max += _sw * _ss + 8;
}
if(_del > noone) removeFrame(_del);
surface_reset_shader();
draw_surface(frame_renderer_content, _x0, _y0);
frame_renderer_x_max = max(0, frame_renderer_x_max - 200);
frame_renderer_x = lerp_float(frame_renderer_x, frame_renderer_x_to, 3);
if(_cnt_hover) {
if(mouse_wheel_down()) frame_renderer_x_to = clamp(frame_renderer_x_to + 80, 0, frame_renderer_x_max);
if(mouse_wheel_up()) frame_renderer_x_to = clamp(frame_renderer_x_to - 80, 0, frame_renderer_x_max);
}
var _bs = 32;
var _bx = _x1 + ui(20) - _bs / 2;
var _by = _y + _h / 2 - _bs / 2;
if(buttonInstant(THEME.button_hide, _bx, _by, _bs, _bs, _m, _focus, _hover,, THEME.add,, COLORS._main_value_positive) == 2) {
attributes.frames++;
refreshFrames();
update();
}
return 8 + _h;
}); #endregion
temp_surface = array_create(1);
input_display_list = [
["Output", false], 0, frame_renderer, 12, 13,
["Brush", true], 6, 15, 17, 16,
["Background", true, 10], 8, 14, 9,
];
#region ++++ data ++++
attributes.frames = 1;
attribute_surface_depth();
attributes.dimension = [ 1, 1 ];
output_surface = [ surface_create_empty(1, 1) ];
canvas_surface = [ surface_create_empty(1, 1) ];
canvas_buffer = [ buffer_create(1 * 1 * 4, buffer_fixed, 2) ];
drawing_surface = surface_create_empty(1, 1);
_drawing_surface = surface_create_empty(1, 1);
surface_w = 1;
surface_h = 1;
prev_surface = surface_create_empty(1, 1);
preview_draw_surface = surface_create_empty(1, 1);
preview_draw_mask = surface_create_empty(1, 1);
draw_stack = ds_list_create();
brush = new canvas_brush();
#endregion
#region ++++ tools ++++
tool_attribute.color = cola(c_white);
tool_attribute.channel = [ true, true, true, true ];
tool_channel_edit = new checkBoxGroup(THEME.tools_canvas_channel, function(ind, val) { tool_attribute.channel[ind] = val; });
tool_attribute.drawLayer = 0;
tool_attribute.pickColor = c_white;
tool_drawLayer_edit = new buttonGroup( [ THEME.canvas_draw_layer, THEME.canvas_draw_layer, THEME.canvas_draw_layer ], function(val) { tool_attribute.drawLayer = val; });
tool_attribute.mirror = [ false, false ];
tool_mirror_edit = new checkBoxGroup( THEME.canvas_mirror, function(ind, val) { tool_attribute.mirror[ind] = val; });
tool_settings = [ [ "", tool_channel_edit, "channel", tool_attribute ],
[ "", tool_drawLayer_edit, "drawLayer", tool_attribute ],
[ "", tool_mirror_edit, "mirror", tool_attribute ],
];
tool_attribute.size = 1;
tool_size_edit = new textBox(TEXTBOX_INPUT.number, function(val) { tool_attribute.size = max(1, round(val)); }).setSlidable(0.1, true, [ 1, 999999 ])
.setFont(f_p3)
.setSideButton(button(function() { dialogPanelCall(new Panel_Node_Canvas_Pressure(self), mouse_mx, mouse_my, { anchor: ANCHOR.top | ANCHOR.left }) })
.setIcon(THEME.pen_pressure, 0, COLORS._main_icon));
tool_size = [ "Size", tool_size_edit, "size", tool_attribute ];
tool_attribute.pressure = false;
tool_attribute.pressure_size = [ 1, 1 ];
tool_attribute.thres = 0;
tool_thrs_edit = new textBox(TEXTBOX_INPUT.number, function(val) { tool_attribute.thres = clamp(val, 0, 1); }).setSlidable(0.01, false, [ 0, 1 ]).setFont(f_p3);
tool_thrs = [ "Threshold", tool_thrs_edit, "thres", tool_attribute ];
tool_attribute.fill8 = false;
tool_fil8_edit = new checkBox(function() { tool_attribute.fill8 = !tool_attribute.fill8; });
tool_fil8 = [ "Diagonal", tool_fil8_edit, "fill8", tool_attribute ];
tools = [
new NodeTool( "Selection", [ THEME.canvas_tools_selection_rectangle, THEME.canvas_tools_selection_circle, THEME.canvas_tools_freeform_selection, THEME.canvas_tools_selection_brush ]),
new NodeTool( "Magic Selection", THEME.canvas_tools_magic_selection )
.setSetting(tool_thrs)
.setSetting(tool_fil8),
new NodeTool( "Pencil", THEME.canvas_tools_pencil)
.setSetting(tool_size),
new NodeTool( "Eraser", THEME.canvas_tools_eraser)
.setSetting(tool_size),
new NodeTool( "Rectangle", [ THEME.canvas_tools_rect, THEME.canvas_tools_rect_fill ])
.setSetting(tool_size),
new NodeTool( "Ellipse", [ THEME.canvas_tools_ellip, THEME.canvas_tools_ellip_fill ])
.setSetting(tool_size),
new NodeTool( "Freeform", THEME.canvas_tools_freeform)
.setSetting(tool_size),
new NodeTool( "Fill", THEME.canvas_tools_bucket)
.setSetting(tool_thrs)
.setSetting(tool_fil8),
];
tool_selection = new canvas_tool_selection();
tool_brush = new canvas_tool_brush(brush, false);
tool_eraser = new canvas_tool_brush(brush, true);
tool_rectangle = new canvas_tool_shape(brush, CANVAS_TOOL_SHAPE.rectangle);
tool_ellipse = new canvas_tool_shape(brush, CANVAS_TOOL_SHAPE.ellipse);
tool_fill = new canvas_tool_fill(tool_attribute);
tool_freeform = new canvas_tool_draw_freeform(brush);
tool_sel_rectangle = new canvas_tool_selection_shape(tool_selection, CANVAS_TOOL_SHAPE.rectangle);
tool_sel_ellipse = new canvas_tool_selection_shape(tool_selection, CANVAS_TOOL_SHAPE.ellipse);
tool_sel_freeform = new canvas_tool_selection_freeform(tool_selection, brush);
tool_sel_magic = new canvas_tool_selection_magic(tool_selection, tool_attribute);
tool_sel_brush = new canvas_tool_selection_brush(tool_selection, brush);
#endregion
#region ++++ right tools ++++
__action_rotate_90_cw = method(self, function() { if(tool_selection.is_selected) tool_selection.rotate90cw() else canvas_action_rotate(-90); });
__action_rotate_90_ccw = method(self, function() { if(tool_selection.is_selected) tool_selection.rotate90ccw() else canvas_action_rotate( 90); });
__action_flip_h = method(self, function() { if(tool_selection.is_selected) tool_selection.flipH() else canvas_action_flip(1); });
__action_flip_v = method(self, function() { if(tool_selection.is_selected) tool_selection.flipV() else canvas_action_flip(0); });
__action_add_node = method(self, function(ctx) { dialogCall(o_dialog_add_node, mouse_mx + 8, mouse_my + 8, { context: ctx }); });
__action_make_brush = method(self, function() {
if(brush.brush_use_surface) {
brush.brush_surface = noone;
brush.brush_use_surface = false;
return;
}
var _surf = tool_selection.selection_surface;
var _bsurf = surface_create(surface_get_width(_surf) + 2, surface_get_height(_surf) + 2);
surface_set_target(_bsurf);
DRAW_CLEAR
draw_surface(_surf, 1, 1);
surface_reset_target();
brush.brush_use_surface = true;
brush.brush_surface = _bsurf;
tool_selection.apply();
PANEL_PREVIEW.tool_current = tools[2];
});
nodeTool = noone;
nodeToolPreview = new NodeTool( "Apply Node", THEME.canvas_tools_node, self ).setToolFn( __action_add_node );
rightTools_general = [
nodeToolPreview,
-1,
new NodeTool( "Resize Canvas", THEME.canvas_resize ).setToolObject( new canvas_tool_resize() ),
new NodeTool( [ "Rotate 90 CW", "Rotate 90 CCW" ],
[ THEME.canvas_rotate_cw, THEME.canvas_rotate_ccw ] )
.setToolFn( [ __action_rotate_90_cw, __action_rotate_90_ccw ] ),
new NodeTool( [ "Flip H", "Flip V" ],
[ THEME.canvas_flip_h, THEME.canvas_flip_v ] )
.setToolFn( [ __action_flip_h, __action_flip_v ] ),
];
rightTools_selection = [
-1,
new NodeTool( "Make/Reset Brush", THEME.canvas_tools_pencil ).setToolFn( __action_make_brush ),
-1,
new NodeTool( "Outline", THEME.canvas_tools_outline ).setToolObject( new canvas_tool_outline() ),
new NodeTool( [ "Extrude", "Inset" ],
[ THEME.canvas_tools_extrude, THEME.canvas_tools_inset ] )
.setToolObject( [ new canvas_tool_extrude(), new canvas_tool_inset() ] ),
];
rightTools_brush = [
-1,
new NodeTool( "Make/Reset Brush", THEME.canvas_tools_pencil ).setToolFn( __action_make_brush ),
];
rightTools = rightTools_general;
tool_brush.rightTools = rightTools_brush;
tool_eraser.rightTools = rightTools_brush;
tool_rectangle.rightTools = rightTools_brush;
tool_ellipse.rightTools = rightTools_brush;
#endregion
function setToolColor(color) { tool_attribute.color = color; }
function getToolColor() { return tool_attribute.color; }
static drawTools = function(_mx, _my, xx, yy, tool_size, hover, focus) { #region
var _sx0 = xx - tool_size / 2;
var _sx1 = xx + tool_size / 2;
var hh = ui(8);
yy += ui(4);
draw_set_color(COLORS._main_icon_dark);
draw_line_round(_sx0 + ui(8), yy, _sx1 - ui(8), yy, 2);
yy += ui(4);
var _cx = _sx0 + ui(8);
var _cw = tool_size - ui(16);
var _ch = ui(12);
var _pd = ui(5);
yy += ui(8);
hh += ui(8);
drawColor(tool_attribute.color, _cx, yy, _cw, _cw);
draw_sprite_stretched_ext(THEME.palette_selecting, 0, _cx - _pd, yy - _pd, _cw + _pd * 2, _cw + _pd * 2, c_white, 1);
if(point_in_rectangle(_mx, _my, _cx, yy, _cx + _cw, yy + _ch) && mouse_press(mb_left, focus))
colorSelectorCall(tool_attribute.color, setToolColor);
yy += _cw + ui(8);
hh += _cw + ui(8);
var _sel = noone;
for( var i = 0, n = array_length(DEF_PALETTE); i < n; i++ ) {
var _c = DEF_PALETTE[i];
var ii = 0;
if(i == 0) ii = 4;
if(i == n - 1) ii = 5;
draw_sprite_stretched_ext(THEME.palette_mask, ii, _cx, yy, _cw, _ch, _c, 1);
if(_c == tool_attribute.color)
_sel = [ _cx, yy ];
if(hover && point_in_rectangle(_mx, _my, _cx, yy, _cx + _cw, yy + _ch)) {
if(mouse_click(mb_left, focus))
tool_attribute.color = _c;
}
yy += _ch;
hh += _ch;
}
if(_sel != noone)
draw_sprite_stretched_ext(THEME.palette_selecting, 0, _sel[0] - _pd, _sel[1] - _pd, _cw + _pd * 2, _ch + _pd * 2, c_white, 1);
return hh + ui(4);
} #endregion
function removeFrame(index = 0) { #region
if(attributes.frames <= 1) return;
if(preview_index == attributes.frames)
preview_index--;
attributes.frames--;
array_delete(canvas_surface, index, 1);
array_delete(canvas_buffer, index, 1);
update();
} #endregion
function refreshFrames() { #region
var fr = attributes.frames;
var _dim = attributes.dimension;
if(array_length(canvas_surface) < fr) {
for( var i = array_length(canvas_surface); i < fr; i++ ) {
canvas_surface[i] = surface_create(_dim[0], _dim[1]);
surface_set_target(canvas_surface[i]);
DRAW_CLEAR
surface_reset_target();
}
} else
array_resize(canvas_surface, fr);
if(array_length(canvas_buffer) < fr) {
for( var i = array_length(canvas_buffer); i < fr; i++ ) {
canvas_buffer[i] = buffer_create(1 * 1 * 4, buffer_fixed, 2);
}
} else
array_resize(canvas_buffer, fr);
} #endregion
function getCanvasSurface(index = preview_index) { INLINE return array_safe_get_fast(canvas_surface, index); }
function setCanvasSurface(surface, index = preview_index) { INLINE canvas_surface[index] = surface; }
function storeAction() { #region
var action = recordAction(ACTION_TYPE.custom, function(data) {
is_selected = false;
var _canvas = surface_clone(getCanvasSurface(data.index));
if(is_surface(data.surface))
setCanvasSurface(surface_clone(data.surface), data.index);
surface_store_buffer(data.index);
surface_free(data.surface);
data.surface = _canvas;
data.index = preview_index;
}, { surface: surface_clone(getCanvasSurface()), tooltip: "Modify canvas", index: preview_index });
action.clear_action = function(data) { surface_free_safe(data.surface); };
} #endregion
function apply_surfaces() { #region
for( var i = 0; i < attributes.frames; i++ )
apply_surface(i);
} #endregion
function apply_surface(index = preview_index) { #region
var _dim = attributes.dimension;
var cDep = attrDepth();
var _canvas_surface = getCanvasSurface(index);
if(!is_surface(_canvas_surface)) { // recover surface from bufffer in case of VRAM refresh
setCanvasSurface(surface_create_from_buffer(_dim[0], _dim[1], canvas_buffer[index]), index);
} else if(surface_get_width_safe(_canvas_surface) != _dim[0] || surface_get_height_safe(_canvas_surface) != _dim[1]) { // resize surface
var _cbuff = array_safe_get_fast(canvas_buffer, index);
if(buffer_exists(_cbuff)) buffer_delete(_cbuff);
canvas_buffer[index] = buffer_create(_dim[0] * _dim[1] * 4, buffer_fixed, 4);
var _newCanvas = surface_create(_dim[0], _dim[1]);
surface_set_target(_newCanvas);
DRAW_CLEAR
draw_surface(_canvas_surface, 0, 0);
surface_reset_target();
setCanvasSurface(_newCanvas, index);
surface_free(_canvas_surface);
}
drawing_surface = surface_verify(drawing_surface, _dim[0], _dim[1], cDep);
surface_clear(drawing_surface);
} #endregion
function surface_store_buffers(index = preview_index) { #region
for( var i = 0; i < attributes.frames; i++ )
surface_store_buffer(i);
} #endregion
function surface_store_buffer(index = preview_index) { #region
if(index >= attributes.frames) return;
buffer_delete(canvas_buffer[index]);
var _canvas_surface = getCanvasSurface(index);
surface_w = surface_get_width_safe(_canvas_surface);
surface_h = surface_get_height_safe(_canvas_surface);
canvas_buffer[index] = buffer_create(surface_w * surface_h * 4, buffer_fixed, 4);
buffer_get_surface(canvas_buffer[index], _canvas_surface, 0);
triggerRender();
apply_surface(index);
} #endregion
function tool_pick_color(_x, _y) { #region
if(tool_selection.is_selected)
tool_attribute.pickColor = surface_get_pixel(tool_selection.selection_surface, _x - tool_selection.selection_position[0], _y - tool_selection.selection_position[1]);
else
tool_attribute.pickColor = surface_get_pixel(getCanvasSurface(), _x, _y);
} #endregion
function apply_draw_surface() { #region
var _can = getCanvasSurface();
var _drw = drawing_surface;
var _dim = attributes.dimension;
var _tmp;
storeAction();
if(tool_selection.is_selected) {
var _tmp = surface_create(surface_get_width(tool_selection.selection_mask), surface_get_height(tool_selection.selection_mask));
var _spx = tool_selection.selection_position[0];
var _spy = tool_selection.selection_position[1];
var _spw = tool_selection.selection_size[0];
var _sph = tool_selection.selection_size[1];
surface_set_target(_tmp);
DRAW_CLEAR
draw_surface(drawing_surface, -_spx, -_spy);
BLEND_ALPHA
if(tool_attribute.mirror[0]) draw_surface_ext_safe(drawing_surface, _spx * 2 + _spw - _spx, -_spy, -1, 1);
if(tool_attribute.mirror[1]) draw_surface_ext_safe(drawing_surface, -_spx, _spy * 2 + _sph - _spy, 1, -1);
if(tool_attribute.mirror[0] && tool_attribute.mirror[1]) draw_surface_ext_safe(drawing_surface, _spx * 2 + _spw - _spx, _spy * 2 + _sph - _spy, -1, -1);
BLEND_NORMAL
BLEND_MULTIPLY
draw_surface(tool_selection.selection_mask, 0, 0);
BLEND_NORMAL
surface_reset_target();
_can = tool_selection.selection_surface;
} else {
var _tmp = surface_create(_dim[0], _dim[1]);
surface_set_target(_tmp);
DRAW_CLEAR
BLEND_OVERRIDE
draw_surface(drawing_surface, 0, 0);
BLEND_ALPHA
if(tool_attribute.mirror[0]) draw_surface_ext_safe(drawing_surface, _dim[0], 0, -1, 1);
if(tool_attribute.mirror[1]) draw_surface_ext_safe(drawing_surface, 0, _dim[1], 1, -1);
if(tool_attribute.mirror[0] && tool_attribute.mirror[1]) draw_surface_ext_safe(drawing_surface, _dim[0], _dim[1], -1, -1);
BLEND_NORMAL
surface_reset_target();
}
var _sw = surface_get_width(_can);
var _sh = surface_get_height(_can);
var _drawnSurface = surface_create(_sw, _sh);
surface_set_shader(_drawnSurface, sh_canvas_apply_draw);
shader_set_i("drawLayer", tool_attribute.drawLayer);
shader_set_i("eraser", isUsingTool("Eraser"));
shader_set_f("channels", tool_attribute.channel);
shader_set_f("alpha", _color_get_alpha(tool_attribute.color));
shader_set_f("mirror", tool_attribute.mirror);
shader_set_color("pickColor", tool_attribute.pickColor);
shader_set_surface("back", _can);
shader_set_surface("fore", _tmp);
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _sw, _sh);
surface_reset_shader();
surface_free(_can);
surface_clear(drawing_surface);
surface_free(_tmp);
if(tool_selection.is_selected) {
tool_selection.selection_surface = _drawnSurface;
} else {
setCanvasSurface(_drawnSurface);
surface_store_buffer();
}
} #endregion
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
if(instance_exists(o_dialog_color_picker)) return;
COLORS_GLOBAL_GET = getToolColor;
COLORS_GLOBAL_SET = setToolColor;
brush.node = self;
brush.step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
if(!tool_selection.is_selected && active && key_mod_press(ALT)) { #region color selector
var dialog = instance_create(0, 0, o_dialog_color_picker);
dialog.onApply = setToolColor;
dialog.def_c = tool_attribute.color;
} #endregion
var _canvas_surface = getCanvasSurface();
if(!surface_exists(_canvas_surface)) return;
#region surfaces
var _dim = attributes.dimension;
_drawing_surface = surface_verify(_drawing_surface, _dim[0], _dim[1]);
drawing_surface = surface_verify( drawing_surface, _dim[0], _dim[1], attrDepth());
surface_set_target(_drawing_surface);
DRAW_CLEAR
draw_surface_safe(drawing_surface);
surface_reset_target();
var __s = surface_get_target();
var _sw = surface_get_width(__s);
var _sh = surface_get_height(__s);
prev_surface = surface_verify(prev_surface, _dim[0], _dim[1]);
preview_draw_surface = surface_verify(preview_draw_surface, _dim[0], _dim[1]);
preview_draw_mask = surface_verify(preview_draw_mask, _sw, _sh);
#endregion
#region tool
var _currTool = PANEL_PREVIEW.tool_current;
var _tool = noone;
rightTools = [];
array_append(rightTools, rightTools_general);
if(tool_selection.is_selected) array_append(rightTools, rightTools_selection);
if(nodeTool != noone)
_tool = nodeTool;
else if(_currTool != noone) {
_tool = _currTool.getToolObject();
switch(_currTool.getName()) {
case "Pencil" : _tool = tool_brush; break;
case "Eraser" : _tool = tool_eraser; break;
case "Fill" : _tool = tool_fill; break;
case "Freeform" : _tool = tool_freeform; break;
case "Rectangle" :
_tool = tool_rectangle;
_tool.fill = _currTool.selecting == 1;
break;
case "Ellipse" :
_tool = tool_ellipse;
_tool.fill = _currTool.selecting == 1;
break;
case "Selection" :
switch(_currTool.selecting) {
case 0 : _tool = tool_sel_rectangle; break;
case 1 : _tool = tool_sel_ellipse; break;
case 2 : _tool = tool_sel_freeform; break;
case 3 : _tool = tool_sel_brush; break;
}
break;
case "Magic Selection" : _tool = tool_sel_magic; break;
}
if(_tool) {
_tool.subtool = _currTool.selecting;
array_append(rightTools, _tool.rightTools);
}
tool_selection.node = self;
tool_selection.drawing_surface = drawing_surface;
tool_selection._canvas_surface = _canvas_surface;
tool_selection.apply_draw_surface = apply_draw_surface;
if(is_instanceof(_tool, canvas_tool_selection) && tool_selection.is_selected) tool_selection.step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
}
if(_tool && _tool.override) {
_tool.node = self;
_tool.step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
_tool.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_set_shader(preview_draw_surface, noone);
_tool.drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_reset_shader();
draw_surface_ext_safe(preview_draw_surface, _x, _y, _s);
surface_set_target(preview_draw_mask);
DRAW_CLEAR
_tool.drawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_reset_target();
shader_set(sh_brush_outline);
shader_set_f("dimension", _sw, _sh);
draw_surface_ext_safe(preview_draw_mask);
shader_reset();
_tool.drawPostOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
return;
}
#endregion
draw_set_color(tool_attribute.color);
if(_tool) { #region tool step
_tool.drawing_surface = drawing_surface;
_tool._canvas_surface = _canvas_surface;
_tool.apply_draw_surface = apply_draw_surface;
_tool.brush = brush;
_tool.node = self;
if(_tool.relative && tool_selection.is_selected) {
_tool._canvas_surface = tool_selection.selection_surface;
var _px = tool_selection.selection_position[0];
var _py = tool_selection.selection_position[1];
var _rx = _x + _px * _s;
var _ry = _y + _py * _s;
_tool.step(hover, active, _rx, _ry, _s, _mx, _my, _snx, _sny);
} else
_tool.step(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
if(_tool.brush_resizable) {
if(hover && key_mod_press(CTRL)) {
if(mouse_wheel_down()) tool_attribute.size = max( 1, tool_attribute.size - 1);
if(mouse_wheel_up()) tool_attribute.size = min(64, tool_attribute.size + 1);
}
brush.sizing(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
}
} #endregion
draw_set_alpha(1);
#region preview
var _alp = _color_get_alpha(tool_attribute.color);
if(tool_selection.is_selected) tool_selection.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
if(_tool) _tool.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_set_shader(preview_draw_surface, noone,, BLEND.alpha);
draw_surface_safe(_drawing_surface, 0, 0);
if(tool_selection.is_selected) {
var _spx = tool_selection.selection_position[0];
var _spy = tool_selection.selection_position[1];
var _spw = tool_selection.selection_size[0];
var _sph = tool_selection.selection_size[1];
if(tool_attribute.mirror[0]) draw_surface_ext_safe(_drawing_surface, _spx * 2 + _spw, 0, -1, 1);
if(tool_attribute.mirror[1]) draw_surface_ext_safe(_drawing_surface, 0, _spy * 2 + _sph, 1, -1);
if(tool_attribute.mirror[0] && tool_attribute.mirror[1]) draw_surface_ext_safe(_drawing_surface, _spx * 2 + _spw, _spy * 2 + _sph, -1, -1);
} else {
if(tool_attribute.mirror[0]) draw_surface_ext_safe(_drawing_surface, _dim[0], 0, -1, 1);
if(tool_attribute.mirror[1]) draw_surface_ext_safe(_drawing_surface, 0, _dim[1], 1, -1);
if(tool_attribute.mirror[0] && tool_attribute.mirror[1]) draw_surface_ext_safe(_drawing_surface, _dim[0], _dim[1], -1, -1);
}
draw_set_color(tool_attribute.color);
if(brush.brush_sizing)
canvas_draw_point_size(brush, brush.brush_sizing_dx, brush.brush_sizing_dy);
else if(_tool)
_tool.drawPreview(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_reset_shader();
draw_surface_ext_safe(preview_draw_surface, _x, _y, _s, _s, 0, isUsingTool("Eraser")? c_red : c_white, isUsingTool("Eraser")? 0.2 : _alp);
surface_set_target(preview_draw_mask);
DRAW_CLEAR
if(tool_selection.is_selected) tool_selection.drawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
if(_tool) _tool.drawMask(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
surface_reset_target();
shader_set(sh_brush_outline);
shader_set_f("dimension", _sw, _sh);
draw_surface_ext_safe(preview_draw_mask, 0, 0, 1, 1, 0, c_white, 1);
shader_reset();
if(_tool) _tool.drawPostOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
#endregion
var _x0 = _x;
var _y0 = _y;
var _x1 = _x0 + _dim[0] * _s;
var _y1 = _y0 + _dim[1] * _s;
draw_set_color(COLORS.panel_preview_surface_outline);
draw_rectangle(_x0, _y0, _x1 - 1, _y1 - 1, true);
draw_set_alpha(1);
previewing = 1;
if((_tool == noone || !_tool.mouse_holding) && key_press(ord("V"), MOD_KEY.ctrl)) { #region
var _str = json_try_parse(clipboard_get_text(), noone);
print(clipboard_get_text())
if(is_struct(_str) && struct_has(_str, "buffer")) {
var _surf = surface_decode(_str);
if(is_surface(_surf)) {
tool_selection.selection_surface = _surf;
tool_selection.is_selected = true;
tool_selection.selection_position = [ 0, 0 ];
}
}
} #endregion
} #endregion
static step = function() { #region
var fram = attributes.frames;
var brush = getInputData(6);
var anim = getInputData(12);
var anims = getInputData(13);
inputs[| 12].setVisible(fram > 1);
inputs[| 13].setVisible(fram > 1 && anim);
inputs[| 15].setVisible(is_surface(brush));
inputs[| 16].setVisible(is_surface(brush));
update_on_frame = fram > 1 && anim;
if(update_on_frame)
preview_index = safe_mod(CURRENT_FRAME * anims, fram);
} #endregion
static update = function(frame = CURRENT_FRAME) { #region
var _dim = getInputData(0);
var _bg = getInputData(8);
var _bga = getInputData(9);
var _bgr = getInputData(10);
var _anim = getInputData(12);
var _anims = getInputData(13);
var _bgDim = getInputData(14);
var cDep = attrDepth();
if(_bgDim && is_surface(_bg)) _dim = [ surface_get_width_safe(_bg), surface_get_height_safe(_bg) ];
attributes.dimension = _dim;
apply_surfaces();
var _frames = attributes.frames;
if(!is_array(output_surface)) output_surface = array_create(_frames);
else if(array_length(output_surface) != _frames)
array_resize(output_surface, _frames);
if(_frames == 1) {
var _canvas_surface = getCanvasSurface(0);
output_surface[0] = surface_verify(output_surface[0], _dim[0], _dim[1], cDep);
surface_set_shader(output_surface[0], noone,, BLEND.alpha);
if(_bgr && is_surface(_bg))
draw_surface_stretched_ext(_bg, 0, 0, _dim[0], _dim[1], c_white, _bga);
draw_surface_safe(_canvas_surface, 0, 0);
surface_reset_shader();
outputs[| 0].setValue(output_surface[0]);
} else {
for( var i = 0; i < _frames; i++ ) {
var _canvas_surface = getCanvasSurface(i);
output_surface[i] = surface_verify(output_surface[i], _dim[0], _dim[1], cDep);
surface_set_shader(output_surface[i], noone,, BLEND.alpha);
if(_bgr && is_surface(_bg))
draw_surface_stretched_ext(_bg, 0, 0, _dim[0], _dim[1], c_white, _bga);
draw_surface_safe(_canvas_surface, 0, 0);
surface_reset_shader();
}
if(_anim) {
var _fr_index = safe_mod(CURRENT_FRAME * _anims, _frames);
outputs[| 0].setValue(output_surface[_fr_index]);
} else
outputs[| 0].setValue(output_surface);
}
} #endregion
static getPreviewValues = function() { return nodeTool == noone || nodeTool.applySelection? output_surface : noone; }
static doSerialize = function(_map) { #region
surface_store_buffers();
var _buff = array_create(attributes.frames);
for( var i = 0; i < attributes.frames; i++ ) {
var comp = buffer_compress(canvas_buffer[i], 0, buffer_get_size(canvas_buffer[i]));
_buff[i] = buffer_base64_encode(comp, 0, buffer_get_size(comp));
}
_map.surfaces = _buff;
} #endregion
static doApplyDeserialize = function() { #region
var _dim = struct_has(attributes, "dimension")? attributes.dimension : getInputData(0);
if(!struct_has(load_map, "surfaces")) {
if(struct_has(load_map, "surface")) {
var buff = buffer_base64_decode(load_map.surface);
canvas_buffer[0] = buffer_decompress(buff);
canvas_surface[0] = surface_create_from_buffer(_dim[0], _dim[1], canvas_buffer[0]);
}
return;
}
canvas_buffer = array_create(array_length(load_map.surfaces));
canvas_surface = array_create(array_length(load_map.surfaces));
for( var i = 0, n = array_length(load_map.surfaces); i < n; i++ ) {
var buff = buffer_base64_decode(load_map.surfaces[i]);
canvas_buffer[i] = buffer_decompress(buff);
canvas_surface[i] = surface_create_from_buffer(_dim[0], _dim[1], canvas_buffer[i]);
}
apply_surfaces();
} #endregion
static onCleanUp = function() { #region
surface_array_free(canvas_surface);
} #endregion
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,50 @@
// 2024-04-14 11:31:22
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform int drawLayer;
uniform int eraser;
uniform vec4 channels;
uniform vec4 pickColor;
uniform float alpha;
uniform vec2 mirror;
uniform sampler2D back;
uniform sampler2D fore;
vec4 blend( in vec4 bgc, in vec4 fgc ) {
vec4 _fgc = vec4(fgc);
_fgc *= channels;
_fgc.a *= alpha;
if(eraser == 1) {
bgc -= _fgc;
return bgc;
}
if(drawLayer == 1) {
vec4 temp = _fgc;
_fgc = bgc;
bgc = temp;
}
if(drawLayer == 2) {
if(bgc != pickColor) return bgc;
}
float al = _fgc.a + bgc.a * (1. - _fgc.a);
vec4 _res = ((_fgc * _fgc.a) + (bgc * bgc.a * (1. - _fgc.a))) / al;
_res.a = al;
return _res;
}
void main() {
vec4 bc = texture2D( back, v_vTexcoord );
vec4 fc = texture2D( fore, v_vTexcoord );
vec4 res = blend(bc, fc);
gl_FragColor = res;
}

View file

@ -0,0 +1,64 @@
// 2024-04-14 11:30:41
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform int drawLayer;
uniform int eraser;
uniform vec4 channels;
uniform vec4 pickColor;
uniform float alpha;
uniform vec2 mirror;
uniform sampler2D back;
uniform sampler2D fore;
vec4 blend( in vec4 bgc, in vec4 fgc ) {
vec4 _fgc = vec4(fgc);
_fgc *= channels;
_fgc.a *= alpha;
if(eraser == 1) {
bgc -= _fgc;
return bgc;
}
if(drawLayer == 1) {
vec4 temp = _fgc;
_fgc = bgc;
bgc = temp;
}
if(drawLayer == 2) {
if(bgc != pickColor) return bgc;
}
float al = _fgc.a + bgc.a * (1. - _fgc.a);
vec4 _res = ((_fgc * _fgc.a) + (bgc * bgc.a * (1. - _fgc.a))) / al;
_res.a = al;
return _res;
}
void main() {
vec4 bc = texture2D( back, v_vTexcoord );
vec4 fc = texture2D( fore, v_vTexcoord );
vec4 res = blend(bc, fc);
if(mirror.x == 1.) {
vec2 pos = vec2( 1. - v_vTexcoord.x, v_vTexcoord.y );
vec4 mfc = texture2D( fore, pos );
res = blend(res, mfc);
}
if(mirror.y == 1.) {
vec2 pos = vec2( v_vTexcoord.x, 1. - v_vTexcoord.y );
vec4 mfc = texture2D( fore, pos );
res = blend(res, mfc);
}
gl_FragColor = res;
}

Binary file not shown.