Mercurial > fife-parpg
comparison engine/core/loaders/native/video_loaders/subimage_loader.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 #include <iostream> | |
24 | |
25 // 3rd party library includes | |
26 #include <SDL.h> | |
27 #include <boost/lexical_cast.hpp> | |
28 | |
29 // FIFE includes | |
30 // These includes are split up in two parts, separated by one empty line | |
31 // First block: files included from the FIFE root src directory | |
32 // Second block: files included from the same folder | |
33 #include "video/image.h" | |
34 #include "video/renderbackend.h" | |
35 #include "video/image_location.h" | |
36 #include "util/base/fife_stdint.h" | |
37 #include "util/resource/resource.h" | |
38 #include "util/base/exception.h" | |
39 #include "util/log/logger.h" | |
40 | |
41 #include "subimage_loader.h" | |
42 | |
43 namespace FIFE { | |
44 static Logger _log(LM_NATIVE_LOADERS); | |
45 | |
46 IResource* SubImageLoader::loadResource(const ResourceLocation& location) { | |
47 const ImageLocation* loc = dynamic_cast<const ImageLocation*>(&location); | |
48 if (!loc) { | |
49 // Wrong location type given for subimage provider | |
50 return NULL; | |
51 } | |
52 Image* r = loc->getParentSource(); | |
53 if (!r) { | |
54 // No parent source assigned, cannot provide subimage | |
55 return NULL; | |
56 } | |
57 SDL_Surface* src = r->getSurface(); | |
58 if (!src) { | |
59 return NULL; | |
60 } | |
61 SDL_Rect src_rect; | |
62 src_rect.x = loc->getXShift(); | |
63 src_rect.y = loc->getYShift(); | |
64 src_rect.w = loc->getWidth(); | |
65 src_rect.h = loc->getHeight(); | |
66 | |
67 FL_DBG(_log, LMsg("subimage_loader") | |
68 << " rect:" << Rect(src_rect.x,src_rect.y,src_rect.w,src_rect.h)); | |
69 | |
70 uint32_t Amask = src->format->Amask ? AMASK : 0; | |
71 SDL_Surface* result = SDL_CreateRGBSurface(SDL_SWSURFACE, src_rect.w, src_rect.h, 32, | |
72 RMASK, GMASK, BMASK, Amask); | |
73 SDL_FillRect(result, NULL, 0); | |
74 SDL_SetAlpha(src,0,SDL_ALPHA_OPAQUE); | |
75 SDL_BlitSurface(src,&src_rect,result,0); | |
76 | |
77 return RenderBackend::instance()->createImage(result); | |
78 }; | |
79 | |
80 } |