本文整理汇总了Python中pandac.PandaModules.TextNode.clearText方法的典型用法代码示例。如果您正苦于以下问题:Python TextNode.clearText方法的具体用法?Python TextNode.clearText怎么用?Python TextNode.clearText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandac.PandaModules.TextNode
的用法示例。
在下文中一共展示了TextNode.clearText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tooltip
# 需要导入模块: from pandac.PandaModules import TextNode [as 别名]
# 或者: from pandac.PandaModules.TextNode import clearText [as 别名]
class Tooltip(object):
'''
classdocs
'''
def __init__(self, ywn):
'''
Constructor
'''
self.ywn = ywn
self.tooltip = TextNode('Tooltip')
self.tooltip.setText("Every day in every way I'm getting better and better.")
self.tooltip.setTextColor(1, 0.5, 0.5, 1)
self.tooltip.setShadow(0.05, 0.05)
self.tooltip.setShadowColor(0, 0, 0, 1)
self.tooltipNodePath = self.ywn.aspect2d.attachNewNode(self.tooltip)
self.tooltipNodePath.setScale(0.07)
self.tooltipNodePath.setPos(-1,0,0.9)
self.ywn.taskMgr.add(self.taskMouseTooltip, 'taskMouseToolip')
def setText(self, text):
self.tooltip.setText(text)
def clearText(self):
self.tooltip.clearText()
def taskMouseTooltip(self, task):
self.tooltipNodePath.setPos(self.ywn.mouseWatcher.currentPosition.x * self.ywn.getAspectRatio(), 0, self.ywn.mouseWatcher.currentPosition.y)
return task.cont
示例2: TextBoard
# 需要导入模块: from pandac.PandaModules import TextNode [as 别名]
# 或者: from pandac.PandaModules.TextNode import clearText [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)
#.........这里部分代码省略.........