00001 /* $Id: exploder_composer.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2004 - 2012 by Philippe Plantier <ayin@anathas.org> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #include "exploder_composer.hpp" 00017 #include "SDL_image.h" 00018 00019 #include <iostream> 00020 00021 composer::composer() : interactive_(false), verbose_(false) 00022 { 00023 } 00024 00025 00026 surface composer::compose(const std::string &src, const std::string &dest) 00027 { 00028 cutter cut; 00029 cut.set_verbose(verbose_); 00030 00031 const config src_conf = cut.load_config(src); 00032 const config dest_conf = cut.load_config(dest); 00033 00034 if(verbose_) { 00035 std::cerr << "Loading masks...\n"; 00036 } 00037 cut.load_masks(src_conf); 00038 cut.load_masks(dest_conf); 00039 00040 if(verbose_) { 00041 std::cerr << "Loading images...\n"; 00042 } 00043 const surface src_surface(make_neutral_surface(IMG_Load(src.c_str()))); 00044 if(src_surface == NULL) 00045 throw exploder_failure("Unable to load the source image " + src); 00046 00047 const surface dest_surface(make_neutral_surface(IMG_Load(dest.c_str()))); 00048 if(dest_surface == NULL) 00049 throw exploder_failure("Unable to load the destination image " + dest); 00050 00051 if(verbose_) { 00052 std::cerr << "Cutting images...\n"; 00053 } 00054 const cutter::surface_map src_surfaces = cut.cut_surface(src_surface, src_conf); 00055 const cutter::surface_map dest_surfaces = cut.cut_surface(dest_surface, dest_conf); 00056 00057 for(cutter::surface_map::const_iterator itor = dest_surfaces.begin(); 00058 itor != dest_surfaces.end(); ++itor) { 00059 00060 const std::string& name = itor->second.name; 00061 00062 if(src_surfaces.find(name) == src_surfaces.end()) 00063 continue; 00064 00065 const cutter::positioned_surface& src_ps = src_surfaces.find(name)->second; 00066 const cutter::positioned_surface& dest_ps = itor->second; 00067 00068 if(!image_empty(dest_ps.image)) { 00069 if(interactive_) { 00070 //TODO: make "interactive" mode work 00071 } else { 00072 std::cerr << "Warning: element " << name << " not empty on destination image\n"; 00073 } 00074 } 00075 if(verbose_) { 00076 std::cerr << "Inserting image " << name 00077 << " on position (" << dest_ps.pos.x 00078 << ", " << dest_ps.pos.y << ")\n"; 00079 } 00080 masked_overwrite_surface(dest_surface, src_ps.image, 00081 src_ps.mask.image, 00082 dest_ps.pos.x, dest_ps.pos.y); 00083 } 00084 00085 return dest_surface; 00086 } 00087 00088 void composer::set_interactive(bool value) 00089 { 00090 interactive_ = value; 00091 } 00092 00093 void composer::set_verbose(bool value) 00094 { 00095 verbose_ = value; 00096 } 00097
| Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:54 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |