Main Page | Namespace List | Class List | File List | Class Members | File Members

video_fonts.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   NGT (Neopontec Gaming Toolkit                                         *
00003  *   Distributed under the terms of the GNU LGPL License                   *
00004  *   Copyright (C) 2005 by Hector Blanco de Frutos                         *
00005  *   hectorblanco@neopontec.com                                            *
00006  *   Refer to the LICENSE file to read the full license agreement          *
00007  ***************************************************************************/
00008  
00009  #include "video_fonts.h"
00010  
00011  void NGT_Font::draw(string text, SDL_Surface *surf, int draw_x, int draw_y){
00012         NGT_Surface textsurface;
00013         
00014         switch (mode){
00015         
00016                 case TEXT_NONE:
00017                         textsurface.surface = TTF_RenderText_Solid(font,text.c_str(),color);
00018                         break;
00019                         
00020                 case TEXT_BLENDED:
00021                         textsurface.surface = TTF_RenderText_Blended(font,text.c_str(),color);
00022                         break;  
00023                 
00024         }
00025 
00026     textsurface.x=draw_x;
00027     textsurface.y=draw_y;
00028     textsurface.draw(surf);
00029     textsurface.free();
00030         
00031  }
00032  
00033  
00034   void NGT_Font::draw(string text, SDL_Surface *scr){
00035         NGT_Surface textsurface;
00036         
00037                 if (font == NULL){
00038                         printf("*NGT_Font.draw: ERROR drawing. A font was not loaded previously\n");    
00039                 }
00040                 
00041         switch (mode){
00042         
00043                 case TEXT_NONE:
00044                         textsurface.surface=TTF_RenderText_Solid(font,text.c_str(),color);
00045                         break;
00046                         
00047                 case TEXT_BLENDED:
00048                         textsurface.surface=TTF_RenderText_Blended(font,text.c_str(),color);
00049                         break;  
00050                 
00051         }
00052 
00053     textsurface.x=x;
00054     textsurface.y=y;
00055     textsurface.draw(scr);
00056     textsurface.free();
00057         
00058  }
00059 
00060 int NGT_Font::LoadTTF(){
00061         LoadTTF(filename, size);
00062         
00063         return 0;
00064 }
00065 
00066  int NGT_Font::LoadTTF(string filename, int size){
00067         // If file cant be load, close the app
00068         if(fopen(filename.c_str(),"r")==NULL){
00069                 printf("*NGT_Font.LoadTTF: ERROR Loading the TTF file: '%s'\n",filename.c_str());
00070                 return(1);
00071         }else{
00072                 // Load the desired TTF Font
00073                 font=TTF_OpenFont(filename.c_str(), size);
00074                 printf("*NGT_Font.LoadTTF: Loaded the TTF file: '%s'\n",filename.c_str());
00075                 
00076                 // Clear the memory used by the font
00077                 //TTF_CloseFont(font);
00078                 return(0);
00079         }
00080         
00081  } 
00082  

Generated on Wed Feb 1 00:07:07 2006 for Neopntec Gaming Toolkit - API reference by  doxygen 1.4.4