Package de.lessvoid.nifty.effects.impl

Source Code of de.lessvoid.nifty.effects.impl.ImageOverlayPulsate

package de.lessvoid.nifty.effects.impl;


import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.effects.EffectImpl;
import de.lessvoid.nifty.effects.EffectProperties;
import de.lessvoid.nifty.effects.Falloff;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.render.NiftyImage;
import de.lessvoid.nifty.render.NiftyRenderEngine;
import de.lessvoid.nifty.render.image.ImageModeFactory;
import de.lessvoid.nifty.render.image.ImageModeHelper;
import de.lessvoid.nifty.tools.TimeProvider;
import de.lessvoid.nifty.tools.pulsate.Pulsator;

/**
* ImagePulsate - image color pulsate.
* @author void
*/
public class ImageOverlayPulsate implements EffectImpl {

  private NiftyImage image;
  private Pulsator pulsater;

  public void activate(final Nifty nifty, final Element element, final EffectProperties parameter) {
    image = nifty.getRenderEngine().createImage(parameter.getProperty("filename"), true);

    String areaProviderProperty = new ImageModeHelper().getAreaProviderProperty(parameter);
    String renderStrategyProperty = new ImageModeHelper().getRenderStrategyProperty(parameter);
    if ((areaProviderProperty != null) || (renderStrategyProperty != null)) {
      image.setImageMode(ImageModeFactory.getSharedInstance().createImageMode(areaProviderProperty,
          renderStrategyProperty));
    }

    this.pulsater = new Pulsator(parameter, new TimeProvider());
  }

  public void execute(
      final Element element,
      final float normalizedTime,
      final Falloff falloff,
      final NiftyRenderEngine r) {
    r.saveState(null);
    float value = pulsater.update();
    r.setColorAlpha(value);
    r.renderImage(image, element.getX(), element.getY(), element.getWidth(), element.getHeight());
    r.restoreState();
  }

  public void deactivate() {
    image.dispose();
  }
}
TOP

Related Classes of de.lessvoid.nifty.effects.impl.ImageOverlayPulsate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.