Example #1
0
    def __init__(self, title, pos, userData, parent=None, callback=None):
        self.title = title
        self.userData = userData
        self.parent = parent
        self.childs = []

        if self.parent:
            self.visible = False
        else:
            self.visible = True

        if callback:
            self.callback = callback
        else:
            self.callback = self.empty

        # Create Surface and Stuff :)
        self.font = pygame.font.Font(None, 32)
        text = self.font.render(title, 1, (255, 255, 255))

        rx, ry, rw, rh = rect = text.get_rect()
        pl, pt, pr, pb = self.padding

        s1 = pygame.Surface((rw + pl + pr, rh + pt + pb))
        s1.fill(tools.hex2rgb(COLOR_HEX_BLUE1))
        s1.blit(text, (pl, pt))

        s2 = pygame.Surface((rw + pl + pr, rh + pt + pb))
        s2.fill(tools.hex2rgb(COLOR_HEX_BLUE2))
        s2.blit(text, (pl, pt))

        self.rect = s1.get_rect().move(pos)

        self.surface_inactive = s1
        self.surface_active = s2
Example #2
0
    def __init__(self, title, pos, userData, parent=None, callback=None):
        self.title = title
        self.userData = userData
        self.parent = parent
        self.childs = []

        if self.parent:
            self.visible = False
        else:
            self.visible = True

        if callback:
            self.callback = callback
        else:
            self.callback = self.empty

        # Create Surface and Stuff :)
        self.font = pygame.font.Font(None, 32)
        text = self.font.render(title, 1, (255, 255, 255))

        rx, ry, rw, rh = text.get_rect()
        pl, pt, pr, pb = self.padding

        s1 = pygame.Surface((rw + pl + pr, rh + pt + pb))
        s1.fill(tools.hex2rgb(COLOR_HEX_BLUE1))
        s1.blit(text, (pl, pt))

        s2 = pygame.Surface((rw + pl + pr, rh + pt + pb))
        s2.fill(tools.hex2rgb(COLOR_HEX_BLUE2))
        s2.blit(text, (pl, pt))

        self.rect = s1.get_rect().move(pos)

        self.surface_inactive = s1
        self.surface_active = s2
Example #3
0
    def draw(self, surface):
        """ Draw the menu with pygame on a given surface
        """
        s = pygame.Surface((self.width, self.height))
        s.fill(tools.hex2rgb(COLOR_HEX_BLUE1))

        surface.blit(s, (0, 0))

        for i in xrange(len(self.items)):
            item = self.items[i]
            if not item.parent:
                x, y, w, h = item.rect
                if self.focus == i + 1:
                    surface.blit(item.surface_active, (x, y))
                else:
                    surface.blit(item.surface_inactive, (x, y))

        # If a menu item is open, draw that
        if self.focus:
            width = 0
            height = 0

            i = []
            for j in self.items:
                if j.parent == self.focus:
                    i.append(j)
                    x, y, w, h = j.rect
                    if w > width:
                        width = w
                    height += h

            if len(i) > 0:
                s = pygame.Surface((width, height))
                s.fill(tools.hex2rgb(COLOR_HEX_BLUE1))

                # Parent Coordinates
                px, py, pw, ph = self.items[self.focus - 1].rect

                # y Counter
                y = 0

                for item in i:
                    item.visible = True
                    s.blit(item.surface_inactive, (0, y))

                    ix, iy, iw, ih = item.rect
                    if (ix, iy) == (0, 0):
                        item.rect = item.rect.move((px, y + ph))
                        ix, iy, iw, ih = item.rect

                    if iw < width:
                        item.rect = (ix, iy, width, ih)

                    y += ih

                surface.blit(s, (px, py + ph))
                self.subwin_rect = s.get_rect().move(px, py + ph)
Example #4
0
    def draw(self, surface):
        """ Draw the menu with pygame on a given surface
        """
        s = pygame.Surface((self.width, self.height))
        s.fill(tools.hex2rgb(COLOR_HEX_BLUE1))

        surface.blit(s, (0, 0))

        for i in xrange(len(self.items)):
            item = self.items[i]
            if not item.parent:
                x, y, w, h = item.rect
                if self.focus == i + 1:
                    surface.blit(item.surface_active, (x, y))
                else:
                    surface.blit(item.surface_inactive, (x, y))

        # If a menu item is open, draw that
        if self.focus:
            width = 0
            height = 0

            i = []
            for j in self.items:
                if j.parent == self.focus:
                    i.append(j)
                    x, y, w, h = j.rect
                    if w > width: width = w
                    height += h

            if len(i) > 0:
                s = pygame.Surface((width, height))
                s.fill(tools.hex2rgb(COLOR_HEX_BLUE1))

                # Parent Coordinates
                px, py, pw, ph = self.items[self.focus - 1].rect

                # y Counter
                y = 0

                for item in i:
                    item.visible = True
                    s.blit(item.surface_inactive, (0, y))

                    ix, iy, iw, ih = item.rect
                    if (ix, iy) == (0, 0):
                        item.rect = item.rect.move((px, y + ph))
                        ix, iy, iw, ih = item.rect

                    if iw < width:
                        item.rect = (ix, iy, width, ih)

                    y += ih

                surface.blit(s, (px, py + ph))
                self.subwin_rect = s.get_rect().move(px, py + ph)
Example #5
0
 def get_color(self):
     """ Get a color - either the fixed one or the next from self.colors 
     
         Return: clr = ((R), (G), (B)) 
     """
     if self.fixed_color != None:
         return self.fixed_color
         
     if self.cur_color == len(self.colors): 
         self.cur_color = 0
         shuffle(self.colors)
 
     clr = self.colors[self.cur_color]
     if clr[0] == "#":
         clr = tools.hex2rgb(clr)
     
     self.cur_color += 1
     return clr
Example #6
0
 def get_color(self):
     """ Get a color - either the fixed one or the next from self.colors 
     
         Return: clr = ((R), (G), (B)) 
     """
     if self.fixed_color != None:
         return self.fixed_color
         
     if self.cur_color == len(self.colors): 
         self.cur_color = 0
         shuffle(self.colors)
 
     clr = self.colors[self.cur_color]
     if clr[0] == "#":
         clr = tools.hex2rgb(clr)
     
     self.cur_color += 1
     return clr