0e2b84582a521182c5121759a0f8f1dd10722972
[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   int len;
38   int i;
39
40 if(shadowsize != 0)
41 text_draw(&black_text,text,x+shadowsize,y+shadowsize, 0, update);
42
43   len = strlen(text);
44
45   for( i = 0; i < len; ++i)
46     {
47       if( text[i] >= 'A' && text[i] <= 'Z')
48       {
49         texture_draw(&ptext->chars[(int)(text[i] - 'A')],x+i*16,y,update);
50         }
51       else if( text[i] >= 'a' && text[i] <= 'z')
52       {
53         texture_draw(&ptext->chars[(int)(text[i] - 'a') + 26],x+i*16,y,update);
54         }
55       else if ( text[i] >= '!' && text[i] <= '9')
56         {
57         texture_draw(&ptext->chars[(int)(text[i] - '!') + 52],x+i*16,y,update);
58         }
59       else if ( text[i] == '?')
60         {
61         texture_draw(&ptext->chars[77],x+i*16,y,update);
62         }
63       else if ( text[i] == '\n')
64         {
65         y += 18;
66         }
67     }
68 }
69
70 void text_drawf(text_type* ptext, char* text, int x, int y, int halign, int valign, int shadowsize, int update)
71 {
72 if(halign == A_RIGHT)
73 x += screen->w;
74 else if(halign == A_HMIDDLE)
75 x += screen->w/2 - ((strlen(text)*16)/2);
76
77 if(valign == A_BOTTOM)
78 y += screen->h - 16;
79 else if(valign == A_VMIDDLE)
80 y += screen->h/2;
81
82 text_draw(ptext,text,x,y,shadowsize,update);
83
84 }
85
86 void text_free(text_type* ptext)
87 {
88   int c;
89   for( c = 0; c < 78; ++c)
90     texture_free(&ptext->chars[c]);
91 }