src/video/SDL_video.c
branchSDL-1.3
changeset 1724 6c63fc2bd986
parent 1720 a1ebb17f9c52
child 1725 98a3207ddde8
     1.1 --- a/src/video/SDL_video.c	Thu Jul 06 05:53:32 2006 +0000
     1.2 +++ b/src/video/SDL_video.c	Thu Jul 06 07:17:11 2006 +0000
     1.3 @@ -188,6 +188,11 @@
     1.4      }
     1.5  #endif
     1.6  
     1.7 +    /* Start the event loop */
     1.8 +    if (SDL_StartEventLoop(flags) < 0) {
     1.9 +        return -1;
    1.10 +    }
    1.11 +
    1.12      /* Check to make sure we don't overwrite '_this' */
    1.13      if (_this != NULL) {
    1.14          SDL_VideoQuit();
    1.15 @@ -277,12 +282,6 @@
    1.16          }
    1.17      }
    1.18  
    1.19 -    /* Start the event loop */
    1.20 -    if (SDL_StartEventLoop(flags) < 0) {
    1.21 -        SDL_VideoQuit();
    1.22 -        return -1;
    1.23 -    }
    1.24 -
    1.25      /* We're ready to go! */
    1.26      return 0;
    1.27  }
    1.28 @@ -1286,10 +1285,22 @@
    1.29      }
    1.30  
    1.31      /* Copy the palette if any */
    1.32 -    if (fmt->palette) {
    1.33 -        SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
    1.34 -                              fmt->palette->ncolors);
    1.35 -        SDL_SetSurfacePalette(&dst, fmt->palette);
    1.36 +    if (SDL_ISPIXELFORMAT_INDEXED(format)) {
    1.37 +        if (fmt->palette) {
    1.38 +            SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
    1.39 +                                  fmt->palette->ncolors);
    1.40 +            SDL_SetSurfacePalette(&dst, fmt->palette);
    1.41 +        } else {
    1.42 +            dst.format->palette =
    1.43 +                SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format)));
    1.44 +            if (!dst.format->palette) {
    1.45 +                SDL_DestroyTexture(textureID);
    1.46 +                SDL_FreeFormat(dst.format);
    1.47 +                return 0;
    1.48 +            }
    1.49 +            SDL_DitherColors(dst.format->palette->colors,
    1.50 +                             SDL_BITSPERPIXEL(format));
    1.51 +        }
    1.52      }
    1.53  
    1.54      /* Make the texture transparent if the surface has colorkey */
    1.55 @@ -1557,7 +1568,8 @@
    1.56  SDL_RenderFill(const SDL_Rect * rect, Uint32 color)
    1.57  {
    1.58      SDL_Renderer *renderer;
    1.59 -    SDL_Rect full_rect;
    1.60 +    SDL_Window *window;
    1.61 +    SDL_Rect real_rect;
    1.62  
    1.63      if (!_this) {
    1.64          return -1;
    1.65 @@ -1568,14 +1580,17 @@
    1.66          return -1;
    1.67      }
    1.68  
    1.69 -    if (!rect) {
    1.70 -        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    1.71 -        full_rect.x = 0;
    1.72 -        full_rect.y = 0;
    1.73 -        full_rect.w = window->w;
    1.74 -        full_rect.h = window->h;
    1.75 -        rect = &full_rect;
    1.76 +    window = SDL_GetWindowFromID(renderer->window);
    1.77 +    real_rect.x = 0;
    1.78 +    real_rect.y = 0;
    1.79 +    real_rect.w = window->w;
    1.80 +    real_rect.h = window->h;
    1.81 +    if (rect) {
    1.82 +        if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
    1.83 +            return 0;
    1.84 +        }
    1.85      }
    1.86 +    rect = &real_rect;
    1.87  
    1.88      return renderer->RenderFill(renderer, rect, color);
    1.89  }
    1.90 @@ -1586,8 +1601,9 @@
    1.91  {
    1.92      SDL_Texture *texture = SDL_GetTextureFromID(textureID);
    1.93      SDL_Renderer *renderer;
    1.94 -    SDL_Rect full_srcrect;
    1.95 -    SDL_Rect full_dstrect;
    1.96 +    SDL_Window *window;
    1.97 +    SDL_Rect real_srcrect;
    1.98 +    SDL_Rect real_dstrect;
    1.99  
   1.100      if (!texture || texture->renderer != SDL_CurrentDisplay.current_renderer) {
   1.101          return -1;
   1.102 @@ -1598,20 +1614,21 @@
   1.103          return -1;
   1.104      }
   1.105  
   1.106 +    /* FIXME: implement clipping */
   1.107 +    window = SDL_GetWindowFromID(renderer->window);
   1.108 +    real_srcrect.x = 0;
   1.109 +    real_srcrect.y = 0;
   1.110 +    real_srcrect.w = texture->w;
   1.111 +    real_srcrect.h = texture->h;
   1.112 +    real_dstrect.x = 0;
   1.113 +    real_dstrect.y = 0;
   1.114 +    real_dstrect.w = window->w;
   1.115 +    real_dstrect.h = window->h;
   1.116      if (!srcrect) {
   1.117 -        full_srcrect.x = 0;
   1.118 -        full_srcrect.y = 0;
   1.119 -        full_srcrect.w = texture->w;
   1.120 -        full_srcrect.h = texture->h;
   1.121 -        srcrect = &full_srcrect;
   1.122 +        srcrect = &real_srcrect;
   1.123      }
   1.124      if (!dstrect) {
   1.125 -        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.126 -        full_dstrect.x = 0;
   1.127 -        full_dstrect.y = 0;
   1.128 -        full_dstrect.w = window->w;
   1.129 -        full_dstrect.h = window->h;
   1.130 -        dstrect = &full_dstrect;
   1.131 +        dstrect = &real_dstrect;
   1.132      }
   1.133  
   1.134      return renderer->RenderCopy(renderer, texture, srcrect, dstrect,