use of com.spinyowl.legui.animation.Animation in project legui by SpinyOwl.
the class ExampleGui method getColorAnimation.
private Animation getColorAnimation(ToggleButton toggleButton, Vector4f targetColor) {
return new Animation() {
private Vector4f baseColor;
private Vector4f endColor;
private Vector4f colorVector;
private double time;
private double spentTime;
@Override
protected void beforeAnimation() {
time = 1.5d;
spentTime = 0;
baseColor = new Vector4f(toggleButton.getStyle().getBackground().getColor());
endColor = targetColor;
colorVector = new Vector4f(endColor).sub(baseColor);
}
@Override
protected boolean animate(double delta) {
spentTime += delta;
float percentage = (float) (spentTime / time);
Vector4f newColor = new Vector4f(baseColor).add(new Vector4f(colorVector).mul(percentage));
toggleButton.getStyle().getBackground().setColor(newColor);
return spentTime >= time;
}
@Override
protected void afterAnimation() {
toggleButton.getStyle().getBackground().setColor(endColor);
}
};
}
use of com.spinyowl.legui.animation.Animation in project legui by SpinyOwl.
the class ExampleGui method createColorAnimationOnHover.
private Animation createColorAnimationOnHover(Component component, Vector4f newColor, Component targetComponent) {
return new Animation() {
private Vector4f initialColor;
private Vector4f colorRange;
private double time;
@Override
protected void beforeAnimation() {
initialColor = new Vector4f(targetComponent.getStyle().getBackground().getColor());
colorRange = newColor.sub(initialColor);
}
@Override
protected boolean animate(double delta) {
time += delta;
targetComponent.getStyle().getBackground().getColor().set(new Vector4f(initialColor).add(new Vector4f(colorRange).mul((float) Math.abs(Math.sin(time * 2)))));
return !component.isHovered();
}
@Override
protected void afterAnimation() {
targetComponent.getStyle().getBackground().getColor().set(initialColor);
}
};
}