Mercurial > sdl-ios-xcode
comparison src/video/SDL_surface.c @ 1735:8dd28c4ef746 SDL-1.3
SDL_Rect now uses int for position and size.
Added a few more rectangle functions.
Added a dirty rectangle list implementation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 07:34:50 +0000 |
parents | 6c63fc2bd986 |
children |
comparison
equal
deleted
inserted
replaced
1734:f7c667ded87d | 1735:8dd28c4ef746 |
---|---|
38 SDL_CreateRGBSurface(Uint32 flags, | 38 SDL_CreateRGBSurface(Uint32 flags, |
39 int width, int height, int depth, | 39 int width, int height, int depth, |
40 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) | 40 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) |
41 { | 41 { |
42 SDL_Surface *surface; | 42 SDL_Surface *surface; |
43 | |
44 /* FIXME!! */ | |
45 /* Make sure the size requested doesn't overflow our datatypes */ | |
46 /* Next time I write a library like SDL, I'll use int for size. :) */ | |
47 if (width >= 16384 || height >= 65536) { | |
48 SDL_SetError("Width or height is too large"); | |
49 return NULL; | |
50 } | |
51 | 43 |
52 /* Allocate the surface */ | 44 /* Allocate the surface */ |
53 surface = (SDL_Surface *) SDL_malloc(sizeof(*surface)); | 45 surface = (SDL_Surface *) SDL_malloc(sizeof(*surface)); |
54 if (surface == NULL) { | 46 if (surface == NULL) { |
55 SDL_OutOfMemory(); | 47 SDL_OutOfMemory(); |
209 SDL_CreateRGBSurface(0, 0, 0, bpp, Rmask, Gmask, Bmask, Amask); | 201 SDL_CreateRGBSurface(0, 0, 0, bpp, Rmask, Gmask, Bmask, Amask); |
210 if (surface) { | 202 if (surface) { |
211 surface->flags |= SDL_HWSURFACE; | 203 surface->flags |= SDL_HWSURFACE; |
212 surface->w = w; | 204 surface->w = w; |
213 surface->h = h; | 205 surface->h = h; |
206 surface->pitch = SDL_CalculatePitch(surface); | |
214 SDL_SetClipRect(surface, NULL); | 207 SDL_SetClipRect(surface, NULL); |
215 } | 208 } |
216 } | 209 } |
217 if (surface) { | 210 if (surface) { |
218 surface->textureID = textureID; | 211 surface->textureID = textureID; |
410 } | 403 } |
411 if (SDL_MUSTLOCK(surface)) { | 404 if (SDL_MUSTLOCK(surface)) { |
412 SDL_UnlockSurface(surface); | 405 SDL_UnlockSurface(surface); |
413 } | 406 } |
414 return 0; | 407 return 0; |
415 } | |
416 | |
417 /* | |
418 * A function to calculate the intersection of two rectangles: | |
419 * return true if the rectangles intersect, false otherwise | |
420 */ | |
421 SDL_bool | |
422 SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, | |
423 SDL_Rect * intersection) | |
424 { | |
425 int Amin, Amax, Bmin, Bmax; | |
426 | |
427 /* Horizontal intersection */ | |
428 Amin = A->x; | |
429 Amax = Amin + A->w; | |
430 Bmin = B->x; | |
431 Bmax = Bmin + B->w; | |
432 if (Bmin > Amin) | |
433 Amin = Bmin; | |
434 intersection->x = Amin; | |
435 if (Bmax < Amax) | |
436 Amax = Bmax; | |
437 intersection->w = Amax - Amin > 0 ? Amax - Amin : 0; | |
438 | |
439 /* Vertical intersection */ | |
440 Amin = A->y; | |
441 Amax = Amin + A->h; | |
442 Bmin = B->y; | |
443 Bmax = Bmin + B->h; | |
444 if (Bmin > Amin) | |
445 Amin = Bmin; | |
446 intersection->y = Amin; | |
447 if (Bmax < Amax) | |
448 Amax = Bmax; | |
449 intersection->h = Amax - Amin > 0 ? Amax - Amin : 0; | |
450 | |
451 return (intersection->w && intersection->h); | |
452 } | 408 } |
453 | 409 |
454 /* | 410 /* |
455 * Set the clipping rectangle for a blittable surface | 411 * Set the clipping rectangle for a blittable surface |
456 */ | 412 */ |