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 <<
".";
331 using namespace std::chrono_literals;
363 #define LOG_HEADER "distributor mouse button " << I << " [" << owner_.id() << "]: "
377 constexpr std::array mouse_data{
406 template<std::
size_t I>
409 , last_click_stamp_()
410 , last_clicked_widget_(nullptr)
413 , signal_handler_sdl_button_down_entered_(false)
414 , signal_handler_sdl_button_up_entered_(false)
416 static_assert(I < mouse_data.size(),
"Out-of-bounds mouse_button template index");
421 std::placeholders::_2,
422 std::placeholders::_3,
423 std::placeholders::_5),
429 std::placeholders::_2,
430 std::placeholders::_3,
431 std::placeholders::_5),
435 template<std::
size_t I>
438 last_click_stamp_ = {};
439 last_clicked_widget_ =
nullptr;
442 is_down_ = button_state & SDL_BUTTON(I + 1);
445 template<std::
size_t I>
449 if(signal_handler_sdl_button_down_entered_) {
457 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
458 WRN_GUI_E <<
LOG_HEADER <<
event <<
". The mouse button is already down, we missed an event.";
464 if(mouse_captured_) {
465 assert(mouse_focus_);
466 focus_ = mouse_focus_;
468 if(!owner_.fire(mouse_data[I].sdl_button_down_event, *focus_,
coordinate)) {
478 if(mouse_over != mouse_focus_) {
479 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
481 <<
"and mouse not captured, we missed events.";
483 mouse_focus_ = mouse_over;
488 if(!owner_.fire(mouse_data[I].sdl_button_down_event, *focus_,
coordinate)) {
496 template<std::
size_t I>
500 if(signal_handler_sdl_button_up_entered_) {
508 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
509 WRN_GUI_E <<
LOG_HEADER <<
event <<
". The mouse button is already up, we missed an event.";
517 if(!owner_.fire(mouse_data[I].sdl_button_up_event, *focus_,
coordinate)) {
528 if(mouse_captured_) {
529 const unsigned mask = SDL_BUTTON_LMASK | SDL_BUTTON_MMASK | SDL_BUTTON_RMASK;
532 mouse_captured_ =
false;
535 if(mouse_focus_ == mouse_over) {
536 mouse_button_click(mouse_focus_);
537 }
else if(!mouse_captured_) {
541 mouse_enter(mouse_over);
544 }
else if(focus_ && focus_ == mouse_over) {
545 mouse_button_click(focus_);
552 template<std::
size_t I>
555 auto stamp = std::chrono::steady_clock::now();
560 last_click_stamp_ = {};
561 last_clicked_widget_ =
nullptr;
566 last_click_stamp_ = stamp;
567 last_clicked_widget_ =
widget;
574 #define LOG_HEADER "distributor mouse motion [" << owner_.id() << "]: "
585 , keyboard_focus_(nullptr)
586 , keyboard_focus_chain_()
588 if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
589 if(SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
597 std::placeholders::_5,
598 std::placeholders::_6,
599 std::placeholders::_7
605 std::placeholders::_5,
606 std::placeholders::_6,
607 std::placeholders::_7
613 std::placeholders::_5,
614 std::placeholders::_6,
615 std::placeholders::_7
621 std::placeholders::_1,
622 std::placeholders::_2
633 std::placeholders::_5,
634 std::placeholders::_6,
635 std::placeholders::_7
641 std::placeholders::_5,
642 std::placeholders::_6,
643 std::placeholders::_7
649 std::placeholders::_5,
650 std::placeholders::_6,
651 std::placeholders::_7
657 std::placeholders::_1,
658 std::placeholders::_2
710 template<
typename Fcn,
typename P1,
typename P2,
typename P3>
730 if(tb->is_composing()) {
759 if(control !=
nullptr && !control->
get_active()) {
772 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.
std::chrono::milliseconds double_click_time
std::size_t add_timer(const std::chrono::milliseconds &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.
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
This file contains the settings handling of the widget library.
Contains the gui2 timer routines.