X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fvideo%2Fscreen.cpp;h=4cef057038160262958265a334d826b6c91c4cee;hb=a5e66c8aec9b24595006c52499c926807cc7118b;hp=b123cecbc3cfb98b578137cd072f4a5b582db48a;hpb=9c511ea692d3a2339597211f08f18ea74fad35ec;p=supertux.git diff --git a/lib/video/screen.cpp b/lib/video/screen.cpp index b123cecbc..4cef05703 100644 --- a/lib/video/screen.cpp +++ b/lib/video/screen.cpp @@ -17,6 +17,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include + #include #include #include @@ -33,16 +35,49 @@ #include #endif +#include "screen.h" #include "app/globals.h" -#include "video/screen.h" #include "video/drawing_context.h" -#include "special/base.h" +#include "math/vector.h" + +using namespace SuperTux; + +/* 'Stolen' from the SDL documentation. + * Return the pixel value at (x, y) + * NOTE: The surface must be locked before calling this! + */ +Uint32 SuperTux::getpixel(SDL_Surface *surface, int x, int y) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to retrieve */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + + switch(bpp) { + case 1: + return *p; + + case 2: + return *(Uint16 *)p; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + else + return p[0] | p[1] << 8 | p[2] << 16; + + case 4: + return *(Uint32 *)p; + + default: + return 0; /* shouldn't happen, but avoids warnings */ + } +} /* 'Stolen' from the SDL documentation. * Set the pixel at (x, y) to the given value * NOTE: The surface must be locked before calling this! */ -void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +void SuperTux::putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) { int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ @@ -80,7 +115,7 @@ void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) } /* Draw a single pixel on the screen. */ -void drawpixel(int x, int y, Uint32 pixel) +void SuperTux::drawpixel(int x, int y, Uint32 pixel) { /* Lock the screen for direct access to the pixels */ if ( SDL_MUSTLOCK(screen) ) @@ -105,7 +140,7 @@ void drawpixel(int x, int y, Uint32 pixel) /* --- FILL A RECT --- */ -void fillrect(float x, float y, float w, float h, int r, int g, int b, int a) +void SuperTux::fillrect(float x, float y, float w, float h, int r, int g, int b, int a) { if(w < 0) { @@ -179,8 +214,7 @@ if(h < 0) #define SGN(x) ((x)>0 ? 1 : ((x)==0 ? 0:(-1))) #define ABS(x) ((x)>0 ? (x) : (-x)) -void -draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a) +void SuperTux::draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a) { #ifndef NOOPENGL if(use_gl) @@ -245,7 +279,7 @@ draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a) #define LOOP_DELAY 20.0 -void fadeout(int fade_time) +void SuperTux::fadeout(int fade_time) { float alpha_inc = 256 / (fade_time / LOOP_DELAY); float alpha = 256; @@ -262,14 +296,10 @@ void fadeout(int fade_time) } fillrect(0, 0, screen->w, screen->h, 0, 0, 0, 255); - - DrawingContext context; - context.draw_text_center(white_text, "Loading...", - Vector(0, screen->h/2), LAYER_FOREGROUND1); - context.do_drawing(); + } -void shrink_fade(const Vector& point, int fade_time) +void SuperTux::shrink_fade(const Vector& point, int fade_time) { float left_inc = point.x / ((float)fade_time / LOOP_DELAY); float right_inc = (screen->w - point.x) / ((float)fade_time / LOOP_DELAY);