#include "headers.h" #include "Engine_Graphics_TextWritter.h" void Engine_Graphics_TextWritter::SetFont(){ font = TTF_OpenFont("/usr/share/fonts/bitstream-vera/Vera.ttf", DEFAULT_FONT_SIZE); if(font == NULL) { printf("Fallo al abrir la fuente"); exit(-1); } } void Engine_Graphics_TextWritter::SetFont(char *filename,int size){ font = TTF_OpenFont(filename, size); if(font == NULL) { printf("Cannot open font file"); exit(-1); } } void Engine_Graphics_TextWritter::SetFont(int size){ font = TTF_OpenFont("/usr/share/fonts/bitstream-vera/Vera.ttf", size); if(font == NULL) { printf("Cannot open font file"); exit(-1); } } void Engine_Graphics_TextWritter::SetFont(char *filename){ font = TTF_OpenFont(filename, DEFAULT_FONT_SIZE); if(font == NULL) { printf("Cannot open font file"); exit(-1); } } void Engine_Graphics_TextWritter::SetFontStyle(){ TTF_SetFontStyle(font, TTF_STYLE_BOLD); } void Engine_Graphics_TextWritter::SetFontStyle(int style){ TTF_SetFontStyle(font, style); } void Engine_Graphics_TextWritter::TextWrite(const char* string,int posx,int posy,int sizex,int sizey){ //surface for store the text as an image SDL_Surface* txt_img; //the text is render as an image txt_img = TTF_RenderText_Blended(font, string , FontColor); //check if(txt_img == NULL) { printf("Text render failed"); exit(-1); } // definition of the rectangle SDL_Rect rect = (SDL_Rect) { posx, posy, sizex, sizey }; //Draw the image (text) in the surface SDL_BlitSurface(txt_img, NULL,surface, &rect); }