- moved loadshared() to the right point
[supertux.git] / src / text.cpp
index 6664258..8258b74 100644 (file)
@@ -17,9 +17,8 @@
 #include "screen.h"
 #include "text.h"
 
-void text_load(text_type* ptext, char* file, int kind, int w, int h)
+void text_load(text_type* ptext, const std::string& file, int kind, int w, int h)
 {
-  int x, y;
   int mx, my;
   SDL_Surface *conv;
   int pixels;
@@ -62,7 +61,7 @@ void text_load(text_type* ptext, char* file, int kind, int w, int h)
   SDL_FreeSurface(conv);
 }
 
-void text_draw(text_type* ptext, char* text, int x, int y, int shadowsize, int update)
+void text_draw(text_type* ptext,const  char* text, int x, int y, int shadowsize, int update)
 {
   if(text != NULL)
     {
@@ -73,7 +72,7 @@ void text_draw(text_type* ptext, char* text, int x, int y, int shadowsize, int u
     }
 }
 
-void text_draw_chars(text_type* ptext, texture_type* pchars, char* text, int x, int y, int update)
+void text_draw_chars(text_type* ptext, texture_type* pchars,const  char* text, int x, int y, int update)
 {
   int i,j,len;
   int w, h;
@@ -87,13 +86,13 @@ void text_draw_chars(text_type* ptext, texture_type* pchars, char* text, int x,
       for( i = 0, j = 0; i < len; ++i,++j)
         {
           if( text[i] >= 'A' && text[i] <= 'Z')
-            texture_draw_part(pchars, (int)(text[i] - 'A')*w, 0, x+(j*w), y, ptext->w, ptext->h, update);
+            texture_draw_part(pchars, (int)(text[i] - 'A')*w, 0, x+(j*w), y, ptext->w, ptext->h, 255,  update);
           else if( text[i] >= 'a' && text[i] <= 'z')
-            texture_draw_part(pchars, (int)(text[i] - 'a')*w, h, x+(j*w), y, ptext->w, ptext->h, update);
+            texture_draw_part(pchars, (int)(text[i] - 'a')*w, h, x+(j*w), y, ptext->w, ptext->h, 255,  update);
           else if ( text[i] >= '!' && text[i] <= '9')
-            texture_draw_part(pchars, (int)(text[i] - '!')*w, h*2, x+(j*w), y, ptext->w, ptext->h, update);
+            texture_draw_part(pchars, (int)(text[i] - '!')*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255,  update);
           else if ( text[i] == '?')
-            texture_draw_part(pchars, 25*w, h*2, x+(j*w), y, ptext->w, ptext->h, update);
+            texture_draw_part(pchars, 25*w, h*2, x+(j*w), y, ptext->w, ptext->h, 255,  update);
           else if ( text[i] == '\n')
             {
               y += ptext->h + 2;
@@ -106,7 +105,7 @@ void text_draw_chars(text_type* ptext, texture_type* pchars, char* text, int x,
       for( i = 0, j = 0; i < len; ++i, ++j)
         {
           if ( text[i] >= '0' && text[i] <= '9')
-            texture_draw_part(pchars, (int)(text[i] - '0')*w, 0, x+(j*w), y, w, h, update);
+            texture_draw_part(pchars, (int)(text[i] - '0')*w, 0, x+(j*w), y, w, h, 255, update);
           else if ( text[i] == '\n')
             {
               y += ptext->h + 2;
@@ -116,7 +115,43 @@ void text_draw_chars(text_type* ptext, texture_type* pchars, char* text, int x,
     }
 }
 
-void text_drawf(text_type* ptext, char* text, int x, int y, int halign, int valign, int shadowsize, int update)
+void text_draw_align(text_type* ptext, const char* text, int x, int y,
+                     TextHAlign halign, TextVAlign valign, int shadowsize, int update)
+{
+  if(text != NULL)
+    {
+      switch (halign)
+        {
+        case A_RIGHT:
+          x += -(strlen(text)*ptext->w);
+          break;
+        case A_HMIDDLE:
+          x += -((strlen(text)*ptext->w)/2);
+          break;
+        case A_LEFT:
+          // default
+          break;
+        }
+
+      switch (valign)
+        {
+        case A_BOTTOM:
+          y -= ptext->h;
+          break;
+          
+        case A_VMIDDLE:
+          y -= ptext->h/2;
+
+        case A_TOP:
+          // default
+          break;
+        }
+
+      text_draw(ptext, text, x, y, shadowsize, update);
+    }
+}
+
+void text_drawf(text_type* ptext,const  char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update)
 {
   if(text != NULL)
     {
@@ -130,13 +165,12 @@ void text_drawf(text_type* ptext, char* text, int x, int y, int halign, int vali
       else if(valign == A_VMIDDLE)
         y += screen->h/2 - ptext->h/2;
 
-      text_draw(ptext,text,x,y,shadowsize,update);
+      text_draw(ptext,text,x,y,shadowsize, update);
     }
 }
 
 void text_free(text_type* ptext)
 {
-  int c;
   if(ptext->kind == TEXT_TEXT)
     texture_free(&ptext->chars);
   else if(ptext->kind == TEXT_NUM)
@@ -145,7 +179,7 @@ void text_free(text_type* ptext)
 
 /* --- ERASE TEXT: --- */
 
-void erasetext(text_type* ptext, char * text, int x, int y, texture_type * ptexture, int update, int shadowsize)
+void erasetext(text_type* ptext,const  char * text, int x, int y, texture_type * ptexture, int update, int shadowsize)
 {
   SDL_Rect dest;
 
@@ -158,7 +192,7 @@ void erasetext(text_type* ptext, char * text, int x, int y, texture_type * ptext
   if (dest.w > screen->w)
     dest.w = screen->w;
 
-  texture_draw_part(ptexture,dest.x,dest.y,dest.x,dest.y,dest.w,dest.h,update);
+  texture_draw_part(ptexture,dest.x,dest.y,dest.x,dest.y,dest.w,dest.h, 255, update);
 
   if (update == UPDATE)
     update_rect(screen, dest.x, dest.y, dest.w, dest.h);
@@ -167,7 +201,7 @@ void erasetext(text_type* ptext, char * text, int x, int y, texture_type * ptext
 
 /* --- ERASE CENTERED TEXT: --- */
 
-void erasecenteredtext(text_type* ptext, char * text, int y, texture_type * ptexture, int update, int shadowsize)
+void erasecenteredtext(text_type* ptext,const  char * text, int y, texture_type * ptexture, int update, int shadowsize)
 {
   erasetext(ptext, text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize);
 }