Beispiel #1
0
    def __init__(self, pos, text, button_labels, font, minimum_width):
        self.buttons = []
        self.grabbed = 0
        self.grabbed_pos = (0, 0)

        width = 0

        for button_label in button_labels:
            self.buttons.append(Button((0, 0), button_label, font))
            width += self.buttons[-1].dim[0]
            
        if len(self.buttons) > 0:
            width += B_BUFFER * (len(self.buttons) - 1)

        button_line_width = width
        width = max(width, minimum_width)

        text_lines = TextLines((H_BUFFER, 
                                V_BUFFER),
                               text,
                               font,
                               width)
        
        button_y_pos = pos[1] + text_lines.dim[1] + 2 * V_BUFFER
#        button_x_pos = pos[0] + H_BUFFER
        button_x_pos = (width - button_line_width + H_BUFFER) / 2
        button_x_pos += pos[0]

        height = button_y_pos - pos[1]

        if len(self.buttons) != 0:
            height += self.buttons[0].dim[1]
            height += V_BUFFER

        for button in self.buttons:
            button.pos = (button_x_pos, button_y_pos)
            button_x_pos += button.dim[0] + H_BUFFER

        dim = (2 * H_BUFFER + width, height)
               
        self.surface = pygame.Surface(dim)
        self.surface.fill(BORDER_COLOR)

        light_surface = pygame.Surface((dim[0] - BOX_MARGINALS, 
                                        dim[1] - BOX_MARGINALS))
        light_surface.fill(BG_COLOR)

        self.surface.blit(light_surface, (BOX_MARGINALS / 2,
                                          BOX_MARGINALS / 2))

        text_lines.render(self.surface, 1)

        Widget.__init__(self, pos, dim, self.buttons)
Beispiel #2
0
    def __init__(self, pos, text, button_labels, font, minimum_width):
        self.buttons = []
        self.grabbed = 0
        self.grabbed_pos = (0, 0)

        width = 0

        for button_label in button_labels:
            self.buttons.append(Button((0, 0), button_label, font))
            width += self.buttons[-1].dim[0]

        if len(self.buttons) > 0:
            width += B_BUFFER * (len(self.buttons) - 1)

        button_line_width = width
        width = max(width, minimum_width)

        text_lines = TextLines((H_BUFFER, V_BUFFER), text, font, width)

        button_y_pos = pos[1] + text_lines.dim[1] + 2 * V_BUFFER
        #        button_x_pos = pos[0] + H_BUFFER
        button_x_pos = (width - button_line_width + H_BUFFER) / 2
        button_x_pos += pos[0]

        height = button_y_pos - pos[1]

        if len(self.buttons) != 0:
            height += self.buttons[0].dim[1]
            height += V_BUFFER

        for button in self.buttons:
            button.pos = (button_x_pos, button_y_pos)
            button_x_pos += button.dim[0] + H_BUFFER

        dim = (2 * H_BUFFER + width, height)

        self.surface = pygame.Surface(dim)
        self.surface.fill(BORDER_COLOR)

        light_surface = pygame.Surface(
            (dim[0] - BOX_MARGINALS, dim[1] - BOX_MARGINALS))
        light_surface.fill(BG_COLOR)

        self.surface.blit(light_surface,
                          (BOX_MARGINALS / 2, BOX_MARGINALS / 2))

        text_lines.render(self.surface, 1)

        Widget.__init__(self, pos, dim, self.buttons)
Beispiel #3
0
             ["New game", "Load", "Save", "Quit"], font, 
             100)

menu2 = Menu((menu1.dim[0]+1, 0), "Menu", 
             ["New game", "Load", "Save", "Help", "Quit"], font, 
             100)

button1 = Button((100, 100), "OK", font, 70)
button2 = Button((200, 100), "Quit", font, 70)

dialog_box = DialogBox((100, 150), "Useless text that could be in a " +
                       "dialog box.",["OK", "Cancel", "Quit"], font, 300)

text_lines = TextLines((300, 300), 
                       "This is a pretty long line that won't fit in 200 px. "+
                       "Hence, it's going to be split.",
                       font, 
                       200,
                       0)

radio_buttons = RadioButtonList((450, 50), ["English",
                                            "French",
                                            "Spanish"],
                                font)

menu1.activate()
menu2.activate()
button1.activate()
button2.activate()
text_lines.activate()
dialog_box.activate()
radio_buttons.activate()