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


Python TextNode.setCardActual方法代码示例

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


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

示例1: __init__

# 需要导入模块: from panda3d.core import TextNode [as 别名]
# 或者: from panda3d.core.TextNode import setCardActual [as 别名]
    def __init__(self,
                 horzmargin=0.5,        # horizontal margin in characters
                 vertmargin=1,          # vertical margin in charaters
                 width=30,              # width of the text box in characters
                 height=5,              # height of the text box in lines
                 scale=0.05,            # scaling of the text box
                 pos=(-3.1,-0.6),         # position of the upper-left corner inside the aspect2d viewport
                 font='arial.ttf',      # font to use for the text
                 align='left',          # alignment of the text (can be 'left', 'center', or 'right')
                 textcolor=(1,1,1,1),   # (r,g,b,a) text color
                 framecolor=(0,0,0,1),  # (r,g,b,a) frame color
                 *args,**kwargs
                 ): 
        
        """Construct a new TextPresenter."""
        MessagePresenter.__init__(self,*args,**kwargs)

        if align == 'left':
            align = TextNode.ALeft
        elif align == 'right':
            align = TextNode.ARight
        else:
            align = TextNode.ACenter

        text = TextNode('TextPresenter')
        text.setText('\n')
        font = loader.loadFont(font)
        text.setFont(font)
        text.setAlign(align)
        text.setWordwrap(width)
        text.setTextColor(textcolor[0],textcolor[1],textcolor[2],textcolor[3])
        if framecolor[3] > 0:
            text.setCardColor(framecolor[0],framecolor[1],framecolor[2],framecolor[3])
            text.setCardActual(-horzmargin,width+horzmargin,-(height+vertmargin),vertmargin)
        self.text = text
        self.text_nodepath = aspect2d.attachNewNode(text)
        self.text_nodepath.setScale(scale)        
        self.pos = pos        
        self.textcolor = textcolor
        pos = self.pos
        self.text_nodepath.setPos(pos[0],0,pos[1])
开发者ID:sccn,项目名称:SNAP,代码行数:43,代码来源:TextPresenter.py

示例2: MessageWriter

# 需要导入模块: from panda3d.core import TextNode [as 别名]
# 或者: from panda3d.core.TextNode import setCardActual [as 别名]
class MessageWriter(DirectObject):
    def __init__(self):
        # the tasktime the last sign in the textfield was written
        self.lastSign = 0.0
        # the sign that is actually written in the textfield
        self.currentSign = 0
        # the text to write in the textfield
        self.textfieldText = ""
        # stop will be used to check if the writing is finished or
        # somehow else stoped
        self.stop = False
        # the speed new letters are added to the text
        # the time, how long the text is shown after it is fully written
        self.showlength = 4

        # the textfield to put instructions hints and everything else, that
        # should be slowly written on screen and disappear after a short while
        self.textfield = TextNode('textfield')
        self.textfield.clearText()
        self.textfield.setShadow(0.005, 0.005)
        self.textfield.setShadowColor(0, 0, 0, 1)
        self.textfield.setWordwrap(base.a2dRight*2-0.4)
        self.textfield.setCardActual(
            -0.1, base.a2dRight*2-0.3,
            0.1, base.a2dBottom+0.5)
        self.textfield.setCardColor(0,0,0,0.45)
        self.textfield.setFlattenFlags(TextNode.FF_none)
        self.textfield.setTextScale(0.06)
        self.textfieldNodePath = aspect2d.attachNewNode(self.textfield)
        self.textfieldNodePath.setScale(1)
        self.textfieldNodePath.setPos(base.a2dLeft+0.2, 0, -0.4)

        self.hide()

    def show(self):
        self.textfieldNodePath.show()

    def hide(self):
        self.textfield.clearText()
        self.textfieldNodePath.hide()

    def clear(self):
        """Clear the textfield and stop the current written text"""
        self.hide()
        taskMgr.remove("writeText")
        self.stop = False
        self.writeDone = False
        self.currentSign = 0
        self.lastSign = 0.0
        self.textfield.clearText()

    def cleanup(self):
        """Function that should be called to remove and reset the
        message writer"""
        self.clear()
        self.ignore("showMessage")

    def run(self):
        """This function can be called to start the writer task."""
        self.textfield.setFlattenFlags(TextNode.FF_none)
        taskMgr.add(self.__writeText, "writeText", priority=30)

    def setMessageAndShow(self, message):
        """Function to simply add a new message and show it if no other
        message is currently shown"""
        self.clear()
        logging.debug("show message %s" % message)
        self.textfieldText = message
        self.show()
        # start the writer task
        self.run()

    def __writeText(self, task):
        elapsed = globalClock.getDt()
        if(self.stop):
            # text is finished and can be cleared now
            self.clear()
            return task.done

        if self.currentSign == len(self.textfieldText)-1:
            self.textfield.setFlattenFlags(TextNode.FF_dynamic_merge)

        if self.currentSign >= len(self.textfieldText):
            # check if the text is fully written
            if task.time - self.lastSign >= self.showlength:
                # now also check if the time the text should
                # be visible on screen has elapsed
                self.stop = True
                self.textfieldNodePath.flattenStrong()
        elif (task.time - self.lastSign > base.textWriteSpeed) and (not self.stop):
            # write the next letter of the text
            self.textfield.appendText(self.textfieldText[self.currentSign])
            self.currentSign += 1
            self.lastSign = task.time

        return task.cont
开发者ID:grimfang,项目名称:owp_ajaw,代码行数:98,代码来源:textfield.py


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