/*
	Lan Wars.
	Copyright (c) 2009, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef BITMAP_FONT_MANAGER_H
#define BITMAP_FONT_MANAGER_H

//=====================================================================================================================
//=====================================================================================================================

#include "Resources\ResourceManager.h"

//=====================================================================================================================
//=====================================================================================================================

namespace Game
{
	//=================================================================================================================
	//=================================================================================================================
	
	class Display;
	class VertexShaderManager;
	class PixelShaderManager;
	class TextureManager;
	class BitmapFont;
	class VertexFormat;
	struct BitmapFontResourceData;	

	//=================================================================================================================
	/// @brief		This type of resource manager loads and keeps track of bitmap font resources. 
	//=================================================================================================================

	class BitmapFontManager : public ResourceManager<BitmapFontResourceData*>
	{
		public:
		
			//=========================================================================================================
			// Constants
			//=========================================================================================================
		
				/// Maximum Number of characters that can be rendered in one batch by a font

				static const int RENDER_BUFFER_SIZE = 4096;
				
			//=========================================================================================================
			// Structs
			//=========================================================================================================
			
				/// Format of the vertices used during font rendering
				
				struct BitmapFontVertex
				{
					/// Posititon of the vertex
				
					Vec3f m_position;
					
					/// Color of the vertex
					
					Color m_color;
					
					/// Texture coordinate of the vertex
					
					Vec2f m_texcoord;
				};

			//=========================================================================================================
			// Functions
			//=========================================================================================================
	        
				/// Constructor. Creates the font manager.
	        
				BitmapFontManager
				( 
					Display *				display	,
					VertexShaderManager *	vs_mgr	,  
					PixelShaderManager *	ps_mgr	,
					TextureManager *		tex_mgr
				);
				
				/// Destructor. Destroys the pixel shader manager.
				
				~BitmapFontManager();
				
				/// Retrieves the given bitmap font
				
				BitmapFont GetBitmapFont( const char * name );
				
				/// Retrieves the given bitmap font
				
				BitmapFont GetBitmapFont( const std::string & name );
				
				/// Tells the object to announce it's type name: this is the type name without the Game:: namespace

				virtual const char * GetTypeName();
				
				/// Gets the texture manager used by this font manager
				
				inline TextureManager * GetTextureManager(){ return m_texture_manager; }
		
				/// Gets the vertex shader manager used by this font manager
				
				inline VertexShaderManager * GetVertexShaderManager(){ return m_vertex_shader_manager; }
				
				/// Gets the pixel shader manager used by this font manager
				
				inline PixelShaderManager * GetPixelShaderManager(){ return m_pixel_shader_manager; }
				
				/// Returns the render buffer stack used by fonts for rendering. Only intended to be used by fonts
				
				inline Stack & GetRenderBuffer(){ return m_render_buffer_stack; }
				
				/// Returns the direct3d device currently in use by the manager
				
				inline IDirect3DDevice9 * GetDevice(){ return m_d3d_device; }
				
				/// Gets the vertex format used by all bitmap fonts
				
				inline VertexFormat * GetVertexFormat(){ return m_vertex_format; }
		
		private:
				
			//=========================================================================================================
			// Variables
			//=========================================================================================================
				
				/// The texture manager used by the font manager
				
				TextureManager * m_texture_manager;
				
				/// The vertex shader manager used by the font manager
				
				VertexShaderManager * m_vertex_shader_manager;
				
				/// The pixel shader manager used by the font manager
				
				PixelShaderManager * m_pixel_shader_manager;
				
				/// A stack used as buffer for rendering
				
				Stack m_render_buffer_stack;
				
				/// The directx 9 display used by the manager
				
				IDirect3DDevice9 * m_d3d_device;
				
				/// The vertex format used by all fonts
				
				VertexFormat * m_vertex_format;
	};	

};

#endif
