/***************************************************************************
 *            font.h
 *
 *  Sun Sep 26 13:33:51 2004
 *  Copyright  2004  Joe Venzon
 *  joe@venzon.net
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
#ifndef _FONT_H

#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#include <string>
#include <iostream>
#include <fstream>

#include "utility.h"
#include "textures.h"
#include "settings.h"
#include "globals.h"

using namespace std;

class CHARACTERINFO
{
public:
	char character;
	int minx;
	int maxx;
	int miny;
	int maxy;
};

class FONT
{
private:
	bool loaded;
	TEXTURE_HANDLE fonttexture;
	string fontname;
	CHARACTERINFO charinfo[96];
	float averagecenter;
	int fontsize, totalx, totaly, tw, th;
	
public:
	FONT() {loaded=false;}
	
	const bool Load(const string & newfontname);
	const string & GetFontName() const {return fontname;}
	const float GetAverageCenter() const {return averagecenter;}
	const int GetFontSize() const {return fontsize;}
	const float Print(const float px, const float py, const string & str, const float scale, const float r, const float g, const float b, const float a, const bool draw);
	const float DrawChar(const char curchar, const float scale, const bool draw, const float px, const float py);
};

class FONTMANAGER
{
private:
	list <FONT> fontlist;

	const string GetBackwardCompatibilityFontName(const int set) const;
	const float GetBackwardCompatibilityScale(const int size) const;
	
public:
	FONTMANAGER() {}
		
	void ClearFonts() {fontlist.clear();}
	
	FONT * const GetFont(const string & name);
	
	const bool LoadFont(const string & newfontname);
	const float Print(const string & name, const float px, const float py, const string & str, const float scale, const float r, const float g, const float b, const float a);
	//float Print(string & name, float px, float py, string & str, float scale, float r, float g, float b, float a, RENDERRECT & dest);
	const float PrintWidth(const string & name, const string & str, const float scale);  //returns a width in percent of screen
	const float GetAverageVerticalPosition(const string & name);
	const int GetFontSize(const string & name);
	const float GetFontHeight(const string & name, const float scale);
	
	//old interface, provided for backwards compatibility
	void Print( float px, float py, const char *string, int set, int size, float opacity ) {Print( px, py, string, set, size, 1,1,1, opacity);}
	void Print( float px, float py, const char *string, int set, int size, float r, float g, float b ) {Print(px, py, string, set, size, r, g, b, 1);}
	void Print( float px, float py, const char *string, int set, int size, float r, float g, float b, float trans );
	const float Width(const char * str, int set, int size);
	float Height(const char * str, int set, int size);
	void Load();
};

/*class FONT
{
private:
	GLuint base;
	TEXTURE_HANDLE texture;

	ofstream error_log;

	int spacing[2][128];

	bool loaded;

	void GetSizing(int size, int & sx, int & sy);
	
public:
	FONT();
	~FONT();
	void Load();
	void Print( float px, float py, const char *string, int set, int size, float opacity );
	void Print( float px, float py, const char *string, int set, int size, float r, float g, float b );
	void Print( float px, float py, const char *string, int set, int size, float r, float g, float b, float trans );

	float Width(const char * str, int set, int size);
	float Height(const char * str, int set, int size);
};*/

#define _FONT_H
#endif /* _FONT_H */
