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)
66 SDL_Surface * temp, * surf;
68 temp = IMG_Load(file);
71 st_abort("Can't load", file);
73 surf = SDL_DisplayFormatAlpha(temp);
76 st_abort("Can't covert to display format", file);
78 if (use_alpha == IGNORE_ALPHA)
79 SDL_SetAlpha(surf, 0, 0);
81 SDL_FreeSurface(temp);
87 /* --- DRAW AN IMAGE ONTO THE SCREEN --- */
89 void drawimage(SDL_Surface * surf, int x, int y, int update)
98 SDL_BlitSurface(surf, NULL, screen, &dest);
100 if (update == UPDATE)
101 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
105 /* --- DRAW PART OF AN IMAGE ONTO THE SCREEN --- */
107 void drawpart(SDL_Surface * surf, int x, int y, int w, int h, int update)
121 SDL_BlitSurface(surf, &src, screen, &dest);
123 if (update == UPDATE)
124 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
127 /* --- DRAW TEXT ONTO THE SCREEN --- */
129 void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize)
131 /* i - helps to keep tracking of the all string length
132 j - helps to keep track of the length of the current line */
137 /* For each letter in the string... */
139 for (i = 0; i < strlen(text); i++)
141 /* Set source rectangle: */
145 if (c >= 'A' && c <= 'Z')
147 /* Capital letter - first row: */
149 src.x = (c - 'A') * 16;
152 else if (c >= 'a' && c <= 'z')
154 /* Lowercase letter - first row: */
156 src.x = (c - 'a') * 16;
159 else if (c >= '!' && c <= '9')
161 /* Punctuation (except '?') or number - third row: */
163 src.x = (c - '!') * 16;
168 /* Question mark - third row, last character: */
173 else if (c == '\n') /* support for multi-lines */
186 /* Draw character: */
190 /* Set destination rectangle for shadow: */
192 dest.x = x + (i * 16) + shadowsize;
193 dest.y = y + shadowsize;
200 SDL_BlitSurface(letters_black, &src, screen, &dest);
203 /* Set destination rectangle for text: */
205 dest.x = x + (i * 16);
213 SDL_BlitSurface(surf, &src, screen, &dest);
220 if (update == UPDATE)
222 dest.w = strlen(text) * 16 + 1;
227 SDL_UpdateRect(screen, x, y, dest.w, 17);
233 /* --- DRAW HORIZONTALLY-CENTERED TEXT: --- */
235 void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize)
237 drawtext(text, 320 - (strlen(text) * 8), y, surf, update, shadowsize);
240 /* --- ERASE TEXT: --- */
242 void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize)
249 dest.w = strlen(text) * 16 + shadowsize;
255 SDL_BlitSurface(surf, &dest, screen, &dest);
257 if (update == UPDATE)
258 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
262 /* --- ERASE CENTERED TEXT: --- */
264 void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize)
266 erasetext(text, 320 - (strlen(text) * 8), y, surf, update, shadowsize);