1 /*
2 * IceBreaker
3 * Copyright (c) 2000-2002 Matthew Miller <mattdm@mattdm.org> and
4 * Enrico Tassi <gareuselesinge@infinito.it>
5 *
6 * <http://www.mattdm.org/icebreaker/>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24 #include <SDL.h>
25 #include <string.h>
26
27 #include "icebreaker.h"
28 #include "text.h"
29 #include "globals.h"
30
31 static char * letterindex;
32 static char * letterdata[6];
33
34
inittext()35 void inittext()
36 {
37 letterindex = " AAAAA BBBBB CCCCC DDDDD EEEEE FFFFF GGGGG HHHHH III JJJJJ KKKK LLLLL MMMMM NNNNN OOOOO PPPPP QQQQQ RRRRR SSSSS TTTTT UUUUU VVVVV WWWWW XXXXX YYYYY ZZZZZ aaaaa bbbbb cccc ddddd eeeee fffff ggggg hhhhh i jjjj kkkk lll mmmmm nnnnn ooooo ppppp qqqqq rrrr sssss tttt uuuuu vvvvv wwwww xxxx yyyyy zzzz 00000 11 22222 33333 44444 55555 66666 77777 88888 99999 ~~~~~ `` ! @@@@ ##### $$$$$ %%%%% ^^^^^ &&&&& ***** (( )) _____ ----- +++++ ===== {{{ [[[ }}} ]]] | : ;; '' <<<<<< ,, >>>>>> . ???? ///// \"\"\" \\\\\\\\\\";
38 letterdata[0]=" # #### ### #### ##### ##### #### # # ### ### # # # # # # # ### #### ### #### #### ##### # # # # # # # # # # ##### # # ### # # # # ## # ### # #### #### ## ##### ### ##### ### ### # # # ## # # ### ## # # ## # # # # # ### # ### # # ## ## ### # # # # ";
39 letterdata[1]=" # # # # # # # # # # # # # # # # # # ## ## ## # # # # # # # # # # # # # # # # # # # # # # # #### #### ### #### ### # #### #### # ## # ## # # ## ### #### #### # ## #### #### # # # # # # # # # # #### # # ## # # # # # # # # # # # # # # # # # ## ##### # # ## # # # # # # # # # # ##### # # # # # # # # ## ## # # # # # ";
40 letterdata[2]=" # # #### # # # #### #### # ## ##### # # ## # # # # # # # # # #### # # #### ### # # # # # # # # # # # # # # # # # # ## ## #### # # # # # # ## # # # # ## # # # # # # # ## ### # # # # # # # # ## # # # # # # ### ### # # #### #### # ### #### # # # ## # # ### # # # ## # ### # # ##### ##### ## # ## # # ## ## ## # # ";
41 letterdata[3]=" ##### # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # ## ## # # # # # ## # # # # # ### # #### # # # # # # # # # # # # # # # # # # # ### # # ## # # # # # ## #### # # # # # # ##### # # # # # # # # ##### # # # ## # # # # # # # # ##### # # # # # # # ## # ## # # # ";
42 letterdata[4]=" # # #### ### #### ##### # #### # # ### ### # # ##### # # # # ### # ### # # #### # ### # # # # # # ##### ## # #### ### #### ### # # # # # # # # # ### # # # # ### #### #### # #### ## ## # # # # # # # #### ### # ##### #### # #### ### # ### ### # ## # # ### # ## ## # # # # # # ### # ### # # ## # ## # # # #";
43 letterdata[5]=" ## ### ## # # ### ##### # # ";
44 }
45
gettextwidth(int size,const char * text)46 int gettextwidth(int size, const char * text)
47 {
48 unsigned int l;
49 int width=0;
50
51 for (l=0; l<strlen(text); l++)
52 {
53 width += getletterwidth(size,*(text+l));
54 width += CHARSPACE;
55 }
56
57
58 // spacing after last letter is not considered
59 width -= CHARSPACE ;
60
61 //fprintf(stderr,"Len of '%s' with size %d is %d pixels.\n",text,size,width);
62
63 return width;
64 }
65
getletterwidth(int size,const char letter)66 int getletterwidth(int size, const char letter)
67 {
68 int i;
69 char * indexpointer;
70 int width=0;
71
72 indexpointer=index(letterindex,letter);
73 if (indexpointer!=NULL)
74 for (i=indexpointer-letterindex; *(letterindex+i)==letter; i++)
75 {
76 width+= size;
77 }
78
79 return width;
80 }
81
puttext(int x,int y,int size,Uint32 color,char * text)82 void puttext(int x, int y, int size, Uint32 color, char * text)
83 {
84 sputtext(screen,x,y,size,color,text);
85 }
86
sputtext(SDL_Surface * scr,int x,int y,int size,Uint32 color,char * text)87 void sputtext(SDL_Surface* scr,int x, int y, int size, Uint32 color, char * text)
88 {
89
90 SDL_Rect tmprect;
91 unsigned int l;
92 int i,j;
93 char * indexpointer;
94 unsigned char c;
95 int w,startx;
96
97 if (size>1)
98 {
99 tmprect.h=(int)(size/2.0+0.5);
100 tmprect.w=(int)(size/2.0+0.5);
101 }
102 else
103 {
104 tmprect.h=1; tmprect.w=1;
105 }
106 startx=x;
107
108 for (l=0; l<strlen(text); l++)
109 {
110 c=*(text+l);
111 indexpointer=index(letterindex,c);
112 if (indexpointer!=NULL)
113 {
114 w=0;
115 for (i=indexpointer-letterindex; *(letterindex+i)==c; i++)
116 { // scan through index for location of letter.
117 for (j=0;j<CHARHEIGHT;j++)
118 {
119 if (*(letterdata[j]+i) != ' ') // hmm. maybe there's a better way to deal with spaces?
120 {
121 tmprect.x=startx+w;
122 tmprect.y=y+j*size;
123 SDL_FillRect(scr,&tmprect,color);
124 }
125 }
126 w+=size;
127 }
128 startx+=w+CHARSPACE;
129 }
130 }
131 }
132
133