Author: ilor
Date: Mon Jul 14 23:18:06 2008
New Revision: 28035

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28035&view=rev
Log:
Editor2: map_fragment class, fill, paint_area and paste actions, make undo fill 
work

Added:
    trunk/src/editor2/map_fragment.cpp   (with props)
    trunk/src/editor2/map_fragment.hpp   (with props)
Modified:
    trunk/src/CMakeLists.txt
    trunk/src/Makefile.am
    trunk/src/SConscript
    trunk/src/editor2/action.cpp
    trunk/src/editor2/action.hpp

Modified: trunk/src/CMakeLists.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=28035&r1=28034&r2=28035&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Mon Jul 14 23:18:06 2008
@@ -310,6 +310,7 @@
     editor2/editor_map.cpp
     editor2/editor_mode.cpp
     editor2/editor_mouse_handler.cpp
+    editor2/map_fragment.cpp
     editor2/mouse_action.cpp
 )
 

Modified: trunk/src/Makefile.am
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/Makefile.am?rev=28035&r1=28034&r2=28035&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Mon Jul 14 23:18:06 2008
@@ -155,6 +155,7 @@
        editor2/editor_map.cpp \
        editor2/editor_mode.cpp \
        editor2/editor_mouse_handler.cpp \
+       editor2/map_fragment.cpp \
        editor2/mouse_action.cpp
 
 if EDITOR2

Modified: trunk/src/SConscript
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=28035&r1=28034&r2=28035&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Mon Jul 14 23:18:06 2008
@@ -247,6 +247,7 @@
     editor2/editor_map.cpp
     editor2/editor_mode.cpp
     editor2/editor_mouse_handler.cpp
+    editor2/map_fragment.cpp
     editor2/mouse_action.cpp
     """)
     

Modified: trunk/src/editor2/action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.cpp?rev=28035&r1=28034&r2=28035&view=diff
==============================================================================
--- trunk/src/editor2/action.cpp (original)
+++ trunk/src/editor2/action.cpp Mon Jul 14 23:18:06 2008
@@ -59,13 +59,16 @@
        }
 }
 
-editor_action_paste* editor_action_paste::perform(editor_map& /*map*/) const
+editor_action_paste* editor_action_paste::perform(editor_map& map) const
 {
-       throw editor_action_not_implemented();
+       map_fragment mf(map, paste_.get_area());
+       editor_action_paste* undo = new 
editor_action_paste(gamemap::location(0,0), mf);
+       perform_without_undo(map);
+       return undo;
 }
-void editor_action_paste::perform_without_undo(editor_map& /*map*/) const
+void editor_action_paste::perform_without_undo(editor_map& map) const
 {
-       throw editor_action_not_implemented();
+       paste_.paste_into(map, loc_);
 }
 
 editor_action_paint_hex* editor_action_paint_hex::perform(editor_map& map) 
const
@@ -79,27 +82,39 @@
        map.set_terrain(loc_, t_);
 }
 
-editor_action_paste* editor_action_paint_brush::perform(editor_map& /*map*/) 
const
+editor_action_paste* editor_action_paint_area::perform(editor_map& map) const
 {
-       throw editor_action_not_implemented();
-}
-void editor_action_paint_brush::perform_without_undo(editor_map& /*map*/) const
+       map_fragment mf(map, area_);
+       editor_action_paste* undo = new 
editor_action_paste(gamemap::location(0,0), mf);
+       perform_without_undo(map);
+       return undo;
+}      
+
+void editor_action_paint_area::perform_without_undo(editor_map& map) const
 {
-       throw editor_action_not_implemented();
+       foreach (gamemap::location loc, area_) {
+               map.set_terrain(loc, t_);
+       }
 }
 
-editor_action_fill* editor_action_fill::perform(editor_map& map) const
+editor_action_paint_area* editor_action_fill::perform(editor_map& map) const
 {
-       editor_action_fill* undo = new editor_action_fill(loc_, 
map.get_terrain(loc_));
-       perform_without_undo(map);
-       return undo;    
+       std::set<gamemap::location> to_fill = 
map.get_contigious_terrain_tiles(loc_);
+       editor_action_paint_area* undo = new editor_action_paint_area(to_fill, 
map.get_terrain(loc_));
+       perform_actual(map, to_fill);
+       return undo;
 }
 void editor_action_fill::perform_without_undo(editor_map& map) const
 {
        std::set<gamemap::location> to_fill = 
map.get_contigious_terrain_tiles(loc_);
+       perform_actual(map, to_fill);
+}
+
+void editor_action_fill::perform_actual(editor_map& map, const 
std::set<gamemap::location>& to_fill) const
+{
        foreach (gamemap::location l, to_fill) {
                map.set_terrain(l, t_);
-       }
+       }       
 }
 
 editor_action_whole_map* editor_action_resize_map::perform(editor_map& 
/*map*/) const

Modified: trunk/src/editor2/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=28035&r1=28034&r2=28035&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Mon Jul 14 23:18:06 2008
@@ -20,6 +20,7 @@
 
 #include "action_base.hpp"
 #include "editor_map.hpp"
+#include "map_fragment.hpp"
 #include "../map.hpp"
 #include "../terrain.hpp"
 
@@ -119,18 +120,17 @@
 };
 
 //paste a region into the map.
-//The paste data will most likely be a gamemap with some sort of mask
 class editor_action_paste : public editor_action_location
 {
     public:
-        editor_action_paste(gamemap::location loc, gamemap paste)
+        editor_action_paste(const gamemap::location& loc, const map_fragment& 
paste)
         : editor_action_location(loc), paste_(paste)
         {
         }
         editor_action_paste* perform(editor_map& map) const;
         void perform_without_undo(editor_map& map) const;
     protected:
-        gamemap paste_;
+        map_fragment paste_;
 };
 
 //replace a hex at a given location with a given terrain
@@ -146,32 +146,19 @@
         void perform_without_undo(editor_map& map) const;
 };
 
-class editor_action_paint_many : public editor_action
-{
-       public:
-               editor_action_paint_many(std::set<gamemap::location> locs, 
t_translation::t_terrain t)
-               : locs_(locs), t_(t)
-               {
-               }
-       protected:
-               std::set<gamemap::location> locs_;
+class editor_action_paint_area : public editor_action
+{
+    public:
+        editor_action_paint_area(std::set<gamemap::location> area, 
+                       t_translation::t_terrain t)
+        : area_(area), t_(t)
+        {
+        }
+        editor_action_paste* perform(editor_map& map) const;
+        void perform_without_undo(editor_map& map) const;
+    protected:
+               std::set<gamemap::location> area_;
                t_translation::t_terrain t_;
-};
-
-//paint a terrain on the map with a brush. The brush is a special mask type
-//note that undo in this case is a paste not a brush paint.
-class editor_action_paint_brush : public editor_action_location_terrain
-{
-    public:
-        editor_action_paint_brush(gamemap::location loc, 
-                       t_translation::t_terrain t, const brush& b)
-        : editor_action_location_terrain(loc, t), b_(b)
-        {
-        }
-        editor_action_paste* perform(editor_map& map) const;
-        void perform_without_undo(editor_map& map) const;
-    protected:
-        const brush& b_;
 };
 
 //flood fill
@@ -183,8 +170,9 @@
         : editor_action_location_terrain(loc, t)
         {
         }
-        editor_action_fill* perform(editor_map& map) const;
-        void perform_without_undo(editor_map& map) const;
+        editor_action_paint_area* perform(editor_map& map) const;
+        void perform_without_undo(editor_map& map) const;
+               void perform_actual(editor_map& map, const 
std::set<gamemap::location>& to_fill) const;
 };
 
 //resize map (streching / clipping behaviour?)

Added: trunk/src/editor2/map_fragment.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/map_fragment.cpp?rev=28035&view=auto
==============================================================================
--- trunk/src/editor2/map_fragment.cpp (added)
+++ trunk/src/editor2/map_fragment.cpp Mon Jul 14 23:18:06 2008
@@ -1,0 +1,55 @@
+/* $Id$ */
+/*
+   Copyright (C) 2008 by Tomasz Sniatowski <[EMAIL PROTECTED]>
+   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License version 2
+   or at your option any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY.
+
+   See the COPYING file for more details.
+*/
+
+#include "map_fragment.hpp"
+
+#include "../foreach.hpp"
+
+#include <vector>
+
+namespace editor2 {
+
+map_fragment::map_fragment()
+{
+}
+
+map_fragment::map_fragment(const gamemap& map, const 
std::set<gamemap::location>& area)
+{
+       foreach (const gamemap::location& loc, area) {
+               add_tile(map, loc);
+       }
+}
+
+void map_fragment::add_tile(const gamemap& map, const gamemap::location& loc)
+{
+       items_.push_back(tile_info(loc, map.get_terrain(loc)));
+}
+
+std::set<gamemap::location> map_fragment::get_area() const
+{
+       std::set<gamemap::location> result;
+       foreach (const tile_info& i, items_) {
+               result.insert(i.offset);
+       }
+       return result;
+}
+
+void map_fragment::paste_into(gamemap& map, const gamemap::location& loc) const
+{
+       foreach (const tile_info& i, items_) {
+               map.set_terrain(i.offset + loc, i.terrain);
+       }
+}
+
+} //end namespace editor2

Propchange: trunk/src/editor2/map_fragment.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/src/editor2/map_fragment.cpp
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Added: trunk/src/editor2/map_fragment.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/map_fragment.hpp?rev=28035&view=auto
==============================================================================
--- trunk/src/editor2/map_fragment.hpp (added)
+++ trunk/src/editor2/map_fragment.hpp Mon Jul 14 23:18:06 2008
@@ -1,0 +1,51 @@
+/* $Id$ */
+/*
+   Copyright (C) 2008 by Tomasz Sniatowski <[EMAIL PROTECTED]>
+   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License version 2
+   or at your option any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY.
+
+   See the COPYING file for more details.
+*/
+
+#ifndef EDITOR2_MAP_FRAGMENT_HPP_INCLUDED
+#define EDITOR2_MAP_FRAGMENT_HPP_INCLUDED
+
+#include "editor_map.hpp"
+
+#include "../config.hpp"
+
+#include <set>
+
+namespace editor2 {
+
+struct tile_info
+{
+       tile_info(const gamemap::location& offset, t_translation::t_terrain 
terrain)
+       : offset(offset), terrain(terrain)
+       {
+       }
+       gamemap::location offset;
+       t_translation::t_terrain terrain;
+};
+       
+class map_fragment
+{
+       public:
+               map_fragment();
+               map_fragment(const gamemap& map, const 
std::set<gamemap::location>& area);
+               void add_tile(const gamemap& map, const gamemap::location& loc);
+               const std::vector<tile_info>& get_items() const { return 
items_; }
+               std::set<gamemap::location> get_area() const;
+               void paste_into(gamemap& map, const gamemap::location& loc) 
const;
+       private:
+               std::vector<tile_info> items_;
+};
+
+} //end namespace editor2
+
+#endif

Propchange: trunk/src/editor2/map_fragment.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/src/editor2/map_fragment.hpp
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'


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

Reply via email to