- [Canvas] Add animation type.

This commit is contained in:
Tanasart 2024-06-29 14:37:07 +07:00
parent 6bd74835f4
commit daef80e921
4 changed files with 77 additions and 25 deletions

View file

@ -47,6 +47,9 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
inputs[| 17] = nodeValue("Random direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0, 0, 0 ] )
.setDisplay(VALUE_DISPLAY.rotation_random);
inputs[| 18] = nodeValue("Animation Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Loop", "Hold", "Clear" ]);
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
frame_renderer_x = 0;
@ -54,7 +57,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
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, _full = true) { #region frame_renderer
frame_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus, _full = true, _fx = frame_renderer_x) { #region frame_renderer
var _h = _full? 64 : 48;
var _anim = getInputData(12);
var _cnt_hover = false;
@ -88,7 +91,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _fr_h = _hh - 8;
var _fr_w = _fr_h;
var _fr_x = 4 - frame_renderer_x;
var _fr_x = 4 - _fx;
var _fr_y = 4;
var surfs = output_surface;
@ -109,7 +112,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _ssw = _sw * _ss;
var _ssh = _sh * _ss;
draw_surface_ext(_surf, _sx, _sy, _ss, _ss, 0, c_white, 0.75);
draw_surface_ext(_surf, _sx, _sy, _ss, _ss, 0, c_white, 1);
draw_sprite_stretched_add(THEME.menu_button_mask, 1, _sx, _sy, _ssw, _ssh, i == preview_index? COLORS._main_accent : COLORS.panel_toolbar_outline, 1);
if(_hover && point_in_rectangle(_m[0], _m[1], _x0, _y0, _x1, _y1)) {
@ -165,15 +168,16 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
}
return _h + 8 * _full;
}); #endregion
}).setNode(self); #endregion
temp_surface = array_create(1);
temp_surface = array_create(2);
live_edit = false;
live_target = "";
input_display_list = [
["Output", false], 0, frame_renderer, 12, 13,
["Output", false], 0, frame_renderer, 12, 18, 13,
["Brush", true], 6, 15, 17, 16,
["Background", true, 10], 8, 14, 9,
];
@ -935,17 +939,19 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
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);
if(update_on_frame) {
var anims = getInputData(13);
var atype = getInputData(18);
if(atype == 0) preview_index = safe_mod(CURRENT_FRAME * anims, fram);
else preview_index = min(CURRENT_FRAME * anims, fram - 1);
}
} #endregion
static update = function(frame = CURRENT_FRAME) { #region
@ -956,6 +962,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _anim = getInputData(12);
var _anims = getInputData(13);
var _bgDim = getInputData(14);
var _atype = getInputData(18);
var cDep = attrDepth();
@ -993,7 +1000,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _canvas_surface = getCanvasSurface(i);
var _bgArray = is_array(_bg)? array_safe_get_fast(_bg, i, 0) : _bg;
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(_bgArray))
draw_surface_stretched_ext(_bgArray, 0, 0, _dim[0], _dim[1], c_white, _bga);
@ -1001,9 +1008,19 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
surface_reset_shader();
}
temp_surface[1] = surface_verify(temp_surface[1], _dim[0], _dim[1], cDep);
surface_clear(temp_surface[1]);
if(_anim) {
var _fr_index = safe_mod(CURRENT_FRAME * _anims, _frames);
outputs[| 0].setValue(output_surface[_fr_index]);
var _fr_index = CURRENT_FRAME * _anims;
switch(_atype) {
case 0 : _fr_index = safe_mod(_fr_index, _frames); break;
case 1 : _fr_index = min(_fr_index, _frames - 1); break;
case 2 : _fr_index = _fr_index < _frames? _fr_index : noone; break;
}
outputs[| 0].setValue(_fr_index == noone? temp_surface[1] : output_surface[_fr_index]);
} else
outputs[| 0].setValue(output_surface);
}

View file

@ -14,6 +14,10 @@ function Node_Canvas_Group(_x, _y, _group) : Node_Collection(_x, _y, _group) con
composite = noone;
canvas_sel = noone;
frame_renderer_x = 0;
frame_renderer_x_to = 0;
frame_renderer_x_max = 0;
layer_height = 0;
layer_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
var _h = ui(4);
@ -46,6 +50,9 @@ function Node_Canvas_Group(_x, _y, _group) : Node_Collection(_x, _y, _group) con
var _yy = _y;
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, frame_renderer.h, COLORS.node_composite_bg_blend, 1);
var _cnt_hover = _hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + frame_renderer.h);
frame_renderer_x_max = 0;
for (var i = array_length(canvases) - 1; i >= 0; i--) {
var _canvas = canvases[i];
@ -55,11 +62,20 @@ function Node_Canvas_Group(_x, _y, _group) : Node_Collection(_x, _y, _group) con
_frame_render.rx = frame_renderer.rx;
_frame_render.ry = frame_renderer.ry;
var _wdh = _frame_render.draw(_x, _yy, _w, _m, _hover, _focus, false);
if(!is_undefined(_wdh)) {
_h += _wdh;
_yy += _wdh;
}
var _wdh = _frame_render.draw(_x, _yy, _w, _m, _hover, _focus, false, frame_renderer_x);
if(is_undefined(_wdh)) continue;
frame_renderer_x_max = max(frame_renderer_x_max, _frame_render.node.frame_renderer_x_max);
_h += _wdh - ui(2);
_yy += _wdh - ui(2);
}
_h += ui(2);
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);
}
frame_renderer.h = _h;

View file

@ -162,7 +162,7 @@ function Node_Composite(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
} else
draw_sprite_ui_uniform(THEME.cursor_select, sel, _bx, _cy + lh / 2, 1, COLORS._main_icon, 0.5 + 0.5 * sel);
var hover = point_in_rectangle(_m[0], _m[1], _bx + ui(12 + 6), _cy, _x + _w - ui(48), _cy + lh - 1);
var hover = _hover && point_in_rectangle(_m[0], _m[1], _bx + ui(12 + 6), _cy, _x + _w - ui(48), _cy + lh - 1);
#endregion
#region draw surface
@ -180,7 +180,7 @@ function Node_Composite(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
else draw_sprite_stretched_add(THEME.menu_button_mask, 1, _sx0, _sy0, ssh, ssh, COLORS._main_icon, 0.3);
#endregion
#region layers
#region canvas layers
var _junc_canvas = noone;
var _jun_layer = noone;
if(canvas_draw != noone && _junc && struct_has(canvas_draw.layers, _junc.node_id)) {
@ -190,11 +190,13 @@ function Node_Composite(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
#endregion
#region draw title
draw_set_text(f_p1, fa_left, fa_center, hover? COLORS._main_text_accent : COLORS._main_text);
var _txt = _inp.name;
var _txx = _sx1 + ui(12);
var _txy = _cy + lh / 2 + ui(2);
if(_junc_canvas) hover &= _m[0] > _txx + ui(8 + 16);
draw_set_text(f_p1, fa_left, fa_center, hover? COLORS._main_text_accent : COLORS._main_text);
if(canvas_draw != noone && _junc_canvas)
_txt = _junc_canvas.display_name;
@ -207,7 +209,22 @@ function Node_Composite(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
var _txh = string_height(_txt);
if(_junc_canvas) {
draw_sprite_ui_uniform(THEME.icon_canvas, 0, _txx + ui(8), _txy - ui(1), 1, draw_get_color(), aa * .8);
var _icx = _txx + ui(8);
var _icy = _txy - ui(1);
var _icc = COLORS._main_icon;
var _ica = aa * .8;
if(_hover && point_in_circle(_m[0], _m[1], _icx, _icy, ui(10))) {
_icc = COLORS._main_icon_light;
_ica = 1;
if(DOUBLE_CLICK) {
var pan = panelAdd("Panel_Inspector", true);
pan.content.setInspecting(_junc_canvas, true);
}
}
draw_sprite_ui_uniform(THEME.icon_canvas, 0, _icx, _icy, 1, _icc, _ica);
draw_set_alpha(aa);
draw_text(_txx + ui(8 + 16), _txy, _txt);
@ -254,7 +271,6 @@ function Node_Composite(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
if(_mhov && DOUBLE_CLICK) {
var pan = panelAdd("Panel_Inspector", true);
// pan.destroy_on_click_out = false;
pan.content.setInspecting(_modi, true);
}
@ -408,7 +424,7 @@ function Node_Composite(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
outputs[| 1] = nodeValue("Atlas data", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, []);
outputs[| 1] = nodeValue("Atlas data", self, JUNCTION_CONNECT.output, VALUE_TYPE.atlas, []);
outputs[| 2] = nodeValue("Dimension", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, [1, 1])
.setVisible(false)

View file

@ -16,6 +16,7 @@
function Inspector_Custom_Renderer(drawFn, registerFn = noone) : widget() constructor { #region
h = 64;
node = noone;
self.draw = drawFn;
if(registerFn != noone) register = registerFn;
@ -26,6 +27,8 @@ function Inspector_Custom_Renderer(drawFn, registerFn = noone) : widget() constr
}
}
static setNode = function(node) { self.node = node; return self; }
static toString = function() { return $"Custon renderer"; }
} #endregion