editor_undo.hpp

Go to the documentation of this file.
00001 /* $Id: editor_undo.hpp 25168 2008-03-26 18:38:50Z boucman $ */
00002 /*
00003   Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
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 version 2
00008   or at your option any later version.
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY.
00011 
00012   See the COPYING file for more details.
00013 */
00014 
00015 // This module is used to manage actions that may be undone in the map
00016 // editor.
00017 
00018 //! @file editor/editor_undo.hpp
00019 //!
00020 
00021 #ifndef EDITOR_UNDO_H_INCLUDED
00022 #define EDITOR_UNDO_H_INCLUDED
00023 
00024 #include "global.hpp"
00025 
00026 #include "map.hpp"
00027 
00028 #include <queue>
00029 #include <vector>
00030 #include <set>
00031 
00032 namespace map_editor {
00033 
00034 //! A saved action that may be undone.
00035 class map_undo_action {
00036 public:
00037     map_undo_action();
00038 
00039     const std::map<gamemap::location, t_translation::t_terrain>& undo_terrains() const;
00040     const std::map<gamemap::location, t_translation::t_terrain>& redo_terrains() const;
00041 
00042     const std::set<gamemap::location> undo_selection() const;
00043     const std::set<gamemap::location> redo_selection() const;
00044 
00045     std::string new_map_data() const;
00046     std::string old_map_data() const;
00047 
00048     const std::map<gamemap::location, int>& undo_starting_locations() const;
00049     const std::map<gamemap::location, int>& redo_starting_locations() const;
00050 
00051     void add_terrain(const t_translation::t_terrain& old_tr,
00052                      const t_translation::t_terrain& new_tr,
00053                      const gamemap::location& lc);
00054 
00055     //! Return true if a terrain change has been saved in this undo
00056     //! action.
00057     bool terrain_set() const;
00058 
00059     void set_selection(const std::set<gamemap::location> &old_selection,
00060                        const std::set<gamemap::location> &new_selection);
00061 
00062     //! Return true if a selection change has been saved in this undo
00063     //! action.
00064     bool selection_set() const;
00065 
00066     void set_map_data(const std::string &old_data,
00067                       const std::string &new_data);
00068 
00069     //! Return true if a map data change has been saved in this undo
00070     //! action.
00071     bool map_data_set() const;
00072 
00073     void add_starting_location(const int old_side, const int new_side,
00074                                const gamemap::location &old_loc,
00075                                const gamemap::location &new_loc);
00076 
00077     //! Return true if starting locations have been saved in this undo
00078     //! action.
00079     bool starting_location_set() const;
00080 
00081     //! Return true if something have been saved in this undo
00082     bool something_set() const;
00083 
00084 private:
00085     std::map<gamemap::location, t_translation::t_terrain> old_terrain_;
00086     std::map<gamemap::location, t_translation::t_terrain> new_terrain_;
00087     bool terrain_set_;
00088     std::set<gamemap::location> old_selection_;
00089     std::set<gamemap::location> new_selection_;
00090     bool selection_set_;
00091     std::string old_map_data_;
00092     std::string new_map_data_;
00093     bool map_data_set_;
00094     std::map<gamemap::location,int> old_starting_locations_;
00095     std::map<gamemap::location,int> new_starting_locations_;
00096     bool starting_locations_set_;
00097 };
00098 
00099 typedef std::deque<map_undo_action> map_undo_list;
00100 
00101 //! Add an undo action to the undo stack. Resize the stack if it gets
00102 //! larger than the maximum size. Add an operation to the number done
00103 //! since save. If keep_selection is true, it indicates that the
00104 //! selection has not changed and the currently selected terrain should
00105 //! be kept if this action is redone/undone. Also clear the redo stack.
00106 void add_undo_action(const map_undo_action &action);
00107 
00108 //! Return true if there exist any undo actions in the undo stack.
00109 bool exist_undo_actions();
00110 //! Return true if there exist any redo actions in the redo stack.
00111 bool exist_redo_actions();
00112 
00113 
00114 //! Remove, store in the redo stack and return the last undo action
00115 //! stored.
00116 map_undo_action pop_undo_action();
00117 
00118 //! Remove, store in the undo stack and return the last redo action
00119 //! stored.
00120 map_undo_action pop_redo_action();
00121 
00122 //! Clear all stored information about performed actions.
00123 void clear_undo_actions();
00124 
00125 }
00126 
00127 
00128 #endif // EDITOR_UNDO_H_INCLUDED

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs