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


Python TextNode.getMaxRows方法代码示例

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


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

示例1: TextBoard

# 需要导入模块: from pandac.PandaModules import TextNode [as 别名]
# 或者: from pandac.PandaModules.TextNode import getMaxRows [as 别名]
class TextBoard():
    
    def __init__(self, text_color=(1,1,1), max_nr_rows=3, nr_char_per_row=20,
                 frame_color=(0,0,0), frame_padding=0.4, frame_line_width=2,
                 background_color=(1,1,0), background_padding=0.8):
        #print "TextBoard::init"
        # everything that belongs to this TextBoard will be stored under the root node
        self.root_node_path = render.attachNewNode(PandaNode(''))
        # create the text node that will be the TextBoard
        self.text_node = TextNode('')
        self.text_node_path = self.root_node_path.attachNewNode(self.text_node)
        self.set_max_nr_rows(max_nr_rows)
        r,g,b = text_color
        self.set_text_color(r, g, b)
        self.text_node.setAlign(TextNode.ALeft)  # TextNode.ALeft, TextNode.ACenterba
        letter_width, letter_height = self._compute_letter_size()
        self.max_row_length = nr_char_per_row * letter_width
        self.text_node.setWordwrap(self.max_row_length)
        width, height = self._compute_max_text_size()
        self.text_node_path.setPos(0.5*background_padding,-0.01,-letter_height)
        self.background_node_path = self.root_node_path.attachNewNode(PandaNode('background_node'))
        self._create_background(self.background_node_path, width+background_padding, height+background_padding+letter_height)
        self.frame_node_path = self.root_node_path.attachNewNode(PandaNode('frame_node'))
        self._create_frame(self.frame_node_path, width+background_padding, height+background_padding+letter_height)
        r,g,b = frame_color
        self.set_frame_color(r, g, b)
        self.set_frame_line_width(frame_line_width)
        r,g,b = background_color
        self.set_background_color(r, g, b)
    
    def _compute_max_text_size(self):
        self.text_node.setText(' ')
        width = 0
        while (not self.text_node.getWidth() == width) and self.text_node.getWidth() < self.max_row_length:
            width = self.text_node.getWidth()
            self.text_node.appendText(' ')
        while self.text_node.getNumRows() < self.text_node.getMaxRows():
            self.text_node.appendText('\n') 
        return self.text_node.getWidth(), self.text_node.getHeight()  
    
    def _compute_letter_size(self):
        self.text_node.setText('W')
        return self.text_node.getWidth(), self.text_node.getHeight()
        
    def _create_background(self, root_node_path, width, height):
        node, _vdata = create_side((0,0), (width, -height))
        root_node_path.attachNewNode(node)
        
    def _create_frame(self, root_node_path, width, height):
        # top
        node, _vdata = create_line(0, 0, width, 0)
        root_node_path.attachNewNode(node)
        # right side
        node, _vdata = create_line(width, 0, width, -height)
        root_node_path.attachNewNode(node)
        # bottom side
        node, _vdata = create_line(width, -height, 0, -height)
        root_node_path.attachNewNode(node)
        # right side
        node, _vdata = create_line(0, -height, 0, 0)
        root_node_path.attachNewNode(node)
        
    
    def get_node_path(self):
        return self.root_node_path
    
    def set_scale(self, scale):
        self.root_node_path.setScale(scale)
        
    def set_center_pos_xz(self, x, z):
        self.set_center_pos(x, 0, z)
        
    def set_center_pos(self, x, y, z):
        width, height = get_bounding_width_height(self.get_node_path())
        self.get_node_path().setPos(x-width/2.0, y, z+height/2.0)
        
    def set_text(self, text=''):
        self.text_node.clearText()
        self.text_node.setText(text)
            
    def set_text_color(self, r, g, b, alpha=1):
        self.text_node.setTextColor(r,g,b,alpha)
    
    def set_max_nr_rows(self, n):
        self.text_node.setMaxRows(n)
    
    def set_frame_visible(self, visible):
        rgba = self.frame_node_path.getColor()
        r = rgba[0]
        g = rgba[1]
        b = rgba[2]
        if visible:
            alpha = 1
        else:
            alpha = 0
        self.frame_node_path.setColor(r, g, b, alpha)
        
    def set_frame_color(self, r, g, b, alpha=1):
        self.frame_node_path.setColor(r, g, b, alpha)
        
#.........这里部分代码省略.........
开发者ID:JingLu92,项目名称:pyff,代码行数:103,代码来源:TextBoard.py


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