class AnimateAnchorOnHoverView extends inkLogicController
{
	private editable var m_Raycaster : inkWidgetRef;
	private var m_AnimProxy : inkAnimProxy;
	private editable var m_HoverAnchor : Vector2;
	private editable var m_NormalAnchor : Vector2;
	private editable var m_AnimTime : Float;
	default m_AnimTime = 0.1f;

	protected event OnInitialize()
	{
		inkWidgetRef.RegisterToCallback( m_Raycaster, 'OnHoverOver', this, 'OnHoverOver' );
		inkWidgetRef.RegisterToCallback( m_Raycaster, 'OnHoverOut', this, 'OnHoverOut' );
	}

	protected event OnUninitialize()
	{
		inkWidgetRef.UnregisterFromCallback( m_Raycaster, 'OnHoverOver', this, 'OnHoverOver' );
		inkWidgetRef.UnregisterFromCallback( m_Raycaster, 'OnHoverOut', this, 'OnHoverOut' );
	}

	protected event OnHoverOver( e : inkPointerEvent )
	{
		OnHoverChanged( true );
	}

	protected event OnHoverOut( e : inkPointerEvent )
	{
		OnHoverChanged( false );
	}

	protected function OnHoverChanged( isHovered : Bool )
	{
		var animDef : inkAnimDef;
		var anchorInterp : inkAnimAnchor;
		if( isHovered )
		{
			StopAnimation();
			animDef = new inkAnimDef;
			anchorInterp = new inkAnimAnchor;
			anchorInterp.SetDirection( inkanimInterpolationDirection.To );
			anchorInterp.SetEndAnchor( m_HoverAnchor );
			anchorInterp.SetDuration( m_AnimTime );
			animDef.AddInterpolator( anchorInterp );
			m_AnimProxy = GetRootWidget().PlayAnimation( animDef );
		}
		else if( !( isHovered ) )
		{
			StopAnimation();
			animDef = new inkAnimDef;
			anchorInterp = new inkAnimAnchor;
			anchorInterp.SetDirection( inkanimInterpolationDirection.To );
			anchorInterp.SetEndAnchor( m_NormalAnchor );
			anchorInterp.SetDuration( m_AnimTime );
			animDef.AddInterpolator( anchorInterp );
			m_AnimProxy = GetRootWidget().PlayAnimation( animDef );
		}
	}

	protected function StopAnimation()
	{
		if( m_AnimProxy && m_AnimProxy.IsPlaying() )
		{
			m_AnimProxy.Stop();
		}
	}

}

