diff --git a/#backups/scripts/__canvas_brush/__canvas_brush.gml.backup0 b/#backups/scripts/__canvas_brush/__canvas_brush.gml.backup0 new file mode 100644 index 000000000..9634571c6 --- /dev/null +++ b/#backups/scripts/__canvas_brush/__canvas_brush.gml.backup0 @@ -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); + } + } +} \ No newline at end of file diff --git a/#backups/scripts/__canvas_brush/__canvas_brush.gml.backup1 b/#backups/scripts/__canvas_brush/__canvas_brush.gml.backup1 new file mode 100644 index 000000000..f78a2ce8a --- /dev/null +++ b/#backups/scripts/__canvas_brush/__canvas_brush.gml.backup1 @@ -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); + } + } +} \ No newline at end of file diff --git a/#backups/scripts/__canvas_tool/__canvas_tool.gml.backup0 b/#backups/scripts/__canvas_tool/__canvas_tool.gml.backup0 new file mode 100644 index 000000000..2b3ce6828 --- /dev/null +++ b/#backups/scripts/__canvas_tool/__canvas_tool.gml.backup0 @@ -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) {} +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_brush/canvas_tool_brush.gml.backup0 b/#backups/scripts/canvas_tool_brush/canvas_tool_brush.gml.backup0 new file mode 100644 index 000000000..eee79f1d7 --- /dev/null +++ b/#backups/scripts/canvas_tool_brush/canvas_tool_brush.gml.backup0 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_brush/canvas_tool_brush.gml.backup1 b/#backups/scripts/canvas_tool_brush/canvas_tool_brush.gml.backup1 new file mode 100644 index 000000000..de8bc565f --- /dev/null +++ b/#backups/scripts/canvas_tool_brush/canvas_tool_brush.gml.backup1 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_curve/canvas_tool_curve.gml.backup0 b/#backups/scripts/canvas_tool_curve/canvas_tool_curve.gml.backup0 new file mode 100644 index 000000000..aef9bf750 --- /dev/null +++ b/#backups/scripts/canvas_tool_curve/canvas_tool_curve.gml.backup0 @@ -0,0 +1,4 @@ +// 2024-04-14 12:31:27 +function canvas_tool_curve() : canvas_tool() constructor { + +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_curve/canvas_tool_curve.gml.backup1 b/#backups/scripts/canvas_tool_curve/canvas_tool_curve.gml.backup1 new file mode 100644 index 000000000..04fafb6bd --- /dev/null +++ b/#backups/scripts/canvas_tool_curve/canvas_tool_curve.gml.backup1 @@ -0,0 +1,4 @@ +// 2024-04-14 12:31:12 +function canvas_tool_curve() : canvas_tool() constructor { + +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_node/canvas_tool_node.gml.backup0 b/#backups/scripts/canvas_tool_node/canvas_tool_node.gml.backup0 new file mode 100644 index 000000000..a28f04ae5 --- /dev/null +++ b/#backups/scripts/canvas_tool_node/canvas_tool_node.gml.backup0 @@ -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; } + } + +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_node/canvas_tool_node.gml.backup1 b/#backups/scripts/canvas_tool_node/canvas_tool_node.gml.backup1 new file mode 100644 index 000000000..3a22c396d --- /dev/null +++ b/#backups/scripts/canvas_tool_node/canvas_tool_node.gml.backup1 @@ -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; } + } + +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_resize/canvas_tool_resize.gml.backup0 b/#backups/scripts/canvas_tool_resize/canvas_tool_resize.gml.backup0 new file mode 100644 index 000000000..1e79e17a8 --- /dev/null +++ b/#backups/scripts/canvas_tool_resize/canvas_tool_resize.gml.backup0 @@ -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 ]; + } + } + +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_resize/canvas_tool_resize.gml.backup1 b/#backups/scripts/canvas_tool_resize/canvas_tool_resize.gml.backup1 new file mode 100644 index 000000000..e4004976f --- /dev/null +++ b/#backups/scripts/canvas_tool_resize/canvas_tool_resize.gml.backup1 @@ -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 ]; + } + } + +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection/canvas_tool_selection.gml.backup0 b/#backups/scripts/canvas_tool_selection/canvas_tool_selection.gml.backup0 new file mode 100644 index 000000000..a1b8585e4 --- /dev/null +++ b/#backups/scripts/canvas_tool_selection/canvas_tool_selection.gml.backup0 @@ -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 +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection/canvas_tool_selection.gml.backup1 b/#backups/scripts/canvas_tool_selection/canvas_tool_selection.gml.backup1 new file mode 100644 index 000000000..ce6f6c832 --- /dev/null +++ b/#backups/scripts/canvas_tool_selection/canvas_tool_selection.gml.backup1 @@ -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 +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection_brush/canvas_tool_selection_brush.gml.backup0 b/#backups/scripts/canvas_tool_selection_brush/canvas_tool_selection_brush.gml.backup0 new file mode 100644 index 000000000..8b6b98230 --- /dev/null +++ b/#backups/scripts/canvas_tool_selection_brush/canvas_tool_selection_brush.gml.backup0 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection_brush/canvas_tool_selection_brush.gml.backup1 b/#backups/scripts/canvas_tool_selection_brush/canvas_tool_selection_brush.gml.backup1 new file mode 100644 index 000000000..96e3c76a6 --- /dev/null +++ b/#backups/scripts/canvas_tool_selection_brush/canvas_tool_selection_brush.gml.backup1 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection_freeform/canvas_tool_selection_freeform.gml.backup0 b/#backups/scripts/canvas_tool_selection_freeform/canvas_tool_selection_freeform.gml.backup0 new file mode 100644 index 000000000..d6650145d --- /dev/null +++ b/#backups/scripts/canvas_tool_selection_freeform/canvas_tool_selection_freeform.gml.backup0 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection_freeform/canvas_tool_selection_freeform.gml.backup1 b/#backups/scripts/canvas_tool_selection_freeform/canvas_tool_selection_freeform.gml.backup1 new file mode 100644 index 000000000..74d23c983 --- /dev/null +++ b/#backups/scripts/canvas_tool_selection_freeform/canvas_tool_selection_freeform.gml.backup1 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection_magic/canvas_tool_selection_magic.gml.backup0 b/#backups/scripts/canvas_tool_selection_magic/canvas_tool_selection_magic.gml.backup0 new file mode 100644 index 000000000..8e389e2da --- /dev/null +++ b/#backups/scripts/canvas_tool_selection_magic/canvas_tool_selection_magic.gml.backup0 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection_magic/canvas_tool_selection_magic.gml.backup1 b/#backups/scripts/canvas_tool_selection_magic/canvas_tool_selection_magic.gml.backup1 new file mode 100644 index 000000000..bc61105ce --- /dev/null +++ b/#backups/scripts/canvas_tool_selection_magic/canvas_tool_selection_magic.gml.backup1 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection_shape/canvas_tool_selection_shape.gml.backup0 b/#backups/scripts/canvas_tool_selection_shape/canvas_tool_selection_shape.gml.backup0 new file mode 100644 index 000000000..f76796816 --- /dev/null +++ b/#backups/scripts/canvas_tool_selection_shape/canvas_tool_selection_shape.gml.backup0 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/canvas_tool_selection_shape/canvas_tool_selection_shape.gml.backup1 b/#backups/scripts/canvas_tool_selection_shape/canvas_tool_selection_shape.gml.backup1 new file mode 100644 index 000000000..aae70b2f6 --- /dev/null +++ b/#backups/scripts/canvas_tool_selection_shape/canvas_tool_selection_shape.gml.backup1 @@ -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); + } +} \ No newline at end of file diff --git a/#backups/scripts/node_canvas/node_canvas.gml.backup0 b/#backups/scripts/node_canvas/node_canvas.gml.backup0 new file mode 100644 index 000000000..4087dff77 --- /dev/null +++ b/#backups/scripts/node_canvas/node_canvas.gml.backup0 @@ -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 +} \ No newline at end of file diff --git a/#backups/scripts/node_canvas/node_canvas.gml.backup1 b/#backups/scripts/node_canvas/node_canvas.gml.backup1 new file mode 100644 index 000000000..b19cf1708 --- /dev/null +++ b/#backups/scripts/node_canvas/node_canvas.gml.backup1 @@ -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 +} \ No newline at end of file diff --git a/#backups/scripts/panel_inspector/panel_inspector.gml.backup0 b/#backups/scripts/panel_inspector/panel_inspector.gml.backup0 new file mode 100644 index 000000000..308595b0f --- /dev/null +++ b/#backups/scripts/panel_inspector/panel_inspector.gml.backup0 @@ -0,0 +1,1028 @@ +// 2024-04-14 12:24:14 +#region funtion calls + function __fnInit_Inspector() { + __registerFunction("inspector_copy_prop", panel_inspector_copy_prop); + __registerFunction("inspector_paste_prop", panel_inspector_paste_prop); + __registerFunction("inspector_toggle_animation", panel_inspector_toggle_animation); + + __registerFunction("inspector_color_pick", panel_inspector_color_pick); + } + + function panel_inspector_copy_prop() { CALL("inspector_copy_prop"); PANEL_INSPECTOR.propSelectCopy(); } + function panel_inspector_paste_prop() { CALL("inspector_paste_prop"); PANEL_INSPECTOR.propSelectPaste(); } + function panel_inspector_toggle_animation() { CALL("inspector_toggle_animation"); PANEL_INSPECTOR.anim_toggling = true; } + + function panel_inspector_color_pick() { CALL("inspector_color_pick"); if(!PREFERENCES.alt_picker) return; PANEL_INSPECTOR.color_picking = true; } +#endregion + +function Inspector_Custom_Renderer(drawFn, registerFn = noone) : widget() constructor { #region + h = 64; + self.draw = drawFn; + + if(registerFn != noone) register = registerFn; + else { + register = function(parent = noone) { + if(!interactable) return; + self.parent = parent; + } + } +} #endregion + +function Inspector_Sprite(spr) constructor { self.spr = spr; } + +function Inspector_Spacer(height, line = false) constructor { self.h = height; self.line = line; } + +function Panel_Inspector() : PanelContent() constructor { + #region ---- main ---- + title = __txt("Inspector"); + context_str = "Inspector"; + icon = THEME.panel_inspector_icon; + + w = ui(400); + h = ui(640); + min_w = ui(160); + + locked = false; + inspecting = noone; + inspectings = []; + inspectGroup = false; + top_bar_h = ui(100); + + static initSize = function() { + content_w = w - ui(32); + content_h = h - top_bar_h - ui(12); + } + initSize(); + + view_mode_tooltip = new tooltipSelector("View", [ "Compact", "Spacious" ]) + #endregion + + #region ---- properties ---- + prop_hover = noone; + prop_selecting = noone; + + prop_highlight = noone; + prop_highlight_time = 0; + + prop_dragging = noone; + prop_sel_drag_x = 0; + prop_sel_drag_y = 0; + + color_picking = false; + + picker_index = 0; + picker_change = false; + #endregion + + globalvar_viewer_init(); + drawWidgetInit(); + + #region ---- header labels ---- + tb_node_name = new textBox(TEXTBOX_INPUT.text, function(txt) { + if(inspecting) inspecting.setDisplayName(txt); + }) + + tb_prop_filter = new textBox(TEXTBOX_INPUT.text, function(txt) { filter_text = txt; }) + tb_prop_filter.no_empty = false; + tb_prop_filter.auto_update = true; + tb_prop_filter.font = f_p0; + tb_prop_filter.color = COLORS._main_text_sub; + tb_prop_filter.align = fa_center; + tb_prop_filter.hide = true; + filter_text = ""; + + prop_page_button = new buttonGroup([ "Properties", "Settings" ], function(val) { prop_page = val; }); + prop_page_button.buttonSpr = [ THEME.button_hide_left, THEME.button_hide_middle, THEME.button_hide_right ]; + prop_page_button.font = f_p1; + prop_page_button.fColor = COLORS._main_text_sub; + prop_page = 0; + #endregion + + #region ---- metadata ---- + current_meta = -1; + meta_tb[0] = new textArea(TEXTBOX_INPUT.text, function(str) { current_meta.description = str; }); + meta_tb[1] = new textArea(TEXTBOX_INPUT.text, function(str) { current_meta.author = str; }); + meta_tb[2] = new textArea(TEXTBOX_INPUT.text, function(str) { current_meta.contact = str; }); + meta_tb[3] = new textArea(TEXTBOX_INPUT.text, function(str) { current_meta.alias = str; }); + meta_tb[4] = new textArrayBox(noone, META_TAGS); + for( var i = 0, n = array_length(meta_tb); i < n; i++ ) + meta_tb[i].hide = true; + + meta_display = [ + [ __txt("Project Settings"), false ], + [ __txt("Metadata"), true ], + [ __txtx("panel_globalvar", "Global variables"), true, button(function() { panelAdd("Panel_Globalvar", true); }, THEME.node_goto).setIcon(THEME.node_goto, 0, COLORS._main_icon) ], + [ __txt("Group Properties"), true ], + ]; + #endregion + + #region ---- workshop ---- + workshop_uploading = false; + #endregion + + #region ++++ hotkeys ++++ + addHotkey("Inspector", "Copy property", "C", MOD_KEY.ctrl, panel_inspector_copy_prop); + addHotkey("Inspector", "Paste property", "V", MOD_KEY.ctrl, panel_inspector_paste_prop); + addHotkey("Inspector", "Toggle animation", "I", MOD_KEY.none, panel_inspector_toggle_animation); + + addHotkey("", "Color picker", "", MOD_KEY.alt, panel_inspector_color_pick); + #endregion + + #region ++++ menus ++++ + static nodeExpandAll = function(node) { + if(node.input_display_list == -1) return; + + var dlist = node.input_display_list; + for( var i = 0, n = array_length(dlist); i < n; i++ ) { + if(!is_array(dlist[i])) continue; + dlist[i][@ 1] = false; + } + } + + static nodeCollapseAll = function(node) { + if(node.input_display_list == -1) return; + + var dlist = node.input_display_list; + for( var i = 0, n = array_length(dlist); i < n; i++ ) { + if(!is_array(dlist[i])) continue; + dlist[i][@ 1] = true; + } + } + + group_menu = [ + menuItem(__txt("Expand all"), function() { + if(inspecting != noone) nodeExpandAll(inspecting); + for( var i = 0, n = array_length(inspectings); i < n; i++ ) + nodeExpandAll(inspectings[i]); + }), + menuItem(__txt("Collapse all"), function() { + if(inspecting != noone) nodeCollapseAll(inspecting); + for( var i = 0, n = array_length(inspectings); i < n; i++ ) + nodeCollapseAll(inspectings[i]); + }), + ] + + __dialog_junction = noone; + menu_junc_reset_value = menuItem(__txtx("panel_inspector_reset", "Reset value"), function() { __dialog_junction.resetValue(); }); + menu_junc_add_anim = menuItem(__txtx("panel_inspector_add", "Add animation"), function() { __dialog_junction.setAnim(true); }); + menu_junc_rem_anim = menuItem(__txtx("panel_inspector_remove", "Remove animation"), function() { __dialog_junction.setAnim(false); }); + menu_junc_combine_axis = menuItem(__txtx("panel_inspector_axis_combine", "Combine axis"), function() { __dialog_junction.sep_axis = false; }); + menu_junc_separate_axis = menuItem(__txtx("panel_inspector_axis_separate", "Separate axis"), function() { __dialog_junction.sep_axis = true; }); + menu_junc_expression_ena = menuItem(__txtx("panel_inspector_use_expression", "Use expression"), function() { __dialog_junction.expUse = true; }); + menu_junc_expression_dis = menuItem(__txtx("panel_inspector_disable_expression", "Disable expression"), function() { __dialog_junction.expUse = false; }); + menu_junc_extract = menuItem(__txtx("panel_inspector_extract_single", "Extract to node"), function() { __dialog_junction.extractNode(); }); + + menu_junc_copy = menuItem(__txt("Copy"), function() { clipboard_set_text(__dialog_junction.getShowString()); }, THEME.copy, ["Inspector", "Copy property"]); + menu_junc_paste = menuItem(__txt("Paste"), function() { __dialog_junction.setString(clipboard_get_text()); }, THEME.paste, ["Inspector", "Paste property"]); + + function setSelectingItemColor(color) { + if(__dialog_junction == noone) return; + + __dialog_junction.setColor(color); + + var _val_to = __dialog_junction.getJunctionTo(); + for( var i = 0, n = array_length(_val_to); i < n; i++ ) + _val_to[i].setColor(color); + } + + var _clrs = COLORS.labels; + var _item = array_create(array_length(_clrs)); + + for( var i = 0, n = array_length(_clrs); i < n; i++ ) { + _item[i] = [ + [ THEME.timeline_color, i > 0, _clrs[i] ], + function(_data) { + setSelectingItemColor(_data.color); + }, "", { color: i == 0? -1 : _clrs[i] } + ]; + } + + array_push(_item, [ + [ THEME.timeline_color, 2 ], + function(_data) { + colorSelectorCall(__dialog_junction? __dialog_junction.color : c_white, setSelectingItemColor); + } + ]); + + menu_junc_color = menuItemGroup(__txt("Color"), _item); + menu_junc_color.spacing = ui(24); + #endregion + + function setInspecting(inspecting) { #region + if(locked) return; + + self.inspecting = inspecting; + + if(inspecting != noone) + inspecting.onInspect(); + contentPane.scroll_y = 0; + contentPane.scroll_y_to = 0; + + picker_index = 0; + } #endregion + + function getInspecting() { #region + if(inspecting == noone) return noone; + return inspecting.active? inspecting : noone; + } #endregion + + function onFocusBegin() { PANEL_INSPECTOR = self; } + + function onResize() { #region + initSize(); + contentPane.resize(content_w, content_h); + } #endregion + + static drawMeta = function(_y, _m) { #region + var con_w = contentPane.surface_w - ui(4); + var _hover = pHOVER && contentPane.hover; + + var context = PANEL_GRAPH.getCurrentContext(); + var meta = context == noone? PROJECT.meta : context.metadata; + if(meta == noone) return 0; + current_meta = meta; + + var hh = ui(8); + var yy = _y + ui(8); + + var rx = x + ui(16); + var ry = y + top_bar_h; + + attribute_hovering = noone; + + for( var i = 0, n = array_length(meta_display); i < n; i++ ) { + if(i == 3) { + var context = PANEL_GRAPH.getCurrentContext(); + if(context == noone) continue; + } + + var _meta = meta_display[i]; + var _txt = array_safe_get_fast(_meta, 0); + var _b = array_safe_get_fast(_meta, 2, noone); + var _x1 = con_w - (_b != noone) * ui(30); + + if(_hover && point_in_rectangle(_m[0], _m[1], 0, yy, _x1, yy + ui(32))) { + draw_sprite_stretched_ext(THEME.group_label, 0, 0, yy, con_w, ui(32), COLORS.panel_inspector_group_hover, 1); + + if(mouse_press(mb_left, pFOCUS)) + meta_display[i][1] = !meta_display[i][1]; + } else + draw_sprite_stretched_ext(THEME.group_label, 0, 0, yy, con_w, ui(32), COLORS.panel_inspector_group_bg, 1); + + if(_b != noone) { + _b.setFocusHover(pFOCUS, _hover); + _b.draw(_x1, yy + ui(2), ui(28), ui(28), _m, THEME.button_hide_fill); + } + + draw_sprite_ui(THEME.arrow, meta_display[i][1]? 0 : 3, ui(16), yy + ui(32) / 2, 1, 1, 0, COLORS.panel_inspector_group_bg, 1); + + draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_inner); + draw_text_add(ui(32), yy + ui(32) / 2, _txt); + + yy += ui(32 + 8); + hh += ui(32 + 8); + + if(meta_display[i][1]) { + yy += ui(4); + hh += ui(4); + continue; + } + + switch(i) { + case 0 : + var _edt = PROJECT.attributeEditor; + for( var j = 0; j < array_length(_edt); j++ ) { + var title = _edt[j][0]; + var param = _edt[j][1]; + var editW = _edt[j][2]; + var drpFn = _edt[j][3]; + + var widx = ui(8); + var widy = yy; + + draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text_inner); + draw_text_add(ui(16), yy, __txt(title)); + yy += line_get_height() + ui(6); + hh += line_get_height() + ui(6); + + editW.setFocusHover(pFOCUS, _hover); + if(pFOCUS) editW.register(contentPane); + + var wh = 0; + var _data = PROJECT.attributes[$ param]; + var _param = new widgetParam(ui(16), yy, w - ui(16 + 48), TEXTBOX_HEIGHT, _data, {}, _m, rx, ry); + + wh = editW.drawParam(_param); + + var jun = PANEL_GRAPH.value_dragging; + var widw = con_w - ui(16); + var widh = line_get_height() + ui(6) + wh + ui(4); + + if(jun != noone && _hover && point_in_rectangle(_m[0], _m[1], widx, widy, widx + widw, widy + widh)) { + draw_sprite_stretched_ext(THEME.ui_panel_active, 0, widx, widy, widw, widh, COLORS._main_value_positive, 1); + attribute_hovering = drpFn; + } + + yy += wh + ui(8); + hh += wh + ui(8); + } + break; + case 1 : + for( var j = 0; j < array_length(meta.displays); j++ ) { + var display = meta.displays[j]; + + draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text_inner); + draw_text_add(ui(16), yy, __txt(display[0])); + yy += line_get_height() + ui(6); + hh += line_get_height() + ui(6); + + meta_tb[j].setFocusHover(pFOCUS, _hover); + if(pFOCUS) meta_tb[j].register(contentPane); + + var wh = 0; + var _dataFunc = display[1]; + var _data = _dataFunc(meta); + + switch(instanceof(meta_tb[j])) { + case "textArea" : + wh = meta_tb[j].draw(ui(16), yy, w - ui(16 + 48), display[2], _data, _m); + break; + case "textArrayBox" : + meta_tb[j].arraySet = current_meta.tags; + wh = meta_tb[j].draw(ui(16), yy, w - ui(16 + 48), display[2], _m, rx, ry); + break; + } + + yy += wh + ui(8); + hh += wh + ui(8); + } + break; + case 2 : + if(findPanel("Panel_Globalvar")) { + yy += ui(4); + hh += ui(4); + continue; + } + + var gvh = globalvar_viewer_draw(ui(16), yy, contentPane.surface_w - ui(24), _m, pFOCUS, _hover, contentPane, ui(16) + x, top_bar_h + y); + yy += gvh + ui(8); + hh += gvh + ui(8); + + var bh = ui(36); + var bx = ui(16); + var by = yy; + var bbw = contentPane.surface_w - ui(24); + + if(var_editing) { + var bw = bbw / 2 - ui(4); + + if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, pFOCUS, _hover) == 2) + var_editing = !var_editing; + + var txt = __txt("Apply"); + var icon = THEME.accept; + var colr = COLORS._main_value_positive; + + draw_set_text(f_p0b, fa_left, fa_center, COLORS._main_icon) + var bxc = bx + bw / 2 - (string_width(txt) + ui(48)) / 2; + var byc = by + bh / 2; + draw_sprite_ui(icon, 0, bxc + ui(24), byc,,,, colr); + draw_text_add(bxc + ui(48), byc, txt); + + bx += bw + ui(4); + + if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, pFOCUS, _hover) == 2) + PROJECT.globalNode.createValue(); + + var txt = __txt("Add"); + var icon = THEME.add; + + draw_set_text(f_p0b, fa_left, fa_center, COLORS._main_icon) + var bxc = bx + bw / 2 - (string_width(txt) + ui(48)) / 2; + var byc = by + bh / 2; + draw_sprite_ui(icon, 0, bxc + ui(24), byc,,,, colr); + draw_text_add(bxc + ui(48), byc, txt); + } else { + var bw = bbw; + + if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, pFOCUS, _hover) == 2) + var_editing = !var_editing; + + var txt = __txt("Edit"); + var icon = THEME.gear; + var colr = COLORS._main_icon; + + draw_set_text(f_p0b, fa_left, fa_center, colr) + var bxc = bx + bw / 2 - (string_width(txt) + ui(48)) / 2; + var byc = by + bh / 2; + draw_sprite_ui(icon, 0, bxc + ui(24), byc,,,, colr); + draw_text_add(bxc + ui(48), byc, txt); + } + break; + case 3 : + var context = PANEL_GRAPH.getCurrentContext(); + var _h = drawNodeProperties(yy, _m, context); + + yy += _h; + hh += _h; + break; + } + + yy += ui(8); + hh += ui(8); + } + + return hh; + } #endregion + + static highlightProp = function(prop) { #region + prop_highlight = prop; + prop_highlight_time = 60; + } #endregion + + static drawNodeProperties = function(_y, _m, _inspecting = inspecting) { #region + var con_w = contentPane.surface_w - ui(4); + var _hover = pHOVER && contentPane.hover; + + _inspecting.inspecting = true; + prop_hover = noone; + var jun = noone; + var amoIn = _inspecting.input_display_list == -1? ds_list_size(_inspecting.inputs) : array_length(_inspecting.input_display_list); + var amoOut = ds_list_size(_inspecting.outputs); + var amo = inspectGroup == 0? amoIn + 1 + amoOut : amoIn; + var hh = 0; + + //tb_prop_filter.register(contentPane); + //tb_prop_filter.setFocusHover(pHOVER, pFOCUS); + //tb_prop_filter.draw(ui(32), _y + ui(4), con_w - ui(64), ui(28), filter_text, _m); + //draw_sprite_ui(THEME.search, 0, ui(32 + 16), _y + ui(4 + 14), 1, 1, 0, COLORS._main_icon, 1); + + var xc = con_w / 2; + + if(prop_page == 1) { #region attribute/settings editor + hh += ui(8); + var hg = ui(32); + var yy = _y + hh; + var wx1 = con_w - ui(8); + var ww = max(ui(180), con_w / 3); + var wx0 = wx1 - ww; + + for( var i = 0, n = array_length(_inspecting.attributeEditors); i < n; i++ ) { + var edt = _inspecting.attributeEditors[i]; + + if(is_string(edt)) { + var lby = yy + ui(12); + draw_set_alpha(0.5); + draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text_sub); + draw_text_add(xc, lby, edt); + + var lbw = string_width(edt) / 2; + draw_set_color(COLORS._main_text_sub); + draw_line_round(xc + lbw + ui(16), lby, wx1, lby, 2); + draw_line_round(xc - lbw - ui(16), lby, ui(8), lby, 2); + draw_set_alpha(1.0); + + yy += ui(32); + hh += ui(32); + continue; + } + + var val = edt[1](); + edt[2].setFocusHover(pFOCUS, pHOVER); + + if(instanceof(edt[2]) == "buttonClass") { + edt[2].text = edt[0]; + edt[2].draw(ui(8), yy, con_w - ui(16), hg, _m); + + yy += hg + ui(8); + hh += hg + ui(8); + continue; + } + + draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text); + draw_text_add(ui(8), yy + hg / 2, edt[0]); + + var _param = new widgetParam(wx0, yy, ww, hg, val, {}, _m, x + contentPane.x, y + contentPane.y); + _param.s = hg; + edt[2].drawParam(_param); + + yy += hg + ui(8); + hh += hg + ui(8); + } + return hh; + } #endregion + + var color_picker_selecting = noone; + var color_picker_index = 0; + var pickers = []; + var _colsp = false; + + for(var i = 0; i < amo; i++) { + var yy = hh + _y; + + if(i < amoIn) { #region inputs + if(_inspecting.input_display_list == -1) { + jun = _inspecting.inputs[| i]; + } else { + if(i >= array_length(_inspecting.input_display_list)) break; + var jun_disp = _inspecting.input_display_list[i]; + if(is_instanceof(jun_disp, Inspector_Spacer)) { // SPACER + var _hh = ui(jun_disp.h); + var _yy = yy + _hh / 2 - ui(2); + + if(jun_disp.line) { + draw_set_color(COLORS.panel_inspector_key_separator); + draw_line(ui(8), _yy, con_w - ui(8), _yy); + } + + hh += _hh; + continue; + + } else if(is_instanceof(jun_disp, Inspector_Sprite)) { // SPRITE + var _spr = jun_disp.spr; + var _sh = sprite_get_height(_spr); + + draw_sprite(_spr, 0, xc, yy); + + hh += _sh + ui(8); + continue; + + } else if(is_array(jun_disp)) { // LABEL + var pad = i && _colsp == false? ui(4) : 0 + _colsp = false; + yy += pad; + + var txt = __txt(jun_disp[0]); + var coll = jun_disp[1] && filter_text == ""; + var lbh = viewMode? ui(32) : ui(26); + var togl = array_safe_get_fast(jun_disp, 2, noone); + if(togl != noone) var toging = _inspecting.getInputData(togl); + + var lbx = (togl != noone) * ui(40); + var lbw = con_w - lbx; + var ltx = lbx + ui(32); + + if(_hover && point_in_rectangle(_m[0], _m[1], lbx, yy, con_w, yy + lbh)) { + draw_sprite_stretched_ext(THEME.group_label, 0, lbx, yy, lbw, lbh, COLORS.panel_inspector_group_hover, 1); + + if(mouse_press(mb_left, pFOCUS)) + jun_disp[@ 1] = !coll; + if(mouse_press(mb_right, pFOCUS)) + menuCall("inspector_group_menu",,, group_menu,, _inspecting); + } else + draw_sprite_stretched_ext(THEME.group_label, 0, lbx, yy, lbw, lbh, COLORS.panel_inspector_group_bg, 1); + + if(filter_text == "") + draw_sprite_ui(THEME.arrow, 0, lbx + ui(16), yy + lbh / 2, 1, 1, -90 + coll * 90, COLORS.panel_inspector_group_bg, 1); + + var cc, aa = 1; + + if(togl != noone) { + if(_hover && point_in_rectangle(_m[0], _m[1], 0, yy, ui(32), yy + lbh)) { + draw_sprite_stretched_ext(THEME.group_label, 0, 0, yy, ui(32), lbh, COLORS.panel_inspector_group_hover, 1); + + if(mouse_press(mb_left, pFOCUS)) + _inspecting.inputs[| togl].setValue(!toging); + } else + draw_sprite_stretched_ext(THEME.group_label, 0, 0, yy, ui(32), lbh, COLORS.panel_inspector_group_bg, 1); + + cc = toging? COLORS._main_accent : COLORS.panel_inspector_group_bg; + aa = 0.5 + toging * 0.5; + + draw_sprite_ui(THEME.inspector_checkbox, 0, ui(16), yy + lbh / 2, 1, 1, 0, cc, 1); + if(toging) + draw_sprite_ui(THEME.inspector_checkbox, 1, ui(16), yy + lbh / 2, 1, 1, 0, cc, 1); + } + + draw_set_alpha(aa); + draw_set_text(viewMode? f_p0 : f_p1, fa_left, fa_center, COLORS._main_text); + draw_text_add(ltx, yy + lbh / 2, txt); + draw_set_alpha(1); + + hh += lbh + ui(viewMode? 8 : 6) + pad; + + if(coll) { // skip + _colsp = true; + var j = i + 1; + var _len = array_length(_inspecting.input_display_list); + + while(j < _len) { + var j_jun = _inspecting.input_display_list[j]; + if(is_array(j_jun)) + break; + j++; + } + + i = j - 1; + } + + continue; + + } else if(is_struct(jun_disp) && instanceof(jun_disp) == "Inspector_Custom_Renderer") { + jun_disp.register(contentPane); + jun_disp.rx = ui(16) + x; + jun_disp.ry = top_bar_h + y; + + hh += jun_disp.draw(ui(6), yy, con_w - ui(12), _m, _hover, pFOCUS) + ui(8); + continue; + } + jun = _inspecting.inputs[| _inspecting.input_display_list[i]]; + } + #endregion + } else if(i == amoIn) { #region output label + hh += ui(8 + 32 + 8); + + draw_sprite_stretched_ext(THEME.group_label, 0, 0, yy + ui(8), con_w, ui(32), COLORS.panel_inspector_output_label, 0.8); + draw_set_text(f_p0b, fa_center, fa_center, COLORS._main_text_sub); + draw_text_add(xc, yy + ui(8 + 16), __txt("Outputs")); + continue; + #endregion + } else { #region outputs + var outInd = i - amoIn - 1; + jun = _inspecting.outputs[| outInd]; + #endregion + } + + if(!is_struct(jun)) continue; + if(instanceof(jun) != "NodeValue") continue; + + if(!jun.show_in_inspector || jun.type == VALUE_TYPE.object) continue; + if(filter_text != "") { + var pos = string_pos(filter_text, string_lower(jun.getName())); + if(pos == 0) continue; + } + + #region ++++ draw widget ++++ + var _font = viewMode == INSP_VIEW_MODE.spacious? f_p0 : f_p2; + + var lb_h = line_get_height(_font) + ui(8); + var lb_w = line_get_width(jun.getName(), _font) + ui(16); + var lb_x = ui(48) + (ui(24) * (jun.color != -1)); + var padd = ui(8); + + var _selY = yy; + + var widg = drawWidget(ui(16), yy, contentPane.surface_w - ui(24), _m, jun, false, pHOVER && contentPane.hover, pFOCUS, contentPane, ui(16) + x, top_bar_h + y); + var widH = widg[0]; + var mbRight = widg[1]; + + var lbHov = point_in_rectangle(_m[0], _m[1], lb_x, _selY + ui(2), lb_x + lb_w, _selY + lb_h - ui(4)); + if(lbHov) draw_sprite_stretched_ext(THEME.button_hide, 1, lb_x, _selY + ui(2), lb_w, lb_h - ui(6), COLORS._main_icon, 1); + + hh += lb_h + widH + padd; + + var _selY1 = yy + lb_h + widH + ui(2); + var _selH = _selY1 - _selY + (viewMode * ui(4)); + + if(jun == prop_highlight && prop_highlight_time) { + if(prop_highlight_time == 60) + contentPane.setScroll(_y - yy); + var aa = min(1, prop_highlight_time / 30); + draw_sprite_stretched_ext(THEME.ui_panel_active, 0, ui(4), yy, contentPane.surface_w - ui(4), _selH, COLORS._main_accent, aa); + } + + if(_hover && lbHov && prop_dragging == noone && mouse_press(mb_left, pFOCUS)) { + prop_dragging = jun; + + prop_sel_drag_x = mouse_mx; + prop_sel_drag_y = mouse_my; + } + #endregion + + if(jun.connect_type == JUNCTION_CONNECT.input && jun.type == VALUE_TYPE.color && jun.display_type == VALUE_DISPLAY._default) { #region color picker + pickers[color_picker_index] = jun; + color_picker_index++; + } #endregion + + if(_hover && point_in_rectangle(_m[0], _m[1], ui(4), _selY, contentPane.surface_w - ui(4), _selY + _selH)) { #region mouse in widget + _HOVERING_ELEMENT = jun; + + var hov = PANEL_GRAPH.value_dragging != noone || (NODE_DROPPER_TARGET != noone && NODE_DROPPER_TARGET != jun); + + if(hov) { + draw_sprite_stretched_ext(THEME.ui_panel_active, 0, ui(4), _selY, contentPane.surface_w - ui(8), _selH, COLORS._main_value_positive, 1); + if(mouse_press(mb_left, NODE_DROPPER_TARGET_CAN)) { + NODE_DROPPER_TARGET.expression += $"{jun.node.internalName}.{jun.connect_type == JUNCTION_CONNECT.input? "inputs" : "outputs"}.{jun.internalName}"; + NODE_DROPPER_TARGET.expressionUpdate(); + } + } else + draw_sprite_stretched_ext(THEME.prop_selecting, 0, ui(4), _selY, contentPane.surface_w - ui(8), _selH, COLORS._main_accent, 1); + + if(anim_toggling) { + jun.setAnim(!jun.is_anim); + anim_toggling = false; + } + + prop_hover = jun; + + if(mouse_press(mb_left, pFOCUS)) + prop_selecting = jun; + + if(mouse_press(mb_right, pFOCUS && mbRight)) { #region right click menu + var _menuItem = [ menu_junc_color, -1 ]; + + if(i < amoIn) { + array_push(_menuItem, menu_junc_reset_value, jun.is_anim? menu_junc_rem_anim : menu_junc_add_anim); + if(jun.sepable) array_push(_menuItem, jun.sep_axis? menu_junc_combine_axis : menu_junc_separate_axis); + array_push(_menuItem, -1); + } + + array_push(_menuItem, jun.expUse? menu_junc_expression_dis : menu_junc_expression_ena, -1, menu_junc_copy); + if(jun.connect_type == JUNCTION_CONNECT.input) + array_push(_menuItem, menu_junc_paste); + + if(jun.connect_type == JUNCTION_CONNECT.input && jun.extract_node != "") { + if(is_array(jun.extract_node)) { + var ext = menuItem(__txtx("panel_inspector_extract_multiple", "Extract to..."), function(_dat) { + var arr = []; + for(var i = 0; i < array_length(__dialog_junction.extract_node); i++) { + var _rec = __dialog_junction.extract_node[i]; + array_push(arr, menuItem(_rec, function(_dat) { __dialog_junction.extractNode(_dat.name); })); + } + + return submenuCall(_dat, arr); + }).setIsShelf(); + array_push(_menuItem, ext); + } else + array_push(_menuItem, menu_junc_extract); + } + + var dia = menuCall("inspector_value_menu",,, _menuItem,, jun); + __dialog_junction = jun; + } #endregion + } #endregion + } + + #region color picker + if(key_mod_press(ALT) && color_picker_index) { + pickers[picker_index].editWidget.onColorPick(); + } + + if(MESSAGE != noone && MESSAGE.type == "Color") { + var inp = array_safe_get_fast(pickers, picker_index, 0); + if(is_struct(inp)) { + inp.setValue(MESSAGE.data); + MESSAGE = noone; + } + } + + color_picking = false; + #endregion + + #region drag + if(prop_dragging) { + if(DRAGGING == noone && point_distance(prop_sel_drag_x, prop_sel_drag_y, mouse_mx, mouse_my) > 16) { + prop_dragging.dragValue(); + prop_dragging = noone; + } + + if(mouse_release(mb_left)) + prop_dragging = noone; + } + #endregion + + if(prop_highlight_time) { + prop_highlight_time--; + if(prop_highlight_time == 0) + prop_highlight = noone; + } + + return hh; + } #endregion + + contentPane = new scrollPane(content_w, content_h, function(_y, _m) { #region + var con_w = contentPane.surface_w - ui(4); + + draw_clear_alpha(COLORS.panel_bg_clear, 0); + + if(point_in_rectangle(_m[0], _m[1], 0, 0, con_w, content_h) && mouse_press(mb_left, pFOCUS)) + prop_selecting = noone; + + if(inspecting == noone) return drawMeta(_y, _m); + + prop_page_button.setFocusHover(pFOCUS, pHOVER); + prop_page_button.draw(ui(32), _y + ui(4), contentPane.w - ui(76), ui(28), prop_page, _m, x + contentPane.x, y + contentPane.y); + + var _hh = ui(40); + _y += _hh; + + if(is_instanceof(inspecting, Node_Canvas) && inspecting.nodeTool != noone && is_instanceof(inspecting.nodeTool.nodeObject, Node)) + return drawNodeProperties(_y, _m, inspecting.nodeTool.nodeObject); + + if(inspectGroup >= 0) + return drawNodeProperties(_y, _m, inspecting); + + for( var i = 0, n = min(10, array_length(inspectings)); i < n; i++ ) { + if(i) { + _y += ui(8); + _hh += ui(8); + } + + if(n > 1) { + draw_sprite_stretched_ext(THEME.group_label, 0, 0, _y, con_w, ui(32), COLORS.panel_inspector_output_label, 0.9); + draw_set_text(f_p0b, fa_center, fa_center, COLORS._main_text_sub); + + var _tx = inspectings[i].getFullName(); + draw_text_add(con_w / 2, _y + ui(16), _tx); + + _y += ui(32 + 8); + _hh += ui(32 + 8); + } + + var _h = drawNodeProperties(_y, _m, inspectings[i]); + _y += _h; + _hh += _h; + } + + return _hh; + }); #endregion + + function propSelectCopy() { #region + if(!prop_selecting) return; + clipboard_set_text(prop_selecting.getShowString()); + } #endregion + + function propSelectPaste() { #region + if(!prop_selecting) return; + + prop_selecting.setString(clipboard_get_text()); + } #endregion + + function drawInspectingNode() { #region + tb_node_name.font = f_h5; + tb_node_name.hide = true; + tb_node_name.align = fa_center; + tb_node_name.format = TEXT_AREA_FORMAT.node_title; + tb_node_name.setFocusHover(pFOCUS, pHOVER); + + var txt = inspecting.renamed? inspecting.display_name : inspecting.name; + if(inspectGroup == 1) txt = $"[{array_length(PANEL_GRAPH.nodes_selecting)}] {txt}"; + else if(inspectGroup == -1) txt = $"[{array_length(PANEL_GRAPH.nodes_selecting)}] Multiple nodes"; + + tb_node_name.draw(ui(64), ui(14), w - ui(128), ui(32), txt, [mx, my]); + + if(inspectGroup >= 0) { + draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text_sub); + draw_text_add(w / 2 + ui(8), ui(56), inspecting.name); + + draw_set_text(f_p3, fa_center, fa_center, COLORS._main_text_sub); + draw_set_alpha(0.65); + draw_text_add(w / 2, ui(76), inspecting.internalName); + draw_set_alpha(1); + } + + var bx = ui(8); + var by = ui(12); + + if(inspectGroup == 0) { + draw_set_font(f_p1); + var lx = w / 2 - string_width(inspecting.name) / 2 - ui(10); + var ly = ui(56 - 8); + if(buttonInstant(THEME.button_hide, lx, ly, ui(16), ui(16), [mx, my], pFOCUS, pHOVER, __txt("Lock"), THEME.lock_12, !locked, locked? COLORS._main_icon_light : COLORS._main_icon) == 2) + locked = !locked; + + if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txt("Presets"), THEME.preset, 1) == 2) + dialogCall(o_dialog_preset, x + bx, y + by + ui(36), { "node": inspecting }); + } else { + draw_sprite_ui_uniform(THEME.preset, 1, bx + ui(32) / 2, by + ui(32) / 2, 1, COLORS._main_icon_dark); + } + + by += ui(36); + view_mode_tooltip.index = viewMode; + if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, view_mode_tooltip, THEME.inspector_view, viewMode) == 2) { + viewMode = !viewMode; + PREFERENCES.inspector_view_default = viewMode; + } + + //////////////////////////////////////////////////////////////////// INSPECTOR ACTIONS //////////////////////////////////////////////////////////////////// + + var bx = w - ui(44); + var by = ui(12); + + if(inspecting.hasInspector1Update(true)) { + var icon = inspecting.insp1UpdateIcon; + var ac = inspecting.insp1UpdateActive; + var cc = ac? icon[2] : COLORS._main_icon_dark; + var tt = inspecting.insp1UpdateTooltip; + if(inspectGroup) tt += " [All]"; + + if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS && ac, pHOVER && ac, tt, icon[0], icon[1], cc) == 2) { + if(inspectGroup == 1) { + for( var i = 0, n = array_length(inspectings); i < n; i++ ) inspectings[i].inspector1Update(); + } else + inspecting.inspector1Update(); + } + } else + draw_sprite_ui(THEME.sequence_control, 1, bx + ui(16), by + ui(16),,,, COLORS._main_icon_dark); + + if(inspecting.hasInspector2Update()) { + by += ui(36); + var icon = inspecting.insp2UpdateIcon; + var ac = inspecting.insp2UpdateActive; + var cc = ac? icon[2] : COLORS._main_icon_dark; + var tt = inspecting.insp2UpdateTooltip; + if(inspectGroup) tt += " [All]"; + + if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS && ac, pHOVER && ac, tt, icon[0], icon[1], cc) = 2) { + if(inspectGroup) { + for( var i = 0, n = array_length(inspectings); i < n; i++ ) inspectings[i].inspector2Update(); + } else + inspecting.inspector2Update(); + } + } + } #endregion + + function drawContent(panel) { #region >>>>>>>>>>>>>>>>>>>> MAIN DRAW <<<<<<<<<<<<<<<<<<<< + draw_clear_alpha(COLORS.panel_bg_clear, 0); + + draw_sprite_stretched(THEME.ui_panel_bg, 1, ui(8), top_bar_h - ui(8), w - ui(16), h - top_bar_h); + + if(inspecting && !inspecting.active) + inspecting = noone; + + if(inspecting) { + var _ins = instanceof(inspecting); + var _nodes = PANEL_GRAPH.nodes_selecting; + + inspectGroup = array_length(_nodes) > 1; + inspectings = array_empty(_nodes)? [ inspecting ] : _nodes; + + for( var i = 0, n = array_length(_nodes); i < n; i++ ) + if(instanceof(_nodes[i]) != _ins) { inspectGroup = -1; break; } + + title = inspecting.renamed? inspecting.display_name : inspecting.name; + inspecting.inspectorStep(); + drawInspectingNode(); + } else { + title = __txt("Inspector"); + + var txt = "Untitled"; + var context = PANEL_GRAPH.getCurrentContext(); + + if(context == noone && file_exists_empty(PROJECT.path)) + txt = string_replace(filename_name(PROJECT.path), filename_ext(PROJECT.path), ""); + else if(context != noone) + txt = context.name; + + draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); + draw_text_add(w / 2, ui(30), txt); + + if(PROJECT.meta.steam == FILE_STEAM_TYPE.steamOpen) { + var _tw = string_width(txt) / 2; + draw_sprite_ui(THEME.steam, 0, w / 2 - _tw - ui(16), ui(32),,,, COLORS._main_icon); + } + + var bx = w - ui(44); + var by = ui(12); + + if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txtx("panel_inspector_set_default", "Set Metadata as default"), THEME.save, 0, COLORS._main_icon) == 2) { + var path = DIRECTORY + "meta.json"; + json_save_struct(path, PROJECT.meta.serialize()); + } + + by += ui(36); + if(STEAM_ENABLED && !workshop_uploading) { + if(PROJECT.path == "") { + buttonInstant(noone, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txtx("panel_inspector_workshop_save", "Save file before upload"), THEME.workshop_upload, 0, COLORS._main_icon, 0.5); + } else { + if(PROJECT.meta.steam == FILE_STEAM_TYPE.local) { //project made locally + if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txtx("panel_inspector_workshop_upload", "Upload to Steam Workshop"), THEME.workshop_upload, 0, COLORS._main_icon) == 2) { + var s = PANEL_PREVIEW.getNodePreviewSurface(); + if(is_surface(s)) { + PROJECT.meta.author_steam_id = STEAM_USER_ID; + PROJECT.meta.steam = FILE_STEAM_TYPE.steamUpload; + SAVE_AT(PROJECT, PROJECT.path); + + steam_ugc_create_project(); + workshop_uploading = true; + } else + noti_warning("Please send any node to preview panel to use as a thumbnail.") + } + } + + if(PROJECT.meta.steam && PROJECT.meta.author_steam_id == STEAM_USER_ID) { + if(PROJECT.meta.steam == FILE_STEAM_TYPE.steamUpload) { + buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], false, pHOVER, __txtx("panel_inspector_workshop_restart", "Open project from the workshop tab to update."), THEME.workshop_update, 0, COLORS._main_icon); + } else if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txtx("panel_inspector_workshop_update", "Update Steam Workshop content"), THEME.workshop_update, 0, COLORS._main_icon) == 2) { + SAVE_AT(PROJECT, PROJECT.path); + steam_ugc_update_project(); + workshop_uploading = true; + } + } + } + } + + if(workshop_uploading) { + draw_sprite_ui(THEME.loading_s, 0, bx + ui(16), by + ui(16),,, current_time / 5, COLORS._main_icon); + if(STEAM_UGC_ITEM_UPLOADING == false) + workshop_uploading = false; + } + } + + contentPane.setFocusHover(pFOCUS, pHOVER); + contentPane.draw(ui(16), top_bar_h, mx - ui(16), my - top_bar_h); + + if(!locked && PANEL_GRAPH.getFocusingNode() && inspecting != PANEL_GRAPH.getFocusingNode()) + setInspecting(PANEL_GRAPH.getFocusingNode()); + } #endregion +} \ No newline at end of file diff --git a/#backups/shaders/sh_canvas_apply_draw/sh_canvas_apply_draw.fsh.backup0 b/#backups/shaders/sh_canvas_apply_draw/sh_canvas_apply_draw.fsh.backup0 new file mode 100644 index 000000000..82c6ebf66 --- /dev/null +++ b/#backups/shaders/sh_canvas_apply_draw/sh_canvas_apply_draw.fsh.backup0 @@ -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; +} diff --git a/#backups/shaders/sh_canvas_apply_draw/sh_canvas_apply_draw.fsh.backup1 b/#backups/shaders/sh_canvas_apply_draw/sh_canvas_apply_draw.fsh.backup1 new file mode 100644 index 000000000..608a094a7 --- /dev/null +++ b/#backups/shaders/sh_canvas_apply_draw/sh_canvas_apply_draw.fsh.backup1 @@ -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; +} diff --git a/datafiles/data/Theme.zip b/datafiles/data/Theme.zip index e44e0877d..e97e21a59 100644 Binary files a/datafiles/data/Theme.zip and b/datafiles/data/Theme.zip differ