initial
[supertux.git] / src / text.c
1 //
2 // C Implementation: text
3 //
4 // Description:
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #include <string.h>
14 #include "globals.h"
15 #include "defines.h"
16 #include "screen.h"
17 #include "text.h"
18
19 void text_load(text_type* ptext, char* file)
20 {
21   int x, y, c;
22
23   c = 0;
24
25   for(y = 0; y < 3 ; ++y)
26     {
27       for(x = 0; x < 26 ; ++x)
28         {
29           texture_load_part(&ptext->chars[c],file,x*16,y*16,16,16, USE_ALPHA);
30           ++c;
31         }
32     }
33 }
34
35 void text_draw(text_type* ptext, char* text, int x, int y, int shadowsize, int update)
36 {
37
38 if(shadowsize != 0)
39 text_draw(&black_text,text,x+shadowsize,y+shadowsize, 0, update);
40
41   int len = strlen(text);
42   int i;
43   for( i = 0; i < len; ++i)
44     {
45       if( text[i] >= 'A' && text[i] <= 'Z')
46       {
47         texture_draw(&ptext->chars[(int)(text[i] - 'A')],x+i*16,y,update);
48         }
49       else if( text[i] >= 'a' && text[i] <= 'z')
50       {
51         texture_draw(&ptext->chars[(int)(text[i] - 'a') + 26],x+i*16,y,update);
52         }
53       else if ( text[i] >= '!' && text[i] <= '9')
54         {
55         texture_draw(&ptext->chars[(int)(text[i] - '!') + 52],x+i*16,y,update);
56         }
57       else if ( text[i] == '?')
58         {
59         texture_draw(&ptext->chars[77],x+i*16,y,update);
60         }
61       else if ( text[i] == '\n')
62         {
63         y += 18;
64         }
65     }
66 }
67
68 void text_drawf(text_type* ptext, char* text, int x, int y, int halign, int valign, int shadowsize, int update)
69 {
70 if(halign == A_RIGHT)
71 x += screen->w;
72 else if(halign == A_HMIDDLE)
73 x += screen->w/2 - ((strlen(text)*16)/2);
74
75 if(valign == A_BOTTOM)
76 y += screen->h - 16;
77 else if(valign == A_VMIDDLE)
78 y += screen->h/2;
79
80 text_draw(ptext,text,x,y,shadowsize,update);
81
82 }
83
84 void text_free(text_type* ptext)
85 {
86   int c;
87   for( c = 0; c < 78; ++c)
88     texture_free(&ptext->chars[c]);
89 }