The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
events::mouse_handler Class Reference

#include <mouse_events.hpp>

Inheritance diagram for events::mouse_handler:
Inheritance graph

Public Member Functions

 mouse_handler (game_display *gui, play_controller &pc)
 
 ~mouse_handler ()
 
void set_side (int side_number)
 
void mouse_press (const SDL_MouseButtonEvent &event, const bool browse)
 
void cycle_units (const bool browse, const bool reverse=false)
 
void cycle_back_units (const bool browse)
 
int get_path_turns () const
 
map_location current_unit_attacks_from (const map_location &loc) const
 
const pathfind::pathscurrent_paths () const
 
const map_locationget_last_hex () const
 
map_location get_selected_hex () const
 
void set_path_turns (const int path_turns)
 
void set_current_paths (const pathfind::paths &new_paths)
 
void deselect_hex ()
 
void invalidate_reachmap ()
 
void set_gui (game_display *gui)
 
unit_map::iterator selected_unit ()
 
pathfind::marked_route get_route (const unit *un, map_location go_to, team &team) const
 
const pathfind::marked_routeget_current_route () const
 
std::set< map_locationget_adj_enemies (const map_location &loc, int side) const
 
int show_attack_dialog (const map_location &attacker_loc, const map_location &defender_loc)
 
void attack_enemy (const map_location &attacker_loc, const map_location &defender_loc, int choice)
 
size_t move_unit_along_route (const std::vector< map_location > &steps, bool &interrupted)
 Moves a unit across the board for a player. More...
 
void select_hex (const map_location &hex, const bool browse, const bool highlight=true, const bool fire_event=true)
 
void move_action (bool browse)
 Overridden in derived class. More...
 
void select_or_action (bool browse)
 
void left_mouse_up (int x, int y, const bool)
 Called when the left mouse button is up. More...
 
void mouse_wheel_up (int x, int y, const bool)
 Called when the mouse wheel is scrolled up. More...
 
void mouse_wheel_down (int x, int y, const bool)
 Called when the mouse wheel is scrolled down. More...
 
void mouse_wheel_left (int x, int y, const bool)
 Called when the mouse wheel is scrolled left. More...
 
void mouse_wheel_right (int x, int y, const bool)
 Called when the mouse wheel is scrolled right. More...
 
- Public Member Functions inherited from events::mouse_handler_base
 mouse_handler_base ()
 
virtual ~mouse_handler_base ()
 
bool is_dragging () const
 
void mouse_motion_event (const SDL_MouseMotionEvent &event, const bool browse)
 
void mouse_update (const bool browse, map_location loc)
 update the mouse with a fake mouse motion More...
 
bool get_show_menu () const
 
bool mouse_motion_default (int x, int y, bool update)
 This handles minimap scrolling and click-drag. More...
 
bool is_left_click (const SDL_MouseButtonEvent &event) const
 
bool is_middle_click (const SDL_MouseButtonEvent &event) const
 
bool is_right_click (const SDL_MouseButtonEvent &event) const
 
virtual void mouse_wheel (int xscroll, int yscroll, bool browse)
 Called when scrolling with the mouse wheel. More...
 
virtual bool allow_mouse_wheel_scroll (int x, int y)
 Derived classes can override this to disable mousewheel scrolling under some circumstances, e.g. More...
 
virtual bool left_click (int x, int y, const bool browse)
 Overridden in derived classes, called on a left click (mousedown). More...
 
virtual void left_drag_end (int x, int y, const bool browse)
 Called whenever the left mouse drag has "ended". More...
 
virtual bool right_click (int x, int y, const bool browse)
 Overridden in derived classes, called on a right click (mousedown). More...
 
virtual void right_drag_end (int x, int y, const bool browse)
 Called whenever the right mouse drag has "ended". More...
 
virtual void right_mouse_up (int x, int y, const bool browse)
 Called when the right mouse button is up. More...
 
void set_scroll_start (int x, int y)
 Called when the middle click scrolling. More...
 
const map_location get_scroll_start ()
 
bool scroll_started ()
 

Static Public Member Functions

static mouse_handlerget_singleton ()
 

Protected Member Functions

game_displaygui ()
 Due to the way this class is constructed we can assume that the display* gui_ member actually points to a game_display (derived class) More...
 
const game_displaygui () const
 Const version. More...
 
int drag_threshold () const
 
void mouse_motion (int x, int y, const bool browse, bool update=false, map_location loc=map_location::null_location())
 Use update to force an update of the mouse state. More...
 
bool right_click_show_menu (int x, int y, const bool browse)
 Called in the default right_click when the context menu is about to be shown, can be used for preprocessing and preventing the menu from being displayed without rewriting the right click function. More...
 
bool move_unit_along_current_route ()
 Moves a unit along the currently cached route. More...
 
void save_whiteboard_attack (const map_location &attacker_loc, const map_location &defender_loc, int weapon_choice)
 
int fill_weapon_choices (std::vector< battle_context > &bc_vector, unit_map::iterator attacker, unit_map::iterator defender)
 
void attack_enemy_ (const map_location &attacker_loc, const map_location &defender_loc, int choice)
 
void show_attack_options (const unit_map::const_iterator &u)
 Causes attackable hexes to be highlighted. More...
 
unit_map::const_iterator find_unit (const map_location &hex) const
 
unit_map::iterator find_unit (const map_location &hex)
 
bool unit_in_cycle (unit_map::const_iterator it)
 
- Protected Member Functions inherited from events::mouse_handler_base
void cancel_dragging ()
 
void clear_dragging (const SDL_MouseButtonEvent &event, bool browse)
 
void init_dragging (bool &dragging_flag)
 

Private Member Functions

teamviewing_team ()
 
const teamviewing_team () const
 
teamcurrent_team ()
 

Private Attributes

game_displaygui_
 
play_controllerpc_
 
map_location previous_hex_
 
map_location previous_free_hex_
 
map_location selected_hex_
 
map_location next_unit_
 
pathfind::marked_route current_route_
 
pathfind::paths current_paths_
 
bool unselected_paths_
 
int path_turns_
 
int side_num_
 
bool over_route_
 
bool reachmap_invalid_
 
bool show_partial_move_
 

Static Private Attributes

static mouse_handlersingleton_ = nullptr
 

Additional Inherited Members

- Protected Attributes inherited from events::mouse_handler_base
bool simple_warp_
 MMB click (on game map) state flag. More...
 
bool minimap_scrolling_
 minimap scrolling (scroll-drag) state flag More...
 
bool dragging_left_
 LMB drag init flag. More...
 
bool dragging_started_
 Actual drag flag. More...
 
bool dragging_right_
 RMB drag init flag. More...
 
int drag_from_x_
 Drag start position x. More...
 
int drag_from_y_
 Drag start position y. More...
 
map_location drag_from_hex_
 Drag start map location. More...
 
map_location last_hex_
 last highlighted hex More...
 
bool show_menu_
 Show context menu flag. More...
 
int scroll_start_x_
 Relative to middle click scrolling. More...
 
int scroll_start_y_
 
bool scroll_started_
 

Detailed Description

Definition at line 37 of file mouse_events.hpp.

Constructor & Destructor Documentation

events::mouse_handler::mouse_handler ( game_display gui,
play_controller pc 
)

Definition at line 75 of file mouse_events.cpp.

References singleton_.

events::mouse_handler::~mouse_handler ( )

Definition at line 95 of file mouse_events.cpp.

References singleton_.

Member Function Documentation

void events::mouse_handler::attack_enemy ( const map_location attacker_loc,
const map_location defender_loc,
int  choice 
)

Definition at line 998 of file mouse_events.cpp.

References attack_enemy_(), and lg::wml_error().

Referenced by wb::attack::execute(), and move_action().

void events::mouse_handler::attack_enemy_ ( const map_location attacker_loc,
const map_location defender_loc,
int  choice 
)
protected
const pathfind::paths& events::mouse_handler::current_paths ( ) const
inline

Definition at line 54 of file mouse_events.hpp.

References current_paths_.

Referenced by play_controller::process_keyup_event().

team & events::mouse_handler::current_team ( )
private
map_location events::mouse_handler::current_unit_attacks_from ( const map_location loc) const
void events::mouse_handler::cycle_back_units ( const bool  browse)
inline

Definition at line 45 of file mouse_events.hpp.

References cycle_units().

Referenced by play_controller::hotkey_handler::cycle_back_units().

void events::mouse_handler::cycle_units ( const bool  browse,
const bool  reverse = false 
)
void events::mouse_handler::deselect_hex ( )
int events::mouse_handler::drag_threshold ( ) const
protectedvirtual

Reimplemented from events::mouse_handler_base.

Definition at line 105 of file mouse_events.cpp.

int events::mouse_handler::fill_weapon_choices ( std::vector< battle_context > &  bc_vector,
unit_map::iterator  attacker,
unit_map::iterator  defender 
)
protected
unit_map::const_iterator events::mouse_handler::find_unit ( const map_location hex) const
protected
unit_map::iterator events::mouse_handler::find_unit ( const map_location hex)
protected
std::set< map_location > events::mouse_handler::get_adj_enemies ( const map_location loc,
int  side 
) const
const pathfind::marked_route& events::mouse_handler::get_current_route ( ) const
inline

Definition at line 69 of file mouse_events.hpp.

References current_route_.

Referenced by wb::manager::create_temp_move().

const map_location& events::mouse_handler::get_last_hex ( ) const
inline
int events::mouse_handler::get_path_turns ( ) const
inline

Definition at line 47 of file mouse_events.hpp.

References path_turns_.

Referenced by play_controller::process_keyup_event().

pathfind::marked_route events::mouse_handler::get_route ( const unit un,
map_location  go_to,
team team 
) const
map_location events::mouse_handler::get_selected_hex ( ) const
inline
static mouse_handler* events::mouse_handler::get_singleton ( )
inlinestatic

Definition at line 41 of file mouse_events.hpp.

References singleton_.

Referenced by unit_display::unit_mover::finish(), and unit_display::unit_die().

game_display& events::mouse_handler::gui ( )
inlineprotectedvirtual

Due to the way this class is constructed we can assume that the display* gui_ member actually points to a game_display (derived class)

Implements events::mouse_handler_base.

Definition at line 102 of file mouse_events.hpp.

References gui_.

Referenced by attack_enemy_(), cycle_units(), mouse_motion(), move_action(), move_unit_along_current_route(), move_unit_along_route(), right_click_show_menu(), save_whiteboard_attack(), select_hex(), set_current_paths(), set_gui(), unit_in_cycle(), and viewing_team().

const game_display& events::mouse_handler::gui ( ) const
inlineprotectedvirtual

Const version.

Implements events::mouse_handler_base.

Definition at line 104 of file mouse_events.hpp.

References gui_.

void events::mouse_handler::invalidate_reachmap ( )
inline

Definition at line 61 of file mouse_events.hpp.

References reachmap_invalid_.

Referenced by unit_display::unit_mover::finish(), and unit_display::unit_die().

void events::mouse_handler::left_mouse_up ( int  x,
int  y,
const bool  browse 
)
virtual
void events::mouse_handler::mouse_motion ( int  x,
int  y,
const bool  browse,
bool  update = false,
map_location  loc = map_location::null_location() 
)
protectedvirtual
void events::mouse_handler::mouse_press ( const SDL_MouseButtonEvent &  event,
const bool  browse 
)
virtual
void events::mouse_handler::mouse_wheel_down ( int  x,
int  y,
const bool  browse 
)
virtual

Called when the mouse wheel is scrolled down.

Reimplemented from events::mouse_handler_base.

Definition at line 495 of file mouse_events.cpp.

References display::find_slider(), play_controller::get_hotkey_command_executor(), gui_, pc_, hotkey::command_executor::set_button_state(), and display::set_zoom().

void events::mouse_handler::mouse_wheel_left ( int  x,
int  y,
const bool  browse 
)
virtual

Called when the mouse wheel is scrolled left.

Reimplemented from events::mouse_handler_base.

Definition at line 503 of file mouse_events.cpp.

References display::find_slider(), play_controller::get_hotkey_command_executor(), gui_, pc_, hotkey::command_executor::set_button_state(), and display::set_zoom().

void events::mouse_handler::mouse_wheel_right ( int  x,
int  y,
const bool  browse 
)
virtual

Called when the mouse wheel is scrolled right.

Reimplemented from events::mouse_handler_base.

Definition at line 511 of file mouse_events.cpp.

References display::find_slider(), play_controller::get_hotkey_command_executor(), gui_, pc_, hotkey::command_executor::set_button_state(), and display::set_zoom().

void events::mouse_handler::mouse_wheel_up ( int  x,
int  y,
const bool  browse 
)
virtual

Called when the mouse wheel is scrolled up.

Reimplemented from events::mouse_handler_base.

Definition at line 487 of file mouse_events.cpp.

References display::find_slider(), play_controller::get_hotkey_command_executor(), gui_, pc_, hotkey::command_executor::set_button_state(), and display::set_zoom().

void events::mouse_handler::move_action ( bool  browse)
virtual
bool events::mouse_handler::move_unit_along_current_route ( )
protected

Moves a unit along the currently cached route.

Returns
true if the end of the route was reached and no information was uncovered that would warrant interrupting a chain of actions; false otherwise.

Definition at line 822 of file mouse_events.cpp.

References current_paths_, current_route_, gui(), move_unit_along_route(), next_unit_, game_display::select_hex(), selected_hex_, game_display::set_route(), pathfind::marked_route::steps, and game_display::unhighlight_reach().

Referenced by move_action().

size_t events::mouse_handler::move_unit_along_route ( const std::vector< map_location > &  steps,
bool &  interrupted 
)

Moves a unit across the board for a player.

This is specifically for movement at the time it is initiated by a player, whether via a mouse click or executing whiteboard actions. Continued moves (including goto execution) can bypass this and call actions::move_unit() directly. This function call may include time for an animation, so make sure the provided route will remain unchanged (the caller should probably make a local copy).

Parameters
[in]stepsThe route to be traveled. The unit to be moved is at the beginning of this route.
[out]interruptedThis is set to true if information was uncovered that warrants interrupting a chain of actions (and set to false otherwise).
Returns
The number of hexes entered. This can safely be used as an index into steps to get the location where movement ended, provided steps is not empty (the return value is guaranteed to be less than steps.size() ).

Definition at line 868 of file mouse_events.cpp.

References _(), game_state::board_, unit_map::find(), play_controller::gamestate(), play_controller::get_map_const(), play_controller::get_undo_stack(), play_controller::get_whiteboard(), gui(), gui_, display::invalidate_game_status(), gamemap::is_keep(), LOG_NG, actions::move_unit_and_record(), cursor::NORMAL, pc_, select_hex(), cursor::set(), show_partial_move_, gui2::show_transient_message(), game_board::units(), display::video(), and display::viewing_side().

Referenced by wb::move::execute(), and move_unit_along_current_route().

bool events::mouse_handler::right_click_show_menu ( int  x,
int  y,
const bool  browse 
)
protectedvirtual

Called in the default right_click when the context menu is about to be shown, can be used for preprocessing and preventing the menu from being displayed without rewriting the right click function.

Returns
true when the menu should be displayed and false otherwise FIXME: This return value is currently ignored

Reimplemented from events::mouse_handler_base.

Definition at line 473 of file mouse_events.cpp.

References gui(), sdl::point_in_rect(), selected_hex_, and map_location::valid().

void events::mouse_handler::save_whiteboard_attack ( const map_location attacker_loc,
const map_location defender_loc,
int  weapon_choice 
)
protected
void events::mouse_handler::select_hex ( const map_location hex,
const bool  browse,
const bool  highlight = true,
const bool  fire_event = true 
)
void events::mouse_handler::select_or_action ( bool  browse)
unit_map::iterator events::mouse_handler::selected_unit ( )
void events::mouse_handler::set_current_paths ( const pathfind::paths new_paths)
void events::mouse_handler::set_gui ( game_display gui)
inline

Definition at line 63 of file mouse_events.hpp.

References gui(), and gui_.

Referenced by play_controller::init().

void events::mouse_handler::set_path_turns ( const int  path_turns)
inline

Definition at line 58 of file mouse_events.hpp.

References path_turns_.

Referenced by play_controller::process_keyup_event().

void events::mouse_handler::set_side ( int  side_number)

Definition at line 100 of file mouse_events.cpp.

References side_num_.

Referenced by play_controller::init_side_begin().

int events::mouse_handler::show_attack_dialog ( const map_location attacker_loc,
const map_location defender_loc 
)
void events::mouse_handler::show_attack_options ( const unit_map::const_iterator u)
protected

Causes attackable hexes to be highlighted.

This checks the hexes that the provided unit can attack. If there is a valid target there, that location is inserted into current_paths_.destinations.

Definition at line 1084 of file mouse_events.cpp.

References game_state::board_, current_paths_, current_team(), pathfind::paths::destinations, unit_map::find(), play_controller::gamestate(), get_adjacent_tiles(), play_controller::get_map_const(), i, unit::incapacitated(), pathfind::paths::dest_vect::insert(), team::is_enemy(), game_board::map(), gamemap::on_board(), pc_, unit::side(), game_board::teams_, and game_board::units().

Referenced by select_hex().

bool events::mouse_handler::unit_in_cycle ( unit_map::const_iterator  it)
protected
team & events::mouse_handler::viewing_team ( )
private
const team & events::mouse_handler::viewing_team ( ) const
private

Member Data Documentation

pathfind::paths events::mouse_handler::current_paths_
private
pathfind::marked_route events::mouse_handler::current_route_
private
game_display* events::mouse_handler::gui_
private
map_location events::mouse_handler::next_unit_
private

Definition at line 143 of file mouse_events.hpp.

Referenced by cycle_units(), move_unit_along_current_route(), and select_hex().

bool events::mouse_handler::over_route_
private

Definition at line 150 of file mouse_events.hpp.

Referenced by mouse_motion().

int events::mouse_handler::path_turns_
private

Definition at line 147 of file mouse_events.hpp.

Referenced by get_path_turns(), mouse_motion(), select_hex(), and set_path_turns().

play_controller& events::mouse_handler::pc_
private
map_location events::mouse_handler::previous_free_hex_
private

Definition at line 141 of file mouse_events.hpp.

Referenced by current_unit_attacks_from(), and mouse_motion().

map_location events::mouse_handler::previous_hex_
private

Definition at line 140 of file mouse_events.hpp.

Referenced by current_unit_attacks_from(), and mouse_motion().

bool events::mouse_handler::reachmap_invalid_
private

Definition at line 151 of file mouse_events.hpp.

Referenced by invalidate_reachmap(), and mouse_motion().

map_location events::mouse_handler::selected_hex_
private
bool events::mouse_handler::show_partial_move_
private
int events::mouse_handler::side_num_
private
mouse_handler * events::mouse_handler::singleton_ = nullptr
staticprivate

Definition at line 154 of file mouse_events.hpp.

Referenced by get_singleton(), mouse_handler(), and ~mouse_handler().

bool events::mouse_handler::unselected_paths_
private

Definition at line 146 of file mouse_events.hpp.

Referenced by mouse_motion(), and select_hex().


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