mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 12:43:44 -04:00
*** empty log message ***
This commit is contained in:
parent
17fc2fec8a
commit
de6e8fba8c
@ -1,13 +1,18 @@
|
|||||||
from ShowBaseGlobal import *
|
from ShowBaseGlobal import *
|
||||||
from DirectObject import *
|
from DirectObject import *
|
||||||
from GuiGlobals import *
|
from GuiGlobals import *
|
||||||
import GuiLabel
|
|
||||||
import GuiButton
|
import GuiButton
|
||||||
|
import Label
|
||||||
|
|
||||||
|
|
||||||
class Button(DirectObject):
|
class Button(DirectObject):
|
||||||
|
|
||||||
def __init__(self, name, label=None, font=getDefaultFont()):
|
def __init__(self, name,
|
||||||
|
label = None,
|
||||||
|
scale = 0.1,
|
||||||
|
width = None,
|
||||||
|
drawOrder = getDefaultDrawOrder(),
|
||||||
|
font = getDefaultFont()):
|
||||||
self.name = name
|
self.name = name
|
||||||
# if no label given, use the button name
|
# if no label given, use the button name
|
||||||
if (label == None):
|
if (label == None):
|
||||||
@ -17,31 +22,27 @@ class Button(DirectObject):
|
|||||||
if (type(label) == type('')):
|
if (type(label) == type('')):
|
||||||
# text label, make text button
|
# text label, make text button
|
||||||
self.label = label
|
self.label = label
|
||||||
# up
|
|
||||||
self.l1 = GuiLabel.GuiLabel.makeSimpleTextLabel(self.label,
|
self.l1 = Label.textLabel(self.label, Label.ButtonUp,
|
||||||
font)
|
scale, width, drawOrder, font)
|
||||||
self.l1.setForegroundColor(0., 0., 0., 1.)
|
self.l2 = Label.textLabel(self.label, Label.ButtonLit,
|
||||||
self.l1.thaw()
|
scale, width, drawOrder, font)
|
||||||
# roll-over up
|
self.l3 = Label.textLabel(self.label, Label.ButtonDown,
|
||||||
self.l2 = GuiLabel.GuiLabel.makeSimpleTextLabel(self.label,
|
scale, width, drawOrder, font)
|
||||||
font)
|
|
||||||
self.l2.setForegroundColor(0., 0., 0., 1.)
|
elif (isinstance(label, NodePath)):
|
||||||
self.l2.setBackgroundColor(1., 1., 0., 1.)
|
# If it's a NodePath, assume it's a little texture card.
|
||||||
self.l2.thaw()
|
self.l1 = Label.modelLabel(label, 1, 1, scale, drawOrder)
|
||||||
# roll-over down
|
self.l2 = self.l1
|
||||||
self.l3 = GuiLabel.GuiLabel.makeSimpleTextLabel(self.label,
|
self.l3 = self.l1
|
||||||
font)
|
|
||||||
self.l3.setForegroundColor(1., 1., 1., 1.)
|
|
||||||
self.l3.setBackgroundColor(0., 0., 0., 1.)
|
|
||||||
self.l3.thaw()
|
|
||||||
else:
|
else:
|
||||||
# label provided, use it for all labels
|
# label provided, use it for all labels
|
||||||
self.l1 = self.l2 = self.l3 = label
|
self.l1 = self.l2 = self.l3 = label
|
||||||
|
|
||||||
self.button = GuiButton.GuiButton(self.name, self.l1, self.l2,
|
self.button = GuiButton.GuiButton(self.name, self.l1, self.l2,
|
||||||
self.l3, self.l3, self.l1)
|
self.l3, self.l3, self.l1)
|
||||||
|
self.button.setDrawOrder(drawOrder)
|
||||||
self.setScale(0.1)
|
|
||||||
self.managed = 0
|
self.managed = 0
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@ -111,9 +112,3 @@ class Button(DirectObject):
|
|||||||
v3 = Vec3(mat.xformPoint(Point3(x, 0., y)))
|
v3 = Vec3(mat.xformPoint(Point3(x, 0., y)))
|
||||||
|
|
||||||
self.button.setPos(v3)
|
self.button.setPos(v3)
|
||||||
|
|
||||||
def setScale(self, scale):
|
|
||||||
self.button.setScale(scale)
|
|
||||||
|
|
||||||
def setDrawOrder(self, drawOrder):
|
|
||||||
self.button.setDrawOrder(drawOrder)
|
|
||||||
|
@ -7,6 +7,7 @@ guiMgr = GuiManager.GuiManager.getPtr(base.win, base.mak.node(),
|
|||||||
base.render2d.node())
|
base.render2d.node())
|
||||||
|
|
||||||
font = loader.loadModelNode("models/fonts/ttf-comic")
|
font = loader.loadModelNode("models/fonts/ttf-comic")
|
||||||
|
drawOrder = 100
|
||||||
|
|
||||||
def getDefaultFont():
|
def getDefaultFont():
|
||||||
return font
|
return font
|
||||||
@ -15,3 +16,9 @@ def setDefaultFont(newFont):
|
|||||||
global font
|
global font
|
||||||
font = newFont
|
font = newFont
|
||||||
|
|
||||||
|
def getDefaultDrawOrder():
|
||||||
|
return drawOrder
|
||||||
|
|
||||||
|
def setDefaultDrawOrder(newDrawOrder):
|
||||||
|
global drawOrder
|
||||||
|
drawOrder = newDrawOrder
|
||||||
|
130
direct/src/gui/Label.py
Normal file
130
direct/src/gui/Label.py
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
from ShowBaseGlobal import *
|
||||||
|
from DirectObject import *
|
||||||
|
from GuiGlobals import *
|
||||||
|
|
||||||
|
## These are the styles of labels we might commonly see. They control
|
||||||
|
## the way the label looks.
|
||||||
|
|
||||||
|
ButtonUp = 1
|
||||||
|
ButtonLit = 2
|
||||||
|
ButtonDown = 3
|
||||||
|
Sign = 4
|
||||||
|
ScrollTitle = 5
|
||||||
|
ScrollItem = 6
|
||||||
|
|
||||||
|
|
||||||
|
def textLabel(string, style,
|
||||||
|
scale = 0.1,
|
||||||
|
width = None,
|
||||||
|
drawOrder = getDefaultDrawOrder(),
|
||||||
|
font = getDefaultFont()):
|
||||||
|
"""textLabel(string, int style, float scale, float width,
|
||||||
|
int drawOrder, Node font)
|
||||||
|
|
||||||
|
Generates a text label suitable for adding to a GuiButton or
|
||||||
|
GuiSign.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
(label, text) = \
|
||||||
|
textLabelAndText(string, style, scale, width, drawOrder, font)
|
||||||
|
return label
|
||||||
|
|
||||||
|
def textLabelAndText(string, style,
|
||||||
|
scale = 0.1,
|
||||||
|
width = None,
|
||||||
|
drawOrder = getDefaultDrawOrder(),
|
||||||
|
font = getDefaultFont()):
|
||||||
|
"""textLabelAndText(string, int style, float scale, float width,
|
||||||
|
int drawOrder, Node font)
|
||||||
|
|
||||||
|
Generates a text label suitable for adding to a GuiButton or
|
||||||
|
GuiSign.
|
||||||
|
|
||||||
|
This function returns both the label and the TextNode that is
|
||||||
|
within the label, allowing the calling function to update the
|
||||||
|
label's text later. If there are a limited number of text
|
||||||
|
strings, however, it would probably be better to create a separate
|
||||||
|
GuiItem for each possible text string, and rotate them in and out.
|
||||||
|
|
||||||
|
"""
|
||||||
|
text = TextNode()
|
||||||
|
|
||||||
|
# Freeze the text so we can set up its properties.
|
||||||
|
text.freeze()
|
||||||
|
|
||||||
|
text.setFont(font)
|
||||||
|
text.setAlign(TMALIGNCENTER)
|
||||||
|
text.setDrawOrder(drawOrder)
|
||||||
|
text.setTextColor(0.0, 0.0, 0.0, 1.0)
|
||||||
|
text.setCardColor(1.0, 1.0, 1.0, 1.0)
|
||||||
|
text.setCardAsMargin(0.1, 0.1, 0.0, 0.0)
|
||||||
|
text.setTransform(Mat4.scaleMat(scale))
|
||||||
|
|
||||||
|
if style == ButtonUp:
|
||||||
|
# This is the default: black on white.
|
||||||
|
pass
|
||||||
|
|
||||||
|
elif style == ButtonLit:
|
||||||
|
# When the mouse is over the button, the background turns
|
||||||
|
# yellow.
|
||||||
|
text.setCardColor(1.0, 1.0, 0.0, 1.0)
|
||||||
|
|
||||||
|
elif style == ButtonDown:
|
||||||
|
# When the button is being depressed, its turns to white
|
||||||
|
# on black.
|
||||||
|
text.setTextColor(1.0, 1.0, 1.0, 1.0)
|
||||||
|
text.setCardColor(0.0, 0.0, 0.0, 1.0)
|
||||||
|
|
||||||
|
elif style == Sign:
|
||||||
|
# For a sign, we want red text with no background card.
|
||||||
|
text.setTextColor(1., 0., 0., 1.)
|
||||||
|
text.clearCard()
|
||||||
|
|
||||||
|
elif style == ScrollTitle:
|
||||||
|
text.setTextColor(1., 0., 0., 1.)
|
||||||
|
text.setCardColor(1., 1., 1., 0.)
|
||||||
|
|
||||||
|
elif style == ScrollItem:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Don't set the text until the very last thing, so the TextNode
|
||||||
|
# has minimal work to do (even though it's frozen).
|
||||||
|
text.setText(string)
|
||||||
|
|
||||||
|
v = text.getCardActual()
|
||||||
|
|
||||||
|
if width != None:
|
||||||
|
# If the user specified a specific width to use, keep it.
|
||||||
|
v = VBase4(-width / 2.0, width / 2.0, v[2], v[3])
|
||||||
|
if text.hasCard():
|
||||||
|
text.setCardActual(v[0], v[1], v[2], v[3])
|
||||||
|
|
||||||
|
# Now we're completely done setting up the text, and we can safely
|
||||||
|
# thaw it.
|
||||||
|
text.thaw()
|
||||||
|
|
||||||
|
# Now create a GuiLabel containing this text.
|
||||||
|
label = GuiLabel.makeModelLabel(text, v[0] * scale, v[1] * scale,
|
||||||
|
v[2] * scale, v[3] * scale)
|
||||||
|
|
||||||
|
label.setDrawOrder(drawOrder)
|
||||||
|
return (label, text)
|
||||||
|
|
||||||
|
|
||||||
|
def modelLabel(model, height, width,
|
||||||
|
scale = 0.1,
|
||||||
|
drawOrder = getDefaultDrawOrder()):
|
||||||
|
|
||||||
|
# Preserve transitions on the arc by creating an intervening node.
|
||||||
|
topnode = NamedNode('model')
|
||||||
|
top = NodePath(topnode)
|
||||||
|
mi = model.instanceTo(top)
|
||||||
|
mi.setScale(scale)
|
||||||
|
mi.setBin('fixed', drawOrder)
|
||||||
|
|
||||||
|
label = GuiLabel.makeModelLabel(topnode, height * scale, width * scale)
|
||||||
|
label.setDrawOrder(drawOrder)
|
||||||
|
return label
|
||||||
|
|
@ -1,5 +1,6 @@
|
|||||||
"""PickList module: contains the PickList class"""
|
"""PickList module: contains the PickList class"""
|
||||||
from ShowBaseGlobal import *
|
from ShowBaseGlobal import *
|
||||||
|
from GuiGlobals import *
|
||||||
import PandaObject
|
import PandaObject
|
||||||
import Frame
|
import Frame
|
||||||
import Button
|
import Button
|
||||||
@ -11,7 +12,11 @@ class PickList(PandaObject.PandaObject):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# special methods
|
# special methods
|
||||||
def __init__(self, name, choiceList):
|
def __init__(self, name, choiceList,
|
||||||
|
scale = 0.1,
|
||||||
|
width = None,
|
||||||
|
drawOrder = getDefaultDrawOrder(),
|
||||||
|
font = getDefaultFont()):
|
||||||
|
|
||||||
#print "In pick list init: t = %.3f" % clock.getRealTime()
|
#print "In pick list init: t = %.3f" % clock.getRealTime()
|
||||||
|
|
||||||
@ -25,7 +30,7 @@ class PickList(PandaObject.PandaObject):
|
|||||||
self.frame.setOffset(0.015)
|
self.frame.setOffset(0.015)
|
||||||
|
|
||||||
# display the menu
|
# display the menu
|
||||||
self.__displayChoices(choiceList)
|
self.__displayChoices(choiceList, scale, width, drawOrder, font)
|
||||||
self.isClean = 0
|
self.isClean = 0
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -62,13 +67,28 @@ class PickList(PandaObject.PandaObject):
|
|||||||
self.eventName = eventName
|
self.eventName = eventName
|
||||||
|
|
||||||
# actions
|
# actions
|
||||||
def __displayChoices(self, choiceList):
|
def __displayChoices(self, choiceList,
|
||||||
|
scale, width, drawOrder, font):
|
||||||
"""__displayChoices(self, string[])
|
"""__displayChoices(self, string[])
|
||||||
Display the list of choices
|
Display the list of choices
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if width == None:
|
||||||
|
# First, compute the maximum width of the buttons. We do this
|
||||||
|
# ahead of time so the Gui code doesn't have to do it and take
|
||||||
|
# forever about it.
|
||||||
|
width = 0
|
||||||
|
text = TextNode()
|
||||||
|
text.setFont(font)
|
||||||
|
for choice in choiceList:
|
||||||
|
w = text.calcWidth(choice) + 0.2
|
||||||
|
width = max(width, w)
|
||||||
|
|
||||||
|
# Now create all the buttons.
|
||||||
for choice in choiceList:
|
for choice in choiceList:
|
||||||
# create a button for each choice
|
# create a button for each choice
|
||||||
button = Button.Button(choice)
|
button = Button.Button(choice, scale = scale, width = width,
|
||||||
|
drawOrder = drawOrder, font = font)
|
||||||
#print "done with button cons: t = %.3f" % clock.getRealTime()
|
#print "done with button cons: t = %.3f" % clock.getRealTime()
|
||||||
choiceIndex = choiceList.index(choice)
|
choiceIndex = choiceList.index(choice)
|
||||||
# set the rollover-up event
|
# set the rollover-up event
|
||||||
@ -88,7 +108,6 @@ class PickList(PandaObject.PandaObject):
|
|||||||
self.choiceList.append(button)
|
self.choiceList.append(button)
|
||||||
|
|
||||||
# set up the frame
|
# set up the frame
|
||||||
self.frame.makeWideAsWidest()
|
|
||||||
self.frame.makeVertical()
|
self.frame.makeVertical()
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
@ -6,13 +6,19 @@ import GuiFrame
|
|||||||
import Button
|
import Button
|
||||||
import GuiLabel
|
import GuiLabel
|
||||||
import Sign
|
import Sign
|
||||||
|
import Label
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ScrollingLabel(PandaObject.PandaObject):
|
class ScrollingLabel(PandaObject.PandaObject):
|
||||||
|
|
||||||
# special methods
|
# special methods
|
||||||
def __init__(self, name, itemList, font=getDefaultFont()):
|
def __init__(self, name, itemList,
|
||||||
|
label = None,
|
||||||
|
scale = 0.1,
|
||||||
|
width = None,
|
||||||
|
drawOrder = getDefaultDrawOrder(),
|
||||||
|
font = getDefaultFont()):
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.eventName = self.name
|
self.eventName = self.name
|
||||||
@ -22,24 +28,22 @@ class ScrollingLabel(PandaObject.PandaObject):
|
|||||||
self.items = itemList
|
self.items = itemList
|
||||||
self.keyFocus = 1
|
self.keyFocus = 1
|
||||||
|
|
||||||
|
if width == None:
|
||||||
|
# Compute the maximum width of the all the items.
|
||||||
|
width = 0
|
||||||
|
text = TextNode()
|
||||||
|
text.setFont(font)
|
||||||
|
for item in itemList:
|
||||||
|
w = text.calcWidth(item) + 0.2
|
||||||
|
width = max(width, w)
|
||||||
|
|
||||||
# create the new title
|
# create the new title
|
||||||
label = GuiLabel.GuiLabel.makeSimpleTextLabel(self.name, font)
|
self.title = Sign.Sign(self.name, self.name, Label.ScrollTitle,
|
||||||
label.setForegroundColor(1., 0., 0., 1.)
|
scale, width, drawOrder, font)
|
||||||
label.setBackgroundColor(1., 1., 1., 0.)
|
|
||||||
label.thaw()
|
|
||||||
self.title = Sign.Sign(self.name, label)
|
|
||||||
self.frame.addItem(self.title)
|
self.frame.addItem(self.title)
|
||||||
|
|
||||||
longest = self.items[0]
|
self.itemSign = Sign.Sign('item', '', Label.ScrollItem,
|
||||||
for item in self.items:
|
scale, width, drawOrder, font)
|
||||||
if len(item) > len(longest):
|
|
||||||
longest = item
|
|
||||||
|
|
||||||
label = GuiLabel.GuiLabel.makeSimpleTextLabel(longest, font)
|
|
||||||
label.setForegroundColor(0., 0., 0., 1.)
|
|
||||||
label.setBackgroundColor(1., 1., 1., 1.)
|
|
||||||
label.thaw()
|
|
||||||
self.itemSign = Sign.Sign(longest, label)
|
|
||||||
self.frame.addItem(self.itemSign)
|
self.frame.addItem(self.itemSign)
|
||||||
|
|
||||||
# pack the first label under the name
|
# pack the first label under the name
|
||||||
@ -48,11 +52,9 @@ class ScrollingLabel(PandaObject.PandaObject):
|
|||||||
self.frame.packItem(self.itemSign, GuiFrame.GuiFrame.ALIGNLEFT,
|
self.frame.packItem(self.itemSign, GuiFrame.GuiFrame.ALIGNLEFT,
|
||||||
self.title)
|
self.title)
|
||||||
|
|
||||||
# make the title and label the same length
|
|
||||||
self.frame.makeWideAsWidest()
|
|
||||||
|
|
||||||
# create the scroll buttons
|
# create the scroll buttons
|
||||||
self.leftButton = Button.Button(self.eventName + "-left", " < ")
|
self.leftButton = Button.Button(self.eventName + "-left", " < ",
|
||||||
|
scale, None, drawOrder, font)
|
||||||
self.leftButton.getGuiItem().setDownRolloverEvent(self.eventName + "-left")
|
self.leftButton.getGuiItem().setDownRolloverEvent(self.eventName + "-left")
|
||||||
self.leftButton.getGuiItem().setUpRolloverEvent(self.eventName + "-rollover")
|
self.leftButton.getGuiItem().setUpRolloverEvent(self.eventName + "-rollover")
|
||||||
self.frame.addItem(self.leftButton)
|
self.frame.addItem(self.leftButton)
|
||||||
@ -60,7 +62,8 @@ class ScrollingLabel(PandaObject.PandaObject):
|
|||||||
self.title)
|
self.title)
|
||||||
self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.LEFT,
|
self.frame.packItem(self.leftButton, GuiFrame.GuiFrame.LEFT,
|
||||||
self.title)
|
self.title)
|
||||||
self.rightButton = Button.Button(self.eventName + "-right", " > ")
|
self.rightButton = Button.Button(self.eventName + "-right", " > ",
|
||||||
|
scale, None, drawOrder, font)
|
||||||
self.rightButton.getGuiItem().setDownRolloverEvent(self.eventName +
|
self.rightButton.getGuiItem().setDownRolloverEvent(self.eventName +
|
||||||
"-right")
|
"-right")
|
||||||
self.rightButton.getGuiItem().setUpRolloverEvent(self.eventName + "-rollover")
|
self.rightButton.getGuiItem().setUpRolloverEvent(self.eventName + "-rollover")
|
||||||
|
@ -3,26 +3,31 @@ from DirectObject import *
|
|||||||
from GuiGlobals import *
|
from GuiGlobals import *
|
||||||
import GuiSign
|
import GuiSign
|
||||||
import GuiLabel
|
import GuiLabel
|
||||||
|
import Label
|
||||||
|
|
||||||
class Sign(DirectObject):
|
class Sign(DirectObject):
|
||||||
|
|
||||||
def __init__(self, name, label=None, font=getDefaultFont()):
|
def __init__(self, name,
|
||||||
|
label = None,
|
||||||
|
style = Label.Sign,
|
||||||
|
scale = 0.1,
|
||||||
|
width = None,
|
||||||
|
drawOrder = getDefaultDrawOrder(),
|
||||||
|
font = getDefaultFont()):
|
||||||
self.name = name
|
self.name = name
|
||||||
# label in this case means GuiLabel
|
self.labelText = None
|
||||||
|
|
||||||
if not label:
|
if not label:
|
||||||
self.label = GuiLabel.GuiLabel.makeSimpleTextLabel(self.name, font)
|
label = self.name
|
||||||
self.label.setForegroundColor(1., 0., 0., 1.)
|
|
||||||
self.label.setBackgroundColor(1., 1., 1., 0.)
|
if (type(label) == type('')):
|
||||||
self.label.thaw()
|
(self.label, self.labelText) = \
|
||||||
elif (type(label) == type('')):
|
Label.textLabelAndText(label, style,
|
||||||
self.label = GuiLabel.GuiLabel.makeSimpleTextLabel(label, font)
|
scale, width, drawOrder, font)
|
||||||
self.label.setForegroundColor(1., 0., 0., 1.)
|
|
||||||
self.label.setBackgroundColor(1., 1., 1., 0.)
|
|
||||||
self.label.thaw()
|
|
||||||
else:
|
else:
|
||||||
self.label = label
|
self.label = label
|
||||||
|
|
||||||
self.sign = GuiSign.GuiSign(self.name, self.label)
|
self.sign = GuiSign.GuiSign(self.name, self.label)
|
||||||
self.setScale(0.1)
|
|
||||||
self.managed = 0
|
self.managed = 0
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -35,14 +40,14 @@ class Sign(DirectObject):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "sign: %s contains label: %s" % (self.name, self.label.name)
|
return "sign: %s contains label: %s" % (self.name, self.label)
|
||||||
|
|
||||||
# accessing
|
# accessing
|
||||||
def getName(self):
|
def getName(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def setText(self, text):
|
def setText(self, text):
|
||||||
self.label.setText(text)
|
self.labelText.setText(text)
|
||||||
|
|
||||||
def getLabel(self):
|
def getLabel(self):
|
||||||
return self.label
|
return self.label
|
||||||
@ -51,20 +56,14 @@ class Sign(DirectObject):
|
|||||||
return self.sign
|
return self.sign
|
||||||
|
|
||||||
def getPos(self):
|
def getPos(self):
|
||||||
self.label.getPos()
|
self.sign.getPos()
|
||||||
|
|
||||||
def setPos(self, x, y):
|
def setPos(self, x, y):
|
||||||
self.label.setPos(x, 0, y)
|
self.sign.setPos(Vec3(x, 0, y))
|
||||||
|
|
||||||
def setScale(self, scale):
|
|
||||||
self.sign.setScale(scale)
|
|
||||||
|
|
||||||
def getWidth(self):
|
def getWidth(self):
|
||||||
return self.label.getWidth()
|
return self.label.getWidth()
|
||||||
|
|
||||||
def setWidth(self, width):
|
|
||||||
self.label.setWidth(width)
|
|
||||||
|
|
||||||
# actions
|
# actions
|
||||||
def manage(self, nodepath = aspect2d):
|
def manage(self, nodepath = aspect2d):
|
||||||
if nodepath:
|
if nodepath:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user