/******************************************************************************
 * $Id: gfx_font.hh,v 1.44 2006/08/10 03:18:58 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Font class (OS-neutral).
 * @remarks Define DEBUG=1 to get error messages.
 *//*
 * 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_HH
#define GFX_FONT_HH 1

#include "gfx_rgb.hh"

namespace gfx {

////////////////////////////////////////////////////////////////////////////////
/// @class FontBase
/// @brief Font class to render fonts from bitmaps.
/// @remarks
/// This base class is derived by the graphic system specific Font class.
/// The Font class provides the interface for printing bitmapped fonts.
/// The FontDesc class provides the interface for defining/allocating a font.
/// The other classes are implementation-specific (don't use elsewhere).

/// @brief Font mode bits.  Select only one justification.
enum eFontMode
{
	eFontMode_NORMAL				= (0),
	// justification
	eFontMode_CENTER				= (1<<0),
	eFontMode_NE					= (1<<1),
	eFontMode_SE					= (1<<2),
	eFontMode_SW					= (1<<3),
	eFontMode_NW					= (1<<4),
	// highlight, background
	eFontMode_BG					= (1<<5),
	eFontMode_HILITE				= (1<<6),
	// masks
	eFontMode_MASK_JUSTIFY_CORNER	= (eFontMode_NE|eFontMode_SE|eFontMode_SW|eFontMode_NW),
	eFontMode_MASK_RIGHT			= (eFontMode_NE|eFontMode_SE),
	eFontMode_MASK_LEFT				= (eFontMode_NW|eFontMode_SW),
};
// ------------------------------------------------

class FontBase
{
    PREVENT_COPYING(FontBase)
public:
	enum eFontError
	{
		eFontError_NOT_READY	= (1<<0),
		eFontError_GFXSYS		= (1<<1),
		eFontError_NEWLINE		= (1<<2)
	};

                    FontBase( void ) { }
	virtual			~FontBase() { }

	/// @brief Print(): Print a text string in the window using a bitmapped font.
	/// @return 0 if successful or Font::ERROR_* bits.
	/// @param	text
	///			String should NOT contain newlines nor tabs (unlike GL-117).
	/// @param	x,y
	///			Font cell coords (sort of like VGA text mode).
	///			For corner-justification, absolute values of coords are used.
	///	@param	mode
	///			Bitmask for justification (relative to a window corner).
	///	@param	rgba
    ///         (optional)
	/// @verbatim
	/// For example:
	/// Print( 0, 0, FONT_CENTER, "HI" );
	/// Print( 2, 1, FONT_SE,     "HELLO );
	/// Print( 0, 0, FONT_NW,     "BYE" );
	///
	///     +-------------------+
	///     |BYE                |
	///     |                   |
	///     |                   |
	///     |                   |
	///     |                   |
	///     |         HI        |
	///     |                   |
	///     |                   |
	///     |                   |
	///     |            HELLO  | (2,1)
	///     |                   |
	///     +-------------------+
	/// @endverbatim
	virtual int		Print( const string& text, float x, float y, eFontMode mode ) = 0;
	virtual int		Print( const string& text, float x, float y, eFontMode mode, const RGBA rgba ) = 0;
	virtual int		Print( const char* text, uint textLen, float x, float y, eFontMode mode ) = 0;
	virtual int		Print( const char* text, uint textLen, float x, float y, eFontMode mode, const RGBA rgba ) = 0;
	virtual void	SetZoom( float z ) = 0;
};

////////////////////////////////////////////////////////////////////////////////
/// Font descriptor class.
class FontDesc
{
    PREVENT_COPYING(FontDesc)
public:
	FontDesc( const string& name, const uchar* data, uint dataLen, int height,
              char start, int letters, bool antialias, float zoom )
	:	mName(name),
		mData(data),
		mDataLen(dataLen),
		mHeight(height),
		mStart(start),
		mLetters(letters),
		mAntialias(antialias),
		mZoom(zoom)
	{
	}
	~FontDesc()
	{
		// NOP
	}

private:
	string				mName;
	const uchar*		mData;
	int					mDataLen;
	int					mHeight;
	char				mStart;
	int					mLetters;
	bool				mAntialias;
	float				mZoom;

friend class Font;
};

// These need to be declared within the gfx namespace.
extern unsigned char gGfxFont1Data[];
extern unsigned int  gGfxFont1DataLen;
extern unsigned char gGfxFont2Data[];
extern unsigned int  gGfxFont2DataLen;

} // namespace gfx

#if GFXSYS_OPENGL
#include "gfx_font_opengl.hh"
#endif

#endif // GFX_FONT_HH
