Unified event touch

HandlingInputInput providers

Introduction

In previous version (before 0.3), touch event management is not extensible. We currently support on_touch_down/up/move which only supports 2D touch events and on_object which supports objects and rotation, how can we add these type of events :

  • 2D, 3D object
  • Wiimote
  • Pen
  • SMK screen

And how can we provide a new way to generate touch events ? This is the mean of refactoring, having the possibility to create new provider, and having only one interface for all kinds of event.

Current architecture :

New events signature

Old signatureNew signature
on_touch_down(self, touches, touchID, x, y)on_touch_down(self, touch)
on_touch_move(self, touches, touchID, x, y)on_touch_move(self, touch)
on_touch_up(self, touches, touchID, x, y)on_touch_up(self, touch)
on_press(self, touchID, x, y)on_press(self, touch)
on_release(self, touchID, x, y)on_release(self, touch)
on_gesture(self, touchID, x, y)on_gesture(self, touch)

Touch coordinate transformation

Touch coordinate are always in 0-1 coordinate space. So a provider **must** provide x/y/... values between 0 and 1.

When the touch is dispatched, MTWindow will scale x/y/... in the coordinate space of Window.

Touch coordinates changes

When we want to change x/y from a touch, we must push/pop attributes before changing it.

touch.push(args='xyz')
touch.x, touch.y = self.to_local(touch.x, touch.y)
# use it
touch.pop()

Post processing modules

Postproc modules are executed right after fetching event from input providers.

Postproc are designed to hold event if needed, and generated own event. You can plug gesture interface here for eg.

Details

New classes:

  • Touch - abtract touch with capabilities functions
    • can(capability) - test a capability
    • capabilities() - get all capabilities
    • grab(wid, exclusive=False) - add wid in grab list. it will always receive event notification
    • ungrab(wid) - remove wid from grab list
  • TouchFactory - handle provider
    • register() - register a new provider
    • list() - get list of providers
  • TouchProvider - abstract class to implement provider
    • start() - start provider to get touch
    • update() - update provider to read his entry, generate event if needed
    • stop() - stop provider
  • TuioTouchProvider - implementation of TouchProvider with TUIO
    • Tuio2dObjTouch - handle 2d obj path with tuio provider
    • Tuio2dCurTouch - handle 2d cur path with tuio provider
  • WiimoteTouchProvider - implementation of TouchProvider with Wiimote
    • WiimoteTouch - handle wiimote touch
  • PenTouchProvider - implementation of TouchProvider with Pen
    • PenTouch - handle pen touch