16 #define GETTEXT_DOMAIN "wesnoth-lib"
63 static std::unique_ptr<class sdl_event_handler>
handler_ =
nullptr;
66 #ifdef MAIN_EVENT_HANDLER
67 static unsigned draw_interval = 0;
68 static unsigned event_poll_interval = 0;
79 static uint32_t timer_sdl_draw_event(uint32_t,
void*)
89 SDL_PushEvent(&event);
100 static uint32_t timer_sdl_poll_events(uint32_t,
void*)
110 return event_poll_interval;
272 void key_down(
const SDL_Event& event);
292 void key_down(
const SDL_Keycode key,
293 const SDL_Keymod modifier,
294 const std::string& unicode);
347 :
events::sdl_handler(false)
348 , mouse_focus(nullptr)
350 , keyboard_focus_(nullptr)
352 if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
353 if(SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
381 case SDL_MOUSEMOTION:
382 #ifdef MOUSE_TOUCH_EMULATION
384 if (event.motion.state != 0)
391 case SDL_MOUSEBUTTONDOWN:
397 case SDL_MOUSEBUTTONUP:
416 execute_timer(
reinterpret_cast<std::size_t
>(event.user.data1));
423 case SDL_JOYBUTTONDOWN:
427 case SDL_JOYBUTTONUP:
430 case SDL_JOYAXISMOTION:
433 case SDL_JOYHATMOTION:
441 case SDL_WINDOWEVENT:
442 switch(event.window.event) {
446 case SDL_WINDOWEVENT_SIZE_CHANGED:
450 case SDL_WINDOWEVENT_ENTER:
451 case SDL_WINDOWEVENT_FOCUS_GAINED:
462 case SDL_TEXTEDITING:
463 text_editing(event.edit.text, event.edit.start, event.edit.length);
466 case SDL_FINGERMOTION:
470 point(event.tfinger.x *
c.x, event.tfinger.y *
c.y),
471 point(event.tfinger.dx *
c.x, event.tfinger.dy *
c.y)
490 case SDL_MULTIGESTURE:
494 point(event.mgesture.x *
c.x, event.mgesture.y *
c.y),
495 event.mgesture.dTheta, event.mgesture.dDist,
496 event.mgesture.numFingers
501 #if(defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
513 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
514 WRN_GUI_E <<
"Unhandled event " <<
static_cast<uint32_t
>(
event.type)
536 LOG_GUI_E <<
"creating new dispatcher event context";
550 DBG_GUI_E <<
"removing dispatcher " <<
static_cast<void*
>(disp);
570 LOG_GUI_E <<
"deleting unused dispatcher event context";
632 case SDL_BUTTON_LEFT:
635 case SDL_BUTTON_MIDDLE:
638 case SDL_BUTTON_RIGHT:
642 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
643 WRN_GUI_E <<
"Unhandled 'mouse button up' event for button "
644 <<
static_cast<uint32_t
>(
button) <<
".";
653 case SDL_BUTTON_LEFT:
656 case SDL_BUTTON_MIDDLE:
659 case SDL_BUTTON_RIGHT:
663 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
664 WRN_GUI_E <<
"Unhandled 'mouse button down' event for button "
665 <<
static_cast<uint32_t
>(
button) <<
".";
763 if(event.type == SDL_TEXTINPUT) {
766 key_down(event.key.keysym.sym,
static_cast<SDL_Keymod
>(event.key.keysym.mod),
"");
773 key_down(SDLK_UNKNOWN,
static_cast<SDL_Keymod
>(0), unicode);
787 unicode,
start, len);
801 const SDL_Keymod modifier,
802 const std::string& unicode)
840 #ifdef MAIN_EVENT_HANDLER
842 SDL_AddTimer(draw_interval, timer_sdl_draw_event,
nullptr);
844 event_poll_interval = 10;
845 SDL_AddTimer(event_poll_interval, timer_sdl_poll_events,
nullptr);
853 #ifdef MAIN_EVENT_HANDLER
855 event_poll_interval = 0;
886 event.type = SDL_MOUSEMOTION;
887 event.motion.type = SDL_MOUSEMOTION;
888 event.motion.x =
mouse.x;
889 event.motion.y =
mouse.y;
891 SDL_PushEvent(&event);
926 stream <<
"close window";
929 stream <<
"SDL video resize";
932 stream <<
"SDL mouse motion";
935 stream <<
"mouse enter";
938 stream <<
"mouse leave";
941 stream <<
"mouse motion";
944 stream <<
"SDL left button down";
947 stream <<
"SDL left button up";
950 stream <<
"left button down";
953 stream <<
"left button up";
956 stream <<
"left button click";
959 stream <<
"left button double click";
962 stream <<
"SDL middle button down";
965 stream <<
"SDL middle button up";
968 stream <<
"middle button down";
971 stream <<
"middle button up";
974 stream <<
"middle button click";
977 stream <<
"middle button double click";
980 stream <<
"SDL right button down";
983 stream <<
"SDL right button up";
986 stream <<
"right button down";
989 stream <<
"right button up";
992 stream <<
"right button click";
995 stream <<
"right button double click";
998 stream <<
"SDL wheel left";
1001 stream <<
"SDL wheel right";
1004 stream <<
"SDL wheel up";
1007 stream <<
"SDL wheel down";
1010 stream <<
"SDL key down";
1013 stream <<
"SDL text input";
1016 stream <<
"SDL text editing";
1020 stream <<
"notify removal";
1023 stream <<
"notify modified";
1026 stream <<
"receive keyboard focus";
1029 stream <<
"lose keyboard focus";
1032 stream <<
"show tooltip";
1035 stream <<
"notify remove tooltip";
1038 stream <<
"SDL activate";
1041 stream <<
"message show tooltip";
1044 stream <<
"show helptip";
1047 stream <<
"message show helptip";
1050 stream <<
"request placement";
1053 stream <<
"SDL touch motion";
1056 stream <<
"SDL touch up";
1059 stream <<
"SDL touch down";
1062 stream <<
"SDL multi-touch gesture";
1065 stream <<
"SDL raw event";
Base class for event handling.
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
virtual bool is_at(const point &coordinate) const =0
Determines whether the location is inside an active widget.
bool get_want_keyboard_input() const
bool execute_hotkey(const hotkey::HOTKEY_COMMAND id)
Executes a hotkey.
mouse_behavior get_mouse_behavior() const
This singleton class handles all events.
void touch_down(const point &position)
Fires a touch "finger down" event.
void keyboard(const ui_event event)
Fires a keyboard event which has no parameters.
void activate()
Reinitializes the state of all dispatchers.
void disconnect(dispatcher *dispatcher)
Disconnects a dispatcher.
void mouse_button_up(const point &position, const uint8_t button)
Fires a mouse button up event.
void close_window(const unsigned window_id)
Fires a CLOSE_WINDOW event for the window with the given ID.
void handle_window_event(const SDL_Event &event) override
Inherited from events::sdl_handler.
void video_resize(const point &new_size)
Fires a video resize event.
void text_editing(const std::string &unicode, int32_t start, int32_t len)
Fires a text editing event.
void touch_up(const point &position)
Fires a touch "finger up" event.
std::vector< dispatcher * > & get_dispatchers()
Returns all dispatchers in the Z order.
dispatcher * keyboard_dispatcher()
Gets the dispatcher that wants to receive the keyboard input.
friend void capture_keyboard(dispatcher *dispatcher)
Captures the keyboard.
void text_input(const std::string &unicode)
Fires a text input event.
void touch_motion(const point &position, const point &distance)
Fires a touch-moved event.
bool hotkey_pressed(const hotkey::hotkey_ptr &key)
Handles the pressing of a hotkey.
void mouse_button_down(const point &position, const uint8_t button)
Fires a mouse button down event.
void hat_motion(const SDL_Event &event)
Handles a hat motion event.
dispatcher * keyboard_focus_
Needed to determine which dispatcher gets the keyboard events.
void connect(dispatcher *dispatcher)
Connects a dispatcher.
void key_down(const SDL_Event &event)
Fires a key down event.
void mouse(const ui_event event, const point &position)
Fires a generic mouse event.
void touch_multi_gesture(const point ¢er, float dTheta, float dDist, uint8_t numFingers)
Fires a touch gesture event.
void mouse_wheel(const point &position, int scrollx, int scrolly)
Fires a mouse wheel event.
std::vector< dispatcher * > dispatchers_
The dispatchers.
void button_down(const SDL_Event &event)
Handles a joystick button down event.
dispatcher * mouse_focus
The dispatcher that captured the mouse focus.
void raw_event(const SDL_Event &event)
Fires a raw SDL event.
void handle_event(const SDL_Event &event) override
Inherited from events::sdl_handler.
base class of top level items, the only item which needs to store the final canvases to draw on.
static window * window_instance(const unsigned handle)
Returns the instance of a window.
Type that can be thrown as an exception to quit to desktop.
#define CLOSE_WINDOW_EVENT
#define SHOW_HELPTIP_EVENT
#define DOUBLE_CLICK_EVENT
#define HOVER_REMOVE_POPUP_EVENT
Define the common log macros for the gui toolkit.
void point(int x, int y)
Draw a single point.
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
Handling of system events.
void pump()
Process all events currently in the queue.
ui_event
The event sent to the dispatcher.
@ MIDDLE_BUTTON_DOUBLE_CLICK
@ SDL_TEXT_INPUT
An SDL text input (commit) event.
@ SDL_TEXT_EDITING
An SDL text editing (IME) event.
@ LEFT_BUTTON_DOUBLE_CLICK
@ SDL_TOUCH_MULTI_GESTURE
@ RIGHT_BUTTON_DOUBLE_CLICK
void capture_mouse(dispatcher *dispatcher)
Captures the mouse.
void release_mouse(dispatcher *dispatcher)
Releases a captured mouse.
void disconnect_dispatcher(dispatcher *dispatcher)
Disconnects a dispatcher to the event handler.
static std::unique_ptr< class sdl_event_handler > handler_
void capture_keyboard(dispatcher *dispatcher)
Captures the keyboard.
@ mouse
Callbacks with a coordinate as extra parameter.
void connect_dispatcher(dispatcher *dispatcher)
Connects a dispatcher to the event handler.
std::vector< dispatcher * > & get_all_dispatchers()
Gets all event dispatchers in the Z order.
std::ostream & operator<<(std::ostream &stream, const ui_event event)
static std::unique_ptr< events::event_context > event_context
void init_mouse_location()
Initializes the location of the mouse.
bool is_in_dialog()
Is a dialog open?
point get_mouse_position()
Returns the current mouse position.
bool execute_timer(const std::size_t id)
Executes a timer.
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
std::shared_ptr< class hotkey_base > hotkey_ptr
const hotkey_ptr get_hotkey(const SDL_Event &event)
Iterate through the list of hotkeys and return a hotkey that matches the SDL_Event and the current ke...
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
point game_canvas_size()
The size of the game canvas, in drawing coordinates / game pixels.
HOTKEY_COMMAND command
The command associated with this hotkey.
Contains the gui2 timer routines.