Author: ilor
Date: Sat Jul 26 14:07:30 2008
New Revision: 28215

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28215&view=rev
Log:
editor2: select actions (not bound yet), swap fg/bg hotkey, two mouse drag 
issues fixed

Modified:
    trunk/src/editor2/action.cpp
    trunk/src/editor2/action.hpp
    trunk/src/editor2/editor_controller.cpp
    trunk/src/editor2/editor_palettes.cpp
    trunk/src/editor2/editor_palettes.hpp
    trunk/src/mouse_handler_base.cpp
    trunk/src/mouse_handler_base.hpp

Modified: trunk/src/editor2/action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.cpp?rev=28215&r1=28214&r2=28215&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Sat Jul 26 14:07:30 2008
@@ -97,6 +97,11 @@
        }
 }
 
+bool editor_action_area::add_location(const gamemap::location& loc)
+{
+       return area_.insert(loc).second;
+}
+
 editor_action_paste* editor_action_paste::perform(editor_map& map) const
 {
        map_fragment mf(map, paste_.get_area());
@@ -127,7 +132,6 @@
        perform_without_undo(map);
        return undo;
 }      
-
 void editor_action_paint_area::perform_without_undo(editor_map& map) const
 {
        draw_terrain(map, t_, area_);
@@ -146,6 +150,58 @@
        draw_terrain(map, t_, to_fill);
 }
 
+editor_action_select_xor* editor_action_select_xor::perform(editor_map& map) 
const
+{
+       perform_without_undo(map);
+       return new editor_action_select_xor(area_);
+}
+void editor_action_select_xor::perform_without_undo(editor_map& map) const
+{
+       foreach (const gamemap::location& loc, area_) {
+               if (map.in_selection(loc)) {
+                       map.remove_from_selection(loc);
+               } else {
+                       map.add_to_selection(loc);
+               }
+       }
+}
+
+editor_action_select_xor* editor_action_select::perform(editor_map& map) const
+{
+       std::set<gamemap::location> undo_locs;
+       foreach (const gamemap::location& loc, area_) {
+               if (!map.in_selection(loc)) {
+                       undo_locs.insert(loc);
+               }
+       }
+       perform_without_undo(map);
+       return new editor_action_select_xor(undo_locs);
+}
+void editor_action_select::perform_without_undo(editor_map& map) const
+{
+       foreach (const gamemap::location& loc, area_) {
+               map.add_to_selection(loc);
+       }
+}
+
+editor_action_select_xor* editor_action_deselect::perform(editor_map& map) 
const
+{
+       std::set<gamemap::location> undo_locs;
+       foreach (const gamemap::location& loc, area_) {
+               if (map.in_selection(loc)) {
+                       undo_locs.insert(loc);
+               }
+       }
+       perform_without_undo(map);
+       return new editor_action_select_xor(undo_locs);
+}
+void editor_action_deselect::perform_without_undo(editor_map& map) const
+{
+       foreach (const gamemap::location& loc, area_) {
+               map.remove_from_selection(loc);
+       }
+}
+
 editor_action_whole_map* editor_action_resize_map::perform(editor_map& 
/*map*/) const
 {
        throw editor_action_not_implemented();

Modified: trunk/src/editor2/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=28215&r1=28214&r2=28215&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Sat Jul 26 14:07:30 2008
@@ -90,6 +90,18 @@
         t_translation::t_terrain t_;
 };
 
+class editor_action_area : public editor_action
+{
+    public:
+        editor_action_area(const std::set<gamemap::location>& area)
+        : area_(area)
+        {
+        }
+               bool add_location(const gamemap::location& loc);
+    protected:
+               std::set<gamemap::location> area_;
+};
+
 //paste a region into the map.
 class editor_action_paste : public editor_action_location
 {
@@ -117,19 +129,17 @@
         void perform_without_undo(editor_map& map) const;
 };
 
-class editor_action_paint_area : public editor_action
+class editor_action_paint_area : public editor_action_area
 {
     public:
         editor_action_paint_area(const std::set<gamemap::location>& area, 
                        t_translation::t_terrain t)
-        : area_(area), t_(t)
+        : editor_action_area(area), t_(t)
         {
         }
         editor_action_paste* perform(editor_map& map) const;
         void perform_without_undo(editor_map& map) const;
-               void add_location(const gamemap::location& loc);
-    protected:
-               std::set<gamemap::location> area_;
+    protected:
                t_translation::t_terrain t_;
 };
 
@@ -144,6 +154,39 @@
         }
         editor_action_paint_area* perform(editor_map& map) const;
         void perform_without_undo(editor_map& map) const;
+};
+
+class editor_action_select_xor : public editor_action_area
+{
+       public:
+               editor_action_select_xor(const std::set<gamemap::location>& 
area)
+               : editor_action_area(area)
+               {
+               }
+               editor_action_select_xor* perform(editor_map& map) const;
+               void perform_without_undo(editor_map& map) const;
+};
+
+class editor_action_select : public editor_action_area
+{
+       public:
+               editor_action_select(const std::set<gamemap::location>& area)
+               : editor_action_area(area)
+               {
+               }
+               editor_action_select_xor* perform(editor_map& map) const;
+               void perform_without_undo(editor_map& map) const;
+};
+
+class editor_action_deselect : public editor_action_area
+{
+       public:
+               editor_action_deselect(const std::set<gamemap::location>& area)
+               : editor_action_area(area)
+               {
+               }
+               editor_action_select_xor* perform(editor_map& map) const;
+               void perform_without_undo(editor_map& map) const;
 };
 
 //resize map (streching / clipping behaviour?)

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28215&r1=28214&r2=28215&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Sat Jul 26 14:07:30 2008
@@ -272,6 +272,7 @@
                case HOTKEY_EDITOR_MAP_SAVE_AS:
                case HOTKEY_EDITOR_BRUSH_NEXT:
                case HOTKEY_EDITOR_TOOL_NEXT:
+               case HOTKEY_EDITOR_TERRAIN_PALETTE_SWAP:
                        return true; //editor hotkeys we can always do
                case HOTKEY_EDITOR_MAP_SAVE:
                case HOTKEY_EDITOR_MAP_REVERT:
@@ -330,6 +331,9 @@
                case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
                        quit_confirm(EXIT_QUIT_TO_DESKTOP);
                        return true;
+               case HOTKEY_EDITOR_TERRAIN_PALETTE_SWAP:
+                       palette_->swap();
+                       return true;
                case HOTKEY_EDITOR_TOOL_PAINT:
                case HOTKEY_EDITOR_TOOL_FILL:
 //             case HOTKEY_EDITOR_TOOL_SELECT:
@@ -471,7 +475,8 @@
 {
        if (mouse_handler_base::mouse_motion_default(x, y, update)) return;
        gamemap::location hex_clicked = gui().hex_clicked_on(x, y);
-       if (dragging_) {
+       if (dragging_ && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LEFT) != 0
+       && map_.on_board_with_border(drag_from_hex_)) {
                if (!map_.on_board_with_border(hex_clicked)) return;
                if (get_mouse_action() != NULL) {
                        LOG_ED << "Mouse drag\n";

Modified: trunk/src/editor2/editor_palettes.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_palettes.cpp?rev=28215&r1=28214&r2=28215&view=diff
==============================================================================
--- trunk/src/editor2/editor_palettes.cpp (original)
+++ trunk/src/editor2/editor_palettes.cpp Sat Jul 26 14:07:30 2008
@@ -254,6 +254,13 @@
        }
 }
 
+void terrain_palette::swap()
+{
+       std::swap(selected_fg_terrain_, selected_bg_terrain_);
+       set_dirty();
+       update_report();
+}
+
 
 //! After the language is changed, the selected terrains needs an update.
 void terrain_palette::update_selected_terrains(void)

Modified: trunk/src/editor2/editor_palettes.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_palettes.hpp?rev=28215&r1=28214&r2=28215&view=diff
==============================================================================
--- trunk/src/editor2/editor_palettes.hpp (original)
+++ trunk/src/editor2/editor_palettes.hpp Sat Jul 26 14:07:30 2008
@@ -74,6 +74,8 @@
        t_translation::t_terrain selected_fg_terrain() const;
        //! Return the currently selected background terrain.
        t_translation::t_terrain selected_bg_terrain() const;
+       
+       void swap();
 
        //! Select a foreground terrain.
        void select_fg_terrain(t_translation::t_terrain);

Modified: trunk/src/mouse_handler_base.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_handler_base.cpp?rev=28215&r1=28214&r2=28215&view=diff
==============================================================================
--- trunk/src/mouse_handler_base.cpp (original)
+++ trunk/src/mouse_handler_base.cpp Sat Jul 26 14:07:30 2008
@@ -128,6 +128,7 @@
                        dragging_ = true;
                        dragging_started_ = false;
                        SDL_GetMouseState(&drag_from_x_, &drag_from_y_);
+                       drag_from_hex_ = gui().hex_clicked_on(drag_from_x_, 
drag_from_y_);
                }
        } else if(is_right_click(event) && event.state == SDL_PRESSED) {
                // The first right-click cancel the selection if any,

Modified: trunk/src/mouse_handler_base.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_handler_base.hpp?rev=28215&r1=28214&r2=28215&view=diff
==============================================================================
--- trunk/src/mouse_handler_base.hpp (original)
+++ trunk/src/mouse_handler_base.hpp Sat Jul 26 14:07:30 2008
@@ -86,6 +86,7 @@
        bool dragging_started_;
        int drag_from_x_;
        int drag_from_y_;
+       gamemap::location drag_from_hex_;
 
        // last highlighted hex
        gamemap::location last_hex_;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to