@@ -19,6 +19,8 @@ class MPong(Activity):
1919 paddle_move_step = None
2020 layer = None
2121 buffer = None
22+ touch_active = False
23+ touch_last_x = None
2224
2325 # Widgets:
2426 screen = None
@@ -76,12 +78,28 @@ def run_mpong(self, timer=None):
7678 self .canvas .invalidate () # force redraw
7779
7880 def touch_cb (self , event ):
79- # TODO: track lv.EVENT.PRESSED, lv.EVENT.PRESSING and lv.EVENT.RELEASED events to detect swipes left and right to move_paddle
80- event_code = event .get_code ()
81- import mpos .ui
82- mpos .ui .print_event (event )
83- if event_code not in [19 ,23 ,25 ,26 ,27 ,28 ,29 ,30 ,49 ]:
84- if event_code == lv .EVENT .PRESSING : # this is probably enough
81+ event_code = event .get_code ()
82+ if event_code == lv .EVENT .PRESSED :
83+ x , y = InputManager .pointer_xy ()
84+ self .touch_active = True
85+ self .touch_last_x = x
86+ return
87+
88+ if event_code == lv .EVENT .PRESSING :
89+ if not self .touch_active :
8590 x , y = InputManager .pointer_xy ()
86- mpong .move_paddle (- 10 ) # TODO: set actual detected swipe left or right
91+ self .touch_active = True
92+ self .touch_last_x = x
8793 return
94+ x , y = InputManager .pointer_xy ()
95+ if self .touch_last_x is not None :
96+ delta = x - self .touch_last_x
97+ if delta :
98+ mpong .move_paddle (delta )
99+ self .touch_last_x = x
100+ return
101+
102+ if event_code == lv .EVENT .RELEASED :
103+ self .touch_active = False
104+ self .touch_last_x = None
105+ return
0 commit comments