Skip to content

Commit

Permalink
Merge pull request #2132 from matham/multi-sim
Browse files Browse the repository at this point in the history
Adds simulated touch as a profile option
  • Loading branch information
tito committed Jul 5, 2014
2 parents 8ef99f5 + 3586e15 commit f68fc92
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
57 changes: 45 additions & 12 deletions kivy/input/providers/mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,43 @@
[input]
mouse = mouse,disable_on_activity
Disabling multitouch interaction with the mouse
-----------------------------------------------
Using multitouch interaction with the mouse
-------------------------------------------
.. versionadded:: 1.3.0
By default, the middle and right mouse buttons are used for multitouch
emulation.
By default, the middle and right mouse buttons, as well as a combination of
ctrl + left mouse button are used for multitouch emulation.
If you want to use them for other purposes, you can disable this behavior by
activating the "disable_multitouch" token::
[input]
mouse = mouse,disable_multitouch
.. versionchanged:: 1.8.1
You can now selectively control whether a click initiated as described above
will emulate multi-touch. If the touch has been initiated in the above manner
(e.g. right mouse button), multitouch_sim will be added to touch's profile,
and property `multitouch_sim` to the touch. By default `multitouch_sim` is
False. If before mouse release (e.g. in on_touch_down/move) `multitouch_sim`
is set to True, the touch will simulate multi-touch. For example::
if 'multitouch_sim' in touch.profile:
touch.multitouch_sim = True
Following is a list of the supported profiles for :class:`MouseMotionEvent`.
=================== ==========================================================
Profile name Description
------------------- ----------------------------------------------------------
button Mouse button (left, right, middle, scrollup, scrolldown)
Use property `button`
pos 2D position. Use properties `x`, `y` or `pos``
multitouch_sim If multitouch is simulated. Use property `multitouch_sim`.
See documatation above.
=================== ==========================================================
'''

__all__ = ('MouseMotionEventProvider', )
Expand All @@ -45,11 +69,17 @@
class MouseMotionEvent(MotionEvent):

def depack(self, args):
self.profile = ['pos', 'button']
profile = self.profile
# don't overwrite previous profile
if not profile:
profile.extend(('pos', 'button'))
self.is_touch = True
self.sx, self.sy = args[:2]
if len(args) == 3:
if len(args) >= 3:
self.button = args[2]
if len(args) == 4:
self.multitouch_sim = args[3]
profile.append('multitouch_sim')
super(MouseMotionEvent, self).depack(args)

#
Expand Down Expand Up @@ -151,8 +181,11 @@ def find_touch(self, x, y):
def create_touch(self, rx, ry, is_double_tap, do_graphics, button):
self.counter += 1
id = 'mouse' + str(self.counter)
self.current_drag = cur = MouseMotionEvent(
self.device, id=id, args=[rx, ry, button])
args = [rx, ry, button]
if do_graphics:
args += [False]
self.current_drag = cur = MouseMotionEvent(self.device, id=id,
args=args)
cur.is_double_tap = is_double_tap
self.touches[id] = cur
if do_graphics:
Expand Down Expand Up @@ -210,10 +243,10 @@ def on_mouse_release(self, win, x, y, button, modifiers):
self.current_drag = None

cur = self.current_drag
if (cur and self.disable_multitouch) or (
button in ('left', 'scrollup', 'scrolldown', 'scrollleft',
'scrollright') and cur and not ('ctrl' in
modifiers)):
if (cur and (self.disable_multitouch or 'multitouch_sim' not in
cur.profile or not cur.multitouch_sim)) or\
(button in ('left', 'scrollup', 'scrolldown', 'scrollleft',
'scrollright') and cur and not ('ctrl' in modifiers)):
self.remove_touch(cur)
self.current_drag = None
if self.alt_touch:
Expand Down
5 changes: 5 additions & 0 deletions kivy/uix/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ def on_touch_down(self, touch):
touch.push()
touch.apply_transform_2d(self.to_local)
if super(Scatter, self).on_touch_down(touch):
# ensure children don't have to do it themselves
if 'multitouch_sim' in touch.profile:
touch.multitouch_sim = True
touch.pop()
self._bring_to_front(touch)
return True
Expand All @@ -518,6 +521,8 @@ def on_touch_down(self, touch):
if not self.collide_point(x, y):
return False

if 'multitouch_sim' in touch.profile:
touch.multitouch_sim = True
# grab the touch so we get all it later move events for sure
self._bring_to_front(touch)
touch.grab(self)
Expand Down

0 comments on commit f68fc92

Please sign in to comment.