当前位置: 首页>>代码示例>>Python>>正文


Python Font.size方法代码示例

本文整理汇总了Python中pygame.font.Font.size方法的典型用法代码示例。如果您正苦于以下问题:Python Font.size方法的具体用法?Python Font.size怎么用?Python Font.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.font.Font的用法示例。


在下文中一共展示了Font.size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import size [as 别名]
    def __init__(self, x, y, width, height, msg, size=16, 
            text_colour=base.BLACK, bg_colour=base.WHITE, 
            highlight_text=base.WHITE, highlight_bg=base.BLACK,
            offset_x=0, offset_y=0, bold=False):

        self.normal = pygame.Surface((width, height))
        self.normal.fill(bg_colour)

        font = Font(_FONT, size)
        font.set_bold(bold)
        font_width, font_height = font.size(msg)
        font_x = (width - font_width) / 2
        font_y = (height - font_height) / 2

        self.normal.blit(font.render(msg, False, text_colour), 
                                    (font_x, font_y))

        self.highlighted = pygame.Surface((width, height))
        self.highlighted.fill(highlight_bg)
        self.highlighted.blit(font.render(msg, False, highlight_text), 
                                        (font_x, font_y))

        self.offset_x = offset_x
        self.offset_y = offset_y
        
        self.force_highlight = False
        self.disabled = False
        PicassoAsset.__init__(self, self.normal, x, y)
开发者ID:anthony-cervantes,项目名称:risk-1,代码行数:30,代码来源:clickable.py

示例2: find_font_size

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import size [as 别名]
 def find_font_size(self):
     size = 100
     while size >= 1:
         f = Font(FONT, size)
         w, h = f.size('8')
         if w < self.w and h < self.h:
             return size
         size = size -1
     return size
开发者ID:sumpfgottheit,项目名称:pdu1800,代码行数:11,代码来源:widgets.py

示例3: draw

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import size [as 别名]
 def draw(self):
     if self.dirty():
         self.count = self.territory_asset.territory.armies
         font = Font(None, self.size)
         dimension = font.size(str(self.count) * 2)
         text_diagonal_length = math.sqrt(math.pow(dimension[0] / 2, 2) + math.pow(dimension[1], 2))
         circle_radius = int(math.ceil(text_diagonal_length / 2))
         #print circle_radius
         #print dimension [0]
         self.surface = pygame.Surface([44, 44], pygame.SRCALPHA, 32)
         self.surface = self.surface.convert_alpha()
         pygame.draw.circle(self.surface, base.BLACK, 
                 (circle_radius, circle_radius), 
                 circle_radius)
         pygame.draw.circle(self.surface, base.LIGHT_BROWN, 
                 (circle_radius, circle_radius), 
                 circle_radius - 2)
         font_surface = font.render(str(self.count), False,
                 self.colour).convert()
         self.surface.blit(font_surface, (circle_radius - dimension[0] / 4, circle_radius - dimension[1] / 2))
     return self.surface
开发者ID:anthony-cervantes,项目名称:risk-1,代码行数:23,代码来源:territory.py

示例4: rect_setup

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import size [as 别名]
 def rect_setup(self, button_width, button_height):
     ''' works out menu button positions and font sizes, iterates down
     from a large size so that it finds the largest size that fits the text
     for all the buttons nicely. Preferably the button strings should vary 
     too much in length'''
     surf_midpoint = (int(0.5 * self.surf_width), int( 0.5 * self.surf_height ))
     text_size = Menu.INITIAL_TEXT_SIZE
     font = Font(None, text_size)
     rect_list = []
     for i in range(self.num_buttons):
         button_pos = (surf_midpoint[0] - button_width/2,
                       surf_midpoint[1] + (button_height * (i - self.num_buttons/2)) * Menu.BUTTON_SPACING)
         rect = Rect(button_pos, (button_width, button_height))
         rect_list.append(rect)
         while (font.size(self.button_strings[i])[0] >= (button_width * Menu.FONT_MARGIN) or
                font.size(self.button_strings[i])[1] >= (button_height * Menu.FONT_MARGIN)):
             text_size -= 1
             font = Font(None, text_size)
     self.button_rects = rect_list
     self.button_text = [font.render(s, 1, BLACK) for s in self.button_strings]
     self.button_text_pos = [(self.button_rects[i].center[0] - self.button_text[i].get_size()[0]/2, 
                             self.button_rects[i].center[1] - self.button_text[i].get_size()[1]/2)
                             for i in range(self.num_buttons)]
开发者ID:BenjaminGardner31,项目名称:JetpacClonePython,代码行数:25,代码来源:menu.py


注:本文中的pygame.font.Font.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。