00001 /* $Id: exploder_composer.cpp 23842 2008-02-16 08:47:16Z mordante $ */ 00002 /* 00003 Copyright (C) 2004 - 2008 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 version 2 00008 or at your option any later version. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 #include "exploder_composer.hpp" 00016 #include "SDL_image.h" 00017 00018 composer::composer() : interactive_(false), verbose_(false) 00019 { 00020 } 00021 00022 00023 surface composer::compose(const std::string &src, const std::string &dest) 00024 { 00025 cutter cut; 00026 cut.set_verbose(verbose_); 00027 00028 const config src_conf = cut.load_config(src); 00029 const config dest_conf = cut.load_config(dest); 00030 00031 if(verbose_) { 00032 std::cerr << "Loading masks...\n"; 00033 } 00034 cut.load_masks(src_conf); 00035 cut.load_masks(dest_conf); 00036 00037 if(verbose_) { 00038 std::cerr << "Loading images...\n"; 00039 } 00040 const surface src_surface(make_neutral_surface(IMG_Load(src.c_str()))); 00041 if(src_surface == NULL) 00042 throw exploder_failure("Unable to load the source image " + src); 00043 00044 const surface dest_surface(make_neutral_surface(IMG_Load(dest.c_str()))); 00045 if(dest_surface == NULL) 00046 throw exploder_failure("Unable to load the destination image " + dest); 00047 00048 if(verbose_) { 00049 std::cerr << "Cutting images...\n"; 00050 } 00051 const cutter::surface_map src_surfaces = cut.cut_surface(src_surface, src_conf); 00052 const cutter::surface_map dest_surfaces = cut.cut_surface(dest_surface, dest_conf); 00053 00054 for(cutter::surface_map::const_iterator itor = dest_surfaces.begin(); 00055 itor != dest_surfaces.end(); ++itor) { 00056 00057 const std::string& name = itor->second.name; 00058 00059 if(src_surfaces.find(name) == src_surfaces.end()) 00060 continue; 00061 00062 const cutter::positioned_surface& src_ps = src_surfaces.find(name)->second; 00063 const cutter::positioned_surface& dest_ps = itor->second; 00064 00065 if(!image_empty(dest_ps.image)) { 00066 if(interactive_) { 00067 //TODO: make "interactive" mode work 00068 } else { 00069 std::cerr << "Warning: element " << name << " not empty on destination image\n"; 00070 } 00071 } 00072 if(verbose_) { 00073 std::cerr << "Inserting image " << name 00074 << " on position (" << dest_ps.pos.x 00075 << ", " << dest_ps.pos.y << ")\n"; 00076 } 00077 masked_overwrite_surface(dest_surface, src_ps.image, 00078 src_ps.mask.image, 00079 dest_ps.pos.x, dest_ps.pos.y); 00080 } 00081 00082 return dest_surface; 00083 } 00084 00085 void composer::set_interactive(bool value) 00086 { 00087 interactive_ = value; 00088 } 00089 00090 void composer::set_verbose(bool value) 00091 { 00092 verbose_ = value; 00093 } 00094
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |