/*************************************************************************** * 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. * ***************************************************************************/ #include "graphics.h" namespace SDLwidgets { void Graphics::drawLine( SDL_Surface* surface, int x0, int y0, int x1, int y1, const SDL_Color* color ) { SDL_PixelFormat* format = surface->format; Uint32 pixelColor = SDL_MapRGB( format, color->r, color->g, color->b ); // special cases if ( x0 == x1 ) { for ( int y = y0; y <= y1; y++ ) { putPixel( surface, x0, y, pixelColor ); } } else if ( y0 == y1 ) { for ( int x = x0; x <= x1; x++ ) { putPixel( surface, x, y0, pixelColor ); } } } void Graphics::fillRectAlpha( SDL_Surface* surface, SDL_Rect* rect, SDL_Color color, Uint8 alpha ) { SDL_Surface* rectSurface = SDL_CreateRGBSurface( SDL_SWSURFACE | SDL_SRCALPHA, rect->w, rect->h, surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask ); Uint32 colorValue = SDL_MapRGB( rectSurface->format, color.r, color.g, color.b ); SDL_FillRect( rectSurface, 0, colorValue ); SDL_SetAlpha( rectSurface, SDL_SRCALPHA | SDL_RLEACCEL, alpha ); SDL_BlitSurface( rectSurface, 0, surface, rect ); SDL_FreeSurface( rectSurface ); } }