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>
22 #include <SDL_mixer.h>
27 #include <sys/types.h>
37 /* --- LOAD AND DISPLAY AN IMAGE --- */
39 void load_and_display_image(char * file)
43 img = load_image(file, IGNORE_ALPHA);
44 SDL_BlitSurface(img, NULL, screen, NULL);
49 /* --- CLEAR SCREEN --- */
51 void clearscreen(int r, int g, int b)
53 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
57 /* --- UPDATE SCREEN --- */
59 void updatescreen(void)
61 SDL_UpdateRect(screen, 0, 0, 640, 480);
65 /* --- LOAD AN IMAGE --- */
67 SDL_Surface * load_image(char * file, int use_alpha)
69 SDL_Surface * temp, * surf;
71 temp = IMG_Load(file);
73 st_abort("Can't load", file);
75 surf = SDL_DisplayFormatAlpha(temp);
78 st_abort("Can't covert to display format", file);
80 if (use_alpha == IGNORE_ALPHA)
81 SDL_SetAlpha(surf, 0, 0);
83 SDL_FreeSurface(temp);
89 /* --- DRAW AN IMAGE ONTO THE SCREEN --- */
91 void drawimage(SDL_Surface * surf, int x, int y, int update)
100 SDL_BlitSurface(surf, NULL, screen, &dest);
102 if (update == UPDATE)
103 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
107 /* --- DRAW PART OF AN IMAGE ONTO THE SCREEN --- */
109 void drawpart(SDL_Surface * surf, int x, int y, int w, int h, int update)
123 SDL_BlitSurface(surf, &src, screen, &dest);
125 if (update == UPDATE)
126 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
130 /* --- DRAW TEXT ONTO THE SCREEN --- */
132 void drawtext(char * text, int x, int y, SDL_Surface * surf, int update)
139 /* For each letter in the string... */
141 for (i = 0; i < strlen(text); i++)
143 /* Set source rectangle: */
147 if (c >= 'A' && c <= 'Z')
149 /* Capital letter - first row: */
151 src.x = (c - 'A') * 16;
154 else if (c >= 'a' && c <= 'z')
156 /* Lowercase letter - first row: */
158 src.x = (c - 'a') * 16;
161 else if (c >= '!' && c <= '9')
163 /* Punctuation (except '?') or number - third row: */
165 src.x = (c - '!') * 16;
170 /* Question mark - third row, last character: */
182 /* Draw character: */
186 /* Set destination rectangle for shadow: */
188 dest.x = x + (i * 16) + 1;
196 SDL_BlitSurface(letters_black, &src, screen, &dest);
199 /* Set destination rectangle for text: */
201 dest.x = x + (i * 16);
209 SDL_BlitSurface(surf, &src, screen, &dest);
216 if (update == UPDATE)
218 dest.w = strlen(text) * 16 + 1;
223 SDL_UpdateRect(screen, x, y, dest.w, 17);
228 /* --- DRAW HORIZONTALLY-CENTERED TEXT: --- */
230 void drawcenteredtext(char * text, int y, SDL_Surface * surf, int update)
232 drawtext(text, 320 - (strlen(text) * 8), y, surf, update);
236 /* --- ERASE TEXT: --- */
238 void erasetext(char * text, int x, int y, SDL_Surface * surf, int update)
245 dest.w = strlen(text) * 16 + 1;
251 SDL_BlitSurface(surf, &dest, screen, &dest);
253 if (update == UPDATE)
254 SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
258 /* --- ERASE CENTERED TEXT: --- */
260 void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update)
262 erasetext(text, 320 - (strlen(text) * 8), y, surf, update);