Ejemplo n.º 1
0
    def refactor(self):

        self.lines, area=gui_util.wrap_text(self.font, self.message, self.wrap_text)

        self.area=list(area)

        if self.image_normal:
            if isinstance(self.image_normal, pygame.Surface):
                pass
            else:
                self.image_normal=self.image_normal.resize(area,self.image_mode)
                if self.image_normal.get_width() > self.area[0]:
                    self.area[0]=self.image_normal.get_width()
                if self.image_normal.get_height() > self.area[1]:
                    self.area[1]=self.image_normal.get_height()

        if self.image_hover:
            if isinstance(self.image_hover, pygame.Surface):
                pass
            else:
                self.image_hover=self.image_hover.resize(area,
                                                         self.image_mode)

        if self.image_click:
            if isinstance(self.image_click, pygame.Surface):
                pass
            else:
                self.image_click=self.image_click.resize(area,self.image_mode)

        self.message_image=pygame.Surface(self.area).convert_alpha()
        self.message_image.fill([0,0,0,0])
        l=[self.font.render(i) for i in self.lines]
        for i in range(len(l)):
            line=l[i]
            r=line.get_rect()

            if self.align[0]=="left":
                r.left=0
            elif self.align[0]=="center":
                r.centerx=self.area[0]/2
            else:
                r.right=self.area[0]

            if self.align[1]=="top":
                r.top=0
            elif self.align[1]=="center":
                r.centery=self.area[1]/2
            else:
                r.right=self.area[1]

            self.message_image.blit(line, r.topleft)

        self.image=self.image_normal

        self.rect=pygame.Rect(self.pos, self.area)
        if self.use_pp:
            self.hitmask_text=pixelperfect.Hitmask(self.message_image, pos=self.pos)
            self.hitmask_image=pixelperfect.Hitmask(self.image,
                                                    pos=self.pos)
Ejemplo n.º 2
0
    def add_message(self, mess):
        if self.wrap:
            for x in gui_util.wrap_text(self.font, mess, self.wrap)[0]:
                self.messages.append(x)
        else:
            self.messages.append(mess)

        if self.max_lines:
            while len(self.messages)>self.max_lines:
                del self.messages[0]

        self.max_width=0
        for i in self.messages:
            w=self.font.size(i)[0]
            if w>self.max_width:
                self.max_width=w
Ejemplo n.º 3
0
    def refactor(self):
        self.lines, area=gui_util.wrap_text(self.font, self.message, self.wrap_text)

        self.area=list(area)

        if self.image:
            if isinstance(self.image, pygame.Surface):
                pass
            else:
                self.image=self.image.resize(self.area, self.image_mode)

            if self.image.get_width() > self.area[0]:
                self.area[0]=self.image.get_width()
            if self.image.get_height() > self.area[1]:
                self.area[1]=self.image.get_height()

        self.message_image=pygame.Surface(self.area).convert_alpha()
        self.message_image.fill([0,0,0,0])
        l=[self.font.render(i) for i in self.lines]
        for i in range(len(l)):
            line=l[i]
            r=line.get_rect()

            if self.align[0]=="left":
                r.left=0
            elif self.align[0]=="center":
                r.centerx=self.area[0]/2
            else:
                r.right=self.area[0]

            if self.align[1]=="top":
                r.top=0
            elif self.align[1]=="center":
                r.centery=self.area[1]/2
            else:
                r.right=self.area[1]

            r.top+=i*(self.font.fsize-(self.font.fsize/3))

            self.message_image.blit(line, r.topleft)

        self.rect=pygame.Rect(self.pos, self.area)