Pixel-Composer/scripts/panel_animation_scaler/panel_animation_scaler.gml

53 lines
1.4 KiB
Text
Raw Normal View History

function Panel_Animation_Scaler() : Panel_Linear_Setting() constructor {
2023-12-24 12:06:44 +01:00
title = __txtx("anim_scale_title", "Animation Scaler");
w = ui(380);
2023-10-09 16:07:33 +02:00
scale_to = TOTAL_FRAMES;
properties = [
new __Panel_Linear_Setting_Item(
__txtx("anim_scale_target_frame_length", "Target frame length"),
new textBox(TEXTBOX_INPUT.number, function(to) /*=>*/ { scale_to = toNumber(to); }),
function() /*=>*/ {return scale_to},
)
];
hpad = ui(36);
setHeight();
b_apply = button(function() /*=>*/ {return scale()}).setIcon(THEME.accept_16, 0, COLORS._main_icon_dark);
static scale = function() {
2023-10-09 16:07:33 +02:00
var fac = scale_to / TOTAL_FRAMES;
for (var i = 0, n = array_length(PROJECT.allNodes); i < n; i++) {
var _node = PROJECT.allNodes[i];
if(!_node || !_node.active) continue;
for(var j = 0, m = array_length(_node.inputs); j < m; j++) {
var in = _node.inputs[j];
if(!in.is_anim) continue;
for(var k = 0, p = array_length(in.animator.values); k < p; k++) {
var t = in.animator.values[k];
t.time = t.ratio * scale_to;
}
}
}
2023-10-09 16:07:33 +02:00
TOTAL_FRAMES = scale_to;
close();
}
function drawContent(panel) {
drawSettings(panel);
var bs = ui(28);
var bx = w - ui(8) - bs;
var by = h - ui(8) - bs;
b_apply.setFocusHover(pFOCUS, pHOVER);
b_apply.register();
b_apply.draw(bx, by, bs, bs, [ mx, my ], THEME.button_lime);
}
}