test/testalpha.c
changeset 2806 938aa47f903a
parent 2799 bbf3aac2672a
child 2822 cf271ff76061
equal deleted inserted replaced
2805:2ed5ff5373d8 2806:938aa47f903a
    34                 SDL_GetError());
    34                 SDL_GetError());
    35         quit(2);
    35         quit(2);
    36     }
    36     }
    37     buffer = (Uint8 *) screen->pixels;
    37     buffer = (Uint8 *) screen->pixels;
    38     switch (screen->format->BytesPerPixel) {
    38     switch (screen->format->BytesPerPixel) {
    39         case 1:
    39     case 1:
    40         case 3:
    40     case 3:
    41             for (i = 0; i < screen->h; ++i) {
    41         for (i = 0; i < screen->h; ++i) {
    42                 memset(buffer, (i * 255) / screen->h,
    42             memset(buffer, (i * 255) / screen->h,
    43                        screen->w * screen->format->BytesPerPixel);
    43                    screen->w * screen->format->BytesPerPixel);
    44                 buffer += screen->pitch;
    44             buffer += screen->pitch;
       
    45         }
       
    46         break;
       
    47     case 2:
       
    48         for (i = 0; i < screen->h; ++i) {
       
    49             Uint16 *buffer16;
       
    50             Uint16 color;
       
    51 
       
    52             gradient = ((i * 255) / screen->h);
       
    53             color = (Uint16) SDL_MapRGB(screen->format,
       
    54                                         gradient, gradient, gradient);
       
    55             buffer16 = (Uint16 *) buffer;
       
    56             for (k = 0; k < screen->w; k++) {
       
    57                 *buffer16++ = color;
    45             }
    58             }
    46             break;
    59             buffer += screen->pitch;
    47         case 2:
    60         }
    48             for (i = 0; i < screen->h; ++i) {
    61         break;
    49                 Uint16 *buffer16;
    62     case 4:
    50                 Uint16 color;
    63         for (i = 0; i < screen->h; ++i) {
    51 
    64             Uint32 *buffer32;
    52                 gradient = ((i * 255) / screen->h);
    65             Uint32 color;
    53                 color = (Uint16) SDL_MapRGB(screen->format,
    66 
    54                                             gradient, gradient, gradient);
    67             gradient = ((i * 255) / screen->h);
    55                 buffer16 = (Uint16 *) buffer;
    68             color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
    56                 for (k = 0; k < screen->w; k++) {
    69             buffer32 = (Uint32 *) buffer;
    57                     *buffer16++ = color;
    70             for (k = 0; k < screen->w; k++) {
    58                 }
    71                 *buffer32++ = color;
    59                 buffer += screen->pitch;
       
    60             }
    72             }
    61             break;
    73             buffer += screen->pitch;
    62         case 4:
    74         }
    63             for (i = 0; i < screen->h; ++i) {
    75         break;
    64                 Uint32 *buffer32;
       
    65                 Uint32 color;
       
    66 
       
    67                 gradient = ((i * 255) / screen->h);
       
    68                 color = SDL_MapRGB(screen->format,
       
    69                                    gradient, gradient, gradient);
       
    70                 buffer32 = (Uint32 *) buffer;
       
    71                 for (k = 0; k < screen->w; k++) {
       
    72                     *buffer32++ = color;
       
    73                 }
       
    74                 buffer += screen->pitch;
       
    75             }
       
    76             break;
       
    77     }
    76     }
    78 
    77 
    79     SDL_UnlockSurface(screen);
    78     SDL_UnlockSurface(screen);
    80     SDL_UpdateRect(screen, 0, 0, 0, 0);
    79     SDL_UpdateRect(screen, 0, 0, 0, 0);
    81 }
    80 }
   521 
   520 
   522                     area.x = event.button.x - 16;
   521                     area.x = event.button.x - 16;
   523                     area.y = event.button.y - 16;
   522                     area.y = event.button.y - 16;
   524                     area.w = 32;
   523                     area.w = 32;
   525                     area.h = 32;
   524                     area.h = 32;
   526                     SDL_FillRect(screen, &area, SDL_MapRGB(screen->format, 0, 0, 0));
   525                     SDL_FillRect(screen, &area,
       
   526                                  SDL_MapRGB(screen->format, 0, 0, 0));
   527                     SDL_UpdateRects(screen, 1, &area);
   527                     SDL_UpdateRects(screen, 1, &area);
   528                 }
   528                 }
   529                 break;
   529                 break;
   530             case SDL_KEYDOWN:
   530             case SDL_KEYDOWN:
   531                 if (event.key.keysym.sym == SDLK_ESCAPE) {
   531                 if (event.key.keysym.sym == SDLK_ESCAPE) {