[Super-tux-commit] supertux/src/screen drawing_context.cpp,1.7,1.8 screen.h,1.3,1.4 texture.cpp,1.6,
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-06-12 16:07:21
|
Update of /cvsroot/super-tux/supertux/src/screen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25597/src/screen Modified Files: drawing_context.cpp screen.h texture.cpp Log Message: Optimized gradient when top color is the same as the bottom one. Index: drawing_context.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/screen/drawing_context.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- drawing_context.cpp 9 Jun 2004 04:43:15 -0000 1.7 +++ drawing_context.cpp 12 Jun 2004 16:07:12 -0000 1.8 @@ -181,15 +181,22 @@ else { #endif - float redstep = (float(bottom.red)-float(top.red)) / float(screen->h); - float greenstep = (float(bottom.green)-float(top.green)) / float(screen->h); - float bluestep = (float(bottom.blue) - float(top.blue)) / float(screen->h); + if(&top == &bottom) + { + fillrect(0, 0, screen->w, screen->h, top.red, top.green, top.blue); + } + else + { + float redstep = (float(bottom.red)-float(top.red)) / float(screen->h); + float greenstep = (float(bottom.green)-float(top.green)) / float(screen->h); + float bluestep = (float(bottom.blue) - float(top.blue)) / float(screen->h); - for(float y = 0; y < screen->h; y += 2) - fillrect(0, (int)y, screen->w, 2, - int(float(top.red) + redstep * y), - int(float(top.green) + greenstep * y), - int(float(top.blue) + bluestep * y), 255); + for(float y = 0; y < screen->h; y += 2) + fillrect(0, (int)y, screen->w, 2, + int(float(top.red) + redstep * y), + int(float(top.green) + greenstep * y), + int(float(top.blue) + bluestep * y), 255); + } #ifndef NOOPENGL } Index: screen.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/screen/screen.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- screen.h 10 Jun 2004 14:09:49 -0000 1.3 +++ screen.h 12 Jun 2004 16:07:12 -0000 1.4 @@ -24,7 +24,7 @@ #ifndef NOOPENGL #include <SDL_opengl.h> #endif - +#include <iostream> class Color { public: @@ -40,6 +40,12 @@ : red(o.red), green(o.green), blue(o.blue), alpha(o.alpha) { } + bool operator==(const Color& o) + { if(red == o.red && green == o.green && + blue == o.blue && alpha == o.alpha) + return true; + return false; } + Uint8 red, green, blue, alpha; }; Index: texture.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/screen/texture.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- texture.cpp 12 Jun 2004 15:42:24 -0000 1.6 +++ texture.cpp 12 Jun 2004 16:07:12 -0000 1.7 @@ -373,21 +373,29 @@ if(sdl_surface == NULL) st_abort("Cannot create surface for the gradient", "SURFACE"); - float redstep = (float(bottom.red)-float(top.red)) / float(h); - float greenstep = (float(bottom.green)-float(top.green)) / float(h); - float bluestep = (float(bottom.blue) - float(top.blue)) / float(h); - - SDL_Rect rect; - rect.x = 0; - rect.w = w; - rect.h = 1; - for(float y = 0; y < h; y++) + if(top == bottom) { - rect.y = (int)y; - SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format, - int(float(top.red) + redstep * y), - int(float(top.green) + greenstep * y), - int(float(top.blue) + bluestep * y))); + SDL_FillRect(sdl_surface, NULL, SDL_MapRGB(sdl_surface->format, + top.red, top.green, top.blue)); + } + else + { + float redstep = (float(bottom.red)-float(top.red)) / float(h); + float greenstep = (float(bottom.green)-float(top.green)) / float(h); + float bluestep = (float(bottom.blue) - float(top.blue)) / float(h); + + SDL_Rect rect; + rect.x = 0; + rect.w = w; + rect.h = 1; + for(float y = 0; y < h; y++) + { + rect.y = (int)y; + SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format, + int(float(top.red) + redstep * y), + int(float(top.green) + greenstep * y), + int(float(top.blue) + bluestep * y))); + } } return sdl_surface; |