Allow the FadeInOutEffect to be used on arbitrary quads.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3837 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-02-07 01:33:46 +00:00
parent e9be71fdf2
commit d822c597b3
@@ -25,6 +25,7 @@ import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA; import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer; import com.jme.renderer.Renderer;
import com.jme.scene.Geometry; import com.jme.scene.Geometry;
import com.jme.scene.Node;
import com.jme.scene.shape.Quad; import com.jme.scene.shape.Quad;
import com.jme.scene.state.AlphaState; import com.jme.scene.state.AlphaState;
import com.jme.system.DisplaySystem; import com.jme.system.DisplaySystem;
@@ -33,9 +34,10 @@ import com.threerings.jme.util.LinearTimeFunction;
import com.threerings.jme.util.TimeFunction; import com.threerings.jme.util.TimeFunction;
/** /**
* Fades the screen in from a solid color or out to a solid color. * Fades a supplied quad (or one that covers the screen) in from a solid color
* or out to a solid color.
*/ */
public class FadeInOutEffect extends Quad public class FadeInOutEffect extends Node
{ {
public FadeInOutEffect (ColorRGBA color, float startAlpha, float endAlpha, public FadeInOutEffect (ColorRGBA color, float startAlpha, float endAlpha,
float duration, boolean overUI) float duration, boolean overUI)
@@ -46,6 +48,13 @@ public class FadeInOutEffect extends Quad
public FadeInOutEffect (ColorRGBA color, TimeFunction alphaFunc, public FadeInOutEffect (ColorRGBA color, TimeFunction alphaFunc,
boolean overUI) boolean overUI)
{
this(null, color, alphaFunc, overUI);
setQuad(createCurtain());
}
public FadeInOutEffect (Quad quad, ColorRGBA color, TimeFunction alphaFunc,
boolean overUI)
{ {
super("FadeInOut"); super("FadeInOut");
@@ -53,17 +62,14 @@ public class FadeInOutEffect extends Quad
color.r, color.g, color.b, alphaFunc.getValue(0)); color.r, color.g, color.b, alphaFunc.getValue(0));
_alphaFunc = alphaFunc; _alphaFunc = alphaFunc;
// we need to render in the ortho queue if (quad != null) {
setQuad(quad);
}
setRenderQueueMode(Renderer.QUEUE_ORTHO); setRenderQueueMode(Renderer.QUEUE_ORTHO);
// create a quad the size of the screen
DisplaySystem ds = DisplaySystem.getDisplaySystem();
float width = ds.getWidth(), height = ds.getHeight();
initialize(width, height);
setLocalTranslation(new Vector3f(width/2, height/2, 0f));
setZOrder(overUI ? -1 : 1); setZOrder(overUI ? -1 : 1);
setDefaultColor(_color);
DisplaySystem ds = DisplaySystem.getDisplaySystem();
AlphaState astate = ds.getRenderer().createAlphaState(); AlphaState astate = ds.getRenderer().createAlphaState();
astate.setBlendEnabled(true); astate.setBlendEnabled(true);
astate.setSrcFunction(AlphaState.SB_SRC_ALPHA); astate.setSrcFunction(AlphaState.SB_SRC_ALPHA);
@@ -74,6 +80,15 @@ public class FadeInOutEffect extends Quad
updateRenderState(); updateRenderState();
} }
/**
* Configures the quad that will be faded in or out.
*/
public void setQuad (Quad quad)
{
attachChild(quad);
quad.setDefaultColor(_color);
}
/** /**
* Allows the fade to be paused. * Allows the fade to be paused.
*/ */
@@ -82,6 +97,14 @@ public class FadeInOutEffect extends Quad
_paused = paused; _paused = paused;
} }
/**
* Indicates whether or not the fade is paused.
*/
public boolean isPaused ()
{
return _paused;
}
// documentation inherited // documentation inherited
public void updateGeometricState (float time, boolean initiator) public void updateGeometricState (float time, boolean initiator)
{ {
@@ -104,6 +127,19 @@ public class FadeInOutEffect extends Quad
{ {
} }
/**
* Creates a quad that covers the entire screen for full-screen fades.
*/
protected Quad createCurtain ()
{
// create a quad the size of the screen
DisplaySystem ds = DisplaySystem.getDisplaySystem();
float width = ds.getWidth(), height = ds.getHeight();
Quad curtain = new Quad("curtain", width, height);
curtain.setLocalTranslation(new Vector3f(width/2, height/2, 0f));
return curtain;
}
protected ColorRGBA _color; protected ColorRGBA _color;
protected TimeFunction _alphaFunc; protected TimeFunction _alphaFunc;
protected boolean _paused; protected boolean _paused;