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 TEXT ONTO THE SCREEN --- */
127 void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize)
133 /* For each letter in the string... */
135 for (i = 0; i < strlen(text); i++)
137 /* Set source rectangle: */
141 if (c >= 'A' && c <= 'Z')
143 /* Capital letter - first row: */
145 src.x = (c - 'A') * 16;
148 else if (c >= 'a' && c <= 'z')
150 /* Lowercase letter - first row: */
152 src.x = (c - 'a') * 16;
155 else if (c >= '!' && c <= '9')
157 /* Punctuation (except '?') or number - third row: */
159 src.x = (c - '!') * 16;
164 /* Question mark - third row, last character: */
176 /* Draw character: */
180 /* Set destination rectangle for shadow: */
182 dest.x = x + (i * 16) + shadowsize;
183 dest.y = y + shadowsize;
190 SDL_BlitSurface(letters_black, &src, screen, &dest);
193 /* Set destination rectangle for text: */
195 dest.x = x + (i * 16);
203 SDL_BlitSurface(surf, &src, screen, &dest);
210 if (update == UPDATE)
212 dest.w = strlen(text) * 16 + 1;
217 SDL_UpdateRect(screen, x, y, dest.w, 17);
223 /* --- DRAW HORIZONTALLY-CENTERED TEXT: --- */
225 void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize)
227 drawtext(text, 320 - (strlen(text) * 8), y, surf, update, shadowsize);
230 /* --- ERASE TEXT: --- */
232 void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize)
239 dest.w = strlen(text) * 16 + shadowsize;
245 SDL_BlitSurface(surf, &dest, screen, &dest);
247 if (update == UPDATE)
248 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
252 /* --- ERASE CENTERED TEXT: --- */
254 void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize)
256 erasetext(text, 320 - (strlen(text) * 8), y, surf, update, shadowsize);