/******************************************************************************
 * $Id: gfx_font_opengl.hh,v 1.52 2006/08/10 03:18:58 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Font class (OpenGL).
 * @remarks	This code originated from GL-117 and was modified by Jim E. Brooks.
 *          Original authors: Thomas A. Drexl et al.
 *			GL-117 is a flight simulator program distributed under the GPL license.
 *          -- see description at gfx_font.hh --
 *//*
 * LEGAL:	COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 ******************************************************************************/

#ifndef GFX_FONT_OPENGL_HH
#define GFX_FONT_OPENGL_HH 1

#include "gfx_tga.hh"

namespace gfx {

class Gui;
class Texture;

////////////////////////////////////////////////////////////////////////////////
/// @brief Font class to render fonts from bitmaps.
/// See description at gfx_font.hh.
class Font : public FontBase
{
private:
	typedef FontBase Parent;

public:
					Font( FontDesc* desc, Gui* gui );
					~Font();
	void			SetZoom( float z );
	int				Print( const string& text, float x, float y, eFontMode mode );
	int				Print( const string& text, float x, float y, eFontMode mode, const RGBA rgba );
	int				Print( const char* text, uint textLen, float x, float y, eFontMode mode );
	int				Print( const char* text, uint textLen, float x, float y, eFontMode mode, const RGBA rgba );

private:
	void			PostProcess( Targa& targa /*IN/OUT*/ );
	bool			IsPixel( const Targa& targa, int x, int y );
	void			ExtractLetters( const Targa& targa );
	int				Error( int err );
	const Rect<float>* LastPrintRect( void ) { return &mRect; } ///< used to render button frames etc
	enum eFontPad	{ eFontPad_DEFAULT = 4 };
	void			SetPadding( int p ) { mPadding = p; }

	int				mErrors;
	Gui*			mGui;
	FontDesc*		mFontDesc;
	int				mPadding;		///< padding (in pixels)
	int				mHeight;		///< fixed line height in the texture (should be maximum letter height)
	char			mStart;			///< starting character
	float			mZoom;			///< zoom factor for output
	int				mLetters;		///< number of letters
	short			mLetterx[256];	///< starting x coordinate in the texture
	short			mLettery[256];	///< starting y coordinate in the texture
	short			mLetterw[256];	///< width in the texture
	Texture*		mTexture;		///< the font texture
	Rect<float>		mRect;			///< pair of 2D viewport coords produced by last Print()

friend class GuiButton;
};
#if DEBUG
typedef       Ptr<Font> FontPtr;
typedef const Ptr<Font> FontPtrc;
#else
typedef Font* FontPtr;
typedef Font* FontPtrc;
#endif

} // namespace gfx

#endif // GFX_FONT_OPENGL_HH
