16 #define GETTEXT_DOMAIN "wesnoth-lib"
65 #define LOG_HEADER "distributor mouse motion [" << owner_.id() << "]: "
68 : mouse_focus_(nullptr)
69 , mouse_captured_(false)
72 , hover_widget_(nullptr)
73 , hover_position_(0, 0)
75 , signal_handler_sdl_mouse_motion_entered_(false)
80 std::placeholders::_2,
81 std::placeholders::_3,
82 std::placeholders::_5),
88 std::placeholders::_2,
89 std::placeholders::_3,
90 std::placeholders::_5,
91 std::placeholders::_6),
97 std::placeholders::_2,
98 std::placeholders::_3,
105 std::placeholders::_2,
106 std::placeholders::_3,
107 std::placeholders::_5
113 std::placeholders::_2,
114 std::placeholders::_3,
115 std::placeholders::_5
121 std::placeholders::_2,
122 std::placeholders::_3,
123 std::placeholders::_5
129 std::placeholders::_2,
130 std::placeholders::_3,
131 std::placeholders::_5),
163 mouse_over = mouse_over->
parent();
329 <<
"' at address " <<
widget <<
".";
362 #define LOG_HEADER "distributor mouse button " << I << " [" << owner_.id() << "]: "
376 constexpr std::array mouse_data{
405 template<std::
size_t I>
408 , last_click_stamp_(0)
409 , last_clicked_widget_(nullptr)
412 , signal_handler_sdl_button_down_entered_(false)
413 , signal_handler_sdl_button_up_entered_(false)
415 static_assert(I < mouse_data.size(),
"Out-of-bounds mouse_button template index");
420 std::placeholders::_2,
421 std::placeholders::_3,
422 std::placeholders::_5),
428 std::placeholders::_2,
429 std::placeholders::_3,
430 std::placeholders::_5),
434 template<std::
size_t I>
437 last_click_stamp_ = 0;
438 last_clicked_widget_ =
nullptr;
441 is_down_ = button_state & SDL_BUTTON(I + 1);
444 template<std::
size_t I>
448 if(signal_handler_sdl_button_down_entered_) {
456 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
457 WRN_GUI_E <<
LOG_HEADER <<
event <<
". The mouse button is already down, we missed an event.";
463 if(mouse_captured_) {
464 assert(mouse_focus_);
465 focus_ = mouse_focus_;
467 if(!owner_.fire(mouse_data[I].sdl_button_down_event, *focus_,
coordinate)) {
477 if(mouse_over != mouse_focus_) {
478 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
480 <<
"and mouse not captured, we missed events.";
482 mouse_focus_ = mouse_over;
487 if(!owner_.fire(mouse_data[I].sdl_button_down_event, *focus_,
coordinate)) {
495 template<std::
size_t I>
499 if(signal_handler_sdl_button_up_entered_) {
507 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
508 WRN_GUI_E <<
LOG_HEADER <<
event <<
". The mouse button is already up, we missed an event.";
516 if(!owner_.fire(mouse_data[I].sdl_button_up_event, *focus_,
coordinate)) {
527 if(mouse_captured_) {
528 const unsigned mask = SDL_BUTTON_LMASK | SDL_BUTTON_MMASK | SDL_BUTTON_RMASK;
531 mouse_captured_ =
false;
534 if(mouse_focus_ == mouse_over) {
535 mouse_button_click(mouse_focus_);
536 }
else if(!mouse_captured_) {
540 mouse_enter(mouse_over);
543 }
else if(focus_ && focus_ == mouse_over) {
544 mouse_button_click(focus_);
551 template<std::
size_t I>
554 uint32_t stamp = SDL_GetTicks();
559 last_click_stamp_ = 0;
560 last_clicked_widget_ =
nullptr;
565 last_click_stamp_ = stamp;
566 last_clicked_widget_ =
widget;
573 #define LOG_HEADER "distributor mouse motion [" << owner_.id() << "]: "
584 , keyboard_focus_(nullptr)
585 , keyboard_focus_chain_()
587 if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
588 if(SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
596 std::placeholders::_5,
597 std::placeholders::_6,
598 std::placeholders::_7
604 std::placeholders::_5,
605 std::placeholders::_6,
606 std::placeholders::_7
612 std::placeholders::_5,
613 std::placeholders::_6,
614 std::placeholders::_7
620 std::placeholders::_1,
621 std::placeholders::_2
632 std::placeholders::_5,
633 std::placeholders::_6,
634 std::placeholders::_7
640 std::placeholders::_5,
641 std::placeholders::_6,
642 std::placeholders::_7
648 std::placeholders::_5,
649 std::placeholders::_6,
650 std::placeholders::_7
656 std::placeholders::_1,
657 std::placeholders::_2
709 template<
typename Fcn,
typename P1,
typename P2,
typename P3>
729 if(tb->is_composing()) {
758 if(control !=
nullptr && !control->
get_active()) {
771 signal_handler_keyboard_internal<signal_keyboard>(
event::SDL_KEY_DOWN, key, modifier, unicode);
Base class for event handling.
void connect_signal(const F &func, const queue_position position=back_child)
Adds a callback to the appropriate queue based on event type.
queue_position
The position where to add a new callback in the signal handler.
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
void disconnect_signal(const F &func, const queue_position position=back_child)
Removes a callback from the appropriate queue based on event type.
widget * keyboard_focus_
The widget that holds the keyboard focus_.
void keyboard_add_to_chain(widget *widget)
Adds the widget to the keyboard chain.
void keyboard_capture(widget *widget)
Captures the keyboard input.
std::vector< widget * > keyboard_focus_chain_
Fall back keyboard focus_ items.
void signal_handler_keyboard_internal(event::ui_event evt, P1 &&p1, P2 &&p2, P3 &&p3)
void keyboard_remove_from_chain(widget *widget)
Remove the widget from the keyboard chain.
void signal_handler_sdl_text_editing(const std::string &unicode, int32_t start, int32_t len)
void signal_handler_sdl_key_down(const SDL_Keycode key, const SDL_Keymod modifier, const std::string &unicode)
Set of functions that handle certain events and sends them to the proper widget.
void initialize_state()
Initializes the state of the keyboard and mouse.
distributor(widget &owner, const dispatcher::queue_position queue_position)
widget * keyboard_focus() const
Return the widget currently capturing keyboard input.
void signal_handler_notify_removal(dispatcher &widget, const ui_event event)
void signal_handler_sdl_text_input(const std::string &unicode, int32_t start, int32_t len)
bool mouse_captured_
Did the current widget capture the focus_?
void mouse_hover(widget *mouse_over, const point &coordinate)
Called when the mouse moves over a widget.
widget * hover_widget_
The widget which should get the hover event.
void signal_handler_sdl_mouse_motion(const event::ui_event event, bool &handled, const point &coordinate)
mouse_motion(widget &owner, const dispatcher::queue_position queue_position)
void mouse_enter(widget *mouse_over)
Called when the mouse enters a widget.
bool hover_shown_
Has the hover been shown for the widget?
void signal_handler_sdl_touch_motion(const event::ui_event event, bool &handled, const point &coordinate, const point &distance)
void capture_mouse(const bool capture=true)
Captures the mouse input.
void signal_handler_show_helptip(const event::ui_event event, bool &handled, const point &coordinate)
void mouse_leave()
Called when the mouse leaves the current widget.
void signal_handler_sdl_wheel(const event::ui_event event, bool &handled, const point &coordinate)
point hover_position_
The anchor point of the hover event.
void stop_hover_timer()
Stops the current hover timer.
void start_hover_timer(widget *widget, const point &coordinate)
Starts the hover timer.
std::size_t hover_timer_
The timer for the hover event.
widget * mouse_focus_
The widget that currently has the mouse focus_.
widget & owner_
The widget that owns us.
void show_tooltip()
Called when the mouse wants the widget to show its tooltip.
bool signal_handler_sdl_mouse_motion_entered_
Small helper to keep a resource (boolean) locked.
resource_locker(bool &locked)
bool wants_mouse_hover() const
Abstract base class for text items.
const ui_event button_click_event
const ui_event button_double_click_event
const ui_event sdl_button_up_event
const ui_event button_up_event
const ui_event sdl_button_down_event
const ui_event button_down_event
Contains the event distributor.
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.
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
@ RIGHT_BUTTON_DOUBLE_CLICK
void init_mouse_location()
Initializes the location of the mouse.
unsigned double_click_time
std::size_t add_timer(const uint32_t interval, const std::function< void(std::size_t id)> &callback, const bool repeat)
Adds a new timer.
point get_mouse_position()
Returns the current mouse position.
bool remove_timer(const std::size_t id)
Removes a timer.
uint32_t get_mouse_button_mask()
Returns the current mouse button mask.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
This file contains the settings handling of the widget library.
Contains the gui2 timer routines.