16 #define GETTEXT_DOMAIN "wesnoth-lib"
67 #define LOG_HEADER "distributor mouse motion [" << owner_.id() << "]: "
70 : mouse_focus_(nullptr)
71 , mouse_captured_(false)
74 , hover_widget_(nullptr)
75 , hover_position_(0, 0)
77 , signal_handler_sdl_mouse_motion_entered_(false)
82 std::placeholders::_2,
83 std::placeholders::_3,
84 std::placeholders::_5),
90 std::placeholders::_2,
91 std::placeholders::_3,
92 std::placeholders::_5,
93 std::placeholders::_6),
99 std::placeholders::_2,
100 std::placeholders::_3,
101 std::placeholders::_5
107 std::placeholders::_2,
108 std::placeholders::_3,
109 std::placeholders::_5
115 std::placeholders::_2,
116 std::placeholders::_3,
117 std::placeholders::_5
123 std::placeholders::_2,
124 std::placeholders::_3,
125 std::placeholders::_5
131 std::placeholders::_2,
132 std::placeholders::_3,
133 std::placeholders::_5),
165 mouse_over = mouse_over->
parent();
331 <<
"' at address " <<
widget <<
".";
333 using namespace std::chrono_literals;
365 #define LOG_HEADER "distributor mouse button " << I << " [" << owner_.id() << "]: "
379 constexpr std::array mouse_data{
408 template<std::
size_t I>
411 , last_click_stamp_()
412 , last_clicked_widget_(nullptr)
415 , signal_handler_sdl_button_down_entered_(false)
416 , signal_handler_sdl_button_up_entered_(false)
418 static_assert(I < mouse_data.size(),
"Out-of-bounds mouse_button template index");
423 std::placeholders::_2,
424 std::placeholders::_3,
425 std::placeholders::_5),
431 std::placeholders::_2,
432 std::placeholders::_3,
433 std::placeholders::_5),
437 template<std::
size_t I>
440 last_click_stamp_ = {};
441 last_clicked_widget_ =
nullptr;
444 is_down_ = button_state & SDL_BUTTON(I + 1);
447 template<std::
size_t I>
451 if(signal_handler_sdl_button_down_entered_) {
459 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
460 WRN_GUI_E <<
LOG_HEADER <<
event <<
". The mouse button is already down, we missed an event.";
466 if(mouse_captured_) {
467 assert(mouse_focus_);
468 focus_ = mouse_focus_;
470 if(!owner_.fire(mouse_data[I].sdl_button_down_event, *focus_,
coordinate)) {
480 if(mouse_over != mouse_focus_) {
481 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
483 <<
"and mouse not captured, we missed events.";
485 mouse_focus_ = mouse_over;
490 if(!owner_.fire(mouse_data[I].sdl_button_down_event, *focus_,
coordinate)) {
498 template<std::
size_t I>
502 if(signal_handler_sdl_button_up_entered_) {
510 #ifdef GUI2_SHOW_UNHANDLED_EVENT_WARNINGS
511 WRN_GUI_E <<
LOG_HEADER <<
event <<
". The mouse button is already up, we missed an event.";
519 if(!owner_.fire(mouse_data[I].sdl_button_up_event, *focus_,
coordinate)) {
530 if(mouse_captured_) {
531 const unsigned mask = SDL_BUTTON_LMASK | SDL_BUTTON_MMASK | SDL_BUTTON_RMASK;
534 mouse_captured_ =
false;
537 if(mouse_focus_ == mouse_over) {
538 mouse_button_click(mouse_focus_);
539 }
else if(!mouse_captured_) {
543 mouse_enter(mouse_over);
546 }
else if(focus_ && focus_ == mouse_over) {
547 mouse_button_click(focus_);
554 template<std::
size_t I>
557 auto stamp = std::chrono::steady_clock::now();
562 last_click_stamp_ = {};
563 last_clicked_widget_ =
nullptr;
568 last_click_stamp_ = stamp;
569 last_clicked_widget_ =
widget;
576 #define LOG_HEADER "distributor mouse motion [" << owner_.id() << "]: "
587 , keyboard_focus_(nullptr)
588 , keyboard_focus_chain_()
590 if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
591 if(SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
599 std::placeholders::_5,
600 std::placeholders::_6,
601 std::placeholders::_7
607 std::placeholders::_5,
608 std::placeholders::_6,
609 std::placeholders::_7
615 std::placeholders::_5,
616 std::placeholders::_6,
617 std::placeholders::_7
623 std::placeholders::_1,
624 std::placeholders::_2
635 std::placeholders::_5,
636 std::placeholders::_6,
637 std::placeholders::_7
643 std::placeholders::_5,
644 std::placeholders::_6,
645 std::placeholders::_7
651 std::placeholders::_5,
652 std::placeholders::_6,
653 std::placeholders::_7
659 std::placeholders::_1,
660 std::placeholders::_2
712 template<
typename Fcn,
typename P1,
typename P2,
typename P3>
732 if(tb->is_composing()) {
761 if(control !=
nullptr && !control->
get_active()) {
774 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.