mouse_events.hpp

Go to the documentation of this file.
00001 /* $Id: mouse_events.hpp 25333 2008-03-30 13:49:03Z jhinrichs $ */
00002 /*
00003    Copyright (C) 2006 - 2008 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
00004    wesnoth playturn Copyright (C) 2003 by David White <dave@whitevine.net>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License version 2
00009    or at your option any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #ifndef MOUSE_EVENTS_H_INCLUDED
00017 #define MOUSE_EVENTS_H_INCLUDED
00018 
00019 #include "global.hpp"
00020 
00021 #include "actions.hpp"
00022 #include "game_display.hpp"
00023 #include "pathfind.hpp"
00024 #include "unit_map.hpp"
00025 
00026 class gamestatus;
00027 
00028 #include "SDL.h"
00029 
00030 namespace events{
00031 
00032 struct command_disabler
00033 {
00034     command_disabler();
00035     ~command_disabler();
00036 };
00037 
00038 class mouse_handler{
00039 public:
00040     mouse_handler(game_display* gui, std::vector<team>& teams, unit_map& units, gamemap& map,
00041         gamestatus& status, undo_list& undo_stack, undo_list& redo_stack);
00042     ~mouse_handler();
00043     static mouse_handler* get_singleton() { return singleton_ ;}
00044     void set_team(const int team_number);
00045     void mouse_motion(const SDL_MouseMotionEvent& event, const bool browse);
00046     // update the mouse with a fake mouse motion
00047     void mouse_update(const bool browse);
00048     void mouse_press(const SDL_MouseButtonEvent& event, const bool browse);
00049     void cycle_units(const bool browse, const bool reverse = false);
00050     void cycle_back_units(const bool browse) { cycle_units(browse, true); }
00051 
00052     int get_path_turns() const { return path_turns_; }
00053     paths get_current_paths() { return current_paths_; }
00054     const gamemap::location& get_last_hex() const { return last_hex_; }
00055     gamemap::location get_selected_hex() const { return selected_hex_; }
00056     bool get_undo() const { return undo_; }
00057     bool get_show_menu() const { return show_menu_; }
00058     void set_path_turns(const int path_turns) { path_turns_ = path_turns; }
00059     void set_current_paths(paths new_paths);
00060     void set_selected_hex(gamemap::location hex) { selected_hex_ = hex; }
00061     void deselect_hex();
00062     void invalidate_reachmap() { reachmap_invalid_ = true; }
00063 
00064     void set_gui(game_display* gui) { gui_ = gui; }
00065     void set_undo(const bool undo) { undo_ = undo; }
00066 
00067     unit_map::iterator selected_unit();
00068     paths::route get_route(unit_map::const_iterator un, gamemap::location go_to, team &team);
00069 private:
00070     team& viewing_team() { return teams_[(*gui_).viewing_team()]; }
00071     const team& viewing_team() const { return teams_[(*gui_).viewing_team()]; }
00072     team& current_team() { return teams_[team_num_-1]; }
00073 
00074     // use update to force an update of the mouse state
00075     void mouse_motion(int x, int y, const bool browse, bool update=false);
00076     bool is_left_click(const SDL_MouseButtonEvent& event);
00077     bool is_middle_click(const SDL_MouseButtonEvent& event);
00078     bool is_right_click(const SDL_MouseButtonEvent& event);
00079     void left_click(const SDL_MouseButtonEvent& event, const bool browse);
00080     void select_hex(const gamemap::location& hex, const bool browse);
00081     void clear_undo_stack();
00082     bool move_unit_along_current_route(bool check_shroud, bool attackmove=false);
00083     // wrapper to catch bad_alloc so this should be called
00084     bool attack_enemy(unit_map::iterator attacker, unit_map::iterator defender);
00085     // the real function but can throw bad_alloc
00086     bool attack_enemy_(unit_map::iterator attacker, unit_map::iterator defender);
00087     void show_attack_options(unit_map::const_iterator u);
00088     gamemap::location current_unit_attacks_from(const gamemap::location& loc);
00089     unit_map::const_iterator find_unit(const gamemap::location& hex) const;
00090     unit_map::iterator find_unit(const gamemap::location& hex);
00091     bool unit_in_cycle(unit_map::const_iterator it);
00092 
00093     game_display* gui_;
00094     std::vector<team>& teams_;
00095     unit_map& units_;
00096     gamemap& map_;
00097     gamestatus& status_;
00098     undo_list& undo_stack_;
00099     undo_list& redo_stack_;
00100 
00101     bool minimap_scrolling_;
00102     bool dragging_;
00103     bool dragging_started_;
00104     int drag_from_x_;
00105     int drag_from_y_;
00106 
00107     // last highlighted hex
00108     gamemap::location last_hex_;
00109     // previous highlighted hexes
00110     // the hex of the selected unit and empty hex are "free"
00111     gamemap::location previous_hex_;
00112     gamemap::location previous_free_hex_;
00113     gamemap::location selected_hex_;
00114     gamemap::location next_unit_;
00115     paths::route current_route_;
00116     paths current_paths_;
00117     bool enemy_paths_;
00118     int path_turns_;
00119     unsigned int team_num_;
00120 
00121     //cached value indicating whether any enemy units are visible.
00122     //computed with enemies_visible()
00123     bool enemies_visible_;
00124     bool undo_;
00125     bool show_menu_;
00126     bool over_route_;
00127     bool attackmove_;
00128     bool reachmap_invalid_;
00129     bool show_partial_move_;
00130 
00131     static mouse_handler * singleton_;
00132 };
00133 
00134 extern int commands_disabled;
00135 }
00136 
00137 #endif

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