The event handler class for the widget library. More...
#include <distributor.hpp>
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... | |
widget * | keyboard_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 | |
widget * | keyboard_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 > | |
std::chrono::steady_clock::time_point | last_click_stamp_ |
The time of the last click used for double clicking. More... | |
widget * | last_clicked_widget_ |
The widget the last click was on, used for double clicking. More... | |
widget * | focus_ |
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 | |
widget * | mouse_focus_ |
The widget that currently has the mouse focus_. More... | |
bool | mouse_captured_ |
Did the current widget capture the focus_? More... | |
widget & | owner_ |
The widget that owns us. More... | |
std::size_t | hover_timer_ |
The timer for the hover event. More... | |
widget * | hover_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... | |
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 205 of file distributor.hpp.
gui2::event::distributor::distributor | ( | widget & | owner, |
const dispatcher::queue_position | queue_position | ||
) |
Definition at line 580 of file distributor.cpp.
References gui2::event::dispatcher::connect_signal(), initialize_state(), gui2::event::NOTIFY_REMOVAL, gui2::event::mouse_motion::owner_, gui2::event::SDL_KEY_DOWN, gui2::event::SDL_TEXT_EDITING, gui2::event::SDL_TEXT_INPUT, signal_handler_notify_removal(), signal_handler_sdl_key_down(), signal_handler_sdl_text_editing(), and signal_handler_sdl_text_input().
gui2::event::distributor::~distributor | ( | ) |
Definition at line 628 of file distributor.cpp.
References gui2::event::dispatcher::disconnect_signal(), gui2::event::NOTIFY_REMOVAL, gui2::event::mouse_motion::owner_, gui2::event::SDL_KEY_DOWN, gui2::event::SDL_TEXT_EDITING, gui2::event::SDL_TEXT_INPUT, signal_handler_notify_removal(), signal_handler_sdl_key_down(), signal_handler_sdl_text_editing(), and signal_handler_sdl_text_input().
void gui2::event::distributor::initialize_state | ( | ) |
Initializes the state of the keyboard and mouse.
Needed after initialization and reactivation.
Definition at line 662 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().
void gui2::event::distributor::keyboard_add_to_chain | ( | widget * | widget | ) |
Adds the widget to the keyboard chain.
widget | The widget to add to the chain. The widget should be valid widget, which hasn't been added to the chain yet. |
Definition at line 693 of file distributor.cpp.
References keyboard_focus_chain_.
void gui2::event::distributor::keyboard_capture | ( | widget * | widget | ) |
Captures the keyboard input.
widget | The widget which should capture the keyboard. Sending nullptr releases the capturing. |
Definition at line 678 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.
widget * gui2::event::distributor::keyboard_focus | ( | ) | const |
Return the widget currently capturing keyboard input.
Definition at line 673 of file distributor.cpp.
References keyboard_focus_.
void gui2::event::distributor::keyboard_remove_from_chain | ( | widget * | widget | ) |
Remove the widget from the keyboard chain.
widget | The widget to be removed from the chain. |
Definition at line 700 of file distributor.cpp.
References keyboard_focus_chain_, and w.
|
private |
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 711 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_.
|
private |
It might be cleaner to do it that way, but creates extra small functions...
Definition at line 785 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().
|
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 770 of file distributor.cpp.
References gui2::event::SDL_KEY_DOWN.
Referenced by distributor(), and ~distributor().
|
private |
Definition at line 780 of file distributor.cpp.
References gui2::event::SDL_TEXT_EDITING, and editor::start().
Referenced by distributor(), and ~distributor().
|
private |
Definition at line 775 of file distributor.cpp.
References gui2::event::SDL_TEXT_INPUT, and editor::start().
Referenced by distributor(), and ~distributor().
|
private |
The widget that holds the keyboard focus_.
Definition at line 253 of file distributor.hpp.
Referenced by keyboard_capture(), keyboard_focus(), signal_handler_keyboard_internal(), and signal_handler_notify_removal().
|
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 265 of file distributor.hpp.
Referenced by keyboard_add_to_chain(), keyboard_remove_from_chain(), signal_handler_keyboard_internal(), and signal_handler_notify_removal().