Search in sources :

Example 1 with Animation

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);
        }
    };
}
Also used : Vector4f(org.joml.Vector4f) Animation(com.spinyowl.legui.animation.Animation)

Example 2 with Animation

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);
        }
    };
}
Also used : Vector4f(org.joml.Vector4f) Animation(com.spinyowl.legui.animation.Animation)

Aggregations

Animation (com.spinyowl.legui.animation.Animation)2 Vector4f (org.joml.Vector4f)2