15 #define GETTEXT_DOMAIN "wesnoth-lib"
57 static Uint32 popup_callback(Uint32 ,
void* )
59 DBG_GUI_E <<
"Pushing popup removal event in queue.\n";
72 SDL_PushEvent(&event);
110 #define LOG_HEADER "distributor mouse motion [" << owner_.id() << "]: "
114 : mouse_focus_(nullptr)
115 , mouse_captured_(false)
118 , hover_widget_(nullptr)
119 , hover_position_(0, 0)
121 , signal_handler_sdl_mouse_motion_entered_(false)
179 mouse_over = mouse_over->
parent();
182 DBG_GUI_E << LOG_HEADER <<
"Firing: " <<
event <<
".\n";
183 if(
owner_.
fire(event, *mouse_over, coordinate)) {
237 DBG_GUI_E << LOG_HEADER <<
"Firing: " <<
event <<
".\n";
238 if(
owner_.
fire(event, *mouse_over, coordinate)) {
266 owner_.
fire(event::MOUSE_MOTION, *mouse_over, coordinate);
285 <<
" bailing out, no hover widget.\n";
329 <<
"' at address " << widget <<
".\n";
365 "distributor mouse button " << name_ << " [" << owner_.id() << "]: "
367 template <
tevent sdl_button_down,
372 tevent button_double_click>
383 , last_click_stamp_(0)
384 , last_clicked_widget_(nullptr)
388 , signal_handler_sdl_button_down_entered_(false)
389 , signal_handler_sdl_button_up_entered_(false)
397 button_double_click>::
410 button_double_click>::
419 template <
tevent sdl_button_down,
424 tevent button_double_click>
430 button_double_click>::initialize_state(
const bool is_down)
432 last_click_stamp_ = 0;
433 last_clicked_widget_ =
nullptr;
438 template <
tevent sdl_button_down,
443 tevent button_double_click>
449 button_double_click>::
454 if(signal_handler_sdl_button_down_entered_) {
457 tlock lock(signal_handler_sdl_button_down_entered_);
463 <<
". The mouse button is already down, "
464 <<
"we missed an event.\n";
469 if(mouse_captured_) {
470 assert(mouse_focus_);
471 focus_ = mouse_focus_;
472 DBG_GUI_E << LOG_HEADER <<
"Firing: " << sdl_button_down <<
".\n";
473 if(!owner_.fire(sdl_button_down, *focus_, coordinate)) {
474 DBG_GUI_E << LOG_HEADER <<
"Firing: " << button_down <<
".\n";
475 owner_.fire(button_down, *mouse_focus_);
483 if(mouse_over != mouse_focus_) {
484 WRN_GUI_E << LOG_HEADER <<
". Mouse down on non focused widget "
485 <<
"and mouse not captured, we missed events.\n";
486 mouse_focus_ = mouse_over;
490 DBG_GUI_E << LOG_HEADER <<
"Firing: " << sdl_button_down <<
".\n";
491 if(!owner_.fire(sdl_button_down, *focus_, coordinate)) {
492 DBG_GUI_E << LOG_HEADER <<
"Firing: " << button_down <<
".\n";
493 owner_.fire(button_down, *focus_);
499 template <
tevent sdl_button_down,
504 tevent button_double_click>
510 button_double_click>::
515 if(signal_handler_sdl_button_up_entered_) {
518 tlock lock(signal_handler_sdl_button_up_entered_);
524 <<
". The mouse button is already up, we missed an event.\n";
530 DBG_GUI_E << LOG_HEADER <<
"Firing: " << sdl_button_up <<
".\n";
531 if(!owner_.fire(sdl_button_up, *focus_, coordinate)) {
532 DBG_GUI_E << LOG_HEADER <<
"Firing: " << button_up <<
".\n";
533 owner_.fire(button_up, *focus_);
538 if(mouse_captured_) {
539 const unsigned mask = SDL_BUTTON_LMASK | SDL_BUTTON_MMASK
542 if((SDL_GetMouseState(
nullptr,
nullptr) & mask) == 0) {
543 mouse_captured_ =
false;
546 if(mouse_focus_ == mouse_over) {
547 mouse_button_click(mouse_focus_);
548 }
else if(!mouse_captured_) {
552 mouse_enter(mouse_over);
555 }
else if(focus_ && focus_ == mouse_over) {
556 mouse_button_click(focus_);
563 template <
tevent sdl_button_down,
568 tevent button_double_click>
574 button_double_click>::mouse_button_click(
twidget* widget)
576 Uint32 stamp = SDL_GetTicks();
578 && last_clicked_widget_ == widget) {
582 owner_.fire(button_double_click, *widget);
583 last_click_stamp_ = 0;
584 last_clicked_widget_ =
nullptr;
589 owner_.fire(button_click, *widget);
590 last_click_stamp_ = stamp;
591 last_clicked_widget_ = widget;
598 #define LOG_HEADER "distributor mouse motion [" << owner_.id() << "]: "
611 , hover_pending_(false)
619 , keyboard_focus_chain_()
621 if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
622 if(SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
647 const Uint8 button_state = SDL_GetMouseState(
nullptr,
nullptr);
649 tmouse_button_left::initialize_state((button_state & SDL_BUTTON(1)) != 0);
650 tmouse_button_middle::initialize_state((button_state & SDL_BUTTON(2)) != 0);
651 tmouse_button_right::initialize_state((button_state & SDL_BUTTON(3)) != 0);
722 for(std::vector<twidget*>::reverse_iterator ritor
749 if(control !=
nullptr && !control->
get_active()) {
754 if(
owner_.
fire(event::SDL_KEY_DOWN, **ritor, key, modifier, unicode)) {
777 if(tmouse_button_left::last_clicked_widget_ == &widget) {
778 tmouse_button_left::last_clicked_widget_ =
nullptr;
780 if(tmouse_button_left::focus_ == &widget) {
781 tmouse_button_left::focus_ =
nullptr;
784 if(tmouse_button_middle::last_clicked_widget_ == &widget) {
785 tmouse_button_middle::last_clicked_widget_ =
nullptr;
787 if(tmouse_button_middle::focus_ == &widget) {
788 tmouse_button_middle::focus_ =
nullptr;
791 if(tmouse_button_right::last_clicked_widget_ == &widget) {
792 tmouse_button_right::last_clicked_widget_ =
nullptr;
794 if(tmouse_button_right::focus_ == &widget) {
795 tmouse_button_right::focus_ =
nullptr;
Define the common log macros for the gui toolkit.
Widget loses keyboard focus.
twidget & owner_
The widget that owns us.
void stop_hover_timer()
Stops the current hover timer.
void capture_mouse(const bool capture=true)
Captures the mouse input.
bool mouse_captured_
Did the current widget capture the focus_?
A mouse leave event for a widget.
unsigned double_click_time
void start_hover_timer(twidget *widget, const tpoint &coordinate)
Starts the hover timer.
A mouse enter event for a widget.
void show_tooltip()
Called when the mouse wants the widget to show its tooltip.
void signal_handler_sdl_wheel(const event::tevent event, bool &handled, const tpoint &coordinate)
Widget gets keyboard focus.
boost::enable_if< boost::mpl::has_key< tset_event, boost::mpl::int_< E > > >::type disconnect_signal(const tsignal_function &signal, const tposition position=back_child)
Disconnect a signal for callback in tset_event.
SDL_AddTimer() callback for the hover event.
bool remove_timer(const size_t id)
Removes a timer.
Contains the event distributor.
Base class for event handling.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
boost::enable_if< boost::mpl::has_key< tset_event, boost::mpl::int_< E > > >::type connect_signal(const tsignal_function &signal, const tposition position=back_child)
Connect a signal for callback in tset_event.
Request the widget to show its hover helptip.
void keyboard_add_to_chain(twidget *widget)
Adds the widget to the keyboard chain.
void signal_handler_sdl_key_down(const SDLKey key, const SDLMod modifier, const utf8::string &unicode)
Set of functions that handle certain events and sends them to the proper widget.
std::vector< twidget * > keyboard_focus_chain_
Fall back keyboard focus_ items.
void signal_handler_show_helptip(const event::tevent event, bool &handled, const tpoint &coordinate)
A SDL mouse motion event.
void init_mouse_location()
Initializes the location of the mouse.
A class inherited from ttext_box that displays its input as stars.
void initialize_state()
Initializes the state of the keyboard and mouse.
twidget * mouse_focus_
The widget that currently has the mouse focus_.
bool fire(const tevent event, twidget &target)
Fires an event which has no extra parameters.
tpoint hover_position_
The anchor point of the hover event.
size_t hover_timer_
The timer for the hover event.
tposition
The position where to add a new callback in the signal handler.
tpoint get_mouse_position()
Returns the current mouse position.
A mouse motion event for a widget.
void signal_handler_sdl_mouse_motion(const event::tevent event, bool &handled, const tpoint &coordinate)
tevent
The event send to the dispatcher.
bool wants_mouse_hover() const
Request the widget to show its hover tooltip.
void keyboard_capture(twidget *widget)
Captures the keyboard input.
std::map< std::string, tfilter >::iterator itor
bool hover_shown_
Has the hover been shown for the widget?
void mouse_enter(twidget *mouse_over)
Called when the mouse enters a widget.
Contains the gui2 timer routines.
void keyboard_remove_from_chain(twidget *widget)
Remove the widget from the keyboard chain.
#define HOVER_REMOVE_POPUP_EVENT
void mouse_leave()
Called when the mouse leaves the current widget.
Send by a widget to notify others it's being destroyed.
Request the widget to show its hover tooltip.
Base class for all visible items.
twidget * hover_widget_
The widget which should get the hover event.
twidget * keyboard_focus_
The widget that holds the keyboard focus_.
bool find(E event, F functor)
Tests whether an event handler is available.
bool signal_handler_sdl_mouse_motion_entered_
tdistributor(twidget &owner, const tdispatcher::tposition queue_position)
virtual bool get_active() const =0
Gets the active state of the control.
void signal_handler_notify_removal(tdispatcher &widget, const tevent event)
size_t add_timer(const Uint32 interval, const std::function< void(size_t id)> &callback, const bool repeat)
Adds a new timer.
void mouse_motion(twidget *mouse_over, const tpoint &coordinate)
Called when the mouse moves over a widget.
GLsizei const GLcharARB ** string
tmouse_motion(twidget &owner, const tdispatcher::tposition queue_position)