FIFE 2008.0
|
00001 /*************************************************************************** 00002 * Copyright (C) 2005-2008 by the FIFE team * 00003 * http://www.fifengine.de * 00004 * This file is part of FIFE. * 00005 * * 00006 * FIFE is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Lesser General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2.1 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * Lesser General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with this library; if not, write to the * 00018 * Free Software Foundation, Inc., * 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00020 ***************************************************************************/ 00021 00022 // Standard C++ library includes 00023 #include <iostream> 00024 00025 // 3rd party library includes 00026 #include <SDL.h> 00027 #include <boost/lexical_cast.hpp> 00028 00029 // FIFE includes 00030 // These includes are split up in two parts, separated by one empty line 00031 // First block: files included from the FIFE root src directory 00032 // Second block: files included from the same folder 00033 #include "video/image.h" 00034 #include "video/renderbackend.h" 00035 #include "video/image_location.h" 00036 #include "util/base/fife_stdint.h" 00037 #include "util/resource/resource.h" 00038 #include "util/base/exception.h" 00039 #include "util/log/logger.h" 00040 00041 #include "subimage_loader.h" 00042 00043 namespace FIFE { 00044 static Logger _log(LM_NATIVE_LOADERS); 00045 00046 IResource* SubImageLoader::loadResource(const ResourceLocation& location) { 00047 const ImageLocation* loc = dynamic_cast<const ImageLocation*>(&location); 00048 if (!loc) { 00049 // Wrong location type given for subimage provider 00050 return NULL; 00051 } 00052 Image* r = loc->getParentSource(); 00053 if (!r) { 00054 // No parent source assigned, cannot provide subimage 00055 return NULL; 00056 } 00057 SDL_Surface* src = r->getSurface(); 00058 if (!src) { 00059 return NULL; 00060 } 00061 SDL_Rect src_rect; 00062 src_rect.x = loc->getXShift(); 00063 src_rect.y = loc->getYShift(); 00064 src_rect.w = loc->getWidth(); 00065 src_rect.h = loc->getHeight(); 00066 00067 FL_DBG(_log, LMsg("subimage_loader") 00068 << " rect:" << Rect(src_rect.x,src_rect.y,src_rect.w,src_rect.h)); 00069 00070 uint32_t Amask = src->format->Amask ? AMASK : 0; 00071 SDL_Surface* result = SDL_CreateRGBSurface(SDL_SWSURFACE, src_rect.w, src_rect.h, 32, 00072 RMASK, GMASK, BMASK, Amask); 00073 SDL_FillRect(result, NULL, 0); 00074 SDL_SetAlpha(src,0,SDL_ALPHA_OPAQUE); 00075 SDL_BlitSurface(src,&src_rect,result,0); 00076 00077 Image* image = RenderBackend::instance()->createImage(result); 00078 image->setResourceLocation(location); 00079 return image; 00080 }; 00081 00082 }