Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

drawtile.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     drawtile - draw tiles onto surfaces
00004  
00005     Copyright (C) 2000,2001,2002  Alexander Pipelka
00006  
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011  
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016  
00017     You should have received a copy of the GNU Library General Public
00018     License along with this library; if not, write to the Free
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  
00021     Alexander Pipelka
00022     pipelka@teleweb.at
00023  
00024     Last Update:      $Author: mbickel $
00025     Update Date:      $Date: 2007-04-13 16:16:00 $
00026     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/draw/drawtile.cpp,v $
00027     CVS/RCS Revision: $Revision: 1.2 $
00028     Status:           $State: Exp $
00029 */
00030 
00031 #include "pgdraw.h"
00032 #include <cmath>
00033 
00034 void PG_Draw::DrawTile(SDL_Surface* surface, const PG_Rect& ref, const PG_Rect& drawrect, SDL_Surface* tilemap) {
00035         PG_Point index1;
00036         PG_Point index2;
00037         PG_Rect oldclip;
00038 
00039         if (!surface || !tilemap) {
00040                 return;
00041         }
00042 
00043         if (!tilemap->w || !tilemap->h || !surface->w || !surface->h) {
00044                 return;
00045         }
00046 
00047         int dx = (int)std::abs((double)(drawrect.x - ref.x));
00048         int dy = (int)std::abs((double)(drawrect.y - ref.y));
00049 
00050         index1.x = dx / tilemap->w;
00051         index1.y = dy / tilemap->h;
00052 
00053         index2.x = (dx + drawrect.w + tilemap->w - 1) / tilemap->w;
00054         index2.y = (dy + drawrect.h + tilemap->h - 1) / tilemap->h;
00055 
00056         SDL_GetClipRect(surface, const_cast<PG_Rect*>(&oldclip));
00057         SDL_SetClipRect(surface, const_cast<PG_Rect*>(&drawrect));
00058 
00059         PG_Rect src(0,0, tilemap->w, tilemap->h);
00060         PG_Rect dst = src;
00061 
00062         for(int y = index1.y; y < index2.y; y++) {
00063                 for(int x = index1.x; x < index2.x; x++) {
00064 
00065                         dst.x = ref.x + x * tilemap->w;
00066                         dst.y = ref.y + y * tilemap->h;
00067 
00068                         PG_Draw::BlitSurface(tilemap, src, surface, dst);
00069                 }
00070         }
00071 
00072         SDL_SetClipRect(surface, const_cast<PG_Rect*>(&oldclip));
00073 }

Generated on Tue Jun 24 01:27:39 2008 for Advanced Strategic Command by  doxygen 1.4.2