16 #define GETTEXT_DOMAIN "wesnoth-lib"
64 static std::unique_ptr<class sdl_event_handler>
handler_ =
nullptr;
67 #ifdef MAIN_EVENT_HANDLER
68 static unsigned draw_interval = 0;
69 static unsigned event_poll_interval = 0;
80 static uint32_t timer_sdl_draw_event(uint32_t,
void*)
90 SDL_PushEvent(&event);
101 static uint32_t timer_sdl_poll_events(uint32_t,
void*)
111 return event_poll_interval;
273 void key_down(
const SDL_Event& event);
293 void key_down(
const SDL_Keycode key,
294 const SDL_Keymod modifier,
295 const std::string& unicode);
348 :
events::sdl_handler(false)
349 , mouse_focus(nullptr)
351 , keyboard_focus_(nullptr)
353 if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
354 if(SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
382 case SDL_MOUSEMOTION:
383 #ifdef MOUSE_TOUCH_EMULATION
385 if (event.motion.state != 0)
392 case SDL_MOUSEBUTTONDOWN:
398 case SDL_MOUSEBUTTONUP:
417 execute_timer(
reinterpret_cast<std::size_t
>(event.user.data1));
424 case SDL_JOYBUTTONDOWN:
428 case SDL_JOYBUTTONUP:
431 case SDL_JOYAXISMOTION:
434 case SDL_JOYHATMOTION:
442 case SDL_WINDOWEVENT:
443 switch(event.window.event) {
447 case SDL_WINDOWEVENT_SIZE_CHANGED:
451 case SDL_WINDOWEVENT_ENTER:
452 case SDL_WINDOWEVENT_FOCUS_GAINED:
463 case SDL_TEXTEDITING:
464 text_editing(event.edit.text, event.edit.start, event.edit.length);
467 case SDL_FINGERMOTION:
471 point(event.tfinger.x *
c.x, event.tfinger.y *
c.y),
472 point(event.tfinger.dx *
c.x, event.tfinger.dy *
c.y)
491 case SDL_MULTIGESTURE:
495 point(event.mgesture.x *
c.x, event.mgesture.y *
c.y),
496 event.mgesture.dTheta, event.mgesture.dDist,
497 event.mgesture.numFingers
502 #if(defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
514 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
515 WRN_GUI_E <<
"Unhandled event " <<
static_cast<uint32_t
>(
event.type)
537 LOG_GUI_E <<
"creating new dispatcher event context";
551 DBG_GUI_E <<
"removing dispatcher " <<
static_cast<void*
>(disp);
571 LOG_GUI_E <<
"deleting unused dispatcher event context";
634 case SDL_BUTTON_LEFT:
637 case SDL_BUTTON_MIDDLE:
640 case SDL_BUTTON_RIGHT:
644 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
645 WRN_GUI_E <<
"Unhandled 'mouse button up' event for button "
646 <<
static_cast<uint32_t
>(
button) <<
".";
655 case SDL_BUTTON_LEFT:
658 case SDL_BUTTON_MIDDLE:
661 case SDL_BUTTON_RIGHT:
665 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
666 WRN_GUI_E <<
"Unhandled 'mouse button down' event for button "
667 <<
static_cast<uint32_t
>(
button) <<
".";
765 if(event.type == SDL_TEXTINPUT) {
768 key_down(event.key.keysym.sym,
static_cast<SDL_Keymod
>(event.key.keysym.mod),
"");
775 key_down(SDLK_UNKNOWN,
static_cast<SDL_Keymod
>(0), unicode);
789 unicode,
start, len);
803 const SDL_Keymod modifier,
804 const std::string& unicode)
842 #ifdef MAIN_EVENT_HANDLER
844 SDL_AddTimer(draw_interval, timer_sdl_draw_event,
nullptr);
846 event_poll_interval = 10;
847 SDL_AddTimer(event_poll_interval, timer_sdl_poll_events,
nullptr);
855 #ifdef MAIN_EVENT_HANDLER
857 event_poll_interval = 0;
888 event.type = SDL_MOUSEMOTION;
889 event.motion.type = SDL_MOUSEMOTION;
890 event.motion.x =
mouse.x;
891 event.motion.y =
mouse.y;
893 SDL_PushEvent(&event);
928 stream <<
"close window";
931 stream <<
"SDL video resize";
934 stream <<
"SDL mouse motion";
937 stream <<
"mouse enter";
940 stream <<
"mouse leave";
943 stream <<
"mouse motion";
946 stream <<
"SDL left button down";
949 stream <<
"SDL left button up";
952 stream <<
"left button down";
955 stream <<
"left button up";
958 stream <<
"left button click";
961 stream <<
"left button double click";
964 stream <<
"SDL middle button down";
967 stream <<
"SDL middle button up";
970 stream <<
"middle button down";
973 stream <<
"middle button up";
976 stream <<
"middle button click";
979 stream <<
"middle button double click";
982 stream <<
"SDL right button down";
985 stream <<
"SDL right button up";
988 stream <<
"right button down";
991 stream <<
"right button up";
994 stream <<
"right button click";
997 stream <<
"right button double click";
1000 stream <<
"SDL wheel left";
1003 stream <<
"SDL wheel right";
1006 stream <<
"SDL wheel up";
1009 stream <<
"SDL wheel down";
1012 stream <<
"SDL key down";
1015 stream <<
"SDL text input";
1018 stream <<
"SDL text editing";
1022 stream <<
"notify removal";
1025 stream <<
"notify modified";
1028 stream <<
"receive keyboard focus";
1031 stream <<
"lose keyboard focus";
1034 stream <<
"show tooltip";
1037 stream <<
"notify remove tooltip";
1040 stream <<
"SDL activate";
1043 stream <<
"message show tooltip";
1046 stream <<
"show helptip";
1049 stream <<
"message show helptip";
1052 stream <<
"request placement";
1055 stream <<
"SDL touch motion";
1058 stream <<
"SDL touch up";
1061 stream <<
"SDL touch down";
1064 stream <<
"SDL multi-touch gesture";
1067 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.
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.
bool hotkey_pressed(const hotkey::hotkey_ptr key)
Handles the pressing of a hotkey.
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
static events::event_context * event_context
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)
void init_mouse_location()
Initializes the location of the mouse.
bool is_in_dialog()
Is a dialog open?
void remove_from_window_stack(window *window)
Removes a entry from the open_window_stack list.
point get_mouse_position()
Returns the current mouse position.
std::vector< window * > open_window_stack
Keeps track of any open windows of any type (modal, non-modal, or tooltip) in the order in which they...
bool execute_timer(const std::size_t id)
Executes a timer.
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...
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
auto reversed_view(T &container)
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.