Author: ilor
Date: Thu Jul 31 00:58:00 2008
New Revision: 28278
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28278&view=rev
Log:
editor2: select all, invert selection, everything_changed member in map_context
Modified:
trunk/data/themes/editor2.cfg
trunk/src/editor2/action.cpp
trunk/src/editor2/action.hpp
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/editor_map.cpp
trunk/src/editor2/editor_map.hpp
trunk/src/editor2/map_context.cpp
trunk/src/editor2/map_context.hpp
trunk/src/hotkeys.cpp
trunk/src/hotkeys.hpp
Modified: trunk/data/themes/editor2.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/themes/editor2.cfg?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/data/themes/editor2.cfg (original)
+++ trunk/data/themes/editor2.cfg Thu Jul 31 00:58:00 2008
@@ -130,7 +130,7 @@
id=menu-editor-edit
title= _ "Edit"
image=lite
-
items=undo,redo,editor-cut,editor-copy,editor-paste,editor-select-all,editor-selection-rotate,editor-selection-flip,editor-selection-generate,editor-selection-randomize
+
items=undo,redo,editor-cut,editor-copy,editor-paste,editor-select-all,editor-select-inverse,editor-selection-rotate,editor-selection-flip,editor-selection-generate,editor-selection-randomize
rect="+2,=,+100,="
xanchor=fixed
yanchor=fixed
Modified: trunk/src/editor2/action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.cpp?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Thu Jul 31 00:58:00 2008
@@ -20,6 +20,8 @@
#include "map_context.hpp"
#include "../foreach.hpp"
+
+#include <algorithm>
namespace editor2 {
@@ -181,6 +183,36 @@
}
}
+editor_action_select_xor* editor_action_select_all::perform(map_context& mc)
const
+{
+
+ std::set<gamemap::location> current = mc.get_map().selection();
+ mc.get_map().select_all();
+ std::set<gamemap::location> all = mc.get_map().selection();
+ std::set<gamemap::location> undo_locs;
+ std::set_difference(all.begin(), all.end(),
+ current.begin(), current.end(),
+ std::inserter(undo_locs, undo_locs.begin()));
+ mc.set_everything_changed();
+ return new editor_action_select_xor(undo_locs);
+}
+void editor_action_select_all::perform_without_undo(map_context& mc) const
+{
+ mc.get_map().select_all();
+ mc.set_everything_changed();
+}
+
+editor_action_select_inverse*
editor_action_select_inverse::perform(map_context& mc) const
+{
+ perform_without_undo(mc);
+ return new editor_action_select_inverse();
+}
+void editor_action_select_inverse::perform_without_undo(map_context& mc) const
+{
+ mc.get_map().invert_selection();
+ mc.set_everything_changed();
+}
+
void editor_action_resize_map::perform_without_undo(map_context& mc) const
{
mc.get_map().resize(x_size_, y_size_, x_offset_, y_offset_);
Modified: trunk/src/editor2/action.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Thu Jul 31 00:58:00 2008
@@ -189,6 +189,26 @@
void perform_without_undo(map_context& mc) const;
};
+class editor_action_select_all : public editor_action
+{
+ public:
+ editor_action_select_all()
+ {
+ }
+ editor_action_select_xor* perform(map_context& mc) const;
+ void perform_without_undo(map_context& mc) const;
+};
+
+class editor_action_select_inverse : public editor_action
+{
+ public:
+ editor_action_select_inverse()
+ {
+ }
+ editor_action_select_inverse* perform(map_context& mc) const;
+ void perform_without_undo(map_context& mc) const;
+};
+
//resize map (streching / clipping behaviour?)
class editor_action_resize_map : public editor_action
{
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Thu Jul 31 00:58:00 2008
@@ -248,6 +248,7 @@
void editor_controller::revert_map()
{
+ if (!confirm_discard()) return;
const std::string& filename = get_map_context().get_filename();
if (filename.empty()) {
ERR_ED << "Empty filename in map revert\n";
@@ -385,6 +386,16 @@
case HOTKEY_EDITOR_CUT:
cut_selection();
return true;
+ case HOTKEY_EDITOR_SELECT_ALL:
+ if (!get_map_context().get_map().everything_selected())
{
+
get_map_context().perform_action(editor_action_select_all());
+ refresh_after_action();
+ return true;
+ } //else intentionally fall through
+ case HOTKEY_EDITOR_SELECT_INVERSE:
+
get_map_context().perform_action(editor_action_select_inverse());
+ refresh_after_action();
+ return true;
case HOTKEY_EDITOR_MAP_FLIP_X: {
editor_action_flip_x fx;
get_map_context().perform_action(fx);
@@ -569,7 +580,11 @@
get_map_context().set_needs_terrain_rebuild(false);
get_map_context().clear_changed_locations();
} else {
- gui().invalidate(get_map_context().changed_locations());
+ if (get_map_context().everything_changed()) {
+ gui().invalidate_all();
+ } else {
+ gui().invalidate(get_map_context().changed_locations());
+ }
get_map_context().clear_changed_locations();
}
gui().recalculate_minimap();
Modified: trunk/src/editor2/editor_map.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.cpp?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.cpp (original)
+++ trunk/src/editor2/editor_map.cpp Thu Jul 31 00:58:00 2008
@@ -102,8 +102,8 @@
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) {
+ for (int x = -1; x < w() + 1; ++x) {
+ for (int y = -1; y < h() + 1; ++y) {
if (selection_.find(gamemap::location(x, y)) ==
selection_.end()) {
new_selection.insert(gamemap::location(x, y));
}
@@ -116,6 +116,12 @@
{
clear_selection();
invert_selection();
+}
+
+bool editor_map::everything_selected() const
+{
+ LOG_ED << selection_.size() << " " << total_width() * total_height() <<
"\n";
+ return selection_.size() == total_width() * total_height();
}
void editor_map::resize(int width, int height, int x_offset, int y_offset,
Modified: trunk/src/editor2/editor_map.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.hpp?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.hpp (original)
+++ trunk/src/editor2/editor_map.hpp Thu Jul 31 00:58:00 2008
@@ -85,6 +85,8 @@
* Select all map hexes
*/
void select_all();
+
+ bool everything_selected() const;
/**
* Resize the map. If the filler is NONE, the border terrain will be
copied
Modified: trunk/src/editor2/map_context.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/map_context.cpp?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/src/editor2/map_context.cpp (original)
+++ trunk/src/editor2/map_context.cpp Thu Jul 31 00:58:00 2008
@@ -32,7 +32,7 @@
map_context::map_context(const editor_map& map)
: map_(map), filename_(), actions_since_save_(0),
-needs_reload_(false), needs_terrain_rebuild_(false)
+needs_reload_(false), needs_terrain_rebuild_(false), everything_changed_(false)
{
}
@@ -82,11 +82,34 @@
}
}
+void map_context::clear_changed_locations()
+{
+ everything_changed_ = false;
+ changed_locations_.clear();
+}
+
+void map_context::add_changed_location(const gamemap::location& loc)
+{
+ if (!everything_changed()) {
+ changed_locations_.insert(loc);
+ }
+}
+
void map_context::add_changed_location(const std::set<gamemap::location>& locs)
{
- foreach (const gamemap::location& loc, locs) {
- changed_locations_.insert(loc);
- }
+ if (!everything_changed()) {
+ changed_locations_.insert(locs.begin(), locs.end());
+ }
+}
+
+void map_context::set_everything_changed()
+{
+ everything_changed_ = true;
+}
+
+bool map_context::everything_changed() const
+{
+ return everything_changed_;
}
void map_context::clear_starting_position_labels(display& disp)
Modified: trunk/src/editor2/map_context.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/map_context.hpp?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/src/editor2/map_context.hpp (original)
+++ trunk/src/editor2/map_context.hpp Thu Jul 31 00:58:00 2008
@@ -49,9 +49,11 @@
void set_needs_terrain_rebuild(bool value=true) {
needs_terrain_rebuild_ = value; }
const std::set<gamemap::location> changed_locations() const { return
changed_locations_; }
- void clear_changed_locations() { changed_locations_.clear(); }
- void add_changed_location(const gamemap::location& loc) {
changed_locations_.insert(loc); }
+ void clear_changed_locations();
+ void add_changed_location(const gamemap::location& loc);
void add_changed_location(const std::set<gamemap::location>& locs);
+ void set_everything_changed();
+ bool everything_changed() const;
void clear_starting_position_labels(display& disp);
@@ -152,6 +154,7 @@
bool needs_reload_;
bool needs_terrain_rebuild_;
std::set<gamemap::location> changed_locations_;
+ bool everything_changed_;
};
Modified: trunk/src/hotkeys.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.cpp?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/src/hotkeys.cpp (original)
+++ trunk/src/hotkeys.cpp Thu Jul 31 00:58:00 2008
@@ -152,6 +152,8 @@
{ hotkey::HOTKEY_EDITOR_PASTE, "editor-paste", N_("Paste"), false,
hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SELECT_ALL, "editor-select-all",
N_("Select All"), false, hotkey::SCOPE_EDITOR },
+ { hotkey::HOTKEY_EDITOR_SELECT_INVERSE, "editor-select-inverse",
+ N_("Invert Selection"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SELECTION_ROTATE, "editor-selection-rotate",
N_("Rotate Selection"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SELECTION_FLIP, "editor-selection-flip",
Modified: trunk/src/hotkeys.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.hpp?rev=28278&r1=28277&r2=28278&view=diff
==============================================================================
--- trunk/src/hotkeys.hpp (original)
+++ trunk/src/hotkeys.hpp Thu Jul 31 00:58:00 2008
@@ -79,7 +79,7 @@
HOTKEY_EDITOR_TOOL_SELECT, HOTKEY_EDITOR_TOOL_STARTING_POSITION,
HOTKEY_EDITOR_BRUSH_NEXT, HOTKEY_EDITOR_BRUSH_DEFAULT,
HOTKEY_EDITOR_CUT, HOTKEY_EDITOR_COPY, HOTKEY_EDITOR_PASTE,
- HOTKEY_EDITOR_SELECT_ALL,
+ HOTKEY_EDITOR_SELECT_ALL, HOTKEY_EDITOR_SELECT_INVERSE,
HOTKEY_EDITOR_SELECTION_ROTATE, HOTKEY_EDITOR_SELECTION_FLIP,
HOTKEY_EDITOR_SELECTION_GENERATE, HOTKEY_EDITOR_SELECTION_RANDOMIZE,
HOTKEY_EDITOR_MAP_RESIZE, HOTKEY_EDITOR_MAP_ROTATE,
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits