Пример #1
0
 def draw_unselected_tab(self, rect):
     DEFAULT_COLOR = transparency(DARKER_MAGENTA, 0.5)
     border = 2
     internal_rect = pygame.Rect((rect.left + border, rect.top + border),
                                 (rect.w - 2 * border, rect.h - border))
     surface = pygame.Surface((rect.width, rect.height), SRCALPHA, 32)
     pygame.draw.rect(surface, DEFAULT_COLOR, internal_rect)
     return Image(surface)
Пример #2
0
    def draw_unselected_tab(self, rect):
        surface = pygame.Surface((rect.width, rect.height), SRCALPHA, 32)
        pygame.draw.rect(surface, self.border_color, rect)

        inner_rect = pygame.Rect(
            (rect.left + self.border, rect.top + self.border),
            (rect.width - 2 * self.border, rect.height - self.border))
        pygame.draw.rect(surface, self.unselected_tab_color, inner_rect)
        return Image(surface)
Пример #3
0
 def init_bg(self, bg):
     if bg is not None:
         bg_surf = pygame.Surface((self.width, self.height), SRCALPHA, 32)\
                   .convert_alpha()
         if isinstance(bg, tuple) and len(bg) >= 3:
             bg_surf.fill(bg)
         else:
             fill_with_surface(bg_surf, bg)
         self.bg = Image(bg_surf)
     else:
         r = pygame.Rect(0, 0, self.width, self.height)
         self.bg = self.theme.draw_menu_bg(r)
Пример #4
0
    def draw_image(self, image):
        """
        *Virtual.*

        Return an Image with how an ImageWidget should be rendered.

        *image* should be a pygame Surface with the ImageWidget's
        appearance.

        This can be overloaded to apply some filters to
        images used in ImageWidgets.
        """
        return Image(image)
Пример #5
0
    def get_icon(self):
        """
        Returns an Image with the item's icon.
        """
        loc = self.get_icon_location()
        if loc is None:
            return None
        if not hasattr(loc, '__len__') or len(loc) not in (2, 4):
            raise Exception('%s.get_icon_location() should return a 2-tuple'
                            'or a 4-tuple')

        image = pygame.image.load(loc[0])
        icon_w = g_cfg.item_icon_width if len(loc) <= 2 else loc[2]
        icon_h = g_cfg.item_icon_height if len(loc) <= 3 else loc[3]
        sliced_img = SlicedImage(image, icon_w, icon_h)
        return Image(sliced_img.get_slice(loc[1]))
Пример #6
0
 def draw(self):
     if self.image is None or self.changed:
         end = self.start + self.height_in_cells
         self.scroll_bar_img = self.theme.draw_scroll_bar(self.height,
                                                          self.start,
                                                          end,
                                                          len(self))
         r = pygame.Rect(0, 0, self.get_cells_width(), self.height)
         #self.scroll_area_img = self.theme.draw_scroll_area(r)
         
         surf = pygame.Surface((self.width, self.height), SRCALPHA, 32)
         #surf.blit(self.scroll_area_img.get_surface(), (0, 0))
         surf.blit(self.scroll_bar_img,
                         (r.w, 0))
         self.image = Image(surf)
         self.changed = False
     Div.draw(self)
Пример #7
0
    def __draw_multi_line(self, font):
        lines = build_lines(self.text, self.max_width, font)
        total_height = sum([e[0] for e in lines])
        s = pygame.Surface((self.max_width, total_height), SRCALPHA, 32)
        y = 0
        for w, h, line in lines:
            line_surface = font.render(line,
                                       self.theme.get_font_anti_alias(),
                                       self.color)
            if self.align == LEFT:
                x = 0
            elif self.align == RIGHT:
                x = self.max_width - w
            elif self.align == CENTER:
                x = (self.max_width - w) / 2

            s.blit(line_surface, (x, y))
            y += h
        self.image = Image(s)
Пример #8
0
    def draw_bar(self, rect, filled=1.0):
        surface = pygame.Surface((rect.width, rect.height), SRCALPHA, 32)
        surface.fill(TRANSPARENT)

        border = 0 if (rect.width < 4 or rect.height < 4) else 1
        for i in xrange(border):
            border_rect = pygame.Rect(
                (rect.left + i, rect.top + i),
                (rect.width - 2 * i, rect.height - 2 * i))
            pygame.draw.rect(surface, WHITE, border_rect, 1)

        width = rect.width - 2 * border
        vertical_lines = int(width * filled)
        for i in xrange(vertical_lines):
            green = (255.0 * (vertical_lines - i)) / width
            color = (255, green, 0, 255)
            pygame.draw.line(
                surface, color, (rect.left + i + border, rect.top + border),
                (rect.left + i + border, rect.bottom - 1 - border), 1)
        return Image(surface)
Пример #9
0
 def draw_round_border_rect_image(self,
                                  rect,
                                  border_flags=(None, True, True, True,
                                                True)):
     surface = self.draw_round_border_rect(rect, border_flags)
     return Image(surface)
Пример #10
0
 def __init__(self, filename, x_offset=0, y_offset=0):
     self.filename = filename
     self.x_offset = x_offset
     self.y_offset = y_offset
     self.image = Image(pygame.image.load(self.filename))
Пример #11
0
 def draw_scroll_area(self, rect):
     DEFAULT_COLOR = transparency(DARK_RED, 0.5)
     surface = pygame.Surface((rect.width, rect.height), SRCALPHA, 32)
     pygame.draw.rect(surface, DEFAULT_COLOR, rect)
     return Image(surface)
Пример #12
0
 def draw_panel(self, rect):
     DEFAULT_COLOR = transparency(PURPLE, 0.5)
     surface = pygame.Surface((rect.width, rect.height), SRCALPHA, 32)
     pygame.draw.rect(surface, DEFAULT_COLOR, rect)
     return Image(surface)
Пример #13
0
 def __draw_one_line(self, font):
     self.image = Image(font.render(self._text,
                                    self.theme.get_font_anti_alias(),
                                    self.color))