class PhotoModeFrame extends inkLogicController
{
	private const editable var m_images : array< inkImageRef >;
	private editable var m_keepImageAspectRatio : Bool;
	var m_stickersController : weak< gameuiPhotoModeStickersController >;
	private var m_currentImagePart : CName;
	private var m_opacity : Float;

	public function SetupScale( rootSize : Vector2 )
	{
		var aspect : Float;
		var minAspect : Float;
		var i : Int32;
		var scale : Float;
		aspect = rootSize.X / rootSize.Y;
		minAspect = 16.0 / 9.0;
		if( m_keepImageAspectRatio && ( aspect < minAspect ) )
		{
			scale = minAspect / aspect;
		}
		else
		{
			scale = 1.0;
		}
		for( i = 0; i < m_images.Size(); i += 1 )
		{
			inkImageRef.SetScale( m_images[ i ], Vector2( scale, scale ) );
		}
	}

	public function SetAtlas( atlasPath : ResRef )
	{
		var i : Int32;
		for( i = 0; i < m_images.Size(); i += 1 )
		{
			inkImageRef.SetAtlasResource( m_images[ i ], atlasPath );
		}
	}

	public function SetImages( const imageParts : ref< array< CName > > )
	{
		var i : Int32;
		for( i = 0; ( i < imageParts.Size() ) && ( i < m_images.Size() ); i += 1 )
		{
			inkImageRef.SetTexturePart( m_images[ i ], imageParts[ i ] );
		}
		m_currentImagePart = imageParts[ 0 ];
		m_opacity = 0.0;
	}

	public function SetColor( color : Color )
	{
		var i : Int32;
		for( i = 0; i < m_images.Size(); i += 1 )
		{
			inkImageRef.SetTintColor( m_images[ i ], color );
		}
	}

	public function SetFlip( horizontal : Bool, vertical : Bool )
	{
		var i : Int32;
		for( i = 0; i < m_images.Size(); i += 1 )
		{
			if( horizontal && vertical )
			{
				inkImageRef.SetBrushMirrorType( m_images[ i ], inkBrushMirrorType.Both );
			}
			else if( horizontal )
			{
				inkImageRef.SetBrushMirrorType( m_images[ i ], inkBrushMirrorType.Horizontal );
			}
			else if( vertical )
			{
				inkImageRef.SetBrushMirrorType( m_images[ i ], inkBrushMirrorType.Vertical );
			}
			else
			{
				inkImageRef.SetBrushMirrorType( m_images[ i ], inkBrushMirrorType.NoMirror );
			}
		}
	}

	public function Update( timeDelta : Float )
	{
		if( m_currentImagePart != '' && inkImageRef.IsTexturePartExist( m_images[ 0 ], m_currentImagePart ) )
		{
			if( m_opacity < 1.0 )
			{
				m_opacity += ( timeDelta * 6.0 );
				if( m_opacity >= 1.0 )
				{
					m_opacity = 1.0;
				}
			}
		}
		else
		{
			m_opacity = 0.0;
		}
		GetRootWidget().SetOpacity( m_opacity );
	}

}

