4 Super Tux - Screen Functions
7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - April 22, 2000
19 #include <SDL_image.h>
23 #include <sys/types.h>
33 /* --- LOAD AND DISPLAY AN IMAGE --- */
35 void load_and_display_image(char * file)
39 img = load_image(file, IGNORE_ALPHA);
40 SDL_BlitSurface(img, NULL, screen, NULL);
45 /* --- CLEAR SCREEN --- */
47 void clearscreen(int r, int g, int b)
49 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
53 /* --- UPDATE SCREEN --- */
55 void updatescreen(void)
57 SDL_UpdateRect(screen, 0, 0, 640, 480);
61 /* --- LOAD AN IMAGE --- */
63 SDL_Surface * load_image(char * file, int use_alpha)
65 SDL_Surface * temp, * surf;
67 temp = IMG_Load(file);
69 st_abort("Can't load", file);
71 surf = SDL_DisplayFormatAlpha(temp);
74 st_abort("Can't covert to display format", file);
76 if (use_alpha == IGNORE_ALPHA)
77 SDL_SetAlpha(surf, 0, 0);
79 SDL_FreeSurface(temp);
85 /* --- DRAW AN IMAGE ONTO THE SCREEN --- */
87 void drawimage(SDL_Surface * surf, int x, int y, int update)
96 SDL_BlitSurface(surf, NULL, screen, &dest);
99 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
103 /* --- DRAW PART OF AN IMAGE ONTO THE SCREEN --- */
105 void drawpart(SDL_Surface * surf, int x, int y, int w, int h, int update)
119 SDL_BlitSurface(surf, &src, screen, &dest);
121 if (update == UPDATE)
122 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
125 /* --- DRAW SHADED TEXT ONTO THE SCREEN --- */
127 void drawshadedtext(char * text, int x, int y, SDL_Surface * surf, int update)
129 if(surf != letters_black)
131 drawtext(text, x+1, y+1, letters_black, update);
132 drawtext(text, x, y, surf, update);
135 drawtext(text, x, y, surf, update);
139 /* --- DRAW TEXT ONTO THE SCREEN --- */
141 void drawtext(char * text, int x, int y, SDL_Surface * surf, int update)
147 /* For each letter in the string... */
149 for (i = 0; i < strlen(text); i++)
151 /* Set source rectangle: */
155 if (c >= 'A' && c <= 'Z')
157 /* Capital letter - first row: */
159 src.x = (c - 'A') * 16;
162 else if (c >= 'a' && c <= 'z')
164 /* Lowercase letter - first row: */
166 src.x = (c - 'a') * 16;
169 else if (c >= '!' && c <= '9')
171 /* Punctuation (except '?') or number - third row: */
173 src.x = (c - '!') * 16;
178 /* Question mark - third row, last character: */
190 /* Draw character: */
194 /* Set destination rectangle for shadow: */
196 dest.x = x + (i * 16) + 1;
204 SDL_BlitSurface(letters_black, &src, screen, &dest);
207 /* Set destination rectangle for text: */
209 dest.x = x + (i * 16);
217 SDL_BlitSurface(surf, &src, screen, &dest);
224 if (update == UPDATE)
226 dest.w = strlen(text) * 16 + 1;
231 SDL_UpdateRect(screen, x, y, dest.w, 17);
237 /* --- DRAW HORIZONTALLY-CENTERED TEXT: --- */
239 void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update)
241 drawtext(text, 320 - (strlen(text) * 8), y, surf, update);
244 /* --- DRAW SHADED HORIZONTALLY-CENTERED TEXT: --- */
246 void drawshadedcenteredtext(char * text, int y, SDL_Surface * surf, int update)
248 drawshadedtext(text, 320 - (strlen(text) * 8), y, surf, update);
251 /* --- ERASE TEXT: --- */
253 void erasetext(char * text, int x, int y, SDL_Surface * surf, int update)
260 dest.w = strlen(text) * 16 + 1;
266 SDL_BlitSurface(surf, &dest, screen, &dest);
268 if (update == UPDATE)
269 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
273 /* --- ERASE CENTERED TEXT: --- */
275 void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update)
277 erasetext(text, 320 - (strlen(text) * 8), y, surf, update);