本文整理汇总了Python中panda3d.core.TextNode.calcWidth方法的典型用法代码示例。如果您正苦于以下问题:Python TextNode.calcWidth方法的具体用法?Python TextNode.calcWidth怎么用?Python TextNode.calcWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.TextNode
的用法示例。
在下文中一共展示了TextNode.calcWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WhisperPopup
# 需要导入模块: from panda3d.core import TextNode [as 别名]
# 或者: from panda3d.core.TextNode import calcWidth [as 别名]
#.........这里部分代码省略.........
def applyClickState(self, clickState):
if self.chatBalloon is not None:
foreground, background = self.whisperColor[clickState]
self.chatBalloon.setForeground(foreground)
self.chatBalloon.setBackground(background)
def setClickState(self, clickState):
if self.isClickable():
self.applyClickState(clickState)
else:
self.applyClickState(PGButton.SInactive)
if self.isHovering() or self.quitButton.isHovering():
self.quitButton.contents.show()
elif self.quitButton.getClickState() == PGButton.SDepressed:
self.quitButton.contents.show()
else:
self.quitButton.contents.hide()
Clickable2d.setClickState(self, clickState)
def enterDepressed(self):
if self.isClickable():
base.playSfx(NametagGlobals.clickSound)
def enterRollover(self):
if self.isClickable() and (self.lastClickState != PGButton.SDepressed):
base.playSfx(NametagGlobals.rolloverSound)
def updateClickRegion(self):
if self.chatBalloon is not None:
right = self.chatBalloon.width / 2.0
left = -right
top = self.chatBalloon.height / 2.0
bottom = -top
self.setClickRegionFrame(left, right, bottom, top)
self.region.setActive(True)
else:
if self.region is not None:
self.region.setActive(False)
if self.quitButton is not None:
self.quitButton.updateClickRegion()
def marginVisibilityChanged(self):
if self.cell is not None:
# We're in the margin display. Reposition our content, and update
# the click region:
self.reposition()
self.updateClickRegion()
else:
# We aren't in the margin display. Disable the click region if one
# is present:
if self.region is not None:
self.region.setActive(False)
def reposition(self):
if self.contents is None:
return
origin = Point3()
self.contents.setPos(origin)
if self.chatBalloon is not None:
self.chatBalloon.removeNode()
self.chatBalloon = None
if self.quitButton is not None:
self.quitButton.destroy()
self.quitButton = None
self.contents.node().removeAllChildren()
if (self.cell in base.leftCells) or (self.cell in base.rightCells):
text = self.text.replace('\x01WLDisplay\x01', '').replace('\x02', '')
textWidth = self.textNode.calcWidth(text)
if (textWidth / self.TEXT_WORD_WRAP) > self.TEXT_MAX_ROWS:
self.textNode.setWordwrap(textWidth / (self.TEXT_MAX_ROWS-0.5))
else:
self.textNode.setWordwrap(self.TEXT_WORD_WRAP)
self.draw()
left, right, bottom, top = self.textNode.getFrameActual()
if self.cell in base.bottomCells:
# Move the origin to the bottom center of the chat balloon:
origin = self.contents.getRelativePoint(
self.chatBalloon.textNodePath, ((left+right) / 2.0, 0, bottom))
elif self.cell in base.leftCells:
# Move the origin to the left center of the chat balloon:
origin = self.contents.getRelativePoint(
self.chatBalloon.textNodePath, (left, 0, (bottom+top) / 2.0))
elif self.cell in base.rightCells:
# Move the origin to the right center of the chat balloon:
origin = self.contents.getRelativePoint(
self.chatBalloon.textNodePath, (right, 0, (bottom+top) / 2.0))
self.contents.setPos(self.contents, -origin)