New grow and skid sounds from remaxim
[supertux.git] / src / video / sdl_renderer.cpp
index 6e8797c..b02d0a1 100644 (file)
@@ -52,6 +52,14 @@ namespace
     int alpha = (int) (alpha_factor * 256);
     SDL_Surface *dst = SDL_CreateRGBSurface(src->flags, src->w, src->h, src->format->BitsPerPixel, src->format->Rmask,  src->format->Gmask, src->format->Bmask, src->format->Amask);
     int bpp = dst->format->BytesPerPixel;
+    if(SDL_MUSTLOCK(src))
+    {
+      SDL_LockSurface(src);
+    }
+    if(SDL_MUSTLOCK(dst))
+    {
+      SDL_LockSurface(dst);
+    }
     for(int y = 0;y < dst->h;y++) {
       for(int x = 0;x < dst->w;x++) {
         Uint8 *srcpixel = (Uint8 *) src->pixels + y * src->pitch + x * bpp;
@@ -106,6 +114,14 @@ namespace
         }
       }
     }
+    if(SDL_MUSTLOCK(dst))
+    {
+      SDL_UnlockSurface(dst);
+    }
+    if(SDL_MUSTLOCK(src))
+    {
+      SDL_UnlockSurface(src);
+    }
     return dst;
   }
 }
@@ -114,6 +130,8 @@ namespace SDL
 {
   Renderer::Renderer()
   {
+    ::Renderer::instance_ = this;
+
     const SDL_VideoInfo *info = SDL_GetVideoInfo();
     log_info << "Hardware surfaces are " << (info->hw_available ? "" : "not ") << "available." << std::endl;
     log_info << "Hardware to hardware blits are " << (info->blit_hw ? "" : "not ") << "accelerated." << std::endl;
@@ -127,8 +145,9 @@ namespace SDL
     int flags = SDL_SWSURFACE | SDL_ANYFORMAT;
     if(config->use_fullscreen)
       flags |= SDL_FULLSCREEN;
-    int width = config->screenwidth;
-    int height = config->screenheight;
+    
+    int width  = 800; //FIXME: config->screenwidth;
+    int height = 600; //FIXME: config->screenheight;
 
     screen = SDL_SetVideoMode(width, height, 0, flags);
     if(screen == 0) {
@@ -138,6 +157,9 @@ namespace SDL
       throw std::runtime_error(msg.str());
     }
 
+    numerator   = 1;
+    denominator = 1;
+    /* FIXME: 
     float xfactor = (float) config->screenwidth / SCREEN_WIDTH;
     float yfactor = (float) config->screenheight / SCREEN_HEIGHT;
     if(xfactor < yfactor)
@@ -150,7 +172,7 @@ namespace SDL
       numerator = config->screenheight;
       denominator = SCREEN_HEIGHT;
     }
-
+    */
     if(texture_manager == 0)
       texture_manager = new TextureManager();
   }
@@ -176,7 +198,7 @@ namespace SDL
     if (transform == 0) {
       std::cerr << "Warning: Tried to draw NULL surface, skipped draw" << std::endl;
       return;
-    }  
+    }
 
     SDL_Rect *src_rect = surface_data->get_src_rect(effect);
     SDL_Rect dst_rect;
@@ -212,11 +234,11 @@ namespace SDL
       {
         if(alpha == 255)
         {
-          SDL_SetAlpha(transform, 0, 0);
+          SDL_SetAlpha(transform, SDL_RLEACCEL, 0);
         }
         else
         {
-          SDL_SetAlpha(transform, SDL_SRCALPHA, alpha);
+          SDL_SetAlpha(transform, SDL_SRCALPHA | SDL_RLEACCEL, alpha);
         }
       }
       /*else
@@ -238,13 +260,13 @@ namespace SDL
     DrawingEffect effect = request.drawing_effect;
     if (surface->get_flipx()) effect = HORIZONTAL_FLIP;
 
-    SDL_Surface *transform = sdltexture->get_transform(Color(1.0, 1.0, 1.0), effect);
+    SDL_Surface *transform = sdltexture->get_transform(request.color, effect);
 
     // get and check SDL_Surface
     if (transform == 0) {
       std::cerr << "Warning: Tried to draw NULL surface, skipped draw" << std::endl;
       return;
-    }  
+    }
 
     int ox, oy;
     if (effect == HORIZONTAL_FLIP)
@@ -275,26 +297,45 @@ namespace SDL
     dst_rect.y = (int) request.pos.y * numerator / denominator;
 
     Uint8 alpha = 0;
-    if(!(transform->flags & SDL_SRCALPHA))
-    {
-      alpha = 255;
-      SDL_SetAlpha(transform, SDL_SRCALPHA, (Uint8) (request.alpha * 255));
-    }
-    else if(!transform->format->Amask)
+    if(request.alpha != 1.0)
     {
-      alpha = transform->format->alpha;
-      SDL_SetAlpha(transform, SDL_SRCALPHA, (Uint8) (request.alpha * alpha));
+      if(!transform->format->Amask)
+      {
+        if(transform->flags & SDL_SRCALPHA)
+        {
+          alpha = transform->format->alpha;
+        }
+        else
+        {
+          alpha = 255;
+        }
+        SDL_SetAlpha(transform, SDL_SRCALPHA, (Uint8) (request.alpha * alpha));
+      }
+      /*else
+      {
+        transform = apply_alpha(transform, request.alpha);
+      }*/
     }
 
     SDL_BlitSurface(transform, &src_rect, screen, &dst_rect);
 
-    if(alpha == 255)
-    {
-      SDL_SetAlpha(transform, 0, 0);
-    }
-    else if(!transform->format->Amask)
+    if(request.alpha != 1.0)
     {
-      SDL_SetAlpha(transform, SDL_SRCALPHA, alpha);
+      if(!transform->format->Amask)
+      {
+        if(alpha == 255)
+        {
+          SDL_SetAlpha(transform, SDL_RLEACCEL, 0);
+        }
+        else
+        {
+          SDL_SetAlpha(transform, SDL_SRCALPHA | SDL_RLEACCEL, alpha);
+        }
+      }
+      /*else
+      {
+        SDL_FreeSurface(transform);
+      }*/
     }
   }
 
@@ -326,7 +367,7 @@ namespace SDL
         SDL_Surface *temp = SDL_CreateRGBSurface(screen->flags, rect.w, rect.h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
 
         SDL_FillRect(temp, 0, color);
-        SDL_SetAlpha(temp, SDL_SRCALPHA, a);
+        SDL_SetAlpha(temp, SDL_SRCALPHA | SDL_RLEACCEL, a);
         SDL_BlitSurface(temp, 0, screen, &rect);
         SDL_FreeSurface(temp);
       }
@@ -334,15 +375,6 @@ namespace SDL
   }
 
   void
-  Renderer::draw_text(const DrawingRequest& request)
-  {
-    const TextRequest* textrequest = (TextRequest*) request.request_data;
-
-    textrequest->font->draw(this, textrequest->text, request.pos,
-        textrequest->alignment, request.drawing_effect, request.alpha);
-  }
-
-  void
   Renderer::draw_filled_rect(const DrawingRequest& request)
   {
     const FillRectRequest* fillrectrequest
@@ -364,12 +396,17 @@ namespace SDL
       SDL_Surface *temp = SDL_CreateRGBSurface(screen->flags, rect.w, rect.h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
 
       SDL_FillRect(temp, 0, color);
-      SDL_SetAlpha(temp, SDL_SRCALPHA, a);
+      SDL_SetAlpha(temp, SDL_SRCALPHA | SDL_RLEACCEL, a);
       SDL_BlitSurface(temp, 0, screen, &rect);
       SDL_FreeSurface(temp);
     }
   }
 
+  void
+  Renderer::draw_inverse_ellipse(const DrawingRequest&)
+  {
+  }
+
   void 
   Renderer::do_take_screenshot()
   {
@@ -404,4 +441,10 @@ namespace SDL
   {
     SDL_Flip(screen);
   }
+
+  void
+  Renderer::resize(int, int)
+  {
+    
+  }
 }