15 #define GETTEXT_DOMAIN "wesnoth-lib"
63 #ifdef MAIN_EVENT_HANDLER
64 static unsigned draw_interval = 0;
65 static unsigned event_poll_interval = 0;
76 static Uint32 timer_sdl_draw_event(Uint32,
void*)
91 SDL_PushEvent(&event);
102 static Uint32 timer_sdl_poll_events(Uint32,
void*)
112 return event_poll_interval;
168 void draw(
const bool force);
241 void key_down(
const SDL_Event& event);
298 :
events::sdl_handler(false)
299 , mouse_focus(nullptr)
301 , keyboard_focus_(nullptr)
303 if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
304 if(SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
330 case SDL_MOUSEMOTION:
334 case SDL_MOUSEBUTTONDOWN:
336 event.button.button);
339 case SDL_MOUSEBUTTONUP:
341 event.button.button);
377 case SDL_JOYBUTTONDOWN:
381 case SDL_JOYBUTTONUP:
384 case SDL_JOYAXISMOTION:
387 case SDL_JOYHATMOTION:
395 case SDL_WINDOWEVENT:
396 switch(event.window.event) {
397 case SDL_WINDOWEVENT_EXPOSED:
401 case SDL_WINDOWEVENT_RESIZED:
403 tpoint(event.window.data1, event.window.data2));
406 case SDL_WINDOWEVENT_ENTER:
407 case SDL_WINDOWEVENT_FOCUS_GAINED:
418 #if(defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
430 WRN_GUI_E <<
"Unhandled event " <<
static_cast<Uint32
>(
event.type)
480 assert(
std::find(dispatchers_.begin(), dispatchers_.end(), dispatcher)
481 == dispatchers_.end());
483 if(dispatchers_.empty()) {
486 event_context =
nullptr;
495 SDL_ACTIVATE, dynamic_cast<twidget&>(*dispatcher),
nullptr);
530 dispatcher->fire(
DRAW, dynamic_cast<twidget&>(*dispatcher));
533 if(!dispatchers_.empty()) {
534 CVideo& video =
dynamic_cast<twindow&
>(*dispatchers_.back()).video();
546 dispatcher->fire(SDL_VIDEO_RESIZE,
547 dynamic_cast<twidget&>(*dispatcher),
554 DBG_GUI_E <<
"Firing: " <<
event <<
".\n";
558 event, dynamic_cast<twidget&>(*
mouse_focus), position);
561 for(std::vector<tdispatcher*>::reverse_iterator ritor
568 .fire(event, dynamic_cast<twidget&>(**ritor), position);
574 if((**ritor).is_at(position)) {
576 .fire(event, dynamic_cast<twidget&>(**ritor), position);
586 case SDL_BUTTON_LEFT:
589 case SDL_BUTTON_MIDDLE:
592 case SDL_BUTTON_RIGHT:
598 WRN_GUI_E <<
"Unhandled 'mouse button up' event for button "
599 <<
static_cast<Uint32
>(button) <<
".\n";
616 case SDL_BUTTON_LEFT:
619 case SDL_BUTTON_MIDDLE:
622 case SDL_BUTTON_RIGHT:
626 WRN_GUI_E <<
"Unhandled 'mouse button down' event for button "
627 <<
static_cast<Uint32
>(button) <<
".\n";
653 for(std::vector<tdispatcher*>::reverse_iterator ritor
658 if((**ritor).get_want_keyboard_input()) {
701 static_cast<const SDL_Keymod>(event.key.keysym.mod),
708 key_down(static_cast<SDLKey>(0), static_cast<SDLMod>(0), unicode);
729 dispatcher->fire(SDL_KEY_DOWN,
730 dynamic_cast<twidget&>(*dispatcher),
739 DBG_GUI_E <<
"Firing: " <<
event <<
".\n";
742 dispatcher->fire(event, dynamic_cast<twidget&>(*dispatcher));
752 #ifdef MAIN_EVENT_HANDLER
754 SDL_AddTimer(draw_interval, timer_sdl_draw_event,
nullptr);
756 event_poll_interval = 10;
757 SDL_AddTimer(event_poll_interval, timer_sdl_poll_events,
nullptr);
766 #ifdef MAIN_EVENT_HANDLER
768 event_poll_interval = 0;
793 event.type = SDL_MOUSEMOTION;
794 event.motion.type = SDL_MOUSEMOTION;
795 event.motion.x = mouse.
x;
796 event.motion.y = mouse.
y;
798 SDL_PushEvent(&event);
833 stream <<
"close window";
836 stream <<
"SDL video resize";
839 stream <<
"SDL mouse motion";
842 stream <<
"mouse enter";
845 stream <<
"mouse leave";
848 stream <<
"mouse motion";
851 stream <<
"SDL left button down";
854 stream <<
"SDL left button up";
857 stream <<
"left button down";
860 stream <<
"left button up";
863 stream <<
"left button click";
866 stream <<
"left button double click";
869 stream <<
"SDL middle button down";
872 stream <<
"SDL middle button up";
875 stream <<
"middle button down";
878 stream <<
"middle button up";
881 stream <<
"middle button click";
884 stream <<
"middle button double click";
887 stream <<
"SDL right button down";
890 stream <<
"SDL right button up";
893 stream <<
"right button down";
896 stream <<
"right button up";
899 stream <<
"right button click";
902 stream <<
"right button double click";
905 stream <<
"SDL wheel left";
908 stream <<
"SDL wheel right";
911 stream <<
"SDL wheel up";
914 stream <<
"SDL wheel down";
917 stream <<
"SDL key down";
921 stream <<
"notify removal";
924 stream <<
"notify modified";
927 stream <<
"receive keyboard focus";
930 stream <<
"lose keyboard focus";
933 stream <<
"show tooltip";
936 stream <<
"notify remove tooltip";
939 stream <<
"SDL activate";
942 stream <<
"message show tooltip";
945 stream <<
"show helptip";
948 stream <<
"message show helptip";
951 stream <<
"request placement";
Define the common log macros for the gui toolkit.
Widget loses keyboard focus.
Request for somebody to show the tooltip based on the data send.
friend void capture_keyboard(tdispatcher *)
Captures the keyboard.
void key_down(const SDL_Event &event)
Fires a key down event.
tdispatcher * keyboard_dispatcher()
Gets the dispatcher that wants to receive the keyboard input.
static thandler * handler
See LEFT_BUTTON_DOUBLE_CLICK.
void connect(tdispatcher *dispatcher)
Connects a dispatcher.
void disconnect(tdispatcher *dispatcher)
Disconnects a dispatcher.
A SDL middle mouse button up event.
A mouse leave event for a widget.
A left mouse button double click event for a widget.
A request to close the current window.
The dialog is closed automatically since it's timeout has been triggered.
A mouse enter event for a widget.
void mouse_button_down(const tpoint &position, const Uint8 button)
Fires a mouse button down event.
void mouse_button_up(const tpoint &position, const Uint8 button)
Fires a mouse button up event.
Widget gets keyboard focus.
#define SDL_BUTTON_WHEELDOWN
std::ostream & operator<<(std::ostream &stream, const tevent event)
bool is_in_dialog()
Is a dialog open?
void video_resize(const tpoint &new_size)
Fires a video resize event.
GLint GLint GLint GLint GLint GLint y
void mouse(const tevent event, const tpoint &position)
Fires a generic mouse event.
Base class for event handling.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
A left mouse button down event for a widget.
static twindow * window_instance(const unsigned handle)
Returns the instance of a window.
Request the widget to show its hover helptip.
#define SDL_BUTTON_WHEELLEFT
A left mouse button click event for a widget.
base class of top level items, the only item which needs to store the final canvases to draw on ...
A SDL mouse motion event.
void init_mouse_location()
Initializes the location of the mouse.
#define SDL_BUTTON_WHEELUP
A class inherited from ttext_box that displays its input as stars.
#define CLOSE_WINDOW_EVENT
void keyboard(const tevent event)
Fires a keyboard event which has no parameters.
See LEFT_BUTTON_DOUBLE_CLICK.
tdispatcher * mouse_focus
The dispatcher that captured the mouse focus.
A SDL resize request, coordinate is the new window size.
static events::event_context * event_context
bool fire(const tevent event, twidget &target)
Fires an event which has no extra parameters.
bool execute_hotkey(const hotkey::HOTKEY_COMMAND id)
Executes a hotkey.
A SDL middle mouse button down event.
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...
void button_down(const SDL_Event &event)
Handles a joystick button down event.
Request for somebody to show the helptip based on the data send.
void text_input(const std::string &unicode)
Fires a text input event.
void set_retval(const int retval, const bool close_window=true)
Sets there return value of the window.
void release_mouse(tdispatcher *dispatcher)
Releases a captured mouse.
tpoint get_mouse_position()
Returns the current mouse position.
Send by a widget to notify others its contents or state are modified.
A SDL left mouse button up event.
A mouse motion event for a widget.
Request for somebody to place the widget.
tevent
The event send to the dispatcher.
void hat_motion(const SDL_Event &event)
Handles a hat motion event.
tdispatcher * keyboard_focus_
Needed to determine which dispatcher gets the keyboard events.
Request the widget to show its hover tooltip.
#define DOUBLE_CLICK_EVENT
A left mouse button up event for a widget.
std::map< std::string, tfilter >::iterator itor
#define SHOW_HELPTIP_EVENT
void connect_dispatcher(tdispatcher *dispatcher)
Connects a dispatcher to the event handler.
A SDL left mouse button down event.
Contains the gui2 timer routines.
GLint GLint GLint GLint GLint x
A SDL right mouse button down event.
#define HOVER_REMOVE_POPUP_EVENT
Send by a widget to notify others it's being destroyed.
void capture_mouse(tdispatcher *dispatcher)
Captures the mouse.
Handling of system events.
Request the widget to show its hover tooltip.
std::vector< tdispatcher * > dispatchers_
The dispatchers.
bool execute_timer(const size_t id)
Executes a timer.
bool find(E event, F functor)
Tests whether an event handler is available.
A SDL right mouse button up event.
void disconnect_dispatcher(tdispatcher *dispatcher)
Disconnects a dispatcher to the event handler.
The main application window is activated.
void mouse_wheel(const tpoint &position, int scrollx, int scrolly)
Fires a mouse wheel event.
void activate()
Reinitializes the state of all dispatchers.
This singleton class handles all events.
bool get_want_keyboard_input() const
bool hotkey_pressed(const hotkey::hotkey_ptr key)
Handles the pressing of a hotkey.
void handle_event(const SDL_Event &event)
Inherited from events::sdl_handler.
GLsizei const GLcharARB ** string
void handle_window_event(const SDL_Event &event)
Inherited from events::sdl_handler.
HOTKEY_COMMAND get_id(const std::string &command)
returns get_hotkey_command(command).id
void capture_keyboard(tdispatcher *dispatcher)
Captures the keyboard.
#define SDL_BUTTON_WHEELRIGHT