mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-11-14 14:33:53 +01:00
124 lines
3.9 KiB
Plaintext
124 lines
3.9 KiB
Plaintext
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;
|
|
|
|
mouse_line_drawing = false;
|
|
mouse_line_x0 = 0;
|
|
mouse_line_y0 = 0;
|
|
mouse_line_x1 = 0;
|
|
mouse_line_y1 = 0;
|
|
|
|
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_presses(SHIFT, 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)) {
|
|
|
|
surface_set_shader(drawing_surface, noone);
|
|
canvas_draw_point_brush(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);
|
|
canvas_draw_line_brush(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_brush(brush, mouse_cur_x, mouse_cur_y, true);
|
|
canvas_draw_line_brush(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);
|
|
|
|
mouse_line_drawing = false;
|
|
|
|
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_press(SHIFT)) {
|
|
|
|
canvas_draw_line_brush(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
|
|
mouse_line_drawing = true;
|
|
mouse_line_x0 = min(mouse_cur_x, mouse_pre_draw_x);
|
|
mouse_line_y0 = min(mouse_cur_y, mouse_pre_draw_y);
|
|
mouse_line_x1 = max(mouse_cur_x, mouse_pre_draw_x) + 1;
|
|
mouse_line_y1 = max(mouse_cur_y, mouse_pre_draw_y) + 1;
|
|
|
|
} else
|
|
canvas_draw_point_brush(brush, mouse_cur_x, mouse_cur_y);
|
|
}
|
|
|
|
function drawPostOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
|
|
|
if(mouse_line_drawing && !brush.brush_sizing && node.attributes.show_slope_check) {
|
|
var _x0 = _x + mouse_line_x0 * _s;
|
|
var _y0 = _y + mouse_line_y0 * _s;
|
|
var _x1 = _x + mouse_line_x1 * _s;
|
|
var _y1 = _y + mouse_line_y1 * _s;
|
|
|
|
var _w = mouse_line_x1 - mouse_line_x0;
|
|
var _h = mouse_line_y1 - mouse_line_y0;
|
|
var _as = max(_w, _h) % min(_w, _h) == 0;
|
|
|
|
draw_set_color(_as? COLORS._main_value_positive : COLORS._main_accent);
|
|
draw_rectangle(_x0, _y0, _x1, _y1, true);
|
|
|
|
draw_set_text(f_p3, fa_center, fa_top);
|
|
draw_text((_x0 + _x1) / 2, _y1 + 8, _w);
|
|
|
|
draw_set_text(f_p3, fa_left, fa_center);
|
|
draw_text(_x1 + 8, (_y0 + _y1) / 2, _h);
|
|
}
|
|
}
|
|
} |