16 #define GETTEXT_DOMAIN "wesnoth-lib"
61 static std::unique_ptr<class sdl_event_handler>
handler_ =
nullptr;
64 #ifdef MAIN_EVENT_HANDLER
65 static unsigned draw_interval = 0;
66 static unsigned event_poll_interval = 0;
77 static uint32_t timer_sdl_draw_event(uint32_t,
void*)
87 SDL_PushEvent(&event);
98 static uint32_t timer_sdl_poll_events(uint32_t,
void*)
108 return event_poll_interval;
270 void key_down(
const SDL_Event& event);
290 void key_down(
const SDL_Keycode key,
291 const SDL_Keymod modifier,
292 const std::string& unicode);
345 :
events::sdl_handler(false)
346 , mouse_focus(nullptr)
348 , keyboard_focus_(nullptr)
350 if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
351 if(SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
379 case SDL_MOUSEMOTION:
380 #ifdef MOUSE_TOUCH_EMULATION
382 if (event.motion.state != 0)
389 case SDL_MOUSEBUTTONDOWN:
395 case SDL_MOUSEBUTTONUP:
414 execute_timer(
reinterpret_cast<std::size_t
>(event.user.data1));
421 case SDL_JOYBUTTONDOWN:
425 case SDL_JOYBUTTONUP:
428 case SDL_JOYAXISMOTION:
431 case SDL_JOYHATMOTION:
439 case SDL_WINDOWEVENT:
440 switch(event.window.event) {
444 case SDL_WINDOWEVENT_SIZE_CHANGED:
448 case SDL_WINDOWEVENT_ENTER:
449 case SDL_WINDOWEVENT_FOCUS_GAINED:
460 case SDL_TEXTEDITING:
461 text_editing(event.edit.text, event.edit.start, event.edit.length);
464 case SDL_FINGERMOTION:
468 point(event.tfinger.x *
c.x, event.tfinger.y *
c.y),
469 point(event.tfinger.dx *
c.x, event.tfinger.dy *
c.y)
488 case SDL_MULTIGESTURE:
492 point(event.mgesture.x *
c.x, event.mgesture.y *
c.y),
493 event.mgesture.dTheta, event.mgesture.dDist,
494 event.mgesture.numFingers
499 #if(defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
511 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
512 WRN_GUI_E <<
"Unhandled event " <<
static_cast<uint32_t
>(
event.type)
534 LOG_GUI_E <<
"creating new dispatcher event context";
548 DBG_GUI_E <<
"removing dispatcher " <<
static_cast<void*
>(disp);
568 LOG_GUI_E <<
"deleting unused dispatcher event context";
630 case SDL_BUTTON_LEFT:
633 case SDL_BUTTON_MIDDLE:
636 case SDL_BUTTON_RIGHT:
640 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
641 WRN_GUI_E <<
"Unhandled 'mouse button up' event for button "
642 <<
static_cast<uint32_t
>(
button) <<
".";
651 case SDL_BUTTON_LEFT:
654 case SDL_BUTTON_MIDDLE:
657 case SDL_BUTTON_RIGHT:
661 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
662 WRN_GUI_E <<
"Unhandled 'mouse button down' event for button "
663 <<
static_cast<uint32_t
>(
button) <<
".";
761 if(event.type == SDL_TEXTINPUT) {
764 key_down(event.key.keysym.sym,
static_cast<SDL_Keymod
>(event.key.keysym.mod),
"");
771 key_down(SDLK_UNKNOWN,
static_cast<SDL_Keymod
>(0), unicode);
785 unicode,
start, len);
799 const SDL_Keymod modifier,
800 const std::string& unicode)
838 #ifdef MAIN_EVENT_HANDLER
840 SDL_AddTimer(draw_interval, timer_sdl_draw_event,
nullptr);
842 event_poll_interval = 10;
843 SDL_AddTimer(event_poll_interval, timer_sdl_poll_events,
nullptr);
851 #ifdef MAIN_EVENT_HANDLER
853 event_poll_interval = 0;
884 event.type = SDL_MOUSEMOTION;
885 event.motion.type = SDL_MOUSEMOTION;
886 event.motion.x =
mouse.x;
887 event.motion.y =
mouse.y;
889 SDL_PushEvent(&event);
924 stream <<
"close window";
927 stream <<
"SDL video resize";
930 stream <<
"SDL mouse motion";
933 stream <<
"mouse enter";
936 stream <<
"mouse leave";
939 stream <<
"mouse motion";
942 stream <<
"SDL left button down";
945 stream <<
"SDL left button up";
948 stream <<
"left button down";
951 stream <<
"left button up";
954 stream <<
"left button click";
957 stream <<
"left button double click";
960 stream <<
"SDL middle button down";
963 stream <<
"SDL middle button up";
966 stream <<
"middle button down";
969 stream <<
"middle button up";
972 stream <<
"middle button click";
975 stream <<
"middle button double click";
978 stream <<
"SDL right button down";
981 stream <<
"SDL right button up";
984 stream <<
"right button down";
987 stream <<
"right button up";
990 stream <<
"right button click";
993 stream <<
"right button double click";
996 stream <<
"SDL wheel left";
999 stream <<
"SDL wheel right";
1002 stream <<
"SDL wheel up";
1005 stream <<
"SDL wheel down";
1008 stream <<
"SDL key down";
1011 stream <<
"SDL text input";
1014 stream <<
"SDL text editing";
1018 stream <<
"notify removal";
1021 stream <<
"notify modified";
1024 stream <<
"receive keyboard focus";
1027 stream <<
"lose keyboard focus";
1030 stream <<
"show tooltip";
1033 stream <<
"notify remove tooltip";
1036 stream <<
"SDL activate";
1039 stream <<
"message show tooltip";
1042 stream <<
"show helptip";
1045 stream <<
"message show helptip";
1048 stream <<
"request placement";
1051 stream <<
"SDL touch motion";
1054 stream <<
"SDL touch up";
1057 stream <<
"SDL touch down";
1060 stream <<
"SDL multi-touch gesture";
1063 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?
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.
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 reversed_view(T &container)
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.