mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
generalize image parameter
This commit is contained in:
parent
22416d34c5
commit
a4d06505c2
@ -123,9 +123,9 @@ class DirectFrame(DirectGuiWidget):
|
|||||||
if arg == None:
|
if arg == None:
|
||||||
# Passed in None
|
# Passed in None
|
||||||
imageList = (None,) * self['numStates']
|
imageList = (None,) * self['numStates']
|
||||||
elif isinstance(arg, NodePath):
|
elif isinstance(arg, NodePath) or \
|
||||||
imageList = (arg,) * self['numStates']
|
isinstance(arg, Texture) or \
|
||||||
elif isinstance(arg, types.StringTypes):
|
isinstance(arg, types.StringTypes):
|
||||||
# Passed in a single node path, make a tuple out of it
|
# Passed in a single node path, make a tuple out of it
|
||||||
imageList = (arg,) * self['numStates']
|
imageList = (arg,) * self['numStates']
|
||||||
else:
|
else:
|
||||||
|
@ -40,34 +40,10 @@ class OnscreenImage(PandaObject, NodePath):
|
|||||||
"""
|
"""
|
||||||
# We ARE a node path. Initially, we're an empty node path.
|
# We ARE a node path. Initially, we're an empty node path.
|
||||||
NodePath.__init__(self)
|
NodePath.__init__(self)
|
||||||
|
|
||||||
if parent == None:
|
if parent == None:
|
||||||
parent = aspect2d
|
parent = aspect2d
|
||||||
# Assign geometry
|
self.setImage(image, parent = parent, sort = sort)
|
||||||
self.sort = sort
|
|
||||||
if isinstance(image, NodePath):
|
|
||||||
self.assign(image.copyTo(parent, sort))
|
|
||||||
elif type(image) == type(''):
|
|
||||||
# Assume its a file name and create a texture card
|
|
||||||
tex = loader.loadTexture(image)
|
|
||||||
cm = CardMaker('OnscreenImage')
|
|
||||||
cm.setFrame(-1, 1, -1, 1)
|
|
||||||
self.assign(parent.attachNewNode(cm.generate(), sort))
|
|
||||||
self.setTexture(tex)
|
|
||||||
elif type(image) == type(()):
|
|
||||||
# Assume its a file+node name, extract texture from node
|
|
||||||
model = loader.loadModelOnce(image[0])
|
|
||||||
if model:
|
|
||||||
node = model.find(image[1])
|
|
||||||
if node:
|
|
||||||
#print 'assigning'
|
|
||||||
self.assign(node.copyTo(parent, sort))
|
|
||||||
else:
|
|
||||||
print 'OnscreenImage: node %s not found' % image[1]
|
|
||||||
return
|
|
||||||
model.removeNode()
|
|
||||||
else:
|
|
||||||
print 'OnscreenImage: model %s not found' % image[0]
|
|
||||||
return
|
|
||||||
|
|
||||||
# Adjust pose
|
# Adjust pose
|
||||||
# Set pos
|
# Set pos
|
||||||
@ -97,24 +73,48 @@ class OnscreenImage(PandaObject, NodePath):
|
|||||||
# Set color, if specified
|
# Set color, if specified
|
||||||
self.setColor(color[0], color[1], color[2], color[3])
|
self.setColor(color[0], color[1], color[2], color[3])
|
||||||
|
|
||||||
def setImage(self, image):
|
def setImage(self, image,
|
||||||
parent = self.getParent()
|
parent = NodePath(),
|
||||||
# Assign geometry
|
transform = TransformState.makeIdentity(),
|
||||||
|
sort = 0):
|
||||||
|
# Get the original parent, transform, and sort, if any, so we can
|
||||||
|
# preserve them across this call.
|
||||||
|
if not self.isEmpty():
|
||||||
|
parent = self.getParent()
|
||||||
|
transform = self.getTransform()
|
||||||
|
sort = self.getSort()
|
||||||
|
|
||||||
self.removeNode()
|
self.removeNode()
|
||||||
|
|
||||||
|
# Assign geometry
|
||||||
if isinstance(image, NodePath):
|
if isinstance(image, NodePath):
|
||||||
self.assign(image.copyTo(parent))
|
self.assign(image.copyTo(parent, sort))
|
||||||
elif type(image) == type(''):
|
elif isinstance(image, types.StringTypes) or \
|
||||||
# Assume its a file name and create a texture card
|
isinstance(image, Texture):
|
||||||
tex = loader.loadTexture(image)
|
if isinstance(image, Texture):
|
||||||
|
# It's a Texture
|
||||||
|
tex = image
|
||||||
|
else:
|
||||||
|
# It's a Texture file name
|
||||||
|
tex = loader.loadTexture(image)
|
||||||
cm = CardMaker('OnscreenImage')
|
cm = CardMaker('OnscreenImage')
|
||||||
cm.setFrame(-1, 1, -1, 1)
|
cm.setFrame(-1, 1, -1, 1)
|
||||||
self.assign(parent.attachNewNode(cm.generate(), self.sort))
|
self.assign(parent.attachNewNode(cm.generate(), sort))
|
||||||
self.setTexture(tex)
|
self.setTexture(tex)
|
||||||
elif type(image) == type(()):
|
elif type(image) == type(()):
|
||||||
|
# Assume its a file+node name, extract texture from node
|
||||||
model = loader.loadModelOnce(image[0])
|
model = loader.loadModelOnce(image[0])
|
||||||
self.assign(model.find(image[1]))
|
if model:
|
||||||
self.reparentTo(parent)
|
node = model.find(image[1])
|
||||||
model.removeNode()
|
if node:
|
||||||
|
self.assign(node.copyTo(parent, sort))
|
||||||
|
else:
|
||||||
|
print 'OnscreenImage: node %s not found' % image[1]
|
||||||
|
else:
|
||||||
|
print 'OnscreenImage: model %s not found' % image[0]
|
||||||
|
|
||||||
|
if not self.isEmpty():
|
||||||
|
self.setTransform(transform)
|
||||||
|
|
||||||
def getImage(self):
|
def getImage(self):
|
||||||
return self
|
return self
|
||||||
|
Loading…
x
Reference in New Issue
Block a user