[Supertux-Commit] r5979 - in branches/supertux-milestone2-grumbel/src: gui object sprite supertux video video/gl video/sdl

grumbel at cummiskey.dreamhost.com grumbel at cummiskey.dreamhost.com
Sun Nov 15 12:59:19 PST 2009


Author: grumbel
Date: 2009-11-15 12:59:17 -0800 (Sun, 15 Nov 2009)
New Revision: 5979

Added:
   branches/supertux-milestone2-grumbel/src/video/surface.cpp
Modified:
   branches/supertux-milestone2-grumbel/src/gui/menu.hpp
   branches/supertux-milestone2-grumbel/src/gui/mousecursor.cpp
   branches/supertux-milestone2-grumbel/src/object/gameobjs.cpp
   branches/supertux-milestone2-grumbel/src/object/scripted_object.cpp
   branches/supertux-milestone2-grumbel/src/sprite/sprite_data.cpp
   branches/supertux-milestone2-grumbel/src/sprite/sprite_data.hpp
   branches/supertux-milestone2-grumbel/src/supertux/game_session.hpp
   branches/supertux-milestone2-grumbel/src/supertux/tile.cpp
   branches/supertux-milestone2-grumbel/src/supertux/tile.hpp
   branches/supertux-milestone2-grumbel/src/supertux/tile_set.cpp
   branches/supertux-milestone2-grumbel/src/supertux/tile_set.hpp
   branches/supertux-milestone2-grumbel/src/video/drawing_context.hpp
   branches/supertux-milestone2-grumbel/src/video/font.cpp
   branches/supertux-milestone2-grumbel/src/video/font.hpp
   branches/supertux-milestone2-grumbel/src/video/gl/gl_lightmap.cpp
   branches/supertux-milestone2-grumbel/src/video/gl/gl_renderer.cpp
   branches/supertux-milestone2-grumbel/src/video/gl/gl_renderer.hpp
   branches/supertux-milestone2-grumbel/src/video/gl/gl_surface_data.hpp
   branches/supertux-milestone2-grumbel/src/video/gl/gl_texture.cpp
   branches/supertux-milestone2-grumbel/src/video/gl/gl_texture.hpp
   branches/supertux-milestone2-grumbel/src/video/sdl/sdl_lightmap.cpp
   branches/supertux-milestone2-grumbel/src/video/sdl/sdl_lightmap.hpp
   branches/supertux-milestone2-grumbel/src/video/sdl/sdl_renderer.cpp
   branches/supertux-milestone2-grumbel/src/video/sdl/sdl_renderer.hpp
   branches/supertux-milestone2-grumbel/src/video/sdl/sdl_surface_data.hpp
   branches/supertux-milestone2-grumbel/src/video/sdl/sdl_texture.cpp
   branches/supertux-milestone2-grumbel/src/video/sdl/sdl_texture.hpp
   branches/supertux-milestone2-grumbel/src/video/surface.hpp
   branches/supertux-milestone2-grumbel/src/video/texture.hpp
Log:
Moved surface code into surface.cpp, fixed includes and some indention

Modified: branches/supertux-milestone2-grumbel/src/gui/menu.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/gui/menu.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/gui/menu.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -19,6 +19,7 @@
 
 #include <list>
 #include <memory>
+#include <SDL.h>
 
 #include "gui/mousecursor.hpp"
 #include "video/font.hpp"

Modified: branches/supertux-milestone2-grumbel/src/gui/mousecursor.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/gui/mousecursor.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/gui/mousecursor.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -16,6 +16,8 @@
 
 #include "gui/mousecursor.hpp"
 
+#include <SDL.h>
+
 #include "supertux/main.hpp"
 #include "video/drawing_context.hpp"
 

Modified: branches/supertux-milestone2-grumbel/src/object/gameobjs.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/object/gameobjs.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/object/gameobjs.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -14,8 +14,11 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+#include "object/gameobjs.hpp"
+
+#include <stdio.h>
+
 #include "math/random_generator.hpp"
-#include "object/gameobjs.hpp"
 #include "sprite/sprite.hpp"
 #include "sprite/sprite_manager.hpp"
 #include "supertux/resources.hpp"

Modified: branches/supertux-milestone2-grumbel/src/object/scripted_object.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/object/scripted_object.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/object/scripted_object.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -15,6 +15,9 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "object/scripted_object.hpp"
+
+#include <stdio.h>
+
 #include "scripting/squirrel_util.hpp"
 #include "sprite/sprite.hpp"
 #include "supertux/object_factory.hpp"

Modified: branches/supertux-milestone2-grumbel/src/sprite/sprite_data.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/sprite/sprite_data.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/sprite/sprite_data.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -16,6 +16,9 @@
 
 #include "sprite/sprite_data.hpp"
 
+#include <stdexcept>
+#include <sstream>
+
 #include "lisp/list_iterator.hpp"
 #include "util/log.hpp"
 
@@ -89,8 +92,7 @@
     } else {
       float max_w = 0;
       float max_h = 0;
-      for(int i = 0; static_cast<unsigned int>(i) < act_tmp->surfaces.size();
-          i++) {
+      for(int i = 0; static_cast<unsigned int>(i) < act_tmp->surfaces.size(); i++) {
         Surface* surface = new Surface(*(act_tmp->surfaces[i]));
         surface->hflip();
         max_w = std::max(max_w, (float) surface->get_width());

Modified: branches/supertux-milestone2-grumbel/src/sprite/sprite_data.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/sprite/sprite_data.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/sprite/sprite_data.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -17,6 +17,8 @@
 #ifndef HEADER_SUPERTUX_SPRITE_SPRITE_DATA_HPP
 #define HEADER_SUPERTUX_SPRITE_SPRITE_DATA_HPP
 
+#include <map>
+
 #include "lisp/lisp.hpp"
 #include "video/surface.hpp"
 

Modified: branches/supertux-milestone2-grumbel/src/supertux/game_session.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/supertux/game_session.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/supertux/game_session.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -18,6 +18,7 @@
 #define HEADER_SUPERTUX_SUPERTUX_GAME_SESSION_HPP
 
 #include <memory>
+#include <vector>
 #include <squirrel.h>
 
 #include "object/endsequence.hpp"

Modified: branches/supertux-milestone2-grumbel/src/supertux/tile.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/supertux/tile.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/supertux/tile.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -15,18 +15,27 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+#include "supertux/tile.hpp"
+
 #include "lisp/lisp.hpp"
 #include "supertux/tile_set.hpp"
 #include "supertux/timer.hpp"
 #include "video/drawing_context.hpp"
 
-Tile::Tile(const TileSet *new_tileset)
-  : tileset(new_tileset), attributes(0), data(0), anim_fps(1)
+Tile::Tile(const TileSet *new_tileset) :
+  tileset(new_tileset), 
+  attributes(0), 
+  data(0), 
+  anim_fps(1)
 {
 }
 
-Tile::Tile(const TileSet *new_tileset, std::vector<std::string> images, Rect rect, Uint32 attributes, Uint32 data, float animfps)
-  : tileset(new_tileset), attributes(attributes), data(data), anim_fps(animfps)
+Tile::Tile(const TileSet *new_tileset, std::vector<std::string> images, Rect rect, 
+           uint32_t attributes, uint32_t data, float animfps) :
+  tileset(new_tileset),
+  attributes(attributes), 
+  data(data), 
+  anim_fps(animfps)
 {
   for(std::vector<std::string>::iterator i = images.begin(); i != images.end(); ++i) {
     imagespecs.push_back(ImageSpec(*i, rect));

Modified: branches/supertux-milestone2-grumbel/src/supertux/tile.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/supertux/tile.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/supertux/tile.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -18,6 +18,9 @@
 #ifndef HEADER_SUPERTUX_SUPERTUX_TILE_HPP
 #define HEADER_SUPERTUX_SUPERTUX_TILE_HPP
 
+#include <stdint.h>
+#include <vector>
+
 #include "math/rect.hpp"
 #include "video/surface.hpp"
 
@@ -137,7 +140,7 @@
   friend class TileSet;
   Tile(const TileSet *tileset);
   Tile(const TileSet *tileset, std::vector<std::string> images, Rect rect,
-       Uint32 attributes = 0, Uint32 data = 0, float animfps = 1.0);
+       uint32_t attributes = 0, uint32_t data = 0, float animfps = 1.0);
 
   void load_images();
 

Modified: branches/supertux-milestone2-grumbel/src/supertux/tile_set.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/supertux/tile_set.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/supertux/tile_set.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -14,9 +14,13 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+#include "supertux/tile_set.hpp"
+
+#include <stdexcept>
+#include <sstream>
+
 #include "lisp/list_iterator.hpp"
 #include "lisp/parser.hpp"
-#include "supertux/tile_set.hpp"
 #include "util/file_system.hpp"
 
 TileSet::TileSet()

Modified: branches/supertux-milestone2-grumbel/src/supertux/tile_set.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/supertux/tile_set.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/supertux/tile_set.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -17,6 +17,8 @@
 #ifndef HEADER_SUPERTUX_SUPERTUX_TILE_SET_HPP
 #define HEADER_SUPERTUX_SUPERTUX_TILE_SET_HPP
 
+#include <stdint.h>
+
 #include "supertux/tile.hpp"
 #include "util/log.hpp"
 

Modified: branches/supertux-milestone2-grumbel/src/video/drawing_context.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/drawing_context.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/drawing_context.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -29,6 +29,7 @@
 #include "video/color.hpp"
 #include "video/drawing_request.hpp"
 #include "video/font.hpp"
+#include "video/texture.hpp"
 
 class Surface;
 class Texture;

Modified: branches/supertux-milestone2-grumbel/src/video/font.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/font.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/font.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -101,9 +101,9 @@
 Font::Font(GlyphWidth glyph_width_,
            const std::string& filename,
            int shadowsize_)
-    :   glyph_width(glyph_width_),
-        shadowsize(shadowsize_),
-        glyphs(65536)
+  :   glyph_width(glyph_width_),
+      shadowsize(shadowsize_),
+      glyphs(65536)
 {
   for(unsigned int i=0; i<65536;i++) glyphs[i].surface_idx = -1;
 
@@ -205,8 +205,8 @@
   int char_width
   )
 {
-  Surface glyph_surface = Surface("images/engine/fonts/" + glyphimage);
-  Surface shadow_surface = Surface("images/engine/fonts/" + shadowimage);
+  Surface glyph_surface("images/engine/fonts/" + glyphimage);
+  Surface shadow_surface("images/engine/fonts/" + shadowimage);
 
   int surface_idx = glyph_surfaces.size();
   glyph_surfaces.push_back(glyph_surface);

Modified: branches/supertux-milestone2-grumbel/src/video/font.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/font.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/font.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -25,6 +25,7 @@
 #include "math/vector.hpp"
 #include "video/color.hpp"
 #include "video/surface.hpp"
+#include "video/texture.hpp"
 
 class Renderer;
 

Modified: branches/supertux-milestone2-grumbel/src/video/gl/gl_lightmap.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/gl/gl_lightmap.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/gl/gl_lightmap.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -93,10 +93,10 @@
     bottom -= center_y;
 
     float vertices[] = {
-        left*ca - top*sa + center_x, left*sa + top*ca + center_y,
-        right*ca - top*sa + center_x, right*sa + top*ca + center_y,
-        right*ca - bottom*sa + center_x, right*sa + bottom*ca + center_y,
-        left*ca - bottom*sa + center_x, left*sa + bottom*ca + center_y
+      left*ca - top*sa + center_x, left*sa + top*ca + center_y,
+      right*ca - top*sa + center_x, right*sa + top*ca + center_y,
+      right*ca - bottom*sa + center_x, right*sa + bottom*ca + center_y,
+      left*ca - bottom*sa + center_x, left*sa + bottom*ca + center_y
     };
     glVertexPointer(2, GL_FLOAT, 0, vertices);
 

Modified: branches/supertux-milestone2-grumbel/src/video/gl/gl_renderer.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/gl/gl_renderer.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/gl/gl_renderer.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -86,10 +86,10 @@
     bottom -= center_y;
 
     float vertices[] = {
-        left*ca - top*sa + center_x, left*sa + top*ca + center_y,
-        right*ca - top*sa + center_x, right*sa + top*ca + center_y,
-        right*ca - bottom*sa + center_x, right*sa + bottom*ca + center_y,
-        left*ca - bottom*sa + center_x, left*sa + bottom*ca + center_y
+      left*ca - top*sa + center_x, left*sa + top*ca + center_y,
+      right*ca - top*sa + center_x, right*sa + top*ca + center_y,
+      right*ca - bottom*sa + center_x, right*sa + bottom*ca + center_y,
+      left*ca - bottom*sa + center_x, left*sa + bottom*ca + center_y
     };
     glVertexPointer(2, GL_FLOAT, 0, vertices);
 
@@ -125,10 +125,10 @@
   // the window size instead of the desktop size.
   const SDL_VideoInfo *info = SDL_GetVideoInfo();
   if (info)
-    {
-      desktop_width  = info->current_w;
-      desktop_height = info->current_h;     
-    }
+  {
+    desktop_width  = info->current_w;
+    desktop_height = info->current_h;     
+  }
 #endif
 
   if(texture_manager != 0)
@@ -153,17 +153,17 @@
   int height;
 
   if(config->use_fullscreen)
-    {
-      flags |= SDL_FULLSCREEN;
-      width  = config->fullscreen_width;
-      height = config->fullscreen_height;
-    }
+  {
+    flags |= SDL_FULLSCREEN;
+    width  = config->fullscreen_width;
+    height = config->fullscreen_height;
+  }
   else
-    {
-//      flags |= SDL_RESIZABLE;
-      width  = config->window_width;
-      height = config->window_height;
-    }
+  {
+    //      flags |= SDL_RESIZABLE;
+    width  = config->window_width;
+    height = config->window_height;
+  }
 
   int bpp = 0;
   SDL_Surface *screen = SDL_SetVideoMode(width, height, bpp, flags);
@@ -300,68 +300,68 @@
   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   
   if (fillrectrequest->radius != 0.0f)
-    {
-      // draw round rect
-      // Keep radius in the limits, so that we get a circle instead of
-      // just graphic junk
-      float radius = std::min(fillrectrequest->radius,
-                              std::min(fillrectrequest->size.x/2,
-                                       fillrectrequest->size.y/2));
+  {
+    // draw round rect
+    // Keep radius in the limits, so that we get a circle instead of
+    // just graphic junk
+    float radius = std::min(fillrectrequest->radius,
+                            std::min(fillrectrequest->size.x/2,
+                                     fillrectrequest->size.y/2));
 
-      // inner rectangle
-      Rect irect(request.pos.x    + radius,
-                 request.pos.y    + radius,
-                 request.pos.x + fillrectrequest->size.x - radius,
-                 request.pos.y + fillrectrequest->size.y - radius);
+    // inner rectangle
+    Rect irect(request.pos.x    + radius,
+               request.pos.y    + radius,
+               request.pos.x + fillrectrequest->size.x - radius,
+               request.pos.y + fillrectrequest->size.y - radius);
 
-      int n = 8;
-      int p = 0;
-      std::vector<float> vertices((n+1) * 4 * 2);
+    int n = 8;
+    int p = 0;
+    std::vector<float> vertices((n+1) * 4 * 2);
 
-      for(int i = 0; i <= n; ++i)
-        {
-          float x = sinf(i * (M_PI/2) / n) * radius;
-          float y = cosf(i * (M_PI/2) / n) * radius;
+    for(int i = 0; i <= n; ++i)
+    {
+      float x = sinf(i * (M_PI/2) / n) * radius;
+      float y = cosf(i * (M_PI/2) / n) * radius;
 
-          vertices[p++] = irect.get_left() - x;
-          vertices[p++] = irect.get_top()  - y;
+      vertices[p++] = irect.get_left() - x;
+      vertices[p++] = irect.get_top()  - y;
 
-          vertices[p++] = irect.get_right() + x;
-          vertices[p++] = irect.get_top()   - y;
-        }
+      vertices[p++] = irect.get_right() + x;
+      vertices[p++] = irect.get_top()   - y;
+    }
 
-      for(int i = 0; i <= n; ++i)
-        {
-          float x = cosf(i * (M_PI/2) / n) * radius;
-          float y = sinf(i * (M_PI/2) / n) * radius;
+    for(int i = 0; i <= n; ++i)
+    {
+      float x = cosf(i * (M_PI/2) / n) * radius;
+      float y = sinf(i * (M_PI/2) / n) * radius;
 
-          vertices[p++] = irect.get_left()   - x;
-          vertices[p++] = irect.get_bottom() + y;
+      vertices[p++] = irect.get_left()   - x;
+      vertices[p++] = irect.get_bottom() + y;
 
-          vertices[p++] = irect.get_right()  + x;
-          vertices[p++] = irect.get_bottom() + y;
-        }
+      vertices[p++] = irect.get_right()  + x;
+      vertices[p++] = irect.get_bottom() + y;
+    }
 
-      glVertexPointer(2, GL_FLOAT, 0, &*vertices.begin());
-      glDrawArrays(GL_TRIANGLE_STRIP, 0,  vertices.size()/2);
-    }
+    glVertexPointer(2, GL_FLOAT, 0, &*vertices.begin());
+    glDrawArrays(GL_TRIANGLE_STRIP, 0,  vertices.size()/2);
+  }
   else
-    {
-      float x = request.pos.x;
-      float y = request.pos.y;
-      float w = fillrectrequest->size.x;
-      float h = fillrectrequest->size.y;
+  {
+    float x = request.pos.x;
+    float y = request.pos.y;
+    float w = fillrectrequest->size.x;
+    float h = fillrectrequest->size.y;
 
-      float vertices[] = {
-        x,   y,
-        x+w, y,
-        x+w, y+h,
-        x,   y+h
-      };
-      glVertexPointer(2, GL_FLOAT, 0, vertices);
+    float vertices[] = {
+      x,   y,
+      x+w, y,
+      x+w, y+h,
+      x,   y+h
+    };
+    glVertexPointer(2, GL_FLOAT, 0, vertices);
 
-      glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-    }
+    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+  }
 
   glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   glEnable(GL_TEXTURE_2D);
@@ -409,33 +409,33 @@
   vertices[p++] = x-w;          vertices[p++] = y;
 
   for(int i = 0; i < slices; ++i)
-    {
-      float ex1 = sinf(M_PI/2 / slices * i) * w;
-      float ey1 = cosf(M_PI/2 / slices * i) * h;
+  {
+    float ex1 = sinf(M_PI/2 / slices * i) * w;
+    float ey1 = cosf(M_PI/2 / slices * i) * h;
 
-      float ex2 = sinf(M_PI/2 / slices * (i+1)) * w;
-      float ey2 = cosf(M_PI/2 / slices * (i+1)) * h;
+    float ex2 = sinf(M_PI/2 / slices * (i+1)) * w;
+    float ey2 = cosf(M_PI/2 / slices * (i+1)) * h;
 
-      // Bottom/Right
-      vertices[p++] = SCREEN_WIDTH; vertices[p++] = SCREEN_HEIGHT;
-      vertices[p++] = x + ex1;      vertices[p++] = y + ey1;
-      vertices[p++] = x + ex2;      vertices[p++] = y + ey2;
+    // Bottom/Right
+    vertices[p++] = SCREEN_WIDTH; vertices[p++] = SCREEN_HEIGHT;
+    vertices[p++] = x + ex1;      vertices[p++] = y + ey1;
+    vertices[p++] = x + ex2;      vertices[p++] = y + ey2;
 
-      // Top/Left
-      vertices[p++] = 0;            vertices[p++] = 0;
-      vertices[p++] = x - ex1;      vertices[p++] = y - ey1;
-      vertices[p++] = x - ex2;      vertices[p++] = y - ey2;
+    // Top/Left
+    vertices[p++] = 0;            vertices[p++] = 0;
+    vertices[p++] = x - ex1;      vertices[p++] = y - ey1;
+    vertices[p++] = x - ex2;      vertices[p++] = y - ey2;
 
-      // Top/Right
-      vertices[p++] = SCREEN_WIDTH; vertices[p++] = 0;
-      vertices[p++] = x + ex1;      vertices[p++] = y - ey1;
-      vertices[p++] = x + ex2;      vertices[p++] = y - ey2;
+    // Top/Right
+    vertices[p++] = SCREEN_WIDTH; vertices[p++] = 0;
+    vertices[p++] = x + ex1;      vertices[p++] = y - ey1;
+    vertices[p++] = x + ex2;      vertices[p++] = y - ey2;
 
-      // Bottom/Left
-      vertices[p++] = 0;            vertices[p++] = SCREEN_HEIGHT;
-      vertices[p++] = x - ex1;      vertices[p++] = y + ey1;
-      vertices[p++] = x - ex2;      vertices[p++] = y + ey2;
-    }
+    // Bottom/Left
+    vertices[p++] = 0;            vertices[p++] = SCREEN_HEIGHT;
+    vertices[p++] = x - ex1;      vertices[p++] = y + ey1;
+    vertices[p++] = x - ex2;      vertices[p++] = y + ey2;
+  }
 
   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   glVertexPointer(2, GL_FLOAT, 0, vertices);
@@ -478,15 +478,15 @@
   for (int i = 0; i < SCREEN_HEIGHT; i++) {
     char* src = pixels + (3 * SCREEN_WIDTH * (SCREEN_HEIGHT - i - 1));
     if(SDL_MUSTLOCK(shot_surf))
-      {
-        SDL_LockSurface(shot_surf);
-      }
+    {
+      SDL_LockSurface(shot_surf);
+    }
     char* dst = ((char*)shot_surf->pixels) + i * shot_surf->pitch;
     memcpy(dst, src, 3 * SCREEN_WIDTH);
     if(SDL_MUSTLOCK(shot_surf))
-      {
-        SDL_UnlockSurface(shot_surf);
-      }
+    {
+      SDL_UnlockSurface(shot_surf);
+    }
   }
 
   // free array
@@ -540,15 +540,15 @@
 Renderer::apply_config()
 {    
   if (0)
-    {
-      std::cout << "Applying Config:" 
-                << "\n  Desktop: " << desktop_width << "x" << desktop_height
-                << "\n  Window:  " << config->window_width << "x" << config->window_height
-                << "\n  FullRes: " << config->fullscreen_width << "x" << config->fullscreen_height
-                << "\n  Aspect:  " << config->aspect_width << ":" << config->aspect_height
-                << "\n  Magnif:  " << config->magnification
-                << std::endl;
-    }
+  {
+    std::cout << "Applying Config:" 
+              << "\n  Desktop: " << desktop_width << "x" << desktop_height
+              << "\n  Window:  " << config->window_width << "x" << config->window_height
+              << "\n  FullRes: " << config->fullscreen_width << "x" << config->fullscreen_height
+              << "\n  Aspect:  " << config->aspect_width << ":" << config->aspect_height
+              << "\n  Magnif:  " << config->magnification
+              << std::endl;
+  }
 
   int w,h;
   float target_aspect = float(desktop_width) / desktop_height;
@@ -559,90 +559,90 @@
   float desktop_aspect = 4.0f / 3.0f; // random default fallback guess
   
   if (desktop_width != -1 && desktop_height != -1)
-    {
-      desktop_aspect = float(desktop_width) / float(desktop_height);
-    }
+  {
+    desktop_aspect = float(desktop_width) / float(desktop_height);
+  }
 
   // Get the screen width
   if (config->use_fullscreen)
-    {
-      w = config->fullscreen_width;
-      h = config->fullscreen_height;
-      desktop_aspect = float(w) / float(h);
-    }
+  {
+    w = config->fullscreen_width;
+    h = config->fullscreen_height;
+    desktop_aspect = float(w) / float(h);
+  }
   else
-    {
-      w = config->window_width;        
-      h = config->window_height;
-    }
+  {
+    w = config->window_width;        
+    h = config->window_height;
+  }
 
   if (target_aspect > 1.0f)
-    {
-      SCREEN_WIDTH  = static_cast<int>(w * (target_aspect / desktop_aspect));
-      SCREEN_HEIGHT = static_cast<int>(h);
-    }
+  {
+    SCREEN_WIDTH  = static_cast<int>(w * (target_aspect / desktop_aspect));
+    SCREEN_HEIGHT = static_cast<int>(h);
+  }
   else
-    {
-      SCREEN_WIDTH  = static_cast<int>(w);
-      SCREEN_HEIGHT = static_cast<int>(h  * (target_aspect / desktop_aspect));
-    }
+  {
+    SCREEN_WIDTH  = static_cast<int>(w);
+    SCREEN_HEIGHT = static_cast<int>(h  * (target_aspect / desktop_aspect));
+  }
 
   int max_width  = 1600; // FIXME: Maybe 1920 is ok too
   int max_height = 1200;
 
   if (config->magnification == 0.0f) // Magic value that means 'minfill'
+  {
+    // This scales SCREEN_WIDTH/SCREEN_HEIGHT so that they never excede
+    // max_width/max_height
+    if (SCREEN_WIDTH > max_width || SCREEN_HEIGHT > max_height)
     {
-      // This scales SCREEN_WIDTH/SCREEN_HEIGHT so that they never excede
-      // max_width/max_height
-      if (SCREEN_WIDTH > max_width || SCREEN_HEIGHT > max_height)
-        {
-          float scale1  = float(max_width)/SCREEN_WIDTH;
-          float scale2  = float(max_height)/SCREEN_HEIGHT;
-          float scale   = (scale1 < scale2) ? scale1 : scale2;
-          SCREEN_WIDTH  = static_cast<int>(SCREEN_WIDTH  * scale);
-          SCREEN_HEIGHT = static_cast<int>(SCREEN_HEIGHT * scale);
-        }
+      float scale1  = float(max_width)/SCREEN_WIDTH;
+      float scale2  = float(max_height)/SCREEN_HEIGHT;
+      float scale   = (scale1 < scale2) ? scale1 : scale2;
+      SCREEN_WIDTH  = static_cast<int>(SCREEN_WIDTH  * scale);
+      SCREEN_HEIGHT = static_cast<int>(SCREEN_HEIGHT * scale);
+    }
 
-      glViewport(0, 0, w, h);
-    }
+    glViewport(0, 0, w, h);
+  }
   else
-    {
-      SCREEN_WIDTH  = static_cast<int>(SCREEN_WIDTH  / config->magnification);
-      SCREEN_HEIGHT = static_cast<int>(SCREEN_HEIGHT / config->magnification);
+  {
+    SCREEN_WIDTH  = static_cast<int>(SCREEN_WIDTH  / config->magnification);
+    SCREEN_HEIGHT = static_cast<int>(SCREEN_HEIGHT / config->magnification);
 
-      // This works by adding black borders around the screen to limit
-      // SCREEN_WIDTH/SCREEN_HEIGHT to max_width/max_height
-      int nw = w;
-      int nh = h;
+    // This works by adding black borders around the screen to limit
+    // SCREEN_WIDTH/SCREEN_HEIGHT to max_width/max_height
+    int nw = w;
+    int nh = h;
 
-      if (SCREEN_WIDTH > max_width)
-        {
-          nw = static_cast<int>((float) nw * float(max_width)/SCREEN_WIDTH);
-          SCREEN_WIDTH = static_cast<int>(max_width);
-        }
+    if (SCREEN_WIDTH > max_width)
+    {
+      nw = static_cast<int>((float) nw * float(max_width)/SCREEN_WIDTH);
+      SCREEN_WIDTH = static_cast<int>(max_width);
+    }
 
-      if (SCREEN_HEIGHT > max_height)
-        {
-          nh = static_cast<int>((float) nh * float(max_height)/SCREEN_HEIGHT);
-          SCREEN_HEIGHT = static_cast<int>(max_height);
-        }
+    if (SCREEN_HEIGHT > max_height)
+    {
+      nh = static_cast<int>((float) nh * float(max_height)/SCREEN_HEIGHT);
+      SCREEN_HEIGHT = static_cast<int>(max_height);
+    }
 
-      // Clear both buffers so that we get a clean black border without junk
-      glClear(GL_COLOR_BUFFER_BIT);
-      SDL_GL_SwapBuffers();
-      glClear(GL_COLOR_BUFFER_BIT);
-      SDL_GL_SwapBuffers();
+    // Clear both buffers so that we get a clean black border without junk
+    glClear(GL_COLOR_BUFFER_BIT);
+    SDL_GL_SwapBuffers();
+    glClear(GL_COLOR_BUFFER_BIT);
+    SDL_GL_SwapBuffers();
 
-      if (0)
-        std::cout << (w-nw)/2 << " "
-                  << (h-nh)/2 << " "
-                  << nw << "x" << nh << std::endl;
+    if (0)
+      std::cout << (w-nw)/2 << " "
+                << (h-nh)/2 << " "
+                << nw << "x" << nh << std::endl;
 
-      glViewport(std::max(0, (w-nw)/2), 
-                 std::max(0, (h-nh)/2), 
-                 std::min(nw, w),
-                 std::min(nh, h));
-    }
+    glViewport(std::max(0, (w-nw)/2), 
+               std::max(0, (h-nh)/2), 
+               std::min(nw, w),
+               std::min(nh, h));
+  }
 
   if (0)
     std::cout << "  -> " << SCREEN_WIDTH << "x" << SCREEN_HEIGHT << std::endl;

Modified: branches/supertux-milestone2-grumbel/src/video/gl/gl_renderer.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/gl/gl_renderer.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/gl/gl_renderer.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -20,27 +20,27 @@
 #include "video/renderer.hpp"
 
 namespace GL {
-  class Renderer : public ::Renderer
-  {
-  private:
-    int desktop_width;
-    int desktop_height;
+class Renderer : public ::Renderer
+{
+private:
+  int desktop_width;
+  int desktop_height;
 
-  public:
-    Renderer();
-    ~Renderer();
+public:
+  Renderer();
+  ~Renderer();
 
-    void draw_surface(const DrawingRequest& request);
-    void draw_surface_part(const DrawingRequest& request);
-    void draw_text(const DrawingRequest& request);
-    void draw_gradient(const DrawingRequest& request);
-    void draw_filled_rect(const DrawingRequest& request);
-    void draw_inverse_ellipse(const DrawingRequest& request);
-    void do_take_screenshot();
-    void flip();
-    void resize(int w, int h);
-    void apply_config();
-  };
+  void draw_surface(const DrawingRequest& request);
+  void draw_surface_part(const DrawingRequest& request);
+  void draw_text(const DrawingRequest& request);
+  void draw_gradient(const DrawingRequest& request);
+  void draw_filled_rect(const DrawingRequest& request);
+  void draw_inverse_ellipse(const DrawingRequest& request);
+  void do_take_screenshot();
+  void flip();
+  void resize(int w, int h);
+  void apply_config();
+};
 }
 
 #endif

Modified: branches/supertux-milestone2-grumbel/src/video/gl/gl_surface_data.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/gl/gl_surface_data.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/gl/gl_surface_data.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -20,45 +20,45 @@
 #include "video/surface.hpp"
 
 namespace GL {
-  class SurfaceData
+class SurfaceData
+{
+private:
+  const Surface &surface;
+  float uv_left;
+  float uv_top;
+  float uv_right;
+  float uv_bottom;
+
+public:
+  SurfaceData(const Surface &surface) :
+    surface(surface),
+    uv_left((float) surface.get_x() / surface.get_texture()->get_texture_width()),
+    uv_top((float) surface.get_y() / surface.get_texture()->get_texture_height()),
+    uv_right((float) (surface.get_x() + surface.get_width()) / surface.get_texture()->get_texture_width()),
+    uv_bottom((float) (surface.get_y() + surface.get_height()) / surface.get_texture()->get_texture_height())
   {
-  private:
-    const Surface &surface;
-    float uv_left;
-    float uv_top;
-    float uv_right;
-    float uv_bottom;
+  }
 
-  public:
-    SurfaceData(const Surface &surface) :
-      surface(surface),
-      uv_left((float) surface.get_x() / surface.get_texture()->get_texture_width()),
-      uv_top((float) surface.get_y() / surface.get_texture()->get_texture_height()),
-      uv_right((float) (surface.get_x() + surface.get_width()) / surface.get_texture()->get_texture_width()),
-      uv_bottom((float) (surface.get_y() + surface.get_height()) / surface.get_texture()->get_texture_height())
-    {
-    }
+  float get_uv_left() const
+  {
+    return surface.get_flipx() ? uv_right : uv_left;
+  }
 
-    float get_uv_left() const
-    {
-      return surface.get_flipx() ? uv_right : uv_left;
-    }
+  float get_uv_top() const
+  {
+    return uv_top;
+  }
 
-    float get_uv_top() const
-    {
-      return uv_top;
-    }
+  float get_uv_right() const
+  {
+    return surface.get_flipx() ? uv_left : uv_right;
+  }
 
-    float get_uv_right() const
-    {
-      return surface.get_flipx() ? uv_left : uv_right;
-    }
-
-    float get_uv_bottom() const
-    {
-      return uv_bottom;
-    }
-  };
+  float get_uv_bottom() const
+  {
+    return uv_bottom;
+  }
+};
 }
 
 #endif

Modified: branches/supertux-milestone2-grumbel/src/video/gl/gl_texture.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/gl/gl_texture.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/gl/gl_texture.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -19,133 +19,133 @@
 
 namespace
 {
-  inline bool is_power_of_2(int v)
-  {
-    return (v & (v-1)) == 0;
-  }
+inline bool is_power_of_2(int v)
+{
+  return (v & (v-1)) == 0;
+}
 
-  inline int next_power_of_two(int val)
-  {
-    int result = 1;
-    while(result < val)
-      result *= 2;
-    return result;
-  }
+inline int next_power_of_two(int val)
+{
+  int result = 1;
+  while(result < val)
+    result *= 2;
+  return result;
 }
+}
 
 namespace GL {
-  Texture::Texture(unsigned int width, unsigned int height)
-  {
-    assert(is_power_of_2(width));
-    assert(is_power_of_2(height));
-    texture_width = width;
-    texture_height = height;
-    image_width = width;
-    image_height = height;
+Texture::Texture(unsigned int width, unsigned int height)
+{
+  assert(is_power_of_2(width));
+  assert(is_power_of_2(height));
+  texture_width = width;
+  texture_height = height;
+  image_width = width;
+  image_height = height;
 
-    assert_gl("before creating texture");
-    glGenTextures(1, &handle);
+  assert_gl("before creating texture");
+  glGenTextures(1, &handle);
 
-    try {
-      glBindTexture(GL_TEXTURE_2D, handle);
+  try {
+    glBindTexture(GL_TEXTURE_2D, handle);
 
-      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
-                   texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
+                 texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
 
-      set_texture_params();
-    } catch(...) {
-      glDeleteTextures(1, &handle);
-      throw;
-    }
+    set_texture_params();
+  } catch(...) {
+    glDeleteTextures(1, &handle);
+    throw;
   }
+}
 
-  Texture::Texture(SDL_Surface* image)
-  {
-    texture_width = next_power_of_two(image->w);
-    texture_height = next_power_of_two(image->h);
-    image_width = image->w;
-    image_height = image->h;
+Texture::Texture(SDL_Surface* image)
+{
+  texture_width = next_power_of_two(image->w);
+  texture_height = next_power_of_two(image->h);
+  image_width = image->w;
+  image_height = image->h;
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-    SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE,
-        texture_width, texture_height, 32,
-        0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
+  SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE,
+                                              texture_width, texture_height, 32,
+                                              0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
 #else
-    SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE,
-        texture_width, texture_height, 32,
-        0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+  SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE,
+                                              texture_width, texture_height, 32,
+                                              0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
 #endif
 
-    if(convert == 0) {
-      throw std::runtime_error("Couldn't create texture: out of memory");
-    }
+  if(convert == 0) {
+    throw std::runtime_error("Couldn't create texture: out of memory");
+  }
 
-    SDL_SetAlpha(image, 0, 0);
-    SDL_BlitSurface(image, 0, convert, 0);
+  SDL_SetAlpha(image, 0, 0);
+  SDL_BlitSurface(image, 0, convert, 0);
 
-    assert_gl("before creating texture");
-    glGenTextures(1, &handle);
+  assert_gl("before creating texture");
+  glGenTextures(1, &handle);
 
-    try {
-      GLenum sdl_format;
-      if(convert->format->BytesPerPixel == 3)
-        sdl_format = GL_RGB;
-      else if(convert->format->BytesPerPixel == 4)
-        sdl_format = GL_RGBA;
-      else
-        assert(false);
+  try {
+    GLenum sdl_format;
+    if(convert->format->BytesPerPixel == 3)
+      sdl_format = GL_RGB;
+    else if(convert->format->BytesPerPixel == 4)
+      sdl_format = GL_RGBA;
+    else
+      assert(false);
 
-      glBindTexture(GL_TEXTURE_2D, handle);
-      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+    glBindTexture(GL_TEXTURE_2D, handle);
+    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 #ifdef GL_UNPACK_ROW_LENGTH
-      glPixelStorei(GL_UNPACK_ROW_LENGTH, convert->pitch/convert->format->BytesPerPixel);
+    glPixelStorei(GL_UNPACK_ROW_LENGTH, convert->pitch/convert->format->BytesPerPixel);
 #else
-      /* OpenGL ES doesn't support UNPACK_ROW_LENGTH, let's hope SDL didn't add
-       * padding bytes, otherwise we need some extra code here... */
-      assert(convert->pitch == texture_width * convert->format->BytesPerPixel);
+    /* OpenGL ES doesn't support UNPACK_ROW_LENGTH, let's hope SDL didn't add
+     * padding bytes, otherwise we need some extra code here... */
+    assert(convert->pitch == texture_width * convert->format->BytesPerPixel);
 #endif
 
-      if(SDL_MUSTLOCK(convert))
-      {
-        SDL_LockSurface(convert);
-      }
-      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
-              texture_height, 0, sdl_format,
-              GL_UNSIGNED_BYTE, convert->pixels);
-      if(SDL_MUSTLOCK(convert))
-      {
-        SDL_UnlockSurface(convert);
-      }
+    if(SDL_MUSTLOCK(convert))
+    {
+      SDL_LockSurface(convert);
+    }
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_width,
+                 texture_height, 0, sdl_format,
+                 GL_UNSIGNED_BYTE, convert->pixels);
+    if(SDL_MUSTLOCK(convert))
+    {
+      SDL_UnlockSurface(convert);
+    }
 
-      assert_gl("creating texture");
+    assert_gl("creating texture");
 
-      set_texture_params();
-    } catch(...) {
-      glDeleteTextures(1, &handle);
-      SDL_FreeSurface(convert);
-      throw;
-    }
+    set_texture_params();
+  } catch(...) {
+    glDeleteTextures(1, &handle);
     SDL_FreeSurface(convert);
+    throw;
   }
+  SDL_FreeSurface(convert);
+}
 
-  Texture::~Texture()
-  {
-    glDeleteTextures(1, &handle);
-  }
+Texture::~Texture()
+{
+  glDeleteTextures(1, &handle);
+}
 
-  void
-  Texture::set_texture_params()
-  {
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+void
+Texture::set_texture_params()
+{
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 #ifdef GL_CLAMP
-    /* OpenGL ES doesn't support it */
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+  /* OpenGL ES doesn't support it */
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 #endif
 
-    assert_gl("set texture params");
-  }
+  assert_gl("set texture params");
 }
+}
 
 /* EOF */

Modified: branches/supertux-milestone2-grumbel/src/video/gl/gl_texture.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/gl/gl_texture.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/gl/gl_texture.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -25,61 +25,61 @@
  * into the texture
  */
 namespace GL {
-  class Texture : public ::Texture
-  {
-  protected:
-    GLuint handle;
-    unsigned int texture_width;
-    unsigned int texture_height;
-    unsigned int image_width;
-    unsigned int image_height;
+class Texture : public ::Texture
+{
+protected:
+  GLuint handle;
+  unsigned int texture_width;
+  unsigned int texture_height;
+  unsigned int image_width;
+  unsigned int image_height;
 
-  public:
-    Texture(unsigned int width, unsigned int height);
-    Texture(SDL_Surface* image);
-    ~Texture();
+public:
+  Texture(unsigned int width, unsigned int height);
+  Texture(SDL_Surface* image);
+  ~Texture();
 
-    const GLuint &get_handle() const {
-      return handle;
-    }
+  const GLuint &get_handle() const {
+    return handle;
+  }
 
-    void set_handle(GLuint handle) {
-      this->handle = handle;
-    }
+  void set_handle(GLuint handle) {
+    this->handle = handle;
+  }
 
-    unsigned int get_texture_width() const
-    {
-      return texture_width;
-    }
+  unsigned int get_texture_width() const
+  {
+    return texture_width;
+  }
 
-    unsigned int get_texture_height() const
-    {
-      return texture_height;
-    }
+  unsigned int get_texture_height() const
+  {
+    return texture_height;
+  }
 
-    unsigned int get_image_width() const
-    {
-      return image_width;
-    }
+  unsigned int get_image_width() const
+  {
+    return image_width;
+  }
 
-    unsigned int get_image_height() const
-    {
-      return image_height;
-    }
+  unsigned int get_image_height() const
+  {
+    return image_height;
+  }
 
-    void set_image_width(unsigned int width)
-    {
-      image_width = width;
-    }
+  void set_image_width(unsigned int width)
+  {
+    image_width = width;
+  }
 
-    void set_image_height(unsigned int height)
-    {
-      image_height = height;
-    }
+  void set_image_height(unsigned int height)
+  {
+    image_height = height;
+  }
 
-  private:
-    void set_texture_params();
-  };
+private:
+  void set_texture_params();
+};
 }
 
 #endif

Modified: branches/supertux-milestone2-grumbel/src/video/sdl/sdl_lightmap.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/sdl/sdl_lightmap.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/sdl/sdl_lightmap.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -21,294 +21,92 @@
 #include "video/sdl/sdl_texture.hpp"
 
 namespace SDL {
-  Lightmap::Lightmap()
-  {
-    screen = SDL_GetVideoSurface();
+Lightmap::Lightmap()
+{
+  screen = SDL_GetVideoSurface();
 
-    //float xfactor = 1.0f; // FIXME: (float) config->screenwidth / SCREEN_WIDTH;
-    //float yfactor = 1.0f; // FIXME: (float) config->screenheight / SCREEN_HEIGHT;
+  //float xfactor = 1.0f; // FIXME: (float) config->screenwidth / SCREEN_WIDTH;
+  //float yfactor = 1.0f; // FIXME: (float) config->screenheight / SCREEN_HEIGHT;
 
-    numerator = 1;
-    denominator = 1;
+  numerator = 1;
+  denominator = 1;
 
-    /* FIXME:
-    if(xfactor < yfactor)
-    {
-      numerator = config->screenwidth;
-      denominator = SCREEN_WIDTH;
-    }
-    else
-    {
-      numerator = config->screenheight;
-      denominator = SCREEN_HEIGHT;
-    }
-    */
+  /* FIXME:
+     if(xfactor < yfactor)
+     {
+     numerator = config->screenwidth;
+     denominator = SCREEN_WIDTH;
+     }
+     else
+     {
+     numerator = config->screenheight;
+     denominator = SCREEN_HEIGHT;
+     }
+  */
 
-    LIGHTMAP_DIV = 8 * numerator / denominator;
+  LIGHTMAP_DIV = 8 * numerator / denominator;
 
-    width = screen->w / LIGHTMAP_DIV;
-    height = screen->h / LIGHTMAP_DIV;
+  width = screen->w / LIGHTMAP_DIV;
+  height = screen->h / LIGHTMAP_DIV;
 
-    red_channel = (Uint8 *)malloc(width * height * sizeof(Uint8));
-    green_channel = (Uint8 *)malloc(width * height * sizeof(Uint8));
-    blue_channel = (Uint8 *)malloc(width * height * sizeof(Uint8));
-  }
+  red_channel = (Uint8 *)malloc(width * height * sizeof(Uint8));
+  green_channel = (Uint8 *)malloc(width * height * sizeof(Uint8));
+  blue_channel = (Uint8 *)malloc(width * height * sizeof(Uint8));
+}
 
-  Lightmap::~Lightmap()
-  {
-    free(red_channel);
-    free(green_channel);
-    free(blue_channel);
-  }
+Lightmap::~Lightmap()
+{
+  free(red_channel);
+  free(green_channel);
+  free(blue_channel);
+}
 
-  void
-  Lightmap::start_draw(const Color &ambient_color)
-  {
-    memset(red_channel, (Uint8) (ambient_color.red * 255), width * height * sizeof(Uint8));
-    memset(green_channel, (Uint8) (ambient_color.green * 255), width * height * sizeof(Uint8));
-    memset(blue_channel, (Uint8) (ambient_color.blue * 255), width * height * sizeof(Uint8));
-  }
+void
+Lightmap::start_draw(const Color &ambient_color)
+{
+  memset(red_channel, (Uint8) (ambient_color.red * 255), width * height * sizeof(Uint8));
+  memset(green_channel, (Uint8) (ambient_color.green * 255), width * height * sizeof(Uint8));
+  memset(blue_channel, (Uint8) (ambient_color.blue * 255), width * height * sizeof(Uint8));
+}
 
-  void
-  Lightmap::end_draw()
-  {
-  }
+void
+Lightmap::end_draw()
+{
+}
 
 //#define BILINEAR
 
 #ifdef BILINEAR
-  namespace
-  {
-    void merge(Uint8 color[3], Uint8 color0[3], Uint8 color1[3], int rem, int total)
-    {
-      color[0] = (color0[0] * (total - rem) + color1[0] * rem) / total;
-      color[1] = (color0[1] * (total - rem) + color1[1] * rem) / total;
-      color[2] = (color0[2] * (total - rem) + color1[2] * rem) / total;
-    }
-  }
+namespace
+{
+void merge(Uint8 color[3], Uint8 color0[3], Uint8 color1[3], int rem, int total)
+{
+  color[0] = (color0[0] * (total - rem) + color1[0] * rem) / total;
+  color[1] = (color0[1] * (total - rem) + color1[1] * rem) / total;
+  color[2] = (color0[2] * (total - rem) + color1[2] * rem) / total;
+}
+}
 #endif
 
-  void
-  Lightmap::do_draw()
+void
+Lightmap::do_draw()
+{
+  // FIXME: This is really slow
+  if(LIGHTMAP_DIV == 1)
   {
-    // FIXME: This is really slow
-    if(LIGHTMAP_DIV == 1)
+    int bpp = screen->format->BytesPerPixel;
+    if(SDL_MUSTLOCK(screen))
     {
-      int bpp = screen->format->BytesPerPixel;
-      if(SDL_MUSTLOCK(screen))
-      {
-        SDL_LockSurface(screen);
-      }
-      Uint8 *pixel = (Uint8 *) screen->pixels;
-      int loc = 0;
-      for(int y = 0;y < height;y++) {
-        for(int x = 0;x < width;x++, pixel += bpp, loc++) {
-          if(red_channel[loc] == 0xff && green_channel[loc] == 0xff && blue_channel[loc] == 0xff)
-          {
-            continue;
-          }
-          Uint32 mapped = 0;
-          switch(bpp) {
-            case 1:
-              mapped = *pixel;
-              break;
-            case 2:
-              mapped = *(Uint16 *)pixel;
-              break;
-            case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-              mapped |= pixel[0] << 16;
-              mapped |= pixel[1] << 8;
-              mapped |= pixel[2] << 0;
-#else
-              mapped |= pixel[0] << 0;
-              mapped |= pixel[1] << 8;
-              mapped |= pixel[2] << 16;
-#endif
-              break;
-            case 4:
-              mapped = *(Uint32 *)pixel;
-              break;
-          }
-          Uint8 red, green, blue, alpha;
-          SDL_GetRGBA(mapped, screen->format, &red, &green, &blue, &alpha);
-          red = (red * red_channel[loc]) >> 8;
-          green = (green * green_channel[loc]) >> 8;
-          blue = (blue * blue_channel[loc]) >> 8;
-          mapped = SDL_MapRGBA(screen->format, red, green, blue, alpha);
-          switch(bpp) {
-            case 1:
-              *pixel = mapped;
-              break;
-            case 2:
-              *(Uint16 *)pixel = mapped;
-              break;
-            case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-              pixel[0] = (mapped >> 16) & 0xff;
-              pixel[1] = (mapped >> 8) & 0xff;
-              pixel[2] = (mapped >> 0) & 0xff;
-#else
-              pixel[0] = (mapped >> 0) & 0xff;
-              pixel[1] = (mapped >> 8) & 0xff;
-              pixel[2] = (mapped >> 16) & 0xff;
-#endif
-              break;
-            case 4:
-              *(Uint32 *)pixel = mapped;
-              break;
-          }
-        }
-        pixel += screen->pitch - width * bpp;
-      }
-      if(SDL_MUSTLOCK(screen))
-      {
-        SDL_UnlockSurface(screen);
-      }
+      SDL_LockSurface(screen);
     }
-    else
-    {
-      int bpp = screen->format->BytesPerPixel;
-      if(SDL_MUSTLOCK(screen))
-      {
-        SDL_LockSurface(screen);
-      }
-      Uint8 *div_pixel = (Uint8 *) screen->pixels;
-      int loc = 0;
-      for(int y = 0;y < height;y++) {
-        for(int x = 0;x < width;x++, div_pixel += bpp * LIGHTMAP_DIV, loc++) {
-          if(red_channel[loc] == 0xff && green_channel[loc] == 0xff && blue_channel[loc] == 0xff)
-          {
-            continue;
-          }
-          Uint8 *pixel = div_pixel;
-          for(int div_y = 0;div_y < LIGHTMAP_DIV;div_y++) {
-            for(int div_x = 0;div_x < LIGHTMAP_DIV;pixel += bpp, div_x++) {
-              Uint32 mapped = 0;
-              switch(bpp) {
-                case 1:
-                  mapped = *pixel;
-                  break;
-                case 2:
-                  mapped = *(Uint16 *)pixel;
-                  break;
-                case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-                  mapped |= pixel[0] << 16;
-                  mapped |= pixel[1] << 8;
-                  mapped |= pixel[2] << 0;
-#else
-                  mapped |= pixel[0] << 0;
-                  mapped |= pixel[1] << 8;
-                  mapped |= pixel[2] << 16;
-#endif
-                  break;
-                case 4:
-                  mapped = *(Uint32 *)pixel;
-                  break;
-              }
-              Uint8 red, green, blue, alpha;
-              SDL_GetRGBA(mapped, screen->format, &red, &green, &blue, &alpha);
-
-#ifdef BILINEAR
-              int xinc = (x + 1 != width ? 1 : 0);
-              int yinc = (y + 1 != height ? width : 0);
-              Uint8 color00[3], color01[3], color10[3], color11[3];
-              {
-                color00[0] = red_channel[loc];
-                color00[1] = green_channel[loc];
-                color00[2] = blue_channel[loc];
-              }
-              {
-                color01[0] = red_channel[loc + xinc];
-                color01[1] = green_channel[loc + xinc];
-                color01[2] = blue_channel[loc + xinc];
-              }
-              {
-                color10[0] = red_channel[loc + yinc];
-                color10[1] = green_channel[loc + yinc];
-                color10[2] = blue_channel[loc + yinc];
-              }
-              {
-                color11[0] = red_channel[loc + yinc + xinc];
-                color11[1] = green_channel[loc + yinc + xinc];
-                color11[2] = blue_channel[loc + yinc + xinc];
-              }
-              Uint8 color0[3], color1[3], color[3];
-              merge(color0, color00, color01, div_x, LIGHTMAP_DIV);
-              merge(color1, color10, color11, div_x, LIGHTMAP_DIV);
-              merge(color, color0, color1, div_y, LIGHTMAP_DIV);
-              red = (red * color[0]) >> 8;
-              green = (green * color[1]) >> 8;
-              blue = (blue * color[2]) >> 8;
-#else
-              red = (red * red_channel[loc]) >> 8;
-              green = (green * green_channel[loc]) >> 8;
-              blue = (blue * blue_channel[loc]) >> 8;
-#endif
-
-              mapped = SDL_MapRGBA(screen->format, red, green, blue, alpha);
-              switch(bpp) {
-                case 1:
-                  *pixel = mapped;
-                  break;
-                case 2:
-                  *(Uint16 *)pixel = mapped;
-                  break;
-                case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-                  pixel[0] = (mapped >> 16) & 0xff;
-                  pixel[1] = (mapped >> 8) & 0xff;
-                  pixel[2] = (mapped >> 0) & 0xff;
-#else
-                  pixel[0] = (mapped >> 0) & 0xff;
-                  pixel[1] = (mapped >> 8) & 0xff;
-                  pixel[2] = (mapped >> 16) & 0xff;
-#endif
-                  break;
-                case 4:
-                  *(Uint32 *)pixel = mapped;
-                  break;
-              }
-            }
-            pixel += screen->pitch - LIGHTMAP_DIV * bpp;
-          }
-        }
-        div_pixel += (screen->pitch - width * bpp) * LIGHTMAP_DIV;
-      }
-      if(SDL_MUSTLOCK(screen))
-      {
-        SDL_UnlockSurface(screen);
-      }
-    }
-  }
-
-  void Lightmap::light_blit(SDL_Surface *src, SDL_Rect *src_rect, int dstx, int dsty)
-  {
-    dstx /= LIGHTMAP_DIV;
-    dsty /= LIGHTMAP_DIV;
-    int srcx = src_rect->x / LIGHTMAP_DIV;
-    int srcy = src_rect->y / LIGHTMAP_DIV;
-    int blit_width = src_rect->w / LIGHTMAP_DIV;
-    int blit_height = src_rect->h / LIGHTMAP_DIV;
-    int bpp = src->format->BytesPerPixel;
-    if(SDL_MUSTLOCK(src))
-    {
-      SDL_LockSurface(src);
-    }
-    Uint8 *pixel = (Uint8 *) src->pixels + srcy * src->pitch + srcx * bpp;
-    int loc = dsty * width + dstx;
-    for(int y = 0;y < blit_height;y++) {
-      for(int x = 0;x < blit_width;x++, pixel += bpp * LIGHTMAP_DIV, loc++) {
-        if(x + dstx < 0 || y + dsty < 0 || x + dstx >= width || y + dsty >= height)
-        {
-          continue;
-        }
+    Uint8 *pixel = (Uint8 *) screen->pixels;
+    int loc = 0;
+    for(int y = 0;y < height;y++) {
+      for(int x = 0;x < width;x++, pixel += bpp, loc++) {
         if(red_channel[loc] == 0xff && green_channel[loc] == 0xff && blue_channel[loc] == 0xff)
         {
           continue;
         }
-
         Uint32 mapped = 0;
         switch(bpp) {
           case 1:
@@ -333,267 +131,469 @@
             break;
         }
         Uint8 red, green, blue, alpha;
-        SDL_GetRGBA(mapped, src->format, &red, &green, &blue, &alpha);
-
-        if(red != 0)
-        {
-          int redsum = red_channel[loc] + (red * alpha >> 8);
-          red_channel[loc] = redsum & ~0xff ? 0xff : redsum;
+        SDL_GetRGBA(mapped, screen->format, &red, &green, &blue, &alpha);
+        red = (red * red_channel[loc]) >> 8;
+        green = (green * green_channel[loc]) >> 8;
+        blue = (blue * blue_channel[loc]) >> 8;
+        mapped = SDL_MapRGBA(screen->format, red, green, blue, alpha);
+        switch(bpp) {
+          case 1:
+            *pixel = mapped;
+            break;
+          case 2:
+            *(Uint16 *)pixel = mapped;
+            break;
+          case 3:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+            pixel[0] = (mapped >> 16) & 0xff;
+            pixel[1] = (mapped >> 8) & 0xff;
+            pixel[2] = (mapped >> 0) & 0xff;
+#else
+            pixel[0] = (mapped >> 0) & 0xff;
+            pixel[1] = (mapped >> 8) & 0xff;
+            pixel[2] = (mapped >> 16) & 0xff;
+#endif
+            break;
+          case 4:
+            *(Uint32 *)pixel = mapped;
+            break;
         }
-        if(green != 0)
-        {
-          int greensum = green_channel[loc] + (green * alpha >> 8);
-          green_channel[loc] = greensum & ~0xff ? 0xff : greensum;
-        }
-        if(blue != 0)
-        {
-          int bluesum = blue_channel[loc] + (blue * alpha >> 8);
-          blue_channel[loc] = bluesum & ~0xff ? 0xff : bluesum;
-        }
       }
-      pixel += (src->pitch - blit_width * bpp) * LIGHTMAP_DIV;
-      loc += width - blit_width;
+      pixel += screen->pitch - width * bpp;
     }
-    if(SDL_MUSTLOCK(src))
+    if(SDL_MUSTLOCK(screen))
     {
-      SDL_UnlockSurface(src);
+      SDL_UnlockSurface(screen);
     }
   }
-
-  /*void Lightmap::light_blit(SDL_Surface *src, SDL_Rect *src_rect, int dstx, int dsty)
+  else
   {
-    int bpp = src->format->BytesPerPixel;
-    if(SDL_MUSTLOCK(src))
+    int bpp = screen->format->BytesPerPixel;
+    if(SDL_MUSTLOCK(screen))
     {
-      SDL_LockSurface(src);
+      SDL_LockSurface(screen);
     }
-    Uint8 *pixel = (Uint8 *) src->pixels + src_rect->y * src->pitch + src_rect->x * bpp;
-    int loc = dsty * width + dstx;
-    for(int y = 0;y < src_rect->h;y++) {
-      for(int x = 0;x < src_rect->w;x++, pixel += bpp, loc++) {
-        if(x + dstx < 0 || y + dsty < 0 || x + dstx >= width || y + dsty >= height)
-        {
-          continue;
-        }
+    Uint8 *div_pixel = (Uint8 *) screen->pixels;
+    int loc = 0;
+    for(int y = 0;y < height;y++) {
+      for(int x = 0;x < width;x++, div_pixel += bpp * LIGHTMAP_DIV, loc++) {
         if(red_channel[loc] == 0xff && green_channel[loc] == 0xff && blue_channel[loc] == 0xff)
         {
           continue;
         }
+        Uint8 *pixel = div_pixel;
+        for(int div_y = 0;div_y < LIGHTMAP_DIV;div_y++) {
+          for(int div_x = 0;div_x < LIGHTMAP_DIV;pixel += bpp, div_x++) {
+            Uint32 mapped = 0;
+            switch(bpp) {
+              case 1:
+                mapped = *pixel;
+                break;
+              case 2:
+                mapped = *(Uint16 *)pixel;
+                break;
+              case 3:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+                mapped |= pixel[0] << 16;
+                mapped |= pixel[1] << 8;
+                mapped |= pixel[2] << 0;
+#else
+                mapped |= pixel[0] << 0;
+                mapped |= pixel[1] << 8;
+                mapped |= pixel[2] << 16;
+#endif
+                break;
+              case 4:
+                mapped = *(Uint32 *)pixel;
+                break;
+            }
+            Uint8 red, green, blue, alpha;
+            SDL_GetRGBA(mapped, screen->format, &red, &green, &blue, &alpha);
 
-        Uint32 mapped = 0;
-        switch(bpp) {
-          case 1:
-            mapped = *pixel;
-            break;
-          case 2:
-            mapped = *(Uint16 *)pixel;
-            break;
-          case 3:
+#ifdef BILINEAR
+            int xinc = (x + 1 != width ? 1 : 0);
+            int yinc = (y + 1 != height ? width : 0);
+            Uint8 color00[3], color01[3], color10[3], color11[3];
+            {
+              color00[0] = red_channel[loc];
+              color00[1] = green_channel[loc];
+              color00[2] = blue_channel[loc];
+            }
+            {
+              color01[0] = red_channel[loc + xinc];
+              color01[1] = green_channel[loc + xinc];
+              color01[2] = blue_channel[loc + xinc];
+            }
+            {
+              color10[0] = red_channel[loc + yinc];
+              color10[1] = green_channel[loc + yinc];
+              color10[2] = blue_channel[loc + yinc];
+            }
+            {
+              color11[0] = red_channel[loc + yinc + xinc];
+              color11[1] = green_channel[loc + yinc + xinc];
+              color11[2] = blue_channel[loc + yinc + xinc];
+            }
+            Uint8 color0[3], color1[3], color[3];
+            merge(color0, color00, color01, div_x, LIGHTMAP_DIV);
+            merge(color1, color10, color11, div_x, LIGHTMAP_DIV);
+            merge(color, color0, color1, div_y, LIGHTMAP_DIV);
+            red = (red * color[0]) >> 8;
+            green = (green * color[1]) >> 8;
+            blue = (blue * color[2]) >> 8;
+#else
+            red = (red * red_channel[loc]) >> 8;
+            green = (green * green_channel[loc]) >> 8;
+            blue = (blue * blue_channel[loc]) >> 8;
+#endif
+
+            mapped = SDL_MapRGBA(screen->format, red, green, blue, alpha);
+            switch(bpp) {
+              case 1:
+                *pixel = mapped;
+                break;
+              case 2:
+                *(Uint16 *)pixel = mapped;
+                break;
+              case 3:
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-            mapped |= pixel[0] << 16;
-            mapped |= pixel[1] << 8;
-            mapped |= pixel[2] << 0;
+                pixel[0] = (mapped >> 16) & 0xff;
+                pixel[1] = (mapped >> 8) & 0xff;
+                pixel[2] = (mapped >> 0) & 0xff;
 #else
-            mapped |= pixel[0] << 0;
-            mapped |= pixel[1] << 8;
-            mapped |= pixel[2] << 16;
+                pixel[0] = (mapped >> 0) & 0xff;
+                pixel[1] = (mapped >> 8) & 0xff;
+                pixel[2] = (mapped >> 16) & 0xff;
 #endif
-            break;
-          case 4:
-            mapped = *(Uint32 *)pixel;
-            break;
+                break;
+              case 4:
+                *(Uint32 *)pixel = mapped;
+                break;
+            }
+          }
+          pixel += screen->pitch - LIGHTMAP_DIV * bpp;
         }
-        Uint8 red, green, blue, alpha;
-        SDL_GetRGBA(mapped, src->format, &red, &green, &blue, &alpha);
-
-        if(red != 0)
-        {
-          int redsum = red_channel[loc] + (red * alpha >> 8);
-          red_channel[loc] = redsum & ~0xff ? 0xff : redsum;
-        }
-        if(green != 0)
-        {
-          int greensum = green_channel[loc] + (green * alpha >> 8);
-          green_channel[loc] = greensum & ~0xff ? 0xff : greensum;
-        }
-        if(blue != 0)
-        {
-          int bluesum = blue_channel[loc] + (blue * alpha >> 8);
-          blue_channel[loc] = bluesum & ~0xff ? 0xff : bluesum;
-        }
       }
-      pixel += src->pitch - src_rect->w * bpp;
-      loc += width - src_rect->w;
+      div_pixel += (screen->pitch - width * bpp) * LIGHTMAP_DIV;
     }
-    if(SDL_MUSTLOCK(src))
+    if(SDL_MUSTLOCK(screen))
     {
-      SDL_UnlockSurface(src);
+      SDL_UnlockSurface(screen);
     }
-  }*/
+  }
+}
 
-  void
-  Lightmap::draw_surface(const DrawingRequest& request)
+void Lightmap::light_blit(SDL_Surface *src, SDL_Rect *src_rect, int dstx, int dsty)
+{
+  dstx /= LIGHTMAP_DIV;
+  dsty /= LIGHTMAP_DIV;
+  int srcx = src_rect->x / LIGHTMAP_DIV;
+  int srcy = src_rect->y / LIGHTMAP_DIV;
+  int blit_width = src_rect->w / LIGHTMAP_DIV;
+  int blit_height = src_rect->h / LIGHTMAP_DIV;
+  int bpp = src->format->BytesPerPixel;
+  if(SDL_MUSTLOCK(src))
   {
-    if((request.color.red == 0.0 && request.color.green == 0.0 && request.color.blue == 0.0) || request.color.alpha == 0.0 || request.alpha == 0.0)
-    {
-      return;
-    }
-    //FIXME: support parameters request.alpha, request.angle, request.blend
- 
-    const Surface* surface = (const Surface*) request.request_data;
-    SDL::Texture *sdltexture = dynamic_cast<SDL::Texture *>(surface->get_texture());
-    SDL::SurfaceData *surface_data = reinterpret_cast<SDL::SurfaceData *>(surface->get_surface_data());
+    SDL_LockSurface(src);
+  }
+  Uint8 *pixel = (Uint8 *) src->pixels + srcy * src->pitch + srcx * bpp;
+  int loc = dsty * width + dstx;
+  for(int y = 0;y < blit_height;y++) {
+    for(int x = 0;x < blit_width;x++, pixel += bpp * LIGHTMAP_DIV, loc++) {
+      if(x + dstx < 0 || y + dsty < 0 || x + dstx >= width || y + dsty >= height)
+      {
+        continue;
+      }
+      if(red_channel[loc] == 0xff && green_channel[loc] == 0xff && blue_channel[loc] == 0xff)
+      {
+        continue;
+      }
 
-    DrawingEffect effect = request.drawing_effect;
-    if (surface->get_flipx()) effect = HORIZONTAL_FLIP;
+      Uint32 mapped = 0;
+      switch(bpp) {
+        case 1:
+          mapped = *pixel;
+          break;
+        case 2:
+          mapped = *(Uint16 *)pixel;
+          break;
+        case 3:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+          mapped |= pixel[0] << 16;
+          mapped |= pixel[1] << 8;
+          mapped |= pixel[2] << 0;
+#else
+          mapped |= pixel[0] << 0;
+          mapped |= pixel[1] << 8;
+          mapped |= pixel[2] << 16;
+#endif
+          break;
+        case 4:
+          mapped = *(Uint32 *)pixel;
+          break;
+      }
+      Uint8 red, green, blue, alpha;
+      SDL_GetRGBA(mapped, src->format, &red, &green, &blue, &alpha);
 
-    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;
+      if(red != 0)
+      {
+        int redsum = red_channel[loc] + (red * alpha >> 8);
+        red_channel[loc] = redsum & ~0xff ? 0xff : redsum;
+      }
+      if(green != 0)
+      {
+        int greensum = green_channel[loc] + (green * alpha >> 8);
+        green_channel[loc] = greensum & ~0xff ? 0xff : greensum;
+      }
+      if(blue != 0)
+      {
+        int bluesum = blue_channel[loc] + (blue * alpha >> 8);
+        blue_channel[loc] = bluesum & ~0xff ? 0xff : bluesum;
+      }
     }
+    pixel += (src->pitch - blit_width * bpp) * LIGHTMAP_DIV;
+    loc += width - blit_width;
+  }
+  if(SDL_MUSTLOCK(src))
+  {
+    SDL_UnlockSurface(src);
+  }
+}
 
-    SDL_Rect *src_rect = surface_data->get_src_rect(effect);
-    int dstx = (int) request.pos.x * numerator / denominator;
-    int dsty = (int) request.pos.y * numerator / denominator;
-    light_blit(transform, src_rect, dstx, dsty);
+/*void Lightmap::light_blit(SDL_Surface *src, SDL_Rect *src_rect, int dstx, int dsty)
+  {
+  int bpp = src->format->BytesPerPixel;
+  if(SDL_MUSTLOCK(src))
+  {
+  SDL_LockSurface(src);
   }
+  Uint8 *pixel = (Uint8 *) src->pixels + src_rect->y * src->pitch + src_rect->x * bpp;
+  int loc = dsty * width + dstx;
+  for(int y = 0;y < src_rect->h;y++) {
+  for(int x = 0;x < src_rect->w;x++, pixel += bpp, loc++) {
+  if(x + dstx < 0 || y + dsty < 0 || x + dstx >= width || y + dsty >= height)
+  {
+  continue;
+  }
+  if(red_channel[loc] == 0xff && green_channel[loc] == 0xff && blue_channel[loc] == 0xff)
+  {
+  continue;
+  }
 
-  void
-  Lightmap::draw_surface_part(const DrawingRequest& request)
+  Uint32 mapped = 0;
+  switch(bpp) {
+  case 1:
+  mapped = *pixel;
+  break;
+  case 2:
+  mapped = *(Uint16 *)pixel;
+  break;
+  case 3:
+  #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+  mapped |= pixel[0] << 16;
+  mapped |= pixel[1] << 8;
+  mapped |= pixel[2] << 0;
+  #else
+  mapped |= pixel[0] << 0;
+  mapped |= pixel[1] << 8;
+  mapped |= pixel[2] << 16;
+  #endif
+  break;
+  case 4:
+  mapped = *(Uint32 *)pixel;
+  break;
+  }
+  Uint8 red, green, blue, alpha;
+  SDL_GetRGBA(mapped, src->format, &red, &green, &blue, &alpha);
+
+  if(red != 0)
   {
-    const SurfacePartRequest* surfacepartrequest
-      = (SurfacePartRequest*) request.request_data;
+  int redsum = red_channel[loc] + (red * alpha >> 8);
+  red_channel[loc] = redsum & ~0xff ? 0xff : redsum;
+  }
+  if(green != 0)
+  {
+  int greensum = green_channel[loc] + (green * alpha >> 8);
+  green_channel[loc] = greensum & ~0xff ? 0xff : greensum;
+  }
+  if(blue != 0)
+  {
+  int bluesum = blue_channel[loc] + (blue * alpha >> 8);
+  blue_channel[loc] = bluesum & ~0xff ? 0xff : bluesum;
+  }
+  }
+  pixel += src->pitch - src_rect->w * bpp;
+  loc += width - src_rect->w;
+  }
+  if(SDL_MUSTLOCK(src))
+  {
+  SDL_UnlockSurface(src);
+  }
+  }*/
 
-    const Surface* surface = surfacepartrequest->surface;
-    SDL::Texture *sdltexture = dynamic_cast<SDL::Texture *>(surface->get_texture());
+void
+Lightmap::draw_surface(const DrawingRequest& request)
+{
+  if((request.color.red == 0.0 && request.color.green == 0.0 && request.color.blue == 0.0) || request.color.alpha == 0.0 || request.alpha == 0.0)
+  {
+    return;
+  }
+  //FIXME: support parameters request.alpha, request.angle, request.blend
+ 
+  const Surface* surface = (const Surface*) request.request_data;
+  SDL::Texture *sdltexture = dynamic_cast<SDL::Texture *>(surface->get_texture());
+  SDL::SurfaceData *surface_data = reinterpret_cast<SDL::SurfaceData *>(surface->get_surface_data());
 
-    DrawingEffect effect = request.drawing_effect;
-    if (surface->get_flipx()) effect = HORIZONTAL_FLIP;
+  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;
-    }
+  // 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)
-    {
-      ox = sdltexture->get_texture_width() - surface->get_x() - (int) surfacepartrequest->size.x;
-    }
-    else
-    {
-      ox = surface->get_x();
-    }
-    if (effect == VERTICAL_FLIP)
-    {
-      oy = sdltexture->get_texture_height() - surface->get_y() - (int) surfacepartrequest->size.y;
-    }
-    else
-    {
-      oy = surface->get_y();
-    }
+  SDL_Rect *src_rect = surface_data->get_src_rect(effect);
+  int dstx = (int) request.pos.x * numerator / denominator;
+  int dsty = (int) request.pos.y * numerator / denominator;
+  light_blit(transform, src_rect, dstx, dsty);
+}
 
-    SDL_Rect src_rect;
-    src_rect.x = (ox + (int) surfacepartrequest->source.x) * numerator / denominator;
-    src_rect.y = (oy + (int) surfacepartrequest->source.y) * numerator / denominator;
-    src_rect.w = (int) surfacepartrequest->size.x * numerator / denominator;
-    src_rect.h = (int) surfacepartrequest->size.y * numerator / denominator;
-    int dstx = (int) request.pos.x * numerator / denominator;
-    int dsty = (int) request.pos.y * numerator / denominator;
-    light_blit(transform, &src_rect, dstx, dsty);
+void
+Lightmap::draw_surface_part(const DrawingRequest& request)
+{
+  const SurfacePartRequest* surfacepartrequest
+    = (SurfacePartRequest*) request.request_data;
+
+  const Surface* surface = surfacepartrequest->surface;
+  SDL::Texture *sdltexture = dynamic_cast<SDL::Texture *>(surface->get_texture());
+
+  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);
+
+  // get and check SDL_Surface
+  if (transform == 0) {
+    std::cerr << "Warning: Tried to draw NULL surface, skipped draw" << std::endl;
+    return;
   }
 
-  void
-  Lightmap::draw_gradient(const DrawingRequest& request)
+  int ox, oy;
+  if (effect == HORIZONTAL_FLIP)
   {
-    const GradientRequest* gradientrequest 
-      = (GradientRequest*) request.request_data;
-    const Color& top = gradientrequest->top;
-    const Color& bottom = gradientrequest->bottom;
+    ox = sdltexture->get_texture_width() - surface->get_x() - (int) surfacepartrequest->size.x;
+  }
+  else
+  {
+    ox = surface->get_x();
+  }
+  if (effect == VERTICAL_FLIP)
+  {
+    oy = sdltexture->get_texture_height() - surface->get_y() - (int) surfacepartrequest->size.y;
+  }
+  else
+  {
+    oy = surface->get_y();
+  }
 
-    int loc = 0;
-    for(int y = 0;y < height;++y)
-    {
-      Uint8 red = (Uint8)((((float)(top.red-bottom.red)/(0-height)) * y + top.red) * 255);
-      Uint8 green = (Uint8)((((float)(top.green-bottom.green)/(0-height)) * y + top.green) * 255);
-      Uint8 blue = (Uint8)((((float)(top.blue-bottom.blue)/(0-height)) * y + top.blue) * 255);
-      Uint8 alpha = (Uint8)((((float)(top.alpha-bottom.alpha)/(0-height)) * y + top.alpha) * 255);
-      for(int x = 0;x < width;x++, loc++) {
-        if(red != 0)
-        {
-          int redsum = red_channel[loc] + (red * alpha >> 8);
-          red_channel[loc] = redsum & ~0xff ? 0xff : redsum;
-        }
-        if(green != 0)
-        {
-          int greensum = green_channel[loc] + (green * alpha >> 8);
-          green_channel[loc] = greensum & ~0xff ? 0xff : greensum;
-        }
-        if(blue != 0)
-        {
-          int bluesum = blue_channel[loc] + (blue * alpha >> 8);
-          blue_channel[loc] = bluesum & ~0xff ? 0xff : bluesum;
-        }
+  SDL_Rect src_rect;
+  src_rect.x = (ox + (int) surfacepartrequest->source.x) * numerator / denominator;
+  src_rect.y = (oy + (int) surfacepartrequest->source.y) * numerator / denominator;
+  src_rect.w = (int) surfacepartrequest->size.x * numerator / denominator;
+  src_rect.h = (int) surfacepartrequest->size.y * numerator / denominator;
+  int dstx = (int) request.pos.x * numerator / denominator;
+  int dsty = (int) request.pos.y * numerator / denominator;
+  light_blit(transform, &src_rect, dstx, dsty);
+}
+
+void
+Lightmap::draw_gradient(const DrawingRequest& request)
+{
+  const GradientRequest* gradientrequest 
+    = (GradientRequest*) request.request_data;
+  const Color& top = gradientrequest->top;
+  const Color& bottom = gradientrequest->bottom;
+
+  int loc = 0;
+  for(int y = 0;y < height;++y)
+  {
+    Uint8 red = (Uint8)((((float)(top.red-bottom.red)/(0-height)) * y + top.red) * 255);
+    Uint8 green = (Uint8)((((float)(top.green-bottom.green)/(0-height)) * y + top.green) * 255);
+    Uint8 blue = (Uint8)((((float)(top.blue-bottom.blue)/(0-height)) * y + top.blue) * 255);
+    Uint8 alpha = (Uint8)((((float)(top.alpha-bottom.alpha)/(0-height)) * y + top.alpha) * 255);
+    for(int x = 0;x < width;x++, loc++) {
+      if(red != 0)
+      {
+        int redsum = red_channel[loc] + (red * alpha >> 8);
+        red_channel[loc] = redsum & ~0xff ? 0xff : redsum;
       }
+      if(green != 0)
+      {
+        int greensum = green_channel[loc] + (green * alpha >> 8);
+        green_channel[loc] = greensum & ~0xff ? 0xff : greensum;
+      }
+      if(blue != 0)
+      {
+        int bluesum = blue_channel[loc] + (blue * alpha >> 8);
+        blue_channel[loc] = bluesum & ~0xff ? 0xff : bluesum;
+      }
     }
   }
+}
 
-  void
-  Lightmap::draw_filled_rect(const DrawingRequest& request)
+void
+Lightmap::draw_filled_rect(const DrawingRequest& request)
+{
+  const FillRectRequest* fillrectrequest
+    = (FillRectRequest*) request.request_data;
+
+  int rect_x = (int) (request.pos.x * width / SCREEN_WIDTH);
+  int rect_y = (int) (request.pos.y * height / SCREEN_HEIGHT);
+  int rect_w = (int) (fillrectrequest->size.x * width / SCREEN_WIDTH);
+  int rect_h = (int) (fillrectrequest->size.y * height / SCREEN_HEIGHT);
+  Uint8 red = (Uint8) (fillrectrequest->color.red * fillrectrequest->color.alpha * 255);
+  Uint8 green = (Uint8) (fillrectrequest->color.green * fillrectrequest->color.alpha * 255);
+  Uint8 blue = (Uint8) (fillrectrequest->color.blue * fillrectrequest->color.alpha * 255);
+  if(red == 0 && green == 0 && blue == 0)
   {
-    const FillRectRequest* fillrectrequest
-      = (FillRectRequest*) request.request_data;
-
-    int rect_x = (int) (request.pos.x * width / SCREEN_WIDTH);
-    int rect_y = (int) (request.pos.y * height / SCREEN_HEIGHT);
-    int rect_w = (int) (fillrectrequest->size.x * width / SCREEN_WIDTH);
-    int rect_h = (int) (fillrectrequest->size.y * height / SCREEN_HEIGHT);
-    Uint8 red = (Uint8) (fillrectrequest->color.red * fillrectrequest->color.alpha * 255);
-    Uint8 green = (Uint8) (fillrectrequest->color.green * fillrectrequest->color.alpha * 255);
-    Uint8 blue = (Uint8) (fillrectrequest->color.blue * fillrectrequest->color.alpha * 255);
-    if(red == 0 && green == 0 && blue == 0)
-    {
-      return;
-    }
-    for(int y = rect_y;y < rect_y + rect_h;y++) {
-      for(int x = rect_x;x < rect_x + rect_w;x++) {
-        int loc = y * width + x;
-        if(red != 0)
-        {
-          int redsum = red_channel[loc] + red;
-          red_channel[loc] = redsum & ~0xff ? 0xff : redsum;
-        }
-        if(green != 0)
-        {
-          int greensum = green_channel[loc] + green;
-          green_channel[loc] = greensum & ~0xff ? 0xff : greensum;
-        }
-        if(blue != 0)
-        {
-          int bluesum = blue_channel[loc] + blue;
-          blue_channel[loc] = bluesum & ~0xff ? 0xff : bluesum;
-        }
+    return;
+  }
+  for(int y = rect_y;y < rect_y + rect_h;y++) {
+    for(int x = rect_x;x < rect_x + rect_w;x++) {
+      int loc = y * width + x;
+      if(red != 0)
+      {
+        int redsum = red_channel[loc] + red;
+        red_channel[loc] = redsum & ~0xff ? 0xff : redsum;
       }
+      if(green != 0)
+      {
+        int greensum = green_channel[loc] + green;
+        green_channel[loc] = greensum & ~0xff ? 0xff : greensum;
+      }
+      if(blue != 0)
+      {
+        int bluesum = blue_channel[loc] + blue;
+        blue_channel[loc] = bluesum & ~0xff ? 0xff : bluesum;
+      }
     }
   }
+}
 
-  void
-  Lightmap::get_light(const DrawingRequest& request) const
-  {
-    const GetLightRequest* getlightrequest 
-      = (GetLightRequest*) request.request_data;
+void
+Lightmap::get_light(const DrawingRequest& request) const
+{
+  const GetLightRequest* getlightrequest 
+    = (GetLightRequest*) request.request_data;
 
-    int x = (int) (request.pos.x * width / SCREEN_WIDTH);
-    int y = (int) (request.pos.y * height / SCREEN_HEIGHT);
-    int loc = y * width + x;
-    *(getlightrequest->color_ptr) = Color(((float)red_channel[loc])/255, ((float)green_channel[loc])/255, ((float)blue_channel[loc])/255);
-  }
+  int x = (int) (request.pos.x * width / SCREEN_WIDTH);
+  int y = (int) (request.pos.y * height / SCREEN_HEIGHT);
+  int loc = y * width + x;
+  *(getlightrequest->color_ptr) = Color(((float)red_channel[loc])/255, ((float)green_channel[loc])/255, ((float)blue_channel[loc])/255);
 }
+}
 
 /* EOF */

Modified: branches/supertux-milestone2-grumbel/src/video/sdl/sdl_lightmap.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/sdl/sdl_lightmap.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/sdl/sdl_lightmap.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -23,33 +23,33 @@
 struct DrawingRequest;
 
 namespace SDL {
-  class Lightmap : public ::Lightmap
-  {
-  public:
-    Lightmap();
-    ~Lightmap();
+class Lightmap : public ::Lightmap
+{
+public:
+  Lightmap();
+  ~Lightmap();
 
-    void start_draw(const Color &ambient_color);
-    void end_draw();
-    void do_draw();
-    void draw_surface(const DrawingRequest& request);
-    void draw_surface_part(const DrawingRequest& request);
-    void draw_text(const DrawingRequest& request);
-    void draw_gradient(const DrawingRequest& request);
-    void draw_filled_rect(const DrawingRequest& request);
-    void get_light(const DrawingRequest& request) const;
+  void start_draw(const Color &ambient_color);
+  void end_draw();
+  void do_draw();
+  void draw_surface(const DrawingRequest& request);
+  void draw_surface_part(const DrawingRequest& request);
+  void draw_text(const DrawingRequest& request);
+  void draw_gradient(const DrawingRequest& request);
+  void draw_filled_rect(const DrawingRequest& request);
+  void get_light(const DrawingRequest& request) const;
 
-  private:
-    SDL_Surface* screen;
-    Uint8 *red_channel;
-    Uint8 *blue_channel;
-    Uint8 *green_channel;
-    int width, height;
-    int numerator, denominator;
-    int LIGHTMAP_DIV;
+private:
+  SDL_Surface* screen;
+  Uint8 *red_channel;
+  Uint8 *blue_channel;
+  Uint8 *green_channel;
+  int width, height;
+  int numerator, denominator;
+  int LIGHTMAP_DIV;
 
-    void light_blit(SDL_Surface *src, SDL_Rect *src_rect, int dstx, int dsty);
-  };
+  void light_blit(SDL_Surface *src, SDL_Rect *src_rect, int dstx, int dsty);
+};
 }
 
 #endif

Modified: branches/supertux-milestone2-grumbel/src/video/sdl/sdl_renderer.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/sdl/sdl_renderer.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/sdl/sdl_renderer.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -26,350 +26,321 @@
 
 namespace
 {
-  SDL_Surface *apply_alpha(SDL_Surface *src, float alpha_factor)
+SDL_Surface *apply_alpha(SDL_Surface *src, float alpha_factor)
+{
+  // FIXME: This is really slow
+  assert(src->format->Amask);
+  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))
   {
-    // FIXME: This is really slow
-    assert(src->format->Amask);
-    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;
-        Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + x * bpp;
-        Uint32 mapped = 0;
-        switch(bpp) {
-          case 1:
-            mapped = *srcpixel;
-            break;
-          case 2:
-            mapped = *(Uint16 *)srcpixel;
-            break;
-          case 3:
+    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;
+      Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + x * bpp;
+      Uint32 mapped = 0;
+      switch(bpp) {
+        case 1:
+          mapped = *srcpixel;
+          break;
+        case 2:
+          mapped = *(Uint16 *)srcpixel;
+          break;
+        case 3:
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-            mapped |= srcpixel[0] << 16;
-            mapped |= srcpixel[1] << 8;
-            mapped |= srcpixel[2] << 0;
+          mapped |= srcpixel[0] << 16;
+          mapped |= srcpixel[1] << 8;
+          mapped |= srcpixel[2] << 0;
 #else
-            mapped |= srcpixel[0] << 0;
-            mapped |= srcpixel[1] << 8;
-            mapped |= srcpixel[2] << 16;
+          mapped |= srcpixel[0] << 0;
+          mapped |= srcpixel[1] << 8;
+          mapped |= srcpixel[2] << 16;
 #endif
-            break;
-          case 4:
-            mapped = *(Uint32 *)srcpixel;
-            break;
-        }
-        Uint8 r, g, b, a;
-        SDL_GetRGBA(mapped, src->format, &r, &g, &b, &a);
-        mapped = SDL_MapRGBA(dst->format, r, g, b, (a * alpha) >> 8);
-        switch(bpp) {
-          case 1:
-            *dstpixel = mapped;
-            break;
-          case 2:
-            *(Uint16 *)dstpixel = mapped;
-            break;
-          case 3:
+          break;
+        case 4:
+          mapped = *(Uint32 *)srcpixel;
+          break;
+      }
+      Uint8 r, g, b, a;
+      SDL_GetRGBA(mapped, src->format, &r, &g, &b, &a);
+      mapped = SDL_MapRGBA(dst->format, r, g, b, (a * alpha) >> 8);
+      switch(bpp) {
+        case 1:
+          *dstpixel = mapped;
+          break;
+        case 2:
+          *(Uint16 *)dstpixel = mapped;
+          break;
+        case 3:
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-            dstpixel[0] = (mapped >> 16) & 0xff;
-            dstpixel[1] = (mapped >> 8) & 0xff;
-            dstpixel[2] = (mapped >> 0) & 0xff;
+          dstpixel[0] = (mapped >> 16) & 0xff;
+          dstpixel[1] = (mapped >> 8) & 0xff;
+          dstpixel[2] = (mapped >> 0) & 0xff;
 #else
-            dstpixel[0] = (mapped >> 0) & 0xff;
-            dstpixel[1] = (mapped >> 8) & 0xff;
-            dstpixel[2] = (mapped >> 16) & 0xff;
+          dstpixel[0] = (mapped >> 0) & 0xff;
+          dstpixel[1] = (mapped >> 8) & 0xff;
+          dstpixel[2] = (mapped >> 16) & 0xff;
 #endif
-            break;
-          case 4:
-            *(Uint32 *)dstpixel = mapped;
-            break;
-        }
+          break;
+        case 4:
+          *(Uint32 *)dstpixel = mapped;
+          break;
       }
     }
-    if(SDL_MUSTLOCK(dst))
-    {
-      SDL_UnlockSurface(dst);
-    }
-    if(SDL_MUSTLOCK(src))
-    {
-      SDL_UnlockSurface(src);
-    }
-    return dst;
   }
+  if(SDL_MUSTLOCK(dst))
+  {
+    SDL_UnlockSurface(dst);
+  }
+  if(SDL_MUSTLOCK(src))
+  {
+    SDL_UnlockSurface(src);
+  }
+  return dst;
 }
+}
 
 namespace SDL {
-  Renderer::Renderer()
-  {
-    ::Renderer::instance_ = this;
+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;
-    log_info << "Hardware to hardware blits with colorkey are " << (info->blit_hw_CC ? "" : "not ") << "accelerated." << std::endl;
-    log_info << "Hardware to hardware blits with alpha are " << (info->blit_hw_A ? "" : "not ") << "accelerated." << std::endl;
-    log_info << "Software to hardware blits are " << (info->blit_sw ? "" : "not ") << "accelerated." << std::endl;
-    log_info << "Software to hardware blits with colorkey are " << (info->blit_sw_CC ? "" : "not ") << "accelerated." << std::endl;
-    log_info << "Software to hardware blits with alpha are " << (info->blit_sw_A ? "" : "not ") << "accelerated." << std::endl;
-    log_info << "Color fills are " << (info->blit_fill ? "" : "not ") << "accelerated." << std::endl;
+  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;
+  log_info << "Hardware to hardware blits with colorkey are " << (info->blit_hw_CC ? "" : "not ") << "accelerated." << std::endl;
+  log_info << "Hardware to hardware blits with alpha are " << (info->blit_hw_A ? "" : "not ") << "accelerated." << std::endl;
+  log_info << "Software to hardware blits are " << (info->blit_sw ? "" : "not ") << "accelerated." << std::endl;
+  log_info << "Software to hardware blits with colorkey are " << (info->blit_sw_CC ? "" : "not ") << "accelerated." << std::endl;
+  log_info << "Software to hardware blits with alpha are " << (info->blit_sw_A ? "" : "not ") << "accelerated." << std::endl;
+  log_info << "Color fills are " << (info->blit_fill ? "" : "not ") << "accelerated." << std::endl;
 
-    int flags = SDL_SWSURFACE | SDL_ANYFORMAT;
-    if(config->use_fullscreen)
-      flags |= SDL_FULLSCREEN;
+  int flags = SDL_SWSURFACE | SDL_ANYFORMAT;
+  if(config->use_fullscreen)
+    flags |= SDL_FULLSCREEN;
     
-    int width  = 800; //FIXME: config->screenwidth;
-    int height = 600; //FIXME: config->screenheight;
+  int width  = 800; //FIXME: config->screenwidth;
+  int height = 600; //FIXME: config->screenheight;
 
-    screen = SDL_SetVideoMode(width, height, 0, flags);
-    if(screen == 0) {
-      std::stringstream msg;
-      msg << "Couldn't set video mode (" << width << "x" << height
-          << "): " << SDL_GetError();
-      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)
-    {
-      numerator = config->screenwidth;
-      denominator = SCREEN_WIDTH;
-    }
-    else
-    {
-      numerator = config->screenheight;
-      denominator = SCREEN_HEIGHT;
-    }
-    */
-    if(texture_manager == 0)
-      texture_manager = new TextureManager();
+  screen = SDL_SetVideoMode(width, height, 0, flags);
+  if(screen == 0) {
+    std::stringstream msg;
+    msg << "Couldn't set video mode (" << width << "x" << height
+        << "): " << SDL_GetError();
+    throw std::runtime_error(msg.str());
   }
 
-  Renderer::~Renderer()
-  {
-  }
+  numerator   = 1;
+  denominator = 1;
+  /* FIXME: 
+     float xfactor = (float) config->screenwidth / SCREEN_WIDTH;
+     float yfactor = (float) config->screenheight / SCREEN_HEIGHT;
+     if(xfactor < yfactor)
+     {
+     numerator = config->screenwidth;
+     denominator = SCREEN_WIDTH;
+     }
+     else
+     {
+     numerator = config->screenheight;
+     denominator = SCREEN_HEIGHT;
+     }
+  */
+  if(texture_manager == 0)
+    texture_manager = new TextureManager();
+}
 
-  void
-  Renderer::draw_surface(const DrawingRequest& request)
-  {
-    //FIXME: support parameters request.alpha, request.angle, request.blend
-    const Surface* surface = (const Surface*) request.request_data;
-    SDL::Texture *sdltexture = dynamic_cast<SDL::Texture *>(surface->get_texture());
-    SDL::SurfaceData *surface_data = reinterpret_cast<SDL::SurfaceData *>(surface->get_surface_data());
+Renderer::~Renderer()
+{
+}
 
-    DrawingEffect effect = request.drawing_effect;
-    if (surface->get_flipx()) effect = HORIZONTAL_FLIP;
+void
+Renderer::draw_surface(const DrawingRequest& request)
+{
+  //FIXME: support parameters request.alpha, request.angle, request.blend
+  const Surface* surface = (const Surface*) request.request_data;
+  SDL::Texture *sdltexture = dynamic_cast<SDL::Texture *>(surface->get_texture());
+  SDL::SurfaceData *surface_data = reinterpret_cast<SDL::SurfaceData *>(surface->get_surface_data());
 
-    SDL_Surface *transform = sdltexture->get_transform(request.color, effect);
+  DrawingEffect effect = request.drawing_effect;
+  if (surface->get_flipx()) effect = HORIZONTAL_FLIP;
 
-    // get and check SDL_Surface
-    if (transform == 0) {
-      std::cerr << "Warning: Tried to draw NULL surface, skipped draw" << std::endl;
-      return;
-    }
+  SDL_Surface *transform = sdltexture->get_transform(request.color, effect);
 
-    SDL_Rect *src_rect = surface_data->get_src_rect(effect);
-    SDL_Rect dst_rect;
-    dst_rect.x = (int) request.pos.x * numerator / denominator;
-    dst_rect.y = (int) request.pos.y * numerator / denominator;
+  // get and check SDL_Surface
+  if (transform == 0) {
+    std::cerr << "Warning: Tried to draw NULL surface, skipped draw" << std::endl;
+    return;
+  }
 
-    Uint8 alpha = 0;
-    if(request.alpha != 1.0)
+  SDL_Rect *src_rect = surface_data->get_src_rect(effect);
+  SDL_Rect dst_rect;
+  dst_rect.x = (int) request.pos.x * numerator / denominator;
+  dst_rect.y = (int) request.pos.y * numerator / denominator;
+
+  Uint8 alpha = 0;
+  if(request.alpha != 1.0)
+  {
+    if(!transform->format->Amask)
     {
-      if(!transform->format->Amask)
+      if(transform->flags & SDL_SRCALPHA)
       {
-        if(transform->flags & SDL_SRCALPHA)
-        {
-          alpha = transform->format->alpha;
-        }
-        else
-        {
-          alpha = 255;
-        }
-        SDL_SetAlpha(transform, SDL_SRCALPHA, (Uint8) (request.alpha * alpha));
+        alpha = transform->format->alpha;
       }
-      /*else
+      else
       {
-        transform = apply_alpha(transform, request.alpha);
+        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);
+  SDL_BlitSurface(transform, src_rect, screen, &dst_rect);
 
-    if(request.alpha != 1.0)
+  if(request.alpha != 1.0)
+  {
+    if(!transform->format->Amask)
     {
-      if(!transform->format->Amask)
+      if(alpha == 255)
       {
-        if(alpha == 255)
-        {
-          SDL_SetAlpha(transform, SDL_RLEACCEL, 0);
-        }
-        else
-        {
-          SDL_SetAlpha(transform, SDL_SRCALPHA | SDL_RLEACCEL, alpha);
-        }
+        SDL_SetAlpha(transform, SDL_RLEACCEL, 0);
       }
-      /*else
+      else
       {
-        SDL_FreeSurface(transform);
+        SDL_SetAlpha(transform, SDL_SRCALPHA | SDL_RLEACCEL, alpha);
+      }
+    }
+    /*else
+      {
+      SDL_FreeSurface(transform);
       }*/
-    }
   }
+}
 
-  void
-  Renderer::draw_surface_part(const DrawingRequest& request)
-  {
-    const SurfacePartRequest* surfacepartrequest
-      = (SurfacePartRequest*) request.request_data;
+void
+Renderer::draw_surface_part(const DrawingRequest& request)
+{
+  const SurfacePartRequest* surfacepartrequest
+    = (SurfacePartRequest*) request.request_data;
 
-    const Surface* surface = surfacepartrequest->surface;
-    SDL::Texture *sdltexture = dynamic_cast<SDL::Texture *>(surface->get_texture());
+  const Surface* surface = surfacepartrequest->surface;
+  SDL::Texture *sdltexture = dynamic_cast<SDL::Texture *>(surface->get_texture());
 
-    DrawingEffect effect = request.drawing_effect;
-    if (surface->get_flipx()) effect = HORIZONTAL_FLIP;
+  DrawingEffect effect = request.drawing_effect;
+  if (surface->get_flipx()) effect = HORIZONTAL_FLIP;
 
-    SDL_Surface *transform = sdltexture->get_transform(request.color, 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;
-    }
+  // 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)
-    {
-      ox = sdltexture->get_texture_width() - surface->get_x() - (int) surfacepartrequest->size.x;
-    }
-    else
-    {
-      ox = surface->get_x();
-    }
-    if (effect == VERTICAL_FLIP)
-    {
-      oy = sdltexture->get_texture_height() - surface->get_y() - (int) surfacepartrequest->size.y;
-    }
-    else
-    {
-      oy = surface->get_y();
-    }
+  int ox, oy;
+  if (effect == HORIZONTAL_FLIP)
+  {
+    ox = sdltexture->get_texture_width() - surface->get_x() - (int) surfacepartrequest->size.x;
+  }
+  else
+  {
+    ox = surface->get_x();
+  }
+  if (effect == VERTICAL_FLIP)
+  {
+    oy = sdltexture->get_texture_height() - surface->get_y() - (int) surfacepartrequest->size.y;
+  }
+  else
+  {
+    oy = surface->get_y();
+  }
 
-    SDL_Rect src_rect;
-    src_rect.x = (ox + (int) surfacepartrequest->source.x) * numerator / denominator;
-    src_rect.y = (oy + (int) surfacepartrequest->source.y) * numerator / denominator;
-    src_rect.w = (int) surfacepartrequest->size.x * numerator / denominator;
-    src_rect.h = (int) surfacepartrequest->size.y * numerator / denominator;
+  SDL_Rect src_rect;
+  src_rect.x = (ox + (int) surfacepartrequest->source.x) * numerator / denominator;
+  src_rect.y = (oy + (int) surfacepartrequest->source.y) * numerator / denominator;
+  src_rect.w = (int) surfacepartrequest->size.x * numerator / denominator;
+  src_rect.h = (int) surfacepartrequest->size.y * numerator / denominator;
 
-    SDL_Rect dst_rect;
-    dst_rect.x = (int) request.pos.x * numerator / denominator;
-    dst_rect.y = (int) request.pos.y * numerator / denominator;
+  SDL_Rect dst_rect;
+  dst_rect.x = (int) request.pos.x * numerator / denominator;
+  dst_rect.y = (int) request.pos.y * numerator / denominator;
 
-    Uint8 alpha = 0;
-    if(request.alpha != 1.0)
+  Uint8 alpha = 0;
+  if(request.alpha != 1.0)
+  {
+    if(!transform->format->Amask)
     {
-      if(!transform->format->Amask)
+      if(transform->flags & SDL_SRCALPHA)
       {
-        if(transform->flags & SDL_SRCALPHA)
-        {
-          alpha = transform->format->alpha;
-        }
-        else
-        {
-          alpha = 255;
-        }
-        SDL_SetAlpha(transform, SDL_SRCALPHA, (Uint8) (request.alpha * alpha));
+        alpha = transform->format->alpha;
       }
-      /*else
+      else
       {
-        transform = apply_alpha(transform, request.alpha);
+        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);
+  SDL_BlitSurface(transform, &src_rect, screen, &dst_rect);
 
-    if(request.alpha != 1.0)
+  if(request.alpha != 1.0)
+  {
+    if(!transform->format->Amask)
     {
-      if(!transform->format->Amask)
+      if(alpha == 255)
       {
-        if(alpha == 255)
-        {
-          SDL_SetAlpha(transform, SDL_RLEACCEL, 0);
-        }
-        else
-        {
-          SDL_SetAlpha(transform, SDL_SRCALPHA | SDL_RLEACCEL, alpha);
-        }
+        SDL_SetAlpha(transform, SDL_RLEACCEL, 0);
       }
-      /*else
+      else
       {
-        SDL_FreeSurface(transform);
+        SDL_SetAlpha(transform, SDL_SRCALPHA | SDL_RLEACCEL, alpha);
+      }
+    }
+    /*else
+      {
+      SDL_FreeSurface(transform);
       }*/
-    }
   }
+}
 
-  void
-  Renderer::draw_gradient(const DrawingRequest& request)
-  {
-    const GradientRequest* gradientrequest 
-      = (GradientRequest*) request.request_data;
-    const Color& top = gradientrequest->top;
-    const Color& bottom = gradientrequest->bottom;
+void
+Renderer::draw_gradient(const DrawingRequest& request)
+{
+  const GradientRequest* gradientrequest 
+    = (GradientRequest*) request.request_data;
+  const Color& top = gradientrequest->top;
+  const Color& bottom = gradientrequest->bottom;
 
-    for(int y = 0;y < screen->h;++y)
-    {
-      Uint8 r = (Uint8)((((float)(top.red-bottom.red)/(0-screen->h)) * y + top.red) * 255);
-      Uint8 g = (Uint8)((((float)(top.green-bottom.green)/(0-screen->h)) * y + top.green) * 255);
-      Uint8 b = (Uint8)((((float)(top.blue-bottom.blue)/(0-screen->h)) * y + top.blue) * 255);
-      Uint8 a = (Uint8)((((float)(top.alpha-bottom.alpha)/(0-screen->h)) * y + top.alpha) * 255);
-      Uint32 color = SDL_MapRGB(screen->format, r, g, b);
-
-      SDL_Rect rect;
-      rect.x = 0;
-      rect.y = y;
-      rect.w = screen->w;
-      rect.h = 1;
-
-      if(a == SDL_ALPHA_OPAQUE) {
-        SDL_FillRect(screen, &rect, color);
-      } else if(a != SDL_ALPHA_TRANSPARENT) {
-        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 | SDL_RLEACCEL, a);
-        SDL_BlitSurface(temp, 0, screen, &rect);
-        SDL_FreeSurface(temp);
-      }
-    }
-  }
-
-  void
-  Renderer::draw_filled_rect(const DrawingRequest& request)
+  for(int y = 0;y < screen->h;++y)
   {
-    const FillRectRequest* fillrectrequest
-      = (FillRectRequest*) request.request_data;
+    Uint8 r = (Uint8)((((float)(top.red-bottom.red)/(0-screen->h)) * y + top.red) * 255);
+    Uint8 g = (Uint8)((((float)(top.green-bottom.green)/(0-screen->h)) * y + top.green) * 255);
+    Uint8 b = (Uint8)((((float)(top.blue-bottom.blue)/(0-screen->h)) * y + top.blue) * 255);
+    Uint8 a = (Uint8)((((float)(top.alpha-bottom.alpha)/(0-screen->h)) * y + top.alpha) * 255);
+    Uint32 color = SDL_MapRGB(screen->format, r, g, b);
 
     SDL_Rect rect;
-    rect.x = (Sint16)request.pos.x * screen->w / SCREEN_WIDTH;
-    rect.y = (Sint16)request.pos.y * screen->h / SCREEN_HEIGHT;
-    rect.w = (Uint16)fillrectrequest->size.x * screen->w / SCREEN_WIDTH;
-    rect.h = (Uint16)fillrectrequest->size.y * screen->h / SCREEN_HEIGHT;
-    Uint8 r = static_cast<Uint8>(fillrectrequest->color.red * 255);
-    Uint8 g = static_cast<Uint8>(fillrectrequest->color.green * 255);
-    Uint8 b = static_cast<Uint8>(fillrectrequest->color.blue * 255);
-    Uint8 a = static_cast<Uint8>(fillrectrequest->color.alpha * 255);
-    Uint32 color = SDL_MapRGB(screen->format, r, g, b);
+    rect.x = 0;
+    rect.y = y;
+    rect.w = screen->w;
+    rect.h = 1;
+
     if(a == SDL_ALPHA_OPAQUE) {
       SDL_FillRect(screen, &rect, color);
     } else if(a != SDL_ALPHA_TRANSPARENT) {
@@ -381,52 +352,81 @@
       SDL_FreeSurface(temp);
     }
   }
+}
 
-  void
-  Renderer::draw_inverse_ellipse(const DrawingRequest&)
-  {
+void
+Renderer::draw_filled_rect(const DrawingRequest& request)
+{
+  const FillRectRequest* fillrectrequest
+    = (FillRectRequest*) request.request_data;
+
+  SDL_Rect rect;
+  rect.x = (Sint16)request.pos.x * screen->w / SCREEN_WIDTH;
+  rect.y = (Sint16)request.pos.y * screen->h / SCREEN_HEIGHT;
+  rect.w = (Uint16)fillrectrequest->size.x * screen->w / SCREEN_WIDTH;
+  rect.h = (Uint16)fillrectrequest->size.y * screen->h / SCREEN_HEIGHT;
+  Uint8 r = static_cast<Uint8>(fillrectrequest->color.red * 255);
+  Uint8 g = static_cast<Uint8>(fillrectrequest->color.green * 255);
+  Uint8 b = static_cast<Uint8>(fillrectrequest->color.blue * 255);
+  Uint8 a = static_cast<Uint8>(fillrectrequest->color.alpha * 255);
+  Uint32 color = SDL_MapRGB(screen->format, r, g, b);
+  if(a == SDL_ALPHA_OPAQUE) {
+    SDL_FillRect(screen, &rect, color);
+  } else if(a != SDL_ALPHA_TRANSPARENT) {
+    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 | SDL_RLEACCEL, a);
+    SDL_BlitSurface(temp, 0, screen, &rect);
+    SDL_FreeSurface(temp);
   }
+}
 
-  void 
-  Renderer::do_take_screenshot()
-  {
-    // [Christoph] TODO: Yes, this method also takes care of the actual disk I/O. Split it?
+void
+Renderer::draw_inverse_ellipse(const DrawingRequest&)
+{
+}
 
-    SDL_Surface *screen = SDL_GetVideoSurface();
+void 
+Renderer::do_take_screenshot()
+{
+  // [Christoph] TODO: Yes, this method also takes care of the actual disk I/O. Split it?
 
-    // save screenshot
-    static const std::string writeDir = PHYSFS_getWriteDir();
-    static const std::string dirSep = PHYSFS_getDirSeparator();
-    static const std::string baseName = "screenshot";
-    static const std::string fileExt = ".bmp";
-    std::string fullFilename;
-    for (int num = 0; num < 1000; num++) {
-      std::ostringstream oss;
-      oss << baseName;
-      oss << std::setw(3) << std::setfill('0') << num;
-      oss << fileExt;
-      std::string fileName = oss.str();
-      fullFilename = writeDir + dirSep + fileName;
-      if (!PHYSFS_exists(fileName.c_str())) {
-        SDL_SaveBMP(screen, fullFilename.c_str());
-        log_debug << "Wrote screenshot to \"" << fullFilename << "\"" << std::endl;
-        return;
-      }
+  SDL_Surface *screen = SDL_GetVideoSurface();
+
+  // save screenshot
+  static const std::string writeDir = PHYSFS_getWriteDir();
+  static const std::string dirSep = PHYSFS_getDirSeparator();
+  static const std::string baseName = "screenshot";
+  static const std::string fileExt = ".bmp";
+  std::string fullFilename;
+  for (int num = 0; num < 1000; num++) {
+    std::ostringstream oss;
+    oss << baseName;
+    oss << std::setw(3) << std::setfill('0') << num;
+    oss << fileExt;
+    std::string fileName = oss.str();
+    fullFilename = writeDir + dirSep + fileName;
+    if (!PHYSFS_exists(fileName.c_str())) {
+      SDL_SaveBMP(screen, fullFilename.c_str());
+      log_debug << "Wrote screenshot to \"" << fullFilename << "\"" << std::endl;
+      return;
     }
-    log_warning << "Did not save screenshot, because all files up to \"" << fullFilename << "\" already existed" << std::endl;
   }
+  log_warning << "Did not save screenshot, because all files up to \"" << fullFilename << "\" already existed" << std::endl;
+}
 
-  void
-  Renderer::flip()
-  {
-    SDL_Flip(screen);
-  }
+void
+Renderer::flip()
+{
+  SDL_Flip(screen);
+}
 
-  void
-  Renderer::resize(int, int)
-  {
+void
+Renderer::resize(int, int)
+{
     
-  }
 }
+}
 
 /* EOF */

Modified: branches/supertux-milestone2-grumbel/src/video/sdl/sdl_renderer.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/sdl/sdl_renderer.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/sdl/sdl_renderer.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -22,26 +22,26 @@
 #include "video/renderer.hpp"
 
 namespace SDL {
-  class Renderer : public ::Renderer
-  {
-  public:
-    Renderer();
-    ~Renderer();
+class Renderer : public ::Renderer
+{
+public:
+  Renderer();
+  ~Renderer();
 
-    void draw_surface(const DrawingRequest& request);
-    void draw_surface_part(const DrawingRequest& request);
-    void draw_text(const DrawingRequest& request);
-    void draw_gradient(const DrawingRequest& request);
-    void draw_filled_rect(const DrawingRequest& request);
-    void draw_inverse_ellipse(const DrawingRequest& request);
-    void do_take_screenshot();
-    void flip();
-    void resize(int w, int h);
-    void apply_config() {}
-  private:
-    SDL_Surface *screen;
-    int numerator, denominator;
-  };
+  void draw_surface(const DrawingRequest& request);
+  void draw_surface_part(const DrawingRequest& request);
+  void draw_text(const DrawingRequest& request);
+  void draw_gradient(const DrawingRequest& request);
+  void draw_filled_rect(const DrawingRequest& request);
+  void draw_inverse_ellipse(const DrawingRequest& request);
+  void do_take_screenshot();
+  void flip();
+  void resize(int w, int h);
+  void apply_config() {}
+private:
+  SDL_Surface *screen;
+  int numerator, denominator;
+};
 }
 
 #endif

Modified: branches/supertux-milestone2-grumbel/src/video/sdl/sdl_surface_data.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/sdl/sdl_surface_data.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/sdl/sdl_surface_data.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -25,57 +25,57 @@
 #include "video/texture.hpp"
 
 namespace SDL {
-  class SurfaceData
+class SurfaceData
+{
+private:
+  const Surface &surface;
+  SDL_Rect src_rects[NUM_EFFECTS];
+
+public:
+  SurfaceData(const Surface &surface) :
+    surface(surface)
   {
-  private:
-    const Surface &surface;
-    SDL_Rect src_rects[NUM_EFFECTS];
+    int numerator   = 1;
+    int denominator = 1;
+    //float xfactor = 1.0f; // FIXME: (float) config->screenwidth  / SCREEN_WIDTH;
+    //float yfactor = 1.0f; // FIXME: (float) config->screenheight / SCREEN_HEIGHT;
 
-  public:
-    SurfaceData(const Surface &surface) :
-      surface(surface)
-    {
-      int numerator   = 1;
-      int denominator = 1;
-      //float xfactor = 1.0f; // FIXME: (float) config->screenwidth  / SCREEN_WIDTH;
-      //float yfactor = 1.0f; // FIXME: (float) config->screenheight / SCREEN_HEIGHT;
+    /* FIXME: 
+       if(xfactor < yfactor)
+       {
+       numerator = config->screenwidth;
+       denominator = SCREEN_WIDTH;
+       }
+       else
+       {
+       numerator = config->screenheight;
+       denominator = SCREEN_HEIGHT;
+       }
+    */
 
-      /* FIXME: 
-      if(xfactor < yfactor)
-      {
-        numerator = config->screenwidth;
-        denominator = SCREEN_WIDTH;
-      }
-      else
-      {
-        numerator = config->screenheight;
-        denominator = SCREEN_HEIGHT;
-      }
-      */
+    src_rects[NO_EFFECT].x = surface.get_x() * numerator / denominator;
+    src_rects[NO_EFFECT].y = surface.get_y() * numerator / denominator;
+    src_rects[NO_EFFECT].w = surface.get_width() * numerator / denominator;
+    src_rects[NO_EFFECT].h = surface.get_height() * numerator / denominator;
 
-      src_rects[NO_EFFECT].x = surface.get_x() * numerator / denominator;
-      src_rects[NO_EFFECT].y = surface.get_y() * numerator / denominator;
-      src_rects[NO_EFFECT].w = surface.get_width() * numerator / denominator;
-      src_rects[NO_EFFECT].h = surface.get_height() * numerator / denominator;
+    int flipped_x = surface.get_texture()->get_texture_width() - surface.get_x() - surface.get_width();
+    src_rects[HORIZONTAL_FLIP].x = flipped_x * numerator / denominator;
+    src_rects[HORIZONTAL_FLIP].y = surface.get_y() * numerator / denominator;
+    src_rects[HORIZONTAL_FLIP].w = surface.get_width() * numerator / denominator;
+    src_rects[HORIZONTAL_FLIP].h = surface.get_height() * numerator / denominator;
 
-      int flipped_x = surface.get_texture()->get_texture_width() - surface.get_x() - surface.get_width();
-      src_rects[HORIZONTAL_FLIP].x = flipped_x * numerator / denominator;
-      src_rects[HORIZONTAL_FLIP].y = surface.get_y() * numerator / denominator;
-      src_rects[HORIZONTAL_FLIP].w = surface.get_width() * numerator / denominator;
-      src_rects[HORIZONTAL_FLIP].h = surface.get_height() * numerator / denominator;
+    int flipped_y = surface.get_texture()->get_texture_height() - surface.get_y() - surface.get_height();
+    src_rects[VERTICAL_FLIP].x = flipped_y * numerator / denominator;
+    src_rects[VERTICAL_FLIP].y = surface.get_y() * numerator / denominator;
+    src_rects[VERTICAL_FLIP].w = surface.get_width() * numerator / denominator;
+    src_rects[VERTICAL_FLIP].h = surface.get_height() * numerator / denominator;
+  }
 
-      int flipped_y = surface.get_texture()->get_texture_height() - surface.get_y() - surface.get_height();
-      src_rects[VERTICAL_FLIP].x = flipped_y * numerator / denominator;
-      src_rects[VERTICAL_FLIP].y = surface.get_y() * numerator / denominator;
-      src_rects[VERTICAL_FLIP].w = surface.get_width() * numerator / denominator;
-      src_rects[VERTICAL_FLIP].h = surface.get_height() * numerator / denominator;
-    }
-
-    SDL_Rect *get_src_rect(DrawingEffect effect)
-    {
-      return src_rects + effect;
-    }
-  };
+  SDL_Rect *get_src_rect(DrawingEffect effect)
+  {
+    return src_rects + effect;
+  }
+};
 }
 
 #endif

Modified: branches/supertux-milestone2-grumbel/src/video/sdl/sdl_texture.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/sdl/sdl_texture.cpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/sdl/sdl_texture.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -30,199 +30,16 @@
 #define BILINEAR
 
 #ifdef NAIVE
-  SDL_Surface *scale(SDL_Surface *src, int numerator, int denominator)
+SDL_Surface *scale(SDL_Surface *src, int numerator, int denominator)
+{
+  if(numerator == denominator)
   {
-    if(numerator == denominator)
-    {
-      src->refcount++;
-      return src;
-    }
-    else
-    {
-      SDL_Surface *dst = SDL_CreateRGBSurface(src->flags, src->w * numerator / denominator, src->h * numerator / denominator, 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 * denominator / numerator) * src->pitch + (x * denominator / numerator) * bpp;
-          Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + x * bpp;
-          switch(bpp) {
-            case 4:
-              dstpixel[3] = srcpixel[3];
-            case 3:
-              dstpixel[2] = srcpixel[2];
-            case 2:
-              dstpixel[1] = srcpixel[1];
-            case 1:
-              dstpixel[0] = srcpixel[0];
-          }
-        }
-      }
-      if(SDL_MUSTLOCK(dst))
-      {
-        SDL_UnlockSurface(dst);
-      }
-      if(SDL_MUSTLOCK(src))
-      {
-        SDL_UnlockSurface(src);
-      }
-      if(!src->format->Amask)
-      {
-        if(src->flags & SDL_SRCALPHA)
-        {
-          SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
-        }
-        if(src->flags & SDL_SRCCOLORKEY)
-        {
-          SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
-        }
-      }
-      return dst;
-    }
+    src->refcount++;
+    return src;
   }
-#endif
-
-#ifdef BILINEAR
-  void getpixel(SDL_Surface *src, int srcx, int srcy, Uint8 color[4])
+  else
   {
-    int bpp = src->format->BytesPerPixel;
-    if(srcx == src->w)
-    {
-      srcx--;
-    }
-    if(srcy == src->h)
-    {
-      srcy--;
-    }
-    Uint8 *srcpixel = (Uint8 *) src->pixels + srcy * src->pitch + srcx * bpp;
-    Uint32 mapped = 0;
-    switch(bpp) {
-      case 1:
-        mapped = *srcpixel;
-        break;
-      case 2:
-        mapped = *(Uint16 *)srcpixel;
-        break;
-      case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-        mapped |= srcpixel[0] << 16;
-        mapped |= srcpixel[1] << 8;
-        mapped |= srcpixel[2] << 0;
-#else
-        mapped |= srcpixel[0] << 0;
-        mapped |= srcpixel[1] << 8;
-        mapped |= srcpixel[2] << 16;
-#endif
-        break;
-      case 4:
-        mapped = *(Uint32 *)srcpixel;
-        break;
-    }
-    SDL_GetRGBA(mapped, src->format, &color[0], &color[1], &color[2], &color[3]);
-  }
-
-  void merge(Uint8 color[4], Uint8 color0[4], Uint8 color1[4], int rem, int total)
-  {
-    color[0] = (color0[0] * (total - rem) + color1[0] * rem) / total;
-    color[1] = (color0[1] * (total - rem) + color1[1] * rem) / total;
-    color[2] = (color0[2] * (total - rem) + color1[2] * rem) / total;
-    color[3] = (color0[3] * (total - rem) + color1[3] * rem) / total;
-  }
-
-  SDL_Surface *scale(SDL_Surface *src, int numerator, int denominator)
-  {
-    if(numerator == denominator)
-    {
-      src->refcount++;
-      return src;
-    }
-    else
-    {
-      SDL_Surface *dst = SDL_CreateRGBSurface(src->flags, src->w * numerator / denominator, src->h * numerator / denominator, 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++) {
-          int srcx = x * denominator / numerator;
-          int srcy = y * denominator / numerator;
-          Uint8 color00[4], color01[4], color10[4], color11[4];
-          getpixel(src, srcx, srcy, color00);
-          getpixel(src, srcx + 1, srcy, color01);
-          getpixel(src, srcx, srcy + 1, color10);
-          getpixel(src, srcx + 1, srcy + 1, color11);
-          Uint8 color0[4], color1[4], color[4];
-          int remx = x * denominator % numerator;
-          merge(color0, color00, color01, remx, numerator);
-          merge(color1, color10, color11, remx, numerator);
-          int remy = y * denominator % numerator;
-          merge(color, color0, color1, remy, numerator);
-          Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + x * bpp;
-          Uint32 mapped = SDL_MapRGBA(dst->format, color[0], color[1], color[2], color[3]);
-          switch(bpp) {
-            case 1:
-              *dstpixel = mapped;
-              break;
-            case 2:
-              *(Uint16 *)dstpixel = mapped;
-              break;
-            case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-              dstpixel[0] = (mapped >> 16) & 0xff;
-              dstpixel[1] = (mapped >> 8) & 0xff;
-              dstpixel[2] = (mapped >> 0) & 0xff;
-#else
-              dstpixel[0] = (mapped >> 0) & 0xff;
-              dstpixel[1] = (mapped >> 8) & 0xff;
-              dstpixel[2] = (mapped >> 16) & 0xff;
-#endif
-              break;
-            case 4:
-              *(Uint32 *)dstpixel = mapped;
-              break;
-          }
-        }
-      }
-      if(SDL_MUSTLOCK(dst))
-      {
-        SDL_UnlockSurface(dst);
-      }
-      if(SDL_MUSTLOCK(src))
-      {
-        SDL_UnlockSurface(src);
-      }
-      if(!src->format->Amask)
-      {
-        if(src->flags & SDL_SRCALPHA)
-        {
-          SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
-        }
-        if(src->flags & SDL_SRCCOLORKEY)
-        {
-          SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
-        }
-      }
-      return dst;
-    }
-  }
-#endif
-
-  SDL_Surface *horz_flip(SDL_Surface *src)
-  {
-    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);
+    SDL_Surface *dst = SDL_CreateRGBSurface(src->flags, src->w * numerator / denominator, src->h * numerator / denominator, src->format->BitsPerPixel, src->format->Rmask,  src->format->Gmask, src->format->Bmask, src->format->Amask);
     int bpp = dst->format->BytesPerPixel;
     if(SDL_MUSTLOCK(src))
     {
@@ -234,8 +51,8 @@
     }
     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;
-        Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + (dst->w - x - 1) * bpp;
+        Uint8 *srcpixel = (Uint8 *) src->pixels + (y * denominator / numerator) * src->pitch + (x * denominator / numerator) * bpp;
+        Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + x * bpp;
         switch(bpp) {
           case 4:
             dstpixel[3] = srcpixel[3];
@@ -269,10 +86,66 @@
     }
     return dst;
   }
+}
+#endif
 
-  SDL_Surface *vert_flip(SDL_Surface *src)
+#ifdef BILINEAR
+void getpixel(SDL_Surface *src, int srcx, int srcy, Uint8 color[4])
+{
+  int bpp = src->format->BytesPerPixel;
+  if(srcx == src->w)
   {
-    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);
+    srcx--;
+  }
+  if(srcy == src->h)
+  {
+    srcy--;
+  }
+  Uint8 *srcpixel = (Uint8 *) src->pixels + srcy * src->pitch + srcx * bpp;
+  Uint32 mapped = 0;
+  switch(bpp) {
+    case 1:
+      mapped = *srcpixel;
+      break;
+    case 2:
+      mapped = *(Uint16 *)srcpixel;
+      break;
+    case 3:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+      mapped |= srcpixel[0] << 16;
+      mapped |= srcpixel[1] << 8;
+      mapped |= srcpixel[2] << 0;
+#else
+      mapped |= srcpixel[0] << 0;
+      mapped |= srcpixel[1] << 8;
+      mapped |= srcpixel[2] << 16;
+#endif
+      break;
+    case 4:
+      mapped = *(Uint32 *)srcpixel;
+      break;
+  }
+  SDL_GetRGBA(mapped, src->format, &color[0], &color[1], &color[2], &color[3]);
+}
+
+void merge(Uint8 color[4], Uint8 color0[4], Uint8 color1[4], int rem, int total)
+{
+  color[0] = (color0[0] * (total - rem) + color1[0] * rem) / total;
+  color[1] = (color0[1] * (total - rem) + color1[1] * rem) / total;
+  color[2] = (color0[2] * (total - rem) + color1[2] * rem) / total;
+  color[3] = (color0[3] * (total - rem) + color1[3] * rem) / total;
+}
+
+SDL_Surface *scale(SDL_Surface *src, int numerator, int denominator)
+{
+  if(numerator == denominator)
+  {
+    src->refcount++;
+    return src;
+  }
+  else
+  {
+    SDL_Surface *dst = SDL_CreateRGBSurface(src->flags, src->w * numerator / denominator, src->h * numerator / denominator, src->format->BitsPerPixel, src->format->Rmask,  src->format->Gmask, src->format->Bmask, src->format->Amask);
     int bpp = dst->format->BytesPerPixel;
     if(SDL_MUSTLOCK(src))
     {
@@ -284,17 +157,42 @@
     }
     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;
-        Uint8 *dstpixel = (Uint8 *) dst->pixels + (dst->h - y - 1) * dst->pitch + x * bpp;
+        int srcx = x * denominator / numerator;
+        int srcy = y * denominator / numerator;
+        Uint8 color00[4], color01[4], color10[4], color11[4];
+        getpixel(src, srcx, srcy, color00);
+        getpixel(src, srcx + 1, srcy, color01);
+        getpixel(src, srcx, srcy + 1, color10);
+        getpixel(src, srcx + 1, srcy + 1, color11);
+        Uint8 color0[4], color1[4], color[4];
+        int remx = x * denominator % numerator;
+        merge(color0, color00, color01, remx, numerator);
+        merge(color1, color10, color11, remx, numerator);
+        int remy = y * denominator % numerator;
+        merge(color, color0, color1, remy, numerator);
+        Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + x * bpp;
+        Uint32 mapped = SDL_MapRGBA(dst->format, color[0], color[1], color[2], color[3]);
         switch(bpp) {
+          case 1:
+            *dstpixel = mapped;
+            break;
+          case 2:
+            *(Uint16 *)dstpixel = mapped;
+            break;
+          case 3:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+            dstpixel[0] = (mapped >> 16) & 0xff;
+            dstpixel[1] = (mapped >> 8) & 0xff;
+            dstpixel[2] = (mapped >> 0) & 0xff;
+#else
+            dstpixel[0] = (mapped >> 0) & 0xff;
+            dstpixel[1] = (mapped >> 8) & 0xff;
+            dstpixel[2] = (mapped >> 16) & 0xff;
+#endif
+            break;
           case 4:
-            dstpixel[3] = srcpixel[3];
-          case 3:
-            dstpixel[2] = srcpixel[2];
-          case 2:
-            dstpixel[1] = srcpixel[1];
-          case 1:
-            dstpixel[0] = srcpixel[0];
+            *(Uint32 *)dstpixel = mapped;
+            break;
         }
       }
     }
@@ -319,20 +217,305 @@
     }
     return dst;
   }
+}
+#endif
 
-  SDL_Surface *colorize(SDL_Surface *src, const Color &color)
+SDL_Surface *horz_flip(SDL_Surface *src)
+{
+  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))
   {
-    // FIXME: This is really slow
-    assert(color.red != 1.0 || color.green != 1.0 || color.blue != 1.0);
-    int red = (int) (color.red * 256);
-    int green = (int) (color.green * 256);
-    int blue = (int) (color.blue * 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;
+    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;
+      Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + (dst->w - x - 1) * bpp;
+      switch(bpp) {
+        case 4:
+          dstpixel[3] = srcpixel[3];
+        case 3:
+          dstpixel[2] = srcpixel[2];
+        case 2:
+          dstpixel[1] = srcpixel[1];
+        case 1:
+          dstpixel[0] = srcpixel[0];
+      }
+    }
+  }
+  if(SDL_MUSTLOCK(dst))
+  {
+    SDL_UnlockSurface(dst);
+  }
+  if(SDL_MUSTLOCK(src))
+  {
+    SDL_UnlockSurface(src);
+  }
+  if(!src->format->Amask)
+  {
+    if(src->flags & SDL_SRCALPHA)
+    {
+      SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
+    }
+    if(src->flags & SDL_SRCCOLORKEY)
+    {
+      SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
+    }
+  }
+  return dst;
+}
+
+SDL_Surface *vert_flip(SDL_Surface *src)
+{
+  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;
+      Uint8 *dstpixel = (Uint8 *) dst->pixels + (dst->h - y - 1) * dst->pitch + x * bpp;
+      switch(bpp) {
+        case 4:
+          dstpixel[3] = srcpixel[3];
+        case 3:
+          dstpixel[2] = srcpixel[2];
+        case 2:
+          dstpixel[1] = srcpixel[1];
+        case 1:
+          dstpixel[0] = srcpixel[0];
+      }
+    }
+  }
+  if(SDL_MUSTLOCK(dst))
+  {
+    SDL_UnlockSurface(dst);
+  }
+  if(SDL_MUSTLOCK(src))
+  {
+    SDL_UnlockSurface(src);
+  }
+  if(!src->format->Amask)
+  {
+    if(src->flags & SDL_SRCALPHA)
+    {
+      SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
+    }
+    if(src->flags & SDL_SRCCOLORKEY)
+    {
+      SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
+    }
+  }
+  return dst;
+}
+
+SDL_Surface *colorize(SDL_Surface *src, const Color &color)
+{
+  // FIXME: This is really slow
+  assert(color.red != 1.0 || color.green != 1.0 || color.blue != 1.0);
+  int red = (int) (color.red * 256);
+  int green = (int) (color.green * 256);
+  int blue = (int) (color.blue * 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;
+      Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + x * bpp;
+      Uint32 mapped = 0;
+      switch(bpp) {
+        case 1:
+          mapped = *srcpixel;
+          break;
+        case 2:
+          mapped = *(Uint16 *)srcpixel;
+          break;
+        case 3:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+          mapped |= srcpixel[0] << 16;
+          mapped |= srcpixel[1] << 8;
+          mapped |= srcpixel[2] << 0;
+#else
+          mapped |= srcpixel[0] << 0;
+          mapped |= srcpixel[1] << 8;
+          mapped |= srcpixel[2] << 16;
+#endif
+          break;
+        case 4:
+          mapped = *(Uint32 *)srcpixel;
+          break;
+      }
+      if(src->format->Amask || !(src->flags & SDL_SRCCOLORKEY) || mapped != src->format->colorkey)
+      {
+        Uint8 r, g, b, a;
+        SDL_GetRGBA(mapped, src->format, &r, &g, &b, &a);
+        mapped = SDL_MapRGBA(dst->format, (r * red) >> 8, (g * green) >> 8, (b * blue) >> 8, a);
+      }
+      switch(bpp) {
+        case 1:
+          *dstpixel = mapped;
+          break;
+        case 2:
+          *(Uint16 *)dstpixel = mapped;
+          break;
+        case 3:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+          dstpixel[0] = (mapped >> 16) & 0xff;
+          dstpixel[1] = (mapped >> 8) & 0xff;
+          dstpixel[2] = (mapped >> 0) & 0xff;
+#else
+          dstpixel[0] = (mapped >> 0) & 0xff;
+          dstpixel[1] = (mapped >> 8) & 0xff;
+          dstpixel[2] = (mapped >> 16) & 0xff;
+#endif
+          break;
+        case 4:
+          *(Uint32 *)dstpixel = mapped;
+          break;
+      }
+    }
+  }
+  if(SDL_MUSTLOCK(dst))
+  {
+    SDL_UnlockSurface(dst);
+  }
+  if(SDL_MUSTLOCK(src))
+  {
+    SDL_UnlockSurface(src);
+  }
+  if(!src->format->Amask)
+  {
+    if(src->flags & SDL_SRCALPHA)
+    {
+      SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
+    }
+    if(src->flags & SDL_SRCCOLORKEY)
+    {
+      SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
+    }
+  }
+  return dst;
+}
+
+SDL_Surface *optimize(SDL_Surface *src)
+{
+  if(!src->format->Amask)
+  {
+    return SDL_DisplayFormat(src);
+  }
+  else
+  {
+    int transparent = 0;
+    int opaque = 0;
+    int semitransparent = 0;
+    int alphasum = 0;
+    int squaredalphasum = 0;
+    bool colors[(1 << 12)];
+    memset(colors, 0, (1 << 12) * sizeof(bool));
+
+    int bpp = src->format->BytesPerPixel;
     if(SDL_MUSTLOCK(src))
     {
       SDL_LockSurface(src);
     }
+    for(int y = 0;y < src->h;y++) {
+      for(int x = 0;x < src->w;x++) {
+        Uint8 *pixel = (Uint8 *) src->pixels + y * src->pitch + x * bpp;
+        Uint32 mapped = 0;
+        switch(bpp) {
+          case 1:
+            mapped = *pixel;
+            break;
+          case 2:
+            mapped = *(Uint16 *)pixel;
+            break;
+          case 3:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+            mapped |= pixel[0] << 16;
+            mapped |= pixel[1] << 8;
+            mapped |= pixel[2] << 0;
+#else
+            mapped |= pixel[0] << 0;
+            mapped |= pixel[1] << 8;
+            mapped |= pixel[2] << 16;
+#endif
+            break;
+          case 4:
+            mapped = *(Uint32 *)pixel;
+            break;
+        }
+        Uint8 red, green, blue, alpha;
+        SDL_GetRGBA(mapped, src->format, &red, &green, &blue, &alpha);
+        if(alpha < 16)
+        {
+          transparent++;
+        }
+        else if (alpha > 240)
+        {
+          opaque++;
+          alphasum += alpha;
+          squaredalphasum += alpha * alpha;
+        }
+        else
+        {
+          semitransparent++;
+          squaredalphasum += alpha * alpha;
+        }
+        if(alpha != 0)
+        {
+          colors[((red & 0xf0) << 4) | (green & 0xf0) | ((blue & 0xf0) >> 4)] = true;
+        }
+      }
+    }
+    if(SDL_MUSTLOCK(src))
+    {
+      SDL_UnlockSurface(src);
+    }
+    int avgalpha = (opaque + semitransparent) ? alphasum / (opaque + semitransparent) : 0;
+    int avgsquaredalpha = (opaque + semitransparent) ? squaredalphasum / (opaque + semitransparent) : 0;
+    int alphavariance = avgsquaredalpha - avgalpha * avgalpha;
+    if(semitransparent > ((transparent + opaque + semitransparent) / 8) && alphavariance > 16)
+    {
+      return SDL_DisplayFormatAlpha(src);
+    }
+    int keycolor = -1;
+    for(int i = 0;i < (1 << 12);i++)
+    {
+      if(!colors[i])
+      {
+        keycolor = i;
+      }
+    }
+    if(keycolor == -1)
+    {
+      return SDL_DisplayFormatAlpha(src);
+    }
+    SDL_Surface *dst = SDL_CreateRGBSurface(src->flags & ~(SDL_SRCALPHA), src->w, src->h, src->format->BitsPerPixel, src->format->Rmask,  src->format->Gmask, src->format->Bmask, 0);
+    bpp = dst->format->BytesPerPixel;
+    Uint32 key = SDL_MapRGB(dst->format, (((keycolor & 0xf00) >> 4) | 0xf), ((keycolor & 0xf0) | 0xf), (((keycolor & 0xf) << 4) | 0xf));
+    if(SDL_MUSTLOCK(src))
+    {
+      SDL_LockSurface(src);
+    }
     if(SDL_MUSTLOCK(dst))
     {
       SDL_LockSurface(dst);
@@ -364,12 +547,16 @@
             mapped = *(Uint32 *)srcpixel;
             break;
         }
-        if(src->format->Amask || !(src->flags & SDL_SRCCOLORKEY) || mapped != src->format->colorkey)
+        Uint8 red, green, blue, alpha;
+        SDL_GetRGBA(mapped, src->format, &red, &green, &blue, &alpha);
+        if(alpha < (avgalpha / 4))
         {
-          Uint8 r, g, b, a;
-          SDL_GetRGBA(mapped, src->format, &r, &g, &b, &a);
-          mapped = SDL_MapRGBA(dst->format, (r * red) >> 8, (g * green) >> 8, (b * blue) >> 8, a);
+          mapped = key;
         }
+        else
+        {
+          mapped = SDL_MapRGB(dst->format, red, green, blue);
+        }
         switch(bpp) {
           case 1:
             *dstpixel = mapped;
@@ -402,258 +589,71 @@
     {
       SDL_UnlockSurface(src);
     }
-    if(!src->format->Amask)
+    if(avgalpha < 240)
     {
-      if(src->flags & SDL_SRCALPHA)
-      {
-        SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
-      }
-      if(src->flags & SDL_SRCCOLORKEY)
-      {
-        SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
-      }
+      SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, avgalpha);
     }
-    return dst;
+    SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, key);
+    SDL_Surface *convert = SDL_DisplayFormat(dst);
+    SDL_FreeSurface(dst);
+    return convert;
   }
+}
+}
 
-  SDL_Surface *optimize(SDL_Surface *src)
-  {
-    if(!src->format->Amask)
-    {
-      return SDL_DisplayFormat(src);
-    }
-    else
-    {
-      int transparent = 0;
-      int opaque = 0;
-      int semitransparent = 0;
-      int alphasum = 0;
-      int squaredalphasum = 0;
-      bool colors[(1 << 12)];
-      memset(colors, 0, (1 << 12) * sizeof(bool));
+namespace SDL {
+Texture::Texture(SDL_Surface* image)
+{
+  texture = optimize(image);
+  //width = texture->w;
+  //height = texture->h;
+  int numerator   = 1;
+  int denominator = 1;
+  //FIXME: float xfactor = (float) config->screenwidth / SCREEN_WIDTH;
+  //FIXME: float yfactor = (float) config->screenheight / SCREEN_HEIGHT;
+  /* FIXME: 
+     if(xfactor < yfactor)
+     {
+     numerator = config->screenwidth;
+     denominator = SCREEN_WIDTH;
+     }
+     else
+     {
+     numerator = config->screenheight;
+     denominator = SCREEN_HEIGHT;
+     }
+  */
+  cache[NO_EFFECT][Color::WHITE] = scale(texture, numerator, denominator);
+}
 
-      int bpp = src->format->BytesPerPixel;
-      if(SDL_MUSTLOCK(src))
-      {
-        SDL_LockSurface(src);
-      }
-      for(int y = 0;y < src->h;y++) {
-        for(int x = 0;x < src->w;x++) {
-          Uint8 *pixel = (Uint8 *) src->pixels + y * src->pitch + x * bpp;
-          Uint32 mapped = 0;
-          switch(bpp) {
-            case 1:
-              mapped = *pixel;
-              break;
-            case 2:
-              mapped = *(Uint16 *)pixel;
-              break;
-            case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-              mapped |= pixel[0] << 16;
-              mapped |= pixel[1] << 8;
-              mapped |= pixel[2] << 0;
-#else
-              mapped |= pixel[0] << 0;
-              mapped |= pixel[1] << 8;
-              mapped |= pixel[2] << 16;
-#endif
-              break;
-            case 4:
-              mapped = *(Uint32 *)pixel;
-              break;
-          }
-          Uint8 red, green, blue, alpha;
-          SDL_GetRGBA(mapped, src->format, &red, &green, &blue, &alpha);
-          if(alpha < 16)
-          {
-            transparent++;
-          }
-          else if (alpha > 240)
-          {
-            opaque++;
-            alphasum += alpha;
-            squaredalphasum += alpha * alpha;
-          }
-          else
-          {
-            semitransparent++;
-            squaredalphasum += alpha * alpha;
-          }
-          if(alpha != 0)
-          {
-            colors[((red & 0xf0) << 4) | (green & 0xf0) | ((blue & 0xf0) >> 4)] = true;
-          }
-        }
-      }
-      if(SDL_MUSTLOCK(src))
-      {
-        SDL_UnlockSurface(src);
-      }
-      int avgalpha = (opaque + semitransparent) ? alphasum / (opaque + semitransparent) : 0;
-      int avgsquaredalpha = (opaque + semitransparent) ? squaredalphasum / (opaque + semitransparent) : 0;
-      int alphavariance = avgsquaredalpha - avgalpha * avgalpha;
-      if(semitransparent > ((transparent + opaque + semitransparent) / 8) && alphavariance > 16)
-      {
-        return SDL_DisplayFormatAlpha(src);
-      }
-      int keycolor = -1;
-      for(int i = 0;i < (1 << 12);i++)
-      {
-        if(!colors[i])
-        {
-          keycolor = i;
-        }
-      }
-      if(keycolor == -1)
-      {
-        return SDL_DisplayFormatAlpha(src);
-      }
-      SDL_Surface *dst = SDL_CreateRGBSurface(src->flags & ~(SDL_SRCALPHA), src->w, src->h, src->format->BitsPerPixel, src->format->Rmask,  src->format->Gmask, src->format->Bmask, 0);
-      bpp = dst->format->BytesPerPixel;
-      Uint32 key = SDL_MapRGB(dst->format, (((keycolor & 0xf00) >> 4) | 0xf), ((keycolor & 0xf0) | 0xf), (((keycolor & 0xf) << 4) | 0xf));
-      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;
-          Uint8 *dstpixel = (Uint8 *) dst->pixels + y * dst->pitch + x * bpp;
-          Uint32 mapped = 0;
-          switch(bpp) {
-            case 1:
-              mapped = *srcpixel;
-              break;
-            case 2:
-              mapped = *(Uint16 *)srcpixel;
-              break;
-            case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-              mapped |= srcpixel[0] << 16;
-              mapped |= srcpixel[1] << 8;
-              mapped |= srcpixel[2] << 0;
-#else
-              mapped |= srcpixel[0] << 0;
-              mapped |= srcpixel[1] << 8;
-              mapped |= srcpixel[2] << 16;
-#endif
-              break;
-            case 4:
-              mapped = *(Uint32 *)srcpixel;
-              break;
-          }
-          Uint8 red, green, blue, alpha;
-          SDL_GetRGBA(mapped, src->format, &red, &green, &blue, &alpha);
-          if(alpha < (avgalpha / 4))
-          {
-            mapped = key;
-          }
-          else
-          {
-            mapped = SDL_MapRGB(dst->format, red, green, blue);
-          }
-          switch(bpp) {
-            case 1:
-              *dstpixel = mapped;
-              break;
-            case 2:
-              *(Uint16 *)dstpixel = mapped;
-              break;
-            case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-              dstpixel[0] = (mapped >> 16) & 0xff;
-              dstpixel[1] = (mapped >> 8) & 0xff;
-              dstpixel[2] = (mapped >> 0) & 0xff;
-#else
-              dstpixel[0] = (mapped >> 0) & 0xff;
-              dstpixel[1] = (mapped >> 8) & 0xff;
-              dstpixel[2] = (mapped >> 16) & 0xff;
-#endif
-              break;
-            case 4:
-              *(Uint32 *)dstpixel = mapped;
-              break;
-          }
-        }
-      }
-      if(SDL_MUSTLOCK(dst))
-      {
-        SDL_UnlockSurface(dst);
-      }
-      if(SDL_MUSTLOCK(src))
-      {
-        SDL_UnlockSurface(src);
-      }
-      if(avgalpha < 240)
-      {
-        SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, avgalpha);
-      }
-      SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, key);
-      SDL_Surface *convert = SDL_DisplayFormat(dst);
-      SDL_FreeSurface(dst);
-      return convert;
-    }
-  }
+Texture::~Texture()
+{
+  SDL_FreeSurface(texture);
 }
 
-namespace SDL {
-  Texture::Texture(SDL_Surface* image)
-  {
-    texture = optimize(image);
-    //width = texture->w;
-    //height = texture->h;
-    int numerator   = 1;
-    int denominator = 1;
-    //FIXME: float xfactor = (float) config->screenwidth / SCREEN_WIDTH;
-    //FIXME: float yfactor = (float) config->screenheight / SCREEN_HEIGHT;
-    /* FIXME: 
-    if(xfactor < yfactor)
-    {
-      numerator = config->screenwidth;
-      denominator = SCREEN_WIDTH;
-    }
-    else
-    {
-      numerator = config->screenheight;
-      denominator = SCREEN_HEIGHT;
-    }
-    */
-    cache[NO_EFFECT][Color::WHITE] = scale(texture, numerator, denominator);
+SDL_Surface *Texture::get_transform(const Color &color, DrawingEffect effect)
+{
+  if(cache[NO_EFFECT][color] == 0) {
+    assert(cache[NO_EFFECT][Color::WHITE]);
+    cache[NO_EFFECT][color] = colorize(cache[NO_EFFECT][Color::WHITE], color);
   }
-
-  Texture::~Texture()
-  {
-    SDL_FreeSurface(texture);
-  }
-
-  SDL_Surface *Texture::get_transform(const Color &color, DrawingEffect effect)
-  {
-    if(cache[NO_EFFECT][color] == 0) {
-      assert(cache[NO_EFFECT][Color::WHITE]);
-      cache[NO_EFFECT][color] = colorize(cache[NO_EFFECT][Color::WHITE], color);
+  if(cache[effect][color] == 0) {
+    assert(cache[NO_EFFECT][color]);
+    switch(effect) {
+      case NO_EFFECT:
+        break;
+      case HORIZONTAL_FLIP:
+        cache[HORIZONTAL_FLIP][color] = horz_flip(cache[NO_EFFECT][color]);
+        break;
+      case VERTICAL_FLIP:
+        cache[VERTICAL_FLIP][color] = vert_flip(cache[NO_EFFECT][color]);
+        break;
+      default:
+        return 0;
     }
-    if(cache[effect][color] == 0) {
-      assert(cache[NO_EFFECT][color]);
-      switch(effect) {
-        case NO_EFFECT:
-          break;
-        case HORIZONTAL_FLIP:
-          cache[HORIZONTAL_FLIP][color] = horz_flip(cache[NO_EFFECT][color]);
-          break;
-        case VERTICAL_FLIP:
-          cache[VERTICAL_FLIP][color] = vert_flip(cache[NO_EFFECT][color]);
-          break;
-        default:
-          return 0;
-      }
-    }
-    return cache[effect][color];
   }
+  return cache[effect][color];
 }
+}
 
 /* EOF */

Modified: branches/supertux-milestone2-grumbel/src/video/sdl/sdl_texture.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/sdl/sdl_texture.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/sdl/sdl_texture.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -26,112 +26,112 @@
 #include "video/texture.hpp"
 
 namespace SDL {
-  class Texture : public ::Texture
+class Texture : public ::Texture
+{
+protected:
+  SDL_Surface *texture;
+  //unsigned int width;
+  //unsigned int height;
+
+  struct ColorCache
   {
-  protected:
-    SDL_Surface *texture;
-    //unsigned int width;
-    //unsigned int height;
+    static const int HASHED_BITS = 3;
+    static const int CACHE_SIZE = 1 << (HASHED_BITS * 3);
 
-    struct ColorCache
+    static void ref(SDL_Surface *surface)
     {
-      static const int HASHED_BITS = 3;
-      static const int CACHE_SIZE = 1 << (HASHED_BITS * 3);
-
-      static void ref(SDL_Surface *surface)
+      if(surface)
       {
-        if(surface)
-        {
-          surface->refcount++;
-        }
+        surface->refcount++;
       }
+    }
 
-      static int hash(const Color &color)
-      {
-        return
-      ((int) (color.red * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1) * 2) |
-      ((int) (color.green * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1)) |
-      ((int) (color.blue * ((1 << HASHED_BITS) - 1)) << 0);
-      }
-
-      SDL_Surface *data[CACHE_SIZE];
-
-      ColorCache()
-      {
-        memset(data, 0, CACHE_SIZE * sizeof(SDL_Surface *));
-      }
-
-      ~ColorCache()
-      {
-        std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
-      }
-
-      void operator = (const ColorCache &other)
-      {
-        std::for_each(other.data, other.data + CACHE_SIZE, ref);
-        std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
-        memcpy(data, other.data, CACHE_SIZE * sizeof(SDL_Surface *));
-      }
-
-      SDL_Surface *&operator [] (const Color &color)
-      {
-        return data[hash(color)];
-      }
-    };
-    //typedef std::map<Color, SDL_Surface *> ColorCache;
-    ColorCache cache[NUM_EFFECTS];
-
-  public:
-    Texture(SDL_Surface* sdlsurface);
-    virtual ~Texture();
-
-    SDL_Surface *get_transform(const Color &color, DrawingEffect effect);
-
-    SDL_Surface *get_texture() const
+    static int hash(const Color &color)
     {
-      return texture;
+      return
+        ((int) (color.red * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1) * 2) |
+        ((int) (color.green * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1)) |
+        ((int) (color.blue * ((1 << HASHED_BITS) - 1)) << 0);
     }
 
-    unsigned int get_texture_width() const
+    SDL_Surface *data[CACHE_SIZE];
+
+    ColorCache()
     {
-      return texture->w;
+      memset(data, 0, CACHE_SIZE * sizeof(SDL_Surface *));
     }
 
-    unsigned int get_texture_height() const
+    ~ColorCache()
     {
-      return texture->h;
+      std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
     }
 
-    unsigned int get_image_width() const
+    void operator = (const ColorCache &other)
     {
-      return texture->w;
+      std::for_each(other.data, other.data + CACHE_SIZE, ref);
+      std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
+      memcpy(data, other.data, CACHE_SIZE * sizeof(SDL_Surface *));
     }
 
-    unsigned int get_image_height() const
+    SDL_Surface *&operator [] (const Color &color)
     {
-      return texture->h;
+      return data[hash(color)];
     }
+  };
+  //typedef std::map<Color, SDL_Surface *> ColorCache;
+  ColorCache cache[NUM_EFFECTS];
 
-    /*unsigned int get_texture_width() const
+public:
+  Texture(SDL_Surface* sdlsurface);
+  virtual ~Texture();
+
+  SDL_Surface *get_transform(const Color &color, DrawingEffect effect);
+
+  SDL_Surface *get_texture() const
+  {
+    return texture;
+  }
+
+  unsigned int get_texture_width() const
+  {
+    return texture->w;
+  }
+
+  unsigned int get_texture_height() const
+  {
+    return texture->h;
+  }
+
+  unsigned int get_image_width() const
+  {
+    return texture->w;
+  }
+
+  unsigned int get_image_height() const
+  {
+    return texture->h;
+  }
+
+  /*unsigned int get_texture_width() const
     {
-      return width;
+    return width;
     }
 
     unsigned int get_texture_height() const
     {
-      return height;
+    return height;
     }
 
     unsigned int get_image_width() const
     {
-      return width;
+    return width;
     }
 
     unsigned int get_image_height() const
     {
-      return height;
+    return height;
     }*/
-  };
+};
 }
 
 #endif

Added: branches/supertux-milestone2-grumbel/src/video/surface.cpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/surface.cpp	                        (rev 0)
+++ branches/supertux-milestone2-grumbel/src/video/surface.cpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -0,0 +1,137 @@
+//  SuperTux
+//  Copyright (C) 2006 Matthias Braun <matze at braunis.de>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "video/surface.hpp"
+
+#include <config.h>
+
+#include <SDL.h>
+
+#include "video/texture.hpp"
+#include "video/video_systems.hpp"
+
+Surface::Surface(const std::string& file) :
+  texture(texture_manager->get(file)),
+  surface_data(),
+  x(0), y(0), w(0), h(0),
+  flipx(false)
+{
+  texture->ref();
+  w = texture->get_image_width();
+  h = texture->get_image_height();
+  surface_data = new_surface_data(*this);
+}
+
+Surface::Surface(const std::string& file, int x, int y, int w, int h) :
+  texture(texture_manager->get(file)),
+  surface_data(),
+  x(x), y(y), w(w), h(h),
+  flipx(false)
+{
+  texture->ref();
+  surface_data = new_surface_data(*this);
+}
+
+Surface::Surface(const Surface& other) :
+  texture(other.texture),
+  surface_data(),
+  x(other.x), y(other.y),
+  w(other.w), h(other.h),
+  flipx(false)
+{
+  texture->ref();
+  surface_data = new_surface_data(*this);
+}
+
+const Surface& 
+Surface::operator= (const Surface& other)
+{
+  other.texture->ref();
+  texture->unref();
+  texture = other.texture;
+  x = other.x;
+  y = other.y;
+  w = other.w;
+  h = other.h;
+  return *this;
+}
+
+Surface::~Surface()
+{
+  free_surface_data(surface_data);
+  texture->unref();
+}
+
+/** flip the surface horizontally */
+void Surface::hflip()
+{
+  flipx = !flipx;
+}
+
+bool Surface::get_flipx() const
+{
+  return flipx;
+}
+
+Texture* 
+Surface::get_texture() const
+{
+  return texture;
+}
+
+void* 
+Surface::get_surface_data() const
+{
+  return surface_data;
+}
+
+int
+Surface::get_x() const
+{
+  return x;
+}
+
+int
+Surface::get_y() const
+{
+  return y;
+}
+
+int 
+Surface::get_width() const
+{
+  return w;
+}
+
+int 
+Surface::get_height() const
+{
+  return h;
+}
+
+Vector
+Surface::get_position() const
+{
+  return Vector(get_x(), get_y()); 
+}
+
+Vector
+Surface::get_size() const
+{
+  return Vector(get_width(), get_height()); 
+}
+
+/* EOF */


Property changes on: branches/supertux-milestone2-grumbel/src/video/surface.cpp
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: branches/supertux-milestone2-grumbel/src/video/surface.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/surface.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/surface.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -17,15 +17,12 @@
 #ifndef HEADER_SUPERTUX_VIDEO_SURFACE_HPP
 #define HEADER_SUPERTUX_VIDEO_SURFACE_HPP
 
-#include <config.h>
-
-#include <SDL.h>
 #include <string>
 
 #include "math/vector.hpp"
-#include "video/texture.hpp"
-#include "video/video_systems.hpp"
 
+class Texture;
+
 /**
  * A rectangular image.
  * The class basically holds a reference to a texture with additional UV
@@ -43,106 +40,28 @@
   bool flipx;
 
 public:
-  Surface(const std::string& file) :
-    texture(texture_manager->get(file)),
-    surface_data(),
-    x(0), y(0), w(0), h(0),
-    flipx(false)
-  {
-    texture->ref();
-    w = texture->get_image_width();
-    h = texture->get_image_height();
-    surface_data = new_surface_data(*this);
-  }
+  Surface(const std::string& file);
+  Surface(const std::string& file, int x, int y, int w, int h);
+  Surface(const Surface& other);
+  ~Surface();
 
-  Surface(const std::string& file, int x, int y, int w, int h) :
-    texture(texture_manager->get(file)),
-    surface_data(),
-    x(x), y(y), w(w), h(h),
-    flipx(false)
-  {
-    texture->ref();
-    surface_data = new_surface_data(*this);
-  }
+  const Surface& operator= (const Surface& other);
 
-  Surface(const Surface& other) :
-    texture(other.texture),
-    surface_data(),
-    x(other.x), y(other.y),
-    w(other.w), h(other.h),
-    flipx(false)
-  {
-    texture->ref();
-    surface_data = new_surface_data(*this);
-  }
-
-  ~Surface()
-  {
-    free_surface_data(surface_data);
-    texture->unref();
-  }
-
   /** flip the surface horizontally */
-  void hflip()
-  {
-    flipx = !flipx;
-  }
+  void hflip();
+  bool get_flipx() const;
 
-  bool get_flipx() const
-  {
-    return flipx;
-  }
-
-  const Surface& operator= (const Surface& other)
-  {
-    other.texture->ref();
-    texture->unref();
-    texture = other.texture;
-    x = other.x;
-    y = other.y;
-    w = other.w;
-    h = other.h;
-    return *this;
-  }
-
-  Texture *get_texture() const
-  {
-    return texture;
-  }
-
-  void *get_surface_data() const
-  {
-    return surface_data;
-  }
-
-  int get_x() const
-  {
-    return x;
-  }
-
-  int get_y() const
-  {
-    return y;
-  }
-
-  int get_width() const
-  {
-    return w;
-  }
-
-  int get_height() const
-  {
-    return h;
-  }
-
-  Vector get_position() const
-  { return Vector(get_x(), get_y()); }
-
+  Texture *get_texture() const;
+  void *get_surface_data() const;
+  int get_x() const;
+  int get_y() const;
+  int get_width() const;
+  int get_height() const;
+  Vector get_position() const;
   /**
    * returns a vector containing width and height
    */
-  Vector get_size() const
-  { return Vector(get_width(), get_height()); }
+  Vector get_size() const;
 };
 
 #endif

Modified: branches/supertux-milestone2-grumbel/src/video/texture.hpp
===================================================================
--- branches/supertux-milestone2-grumbel/src/video/texture.hpp	2009-11-15 20:33:01 UTC (rev 5978)
+++ branches/supertux-milestone2-grumbel/src/video/texture.hpp	2009-11-15 20:59:17 UTC (rev 5979)
@@ -83,6 +83,10 @@
   {
     texture_manager->release(this);
   }
+
+private:
+  Texture(const Texture&);
+  Texture& operator=(const Texture&);
 };
 
 #endif



More information about the Supertux-Commit mailing list