changeset 43:792c8429681a

Limit distribution of mouse events
author Stefano Rivera <stefano@rivera.za.net>
date Sun, 11 Sep 2011 15:20:19 +0200
parents 8521c142cd43
children c54a25772e99
files mamba/habitats/mainmenu.py mamba/widgets/base.py
diffstat 2 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/habitats/mainmenu.py	Sun Sep 11 15:16:37 2011 +0200
+++ b/mamba/habitats/mainmenu.py	Sun Sep 11 15:20:19 2011 +0200
@@ -5,7 +5,6 @@
 
 
 class MainMenu(Habitat):
-
     def __init__(self):
         super(MainMenu, self).__init__()
         self.container.add(TextWidget((100, 100), "Hello", color='white'))
--- a/mamba/widgets/base.py	Sun Sep 11 15:16:37 2011 +0200
+++ b/mamba/widgets/base.py	Sun Sep 11 15:20:19 2011 +0200
@@ -1,4 +1,5 @@
 import pygame
+from pygame.locals import MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN
 
 
 class Widget(object):
@@ -24,7 +25,9 @@
 
     def event(self, event):
         for child in self.children:
-            # TODO mouse events
+            if event.type in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN):
+                if not child.rect.collidepoint(event.pos):
+                    continue
             child.event(event)
 
     def add(self, widget):