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

The event handler class for the widget library. More...

#include <distributor.hpp>

Inheritance diagram for gui2::event::distributor:

Public Member Functions

 distributor (widget &owner, const dispatcher::queue_position queue_position)
 
 ~distributor ()
 
void initialize_state ()
 Initializes the state of the keyboard and mouse. More...
 
void keyboard_capture (widget *widget)
 Captures the keyboard input. More...
 
void keyboard_add_to_chain (widget *widget)
 Adds the widget to the keyboard chain. More...
 
void keyboard_remove_from_chain (widget *widget)
 Remove the widget from the keyboard chain. More...
 
widgetkeyboard_focus () const
 Return the widget currently capturing keyboard input. More...
 
- Public Member Functions inherited from gui2::event::mouse_button< I >
 mouse_button (widget &owner, const dispatcher::queue_position queue_position)
 
void initialize_state (int32_t button_state)
 Initializes the state of the button. More...
 
- Public Member Functions inherited from gui2::event::mouse_motion
 mouse_motion (widget &owner, const dispatcher::queue_position queue_position)
 
 ~mouse_motion ()
 
void capture_mouse (const bool capture=true)
 Captures the mouse input. More...
 

Private Member Functions

void signal_handler_sdl_key_down (const SDL_Keycode key, const SDL_Keymod modifier, const std::string &unicode)
 Set of functions that handle certain events and sends them to the proper widget. More...
 
void signal_handler_sdl_text_input (const std::string &unicode, int32_t start, int32_t len)
 
void signal_handler_sdl_text_editing (const std::string &unicode, int32_t start, int32_t len)
 
template<typename Fcn , typename P1 , typename P2 , typename P3 >
void signal_handler_keyboard_internal (event::ui_event evt, P1 &&p1, P2 &&p2, P3 &&p3)
 
void signal_handler_notify_removal (dispatcher &widget, const ui_event event)
 

Private Attributes

widgetkeyboard_focus_
 The widget that holds the keyboard focus_. More...
 
std::vector< widget * > keyboard_focus_chain_
 Fall back keyboard focus_ items. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gui2::event::mouse_motion
void start_hover_timer (widget *widget, const point &coordinate)
 Starts the hover timer. More...
 
void stop_hover_timer ()
 Stops the current hover timer. More...
 
void mouse_enter (widget *mouse_over)
 Called when the mouse enters a widget. More...
 
void mouse_leave ()
 Called when the mouse leaves the current widget. More...
 
- Protected Attributes inherited from gui2::event::mouse_button< I >
uint32_t last_click_stamp_
 The time of the last click used for double clicking. More...
 
widgetlast_clicked_widget_
 The widget the last click was on, used for double clicking. More...
 
widgetfocus_
 If the mouse isn't captured we need to verify the up is on the same widget as the down so we send a proper click, also needed to send the up to the right widget. More...
 
- Protected Attributes inherited from gui2::event::mouse_motion
widgetmouse_focus_
 The widget that currently has the mouse focus_. More...
 
bool mouse_captured_
 Did the current widget capture the focus_? More...
 
widgetowner_
 The widget that owns us. More...
 
std::size_t hover_timer_
 The timer for the hover event. More...
 
widgethover_widget_
 The widget which should get the hover event. More...
 
point hover_position_
 The anchor point of the hover event. More...
 
bool hover_shown_
 Has the hover been shown for the widget? More...
 

Detailed Description

The event handler class for the widget library.

C++ doesn't allow multiple inheritance to directly use more than one instance of a superclass.

It's a diamond inheritance, as all of these have virtual base class mouse_motion; refactoring that would allow these multiple classes to be replaced with a simple (distributor has-a std::array<mouse_button, 3>) relationship.

Definition at line 204 of file distributor.hpp.

Constructor & Destructor Documentation

◆ distributor()

gui2::event::distributor::distributor ( widget owner,
const dispatcher::queue_position  queue_position 
)

◆ ~distributor()

gui2::event::distributor::~distributor ( )

Member Function Documentation

◆ initialize_state()

void gui2::event::distributor::initialize_state ( )

Initializes the state of the keyboard and mouse.

Needed after initialization and reactivation.

Definition at line 661 of file distributor.cpp.

References sdl::get_mouse_button_mask(), gui2::event::init_mouse_location(), and gui2::event::mouse_button< I >::initialize_state().

Referenced by distributor().

◆ keyboard_add_to_chain()

void gui2::event::distributor::keyboard_add_to_chain ( widget widget)

Adds the widget to the keyboard chain.

Parameters
widgetThe widget to add to the chain. The widget should be valid widget, which hasn't been added to the chain yet.

Definition at line 692 of file distributor.cpp.

References keyboard_focus_chain_.

◆ keyboard_capture()

void gui2::event::distributor::keyboard_capture ( widget widget)

Captures the keyboard input.

Parameters
widgetThe widget which should capture the keyboard. Sending nullptr releases the capturing.

Definition at line 677 of file distributor.cpp.

References DBG_GUI_E, gui2::event::dispatcher::fire(), keyboard_focus_, LOG_HEADER, gui2::event::LOSE_KEYBOARD_FOCUS, gui2::event::mouse_motion::owner_, and gui2::event::RECEIVE_KEYBOARD_FOCUS.

◆ keyboard_focus()

widget * gui2::event::distributor::keyboard_focus ( ) const

Return the widget currently capturing keyboard input.

Definition at line 672 of file distributor.cpp.

References keyboard_focus_.

◆ keyboard_remove_from_chain()

void gui2::event::distributor::keyboard_remove_from_chain ( widget widget)

Remove the widget from the keyboard chain.

Parameters
widgetThe widget to be removed from the chain.

Definition at line 699 of file distributor.cpp.

References keyboard_focus_chain_, and w.

◆ signal_handler_keyboard_internal()

template<typename Fcn , typename P1 , typename P2 , typename P3 >
void gui2::event::distributor::signal_handler_keyboard_internal ( event::ui_event  evt,
P1 &&  p1,
P2 &&  p2,
P3 &&  p3 
)
private
Todo:
Test whether recursion protection is needed.
Todo:
Make sure we're not in the event chain.

No idea why we're here, but needs to be fixed, otherwise we keep calling this function recursively upon unhandled events...

Probably added to make sure the window can grab the events and handle + block them when needed, this is no longer needed with the chain.

Definition at line 710 of file distributor.cpp.

References DBG_GUI_E, gui2::event::dispatcher::fire(), gui2::styled_widget::get_active(), keyboard_focus_, keyboard_focus_chain_, LOG_HEADER, and gui2::event::mouse_motion::owner_.

◆ signal_handler_notify_removal()

void gui2::event::distributor::signal_handler_notify_removal ( dispatcher widget,
const ui_event  event 
)
private
Todo:
Evaluate whether moving the cleanup parts in the subclasses.

It might be cleaner to do it that way, but creates extra small functions...

Definition at line 784 of file distributor.cpp.

References DBG_GUI_E, gui2::event::mouse_button< I >::focus_, gui2::event::mouse_motion::hover_widget_, keyboard_focus_, keyboard_focus_chain_, gui2::event::mouse_button< I >::last_clicked_widget_, LOG_HEADER, gui2::event::mouse_motion::mouse_focus_, gui2::event::mouse_motion::stop_hover_timer(), and w.

Referenced by distributor(), and ~distributor().

◆ signal_handler_sdl_key_down()

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

Set of functions that handle certain events and sends them to the proper widget.

These functions are called by the SDL event handling functions.

Definition at line 769 of file distributor.cpp.

References gui2::event::SDL_KEY_DOWN.

Referenced by distributor(), and ~distributor().

◆ signal_handler_sdl_text_editing()

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

Definition at line 779 of file distributor.cpp.

References gui2::event::SDL_TEXT_EDITING, and editor::start().

Referenced by distributor(), and ~distributor().

◆ signal_handler_sdl_text_input()

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

Definition at line 774 of file distributor.cpp.

References gui2::event::SDL_TEXT_INPUT, and editor::start().

Referenced by distributor(), and ~distributor().

Member Data Documentation

◆ keyboard_focus_

widget* gui2::event::distributor::keyboard_focus_
private

The widget that holds the keyboard focus_.

Definition at line 252 of file distributor.hpp.

Referenced by keyboard_capture(), keyboard_focus(), signal_handler_keyboard_internal(), and signal_handler_notify_removal().

◆ keyboard_focus_chain_

std::vector<widget*> gui2::event::distributor::keyboard_focus_chain_
private

Fall back keyboard focus_ items.

When the focused widget didn't handle the keyboard event (or no handler for the keyboard focus_) it is send all widgets in this vector. The order is from rbegin() to rend(). If the keyboard_focus_ is in the vector it won't get the event twice. The first item added to the vector should be the window, so it will be the last handler and can dispatch the hotkeys registered.

Definition at line 264 of file distributor.hpp.

Referenced by keyboard_add_to_chain(), keyboard_remove_from_chain(), signal_handler_keyboard_internal(), and signal_handler_notify_removal().


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