/* * TTF example. (incomplete class) * Author: Camilo Menay * 2008 * */ #ifndef ENGINE_GRAPHICS_TEXTWRITTER_H_ #define ENGINE_GRAPHICS_TEXTWRITTER_H_ #include "headers.h" ///Class that write in a surface, you can select color, style and the font type. /** * * SDL text writter class. Needs SDL_ttf. * */ class Engine_Graphics_TextWritter { public: /** * * A constructor. The font load some initial values. * That might be changed then (not fully implemented). * @param srf an SDL surface, writting destination. * */ Engine_Graphics_TextWritter(SDL_Surface* srf) { //TTF engine if (TTF_Init() == -1) { printf("Fallo al inicializar SDL_TTF"); exit(-1); } surface=srf; SetFont(); SetFontStyle(); SetColor(); } /** * * Same as above, but didn't take any particular surface, it * tries to get the actual video surface. */ Engine_Graphics_TextWritter() { //TTF engine if (TTF_Init() == -1) { printf("Fallo al inicializar SDL_TTF"); exit(-1); } surface= SDL_GetVideoSurface(); SetFont(); SetFontStyle(); SetColor(); } /** * Destructor. Should close TTF. */ ~Engine_Graphics_TextWritter() { TTF_Quit(); } /** * Set the font properties. Overloaded so you dont need to give full parameters. * Without parameters, it load the DEFAULT values. */ void SetFont(); void SetFont(char *filename,int size); void SetFont(int size); void SetFont(char *filename); /** * Font style. * Without parameters load a default value. */ void SetFontStyle(); void SetFontStyle(int style); /** * * Font color. * Default color is red. */ void SetColor(){ FontColor = (SDL_Color) {255,100,100,255}; } /** * * Sets an specific color. * @param r as an integer. Red level. * @param g as an integer. Green level. * @param b as an integer. Blue level. * @param u unused. * */ void SetColor(int r,int g,int b,int u) { FontColor = (SDL_Color) {r,g,b,u}; } /** * Write text in the surface, at specific location. * Parameters are not checked (should be). */ void TextWrite(const char* string,int posx,int posy,int sizex,int sizey); /** * Gets the actual surface. */ SDL_Surface* getSurface() { return surface; } private: TTF_Font* font; SDL_Color FontColor; SDL_Surface* surface; }; #endif /*ENGINE_GRAPHICS_TEXTWRITTER_H_*/