This singleton class handles all events. More...
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... | |
![]() | |
virtual void | process_event () |
virtual bool | requires_event_focus (const SDL_Event *=nullptr) const |
virtual void | process_tooltip_string (int, int) |
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 () |
sdl_handler & | operator= (sdl_handler &&)=delete |
Moving would require two instances' context membership to be handled, it's simpler to delete these and require the two instances to be separately constructed / destructed. More... | |
sdl_handler (sdl_handler &&)=delete | |
Public Attributes | |
dispatcher * | mouse_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... | |
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... | |
dispatcher * | keyboard_dispatcher () |
Gets the dispatcher that wants to receive the keyboard input. More... | |
void | touch_motion (const point &position, const point &distance) |
Fires a touch-moved event. More... | |
void | touch_down (const point &position) |
Fires a touch "finger down" event. More... | |
void | touch_up (const point &position) |
Fires a touch "finger up" event. More... | |
void | touch_multi_gesture (const point ¢er, float dTheta, float dDist, uint8_t numFingers) |
Fires a touch gesture 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... | |
dispatcher * | keyboard_focus_ |
Needed to determine which dispatcher gets the keyboard events. More... | |
Friends | |
bool | gui2::is_in_dialog () |
void | capture_keyboard (dispatcher *dispatcher) |
Captures the keyboard. More... | |
Additional Inherited Members | |
![]() | |
sdl_handler (const bool auto_join=true) | |
sdl_handler (const sdl_handler &) | |
sdl_handler & | operator= (const sdl_handler &) |
virtual | ~sdl_handler () |
virtual std::vector< sdl_handler * > | handler_members () |
This singleton class handles all events.
It's a new experimental class.
Definition at line 121 of file handler.cpp.
gui2::event::sdl_event_handler::sdl_event_handler | ( | ) |
Definition at line 346 of file handler.cpp.
References events::sdl_handler::join().
gui2::event::sdl_event_handler::~sdl_event_handler | ( | ) |
Definition at line 364 of file handler.cpp.
References events::sdl_handler::leave().
|
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 576 of file handler.cpp.
References dispatchers_, gui2::event::dispatcher::fire(), and gui2::event::SDL_ACTIVATE.
Referenced by handle_event().
|
private |
Handles a joystick button down event.
event | The SDL joystick button event triggered. |
Definition at line 742 of file handler.cpp.
References hotkey::get_hotkey(), and hotkey_pressed().
Referenced by handle_event().
|
private |
Fires a CLOSE_WINDOW event for the window with the given ID.
window_id | The ID of the window to close. |
Definition at line 824 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().
void gui2::event::sdl_event_handler::connect | ( | dispatcher * | dispatcher | ) |
Connects a dispatcher.
dispatcher | The dispatcher to connect. |
Definition at line 528 of file handler.cpp.
References DBG_GUI_E, dispatchers_, gui2::event::event_context, utils::find(), events::sdl_handler::join(), and LOG_GUI_E.
void gui2::event::sdl_event_handler::disconnect | ( | dispatcher * | dispatcher | ) |
Disconnects a dispatcher.
dispatcher | The dispatcher to disconnect. |
Definition at line 544 of file handler.cpp.
References DBG_GUI_E, dispatchers_, gui2::event::event_context, utils::find(), keyboard_focus_, events::sdl_handler::leave(), LOG_GUI_E, and mouse_focus.
|
inline |
Returns all dispatchers in the Z order.
Definition at line 153 of file handler.cpp.
References dispatchers_.
|
overridevirtual |
Inherited from events::sdl_handler.
No dispatchers drop the event.
Implements events::sdl_handler.
Definition at line 371 of file handler.cpp.
References activate(), gui2::button::button(), button_down(), c, close_window(), CLOSE_WINDOW_EVENT, dispatchers_, DOUBLE_CLICK_EVENT, gui2::execute_timer(), video::game_canvas_size(), gui2::get_mouse_position(), hat_motion(), HOVER_REMOVE_POPUP_EVENT, key_down(), mouse(), mouse_button_down(), mouse_button_up(), mouse_wheel(), draw::point(), raw_event(), gui2::event::SDL_MOUSE_MOTION, gui2::event::SHOW_HELPTIP, SHOW_HELPTIP_EVENT, text_editing(), TIMER_EVENT, touch_down(), touch_motion(), touch_multi_gesture(), touch_up(), video_resize(), and WRN_GUI_E.
Referenced by handle_window_event().
|
overridevirtual |
Inherited from events::sdl_handler.
Reimplemented from events::sdl_handler.
Definition at line 523 of file handler.cpp.
References handle_event().
|
private |
Handles a hat motion event.
event | The SDL joystick hat event triggered. |
Definition at line 729 of file handler.cpp.
References hotkey::get_hotkey(), and hotkey_pressed().
Referenced by handle_event().
|
private |
Handles the pressing of a hotkey.
key | The hotkey item pressed. |
Definition at line 791 of file handler.cpp.
References hotkey::hotkey_command::command, gui2::event::dispatcher::execute_hotkey(), hotkey::get_hotkey_command(), and keyboard_dispatcher().
Referenced by button_down(), hat_motion(), and key_down().
|
private |
Fires a key down event.
event | The SDL keyboard event triggered. |
Definition at line 755 of file handler.cpp.
References hotkey::get_hotkey(), hotkey_pressed(), and text_input().
Referenced by handle_event(), and text_input().
|
private |
Fires a key down 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 800 of file handler.cpp.
References DBG_GUI_E, gui2::event::dispatcher::fire(), keyboard_dispatcher(), and gui2::event::SDL_KEY_DOWN.
|
private |
Fires a keyboard event which has no parameters.
This can happen for example when the mouse wheel is used.
event | The event to fire. |
Definition at line 815 of file handler.cpp.
References DBG_GUI_E, gui2::event::dispatcher::fire(), and keyboard_dispatcher().
|
private |
Gets the dispatcher that wants to receive the keyboard input.
nullptr | No dispatcher found. |
Definition at line 686 of file handler.cpp.
References dispatchers_, gui2::event::dispatcher::get_want_keyboard_input(), keyboard_focus_, and utils::views::reverse.
Referenced by hotkey_pressed(), key_down(), keyboard(), text_editing(), and text_input().
Fires a generic mouse event.
event | The event to fire. |
position | The position of the mouse. |
Definition at line 603 of file handler.cpp.
References gui2::event::dispatcher::all, DBG_GUI_E, dispatchers_, gui2::event::dispatcher::fire(), gui2::event::dispatcher::get_mouse_behavior(), gui2::event::dispatcher::is_at(), mouse_focus, gui2::event::dispatcher::none, and utils::views::reverse.
Referenced by handle_event(), mouse_button_down(), mouse_button_up(), and mouse_wheel().
|
private |
Fires a mouse button down event.
position | The position of the mouse. |
button | The SDL id of the button that caused the event. |
Definition at line 650 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().
|
private |
Fires a mouse button up event.
position | The position of the mouse. |
button | The SDL id of the button that caused the event. |
Definition at line 629 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().
|
private |
Fires a mouse wheel event.
position | The position of the mouse. |
scrollx | The amount of horizontal scrolling. |
scrolly | The amount of vertical scrolling. |
Definition at line 671 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().
|
private |
Fires a raw SDL event.
Definition at line 594 of file handler.cpp.
References DBG_GUI_E, dispatchers_, gui2::event::dispatcher::fire(), and gui2::event::SDL_RAW_EVENT.
Referenced by handle_event().
|
private |
Fires a text editing event.
unicode | The unicode value for the text being edited. |
start | The start position for the text being edited. |
len | The selection length for the text being edited. |
Definition at line 782 of file handler.cpp.
References gui2::event::dispatcher::fire(), keyboard_dispatcher(), gui2::event::SDL_TEXT_EDITING, and editor::start().
Referenced by handle_event().
|
private |
Fires a text input event.
unicode | The unicode value for the text entered. |
Definition at line 771 of file handler.cpp.
References gui2::event::dispatcher::fire(), key_down(), keyboard_dispatcher(), and gui2::event::SDL_TEXT_INPUT.
Referenced by key_down().
|
private |
Fires a touch "finger down" event.
position | The position touched. |
Definition at line 715 of file handler.cpp.
References dispatchers_, gui2::event::dispatcher::fire(), utils::views::reverse, and gui2::event::SDL_TOUCH_DOWN.
Referenced by handle_event().
|
private |
Fires a touch-moved event.
position | The position touched. |
distance | The distance moved. |
Definition at line 701 of file handler.cpp.
References dispatchers_, gui2::event::dispatcher::fire(), utils::views::reverse, and gui2::event::SDL_TOUCH_MOTION.
Referenced by handle_event().
|
private |
Fires a touch gesture event.
center | the center of gesture |
dTheta | the amount that the fingers rotated during this motion |
dDist | the amount that the fingers pinched during this motion |
numFingers | the number of fingers used in the gesture |
Definition at line 722 of file handler.cpp.
References dispatchers_, gui2::event::dispatcher::fire(), utils::views::reverse, and gui2::event::SDL_TOUCH_MULTI_GESTURE.
Referenced by handle_event().
|
private |
Fires a touch "finger up" event.
position | The position touched. |
Definition at line 708 of file handler.cpp.
References dispatchers_, gui2::event::dispatcher::fire(), utils::views::reverse, and gui2::event::SDL_TOUCH_UP.
Referenced by handle_event().
|
private |
Fires a video resize event.
new_size | The new size of the window. |
Definition at line 584 of file handler.cpp.
References DBG_GUI_E, dispatchers_, gui2::event::dispatcher::fire(), and gui2::event::SDL_VIDEO_RESIZE.
Referenced by handle_event().
|
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.
dispatcher | The dispatcher which should get the keyboard focus. |
Definition at line 910 of file handler.cpp.
|
friend |
|
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 335 of file handler.cpp.
Referenced by activate(), connect(), disconnect(), get_dispatchers(), handle_event(), keyboard_dispatcher(), mouse(), raw_event(), touch_down(), touch_motion(), touch_multi_gesture(), touch_up(), and video_resize().
|
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 342 of file handler.cpp.
Referenced by disconnect(), and keyboard_dispatcher().
dispatcher* gui2::event::sdl_event_handler::mouse_focus |
The dispatcher that captured the mouse focus.
Definition at line 156 of file handler.cpp.
Referenced by disconnect(), and mouse().