map_editor::map_editor Class Reference

A map editor. Receives SDL events and can execute hotkey commands. More...

#include <editor.hpp>

Inheritance diagram for map_editor::map_editor:

Inheritance graph
[legend]
Collaboration diagram for map_editor::map_editor:

Collaboration graph
[legend]

List of all members.

Public Types

enum  ABORT_MODE { DONT_ABORT, ABORT_NORMALLY, ABORT_HARD }
 How to abort the map editor. More...

Public Member Functions

 map_editor (editor_display &gui, editormap &map, config &theme, config &game_config)
virtual ~map_editor ()
void main_loop ()
 Enter the main loop.
void set_file_to_save_as (const std::string, bool from_scenario)
 Set the filename that map should be saved as.
void set_abort (const ABORT_MODE abort=ABORT_NORMALLY)
 Set the abort flag, which indicates if the editor should exit in some way after the current iteration of the main loop.
bool save_map (const std::string filename="", const bool display_confirmation=true)
 Save the current map.
virtual void handle_event (const SDL_Event &event)
void handle_keyboard_event (const SDL_KeyboardEvent &event, const int mousex, const int mousey)
 Handle a keyboard event.
void handle_mouse_button_event (const SDL_MouseButtonEvent &event, const int mousex, const int mousey)
 Handle a mouse button event.
bool changed_since_save () const
 Return true if the map has changed since the last time it was saved.
void redraw_everything ()
 Recalculate layout and redraw everything.
virtual void change_language ()
virtual void toggle_grid ()
virtual void undo ()
virtual void redo ()
virtual void preferences ()
virtual void edit_quit ()
virtual void edit_new_map ()
virtual void edit_load_map ()
virtual void edit_save_map ()
virtual void edit_save_as ()
virtual void edit_set_start_pos ()
 Display a dialog asking for a player number and set the starting position of the given player to the currently selected hex.
virtual void edit_flood_fill ()
virtual void edit_fill_selection ()
virtual void edit_rotate_selection ()
virtual void edit_cut ()
virtual void edit_copy ()
virtual void edit_paste ()
virtual void edit_revert ()
virtual void edit_resize ()
virtual void edit_flip ()
virtual void edit_select_all ()
 Either select or deselect all hexes on the map depending on if this operations has been invoked before or not.
virtual void edit_draw ()
virtual void edit_refresh ()
virtual void edit_update ()
virtual void edit_auto_update ()
void perform_flood_fill (const t_translation::t_terrain fill_with)
void perform_paste ()
void perform_set_starting_pos ()
virtual bool can_execute_command (hotkey::HOTKEY_COMMAND command, int) const
virtual hotkey::ACTION_STATE get_action_state (hotkey::HOTKEY_COMMAND command) const

Private Types

enum  LEFT_BUTTON_HELD_FUNC {
  DRAW_TERRAIN, DRAW_TERRAIN_LAYER, ADD_SELECTION, REMOVE_SELECTION,
  MOVE_SELECTION, NONE
}
 What to perform while the left button is held down. More...
enum  LEFT_BUTTON_FUNC {
  DRAW, SELECT_HEXES, FLOOD_FILL, SET_STARTING_POSITION,
  PASTE, NUM_L_BUTTON_FUNC
}
 What to perform on a left button click. More...
typedef std::vector< buffer_itemmap_buffer

Private Member Functions

void left_button_down (const int mousex, const int mousey)
 Called in every iteration when the left mouse button is held down.
void left_click (const gamemap::location loc)
 Handle a left click on the location.
void right_button_down (const int mousex, const int mousey)
 Called in every iteration when the right mouse button is held down.
void right_click (const gamemap::location loc)
 Handle a right click on the location.
void middle_button_down (const int mousex, const int mousey)
 Called in every iteration when the middle mouse button is held down.
bool confirm_exit_and_save ()
 Confirm that exiting is desired and ask for saving of the map.
void set_starting_position (const int player, const gamemap::location loc)
 Set the starting position for the given player to the location given.
bool verify_filename (const std::string &filename, bool show_error) const
 Check whether the filename contains illegal characters.
void show_menu (const std::vector< std::string > &items_arg, const int xloc, const int yloc, const bool context_menu=false)
 Display a menu with given items and at the given location.
void execute_command (const hotkey::HOTKEY_COMMAND command)
 Pass the command onto the hotkey handling system.
void draw_terrain (const t_translation::t_terrain terrain, const std::vector< gamemap::location > &hexes, const bool one_layer_only)
 Draw terrain at a location.
void recalculate_starting_pos_labels ()
 Re-set the labels for the starting positions of the players.
void update_mouse_over_hexes (const gamemap::location mouse_over_hex)
 Update the selection and highlightning of the hexes the mouse currently is over.
void insert_selection_in_clipboard ()
 Insert the currently selected locations in the clipboard.
void perform_fill_hexes (std::set< gamemap::location > &fill_hexes, const t_translation::t_terrain terrain, map_undo_action &undo_action)
 Commit hexes filling.
void perform_selection_move ()
 Commit the movement of a selection.
void highlight_selected_hexes (const bool clear_old=true)
 Highlight the currently selected hexes.
void clear_highlighted_hexes_in_gui ()
 Clear the highlighted hexes in the gui and set a variable to indicate this so that the brush size highlighting may be refreshed.
void set_mouseover_overlay ()
void reset_mouseover_overlay ()
void terrain_changed (const gamemap::location &hex)
 Terrain has changed at the specified hex through user drawing (not undo/redo or other special things).
void save_undo_action (const map_undo_action &action)
 Save an action so that it may be undone.
void left_button_func_changed (const LEFT_BUTTON_FUNC func)
 Call when the left mouse button function has changed.
void update_l_button_palette ()
 Draw black squares around the buttons that are used to select the left button function and draw a read square around the currently selected function.
std::string get_action_name (const LEFT_BUTTON_FUNC func) const
 Return the hotkey-string representing the left button function.
bool is_left_button_func_menu (const theme::menu &menu) const
 Return true if the menu is a button used for setting the left mouse button function.
void draw_on_mouseover_hexes (const t_translation::t_terrain t, const bool one_layer_only=false)
 Draw the terrain on the hexes the mouse is over, taking account for brush size.
void load_tooltips (void)
void copy_buffer (map_buffer &buffer, const std::set< gamemap::location > &locs, const gamemap::location &origin)
void paste_buffer (const map_buffer &buffer, const gamemap::location &loc, map_undo_action &undo_action)
void clear_buffer (map_buffer &buffer)

Private Attributes

editor_displaygui_
editormapmap_
std::string filename_
std::string original_filename_
bool from_scenario_
ABORT_MODE abort_
size_specs size_specs_
configtheme_
configgame_config_
CKey key_
gamemap::location selected_hex_
bool map_dirty_
bool auto_update_
bool l_button_palette_dirty_
bool everything_dirty_
terrain_palette palette_
brush_bar brush_
std::vector< gamemap::locationstarting_positions_
std::set< gamemap::locationmouse_over_hexes_
std::set< gamemap::locationselected_hexes_
map_buffer clipboard_
LEFT_BUTTON_HELD_FUNC l_button_held_func_
gamemap::location selection_move_start_
tooltips::manager tooltip_manager_
font::floating_label_context floating_label_manager_
bool mouse_moved_
bool highlighted_locs_cleared_
const hotkey::manager hotkey_manager_
const preferences::display_manager prefs_disp_manager_
bool all_hexes_selected_

Static Private Attributes

static int num_operations_since_save_ = 0
static config prefs_
static config hotkeys_
static bool first_time_created_ = true
static LEFT_BUTTON_FUNC l_button_func_ = PASTE
static t_translation::t_terrain old_fg_terrain_
static t_translation::t_terrain old_bg_terrain_
static int old_brush_size_

Classes

struct  buffer_item
 An item in the buffer. More...
struct  load_map_exception
 Exception thrown when the loading of a map failed. More...
struct  new_map_exception
 Exception thrown when new map is to be loaded. More...


Detailed Description

A map editor. Receives SDL events and can execute hotkey commands.

Definition at line 50 of file editor.hpp.


Member Typedef Documentation

typedef std::vector<buffer_item> map_editor::map_editor::map_buffer [private]

Definition at line 292 of file editor.hpp.


Member Enumeration Documentation

How to abort the map editor.

DONT_ABORT is set during normal operation. When ABORT_NORMALLY is set, the editor asks for confirmation and if save is desired before it exits. When ABORT_HARD is set, the editor exists without asking any questions or saving.

Enumerator:
DONT_ABORT 
ABORT_NORMALLY 
ABORT_HARD 

Definition at line 69 of file editor.hpp.

What to perform while the left button is held down.

Enumerator:
DRAW_TERRAIN 
DRAW_TERRAIN_LAYER 
ADD_SELECTION 
REMOVE_SELECTION 
MOVE_SELECTION 
NONE 

Definition at line 158 of file editor.hpp.

What to perform on a left button click.

Enumerator:
DRAW 
SELECT_HEXES 
FLOOD_FILL 
SET_STARTING_POSITION 
PASTE 
NUM_L_BUTTON_FUNC 

Definition at line 162 of file editor.hpp.


Constructor & Destructor Documentation

map_editor::map_editor::map_editor ( editor_display gui,
editormap map,
config theme,
config game_config 
)

virtual map_editor::map_editor::~map_editor (  )  [virtual]


Member Function Documentation

void map_editor::map_editor::main_loop (  ) 

Enter the main loop.

The loop runs until set_abort() is called to set an abort mode which makes the loop exit.

Referenced by main().

void map_editor::map_editor::set_file_to_save_as ( const std::string  ,
bool  from_scenario 
)

Set the filename that map should be saved as.

Referenced by main().

void map_editor::map_editor::set_abort ( const ABORT_MODE  abort = ABORT_NORMALLY  ) 

Set the abort flag, which indicates if the editor should exit in some way after the current iteration of the main loop.

bool map_editor::map_editor::save_map ( const std::string  filename = "",
const bool  display_confirmation = true 
)

Save the current map.

If filename is an empty string, use the filename that is set with set_file_to_save_as(). A message box that shows confirmation that the map was saved is shown if display_confirmation is true. Return false if the save failed.

virtual void map_editor::map_editor::handle_event ( const SDL_Event &  event  )  [virtual]

Implements events::handler.

void map_editor::map_editor::handle_keyboard_event ( const SDL_KeyboardEvent &  event,
const int  mousex,
const int  mousey 
)

Handle a keyboard event.

mousex and mousey is the current position of the mouse.

void map_editor::map_editor::handle_mouse_button_event ( const SDL_MouseButtonEvent &  event,
const int  mousex,
const int  mousey 
)

Handle a mouse button event.

mousex and mousey is the current position of the mouse.

bool map_editor::map_editor::changed_since_save (  )  const

Return true if the map has changed since the last time it was saved.

void map_editor::map_editor::redraw_everything (  ) 

Recalculate layout and redraw everything.

virtual void map_editor::map_editor::change_language (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::toggle_grid (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::undo (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::redo (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::preferences (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_quit (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_new_map (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_load_map (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_save_map (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_save_as (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_set_start_pos (  )  [virtual]

Display a dialog asking for a player number and set the starting position of the given player to the currently selected hex.

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_flood_fill (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_fill_selection (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_rotate_selection (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_cut (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_copy (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_paste (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_revert (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_resize (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_flip (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_select_all (  )  [virtual]

Either select or deselect all hexes on the map depending on if this operations has been invoked before or not.

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_draw (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_refresh (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_update (  )  [virtual]

Reimplemented from hotkey::command_executor.

virtual void map_editor::map_editor::edit_auto_update (  )  [virtual]

Reimplemented from hotkey::command_executor.

void map_editor::map_editor::perform_flood_fill ( const t_translation::t_terrain  fill_with  ) 

void map_editor::map_editor::perform_paste (  ) 

void map_editor::map_editor::perform_set_starting_pos (  ) 

virtual bool map_editor::map_editor::can_execute_command ( hotkey::HOTKEY_COMMAND  command,
int   
) const [virtual]

virtual hotkey::ACTION_STATE map_editor::map_editor::get_action_state ( hotkey::HOTKEY_COMMAND  command  )  const [virtual]

Reimplemented from hotkey::command_executor.

void map_editor::map_editor::left_button_down ( const int  mousex,
const int  mousey 
) [private]

Called in every iteration when the left mouse button is held down.

Note that this differs from a click.

void map_editor::map_editor::left_click ( const gamemap::location  loc  )  [private]

Handle a left click on the location.

void map_editor::map_editor::right_button_down ( const int  mousex,
const int  mousey 
) [private]

Called in every iteration when the right mouse button is held down.

Note that this differs from a click.

void map_editor::map_editor::right_click ( const gamemap::location  loc  )  [private]

Handle a right click on the location.

void map_editor::map_editor::middle_button_down ( const int  mousex,
const int  mousey 
) [private]

Called in every iteration when the middle mouse button is held down.

Note that this differs from a click.

bool map_editor::map_editor::confirm_exit_and_save (  )  [private]

Confirm that exiting is desired and ask for saving of the map.

Return true if exit is confirmed and the save is successful or not wanted. Return false if exit is cancelled or the requested save failed.

void map_editor::map_editor::set_starting_position ( const int  player,
const gamemap::location  loc 
) [private]

Set the starting position for the given player to the location given.

bool map_editor::map_editor::verify_filename ( const std::string &  filename,
bool  show_error 
) const [private]

Check whether the filename contains illegal characters.

void map_editor::map_editor::show_menu ( const std::vector< std::string > &  items_arg,
const int  xloc,
const int  yloc,
const bool  context_menu = false 
) [private]

Display a menu with given items and at the given location.

void map_editor::map_editor::execute_command ( const hotkey::HOTKEY_COMMAND  command  )  [private]

Pass the command onto the hotkey handling system.

Quit requests are intercepted because the editor does not want the default behavior of those.

void map_editor::map_editor::draw_terrain ( const t_translation::t_terrain  terrain,
const std::vector< gamemap::location > &  hexes,
const bool  one_layer_only 
) [private]

Draw terrain at a location.

The operation is saved in the undo stack. Update the map to reflect the change.

void map_editor::map_editor::recalculate_starting_pos_labels (  )  [private]

Re-set the labels for the starting positions of the players.

Should be called when the terrain has changed, which may have changed the starting positions.

void map_editor::map_editor::update_mouse_over_hexes ( const gamemap::location  mouse_over_hex  )  [private]

Update the selection and highlightning of the hexes the mouse currently is over.

void map_editor::map_editor::insert_selection_in_clipboard (  )  [private]

Insert the currently selected locations in the clipboard.

void map_editor::map_editor::perform_fill_hexes ( std::set< gamemap::location > &  fill_hexes,
const t_translation::t_terrain  terrain,
map_undo_action undo_action 
) [private]

Commit hexes filling.

void map_editor::map_editor::perform_selection_move (  )  [private]

Commit the movement of a selection.

void map_editor::map_editor::highlight_selected_hexes ( const bool  clear_old = true  )  [private]

Highlight the currently selected hexes.

If clear_old is true the old highlighting is cleared, otherwise the current selection is only added, which may leave old selected terrain still highlighted.

void map_editor::map_editor::clear_highlighted_hexes_in_gui (  )  [private]

Clear the highlighted hexes in the gui and set a variable to indicate this so that the brush size highlighting may be refreshed.

void map_editor::map_editor::set_mouseover_overlay (  )  [private]

void map_editor::map_editor::reset_mouseover_overlay (  )  [inline, private]

Definition at line 243 of file editor.hpp.

References display::clear_mouseover_hex_overlay(), and gui_.

void map_editor::map_editor::terrain_changed ( const gamemap::location hex  )  [private]

Terrain has changed at the specified hex through user drawing (not undo/redo or other special things).

void map_editor::map_editor::save_undo_action ( const map_undo_action action  )  [private]

Save an action so that it may be undone.

Add an operation to the number done since save.

void map_editor::map_editor::left_button_func_changed ( const LEFT_BUTTON_FUNC  func  )  [private]

Call when the left mouse button function has changed.

Updated the report indicating what will be performed. New_function is the hotkey-string describing the action.

void map_editor::map_editor::update_l_button_palette (  )  [private]

Draw black squares around the buttons that are used to select the left button function and draw a read square around the currently selected function.

std::string map_editor::map_editor::get_action_name ( const LEFT_BUTTON_FUNC  func  )  const [private]

Return the hotkey-string representing the left button function.

The "action_" is left out.

bool map_editor::map_editor::is_left_button_func_menu ( const theme::menu menu  )  const [private]

Return true if the menu is a button used for setting the left mouse button function.

void map_editor::map_editor::draw_on_mouseover_hexes ( const t_translation::t_terrain  t,
const bool  one_layer_only = false 
) [private]

Draw the terrain on the hexes the mouse is over, taking account for brush size.

void map_editor::map_editor::load_tooltips ( void   )  [private]

void map_editor::map_editor::copy_buffer ( map_buffer buffer,
const std::set< gamemap::location > &  locs,
const gamemap::location origin 
) [private]

void map_editor::map_editor::paste_buffer ( const map_buffer buffer,
const gamemap::location loc,
map_undo_action undo_action 
) [private]

void map_editor::map_editor::clear_buffer ( map_buffer buffer  )  [inline, private]

Definition at line 298 of file editor.hpp.


Member Data Documentation

Definition at line 298 of file editor.hpp.

Referenced by reset_mouseover_overlay().

Definition at line 301 of file editor.hpp.

std::string map_editor::map_editor::filename_ [private]

Definition at line 302 of file editor.hpp.

Definition at line 302 of file editor.hpp.

Definition at line 303 of file editor.hpp.

Definition at line 304 of file editor.hpp.

Definition at line 308 of file editor.hpp.

Definition at line 309 of file editor.hpp.

Definition at line 310 of file editor.hpp.

Definition at line 311 of file editor.hpp.

Definition at line 312 of file editor.hpp.

Definition at line 313 of file editor.hpp.

Definition at line 317 of file editor.hpp.

Definition at line 318 of file editor.hpp.

Definition at line 319 of file editor.hpp.

Definition at line 320 of file editor.hpp.

Definition at line 321 of file editor.hpp.

Definition at line 322 of file editor.hpp.

Definition at line 323 of file editor.hpp.

Definition at line 324 of file editor.hpp.

Definition at line 325 of file editor.hpp.

Definition at line 326 of file editor.hpp.

Definition at line 328 of file editor.hpp.

Definition at line 329 of file editor.hpp.

Definition at line 331 of file editor.hpp.

Definition at line 332 of file editor.hpp.

Definition at line 335 of file editor.hpp.

Definition at line 336 of file editor.hpp.

Definition at line 337 of file editor.hpp.

Definition at line 338 of file editor.hpp.

Definition at line 339 of file editor.hpp.

Definition at line 340 of file editor.hpp.

bool map_editor::map_editor::first_time_created_ = true [static, private]

Definition at line 341 of file editor.hpp.

Definition at line 342 of file editor.hpp.

Definition at line 343 of file editor.hpp.

Definition at line 343 of file editor.hpp.

Definition at line 344 of file editor.hpp.

Definition at line 345 of file editor.hpp.


The documentation for this class was generated from the following files:

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