The Battle for Wesnoth  1.15.0-dev
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
gui2::event::sdl_event_handler Class Reference

This singleton class handles all events. More...

Inheritance diagram for gui2::event::sdl_event_handler:
Inheritance graph

Public Member Functions

 sdl_event_handler ()
 
 ~sdl_event_handler ()
 
void handle_event (const SDL_Event &event) override
 Inherited from events::sdl_handler. More...
 
void handle_window_event (const SDL_Event &event) override
 Inherited from events::sdl_handler. More...
 
void connect (dispatcher *dispatcher)
 Connects a dispatcher. More...
 
void disconnect (dispatcher *dispatcher)
 Disconnects a dispatcher. More...
 
std::vector< dispatcher * > & get_dispatchers ()
 Returns all dispatchers in the Z order. More...
 
- Public Member Functions inherited from events::sdl_handler
virtual void process_event ()
 
virtual bool requires_event_focus (const SDL_Event *=nullptr) const
 
virtual void join ()
 
virtual void join (context &c)
 
virtual void join_same (sdl_handler *parent)
 
virtual void leave ()
 
virtual void join_global ()
 
virtual void leave_global ()
 
virtual bool has_joined ()
 
virtual bool has_joined_global ()
 

Public Attributes

dispatchermouse_focus
 The dispatcher that captured the mouse focus. More...
 

Private Member Functions

void activate ()
 Reinitializes the state of all dispatchers. More...
 
void raw_event (const SDL_Event &event)
 Fires a raw SDL event. More...
 
virtual void draw () override final
 Fires a draw event. More...
 
void video_resize (const point &new_size)
 Fires a video resize event. More...
 
void mouse (const ui_event event, const point &position)
 Fires a generic mouse event. More...
 
void mouse_button_up (const point &position, const uint8_t button)
 Fires a mouse button up event. More...
 
void mouse_button_down (const point &position, const uint8_t button)
 Fires a mouse button down event. More...
 
void mouse_wheel (const point &position, int scrollx, int scrolly)
 Fires a mouse wheel event. More...
 
dispatcherkeyboard_dispatcher ()
 Gets the dispatcher that wants to receive the keyboard input. More...
 
void touch_motion (const point &position, const point &distance)
 Fires a generic touch event. More...
 
void hat_motion (const SDL_Event &event)
 Handles a hat motion event. More...
 
void button_down (const SDL_Event &event)
 Handles a joystick button down event. More...
 
void key_down (const SDL_Event &event)
 Fires a key down event. More...
 
bool hotkey_pressed (const hotkey::hotkey_ptr key)
 Handles the pressing of a hotkey. More...
 
void key_down (const SDL_Keycode key, const SDL_Keymod modifier, const std::string &unicode)
 Fires a key down event. More...
 
void text_input (const std::string &unicode)
 Fires a text input event. More...
 
void text_editing (const std::string &unicode, int32_t start, int32_t len)
 Fires a text editing event. More...
 
void keyboard (const ui_event event)
 Fires a keyboard event which has no parameters. More...
 
void close_window (const unsigned window_id)
 Fires a CLOSE_WINDOW event for the window with the given ID. More...
 

Private Attributes

std::vector< dispatcher * > dispatchers_
 The dispatchers. More...
 
dispatcherkeyboard_focus_
 Needed to determine which dispatcher gets the keyboard events. More...
 

Friends

bool gui2::is_in_dialog ()
 
void capture_keyboard (dispatcher *)
 Captures the keyboard. More...
 

Additional Inherited Members

- Protected Member Functions inherited from events::sdl_handler
 sdl_handler (const bool auto_join=true)
 
virtual ~sdl_handler ()
 
virtual std::vector< sdl_handler * > handler_members ()
 

Detailed Description

This singleton class handles all events.

It's a new experimental class.

Definition at line 90 of file handler.cpp.

Constructor & Destructor Documentation

◆ sdl_event_handler()

gui2::event::sdl_event_handler::sdl_event_handler ( )

Definition at line 295 of file handler.cpp.

Referenced by gui2::event::manager::manager().

◆ ~sdl_event_handler()

gui2::event::sdl_event_handler::~sdl_event_handler ( )

Definition at line 312 of file handler.cpp.

Member Function Documentation

◆ activate()

void gui2::event::sdl_event_handler::activate ( )
private

Reinitializes the state of all dispatchers.

This is needed when the application gets activated, to make sure the state of mainly the mouse is set properly.

Definition at line 473 of file handler.cpp.

References dispatchers_, gui2::event::dispatcher::fire(), and gui2::event::SDL_ACTIVATE.

Referenced by disconnect(), and handle_event().

◆ button_down()

void gui2::event::sdl_event_handler::button_down ( const SDL_Event &  event)
private

Handles a joystick button down event.

Parameters
eventThe SDL joystick button event triggered.

Definition at line 639 of file handler.cpp.

References hotkey::get_hotkey(), and hotkey_pressed().

Referenced by handle_event().

◆ close_window()

void gui2::event::sdl_event_handler::close_window ( const unsigned  window_id)
private

Fires a CLOSE_WINDOW event for the window with the given ID.

Parameters
window_idThe ID of the window to close.

Definition at line 721 of file handler.cpp.

References gui2::event::CLOSE_WINDOW, DBG_GUI_E, gui2::event::dispatcher::fire(), and gui2::window::window_instance().

Referenced by handle_event().

◆ connect()

void gui2::event::sdl_event_handler::connect ( dispatcher dispatcher)

Connects a dispatcher.

Parameters
dispatcherThe dispatcher to connect.

Definition at line 434 of file handler.cpp.

References dispatchers_, and events::sdl_handler::join().

◆ disconnect()

void gui2::event::sdl_event_handler::disconnect ( dispatcher dispatcher)

Disconnects a dispatcher.

Parameters
dispatcherThe dispatcher to disconnect.

Definition at line 446 of file handler.cpp.

References activate(), dispatchers_, keyboard_focus_, and events::sdl_handler::leave().

◆ draw()

void gui2::event::sdl_event_handler::draw ( )
finaloverrideprivatevirtual

Fires a draw event.

Todo:
Need to evaluate which windows really to redraw.

For now we use a hack, but would be nice to rewrite it for 1.9/1.11.

Reimplemented from events::sdl_handler.

Definition at line 481 of file handler.cpp.

References dispatchers_, gui2::event::DRAW, and gui2::event::dispatcher::fire().

Referenced by handle_event().

◆ get_dispatchers()

std::vector<dispatcher*>& gui2::event::sdl_event_handler::get_dispatchers ( )
inline

Returns all dispatchers in the Z order.

Definition at line 122 of file handler.cpp.

References dispatchers_.

◆ handle_event()

void gui2::event::sdl_event_handler::handle_event ( const SDL_Event &  event)
overridevirtual

◆ handle_window_event()

void gui2::event::sdl_event_handler::handle_window_event ( const SDL_Event &  event)
overridevirtual

Inherited from events::sdl_handler.

Implements events::sdl_handler.

Definition at line 429 of file handler.cpp.

References handle_event().

◆ hat_motion()

void gui2::event::sdl_event_handler::hat_motion ( const SDL_Event &  event)
private

Handles a hat motion event.

Parameters
eventThe SDL joystick hat event triggered.

Definition at line 626 of file handler.cpp.

References hotkey::get_hotkey(), and hotkey_pressed().

Referenced by handle_event().

◆ hotkey_pressed()

bool gui2::event::sdl_event_handler::hotkey_pressed ( const hotkey::hotkey_ptr  key)
private

Handles the pressing of a hotkey.

Parameters
keyThe hotkey item pressed.
Returns
True if there was a valid dispatcher with which to execute the hotkey callback, false otherwise.

Definition at line 688 of file handler.cpp.

References gui2::event::dispatcher::execute_hotkey(), hotkey::get_id(), and keyboard_dispatcher().

Referenced by button_down(), hat_motion(), and key_down().

◆ key_down() [1/2]

void gui2::event::sdl_event_handler::key_down ( const SDL_Event &  event)
private

Fires a key down event.

Parameters
eventThe SDL keyboard event triggered.

Definition at line 652 of file handler.cpp.

References hotkey::get_hotkey(), hotkey_pressed(), and text_input().

Referenced by handle_event(), and text_input().

◆ key_down() [2/2]

void gui2::event::sdl_event_handler::key_down ( const SDL_Keycode  key,
const SDL_Keymod  modifier,
const std::string &  unicode 
)
private

Fires a key down event.

Parameters
keyThe SDL key code of the key pressed.
modifierThe SDL key modifiers used.
unicodeThe unicode value for the key pressed.

Definition at line 697 of file handler.cpp.

References DBG_GUI_E, gui2::event::dispatcher::fire(), keyboard_dispatcher(), and gui2::event::SDL_KEY_DOWN.

◆ keyboard()

void gui2::event::sdl_event_handler::keyboard ( const ui_event  event)
private

Fires a keyboard event which has no parameters.

This can happen for example when the mouse wheel is used.

Parameters
eventThe event to fire.

Definition at line 712 of file handler.cpp.

References DBG_GUI_E, gui2::event::dispatcher::fire(), and keyboard_dispatcher().

◆ keyboard_dispatcher()

dispatcher * gui2::event::sdl_event_handler::keyboard_dispatcher ( )
private

Gets the dispatcher that wants to receive the keyboard input.

Returns
The dispatcher.
Return values
nullptrNo dispatcher found.

Definition at line 604 of file handler.cpp.

References dispatchers_, gui2::event::dispatcher::get_want_keyboard_input(), keyboard_focus_, and reverse().

Referenced by hotkey_pressed(), key_down(), keyboard(), text_editing(), and text_input().

◆ mouse()

void gui2::event::sdl_event_handler::mouse ( const ui_event  event,
const point position 
)
private

◆ mouse_button_down()

void gui2::event::sdl_event_handler::mouse_button_down ( const point position,
const uint8_t  button 
)
private

Fires a mouse button down event.

Parameters
positionThe position of the mouse.
buttonThe SDL id of the button that caused the event.

Definition at line 568 of file handler.cpp.

References mouse(), gui2::event::SDL_LEFT_BUTTON_DOWN, gui2::event::SDL_MIDDLE_BUTTON_DOWN, gui2::event::SDL_RIGHT_BUTTON_DOWN, and WRN_GUI_E.

Referenced by handle_event().

◆ mouse_button_up()

void gui2::event::sdl_event_handler::mouse_button_up ( const point position,
const uint8_t  button 
)
private

Fires a mouse button up event.

Parameters
positionThe position of the mouse.
buttonThe SDL id of the button that caused the event.

Definition at line 547 of file handler.cpp.

References mouse(), gui2::event::SDL_LEFT_BUTTON_UP, gui2::event::SDL_MIDDLE_BUTTON_UP, gui2::event::SDL_RIGHT_BUTTON_UP, and WRN_GUI_E.

Referenced by handle_event().

◆ mouse_wheel()

void gui2::event::sdl_event_handler::mouse_wheel ( const point position,
int  scrollx,
int  scrolly 
)
private

Fires a mouse wheel event.

Parameters
positionThe position of the mouse.
scrollxThe amount of horizontal scrolling.
scrollyThe amount of vertical scrolling.

Definition at line 589 of file handler.cpp.

References mouse(), gui2::event::SDL_WHEEL_DOWN, gui2::event::SDL_WHEEL_LEFT, gui2::event::SDL_WHEEL_RIGHT, and gui2::event::SDL_WHEEL_UP.

Referenced by handle_event().

◆ raw_event()

void gui2::event::sdl_event_handler::raw_event ( const SDL_Event &  event)
private

Fires a raw SDL event.

Definition at line 512 of file handler.cpp.

References DBG_GUI_E, dispatchers_, gui2::event::dispatcher::fire(), and gui2::event::SDL_RAW_EVENT.

Referenced by handle_event().

◆ text_editing()

void gui2::event::sdl_event_handler::text_editing ( const std::string &  unicode,
int32_t  start,
int32_t  len 
)
private

Fires a text editing event.

Parameters
unicodeThe unicode value for the text being edited.
startThe start position for the text being edited.
lenThe selection length for the text being edited.

Definition at line 679 of file handler.cpp.

References gui2::event::dispatcher::fire(), keyboard_dispatcher(), and gui2::event::SDL_TEXT_EDITING.

Referenced by handle_event().

◆ text_input()

void gui2::event::sdl_event_handler::text_input ( const std::string &  unicode)
private

Fires a text input event.

Parameters
unicodeThe unicode value for the text entered.

Definition at line 668 of file handler.cpp.

References gui2::event::dispatcher::fire(), key_down(), keyboard_dispatcher(), and gui2::event::SDL_TEXT_INPUT.

Referenced by key_down().

◆ touch_motion()

void gui2::event::sdl_event_handler::touch_motion ( const point position,
const point distance 
)
private

Fires a generic touch event.

Parameters
positionThe position touched.
distanceThe distance moved.

Definition at line 619 of file handler.cpp.

References dispatchers_, gui2::event::dispatcher::fire(), reverse(), and gui2::event::SDL_TOUCH_MOTION.

Referenced by handle_event().

◆ video_resize()

void gui2::event::sdl_event_handler::video_resize ( const point new_size)
private

Fires a video resize event.

Parameters
new_sizeThe new size of the window.

Definition at line 502 of file handler.cpp.

References DBG_GUI_E, dispatchers_, gui2::event::dispatcher::fire(), and gui2::event::SDL_VIDEO_RESIZE.

Referenced by handle_event().

Friends And Related Function Documentation

◆ capture_keyboard

void capture_keyboard ( dispatcher )
friend

Captures the keyboard.

A dispatcher can capture the keyboard, when for example it's pressed on a button, this means all keyboard events after that are send to that widget.

Parameters
dispatcherThe dispatcher which should get the keyboard focus.

Definition at line 804 of file handler.cpp.

◆ gui2::is_in_dialog

bool gui2::is_in_dialog ( )
friend

Member Data Documentation

◆ dispatchers_

std::vector<dispatcher*> gui2::event::sdl_event_handler::dispatchers_
private

The dispatchers.

The order of the items in the list is also the z-order the front item being the one completely in the background and the back item the one completely in the foreground.

Definition at line 284 of file handler.cpp.

Referenced by activate(), connect(), disconnect(), draw(), get_dispatchers(), handle_event(), keyboard_dispatcher(), mouse(), raw_event(), touch_motion(), and video_resize().

◆ keyboard_focus_

dispatcher* gui2::event::sdl_event_handler::keyboard_focus_
private

Needed to determine which dispatcher gets the keyboard events.

NOTE the keyboard events aren't really wired in yet so doesn't do much.

Definition at line 291 of file handler.cpp.

Referenced by disconnect(), and keyboard_dispatcher().

◆ mouse_focus

dispatcher* gui2::event::sdl_event_handler::mouse_focus

The dispatcher that captured the mouse focus.

Definition at line 125 of file handler.cpp.


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