/*************************************************************************** * Copyright (C) 2004 by Christoph Freundl * * Christoph.Freundl@informatik.uni-erlangen.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 2 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, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef SDLWIDGETS_GRAPHICS_H #define SDLWIDGETS_GRAPHICS_H #include namespace SDLwidgets { class Graphics { public: static void putPixel( SDL_Surface* surface, int x, int y, Uint32 pixelValue ) { /* Copied from the SDL manual */ int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ Uint8* p = static_cast( surface->pixels ) + y * surface->pitch + x * bpp; switch ( bpp ) { case 1: *p = pixelValue; break; case 2: *( reinterpret_cast( p ) ) = pixelValue; break; case 3: if( SDL_BYTEORDER == SDL_BIG_ENDIAN ) { p[0] = ( pixelValue >> 16 ) & 0xff; p[1] = ( pixelValue >> 8 ) & 0xff; p[2] = pixelValue & 0xff; } else { p[0] = pixelValue & 0xff; p[1] = ( pixelValue >> 8) & 0xff; p[2] = ( pixelValue >> 16) & 0xff; } break; case 4: *( reinterpret_cast( p ) ) = pixelValue; break; } } static void putPixel( SDL_Surface* surface, int x, int y, const SDL_Color* color ) { Uint32 pixelValue = SDL_MapRGB( surface->format, color->r, color->g, color->b ); putPixel( surface, x, y, pixelValue ); } static void drawLine( SDL_Surface* surface, int x0, int y0, int x1, int y1, const SDL_Color* color ); static void fillRectAlpha( SDL_Surface* surface, SDL_Rect* rect, SDL_Color color, Uint8 alpha ); }; } #endif // SDLWIDGETS_GRAPHICS_H