The Battle for Wesnoth  1.19.0-dev
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
events::mouse_handler_base Class Referenceabstract

#include <mouse_handler_base.hpp>

Inheritance diagram for events::mouse_handler_base:

Public Member Functions

 mouse_handler_base ()
 
virtual ~mouse_handler_base ()
 
virtual displaygui ()=0
 Reference to the used display objects. More...
 
virtual const displaygui () const =0
 Const version of gui. More...
 
bool dragging_started () const
 If mouse/finger has moved far enough to consider it move/swipe, and not a click/touch. More...
 
bool is_dragging () const
 
virtual int drag_threshold () const
 Minimum dragging distance to fire the drag&drop. More...
 
void mouse_motion_event (const SDL_MouseMotionEvent &event, const bool browse)
 
void touch_motion_event (const SDL_TouchFingerEvent &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...
 
virtual void mouse_motion (int x, int y, const bool browse, bool update=false, map_location new_loc=map_location::null_location())=0
 Called when a mouse motion event takes place. More...
 
virtual void touch_motion (int x, int y, const bool browse, bool update=false, map_location new_loc=map_location::null_location())=0
 
virtual void mouse_press (const SDL_MouseButtonEvent &event, const bool browse)
 
virtual bool mouse_button_event (const SDL_MouseButtonEvent &event, uint8_t button, map_location loc, bool click=false)
 
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
 
bool is_touch_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, int)
 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 move_action (bool)
 Overridden in derived class. More...
 
virtual void touch_action (const map_location hex, bool browse)
 
virtual void left_drag_end (int, int, const bool)
 Called whenever the left mouse drag has "ended". More...
 
virtual void left_mouse_up (int, int, const bool)
 Called when the left mouse button is up. More...
 
virtual bool right_click (int x, int y, const bool browse)
 Overridden in derived classes, called on a right click (mousedown). More...
 
virtual bool right_click_show_menu (int, int, const bool)
 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...
 
virtual void right_drag_end (int, int, const bool)
 Called whenever the right mouse drag has "ended". More...
 
virtual void right_mouse_up (int, int, const bool)
 Called when the right mouse button is up. More...
 
virtual void mouse_wheel_up (int, int, const bool)
 Called when the mouse wheel is scrolled up. More...
 
virtual void mouse_wheel_down (int, int, const bool)
 Called when the mouse wheel is scrolled down. More...
 
virtual void mouse_wheel_left (int, int, const bool)
 Called when the mouse wheel is scrolled left. More...
 
virtual void mouse_wheel_right (int, int, const bool)
 Called when the mouse wheel is scrolled right. More...
 
void set_scroll_start (int x, int y)
 Called when the middle click scrolling. More...
 
const SDL_Point get_scroll_start () const
 
bool scroll_started () const
 

Protected Member Functions

void cancel_dragging ()
 
void clear_dragging (const SDL_MouseButtonEvent &event, bool browse)
 
void clear_drag_from_hex ()
 
void init_dragging (bool &dragging_flag)
 

Protected Attributes

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_touch_
 Finger 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 or mouse-down 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 35 of file mouse_handler_base.hpp.

Constructor & Destructor Documentation

◆ mouse_handler_base()

events::mouse_handler_base::mouse_handler_base ( )

Definition at line 53 of file mouse_handler_base.cpp.

◆ ~mouse_handler_base()

virtual events::mouse_handler_base::~mouse_handler_base ( )
inlinevirtual

Definition at line 40 of file mouse_handler_base.hpp.

Member Function Documentation

◆ allow_mouse_wheel_scroll()

virtual bool events::mouse_handler_base::allow_mouse_wheel_scroll ( int  ,
int   
)
inlinevirtual

Derived classes can override this to disable mousewheel scrolling under some circumstances, e.g.

when the mouse wheel controls something else, but the event is also received by this class

Reimplemented in editor::editor_controller.

Definition at line 113 of file mouse_handler_base.hpp.

◆ cancel_dragging()

void events::mouse_handler_base::cancel_dragging ( )
protected

◆ clear_drag_from_hex()

void events::mouse_handler_base::clear_drag_from_hex ( )
protected

Definition at line 455 of file mouse_handler_base.cpp.

References drag_from_hex_, and map_location::null_location().

Referenced by mouse_press().

◆ clear_dragging()

void events::mouse_handler_base::clear_dragging ( const SDL_MouseButtonEvent &  event,
bool  browse 
)
protected

◆ drag_threshold()

virtual int events::mouse_handler_base::drag_threshold ( ) const
inlinevirtual

Minimum dragging distance to fire the drag&drop.

Reimplemented in events::mouse_handler.

Definition at line 62 of file mouse_handler_base.hpp.

Referenced by controller_base::long_touch_callback(), and mouse_motion_default().

◆ dragging_started()

bool events::mouse_handler_base::dragging_started ( ) const

If mouse/finger has moved far enough to consider it move/swipe, and not a click/touch.

Definition at line 71 of file mouse_handler_base.cpp.

References dragging_started_.

◆ get_scroll_start()

const SDL_Point events::mouse_handler_base::get_scroll_start ( ) const
inline

Definition at line 207 of file mouse_handler_base.hpp.

References scroll_start_x_, and scroll_start_y_.

Referenced by controller_base::handle_scroll().

◆ get_show_menu()

bool events::mouse_handler_base::get_show_menu ( ) const
inline

Definition at line 74 of file mouse_handler_base.hpp.

References show_menu_.

Referenced by controller_base::handle_event().

◆ gui() [1/2]

virtual const display& events::mouse_handler_base::gui ( ) const
pure virtual

Const version of gui.

Implemented in events::mouse_handler, and editor::editor_controller.

◆ gui() [2/2]

virtual display& events::mouse_handler_base::gui ( )
pure virtual

Reference to the used display objects.

Derived classes should ensure this is always valid. Note the constructor of this class cannot use this.

Implemented in events::mouse_handler, and editor::editor_controller.

Referenced by init_dragging(), left_click(), controller_base::long_touch_callback(), mouse_motion_default(), mouse_press(), mouse_wheel(), and right_mouse_up().

◆ init_dragging()

void events::mouse_handler_base::init_dragging ( bool &  dragging_flag)
protected

◆ is_dragging()

bool events::mouse_handler_base::is_dragging ( ) const
Returns
true when the class in the "dragging" state.

Definition at line 76 of file mouse_handler_base.cpp.

References dragging_left_, dragging_right_, and dragging_touch_.

Referenced by editor::editor_controller::mouse_motion(), mouse_motion_default(), and events::mouse_handler::touch_motion().

◆ is_left_click()

bool events::mouse_handler_base::is_left_click ( const SDL_MouseButtonEvent &  event) const

Definition at line 292 of file mouse_handler_base.cpp.

References events::command_active().

Referenced by mouse_press().

◆ is_middle_click()

bool events::mouse_handler_base::is_middle_click ( const SDL_MouseButtonEvent &  event) const

Definition at line 305 of file mouse_handler_base.cpp.

Referenced by mouse_press().

◆ is_right_click()

bool events::mouse_handler_base::is_right_click ( const SDL_MouseButtonEvent &  event) const

Definition at line 310 of file mouse_handler_base.cpp.

References events::command_active().

Referenced by mouse_press().

◆ is_touch_click()

bool events::mouse_handler_base::is_touch_click ( const SDL_MouseButtonEvent &  event) const

Definition at line 324 of file mouse_handler_base.cpp.

Referenced by mouse_press().

◆ left_click()

bool events::mouse_handler_base::left_click ( int  x,
int  y,
const bool  browse 
)
virtual

Overridden in derived classes, called on a left click (mousedown).

Defaults to process (initiate) minimap scrolling.

Returns
true when the click should not process the event further. This means do not treat the call as a start of drag movement. FIXME: This return value is currently ignored

Reimplemented in editor::editor_controller.

Definition at line 329 of file mouse_handler_base.cpp.

References gui(), last_hex_, display::minimap_location_on(), minimap_scrolling_, display::scroll_to_tile(), map_location::valid(), and display::WARP.

Referenced by mouse_press().

◆ left_drag_end()

void events::mouse_handler_base::left_drag_end ( int  ,
int  ,
const bool  browse 
)
virtual

Called whenever the left mouse drag has "ended".

Reimplemented in editor::editor_controller.

Definition at line 352 of file mouse_handler_base.cpp.

References move_action().

Referenced by clear_dragging().

◆ left_mouse_up()

virtual void events::mouse_handler_base::left_mouse_up ( int  ,
int  ,
const bool   
)
inlinevirtual

Called when the left mouse button is up.

Reimplemented in editor::editor_controller.

Definition at line 140 of file mouse_handler_base.hpp.

Referenced by mouse_press().

◆ mouse_button_event()

bool events::mouse_handler_base::mouse_button_event ( const SDL_MouseButtonEvent &  event,
uint8_t  button,
map_location  loc,
bool  click = false 
)
virtual

Reimplemented in events::mouse_handler.

Definition at line 161 of file mouse_handler_base.cpp.

References tooltips::click().

Referenced by mouse_press().

◆ mouse_motion()

virtual void events::mouse_handler_base::mouse_motion ( int  x,
int  y,
const bool  browse,
bool  update = false,
map_location  new_loc = map_location::null_location() 
)
pure virtual

Called when a mouse motion event takes place.

Derived classes must provide an implementation, possibly using mouse_motion_default().

Implemented in events::mouse_handler, and editor::editor_controller.

Referenced by mouse_motion_event(), and mouse_update().

◆ mouse_motion_default()

bool events::mouse_handler_base::mouse_motion_default ( int  x,
int  y,
bool  update 
)

This handles minimap scrolling and click-drag.

Returns
true when the caller should not process the mouse motion further (i.e. should return), false otherwise.

Definition at line 100 of file mouse_handler_base.cpp.

References drag_from_x_, drag_from_y_, drag_threshold(), dragging_left_, dragging_right_, dragging_started_, sdl::get_mouse_button_mask(), sdl::get_mouse_state(), gui(), is_dragging(), last_hex_, display::minimap_location_on(), minimap_scrolling_, tooltips::process(), display::scroll_to_tile(), cursor::set_dragging(), simple_warp_, map_location::valid(), and display::WARP.

Referenced by events::mouse_handler::mouse_motion().

◆ mouse_motion_event()

void events::mouse_handler_base::mouse_motion_event ( const SDL_MouseMotionEvent &  event,
const bool  browse 
)

Definition at line 81 of file mouse_handler_base.cpp.

References mouse_motion().

Referenced by controller_base::handle_event().

◆ mouse_press()

void events::mouse_handler_base::mouse_press ( const SDL_MouseButtonEvent &  event,
const bool  browse 
)
virtual

◆ mouse_update()

void events::mouse_handler_base::mouse_update ( const bool  browse,
map_location  loc 
)

Update the mouse with a fake mouse motion.

Definition at line 93 of file mouse_handler_base.cpp.

References sdl::get_mouse_state(), and mouse_motion().

Referenced by mouse_press(), and controller_base::play_slice().

◆ mouse_wheel()

void events::mouse_handler_base::mouse_wheel ( int  xscroll,
int  yscroll,
bool  browse 
)
virtual

◆ mouse_wheel_down()

virtual void events::mouse_handler_base::mouse_wheel_down ( int  ,
int  ,
const bool   
)
inlinevirtual

Called when the mouse wheel is scrolled down.

Definition at line 186 of file mouse_handler_base.hpp.

Referenced by mouse_wheel().

◆ mouse_wheel_left()

virtual void events::mouse_handler_base::mouse_wheel_left ( int  ,
int  ,
const bool   
)
inlinevirtual

Called when the mouse wheel is scrolled left.

Definition at line 191 of file mouse_handler_base.hpp.

Referenced by mouse_wheel().

◆ mouse_wheel_right()

virtual void events::mouse_handler_base::mouse_wheel_right ( int  ,
int  ,
const bool   
)
inlinevirtual

Called when the mouse wheel is scrolled right.

Definition at line 196 of file mouse_handler_base.hpp.

Referenced by mouse_wheel().

◆ mouse_wheel_up()

virtual void events::mouse_handler_base::mouse_wheel_up ( int  ,
int  ,
const bool   
)
inlinevirtual

Called when the mouse wheel is scrolled up.

Definition at line 181 of file mouse_handler_base.hpp.

Referenced by mouse_wheel().

◆ move_action()

virtual void events::mouse_handler_base::move_action ( bool  )
inlinevirtual

Overridden in derived class.

Called on drag + drop movements.

Reimplemented in events::mouse_handler.

Definition at line 129 of file mouse_handler_base.hpp.

Referenced by left_drag_end().

◆ right_click()

virtual bool events::mouse_handler_base::right_click ( int  x,
int  y,
const bool  browse 
)
inlinevirtual

Overridden in derived classes, called on a right click (mousedown).

Defaults to displaying the menu (by setting the appropriate flag) if right_click_show_menu returns true.

Returns
true when the click should not process the event further. This means do not treat the call as a start of drag movement.

Reimplemented in editor::editor_controller.

Definition at line 152 of file mouse_handler_base.hpp.

References right_click_show_menu().

Referenced by mouse_press().

◆ right_click_show_menu()

virtual bool events::mouse_handler_base::right_click_show_menu ( int  ,
int  ,
const bool   
)
inlinevirtual

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 in events::mouse_handler, and editor::editor_controller.

Definition at line 165 of file mouse_handler_base.hpp.

Referenced by right_click(), and right_mouse_up().

◆ right_drag_end()

virtual void events::mouse_handler_base::right_drag_end ( int  ,
int  ,
const bool   
)
inlinevirtual

Called whenever the right mouse drag has "ended".

Reimplemented in editor::editor_controller.

Definition at line 171 of file mouse_handler_base.hpp.

Referenced by clear_dragging().

◆ right_mouse_up()

void events::mouse_handler_base::right_mouse_up ( int  x,
int  y,
const bool  browse 
)
virtual

Called when the right mouse button is up.

Reimplemented in editor::editor_controller.

Definition at line 393 of file mouse_handler_base.cpp.

References theme::context_menu(), display::get_theme(), gui(), right_click_show_menu(), show_menu_, and WRN_DP.

Referenced by mouse_press().

◆ scroll_started()

bool events::mouse_handler_base::scroll_started ( ) const
inline

Definition at line 212 of file mouse_handler_base.hpp.

References scroll_started_.

Referenced by controller_base::handle_scroll().

◆ set_scroll_start()

void events::mouse_handler_base::set_scroll_start ( int  x,
int  y 
)
inline

Called when the middle click scrolling.

Definition at line 201 of file mouse_handler_base.hpp.

References scroll_start_x_, and scroll_start_y_.

Referenced by controller_base::handle_scroll(), and mouse_press().

◆ touch_action()

void events::mouse_handler_base::touch_action ( const map_location  hex,
bool  browse 
)
virtual

Reimplemented in events::mouse_handler.

Definition at line 348 of file mouse_handler_base.cpp.

◆ touch_motion()

virtual void events::mouse_handler_base::touch_motion ( int  x,
int  y,
const bool  browse,
bool  update = false,
map_location  new_loc = map_location::null_location() 
)
pure virtual

◆ touch_motion_event()

void events::mouse_handler_base::touch_motion_event ( const SDL_TouchFingerEvent &  event,
const bool  browse 
)

Definition at line 86 of file mouse_handler_base.cpp.

References touch_motion().

Referenced by controller_base::handle_event().

Member Data Documentation

◆ drag_from_hex_

map_location events::mouse_handler_base::drag_from_hex_
protected

◆ drag_from_x_

int events::mouse_handler_base::drag_from_x_
protected

◆ drag_from_y_

int events::mouse_handler_base::drag_from_y_
protected

◆ dragging_left_

bool events::mouse_handler_base::dragging_left_
protected

◆ dragging_right_

bool events::mouse_handler_base::dragging_right_
protected

◆ dragging_started_

bool events::mouse_handler_base::dragging_started_
protected

◆ dragging_touch_

bool events::mouse_handler_base::dragging_touch_
protected

Finger drag init flag.

Definition at line 233 of file mouse_handler_base.hpp.

Referenced by cancel_dragging(), clear_dragging(), is_dragging(), mouse_press(), and events::mouse_handler::touch_motion().

◆ last_hex_

map_location events::mouse_handler_base::last_hex_
protected

◆ minimap_scrolling_

bool events::mouse_handler_base::minimap_scrolling_
protected

minimap scrolling (scroll-drag) state flag

Definition at line 227 of file mouse_handler_base.hpp.

Referenced by left_click(), mouse_motion_default(), mouse_press(), and events::mouse_handler::touch_motion().

◆ scroll_start_x_

int events::mouse_handler_base::scroll_start_x_
protected

Relative to middle click scrolling.

Definition at line 257 of file mouse_handler_base.hpp.

Referenced by get_scroll_start(), and set_scroll_start().

◆ scroll_start_y_

int events::mouse_handler_base::scroll_start_y_
protected

Definition at line 258 of file mouse_handler_base.hpp.

Referenced by get_scroll_start(), and set_scroll_start().

◆ scroll_started_

bool events::mouse_handler_base::scroll_started_
protected

◆ show_menu_

bool events::mouse_handler_base::show_menu_
protected

Show context menu flag.

Definition at line 254 of file mouse_handler_base.hpp.

Referenced by get_show_menu(), mouse_press(), and right_mouse_up().

◆ simple_warp_

bool events::mouse_handler_base::simple_warp_
protected

MMB click (on game map) state flag.

Definition at line 224 of file mouse_handler_base.hpp.

Referenced by mouse_motion_default(), mouse_press(), and events::mouse_handler::touch_motion().


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