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);
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) {
444 case SDL_WINDOWEVENT_RESIZED:
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)
477 touch_up(
point(event.tfinger.x * c.x, event.tfinger.y * 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)
531 DBG_GUI_E <<
"adding dispatcher " <<
static_cast<void*
>(dispatcher);
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";
571 event_context =
nullptr;
631 case SDL_BUTTON_LEFT:
634 case SDL_BUTTON_MIDDLE:
637 case SDL_BUTTON_RIGHT:
641 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS 642 WRN_GUI_E <<
"Unhandled 'mouse button up' event for button " 643 <<
static_cast<uint32_t
>(button) <<
".";
652 case SDL_BUTTON_LEFT:
655 case SDL_BUTTON_MIDDLE:
658 case SDL_BUTTON_RIGHT:
662 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS 663 WRN_GUI_E <<
"Unhandled 'mouse button down' event for button " 664 <<
static_cast<uint32_t
>(button) <<
".";
762 if(event.type == SDL_TEXTINPUT) {
765 key_down(event.key.keysym.sym, static_cast<SDL_Keymod>(event.key.keysym.mod),
"");
772 key_down(SDLK_UNKNOWN, static_cast<SDL_Keymod>(0), unicode);
786 unicode, start, len);
800 const SDL_Keymod modifier,
801 const std::string& unicode)
829 window->
fire(CLOSE_WINDOW, *window);
839 #ifdef MAIN_EVENT_HANDLER 841 SDL_AddTimer(draw_interval, timer_sdl_draw_event,
nullptr);
843 event_poll_interval = 10;
844 SDL_AddTimer(event_poll_interval, timer_sdl_poll_events,
nullptr);
850 handler_.reset(
nullptr);
852 #ifdef MAIN_EVENT_HANDLER 854 event_poll_interval = 0;
864 handler_->connect(dispatcher);
871 handler_->disconnect(dispatcher);
877 return handler_->get_dispatchers();
885 event.type = SDL_MOUSEMOTION;
886 event.motion.type = SDL_MOUSEMOTION;
887 event.motion.x = mouse.x;
888 event.motion.y = mouse.y;
890 SDL_PushEvent(&event);
897 handler_->mouse_focus = dispatcher;
904 if(handler_->mouse_focus == dispatcher) {
905 handler_->mouse_focus =
nullptr;
915 handler_->keyboard_focus_ = dispatcher;
925 stream <<
"close window";
928 stream <<
"SDL video resize";
931 stream <<
"SDL mouse motion";
934 stream <<
"mouse enter";
937 stream <<
"mouse leave";
940 stream <<
"mouse motion";
943 stream <<
"SDL left button down";
946 stream <<
"SDL left button up";
949 stream <<
"left button down";
952 stream <<
"left button up";
955 stream <<
"left button click";
958 stream <<
"left button double click";
961 stream <<
"SDL middle button down";
964 stream <<
"SDL middle button up";
967 stream <<
"middle button down";
970 stream <<
"middle button up";
973 stream <<
"middle button click";
976 stream <<
"middle button double click";
979 stream <<
"SDL right button down";
982 stream <<
"SDL right button up";
985 stream <<
"right button down";
988 stream <<
"right button up";
991 stream <<
"right button click";
994 stream <<
"right button double click";
997 stream <<
"SDL wheel left";
1000 stream <<
"SDL wheel right";
1003 stream <<
"SDL wheel up";
1006 stream <<
"SDL wheel down";
1009 stream <<
"SDL key down";
1012 stream <<
"SDL text input";
1015 stream <<
"SDL text editing";
1019 stream <<
"notify removal";
1022 stream <<
"notify modified";
1025 stream <<
"receive keyboard focus";
1028 stream <<
"lose keyboard focus";
1031 stream <<
"show tooltip";
1034 stream <<
"notify remove tooltip";
1037 stream <<
"SDL activate";
1040 stream <<
"message show tooltip";
1043 stream <<
"show helptip";
1046 stream <<
"message show helptip";
1049 stream <<
"request placement";
1052 stream <<
"SDL touch motion";
1055 stream <<
"SDL touch up";
1058 stream <<
"SDL touch down";
1061 stream <<
"SDL multi-touch gesture";
1064 stream <<
"SDL raw event";
1078 if(*iter == window) {
mouse_behavior get_mouse_behavior() const
Define the common log macros for the gui toolkit.
dispatcher * keyboard_focus_
Needed to determine which dispatcher gets the keyboard events.
static std::unique_ptr< class sdl_event_handler > handler_
void touch_multi_gesture(const point ¢er, float dTheta, float dDist, uint8_t numFingers)
Fires a touch gesture event.
ui_event
The event sent to the dispatcher.
void video_resize(const point &new_size)
Fires a video resize event.
bool hotkey_pressed(const hotkey::hotkey_ptr key)
Handles the pressing of a hotkey.
Base class for event handling.
void activate()
Reinitializes the state of all dispatchers.
auto reversed_view(T &container)
void handle_window_event(const SDL_Event &event) override
Inherited from events::sdl_handler.
void text_editing(const std::string &unicode, int32_t start, int32_t len)
Fires a text editing event.
An SDL text input (commit) event.
bool is_in_dialog()
Is a dialog open?
void capture_mouse(dispatcher *dispatcher)
Captures the mouse.
void button_down(const SDL_Event &event)
Handles a joystick button down event.
void hat_motion(const SDL_Event &event)
Handles a hat motion event.
void key_down(const SDL_Event &event)
Fires a key down event.
void touch_motion(const point &position, const point &distance)
Fires a touch-moved event.
void init_mouse_location()
Initializes the location of the mouse.
#define CLOSE_WINDOW_EVENT
bool get_want_keyboard_input() const
An SDL text editing (IME) event.
static events::event_context * event_context
EXIT_STATUS start(const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
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...
virtual bool is_at(const point &coordinate) const =0
Determines whether the location is inside an active widget.
This singleton class handles all events.
void close_window(const unsigned window_id)
Fires a CLOSE_WINDOW event for the window with the given ID.
std::shared_ptr< class hotkey_base > hotkey_ptr
std::vector< dispatcher * > & get_all_dispatchers()
Gets all event dispatchers in the Z order.
friend void capture_keyboard(dispatcher *dispatcher)
Captures the keyboard.
bool execute_hotkey(const hotkey::HOTKEY_COMMAND id)
Executes a hotkey.
void remove_from_window_stack(window *window)
Removes a entry from the open_window_stack list.
void disconnect_dispatcher(dispatcher *dispatcher)
Disconnects a dispatcher to the event handler.
sdl_handler(sdl_handler &&)=delete
void connect_dispatcher(dispatcher *dispatcher)
Connects a dispatcher to the event handler.
std::vector< dispatcher * > & get_dispatchers()
Returns all dispatchers in the Z order.
void pump()
Process all events currently in the queue.
void mouse_button_up(const point &position, const uint8_t button)
Fires a mouse button up event.
static window * window_instance(const unsigned handle)
Returns the instance of a window.
void mouse(const ui_event event, const point &position)
Fires a generic mouse event.
void mouse_wheel(const point &position, int scrollx, int scrolly)
Fires a mouse wheel event.
#define DOUBLE_CLICK_EVENT
void mouse_button_down(const point &position, const uint8_t button)
Fires a mouse button down event.
void text_input(const std::string &unicode)
Fires a text input event.
#define SHOW_HELPTIP_EVENT
point game_canvas_size()
The size of the game canvas, in drawing coordinates / game pixels.
void disconnect(dispatcher *dispatcher)
Disconnects a dispatcher.
std::ostream & operator<<(std::ostream &stream, const ui_event event)
Contains the gui2 timer routines.
#define HOVER_REMOVE_POPUP_EVENT
void keyboard(const ui_event event)
Fires a keyboard event which has no parameters.
Type that can be thrown as an exception to quit to desktop.
void raw_event(const SDL_Event &event)
Fires a raw SDL event.
Handling of system events.
point get_mouse_position()
Returns the current mouse position.
void touch_up(const point &position)
Fires a touch "finger up" event.
std::vector< dispatcher * > dispatchers_
The dispatchers.
void handle_event(const SDL_Event &event) override
Inherited from events::sdl_handler.
void connect(dispatcher *dispatcher)
Connects a dispatcher.
void release_mouse(dispatcher *dispatcher)
Releases a captured mouse.
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
void point(int x, int y)
Draw a single point.
dispatcher * keyboard_dispatcher()
Gets the dispatcher that wants to receive the keyboard input.
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
void touch_down(const point &position)
Fires a touch "finger down" event.
base class of top level items, the only item which needs to store the final canvases to draw on...
dispatcher * mouse_focus
The dispatcher that captured the mouse focus.
bool execute_timer(const std::size_t id)
Executes a timer.
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...