def get_text_transparent(name):
    text = loaders.text(name, fonts['mono']['15']).convert()
    text.fill(pygame.color.Color("black"))
    #TODO: the colorkey should be a property of the skin
    text.set_colorkey(pygame.color.Color("black"))
    text.blit(loaders.text(name, fonts['mono']['15']), (0, 0))
    return text
def get_text_transparent(name):
    text = loaders.text(name, fonts['mono']['10']).convert()
    #FIXME: the colorkey should be in a skin configuration file
    text.fill(pygame.color.Color("black"))
    text.set_colorkey(pygame.color.Color("black"))
    text.blit(loaders.text(name, fonts['mono']['22']), (0, 0))
    return text
Beispiel #3
0
def get_text_transparent(name):
    text = loaders.text(name, fonts['mono']['15']).convert()
    text.fill(pygame.color.Color("black"))
    #TODO: the colorkey should be a property of the skin
    text.set_colorkey(pygame.color.Color("black"))
    text.blit(loaders.text(name, fonts['mono']['15']), (0, 0))
    return text
Beispiel #4
0
def get_text_transparent(name):
    text = loaders.text(name, fonts['mono']['10']).convert()
    #FIXME: the colorkey should be in a skin configuration file
    text.fill(pygame.color.Color("black"))
    text.set_colorkey(pygame.color.Color("black"))
    text.blit(loaders.text(name, fonts['mono']['22']), (0, 0))
    return text
 def display_fps(self):
     """ FPS counter
     """
     if CONFIG.display.SHOW_FPS:
         self.screen.blit(
             loaders.text("FPS: " + str(self.clock.get_fps()),
                          fonts["mono"]["38"]), (10, 5))
    def update(self):
        self.background = loaders.image(
                os.path.join(
                    CONFIG.system_path, "gui",
                    CONFIG.general.THEME,"keyboard.png"),
                scale=(self.width, self.height))[0]

        self.background_hover = loaders.image(
                os.path.join(
                    CONFIG.system_path,
                    "gui",
                    CONFIG.general.THEME,
                    "keyboard_hover.png"),
                scale=(self.width, self.height))[0]

        text = loaders.text(self.letter, self.font)
        if text.get_width() > self.width:
            text = pygame.transform.smoothscale(
                    text, (
                        self.width,
                        self.width * text.get_height() / text.get_width()))

        posx = self.width/2 - text.get_width()/2
        posy = self.height/2 - text.get_height()/2
        self.surface = loaders.image_layer(self.background_hover,
                text, (posx, posy))
        self.surface_hover = loaders.image_layer(self.background,
                text, (posx, posy))
        self.screen = pygame.display.get_surface()
    def name(self, name):
        self._name = name.replace('_', ' ')

        #center the title
        self.indent_title = (
                CONFIG.general.WIDTH/2 - loaders.text(
                    self._name, fonts['mono']['15']).get_width()/2)
Beispiel #8
0
    def display_game_state(self):
        """
        Display whether the game is ended by a win or a draw, does nothing if the
        game is still running
        """

        alive_players = filter(Entity.alive, self.players)

        if len(alive_players) == 1:
            self.screen.blit(
                    loaders.text(
                        alive_players[0].name.capitalize() + _(" WON!"),
                        fonts["bold"][15], 0, 0, 0),
                    (self.size[0] / 2, self.size[1] / 2))

        elif len(alive_players) == 0:
            self.screen.blit(GAME_FONT.render(
                _("OOPS... DRAW!!!"),
                True,
                pygame.color.Color("#" +
                    str(math.sin(self.ending / 10))[3:5] +
                    "50" +
                    str(math.sin(self.ending / 10))[3:5] +
                    "30")),
                (self.size[0] / 2, self.size[1] / 2))
    def update(self):
        #draw the title of the surface
        self.surface.blit(loaders.text(self.name, fonts['mono']['15']),
                (self.indent_title, 10))

        #draw all the others widgets
        self.widget.draw()
Beispiel #10
0
    def update_youhere(self):
        screen_list = ""
        for scr in self.screen_history:
            screen_list += scr + "/"

        screen_list += self.current_screen + "/"
        self.here = loaders.text("> " + _("you are here:") + screen_list,
                                 fonts['mono']['30'])
    def update_youhere(self):
        screen_list = ""
        for scr in self.screen_history:
            screen_list += scr + "/"

        screen_list += self.current_screen + "/"
        self.here = loaders.text("> " + _("you are here:") + screen_list,
            fonts['mono']['30'])
Beispiel #12
0
 def display_fps(self):
     """ FPS counter
     """
     if CONFIG.display.SHOW_FPS:
         self.screen.blit(
                 loaders.text(
                     "FPS: " + str(self.clock.get_fps()),
                     fonts["mono"]["38"]),
                 (10, 5))
    def __init__(self, path):
        super(Paragraph, self).__init__()
        self.defil = 0
        self.state = False
        self.slider_y = 0
        self.hover = False
        self.auto_scroll = True

        text = open(join(CONFIG.system_path, path), 'r').readlines()
        text_height = loaders.text("", fonts['mono']['normal']).get_height()

        #the slider (at left)
        self.width_slider = 34
        self.height_slider = 125
        self.pos_slider = self.width / 20 * 19

        #the main surface
        self.width = 500 #XXX hardcoded values
        self.height = 125 #XXX hardcoded values
        self.surface = pygame.surface.Surface((self.width, self.height))

        #create the surface whiwh will contain _all_ the text
        width = self.width - self.width_slider * 2
        if width < 0:
            width = 0
        self.surface_text = pygame.surface.Surface(
                (width, len(text) * text_height))

        #draw all the text into the surface
        for i, t in enumerate(text):
            self.surface_text.blit(
                    loaders.text(
                        t.replace('\n', ""),
                        fonts['mono']['normal']),
                    (0, text_height * i))

        self.slider = SubPixelSurface(loaders.image(
            join(
                CONFIG.system_path,
                "gui",
                CONFIG.general.THEME,
                "sliderh_center.png"),
            scale=(self.width_slider, self.height_slider))[0], x_level=4)
 def _draw_debug_current_animation(self, coords, surface, debug_params):
     """
     if the current_animation debug is set, write the name of the current
         animation near of the character
     """
     if self.visible:
         if debug_params.get('current_animation', False):
             surface.blit(
                 loaders.text(self.entity_skin.current_animation,
                 fonts['mono']['25']),
                 (coords[0], coords[1] - self.entity_skin.animation.rect[3]))
    def set_text(self, text):
        """ update the text surface
        """
        self.text = text
        self.surface_text = loaders.text(self.text, fonts['sans']['normal'])

        if self.dynamic_size[0]:
            if 'size_request' in self.properties:
                self.height = max(
                        self.properties['size_request'][1],
                        self.surface_text.get_height() + self.txtmargin * 2)
            else:
                self.height = (
                        self.surface_text.get_height() + self.txtmargin * 2)

        if self.dynamic_size[1]:
            if 'size_request' in self.properties:
                self.width = max(
                        self.properties['size_request'][0],
                        self.surface_text.get_width() + self.txtmargin * 2)

            else:
                self.width = self.surface_text.get_width() + self.txtmargin * 2

        if self.align == "center":
            self.indent = self.width / 2 - self.surface_text.get_width() / 2
        else:
            self.indent = 0

        self.horizontal_indent = (
                self.height / 2 - self.surface_text.get_height() / 2)

        try:
            if self.background_expand:
                self.background = loaders.image(
                    join(
                        CONFIG.system_path, self.background_path),
                    expand=(self.width, self.height, 10))[0]
            else:
                self.background = loaders.image(
                    join(
                        CONFIG.system_path, self.background_path),
                    scale=(self.width, self.height))[0]

            self.surface = loaders.image_layer(
                    self.background,
                    self.surface_text,
                    (self.txtmargin + self.indent, self.horizontal_indent))

        except AttributeError:
            self.surface = self.surface_text
        self.screen = pygame.display.get_surface()
Beispiel #16
0
    def __init__(self, path):
        super(Paragraph, self).__init__()
        self.defil = 0
        self.state = False
        self.slider_y = 0
        self.hover = False
        self.auto_scroll = True

        text = open(join(CONFIG.system_path, path), 'r').readlines()
        text_height = loaders.text("", fonts['mono']['normal']).get_height()

        #the slider (at left)
        self.width_slider = 34
        self.height_slider = 125
        self.pos_slider = self.width / 20 * 19

        #the main surface
        self.width = 500  #XXX hardcoded values
        self.height = 125  #XXX hardcoded values
        self.surface = pygame.surface.Surface((self.width, self.height))

        #create the surface whiwh will contain _all_ the text
        width = self.width - self.width_slider * 2
        if width < 0:
            width = 0
        self.surface_text = pygame.surface.Surface(
            (width, len(text) * text_height))

        #draw all the text into the surface
        for i, t in enumerate(text):
            self.surface_text.blit(
                loaders.text(t.replace('\n', ""), fonts['mono']['normal']),
                (0, text_height * i))

        self.slider = SubPixelSurface(loaders.image(
            join(CONFIG.system_path, "gui", CONFIG.general.THEME,
                 "sliderh_center.png"),
            scale=(self.width_slider, self.height_slider))[0],
                                      x_level=4)
Beispiel #17
0
    def set_text(self, text):
        """ update the text surface
        """
        self.text = text
        self.surface_text = loaders.text(self.text, fonts['sans']['normal'])

        if self.dynamic_size[0]:
            if 'size_request' in self.properties:
                self.height = max(
                    self.properties['size_request'][1],
                    self.surface_text.get_height() + self.txtmargin * 2)
            else:
                self.height = (self.surface_text.get_height() +
                               self.txtmargin * 2)

        if self.dynamic_size[1]:
            if 'size_request' in self.properties:
                self.width = max(
                    self.properties['size_request'][0],
                    self.surface_text.get_width() + self.txtmargin * 2)

            else:
                self.width = self.surface_text.get_width() + self.txtmargin * 2

        if self.align == "center":
            self.indent = self.width / 2 - self.surface_text.get_width() / 2
        else:
            self.indent = 0

        self.horizontal_indent = (self.height / 2 -
                                  self.surface_text.get_height() / 2)

        try:
            if self.background_expand:
                self.background = loaders.image(join(CONFIG.system_path,
                                                     self.background_path),
                                                expand=(self.width,
                                                        self.height, 10))[0]
            else:
                self.background = loaders.image(join(CONFIG.system_path,
                                                     self.background_path),
                                                scale=(self.width,
                                                       self.height))[0]

            self.surface = loaders.image_layer(
                self.background, self.surface_text,
                (self.txtmargin + self.indent, self.horizontal_indent))

        except AttributeError:
            self.surface = self.surface_text
        self.screen = pygame.display.get_surface()
 def move_cursor(self, x):
     """ place the cursor at the position nearest of x in the widget
     """
     x -= self.indent
     text = self.get_text()
     diff = self.width
     self.cursor = 1
     text_font = font.fonts["sans"]["normal"]
     for i in range(0, len(text) + 1):
         diff_temp = min(
             diff, abs(x - loaders.text(text[0:i], text_font).get_width()))
         if diff is not diff_temp:
             self.cursor = i
         diff = diff_temp
 def move_cursor(self, x):
     """ place the cursor at the position nearest of x in the widget
     """
     x -= self.indent
     text = self.get_text()
     diff = self.width
     self.cursor = 1
     text_font = font.fonts["sans"]["normal"]
     for i in range(0, len(text) + 1):
         diff_temp = min(diff,
                 abs(x - loaders.text(text[0:i], text_font).get_width()))
         if diff is not diff_temp:
             self.cursor = i
         diff = diff_temp
    def draw(self):
        super(TextEntry, self).draw()

        # Display the cursor
        if self.state:
            # Get text width
            offset = loaders.text(
                self.get_text()[0:self.cursor],
                font.fonts["sans"]['normal']).get_width() + self.indent

            # Draw cursor
            color_value = int(abs(sin(self.cursor_state)) * 255) / 2
            #print color_value
            color_cursor = color.Color(color_value, color_value, color_value)
            draw.line(self.screen, color_cursor,
                      (self.parentpos[0] + self.x + offset,
                       self.parentpos[1] + self.y),
                      (self.parentpos[0] + self.x + offset,
                       self.parentpos[1] + self.y + self.height), 2)
        self.start_anim()
    def draw(self):
        super(TextEntry, self).draw()

        # Display the cursor
        if self.state:
            # Get text width
            offset = loaders.text(
                    self.get_text()[0:self.cursor],
                    font.fonts["sans"]['normal']).get_width() + self.indent

            # Draw cursor
            color_value = int(abs(sin(self.cursor_state))*255)/2
            #print color_value
            color_cursor = color.Color(color_value, color_value, color_value)
            draw.line(self.screen, color_cursor,
                      (self.parentpos[0] + self.x + offset,
                       self.parentpos[1] + self.y),
                      (self.parentpos[0] + self.x + offset,
                       self.parentpos[1] + self.y + self.height),
                     2)
        self.start_anim()
    def update(self):
        self.background = loaders.image(os.path.join(CONFIG.system_path, "gui",
                                                     CONFIG.general.THEME,
                                                     "keyboard.png"),
                                        scale=(self.width, self.height))[0]

        self.background_hover = loaders.image(
            os.path.join(CONFIG.system_path, "gui", CONFIG.general.THEME,
                         "keyboard_hover.png"),
            scale=(self.width, self.height))[0]

        text = loaders.text(self.letter, self.font)
        if text.get_width() > self.width:
            text = pygame.transform.smoothscale(
                text, (self.width,
                       self.width * text.get_height() / text.get_width()))

        posx = self.width / 2 - text.get_width() / 2
        posy = self.height / 2 - text.get_height() / 2
        self.surface = loaders.image_layer(self.background_hover, text,
                                           (posx, posy))
        self.surface_hover = loaders.image_layer(self.background, text,
                                                 (posx, posy))
        self.screen = pygame.display.get_surface()
 def load(self):
     loaders.text(self.name, fonts['mono']['15'])
     self.widget.draw()