computeBounds method
Implementation
@override
Bounds computeBounds(SkeletonDrawable drawable) {
final data = drawable.skeletonData;
final oldSkin = drawable.skeleton.getSkin();
final customSkin = Skin("custom-skin");
for (final skinName in skins) {
final skin = data.findSkin(skinName);
if (skin == null) continue;
customSkin.addSkin(skin);
}
drawable.skeleton.setSkin(customSkin);
drawable.skeleton.setToSetupPose();
final animation = this.animation != null ? data.findAnimation(this.animation!) : null;
double minX = double.infinity;
double minY = double.infinity;
double maxX = double.negativeInfinity;
double maxY = double.negativeInfinity;
if (animation == null) {
final bounds = drawable.skeleton.getBounds();
minX = bounds.x;
minY = bounds.y;
maxX = minX + bounds.width;
maxY = minY + bounds.height;
} else {
drawable.animationState.setAnimation(0, animation, false);
final steps = max(animation.getDuration() / stepTime, 1.0).toInt();
for (int i = 0; i < steps; i++) {
drawable.update(i > 0 ? stepTime : 0);
final bounds = drawable.skeleton.getBounds();
minX = min(minX, bounds.x);
minY = min(minY, bounds.y);
maxX = max(maxX, minX + bounds.width);
maxY = max(maxY, minY + bounds.height);
}
}
drawable.skeleton.setSkinByName("default");
drawable.animationState.clearTracks();
if (oldSkin != null) drawable.skeleton.setSkin(oldSkin);
drawable.skeleton.setToSetupPose();
drawable.update(0);
customSkin.dispose();
return Bounds(minX, minY, maxX - minX, maxY - minY);
}