#ifndef __TEXTRENDER_H
#define __TEXTRENDER_H

#ifdef __cplusplus
extern "C" {
#endif

#define DEFAULT_X 5
#define DEFAULT_Y 5

#define DEFAULT_Y_CUSHION 2
#define DEFAULT_TAB_SPACE 50

#define DEFAULT_X_RIGHT_EDGE 5

#include <stdint.h>
#include <ft2build.h>
#include FT_FREETYPE_H

#include "color.h"
#include "sound.h"
#include "theme.h"

typedef struct
{
	int left;
	int top;
	int width;
	int rows;
	int advance;
	uint8_t *data;
} Buffer;

class TextRender
{
	public:
		TextRender();
		~TextRender();
		
		void setFont(const char *font);
		void setColor(Color c);
		void setSize(int s);
		
		void setRenderPosition(int x, int y);
		void setBuffer(uint8_t *buf, int width, int height);
		void renderSimple(const char *out);
		void render(const char *fmt, ...);
		
		int getRenderedWidth();
		int getRenderedHeight();
	private:
		void Blit(uint8_t *bmpBuf, int runWidth, int runHeight, int left, int top);
		
		static FT_Library library;
		static int renderCount;
		
		Theme windowManager;
		FT_Face face;
		
		Sound sound;
		
		uint8_t *_buf;
		int _width;
		int _height;
		int _fontheight;
		Color _color;
		
		int _renderx;
		int _rendery;
		
		int _renderedwidth;
		int _renderedheight;
		
		Buffer spriteBuf[256];
};

#ifdef __cplusplus
}
#endif

#endif


