Behold, Nenya, Ring of Water and repository for our media and animation related
goodies, both Java 2D and LWJGL/JME 3D. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.jme.effect;
|
||||
|
||||
import com.jme.math.Vector3f;
|
||||
import com.jme.renderer.ColorRGBA;
|
||||
import com.jme.renderer.Renderer;
|
||||
import com.jme.scene.Geometry;
|
||||
import com.jme.scene.Node;
|
||||
import com.jme.scene.shape.Quad;
|
||||
import com.jme.scene.state.AlphaState;
|
||||
import com.jme.system.DisplaySystem;
|
||||
|
||||
import com.threerings.jme.util.LinearTimeFunction;
|
||||
import com.threerings.jme.util.TimeFunction;
|
||||
|
||||
/**
|
||||
* 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 Node
|
||||
{
|
||||
public FadeInOutEffect (ColorRGBA color, float startAlpha, float endAlpha,
|
||||
float duration, boolean overUI)
|
||||
{
|
||||
this(color, new LinearTimeFunction(startAlpha, endAlpha, duration),
|
||||
overUI);
|
||||
}
|
||||
|
||||
public FadeInOutEffect (ColorRGBA color, TimeFunction alphaFunc,
|
||||
boolean overUI)
|
||||
{
|
||||
this(null, color, alphaFunc, overUI);
|
||||
setQuad(createCurtain());
|
||||
}
|
||||
|
||||
public FadeInOutEffect (Quad quad, ColorRGBA color, TimeFunction alphaFunc,
|
||||
boolean overUI)
|
||||
{
|
||||
super("FadeInOut");
|
||||
|
||||
_color = new ColorRGBA(
|
||||
color.r, color.g, color.b, alphaFunc.getValue(0));
|
||||
_alphaFunc = alphaFunc;
|
||||
|
||||
DisplaySystem ds = DisplaySystem.getDisplaySystem();
|
||||
_astate = ds.getRenderer().createAlphaState();
|
||||
_astate.setBlendEnabled(true);
|
||||
_astate.setSrcFunction(AlphaState.SB_SRC_ALPHA);
|
||||
_astate.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
|
||||
_astate.setEnabled(true);
|
||||
|
||||
if (quad != null) {
|
||||
setQuad(quad);
|
||||
}
|
||||
|
||||
setRenderQueueMode(Renderer.QUEUE_ORTHO);
|
||||
setZOrder(overUI ? -1 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the quad that will be faded in or out.
|
||||
*/
|
||||
public void setQuad (Quad quad)
|
||||
{
|
||||
attachChild(quad);
|
||||
quad.setDefaultColor(_color);
|
||||
quad.setRenderState(_astate);
|
||||
quad.updateRenderState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the fade to be paused.
|
||||
*/
|
||||
public void setPaused (boolean paused)
|
||||
{
|
||||
_paused = paused;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not the fade is paused.
|
||||
*/
|
||||
public boolean isPaused ()
|
||||
{
|
||||
return _paused;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void updateGeometricState (float time, boolean initiator)
|
||||
{
|
||||
super.updateGeometricState(time, initiator);
|
||||
if (_paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
float alpha = _alphaFunc.getValue(time);
|
||||
_color.a = Math.min(1f, Math.max(0f, alpha));
|
||||
if (_alphaFunc.isComplete()) {
|
||||
fadeComplete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called (only once) when we have reached the end of our fade.
|
||||
* Automatically detaches this effect from the hierarchy.
|
||||
*/
|
||||
protected void fadeComplete ()
|
||||
{
|
||||
getParent().detachChild(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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" + hashCode(), width, height);
|
||||
curtain.setLocalTranslation(new Vector3f(width/2, height/2, 0f));
|
||||
return curtain;
|
||||
}
|
||||
|
||||
protected ColorRGBA _color;
|
||||
protected AlphaState _astate;
|
||||
protected TimeFunction _alphaFunc;
|
||||
protected boolean _paused;
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.jme.effect;
|
||||
|
||||
import com.jme.scene.Node;
|
||||
import com.jme.system.DisplaySystem;
|
||||
|
||||
import com.jmex.bui.BWindow;
|
||||
|
||||
import com.threerings.jme.util.LinearTimeFunction;
|
||||
import com.threerings.jme.util.TimeFunction;
|
||||
|
||||
/**
|
||||
* Slides a window onto the center of the screen from offscreen or offscreen
|
||||
* from the center of the screen.
|
||||
*/
|
||||
public class WindowSlider extends Node
|
||||
{
|
||||
public static final int FROM_TOP = 0;
|
||||
public static final int FROM_RIGHT = 1;
|
||||
public static final int TO_TOP = 2;
|
||||
public static final int TO_RIGHT = 3;
|
||||
|
||||
/**
|
||||
* Creates a window slider with the specified mode and window that will
|
||||
* slide the window either onto or off of the screen in the specified
|
||||
* number of seconds.
|
||||
*
|
||||
* @param dx an offset applied to the starting or destination position
|
||||
* along the x axis (starting for sliding off, destination for sliding on).
|
||||
* @param dy an offset applied along the y axis.
|
||||
*/
|
||||
public WindowSlider (BWindow window, int mode, float duration,
|
||||
int dx, int dy)
|
||||
{
|
||||
super("slider");
|
||||
|
||||
DisplaySystem ds = DisplaySystem.getDisplaySystem();
|
||||
int swidth = ds.getWidth(), sheight = ds.getHeight();
|
||||
int wwidth = window.getWidth(), wheight = window.getHeight();
|
||||
|
||||
int start = 0, end = 0;
|
||||
switch (mode) {
|
||||
case FROM_TOP:
|
||||
start = sheight+wheight;
|
||||
end = (sheight-wheight)/2 + dy;
|
||||
window.setLocation((swidth-wwidth)/2 + dx, start);
|
||||
break;
|
||||
|
||||
case FROM_RIGHT:
|
||||
start = swidth+wwidth;
|
||||
end = (swidth-wwidth)/2 + dx;
|
||||
window.setLocation(start, (sheight-wheight)/2 + dy);
|
||||
break;
|
||||
|
||||
case TO_TOP:
|
||||
start = (sheight-wheight)/2 + dy;
|
||||
end = sheight+wheight;
|
||||
window.setLocation((swidth-wwidth)/2 + dx, start);
|
||||
break;
|
||||
|
||||
case TO_RIGHT:
|
||||
start = (swidth-wwidth)/2 + dx;
|
||||
end = swidth+wwidth;
|
||||
window.setLocation(start, (sheight-wheight)/2 + dy);
|
||||
break;
|
||||
}
|
||||
|
||||
_mode = mode;
|
||||
_window = window;
|
||||
_tfunc = new LinearTimeFunction(start, end, duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows some number of ticks to be skipped to give the window that is
|
||||
* being slid a chance to be layed out before we start keeping track of
|
||||
* time. The layout may be expensive and cause the frame rate to drop for a
|
||||
* frame or two, thus booching our smooth sliding onto the screen.
|
||||
*/
|
||||
public void setSkipTicks (int skipTicks)
|
||||
{
|
||||
_skipTicks = skipTicks;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void updateGeometricState (float time, boolean initiator)
|
||||
{
|
||||
super.updateGeometricState(time, initiator);
|
||||
|
||||
// skip ticks as long as we need to
|
||||
if (_skipTicks-- > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int winx, winy;
|
||||
if (_mode % 2 == 1) {
|
||||
winx = (int)_tfunc.getValue(time);
|
||||
winy = _window.getY();
|
||||
} else {
|
||||
winx = _window.getX();
|
||||
winy = (int)_tfunc.getValue(time);
|
||||
}
|
||||
_window.setLocation(winx, winy);
|
||||
|
||||
if (_tfunc.isComplete()) {
|
||||
slideComplete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called (only once) when we have reached the end of our slide.
|
||||
* Automatically detaches this effect from the hierarchy.
|
||||
*/
|
||||
protected void slideComplete ()
|
||||
{
|
||||
getParent().detachChild(this);
|
||||
}
|
||||
|
||||
protected int _mode;
|
||||
protected BWindow _window;
|
||||
protected TimeFunction _tfunc;
|
||||
|
||||
// skip two frames by default as that generally handles the normal window
|
||||
// layout process
|
||||
protected int _skipTicks = 2;
|
||||
}
|
||||
Reference in New Issue
Block a user