Changeset 223
- Timestamp:
- 12/25/06 16:51:01 (5 years ago)
- Files:
-
- 1 modified
-
trunk/src/pyspacewar/ui.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/pyspacewar/ui.py
r222 r223 792 792 height = max(0, (item_height + yspacing) * len(items) - yspacing) 793 793 HUDElement.__init__(self, width, height, xalign, yalign) 794 self.full_height = height 794 795 self.font = font 795 796 self.items = items … … 798 799 self.ypadding = ypadding 799 800 self.selected_item = 0 801 self.top = 0 800 802 self.item_height = item_height 801 self.surface = pygame.Surface((self.width, self. height))803 self.surface = pygame.Surface((self.width, self.full_height)) 802 804 self.surface.set_alpha(255 * 0.9) 803 805 self.surface.set_colorkey((1, 1, 1)) 804 806 self.invalidate() 807 808 def position(self, surface, margin=10): 809 """Calculate screen position for the widget.""" 810 max_height = surface.get_height() - 2 * margin 811 item_spacing = self.item_height + self.yspacing 812 self.height = self.full_height 813 while self.height > max_height: 814 self.height -= item_spacing 815 if self.selected_item * item_spacing < self.top: 816 self.top = self.selected_item * item_spacing 817 while (self.selected_item * item_spacing + self.item_height > 818 self.top + self.height): 819 self.top += item_spacing 820 return HUDElement.position(self, surface, margin) 805 821 806 822 def invalidate(self): … … 821 837 """Find the item at given coordinates.""" 822 838 ix, iy = self.position(surface) 839 iy -= self.top 823 840 for idx, item in enumerate(self.items): 824 841 if (ix <= x < ix + self.width and … … 856 873 self._draw() 857 874 x, y = self.position(surface) 858 surface.blit(self.surface, (x, y)) 875 surface.blit(self.surface, (x, y), 876 (0, self.top, self.width, self.height)) 859 877 860 878
