mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
scale buttons around button center
This commit is contained in:
parent
642e15632a
commit
2cd325216e
@ -47,16 +47,31 @@ class DirectButton(DirectFrame):
|
|||||||
# Initialize superclasses
|
# Initialize superclasses
|
||||||
DirectFrame.__init__(self, parent)
|
DirectFrame.__init__(self, parent)
|
||||||
|
|
||||||
# If specifed, add scaling to the pressed state to make it look
|
# If specifed, add scaling to the pressed state to make it
|
||||||
# like the button is moving when you press it
|
# look like the button is moving when you press it. We have
|
||||||
|
# to set up the node first, before we call initialise options;
|
||||||
|
# but we can't actually apply the scale until we have the
|
||||||
|
# bounding volume (which happens during initialise options).
|
||||||
|
pressEffectNP = None
|
||||||
if self['pressEffect']:
|
if self['pressEffect']:
|
||||||
np = self.stateNodePath[1].attachNewNode('pressEffect', 1)
|
pressEffectNP = self.stateNodePath[1].attachNewNode('pressEffect', 1)
|
||||||
np.setScale(0.98)
|
self.stateNodePath[1] = pressEffectNP
|
||||||
self.stateNodePath[1] = np
|
|
||||||
|
|
||||||
# Call option initialization functions
|
# Call option initialization functions
|
||||||
self.initialiseoptions(DirectButton)
|
self.initialiseoptions(DirectButton)
|
||||||
|
|
||||||
|
# Now apply the scale.
|
||||||
|
if pressEffectNP:
|
||||||
|
bounds = self.getBounds()
|
||||||
|
centerX = (bounds[0] + bounds[1]) / 2
|
||||||
|
centerY = (bounds[2] + bounds[3]) / 2
|
||||||
|
|
||||||
|
# Make a matrix that scales about the point
|
||||||
|
mat = Mat4.translateMat(-centerX, 0, -centerY) * \
|
||||||
|
Mat4.scaleMat(0.98) * \
|
||||||
|
Mat4.translateMat(centerX, 0, centerY)
|
||||||
|
pressEffectNP.setMat(mat)
|
||||||
|
|
||||||
def setCommandButtons(self):
|
def setCommandButtons(self):
|
||||||
# Attach command function to specified buttons
|
# Attach command function to specified buttons
|
||||||
# Left mouse button
|
# Left mouse button
|
||||||
|
Loading…
x
Reference in New Issue
Block a user