From 51202f86f4de6d101fadcbabc168432242505e38 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Fri, 10 Feb 2017 10:04:41 +1100 Subject: [PATCH] GUI2: further progress on touch event backend implementation --- src/gui/core/event/dispatcher.cpp | 41 +++++++++++++++++++++++ src/gui/core/event/dispatcher.hpp | 13 +++++++ src/gui/core/event/dispatcher_private.hpp | 1 + src/gui/core/event/handler.cpp | 17 +++++++++- 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/gui/core/event/dispatcher.cpp b/src/gui/core/event/dispatcher.cpp index 518b8339bc2a..4bb770d402c2 100644 --- a/src/gui/core/event/dispatcher.cpp +++ b/src/gui/core/event/dispatcher.cpp @@ -86,6 +86,10 @@ bool dispatcher::has_event(const ui_event event, const event_queue_type event_ty event, dispatcher_implementation::has_handler(event_type, *this)) + || find( + event, + dispatcher_implementation::has_handler(event_type, + *this)) || find( event, dispatcher_implementation::has_handler(event_type, @@ -246,6 +250,43 @@ bool dispatcher::fire(const ui_event event, trigger_keyboard(key, modifier, unicode)); } +/** Helper struct to wrap the functor call. */ +class trigger_touch +{ +public: + trigger_touch(const point& pos, const point& distance) + : pos_(pos) + , distance_(distance) + { + } + + void operator()(signal_touch_function functor, + dispatcher& dispatcher, + const ui_event event, + bool& handled, + bool& halt) + { + functor(dispatcher, event, handled, halt, pos_, distance_); + } + +private: + point pos_; + point distance_; +}; + +bool dispatcher::fire(const ui_event event, + widget& target, + const point& pos, + const point& distance) +{ + assert(find(event, event_in_set())); + return fire_event( + event, + dynamic_cast(this), + &target, + trigger_touch(pos, distance)); +} + /** Helper struct to wrap the functor call. */ class trigger_notification { diff --git a/src/gui/core/event/dispatcher.hpp b/src/gui/core/event/dispatcher.hpp index 2044d3cb8ac8..444a5fea3396 100644 --- a/src/gui/core/event/dispatcher.hpp +++ b/src/gui/core/event/dispatcher.hpp @@ -202,6 +202,19 @@ class dispatcher const SDL_Keymod modifier, const utf8::string& unicode); + /** + * Fires an event which takes touch parameters. + * + * @param event The event to fire. + * @param target The widget that should receive the event. + * @param pos The location touched. + * @param distance The distance moved. + */ + bool fire(const ui_event event, + widget& target, + const point& pos, + const point& distance); + /** * Fires an event which takes notification parameters. * diff --git a/src/gui/core/event/dispatcher_private.hpp b/src/gui/core/event/dispatcher_private.hpp index f5ebfac04383..3909c8f69d81 100644 --- a/src/gui/core/event/dispatcher_private.hpp +++ b/src/gui/core/event/dispatcher_private.hpp @@ -107,6 +107,7 @@ struct dispatcher_implementation IMPLEMENT_EVENT_SIGNAL_WRAPPER(mouse) IMPLEMENT_EVENT_SIGNAL_WRAPPER(keyboard) + IMPLEMENT_EVENT_SIGNAL_WRAPPER(touch) IMPLEMENT_EVENT_SIGNAL_WRAPPER(notification) IMPLEMENT_EVENT_SIGNAL_WRAPPER(message) diff --git a/src/gui/core/event/handler.cpp b/src/gui/core/event/handler.cpp index 02cc501682e1..1eb01e991916 100644 --- a/src/gui/core/event/handler.cpp +++ b/src/gui/core/event/handler.cpp @@ -218,6 +218,14 @@ class sdl_event_handler : public events::sdl_handler */ dispatcher* keyboard_dispatcher(); + /** + * Fires a generic touch event. + * + * @param position The position touched. + * @param distance The distance moved. + */ + void touch_motion(const point& position, const point& distance); + /** * Handles a hat motion event. * @@ -414,7 +422,7 @@ void sdl_event_handler::handle_event(const SDL_Event& event) break; case SDL_FINGERMOTION: - // TODO? + touch_motion(point(event.tfinger.x, event.tfinger.y), point(event.tfinger.dx, event.tfinger.dy)); break; #if(defined(_X11) && !defined(__APPLE__)) || defined(_WIN32) @@ -652,6 +660,13 @@ dispatcher* sdl_event_handler::keyboard_dispatcher() return nullptr; } +void sdl_event_handler::touch_motion(const point& position, const point& distance) +{ + for(auto& dispatcher : boost::adaptors::reverse(dispatchers_)) { + dispatcher->fire(SDL_TOUCH_MOTION , dynamic_cast(*dispatcher), position, distance); + } +} + void sdl_event_handler::hat_motion(const SDL_Event& event) { const hotkey::hotkey_ptr& hk = hotkey::get_hotkey(event);