1 #define max(a, b) ((a > b) ? a : b)
2 #define min(a, b) ((a < b) ? a : b)
5 gacela_SDL_SurfaceFormat (int surface)
7 SDL_Surface *s = surface;
13 gacela_SDL_BlitSurface (int src, int srcrect, int dst, int dstrect)
15 SDL_BlitSurface (src, srcrect, dst, dstrect);
19 gacela_SDL_Rect (int x, int y, int w, int h)
23 rect = (SDL_Rect *)malloc (sizeof (SDL_Rect));
33 gacela_TTF_Init (void)
39 gacela_TTF_OpenFont (char *file, int ptsize)
41 return TTF_OpenFont (file, ptsize);
45 gacela_TTF_CloseFont (int font)
51 gacela_TTF_Quit (void)
57 gacela_Mix_OpenAudio (int frequency, int channels, int chunksize)
59 return Mix_OpenAudio (frequency, MIX_DEFAULT_FORMAT, channels, chunksize);
63 gacela_Mix_LoadMUS (char *filename)
65 return Mix_LoadMUS (filename);
69 gacela_Mix_LoadWAV (char *filename)
71 return Mix_LoadWAV (filename);
75 gacela_Mix_PlayChannel (int channel, int chunk, int loops)
77 return Mix_PlayChannel (channel, chunk, loops);
81 gacela_Mix_PlayMusic (int music, int loops)
83 return Mix_PlayMusic (music, loops);
87 gacela_Mix_PlayingMusic (void)
89 return Mix_PlayingMusic ();
93 gacela_Mix_PausedMusic (void)
95 return Mix_PausedMusic ();
99 gacela_Mix_PauseMusic (void)
105 gacela_Mix_ResumeMusic (void)
111 gacela_Mix_HaltMusic (void)
113 return Mix_HaltMusic ();
117 gacela_Mix_FreeChunk (int chunk)
119 Mix_FreeChunk (chunk);
123 gacela_Mix_FreeMusic (int music)
125 Mix_FreeMusic (music);
129 gacela_Mix_CloseAudio (void)
135 gacela_sge_FilledCircle (int surface, int x, int y, int r, int red, int green, int blue)
137 SDL_Surface *s = surface;
139 sge_FilledCircle (s, x, y, r, SDL_MapRGB (s->format, red, green, blue));
143 gacela_sge_FilledRect (int surface, int x1, int y1, int x2, int y2, int red, int green, int blue)
145 SDL_Surface *s = surface;
147 sge_FilledRect (s, x1, y1, x2, y2, SDL_MapRGB (s->format, red, green, blue));
151 gacela_free (int pointer)
157 apply_surface (int x, int y, int source, int destination, \
158 int cx, int cy, int cw, int ch, int cid)
161 SDL_Rect *clip = NULL;
162 SDL_Surface *tmps = source;
163 int tmpw, tmpx, tmpy;
165 if (cw != 0 || ch != 0)
167 clip = (SDL_Rect *)malloc(sizeof(SDL_Rect));
176 if (tmps->w % cw > 0) tmpw++;
178 tmpx = cid - tmpw*tmpy;
180 if (tmpx * cw > tmps->w || tmpy * ch > tmps->h)
190 printf ("Id: %d cx: %d cy: %d\n", cid, clip->x, clip->y);
198 SDL_BlitSurface (source, clip, destination, &offset);
203 render_text (int font, char *text, int red, int green, int blue)
205 SDL_Color textColor = {red, green, blue};
206 return TTF_RenderText_Solid (font, text, textColor);
210 load_image (char *filename, int red, int green, int blue)
212 SDL_Surface *loadedImage = NULL;
213 SDL_Surface *optimizedImage = NULL;
215 loadedImage = IMG_Load (filename);
216 if (loadedImage != NULL)
218 optimizedImage = SDL_DisplayFormat (loadedImage);
219 SDL_FreeSurface (loadedImage);
220 if (optimizedImage != NULL)
222 SDL_SetColorKey (optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB (optimizedImage->format, red, green, blue));
225 return optimizedImage;
229 fill_surface (int surface, int red, int green, int blue)
231 SDL_Surface *s = surface;
233 SDL_FillRect (s, &s->clip_rect, SDL_MapRGB (s->format, red, green, blue));
237 box_collision (int surface1, int x1, int y1, int surface2, int x2, int y2)
239 SDL_Surface *s1 = surface1;
240 SDL_Surface *s2 = surface2;
241 int left1, left2, bottom1, bottom2;
242 int xstart, xend, ystart, yend;
245 left1 = x1 + s1->w - 1;
246 bottom1 = y1 + s1->h - 1;
247 left2 = x2 + s2->w - 1;
248 bottom2 = y2 + s2->h - 1;
250 if ((x1 > left2) || (x2 > left1)) return 0;
251 if ((y1 > bottom2) || (y2 > bottom1)) return 0;
256 transparent_pixel (SDL_Surface *surface, int x, int y)
258 int bpp = surface->format->BytesPerPixel;
262 if (SDL_MUSTLOCK (surface)) SDL_LockSurface (surface);
263 assert ((x < surface->w) && (y < surface->h));
265 p = (Uint8 *)surface->pixels + y*surface->pitch + x*bpp;
274 pixelcolor = *(Uint16 *)p;
278 if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
279 pixelcolor = p[0] << 16 | p[1] << 8 | p[2];
281 pixelcolor = p[0] | p[1] << 8 | p[2] << 16;
285 pixelcolor = *(Uint32 *)p;
289 if (SDL_MUSTLOCK (surface)) SDL_UnlockSurface (surface);
291 return (pixelcolor == surface->format->colorkey);
295 create_SDL_Surface (int screen, int w, int h, int red, int green, int blue)
297 SDL_Surface *s = screen;
298 SDL_Surface *new = NULL;
300 new = SDL_CreateRGBSurface (s->flags, w, h, \
301 s->format->BitsPerPixel, \
302 s->format->Rmask, s->format->Gmask, \
303 s->format->Bmask, s->format->Amask);
306 SDL_SetColorKey (new, SDL_SRCCOLORKEY, SDL_MapRGB (new->format, red, green, blue));
313 copy_SDL_Surface (int surface)
315 SDL_Surface *s = surface;
317 return SDL_ConvertSurface (s, s->format, s->flags);