class sampleUICustomizableAnimationsController extends inkLogicController
{
	editable var imagePath : CName;
	editable var interpolationType : inkanimInterpolationType;
	editable var interpolationMode : inkanimInterpolationMode;
	editable var delayTime : Float;
	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_position_anim : inkAnimDef;
	private var imageWidget : weak< inkWidget >;
	private var animProxy : inkAnimProxy;
	private var CanRotate : Bool;
	private var CanResize : Bool;
	private var CanChangeColor : Bool;
	private var CanChangeAlpha : Bool;
	private var CanMove : Bool;
	private var m_defaultSize : Vector2;
	private var m_defaultMargin : inkMargin;
	private var m_defaultRotation : Float;
	private var m_defaultColor : HDRColor;
	private var m_defaultAlpha : Float;
	private var m_isHighlighted : Bool;
	private var m_currentTarget : weak< inkWidget >;
	private var m_currentAnimProxy : inkAnimProxy;

	protected event OnInitialize()
	{
		imageWidget = GetWidget( imagePath );
		SaveDefaults();
		UpdateDefinitions();
	}

	public function Higlight( e : inkPointerEvent )
	{
		m_currentTarget = e.GetTarget();
		m_isHighlighted = true;
		m_currentTarget.SetTintColor( Color( 180, 180, 180, 255 ) );
	}

	public function EndHiglight( e : inkPointerEvent )
	{
		m_isHighlighted = false;
		m_currentTarget.SetTintColor( Color( 255, 255, 255, 255 ) );
	}

	private function SaveDefaults()
	{
		m_defaultSize = imageWidget.GetSize();
		m_defaultMargin = imageWidget.GetMargin();
		m_defaultRotation = 0.0;
		m_defaultColor = imageWidget.GetTintColor();
		m_defaultAlpha = imageWidget.GetOpacity();
	}

	public function Reset( e : inkPointerEvent )
	{
		imageWidget.SetSize( m_defaultSize );
		imageWidget.SetMargin( m_defaultMargin );
		imageWidget.SetRotation( m_defaultRotation );
		imageWidget.SetTintColor( m_defaultColor );
		imageWidget.SetOpacity( m_defaultAlpha );
	}

	public function PlayAnimation( e : inkPointerEvent )
	{
		if( CanRotate )
		{
			imageWidget.PlayAnimation( m_rotation_anim );
		}
		if( CanResize )
		{
			imageWidget.PlayAnimation( m_size_anim );
		}
		if( CanChangeColor )
		{
			imageWidget.PlayAnimation( m_color_anim );
		}
		if( CanChangeAlpha )
		{
			imageWidget.PlayAnimation( m_alpha_anim );
		}
		if( CanMove )
		{
			imageWidget.PlayAnimation( m_position_anim );
		}
		m_currentAnimProxy = PlayLibraryAnimation( 'BinkTest' );
	}

	private function SetText( buttonName : CName, status : Bool )
	{
		var widget : weak< inkText >;
		var backgroundWidget : weak< inkRectangle >;
		backgroundWidget = ( ( inkRectangle )( GetWidget( StringToName( ( "Buttons\" + ( ( String )( buttonName ) ) ) + "\Button_bg" ) ) ) );
		widget = ( ( inkText )( GetWidget( StringToName( ( "Buttons\" + ( ( String )( buttonName ) ) ) + "\Texts\animStatus" ) ) ) );
		if( status )
		{
			widget.SetText( "ON" );
			backgroundWidget.SetTintColor( Color( 101, 255, 145, 255 ) );
		}
		else
		{
			widget.SetText( "OFF" );
			backgroundWidget.SetTintColor( Color( 255, 255, 255, 255 ) );
		}
	}

	public function ToggleRotationAnim( e : inkPointerEvent )
	{
		CanRotate = !( CanRotate );
		SetText( 'Button_1', CanRotate );
	}

	public function ToggleSizeAnim( e : inkPointerEvent )
	{
		CanResize = !( CanResize );
		SetText( 'Button_2', CanResize );
	}

	public function ToggleColorAnim( e : inkPointerEvent )
	{
		CanChangeColor = !( CanChangeColor );
		SetText( 'Button_3', CanChangeColor );
	}

	public function ToggleAlphaAnim( e : inkPointerEvent )
	{
		CanChangeAlpha = !( CanChangeAlpha );
		SetText( 'Button_4', CanChangeAlpha );
	}

	public function TogglePositionAnim( e : inkPointerEvent )
	{
		CanMove = !( CanMove );
		SetText( 'Button_5', CanMove );
	}

	private function UpdateDefinitions()
	{
		var rotationInterpolator : inkAnimRotation;
		var positionInterpolator : inkAnimMargin;
		var sizeInterpolator : inkAnimSize;
		var colorInterpolator : inkAnimColor;
		var alphaInterpolator : inkAnimTransparency;
		m_rotation_anim = new inkAnimDef;
		rotationInterpolator = new inkAnimRotation;
		rotationInterpolator.SetStartRotation( 0.0 );
		rotationInterpolator.SetEndRotation( 180.0 );
		rotationInterpolator.SetDuration( 3.0 );
		rotationInterpolator.SetType( interpolationType );
		rotationInterpolator.SetMode( interpolationMode );
		if( delayTime > 0.0 )
		{
			rotationInterpolator.SetStartDelay( delayTime );
		}
		m_rotation_anim.AddInterpolator( rotationInterpolator );
		m_size_anim = new inkAnimDef;
		sizeInterpolator = new inkAnimSize;
		sizeInterpolator.SetStartSize( Vector2( 128.0, 128.0 ) );
		sizeInterpolator.SetEndSize( Vector2( 96.0, 96.0 ) );
		sizeInterpolator.SetDuration( 3.0 );
		sizeInterpolator.SetType( interpolationType );
		sizeInterpolator.SetMode( interpolationMode );
		if( delayTime > 0.0 )
		{
			sizeInterpolator.SetStartDelay( delayTime );
		}
		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( interpolationType );
		colorInterpolator.SetMode( interpolationMode );
		if( delayTime > 0.0 )
		{
			colorInterpolator.SetStartDelay( delayTime );
		}
		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( interpolationType );
		alphaInterpolator.SetMode( interpolationMode );
		if( delayTime > 0.0 )
		{
			alphaInterpolator.SetStartDelay( delayTime );
		}
		m_alpha_anim.AddInterpolator( alphaInterpolator );
		m_position_anim = new inkAnimDef;
		positionInterpolator = new inkAnimMargin;
		positionInterpolator.SetStartMargin( inkMargin( 800.0, 150.0, 0.0, 0.0 ) );
		positionInterpolator.SetEndMargin( inkMargin( 600.0, 150.0, 0.0, 0.0 ) );
		positionInterpolator.SetDuration( 3.0 );
		positionInterpolator.SetType( interpolationType );
		positionInterpolator.SetMode( interpolationMode );
		if( delayTime > 0.0 )
		{
			positionInterpolator.SetStartDelay( delayTime );
		}
		m_position_anim.AddInterpolator( positionInterpolator );
	}

}

