Skip to content

Commit

Permalink
GUI2: further progress on touch event backend implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Feb 9, 2017
1 parent 261bf4f commit 51202f8
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/gui/core/event/dispatcher.cpp
Expand Up @@ -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<set_event_touch>(
event,
dispatcher_implementation::has_handler(event_type,
*this))
|| find<set_event_notification>(
event,
dispatcher_implementation::has_handler(event_type,
Expand Down Expand Up @@ -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<set_event_touch>(event, event_in_set()));
return fire_event<signal_touch_function>(
event,
dynamic_cast<widget*>(this),
&target,
trigger_touch(pos, distance));
}

/** Helper struct to wrap the functor call. */
class trigger_notification
{
Expand Down
13 changes: 13 additions & 0 deletions src/gui/core/event/dispatcher.hpp
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/gui/core/event/dispatcher_private.hpp
Expand Up @@ -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)

Expand Down
17 changes: 16 additions & 1 deletion src/gui/core/event/handler.cpp
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<widget&>(*dispatcher), position, distance);
}
}

void sdl_event_handler::hat_motion(const SDL_Event& event)
{
const hotkey::hotkey_ptr& hk = hotkey::get_hotkey(event);
Expand Down

0 comments on commit 51202f8

Please sign in to comment.