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);
126 /* --- DRAW TEXT ONTO THE SCREEN --- */
128 void drawtext(char * text, int x, int y, SDL_Surface * surf, int update)
135 /* For each letter in the string... */
137 for (i = 0; i < strlen(text); i++)
139 /* Set source rectangle: */
143 if (c >= 'A' && c <= 'Z')
145 /* Capital letter - first row: */
147 src.x = (c - 'A') * 16;
150 else if (c >= 'a' && c <= 'z')
152 /* Lowercase letter - first row: */
154 src.x = (c - 'a') * 16;
157 else if (c >= '!' && c <= '9')
159 /* Punctuation (except '?') or number - third row: */
161 src.x = (c - '!') * 16;
166 /* Question mark - third row, last character: */
178 /* Draw character: */
182 /* Set destination rectangle for shadow: */
184 dest.x = x + (i * 16) + 1;
192 SDL_BlitSurface(letters_black, &src, screen, &dest);
195 /* Set destination rectangle for text: */
197 dest.x = x + (i * 16);
205 SDL_BlitSurface(surf, &src, screen, &dest);
212 if (update == UPDATE)
214 dest.w = strlen(text) * 16 + 1;
219 SDL_UpdateRect(screen, x, y, dest.w, 17);
224 /* --- DRAW HORIZONTALLY-CENTERED TEXT: --- */
226 void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update)
228 drawtext(text, 320 - (strlen(text) * 8), y, surf, update);
232 /* --- ERASE TEXT: --- */
234 void erasetext(char * text, int x, int y, SDL_Surface * surf, int update)
241 dest.w = strlen(text) * 16 + 1;
247 SDL_BlitSurface(surf, &dest, screen, &dest);
249 if (update == UPDATE)
250 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
254 /* --- ERASE CENTERED TEXT: --- */
256 void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update)
258 erasetext(text, 320 - (strlen(text) * 8), y, surf, update);