Mercurial > sdl-ios-xcode
diff test/graywin.c @ 691:609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
From: "Mike Gorchak"
Subject: Patches for tests and QNX6
1) graywin - added support for the gray gradient in the 15/16 bpp modes. Added SDL_VIDEOEXPOSE event handling.
2) testalpha - added support for the gray gradient in the 15/16 bpp modes.
3) testbitmap - added support for the gray gradient in the 8/15/16 bpp modes.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 23 Aug 2003 23:18:49 +0000 |
parents | d3abe873e3f7 |
children | d33645c36072 |
line wrap: on
line diff
--- a/test/graywin.c Sat Aug 23 23:12:19 2003 +0000 +++ b/test/graywin.c Sat Aug 23 23:18:49 2003 +0000 @@ -20,6 +20,7 @@ static unsigned int seeded = 0; SDL_Rect area; Uint32 color; + Uint32 randc; /* Seed the random number generator */ if ( seeded == 0 ) { @@ -32,7 +33,16 @@ area.h = (rand()%height); area.x = X-(area.w/2); area.y = Y-(area.h/2); - color = (rand()%NUM_COLORS); + randc = (rand()%NUM_COLORS); + + if (screen->format->BytesPerPixel==1) + { + color = randc; + } + else + { + color = SDL_MapRGB(screen->format, randc, randc, randc); + } /* Do it! */ SDL_FillRect(screen, &area, color); @@ -43,12 +53,60 @@ } } +void DrawBackground(SDL_Surface *screen) +{ + int i, j, k; + Uint8 *buffer; + Uint16 *buffer16; + Uint16 color; + Uint8 gradient; + + /* Set the surface pixels and refresh! */ + /* Use two loops in case the surface is double-buffered (both sides) */ + + for ( j=0; j<2; ++j ) { + if ( SDL_LockSurface(screen) < 0 ) { + fprintf(stderr, "Couldn't lock display surface: %s\n", + SDL_GetError()); + return; + } + buffer = (Uint8 *)screen->pixels; + + if (screen->format->BytesPerPixel!=2) { + for ( i=0; i<screen->h; ++i ) { + memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel); + buffer += screen->pitch; + } + } + else + { + for ( i=0; i<screen->h; ++i ) { + gradient=((i*(NUM_COLORS-1))/screen->h); + color = SDL_MapRGB(screen->format, gradient, gradient, gradient); + buffer16=(Uint16*)buffer; + for (k=0; k<screen->w; k++) + { + *(buffer16+k)=color; + } + buffer += screen->pitch; + } + } + + SDL_UnlockSurface(screen); + if ( screen->flags & SDL_DOUBLEBUF ) { + SDL_Flip(screen); + } else { + SDL_UpdateRect(screen, 0, 0, 0, 0); + break; + } + } +} + SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags) { SDL_Surface *screen; int i; SDL_Color palette[NUM_COLORS]; - Uint8 *buffer; /* Set the video mode */ screen = SDL_SetVideoMode(w, h, bpp, flags); @@ -60,33 +118,14 @@ fprintf(stderr, "Screen is in %s mode\n", (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed"); - /* Set a gray colormap, reverse order from white to black */ - for ( i=0; i<NUM_COLORS; ++i ) { - palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS); - palette[i].g = (NUM_COLORS-1)-i * (256 / NUM_COLORS); - palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS); - } - SDL_SetColors(screen, palette, 0, NUM_COLORS); - - /* Set the surface pixels and refresh! */ - /* Use two loops in case the surface is double-buffered (both sides) */ - for ( i=0; i<2; ++i ) { - if ( SDL_LockSurface(screen) < 0 ) { - fprintf(stderr, "Couldn't lock display surface: %s\n", - SDL_GetError()); - return(NULL); + if (bpp==8) { + /* Set a gray colormap, reverse order from white to black */ + for ( i=0; i<NUM_COLORS; ++i ) { + palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS); + palette[i].g = (NUM_COLORS-1)-i * (256 / NUM_COLORS); + palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS); } - buffer = (Uint8 *)screen->pixels; - for ( i=0; i<screen->h; ++i ) { - memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel); - buffer += screen->pitch; - } - SDL_UnlockSurface(screen); - if ( screen->flags & SDL_DOUBLEBUF ) { - SDL_Flip(screen); - } else { - SDL_UpdateRect(screen, 0, 0, 0, 0); - } + SDL_SetColors(screen, palette, 0, NUM_COLORS); } return(screen); @@ -151,6 +190,8 @@ if ( screen == NULL ) { exit(2); } + + DrawBackground(screen); /* Wait for a keystroke */ done = 0; @@ -182,12 +223,16 @@ "Couldn't toggle fullscreen mode\n"); done = 1; } + DrawBackground(screen); break; } /* Any other key quits the application... */ case SDL_QUIT: done = 1; break; + case SDL_VIDEOEXPOSE: + DrawBackground(screen); + break; default: break; }