Base class for event handling. More...
#include <dispatcher.hpp>
Classes | |
struct | signal_queue |
Helper struct to generate the various event queues. More... | |
struct | signal_type |
Helper struct to generate the various signal types. More... | |
Public Types | |
enum | event_queue_type { pre = 1 , child = 2 , post = 4 } |
enum | queue_position { front_pre_child , back_pre_child , front_child , back_child , front_post_child , back_post_child } |
The position where to add a new callback in the signal handler. More... | |
enum class | mouse_behavior { all , hit , none } |
The behavior of the mouse events. More... | |
Public Member Functions | |
dispatcher () | |
virtual | ~dispatcher () |
void | connect () |
Connects the dispatcher to the event handler. More... | |
void | disconnect () |
Disconnects the dispatcher from the event handler. More... | |
bool | is_connected () const |
Return whether the dispatcher is currently connected. More... | |
virtual bool | is_at (const point &coordinate) const =0 |
Determines whether the location is inside an active widget. More... | |
bool | has_event (const ui_event event, const event_queue_type event_type) |
bool | fire (const ui_event event, widget &target) |
Fires an event which has no extra parameters. More... | |
bool | fire (const ui_event event, widget &target, const point &coordinate) |
Fires an event which takes a coordinate parameter. More... | |
bool | fire (const ui_event event, widget &target, const SDL_Keycode key, const SDL_Keymod modifier, const std::string &unicode) |
Fires an event which takes keyboard parameters. More... | |
bool | fire (const ui_event event, widget &target, const point &pos, const point &distance) |
Fires an event which takes touch-motion parameters. More... | |
bool | fire (const ui_event event, widget &target, const point ¢er, float dTheta, float dDist, uint8_t numFingers) |
Fires an event which takes touch-gesture parameters. More... | |
bool | fire (const ui_event event, widget &target, void *) |
Fires an event which takes notification parameters. More... | |
bool | fire (const ui_event event, widget &target, const message &msg) |
Fires an event which takes message parameters. More... | |
bool | fire (const ui_event event, widget &target, const SDL_Event &sdlevent) |
Fires an event that's a raw SDL event. More... | |
bool | fire (const ui_event event, widget &target, const std::string &text, int32_t start, int32_t len) |
Fires an event which takes text input parameters. More... | |
template<ui_event E, typename F > | |
void | connect_signal (const F &func, const queue_position position=back_child) |
Adds a callback to the appropriate queue based on event type. More... | |
template<ui_event E, typename F > | |
void | disconnect_signal (const F &func, const queue_position position=back_child) |
Removes a callback from the appropriate queue based on event type. More... | |
void | capture_mouse () |
Captures the mouse. More... | |
void | release_mouse () |
Releases the mouse capture. More... | |
void | set_mouse_behavior (const mouse_behavior mouse_behavior) |
mouse_behavior | get_mouse_behavior () const |
void | set_want_keyboard_input (const bool want_keyboard_input) |
bool | get_want_keyboard_input () const |
void | register_hotkey (const hotkey::HOTKEY_COMMAND id, const hotkey_function &function) |
Registers a hotkey. More... | |
bool | execute_hotkey (const hotkey::HOTKEY_COMMAND id) |
Executes a hotkey. More... | |
Private Member Functions | |
template<event_category cat> | |
auto & | get_signal_queue () |
Friends | |
struct | dispatcher_implementation |
Base class for event handling.
A dispatcher has slots for events, when an event arrives it looks for the functions that registered themselves for that event and calls their callbacks.
This class is a base class for all widgets[1], what a widget does on a callback can differ greatly, an image might ignore all events a window can track the mouse location and fire MOUSE_ENTER and MOUSE_LEAVE events to the widgets involved.
[1] Not really sure whether it will be a base class for a widget or styled_widget yet.
Definition at line 149 of file dispatcher.hpp.
Enumerator | |
---|---|
pre | |
child | |
post |
Definition at line 193 of file dispatcher.hpp.
|
strong |
The behavior of the mouse events.
Normally for mouse events there's first checked whether a dispatcher has captured the mouse if so it gets the event. If not the dispatcher is searched from the back to the front in the layers and its behavior is checked.
If after these tests no dispatcher is found the event is ignored.
Enumerator | |
---|---|
all | |
hit | |
none |
Definition at line 392 of file dispatcher.hpp.
The position where to add a new callback in the signal handler.
The signal handler has three callback queues:
For every queue it's possible to add a new event in the front or in the back.
Whether all three queues are executed depend on the whether the callbacks modify the handled and halt flag.
Here are some use case examples. A button that plays a sound and executes an optional user callback:
A toggle button may or may not be toggled:
Enumerator | |
---|---|
front_pre_child | |
back_pre_child | |
front_child | |
back_child | |
front_post_child | |
back_post_child |
Definition at line 331 of file dispatcher.hpp.
gui2::event::dispatcher::dispatcher | ( | ) |
Definition at line 27 of file dispatcher.cpp.
Referenced by gui2::pane::signal_handler_request_placement().
|
virtual |
Definition at line 42 of file dispatcher.cpp.
References connected_, and disconnect().
|
inline |
Captures the mouse.
Definition at line 399 of file dispatcher.hpp.
References gui2::event::capture_mouse().
void gui2::event::dispatcher::connect | ( | ) |
Connects the dispatcher to the event handler.
When a dispatcher is connected to the event handler it will get the events directly from the event handler. This is wanted for top level items like windows but not for most other widgets.
So a window can call connect to register itself, it will automatically disconnect upon destruction.
Definition at line 49 of file dispatcher.cpp.
References gui2::event::connect_dispatcher(), and connected_.
|
inline |
Adds a callback to the appropriate queue based on event type.
E | The event the callback needs to react to. |
F | The event signature. This must match the appropriate queue's callback signature. |
func | The callback function. |
position | The position to place the callback. |
Definition at line 351 of file dispatcher.hpp.
Referenced by gui2::group< T >::add_member(), connect_queue(), gui2::event::connect_signal_mouse_left_click(), gui2::event::connect_signal_mouse_left_double_click(), gui2::event::connect_signal_mouse_left_release(), gui2::event::connect_signal_notify_modified(), gui2::event::connect_signal_on_draw(), gui2::event::connect_signal_pre_key_press(), gui2::event::distributor::distributor(), gui2::tab_container::finalize_listbox(), gui2::event::mouse_button< I >::mouse_button(), gui2::event::mouse_motion::mouse_motion(), gui2::dialogs::mp_login::pre_show(), and gui2::tree_view_node::tree_view_node().
void gui2::event::dispatcher::disconnect | ( | ) |
Disconnects the dispatcher from the event handler.
Definition at line 56 of file dispatcher.cpp.
References connected_, and gui2::event::disconnect_dispatcher().
Referenced by ~dispatcher().
|
inline |
Removes a callback from the appropriate queue based on event type.
E | The event the callback needs to react to. |
F | The event signature. This must match the appropriate queue's callback signature. |
func | The callback function. |
position | The place where the function was added. Needed remove the event from the right place. (The function doesn't care whether was added in front or back.) |
Definition at line 370 of file dispatcher.hpp.
Referenced by gui2::event::disconnect_signal_mouse_left_click(), gui2::event::disconnect_signal_mouse_left_release(), and gui2::event::distributor::~distributor().
bool gui2::event::dispatcher::execute_hotkey | ( | const hotkey::HOTKEY_COMMAND | id | ) |
Executes a hotkey.
id | The hotkey to execute. |
Definition at line 152 of file dispatcher.cpp.
References hotkeys_.
Referenced by gui2::event::sdl_event_handler::hotkey_pressed().
Fires an event which has no extra parameters.
Definition at line 74 of file dispatcher.cpp.
References gui2::event::fire_event_double_click(), gui2::event::general, gui2::event::is_in_category(), gui2::event::LEFT_BUTTON_CLICK, gui2::event::LEFT_BUTTON_DOUBLE_CLICK, gui2::event::MIDDLE_BUTTON_CLICK, gui2::event::MIDDLE_BUTTON_DOUBLE_CLICK, gui2::event::RIGHT_BUTTON_CLICK, gui2::event::RIGHT_BUTTON_DOUBLE_CLICK, gui2::event_executor::wants_mouse_left_double_click(), gui2::event_executor::wants_mouse_middle_double_click(), and gui2::event_executor::wants_mouse_right_double_click().
Referenced by gui2::event::sdl_event_handler::activate(), BOOST_AUTO_TEST_CASE(), gui2::tab_container::change_selection(), gui2::event::sdl_event_handler::close_window(), gui2::scrollbar_container::content_resize_request(), gui2::pane::create_item(), gui2::text_box_base::handle_commit(), gui2::text_box_base::handle_key_backspace(), gui2::text_box_base::handle_key_delete(), gui2::event::sdl_event_handler::key_down(), gui2::event::sdl_event_handler::keyboard(), gui2::event::distributor::keyboard_capture(), gui2::listbox::list_item_clicked(), gui2::event::sdl_event_handler::mouse(), gui2::event::mouse_motion::mouse_enter(), gui2::event::mouse_motion::mouse_hover(), gui2::event::mouse_motion::mouse_leave(), gui2::scrollbar_base::move_positioner(), gui2::text_box_base::paste_selection(), gui2::dialogs::drop_down_menu::pre_show(), gui2::event::sdl_event_handler::raw_event(), gui2::scrollbar_base::scroll(), gui2::slider_base::scroll(), gui2::tree_view_node::select_node(), gui2::grid::set_child_alignment(), gui2::scrollbar_base::set_item_position(), gui2::listbox::set_row_shown(), gui2::combobox::set_selected(), gui2::menu_button::set_selected(), gui2::slider::set_value(), gui2::toggle_button::set_value(), gui2::toggle_panel::set_value(), gui2::widget::set_visible(), gui2::event::mouse_motion::show_tooltip(), gui2::event::distributor::signal_handler_keyboard_internal(), gui2::tree_view_node::signal_handler_label_left_button_click(), gui2::repeating_button::signal_handler_left_button_down(), gui2::toggle_panel::signal_handler_pre_left_button_click(), gui2::event::mouse_motion::signal_handler_sdl_mouse_motion(), gui2::event::mouse_motion::signal_handler_sdl_touch_motion(), gui2::event::mouse_motion::signal_handler_sdl_wheel(), gui2::event::mouse_motion::signal_handler_show_helptip(), gui2::styled_widget::signal_handler_show_helptip(), gui2::tree_view_node::signal_handler_toggle_left_click(), gui2::event::sdl_event_handler::text_editing(), gui2::event::sdl_event_handler::text_input(), gui2::event::sdl_event_handler::touch_down(), gui2::event::sdl_event_handler::touch_motion(), gui2::event::sdl_event_handler::touch_multi_gesture(), gui2::event::sdl_event_handler::touch_up(), gui2::slider_base::update_slider_position(), gui2::listbox::update_visible_area_on_key_event(), gui2::event::sdl_event_handler::video_resize(), and gui2::widget::~widget().
Fires an event which takes message parameters.
event | The event to fire. |
target | The widget that should receive the event. Normally this is the window holding the widget. |
msg | The extra information needed for a window (or another widget in the chain) to handle the message. |
Definition at line 141 of file dispatcher.cpp.
References gui2::event::is_in_category(), gui2::event::message, and wfl::msg().
bool gui2::event::dispatcher::fire | ( | const ui_event | event, |
widget & | target, | ||
const point & | center, | ||
float | dTheta, | ||
float | dDist, | ||
uint8_t | numFingers | ||
) |
Fires an event which takes touch-gesture parameters.
event | The event to fire. |
target | The widget that should receive the event. |
center | The location touched. |
dTheta | Probably the direction moved. |
dDist | The distance moved. |
numFingers | Probably the number of fingers touching the screen. |
Definition at line 117 of file dispatcher.cpp.
References gui2::event::is_in_category(), and gui2::event::touch_gesture.
bool gui2::event::dispatcher::fire | ( | const ui_event | event, |
widget & | target, | ||
const point & | coordinate | ||
) |
Fires an event which takes a coordinate parameter.
event | The event to fire. |
target | The widget that should receive the event. |
coordinate | The mouse position for the event. |
Definition at line 95 of file dispatcher.cpp.
References gui2::event::is_in_category(), and gui2::event::mouse.
bool gui2::event::dispatcher::fire | ( | const ui_event | event, |
widget & | target, | ||
const point & | pos, | ||
const point & | distance | ||
) |
Fires an event which takes touch-motion parameters.
event | The event to fire. |
target | The widget that should receive the event. |
pos | The location touched. |
distance | The distance moved. |
Definition at line 111 of file dispatcher.cpp.
References gui2::event::is_in_category(), and gui2::event::touch_motion.
bool gui2::event::dispatcher::fire | ( | const ui_event | event, |
widget & | target, | ||
const SDL_Event & | sdlevent | ||
) |
Fires an event that's a raw SDL event.
event | The event to fire. |
target | The widget that should receive the event. Normally this is the window holding the widget. |
sdlevent | The raw SDL event |
Definition at line 123 of file dispatcher.cpp.
References gui2::event::is_in_category(), and gui2::event::raw_event.
bool gui2::event::dispatcher::fire | ( | const ui_event | event, |
widget & | target, | ||
const SDL_Keycode | key, | ||
const SDL_Keymod | modifier, | ||
const std::string & | unicode | ||
) |
Fires an event which takes keyboard parameters.
event | The event to fire. |
target | The widget that should receive the event. |
key | The SDL key code of the key pressed. |
modifier | The SDL key modifiers used. |
unicode | The unicode value for the key pressed. |
Definition at line 101 of file dispatcher.cpp.
References gui2::event::is_in_category(), and gui2::event::keyboard.
bool gui2::event::dispatcher::fire | ( | const ui_event | event, |
widget & | target, | ||
const std::string & | text, | ||
int32_t | start, | ||
int32_t | len | ||
) |
Fires an event which takes text input parameters.
event | The event to fire. |
target | The widget that should receive the event. Normally this is the window holding the widget. |
text | The text involved in the event |
start | The start point for IME editing |
len | The selection length for IME editing |
Definition at line 129 of file dispatcher.cpp.
References gui2::event::is_in_category(), editor::start(), and gui2::event::text_input.
Fires an event which takes notification parameters.
event | The event to fire. |
target | The widget that should receive the event. |
Definition at line 135 of file dispatcher.cpp.
References gui2::event::is_in_category(), and gui2::event::notification.
|
inline |
Definition at line 417 of file dispatcher.hpp.
References mouse_behavior_.
Referenced by gui2::event::sdl_event_handler::mouse().
|
inlineprivate |
Definition at line 614 of file dispatcher.hpp.
References utils::dependent_false_v, gui2::event::general, gui2::event::keyboard, gui2::event::message, gui2::event::mouse, gui2::event::notification, gui2::event::raw_event, signal_keyboard_queue_, signal_message_queue_, signal_mouse_queue_, signal_notification_queue_, signal_queue_, signal_raw_event_queue_, signal_text_input_queue_, signal_touch_gesture_queue_, signal_touch_motion_queue_, gui2::event::text_input, gui2::event::touch_gesture, and gui2::event::touch_motion.
Referenced by gui2::event::dispatcher_implementation::event_signal().
|
inline |
Definition at line 427 of file dispatcher.hpp.
References want_keyboard_input_.
Referenced by gui2::event::sdl_event_handler::keyboard_dispatcher().
bool gui2::event::dispatcher::has_event | ( | const ui_event | event, |
const event_queue_type | event_type | ||
) |
Definition at line 63 of file dispatcher.cpp.
References gui2::event::dispatcher_implementation::has_handler(), and PLAIN_LOG.
|
pure virtual |
Determines whether the location is inside an active widget.
This is used to see whether a mouse event is inside the widget.
coordinate | The coordinate to test whether inside the widget. |
Implemented in gui2::widget.
Referenced by gui2::event::sdl_event_handler::mouse().
|
inline |
Return whether the dispatcher is currently connected.
Definition at line 175 of file dispatcher.hpp.
References connected_.
void gui2::event::dispatcher::register_hotkey | ( | const hotkey::HOTKEY_COMMAND | id, |
const hotkey_function & | function | ||
) |
Registers a hotkey.
Once that's done execute_hotkey will first try to execute a global hotkey and if that fails tries the hotkeys in this dispatcher.
id | The hotkey to register. |
function | The callback function to call. |
Definition at line 147 of file dispatcher.cpp.
Referenced by gui2::dialogs::title_screen::init_callbacks(), gui2::dialogs::mp_staging::pre_show(), and gui2::dialogs::title_screen::register_button().
|
inline |
Releases the mouse capture.
Definition at line 405 of file dispatcher.hpp.
References gui2::event::release_mouse().
|
inline |
Definition at line 412 of file dispatcher.hpp.
References mouse_behavior_.
|
inline |
Definition at line 422 of file dispatcher.hpp.
References want_keyboard_input_.
|
friend |
Definition at line 151 of file dispatcher.hpp.
|
private |
Are we connected to the event handler.
Definition at line 608 of file dispatcher.hpp.
Referenced by connect(), disconnect(), is_connected(), and ~dispatcher().
|
private |
The registered hotkeys for this dispatcher.
Definition at line 611 of file dispatcher.hpp.
Referenced by execute_hotkey(), and register_hotkey().
|
private |
The mouse behavior for the dispatcher.
Definition at line 566 of file dispatcher.hpp.
Referenced by get_mouse_behavior(), and set_mouse_behavior().
|
private |
Signal queue for callbacks in event_category::keyboard.
Definition at line 587 of file dispatcher.hpp.
Referenced by get_signal_queue(), and gui2::event::dispatcher_implementation::has_handler().
|
private |
Signal queue for callbacks in event_category::message.
Definition at line 599 of file dispatcher.hpp.
Referenced by get_signal_queue(), and gui2::event::dispatcher_implementation::has_handler().
|
private |
Signal queue for callbacks in event_category::mouse.
Definition at line 584 of file dispatcher.hpp.
Referenced by get_signal_queue(), and gui2::event::dispatcher_implementation::has_handler().
|
private |
Signal queue for callbacks in event_category::notification.
Definition at line 596 of file dispatcher.hpp.
Referenced by get_signal_queue(), and gui2::event::dispatcher_implementation::has_handler().
|
private |
Signal queue for callbacks in event_category::general.
Definition at line 581 of file dispatcher.hpp.
Referenced by get_signal_queue(), and gui2::event::dispatcher_implementation::has_handler().
|
private |
Signal queue for callbacks in event_category::raw_event.
Definition at line 602 of file dispatcher.hpp.
Referenced by get_signal_queue(), and gui2::event::dispatcher_implementation::has_handler().
|
private |
Signal queue for callbacks in event_category::text_input.
Definition at line 605 of file dispatcher.hpp.
Referenced by get_signal_queue(), and gui2::event::dispatcher_implementation::has_handler().
|
private |
Signal queue for callbacks in event_category::touch_gesture.
Definition at line 593 of file dispatcher.hpp.
Referenced by get_signal_queue(), and gui2::event::dispatcher_implementation::has_handler().
|
private |
Signal queue for callbacks in event_category::touch_motion.
Definition at line 590 of file dispatcher.hpp.
Referenced by get_signal_queue(), and gui2::event::dispatcher_implementation::has_handler().
|
private |
Does the dispatcher want to receive keyboard input.
Definition at line 578 of file dispatcher.hpp.
Referenced by get_want_keyboard_input(), and set_want_keyboard_input().