[ocemp-devel] Update process and dirty flag
Status: Beta
Brought to you by:
marcusva
From: Bertrand C. <ber...@gm...> - 2006-06-28 16:39:11
|
Hi all, There is something I don't understand in the update process. When a widget need to be modified (its rendering), it is marked as dirty. This way, its parent is also marked as dirty. That mean that the container will redraw everything: its background and all its children. Instead of this process, when a widget is marked as dirty, its parent don't need to be marked as dirty and we can override the update method into the Container module and do the things like that: def update (self, *args): DirtyChild = False ChildrenRects = [] for child in self._children: if child.dirty == True: child.update() self._image.blit(child.image,child.image.get_rect()) ChildrenRects.append(child.image.get_rect()) DirtyChild = True if DirtyChild: self._oldrect = self._rect rect = ChildrenRects[0] for r in ChildrenRects: if r.left < rect.left: rect.left = r.left if r.top < rect.top: rect.top = r.top if r.right > rect.right: rect.right = r.right if r.bottom > rect.bottom: rect.bottom = r.bottom self._rect = rect BaseWidget.update(self) This way, only modified widget included into the container are modified, which is faster. What do you thing of this solution, and what do I have missed ? Sincerely Bertrand |