de.matthiasmann.twl.utils
Class TintAnimator

java.lang.Object
  extended by de.matthiasmann.twl.utils.TintAnimator

public class TintAnimator
extends java.lang.Object

A utility class to animate tint colors for widgets


Nested Class Summary
static class TintAnimator.AnimationStateTimeSource
          A time source which uses a specified animation state as time source.
static class TintAnimator.GUITimeSource
          A time source which uses the GUI object of the specified widget or a directly specified GUI instance.
static interface TintAnimator.TimeSource
          A time source for the fade animation
 
Constructor Summary
TintAnimator(GUI gui)
          Creates a new TintAnimator which starts with Color.WHITE and uses the specified GUI as time source.
TintAnimator(GUI gui, Color color)
          Creates a new TintAnimator which starts in the specified color and uses the specified GUI as time source.
TintAnimator(TintAnimator.TimeSource timeSource)
          Creates a new TintAnimator which starts with Color.WHITE
TintAnimator(TintAnimator.TimeSource timeSource, Color color)
          Creates a new TintAnimator which starts in the specified color.
TintAnimator(Widget owner)
          Creates a new TintAnimator which starts with Color.WHITE and uses the specified Widget as time source.
TintAnimator(Widget owner, Color color)
          Creates a new TintAnimator which starts in the specified color and uses the specified Widget as time source.
 
Method Summary
 void addFadeDoneCallback(java.lang.Runnable cb)
          Registers a callback to be executed when the fade animation is finished.
 void fadeTo(Color color, int fadeDuration)
          Fade the current color to the specified color.
 void fadeToHide(int fadeDuration)
          Fade the current color to alpha 0.0f.
 boolean hasTint()
          Returns true when the current tint color is not Color.WHITE
 boolean isFadeActive()
          Returns true when a fade is active
 boolean isZeroAlpha()
          Returns true is the current alpha value is 0.0f
 void paintWithTint(Renderer renderer)
          Calls renderer.pushGlobalTintColor with the current tint color.
 void removeFadeDoneCallback(java.lang.Runnable cb)
           
 void setColor(Color color)
          Sets the current color without a fade.
 void update()
          Updates the fade animation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TintAnimator

public TintAnimator(TintAnimator.TimeSource timeSource,
                    Color color)
Creates a new TintAnimator which starts in the specified color.

Parameters:
timeSource - the time source for the fade animation
color - the starting color

TintAnimator

public TintAnimator(GUI gui,
                    Color color)
Creates a new TintAnimator which starts in the specified color and uses the specified GUI as time source.

Parameters:
gui - the GUI instance - must not be null
color - the starting color

TintAnimator

public TintAnimator(Widget owner,
                    Color color)
Creates a new TintAnimator which starts in the specified color and uses the specified Widget as time source.

Parameters:
owner - the Widget instance - must not be null
color - the starting color

TintAnimator

public TintAnimator(TintAnimator.TimeSource timeSource)
Creates a new TintAnimator which starts with Color.WHITE

Parameters:
timeSource - the time source for the fade animation

TintAnimator

public TintAnimator(GUI gui)
Creates a new TintAnimator which starts with Color.WHITE and uses the specified GUI as time source.

Parameters:
gui - the GUI instance - must not be null
See Also:
GUITimeSource#GUITimeSource(de.matthiasmann.twl.GUI)

TintAnimator

public TintAnimator(Widget owner)
Creates a new TintAnimator which starts with Color.WHITE and uses the specified Widget as time source.

Parameters:
owner - the Widget instance - must not be null
See Also:
GUITimeSource#GUITimeSource(de.matthiasmann.twl.GUI)
Method Detail

setColor

public void setColor(Color color)
Sets the current color without a fade. Any active fade is stopped. The time source is also reset even so no animation is started.

Parameters:
color - the new color

addFadeDoneCallback

public void addFadeDoneCallback(java.lang.Runnable cb)
Registers a callback to be executed when the fade animation is finished. NOTE: the callback is only fired if the fade finishes via timeout and not when it is stopped through a call to fadeTo(de.matthiasmann.twl.Color, int) or fadeToHide(int).

Parameters:
cb - the callback

removeFadeDoneCallback

public void removeFadeDoneCallback(java.lang.Runnable cb)

fadeTo

public void fadeTo(Color color,
                   int fadeDuration)
Fade the current color to the specified color.

Any active fade is stopped.

A zero or negative fadeDuration will set the new color directly and does not start a fade. So no callbacks are fired as a result of this.

Parameters:
color - the destination color of the fade
fadeDuration - the fade time in miliseconds
See Also:
addFadeDoneCallback(java.lang.Runnable)

fadeToHide

public void fadeToHide(int fadeDuration)
Fade the current color to alpha 0.0f. Any active fade is stopped.

This method uses the current color (which may be a mix if a fade was active) as a base to fade the alpha value. Because of that the only defined part of the target color is the alpha channel. This is the reason why no fadeToShow method exists. Use fadeTo with the desired color to make the widget visible again.

A zero or negative fadeDuration will set the alpha value directly and does not start a fade. So no callbacks are fired as a result of this.

Parameters:
fadeDuration - the fade time in miliseconds
See Also:
addFadeDoneCallback(java.lang.Runnable)

update

public void update()
Updates the fade animation. Does not need to be called when no fade is active.


isFadeActive

public boolean isFadeActive()
Returns true when a fade is active

Returns:
true when a fade is active

hasTint

public boolean hasTint()
Returns true when the current tint color is not Color.WHITE

Returns:
true when the current tint color is not Color.WHITE

isZeroAlpha

public boolean isZeroAlpha()
Returns true is the current alpha value is 0.0f

Returns:
true is the current alpha value is 0.0f

paintWithTint

public void paintWithTint(Renderer renderer)
Calls renderer.pushGlobalTintColor with the current tint color. It is important to call renderer.popGlobalTintColor after this method.

Parameters:
renderer - The renderer
See Also:
Renderer.pushGlobalTintColor(float, float, float, float), Renderer.popGlobalTintColor()