Tweak drawing code. Ensure we try children for touch events before the scroll view...
authorNeil <neil@dip.sun.ac.za>
Thu, 18 Jul 2013 15:29:40 +0000 (17:29 +0200)
committerNeil <neil@dip.sun.ac.za>
Thu, 18 Jul 2013 15:29:40 +0000 (17:29 +0200)
erdslangetjie/localwidgets.py

index fe719be7d2fcf0ef1de3f5bca0889f0d670ca207..06f6a0a866de68d748483c3305e50eea2e2281c3 100644 (file)
@@ -63,18 +63,15 @@ class GameWindow(RelativeLayout):
         self._background = Widget(size=self.size, pos=(0, 0))
         tiles = self.level_obj.get_tiles()
         bx, by = 0, 0
-        for tile_line in tiles:
-            bx = 0
-            for tile in tile_line:
-                self.draw_tile((bx, by), tile)
-                bx += TILE_SIZE
-            by += TILE_SIZE
-        self.add_widget(self._background)
-
-    def draw_tile(self, pos, tile):
         with self._background.canvas:
-            Rectangle(pos=pos, size=(TILE_SIZE, TILE_SIZE),
-                    texture=tile.texture)
+            for tile_line in tiles:
+                bx = 0
+                for tile in tile_line:
+                    Rectangle(pos=(bx, by), size=(TILE_SIZE, TILE_SIZE),
+                            texture=tile.texture)
+                    bx += TILE_SIZE
+                by += TILE_SIZE
+        self.add_widget(self._background)
 
     def fix_scroll_margins(self):
         # We need to call this after app.root is set
@@ -282,7 +279,9 @@ class GameWindow(RelativeLayout):
             self.level_obj.trigger_button(self.nemesis.pos)
         for map_pos, new_tile in self.level_obj.get_changed_tiles():
             pos = (map_pos[0] * TILE_SIZE, map_pos[1] * TILE_SIZE)
-            self.draw_tile(pos, new_tile)
+            with self._background.canvas:
+                Rectangle(pos=pos, size=(TILE_SIZE, TILE_SIZE),
+                        texture=new_tile.texture)
         return False
 
     def _calc_mouse_pos(self, pos):
@@ -298,6 +297,7 @@ class GameWindow(RelativeLayout):
         if self._near_player(pos):
             self.mouse_move = True
             self.mouse_start = pos
+            return True
 
     def on_touch_up(self, touch):
         self.mouse_move = False
@@ -311,6 +311,7 @@ class GameWindow(RelativeLayout):
                         pos[1] - self.mouse_start[1])
                 self.do_move(direction)
                 self.mouse_start = pos
+                return True
 
 
 class Screen(Widget):
@@ -365,11 +366,15 @@ class MyScrollView(ScrollView):
 
     def on_touch_down(self, touch):
         for child in self.children:
-            child.on_touch_down(touch)
+            if child.on_touch_down(touch):
+                return True
+        return super(MyScrollView, self).on_touch_up(touch)
 
     def on_touch_up(self, touch):
         for child in self.children:
-            child.on_touch_up(touch)
+            if child.on_touch_up(touch):
+                return True
+        return super(MyScrollView, self).on_touch_up(touch)
 
 
 class GameApp(App):