GUI2: further progress on touch event backend implementation
This commit is contained in:
parent
261bf4fcab
commit
51202f86f4
4 changed files with 71 additions and 1 deletions
|
@ -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,
|
||||
|
@ -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
|
||||
{
|
||||
|
|
|
@ -202,6 +202,19 @@ public:
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -218,6 +218,14 @@ private:
|
|||
*/
|
||||
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<widget&>(*dispatcher), position, distance);
|
||||
}
|
||||
}
|
||||
|
||||
void sdl_event_handler::hat_motion(const SDL_Event& event)
|
||||
{
|
||||
const hotkey::hotkey_ptr& hk = hotkey::get_hotkey(event);
|
||||
|
|
Loading…
Add table
Reference in a new issue