Pixel-Composer/scripts/canvas_tool_outline/canvas_tool_outline.gml

72 lines
2.1 KiB
Text
Raw Normal View History

2024-04-13 07:32:04 +02:00
function canvas_tool_outline() : canvas_tool_shader() constructor {
2024-04-14 07:58:38 +02:00
mouse_sx = 0;
2024-04-13 07:32:04 +02:00
function init() { mouse_init = true; }
function onInit(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
2024-04-14 07:58:38 +02:00
mouse_sx = _mx;
2024-04-13 07:32:04 +02:00
}
function stepEffect(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _dim = node.attributes.dimension;
var _thck = abs(round((_mx - mouse_sx) / _s));
var _side = _mx > mouse_sx;
surface_set_shader(preview_surface[1], sh_outline);
shader_set_f("dimension", _dim);
shader_set_f("borderSize", _thck, _thck);
shader_set_f("borderStart", 0, 0);
shader_set_i("side", _side);
shader_set_color("borderColor", node.tool_attribute.color);
draw_surface(preview_surface[0], 0, 0);
surface_reset_shader();
}
2024-04-14 07:58:38 +02:00
function stepMaskEffect(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _dim = node.attributes.dimension;
var _thck = abs(round((_mx - mouse_sx) / _s));
var _side = _mx > mouse_sx;
if(_side) {
surface_set_shader(preview_surface[1], sh_outline);
shader_set_f("dimension", _dim);
shader_set_f("borderSize", _thck, _thck);
shader_set_f("borderStart", 0, 0);
shader_set_i("side", _side);
shader_set_color("borderColor", c_white);
draw_surface(preview_surface[0], 0, 0);
surface_reset_shader();
mask_boundary[0] = mask_boundary_init[0] - _thck;
mask_boundary[1] = mask_boundary_init[1] - _thck;
mask_boundary[2] = mask_boundary_init[2] + _thck * 2;
mask_boundary[3] = mask_boundary_init[3] + _thck * 2;
} else {
surface_set_shader(preview_surface[1], sh_erode);
shader_set_f("dimension", _dim);
shader_set_f("size", _thck, _thck);
shader_set_i("border", 0);
shader_set_i("alpha", 1);
draw_surface(preview_surface[0], 0, 0);
surface_reset_shader();
mask_boundary[0] = mask_boundary_init[0] + _thck;
mask_boundary[1] = mask_boundary_init[1] + _thck;
mask_boundary[2] = mask_boundary_init[2] - _thck * 2;
mask_boundary[3] = mask_boundary_init[3] - _thck * 2;
}
}
2024-04-13 07:32:04 +02:00
}