class TextHistoryLabel(NodePath): def __init__(self, text, speaker = None, voiceName = None, parent = None, height = 0): #TODO add a voice button in it NodePath.__init__(self,'texthistorylabel') self.parent = parent or aspect2d self.reparentTo(parent) if speaker: text = '\1th_name\1(' + speaker.strip() + ')\n\2' + text self.textcontent = OnscreenText(text = text,align = TextNode.ALeft, pos = (TEXTLEFT,-height), wordwrap = WORDWRAP, parent = self, **base.getStyle('historytext')) self.labelHeight = self.textcontent.textNode.getHeight() * self.textcontent.getScale()[1] def destroy(self): self.textcontent.destroy() self.removeNode() def getLabelHeight(self): return self.labelHeight
def __init__(self): ShowBase.__init__(self) font = loader.loadFont("cmr12.egg") props = TextProperties() props.setTextColor(1, 1, 0, 0.5) tp = TextPropertiesManager.getGlobalPtr() tp.setProperties("yellow", props) OnscreenText(text = "Panda3D Rocks!!", frame = Vec4(1, 0, 0, 1), bg = Vec4(1, 1, 0, 1), pos = Vec2(-0.5, 0.5), scale = 0.2, font = font) wrapWidth = 6 text = OnscreenText(text = "So long... \1yellow\1And thanks for all the bamboo\2!!", wordwrap = wrapWidth, fg = Vec4(1, 1, 1, 1), shadow = Vec4(0, 0, 0, 1), scale = 0.07, font = font) wrap = text.getScale()[0] * wrapWidth print "Word wrap after", wrap, "screen units"
def test_onscreentext_node_scale(): text = OnscreenText() text.set_scale(1, 2, 3) assert text['scale'] == (0.07, 0.07) assert text.scale == (0.07, 0.07) assert text.getScale() == (0.07, 0.07) assert text.text_scale == (0.07, 0.07) assert text.getTextScale() == (0.07, 0.07) assert text.get_scale() == (1, 2, 3)
def sign_cb(parent): text = '\n\n'.join(ThanksNames.get_thanks(3, 4)) txt = OnscreenText(text, parent=parent, scale=.2, fg=(0, 0, 0, 1), pos=(.245, 0)) bounds = lambda: txt.get_tight_bounds() while bounds()[1].x - bounds()[0].x > .48: scale = txt.getScale()[0] # NB getScale is OnscreenText's meth; it doesn't have swizzle txt.setScale(scale - .01, scale - .01) bounds = txt.get_tight_bounds() height = bounds[1].z - bounds[0].z txt.set_z(.06 + height / 2)
def sign_cb(parent): text = '\n\n'.join(ThanksNames.get_thanks(3, 4)) txt = OnscreenText(text, parent=parent, scale=.2, fg=(0, 0, 0, 1), pos=(.245, 0)) bounds = lambda: txt.get_tight_bounds() while bounds()[1].x - bounds()[0].x > .48: scale = txt.getScale()[0] # NB getScale is OnscreenText's meth; it doesn't have swizzle txt.setScale(scale - .01, scale - .01) bounds = txt.get_tight_bounds() height = bounds[1].z - bounds[0].z txt.set_z(.06 + height / 2)
def __init__(self): ShowBase.__init__(self) font = loader.loadFont("simsun.ttc") props = TextProperties() props.setTextColor(1, 1, 0, 0.5) tp = TextPropertiesManager.getGlobalPtr() tp.setProperties("yellow", props) OnscreenText(text = "Panda3D Rocks!!中文", frame = Vec4(1, 0, 0, 1), bg = Vec4(1, 1, 0, 1), pos = Vec2(-0.5, 0.5), scale = 0.2, font = font) wrapWidth = 6 text = OnscreenText(text = "So long... \1yellow\1And thanks for all the bamboo\2!!", wordwrap = wrapWidth, fg = Vec4(1,1,1,1), shadow = Vec4(0,0,0,1), scale = 0.07, font = font) wrap = text.getScale()[0] * wrapWidth print "Word wrap after", wrap, "screen units"
def sign_cb(parent): thanks = open(eng.curr_path + 'assets/thanks.txt').readlines() shuffle(thanks) text = '\n\n'.join(thanks[:3]) txt = OnscreenText(text, parent=parent, scale=.2, fg=(0, 0, 0, 1), pos=(.245, 0)) bounds = lambda: txt.getTightBounds() while bounds()[1][0] - bounds()[0][0] > .48: scale = txt.getScale()[0] txt.setScale(scale - .01, scale - .01) bounds = txt.getTightBounds() height = bounds[1][2] - bounds[0][2] txt.setZ(.06 + height / 2)
def test_onscreentext_text_scale(): text = OnscreenText(scale=(1, 2)) assert text['scale'] == (1, 2) assert text.scale == (1, 2) assert text.getScale() == (1, 2) assert text.text_scale == (1, 2) assert text.getTextScale() == (1, 2) assert text.get_scale() == (1, 1, 1) text.setTextScale(3, 4) assert text['scale'] == (3, 4) assert text.scale == (3, 4) assert text.getScale() == (3, 4) assert text.text_scale == (3, 4) assert text.getTextScale() == (3, 4) assert text.get_scale() == (1, 1, 1) text.text_scale = (7, 8) assert text['scale'] == (7, 8) assert text.scale == (7, 8) assert text.getScale() == (7, 8) assert text.text_scale == (7, 8) assert text.getTextScale() == (7, 8) assert text.get_scale() == (1, 1, 1) text.setScale(9, 10) assert text['scale'] == (9, 10) assert text.scale == (9, 10) assert text.getScale() == (9, 10) assert text.text_scale == (9, 10) assert text.getTextScale() == (9, 10) assert text.get_scale() == (1, 1, 1) text['scale'] = (11, 12) assert text['scale'] == (11, 12) assert text.scale == (11, 12) assert text.getScale() == (11, 12) assert text.text_scale == (11, 12) assert text.getTextScale() == (11, 12) assert text.get_scale() == (1, 1, 1) text.scale = 13 assert text['scale'] == (13, 13) assert text.scale == (13, 13) assert text.getScale() == (13, 13) assert text.text_scale == (13, 13) assert text.getTextScale() == (13, 13) assert text.get_scale() == (1, 1, 1)