00001 /* $Id: brush.cpp 53571 2012-03-20 20:24:19Z fendrin $ */ 00002 /* 00003 Copyright (C) 2008 - 2012 by Tomasz Sniatowski <kailoran@gmail.com> 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 #define GETTEXT_DOMAIN "wesnoth-editor" 00016 00017 #include "brush.hpp" 00018 #include "editor/editor_common.hpp" 00019 00020 #include "foreach.hpp" 00021 #include "pathutils.hpp" 00022 00023 namespace editor { 00024 00025 /*WIKI 00026 * @page = EditorWML 00027 * @order = 1_header 00028 * 00029 * {{AutogeneratedWML}} 00030 * 00031 * = Brush = 00032 * 00033 * Each brush tag defines one brush. (0,0) is the hotspot, that is, the brush 00034 * is always moved so the mouse is over the brush's (0,0) coordinate. The 00035 * following keys and tags are recognized: 00036 * 00037 * (Note the 1.5 version and the mandatory image are for testing only.) 00038 * 00039 * @begin{description}{wml_reference} 00040 * name & string & "" & & 00041 * Name for the brush (will possibly show up in the tooltip for the 00042 * brush). $ 00043 * image & filename & "" & & 00044 * Icon for the brush to de displayed on the toolbar. $ 00045 * radius & integer & 0 & & 00046 * Include in the brushall hexes that are this or closer to the center 00047 * of the brush, excluding the (0,0) point. $ 00048 * [relative] & node & 1 & & Include in the brush a single hex with 00049 * coordinates relative from the center of the brush. $ 00050 * 00051 * @begin{description}{wml_reference} 00052 * x & int & 0 & & The relative x coordinate. $ 00053 * y & int & 0 & & The relative y coordinate. $ 00054 * @end{description} 00055 * 00056 * @end{description} 00057 * A brush that has neither a radius nor any [relative] hexes will be empty 00058 * which is not desired and a warning or error is to be expected. 00059 */ 00060 00061 brush::brush() 00062 : relative_tiles_() 00063 , name_() 00064 , image_() 00065 { 00066 } 00067 00068 brush::brush(const config& cfg) 00069 : relative_tiles_() 00070 , name_(cfg["name"]) 00071 , image_(cfg["image"]) 00072 { 00073 int radius = cfg["radius"]; 00074 if (radius > 0) { 00075 std::vector<map_location> in_radius; 00076 get_tiles_in_radius(map_location(0, 0), radius, in_radius); 00077 foreach (map_location& loc, in_radius) { 00078 add_relative_location(loc.x, loc.y); 00079 } 00080 } 00081 foreach (const config &relative, cfg.child_range("relative")) 00082 { 00083 int x = relative["x"]; 00084 int y = relative["y"]; 00085 add_relative_location(x, y); 00086 } 00087 if (relative_tiles_.empty()) { 00088 WRN_ED << "Empty brush definition, name=" << name_ << "\n"; 00089 } 00090 } 00091 00092 void brush::add_relative_location(int relative_x, int relative_y) 00093 { 00094 relative_tiles_.insert(map_location(relative_x, relative_y)); 00095 } 00096 00097 std::set<map_location> brush::project(const map_location& hotspot) const 00098 { 00099 std::set<map_location> result; 00100 foreach (const map_location& relative, relative_tiles_) { 00101 result.insert(relative.vector_sum(hotspot)); 00102 } 00103 return result; 00104 } 00105 00106 00107 } //end namespace editor
| Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:37 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |