Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes

editor::map_context Class Reference

This class wraps around a map to provide a concise interface for the editor to work with. More...

#include <map_context.hpp>

Collaboration diagram for editor::map_context:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 map_context (const editor_map &map)
 Create a map context from an existing map.
 map_context (const config &game_config, const std::string &filename, const display &disp)
 Create map_context from a map file.
 ~map_context ()
 Map context destructor.
editor_mapget_map ()
 Map accesor.
const editor_mapget_map () const
 Map accesor - const version.
void draw_terrain (t_translation::t_terrain terrain, const map_location &loc, bool one_layer_only=false)
 Draw a terrain on a single location on the map.
void draw_terrain_actual (t_translation::t_terrain terrain, const map_location &loc, bool one_layer_only=false)
 Actual drawing function used by both overloaded variants of draw_terrain.
void draw_terrain (t_translation::t_terrain terrain, const std::set< map_location > &locs, bool one_layer_only=false)
 Draw a terrain on a set of locations on the map.
bool needs_reload () const
 Getter for the reload flag.
void set_needs_reload (bool value=true)
 Setter for the reload flag.
bool needs_terrain_rebuild () const
 Getter for the terrain rebuild flag.
void set_needs_terrain_rebuild (bool value=true)
 Setter for the terrain rebuild flag.
bool needs_labels_reset () const
 Getter fo the labels reset flag.
void set_needs_labels_reset (bool value=true)
 Setter for the labels reset flag.
const std::set< map_locationchanged_locations () const
void clear_changed_locations ()
void add_changed_location (const map_location &loc)
void add_changed_location (const std::set< map_location > &locs)
void set_everything_changed ()
bool everything_changed () const
void set_labels (display &disp)
void clear_starting_position_labels (display &disp)
void set_starting_position_labels (display &disp)
void reset_starting_position_labels (display &disp)
const std::string & get_filename () const
void set_filename (const std::string &fn)
const std::string & get_map_data_key () const
bool is_embedded () const
void set_embedded (bool v)
bool save ()
 Saves the map under the current filename.
void set_map (const editor_map &map)
void perform_action (const editor_action &action)
 Performs an action (thus modyfying the map).
void perform_partial_action (const editor_action &action)
 Performs a partial action, assumes that the top undo action has been modified to maintain coherent state of the undo stacks, and so a new undo action is not created.
bool modified () const
void clear_modified ()
 Clear the modified state.
bool can_undo () const
bool can_redo () const
editor_actionlast_undo_action ()
editor_actionlast_redo_action ()
const editor_actionlast_undo_action () const
 const version of last_undo_action
const editor_actionlast_redo_action () const
 const version of last_redo_action
void undo ()
 Un-does the last action, and puts it in the redo stack for a possible redo.
void redo ()
 Re-does a previousle undid action, and puts it back in the undo stack.
void partial_undo ()
 Un-does a single step from a undo action chain.
void clear_undo_redo ()
 Clear the undo and redo stacks.

Protected Types

typedef std::deque
< editor_action * > 
action_stack
 Container type used to store actions in the undo and redo stacks.

Protected Member Functions

void trim_stack (action_stack &stack)
 Checks if an action stack reached its capacity and removes the front element if so.
void clear_stack (action_stack &stack)
 Clears an action stack and deletes all its contents.
void perform_action_between_stacks (action_stack &from, action_stack &to)
 Perform an action at the back of one stack, and then move it to the back of the other stack.

Protected Attributes

std::string filename_
 The actual filename of this map.
std::string map_data_key_
 When a scenario file is loaded, the referenced map is loaded instead.
bool embedded_
 Whether the map context refers to a map embedded in a scenario file.
editor_map map_
 The map object of this map_context.
action_stack undo_stack_
 The undo stack.
action_stack redo_stack_
 The redo stack.
int actions_since_save_
 Number of actions performed since the map was saved.
std::set< map_locationstarting_position_label_locs_
 Cache of set starting position labels.
bool needs_reload_
 Refresh flag indicating the map in this context should be completely reloaded by the display.
bool needs_terrain_rebuild_
 Refresh flag indicating the terrain in the map has changed and requires a rebuild.
bool needs_labels_reset_
 Refresh flag indicating the labels in the map have changed.
std::set< map_locationchanged_locations_
bool everything_changed_

Static Protected Attributes

static const size_t max_action_stack_size_ = 100
 Action stack (i.e.

Detailed Description

This class wraps around a map to provide a concise interface for the editor to work with.

The actual map object can change rapidly (be assigned to), the map context persists data (like the undo stacks) in this case. The functionality is here, not in editor_controller as e.g. the undo stack is part of the map, not the editor as a whole. This might allow many maps to be open at the same time.

Definition at line 33 of file map_context.hpp.


Member Typedef Documentation

typedef std::deque<editor_action*> editor::map_context::action_stack [protected]

Container type used to store actions in the undo and redo stacks.

Definition at line 236 of file map_context.hpp.


Constructor & Destructor Documentation

editor::map_context::map_context ( const editor_map map  )  [explicit]

Create a map context from an existing map.

The filename is set to be empty, indicating a new map. Marked "explicit" to avoid automatic conversions.

Definition at line 40 of file map_context.cpp.

editor::map_context::map_context ( const config game_config,
const std::string &  filename,
const display disp 
)

Create map_context from a map file.

If the map cannot be loaded, an exception will be thrown and the object will not be constructed. If the map file is a scenario, the map specified in its map_data key will be loaded, and the stored filename updated accordingly. Maps embedded inside scenarios do not change the filename, but set the "embedded" flag instead.

Definition at line 57 of file map_context.cpp.

References _, directory_name(), embedded_, file_exists(), filename_, editor::editor_map::from_string(), get_wml_location(), is_directory(), LOG_ED, log_editor, log_scope2, map_, map_data_key_, read(), and read_file().

Here is the call graph for this function:

editor::map_context::~map_context (  ) 

Map context destructor.

Definition at line 126 of file map_context.cpp.

References clear_stack(), redo_stack_, and undo_stack_.

Here is the call graph for this function:


Member Function Documentation

void editor::map_context::add_changed_location ( const map_location loc  ) 

Definition at line 180 of file map_context.cpp.

References changed_locations_, and everything_changed().

Referenced by draw_terrain_actual().

Here is the call graph for this function:

Here is the caller graph for this function:

void editor::map_context::add_changed_location ( const std::set< map_location > &  locs  ) 

Definition at line 187 of file map_context.cpp.

References changed_locations_, and everything_changed().

Here is the call graph for this function:

bool editor::map_context::can_redo (  )  const
Returns:
true when redo can be performed, false otherwise

Definition at line 335 of file map_context.cpp.

References redo_stack_.

Referenced by redo().

Here is the caller graph for this function:

bool editor::map_context::can_undo (  )  const
Returns:
true when undo can be performed, false otherwise

Definition at line 330 of file map_context.cpp.

References undo_stack_.

Referenced by partial_undo(), perform_partial_action(), and undo().

Here is the caller graph for this function:

const std::set<map_location> editor::map_context::changed_locations (  )  const [inline]

Definition at line 119 of file map_context.hpp.

References changed_locations_.

Referenced by editor::context_manager::refresh_after_action().

Here is the caller graph for this function:

void editor::map_context::clear_changed_locations (  ) 

Definition at line 174 of file map_context.cpp.

References changed_locations_, and everything_changed_.

Referenced by editor::context_manager::refresh_after_action(), and editor::context_manager::refresh_all().

Here is the caller graph for this function:

void editor::map_context::clear_modified (  ) 

Clear the modified state.

Definition at line 325 of file map_context.cpp.

References actions_since_save_.

Referenced by save().

Here is the caller graph for this function:

void editor::map_context::clear_stack ( action_stack stack  )  [protected]

Clears an action stack and deletes all its contents.

Helper function used when the undo or redo stack needs to be cleared

Definition at line 420 of file map_context.cpp.

Referenced by clear_undo_redo(), perform_action(), perform_partial_action(), and ~map_context().

Here is the caller graph for this function:

void editor::map_context::clear_starting_position_labels ( display disp  ) 

Definition at line 204 of file map_context.cpp.

References map_labels::clear_all(), display::labels(), and starting_position_label_locs_.

Referenced by reset_starting_position_labels().

Here is the call graph for this function:

Here is the caller graph for this function:

void editor::map_context::clear_undo_redo (  ) 

Clear the undo and redo stacks.

Definition at line 406 of file map_context.cpp.

References clear_stack(), redo_stack_, and undo_stack_.

Here is the call graph for this function:

void editor::map_context::draw_terrain ( t_translation::t_terrain  terrain,
const std::set< map_location > &  locs,
bool  one_layer_only = false 
)

Draw a terrain on a set of locations on the map.

Sets the refresh flags accordingly.

Definition at line 163 of file map_context.cpp.

References draw_terrain_actual(), gamemap::get_terrain_info(), map_, and terrain_type::terrain_with_default_base().

Here is the call graph for this function:

void editor::map_context::draw_terrain ( t_translation::t_terrain  terrain,
const map_location loc,
bool  one_layer_only = false 
)

Draw a terrain on a single location on the map.

Sets the refresh flags accordingly.

Definition at line 132 of file map_context.cpp.

References draw_terrain_actual(), gamemap::get_terrain_info(), map_, and terrain_type::terrain_with_default_base().

Referenced by editor::editor_action_starting_position::clone(), and editor::editor_action_fill::clone().

Here is the call graph for this function:

Here is the caller graph for this function:

void editor::map_context::draw_terrain_actual ( t_translation::t_terrain  terrain,
const map_location loc,
bool  one_layer_only = false 
)

Actual drawing function used by both overloaded variants of draw_terrain.

Definition at line 141 of file map_context.cpp.

References add_changed_location(), gamemap::BASE, t_translation::t_terrain::base, gamemap::get_terrain(), LOG_ED, map_, t_translation::NO_LAYER, gamemap::on_board_with_border(), gamemap::OVERLAY, and gamemap::set_terrain().

Referenced by draw_terrain().

Here is the call graph for this function:

Here is the caller graph for this function:

bool editor::map_context::everything_changed (  )  const

Definition at line 199 of file map_context.cpp.

References everything_changed_.

Referenced by add_changed_location().

Here is the caller graph for this function:

const std::string& editor::map_context::get_filename (  )  const [inline]
const editor_map& editor::map_context::get_map (  )  const [inline]

Map accesor - const version.

Definition at line 66 of file map_context.hpp.

References map_.

editor_map& editor::map_context::get_map (  )  [inline]
const std::string& editor::map_context::get_map_data_key (  )  const [inline]

Definition at line 138 of file map_context.hpp.

References map_data_key_.

Referenced by editor::context_manager::load_map().

Here is the caller graph for this function:

bool editor::map_context::is_embedded (  )  const [inline]

Definition at line 140 of file map_context.hpp.

References embedded_.

Referenced by editor::context_manager::load_map(), save(), and editor::context_manager::save_map_as().

Here is the caller graph for this function:

editor_action * editor::map_context::last_redo_action (  ) 
Returns:
a pointer to the last redo action or NULL if the undo stack is empty

Definition at line 345 of file map_context.cpp.

References redo_stack_.

const editor_action * editor::map_context::last_redo_action (  )  const

const version of last_redo_action

Definition at line 355 of file map_context.cpp.

References redo_stack_.

editor_action * editor::map_context::last_undo_action (  ) 
Returns:
a pointer to the last undo action or NULL if the undo stack is empty

Definition at line 340 of file map_context.cpp.

References undo_stack_.

Referenced by partial_undo(), and perform_partial_action().

Here is the caller graph for this function:

const editor_action * editor::map_context::last_undo_action (  )  const

const version of last_undo_action

Definition at line 350 of file map_context.cpp.

References undo_stack_.

bool editor::map_context::modified (  )  const
Returns:
whether the map was modified since the last save

Definition at line 320 of file map_context.cpp.

References actions_since_save_.

Referenced by editor::context_manager::modified_maps().

Here is the caller graph for this function:

bool editor::map_context::needs_labels_reset (  )  const [inline]

Getter fo the labels reset flag.

Set when the labels need to be refreshed.

Definition at line 112 of file map_context.hpp.

References needs_labels_reset_.

bool editor::map_context::needs_reload (  )  const [inline]

Getter for the reload flag.

Reload is the highest level of required refreshing, set when the map size has changed or the map was reassigned.

Definition at line 92 of file map_context.hpp.

References needs_reload_.

bool editor::map_context::needs_terrain_rebuild (  )  const [inline]

Getter for the terrain rebuild flag.

Set whenever any terrain has changed.

Definition at line 102 of file map_context.hpp.

References needs_terrain_rebuild_.

void editor::map_context::partial_undo (  ) 

Un-does a single step from a undo action chain.

The action is separated from the chain and it's undo (the redo) is added as a standalone action to the redo stack. Precodnition: the last undo action has to actually be an action chain.

Definition at line 384 of file map_context.cpp.

References actions_since_save_, can_undo(), editor::editor_action_chain::empty(), last_undo_action(), editor::editor_action_chain::pop_first_action(), redo_stack_, and undo_stack_.

Here is the call graph for this function:

void editor::map_context::perform_action ( const editor_action action  ) 

Performs an action (thus modyfying the map).

An appropriate undo action is added to the undo stack. The redo stack is cleared. Note that this may throw, use caution when calling this with a dereferennced pointer that you own (i.e. use a smart pointer).

Definition at line 288 of file map_context.cpp.

References actions_since_save_, clear_stack(), editor::editor_action::get_id(), editor::editor_action::get_instance_count(), editor::editor_action::get_name(), LOG_ED, editor::editor_action::perform(), redo_stack_, trim_stack(), undo(), and undo_stack_.

Referenced by editor::context_manager::perform_refresh().

Here is the call graph for this function:

Here is the caller graph for this function:

void editor::map_context::perform_action_between_stacks ( action_stack from,
action_stack to 
) [protected]

Perform an action at the back of one stack, and then move it to the back of the other stack.

This is the implementation of both undo and redo which only differ in the direction.

Definition at line 428 of file map_context.cpp.

References trim_stack().

Referenced by redo(), and undo().

Here is the call graph for this function:

Here is the caller graph for this function:

void editor::map_context::perform_partial_action ( const editor_action action  ) 

Performs a partial action, assumes that the top undo action has been modified to maintain coherent state of the undo stacks, and so a new undo action is not created.

Definition at line 304 of file map_context.cpp.

References can_undo(), clear_stack(), editor::editor_action::get_id(), editor::editor_action::get_instance_count(), editor::editor_action::get_name(), last_undo_action(), LOG_ED, editor::editor_action::perform(), editor::editor_action_chain::prepend_action(), redo_stack_, and undo().

Here is the call graph for this function:

void editor::map_context::redo (  ) 

Re-does a previousle undid action, and puts it back in the undo stack.

Definition at line 372 of file map_context.cpp.

References actions_since_save_, can_redo(), LOG_ED, perform_action_between_stacks(), redo_stack_, undo_stack_, and WRN_ED.

Here is the call graph for this function:

void editor::map_context::reset_starting_position_labels ( display disp  ) 

Definition at line 216 of file map_context.cpp.

References clear_starting_position_labels(), set_needs_labels_reset(), and set_starting_position_labels().

Referenced by editor::context_manager::refresh_after_action(), and editor::context_manager::reload_map().

Here is the call graph for this function:

Here is the caller graph for this function:

bool editor::map_context::save (  ) 

Saves the map under the current filename.

Filename must be valid. May throw an exception on failure.

Definition at line 223 of file map_context.cpp.

References _, clear_modified(), get_filename(), is_embedded(), map_, game_logic::msg(), read_file(), vgettext(), game::error::what(), config_writer::write(), editor::editor_map::write(), write_file(), and writer().

Referenced by editor::context_manager::write_map().

Here is the call graph for this function:

Here is the caller graph for this function:

void editor::map_context::set_embedded ( bool  v  )  [inline]

Definition at line 142 of file map_context.hpp.

References embedded_.

Referenced by editor::context_manager::save_map_as().

Here is the caller graph for this function:

void editor::map_context::set_everything_changed (  ) 

Definition at line 194 of file map_context.cpp.

References everything_changed_.

Referenced by editor::editor_action_resize_map::clone(), editor::editor_action_select_inverse::clone(), and editor::editor_action_select_none::clone().

Here is the caller graph for this function:

void editor::map_context::set_filename ( const std::string &  fn  )  [inline]

Definition at line 136 of file map_context.hpp.

References filename_.

Referenced by editor::context_manager::save_all_maps(), and editor::context_manager::save_map_as().

Here is the caller graph for this function:

void editor::map_context::set_labels ( display disp  ) 
void editor::map_context::set_map ( const editor_map map  ) 

Definition at line 278 of file map_context.cpp.

References gamemap::h(), map_, set_needs_reload(), set_needs_terrain_rebuild(), and gamemap::w().

Here is the call graph for this function:

void editor::map_context::set_needs_labels_reset ( bool  value = true  )  [inline]

Setter for the labels reset flag.

Definition at line 117 of file map_context.hpp.

References needs_labels_reset_.

Referenced by reset_starting_position_labels().

Here is the caller graph for this function:

void editor::map_context::set_needs_reload ( bool  value = true  )  [inline]

Setter for the reload flag.

Definition at line 97 of file map_context.hpp.

References needs_reload_.

Referenced by editor::editor_action_apply_mask::clone(), editor::context_manager::reload_map(), and set_map().

Here is the caller graph for this function:

void editor::map_context::set_needs_terrain_rebuild ( bool  value = true  )  [inline]
void editor::map_context::set_starting_position_labels ( display disp  ) 

Definition at line 210 of file map_context.cpp.

References map_, editor::editor_map::set_starting_position_labels(), and starting_position_label_locs_.

Referenced by reset_starting_position_labels().

Here is the call graph for this function:

Here is the caller graph for this function:

void editor::map_context::trim_stack ( action_stack stack  )  [protected]

Checks if an action stack reached its capacity and removes the front element if so.

Definition at line 412 of file map_context.cpp.

References max_action_stack_size_.

Referenced by perform_action(), and perform_action_between_stacks().

Here is the caller graph for this function:

void editor::map_context::undo (  ) 

Un-does the last action, and puts it in the redo stack for a possible redo.

Definition at line 360 of file map_context.cpp.

References actions_since_save_, can_undo(), LOG_ED, perform_action_between_stacks(), redo_stack_, undo_stack_, and WRN_ED.

Referenced by perform_action(), and perform_partial_action().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Number of actions performed since the map was saved.

Zero means the map was not modified.

Definition at line 279 of file map_context.hpp.

Referenced by clear_modified(), modified(), partial_undo(), perform_action(), redo(), and undo().

Whether the map context refers to a map embedded in a scenario file.

This distinction is important in order to avoid overwriting the scenario.

Definition at line 225 of file map_context.hpp.

Referenced by is_embedded(), map_context(), and set_embedded().

std::string editor::map_context::filename_ [protected]

The actual filename of this map.

An empty string indicates a new map.

Definition at line 213 of file map_context.hpp.

Referenced by get_filename(), map_context(), and set_filename().

The map object of this map_context.

Definition at line 230 of file map_context.hpp.

Referenced by draw_terrain(), draw_terrain_actual(), get_map(), map_context(), save(), set_map(), and set_starting_position_labels().

std::string editor::map_context::map_data_key_ [protected]

When a scenario file is loaded, the referenced map is loaded instead.

The verbatim form of the reference is kept here.

Definition at line 219 of file map_context.hpp.

Referenced by get_map_data_key(), and map_context().

const size_t editor::map_context::max_action_stack_size_ = 100 [static, protected]

Action stack (i.e.

undo and redo) maximum size

Definition at line 274 of file map_context.hpp.

Referenced by trim_stack().

Refresh flag indicating the labels in the map have changed.

Definition at line 299 of file map_context.hpp.

Referenced by needs_labels_reset(), and set_needs_labels_reset().

Refresh flag indicating the map in this context should be completely reloaded by the display.

Definition at line 289 of file map_context.hpp.

Referenced by needs_reload(), and set_needs_reload().

Refresh flag indicating the terrain in the map has changed and requires a rebuild.

Definition at line 294 of file map_context.hpp.

Referenced by needs_terrain_rebuild(), and set_needs_terrain_rebuild().

Cache of set starting position labels.

Necessary for removing them.

Definition at line 284 of file map_context.hpp.

Referenced by clear_starting_position_labels(), and set_starting_position_labels().

The undo stack.

A double-ended queues due to the need to add items to one end, and remove from both when performing the undo or when trimming the size. This container owns all contents, i.e. no action in the stack shall be deleted, and unless otherwise noted the contents could be deleted at an time during normal operation of the stack. To work on an action, either remove it from the container or make a copy. Actions are inserted at the back of the container and disappear from the front when the capacity is exceeded.

Todo:
Use boost's pointer-owning container?

Definition at line 264 of file map_context.hpp.

Referenced by can_undo(), clear_undo_redo(), last_undo_action(), partial_undo(), perform_action(), redo(), undo(), and ~map_context().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:19:55 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs