-
Notifications
You must be signed in to change notification settings - Fork 7
/
text.c
132 lines (112 loc) · 6.67 KB
/
text.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* IceBreaker
* Copyright (c) 2000-2020 Matthew Miller <[email protected]> and
* Enrico Tassi <[email protected]>
*
* <http://www.mattdm.org/icebreaker/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <SDL.h>
#include <string.h>
#include "icebreaker.h"
#include "text.h"
#include "globals.h"
static char * letterindex;
static char * letterdata[6];
void inittext()
{
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 ~~~~~ `` ! @@@@ ##### $$$$$ %%%%% ^^^^^ &&&&& ***** (( )) _____ ----- +++++ ===== {{{ [[[ }}} ]]] | : ;; '' <<<<<< ,, >>>>>> . ???? ///// \"\"\" \\\\\\\\\\";
letterdata[0]=" # #### ### #### ##### ##### #### # # ### ### # # # # # # # ### #### ### #### #### ##### # # # # # # # # # # ##### # # ### # # # # ## # ### # #### #### ## ##### ### ##### ### ### # # # ## # # ### ## # # ## # # # # # ### # ### # # ## ## ### # # # # ";
letterdata[1]=" # # # # # # # # # # # # # # # # # # ## ## ## # # # # # # # # # # # # # # # # # # # # # # # #### #### ### #### ### # #### #### # ## # ## # # ## ### #### #### # ## #### #### # # # # # # # # # # #### # # ## # # # # # # # # # # # # # # # # # ## ##### # # ## # # # # # # # # # # ##### # # # # # # # # ## ## # # # # # ";
letterdata[2]=" # # #### # # # #### #### # ## ##### # # ## # # # # # # # # # #### # # #### ### # # # # # # # # # # # # # # # # # # ## ## #### # # # # # # ## # # # # ## # # # # # # # ## ### # # # # # # # # ## # # # # # # ### ### # # #### #### # ### #### # # # ## # # ### # # # ## # ### # # ##### ##### ## # ## # # ## ## ## # # ";
letterdata[3]=" ##### # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # ## ## # # # # # ## # # # # # ### # #### # # # # # # # # # # # # # # # # # # # ### # # ## # # # # # ## #### # # # # # # ##### # # # # # # # # ##### # # # ## # # # # # # # # ##### # # # # # # # ## # ## # # # ";
letterdata[4]=" # # #### ### #### ##### # #### # # ### ### # # ##### # # # # ### # ### # # #### # ### # # # # # # ##### ## # #### ### #### ### # # # # # # # # # ### # # # # ### #### #### # #### ## ## # # # # # # # #### ### # ##### #### # #### ### # ### ### # ## # # ### # ## ## # # # # # # ### # ### # # ## # ## # # # #";
letterdata[5]=" ## ### ## # # ### ##### # # ";
}
int gettextwidth(int size, const char * text)
{
unsigned int l;
int width=0;
for (l=0; l<strlen(text); l++)
{
width += getletterwidth(size,*(text+l));
width += CHARSPACE;
}
// spacing after last letter is not considered
width -= CHARSPACE ;
//fprintf(stderr,"Len of '%s' with size %d is %d pixels.\n",text,size,width);
return width;
}
int getletterwidth(int size, const char letter)
{
int i;
char * indexpointer;
int width=0;
indexpointer=index(letterindex,letter);
if (indexpointer!=NULL)
for (i=indexpointer-letterindex; *(letterindex+i)==letter; i++)
{
width+= size;
}
return width;
}
void puttext(int x, int y, int size, Uint32 color, char * text)
{
sputtext(screen,x,y,size,color,text);
}
void sputtext(SDL_Surface* scr,int x, int y, int size, Uint32 color, char * text)
{
SDL_Rect tmprect;
unsigned int l;
int i,j;
char * indexpointer;
unsigned char c;
int w,startx;
if (size>1)
{
tmprect.h=(int)(size/2.0+0.5);
tmprect.w=(int)(size/2.0+0.5);
}
else
{
tmprect.h=1; tmprect.w=1;
}
startx=x;
for (l=0; l<strlen(text); l++)
{
c=*(text+l);
indexpointer=index(letterindex,c);
if (indexpointer!=NULL)
{
w=0;
for (i=indexpointer-letterindex; *(letterindex+i)==c; i++)
{ // scan through index for location of letter.
for (j=0;j<CHARHEIGHT;j++)
{
if (*(letterdata[j]+i) != ' ') // hmm. maybe there's a better way to deal with spaces?
{
tmprect.x=startx+w;
tmprect.y=y+j*size;
SDL_FillRect(scr,&tmprect,color);
}
}
w+=size;
}
startx+=w+CHARSPACE;
}
}
}