Author: ilor
Date: Mon Jul 7 18:32:29 2008
New Revision: 27817
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27817&view=rev
Log:
editor2:
* implement invert_selection internally
* make editor_exception derive from std::exception
Modified:
trunk/src/editor2/editor_common.hpp
trunk/src/editor2/editor_map.cpp
trunk/src/editor2/editor_map.hpp
Modified: trunk/src/editor2/editor_common.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_common.hpp?rev=27817&r1=27816&r2=27817&view=diff
==============================================================================
--- trunk/src/editor2/editor_common.hpp (original)
+++ trunk/src/editor2/editor_common.hpp Mon Jul 7 18:32:29 2008
@@ -22,6 +22,8 @@
#define EDITOR2_EDITOR_COMMON_HPP_INCLUDED
#include "../log.hpp"
+#include <stdexcept>
+
#define DBG_ED LOG_STREAM_INDENT(debug, editor)
#define LOG_ED LOG_STREAM_INDENT(info, editor)
#define WRN_ED LOG_STREAM_INDENT(warn, editor)
@@ -31,7 +33,7 @@
namespace editor2 {
-struct editor_exception
+struct editor_exception : public std::exception
{
};
Modified: trunk/src/editor2/editor_map.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.cpp?rev=27817&r1=27816&r2=27817&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.cpp (original)
+++ trunk/src/editor2/editor_map.cpp Mon Jul 7 18:32:29 2008
@@ -59,22 +59,35 @@
{
return selection_.find(loc) != selection_.end();
}
+
bool editor_map::add_to_selection(const gamemap::location& loc)
{
return selection_.insert(loc).second;
}
+
bool editor_map::remove_from_selection(const gamemap::location& loc)
{
return selection_.erase(loc);
}
+
void editor_map::clear_selection()
{
selection_.clear();
}
+
void editor_map::invert_selection()
{
-
+ std::set<gamemap::location> new_selection;
+ for (int x = 0; x < w(); ++x) {
+ for (int y = 0; y < h(); ++y) {
+ if (selection_.find(gamemap::location(x, y)) ==
selection_.end()) {
+ new_selection.insert(gamemap::location(x, y));
+ }
+ }
+ }
+ selection_.swap(new_selection);
}
+
void editor_map::select_all()
{
clear_selection();
Modified: trunk/src/editor2/editor_map.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.hpp?rev=27817&r1=27816&r2=27817&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.hpp (original)
+++ trunk/src/editor2/editor_map.hpp Mon Jul 7 18:32:29 2008
@@ -20,7 +20,7 @@
namespace editor2 {
/**
- * This class adds extra editor-specific functionality to a normal gamemap
+ * This class adds extra editor-specific functionality to a normal gamemap.
*/
class editor_map : public gamemap
@@ -30,14 +30,47 @@
std::vector<gamemap::location> get_tiles_in_radius(const
gamemap::location& center, const unsigned int radius);
static editor_map new_map(const config& terrain_cfg, size_t width,
size_t height, t_translation::t_terrain filler);
+ /**
+ * @return true when the location is part of the selection, false
otherwise
+ */
bool in_selection(const gamemap::location& loc) const;
+
+ /**
+ * Add a location to the selection. The location should be valid (i.e.
on the map)
+ * @return true if the selected hexes set was modified
+ */
bool add_to_selection(const gamemap::location& loc);
+
+ /**
+ * Remove a location to the selection. The location does not actually
have to be selected
+ * @return true if the selected hexes set was modified
+ */
bool remove_from_selection(const gamemap::location& loc);
+
+ /**
+ * Return the selection set.
+ */
const std::set<gamemap::location> selection() const { return
selection_; }
+
+ /**
+ * Clear the selection
+ */
void clear_selection();
+
+ /**
+ * Invert the selection, i.e. select all the map hexes that were not
selected.
+ */
void invert_selection();
+
+ /**
+ * Select all map hexes
+ */
void select_all();
+
protected:
+ /**
+ * The selected hexes
+ */
std::set<gamemap::location> selection_;
};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits