import pygame
+from naja.events import InvalidateTheWorld
class Widget(object):
return pygame.Rect(self.pos, self.size)
def render(self, surface):
+ '''Draw the widget onto surface'''
if not self._prepared:
self.prepare()
self._prepared = True
self.draw(surface)
def draw(self, surface):
+ '''The overrideable bit of widget drawing'''
raise NotImplemented()
def prepare(self):
- raise NotImplemented()
+ '''Prepare the widget for drawing. This usually caches a surface.'''
def handle_event(self, ev):
+ '''Return True if the event has been handled'''
+ if InvalidateTheWorld.matches(ev):
+ # Invalidate has special handling. Widgets should never return
+ # True for for this event
+ self._prepared = False
+ return False
return False