class sampleUIAnimationController extends inkLogicController
{
	private var m_rotation_anim : inkAnimDef;
	private var m_size_anim : inkAnimDef;
	private var m_color_anim : inkAnimDef;
	private var m_alpha_anim : inkAnimDef;
	private var m_rotation_anim_proxy : inkAnimProxy;
	private var m_size_anim_proxy : inkAnimProxy;
	private var m_color_anim_proxy : inkAnimProxy;
	private var m_alpha_anim_proxy : inkAnimProxy;
	private var m_rotation_widget : weak< inkWidget >;
	private var m_size_widget : weak< inkWidget >;
	private var m_color_widget : weak< inkWidget >;
	private var m_alpha_widget : weak< inkWidget >;
	private var m_iteration_counter : Uint32;
	private var m_is_paused : Bool;
	private var m_is_stoped : Bool;
	private var m_playReversed : Bool;

	protected event OnInitialize()
	{
		m_iteration_counter = 3;
		m_is_paused = false;
		m_is_stoped = true;
		m_playReversed = false;
		PrepareDefinitions();
		m_rotation_widget = GetWidget( 'simple_animations/simple_rotation_anim/simple_rotation_example' );
		m_size_widget = GetWidget( 'simple_animations/simple_size_anim/simple_size_example' );
		m_color_widget = GetWidget( 'simple_animations/simple_color_anim/simple_color_example' );
		m_alpha_widget = GetWidget( 'simple_animations/simple_alpha_anim/simple_alpha_example' );
		OnPlayPingPongLoop( GetRootWidget() );
	}

	public function OnStopAnimation( widget : weak< inkWidget > )
	{
		m_is_paused = false;
		m_is_stoped = true;
		m_rotation_anim_proxy.Stop();
		m_size_anim_proxy.Stop();
		m_color_anim_proxy.Stop();
		m_alpha_anim_proxy.Stop();
	}

	public function OnPauseResumeAnimation( widget : weak< inkWidget > )
	{
		var widgetHandle : inkWidget;
		var root : inkCompoundWidget;
		var label : inkText;
		widgetHandle = ( ( inkWidget )( widget ) );
		root = ( ( inkCompoundWidget )( widgetHandle ) );
		label = ( ( inkText )( root.GetWidget( 'pause_button_text' ) ) );
		m_is_paused = !( m_is_paused );
		m_is_stoped = false;
		if( m_is_paused == true )
		{
			label.SetText( "RESUME" );
			m_rotation_anim_proxy.Pause();
			m_size_anim_proxy.Pause();
			m_color_anim_proxy.Pause();
			m_alpha_anim_proxy.Pause();
		}
		else
		{
			label.SetText( "PAUSE" );
			m_rotation_anim_proxy.Resume();
			m_size_anim_proxy.Resume();
			m_color_anim_proxy.Resume();
			m_alpha_anim_proxy.Resume();
		}
	}

	public function OnPlay( widget : weak< inkWidget > )
	{
		m_is_paused = false;
		m_is_stoped = false;
		m_rotation_widget.PlayAnimation( m_rotation_anim );
		m_size_widget.PlayAnimation( m_size_anim );
		m_color_widget.PlayAnimation( m_color_anim );
		m_alpha_widget.PlayAnimation( m_alpha_anim );
	}

	public function OnPlayCycleLoop( widget : weak< inkWidget > )
	{
		var options : inkAnimOptions;
		m_is_paused = false;
		m_is_stoped = false;
		options.playReversed = m_playReversed;
		options.executionDelay = 0.0;
		options.loopType = inkanimLoopType.Cycle;
		options.loopCounter = m_iteration_counter;
		m_rotation_widget.PlayAnimationWithOptions( m_rotation_anim, options );
		m_size_widget.PlayAnimationWithOptions( m_size_anim, options );
		m_color_widget.PlayAnimationWithOptions( m_color_anim, options );
		m_alpha_widget.PlayAnimationWithOptions( m_alpha_anim, options );
	}

	public function OnPlayPingPongLoop( widget : weak< inkWidget > )
	{
		var options : inkAnimOptions;
		m_is_paused = false;
		m_is_stoped = false;
		options.playReversed = m_playReversed;
		options.executionDelay = 0.0;
		options.loopType = inkanimLoopType.PingPong;
		options.loopCounter = m_iteration_counter;
		m_rotation_widget.PlayAnimationWithOptions( m_rotation_anim, options );
		m_size_widget.PlayAnimationWithOptions( m_size_anim, options );
		m_color_widget.PlayAnimationWithOptions( m_color_anim, options );
		m_alpha_widget.PlayAnimationWithOptions( m_alpha_anim, options );
	}

	private function PrepareDefinitions()
	{
		var rotationInterpolator : inkAnimRotation;
		var sizeInterpolator : inkAnimSize;
		var colorInterpolator : inkAnimColor;
		var alphaInterpolator : inkAnimTransparency;
		var blinkEvent : inkAnimToggleVisibilityEvent;
		m_rotation_anim = new inkAnimDef;
		rotationInterpolator = new inkAnimRotation;
		rotationInterpolator.SetStartRotation( 0.0 );
		rotationInterpolator.SetEndRotation( 180.0 );
		rotationInterpolator.SetDuration( 3.0 );
		rotationInterpolator.SetType( inkanimInterpolationType.Linear );
		rotationInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_rotation_anim.AddInterpolator( rotationInterpolator );
		blinkEvent = new inkAnimToggleVisibilityEvent;
		blinkEvent.SetStartTime( 1.5 );
		m_rotation_anim.AddEvent( blinkEvent );
		m_size_anim = new inkAnimDef;
		sizeInterpolator = new inkAnimSize;
		sizeInterpolator.SetStartSize( Vector2( 32.0, 32.0 ) );
		sizeInterpolator.SetEndSize( Vector2( 16.0, 16.0 ) );
		sizeInterpolator.SetDuration( 3.0 );
		sizeInterpolator.SetType( inkanimInterpolationType.Linear );
		sizeInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_size_anim.AddInterpolator( sizeInterpolator );
		m_color_anim = new inkAnimDef;
		colorInterpolator = new inkAnimColor;
		colorInterpolator.SetStartColor( HDRColor( 1.0, 1.0, 1.0, 1.0 ) );
		colorInterpolator.SetEndColor( HDRColor( 1.0, 0.0, 0.0, 1.0 ) );
		colorInterpolator.SetDuration( 3.0 );
		colorInterpolator.SetType( inkanimInterpolationType.Linear );
		colorInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_color_anim.AddInterpolator( colorInterpolator );
		m_alpha_anim = new inkAnimDef;
		alphaInterpolator = new inkAnimTransparency;
		alphaInterpolator.SetStartTransparency( 1.0 );
		alphaInterpolator.SetEndTransparency( 0.2 );
		alphaInterpolator.SetDuration( 3.0 );
		alphaInterpolator.SetType( inkanimInterpolationType.Linear );
		alphaInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		m_alpha_anim.AddInterpolator( alphaInterpolator );
	}

}

