add base.adjustWindowAspectRatio()

This commit is contained in:
David Rose 2012-01-17 05:39:25 +00:00
parent 2e3667e7d4
commit 17f27744a9

View File

@ -2626,73 +2626,7 @@ class ShowBase(DirectObject.DirectObject):
# If we have not forced the aspect ratio, let's see if it has
# changed and update the camera lenses and aspect2d parameters
if not self.__configAspectRatio:
aspectRatio = self.getAspectRatio()
if aspectRatio != self.__oldAspectRatio:
self.__oldAspectRatio = aspectRatio
# Fix up some anything that depends on the aspectRatio
self.camLens.setAspectRatio(aspectRatio)
if aspectRatio < 1:
# If the window is TALL, lets expand the top and bottom
self.aspect2d.setScale(1.0, 1.0, aspectRatio)
self.a2dTop = 1.0 / aspectRatio
self.a2dBottom = - 1.0 / aspectRatio
self.a2dLeft = -1
self.a2dRight = 1.0
# Don't forget 2dp
self.aspect2dp.setScale(1.0, 1.0, aspectRatio)
self.a2dpTop = 1.0 / aspectRatio
self.a2dpBottom = - 1.0 / aspectRatio
self.a2dpLeft = -1
self.a2dpRight = 1.0
else:
# If the window is WIDE, lets expand the left and right
self.aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0)
self.a2dTop = 1.0
self.a2dBottom = -1.0
self.a2dLeft = -aspectRatio
self.a2dRight = aspectRatio
# Don't forget 2dp
self.aspect2dp.setScale(1.0 / aspectRatio, 1.0, 1.0)
self.a2dpTop = 1.0
self.a2dpBottom = -1.0
self.a2dpLeft = -aspectRatio
self.a2dpRight = aspectRatio
# Reposition the aspect2d marker nodes
self.a2dTopCenter.setPos(0, 0, self.a2dTop)
self.a2dBottomCenter.setPos(0, 0, self.a2dBottom)
self.a2dLeftCenter.setPos(self.a2dLeft, 0, 0)
self.a2dRightCenter.setPos(self.a2dRight, 0, 0)
self.a2dTopLeft.setPos(self.a2dLeft, 0, self.a2dTop)
self.a2dTopRight.setPos(self.a2dRight, 0, self.a2dTop)
self.a2dBottomLeft.setPos(self.a2dLeft, 0, self.a2dBottom)
self.a2dBottomRight.setPos(self.a2dRight, 0, self.a2dBottom)
# Reposition the aspect2d marker nodes
self.a2dTopCenterNs.setPos(0, 0, self.a2dTop)
self.a2dBottomCenterNs.setPos(0, 0, self.a2dBottom)
self.a2dLeftCenterNs.setPos(self.a2dLeft, 0, 0)
self.a2dRightCenterNs.setPos(self.a2dRight, 0, 0)
self.a2dTopLeftNs.setPos(self.a2dLeft, 0, self.a2dTop)
self.a2dTopRightNs.setPos(self.a2dRight, 0, self.a2dTop)
self.a2dBottomLeftNs.setPos(self.a2dLeft, 0, self.a2dBottom)
self.a2dBottomRightNs.setPos(self.a2dRight, 0, self.a2dBottom)
# Reposition the aspect2dp marker nodes
self.a2dpTopCenter.setPos(0, 0, self.a2dpTop)
self.a2dpBottomCenter.setPos(0, 0, self.a2dpBottom)
self.a2dpLeftCenter.setPos(self.a2dpLeft, 0, 0)
self.a2dpRightCenter.setPos(self.a2dpRight, 0, 0)
self.a2dpTopLeft.setPos(self.a2dpLeft, 0, self.a2dpTop)
self.a2dpTopRight.setPos(self.a2dpRight, 0, self.a2dpTop)
self.a2dpBottomLeft.setPos(self.a2dpLeft, 0, self.a2dpBottom)
self.a2dpBottomRight.setPos(self.a2dpRight, 0, self.a2dpBottom)
# If anybody needs to update their GUI, put a callback on this event
messenger.send("aspectRatioChanged")
self.adjustWindowAspectRatio(self.getAspectRatio())
# Temporary hasattr for old Pandas
if not hasattr(win, 'getSbsLeftXSize'):
@ -2702,6 +2636,78 @@ class ShowBase(DirectObject.DirectObject):
self.pixel2d.setScale(2.0 / win.getSbsLeftXSize(), 1.0, 2.0 / win.getSbsLeftYSize())
self.pixel2dp.setScale(2.0 / win.getSbsLeftXSize(), 1.0, 2.0 / win.getSbsLeftYSize())
def adjustWindowAspectRatio(self, aspectRatio):
""" This function is normally called internally by
windowEvent(), but it may also be called to explicitly adjust
the aspect ratio of the render/render2d DisplayRegion, by a
class that has redefined these. """
if not self.__configAspectRatio:
if aspectRatio != self.__oldAspectRatio:
self.__oldAspectRatio = aspectRatio
# Fix up some anything that depends on the aspectRatio
self.camLens.setAspectRatio(aspectRatio)
if aspectRatio < 1:
# If the window is TALL, lets expand the top and bottom
self.aspect2d.setScale(1.0, 1.0, aspectRatio)
self.a2dTop = 1.0 / aspectRatio
self.a2dBottom = - 1.0 / aspectRatio
self.a2dLeft = -1
self.a2dRight = 1.0
# Don't forget 2dp
self.aspect2dp.setScale(1.0, 1.0, aspectRatio)
self.a2dpTop = 1.0 / aspectRatio
self.a2dpBottom = - 1.0 / aspectRatio
self.a2dpLeft = -1
self.a2dpRight = 1.0
else:
# If the window is WIDE, lets expand the left and right
self.aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0)
self.a2dTop = 1.0
self.a2dBottom = -1.0
self.a2dLeft = -aspectRatio
self.a2dRight = aspectRatio
# Don't forget 2dp
self.aspect2dp.setScale(1.0 / aspectRatio, 1.0, 1.0)
self.a2dpTop = 1.0
self.a2dpBottom = -1.0
self.a2dpLeft = -aspectRatio
self.a2dpRight = aspectRatio
# Reposition the aspect2d marker nodes
self.a2dTopCenter.setPos(0, 0, self.a2dTop)
self.a2dBottomCenter.setPos(0, 0, self.a2dBottom)
self.a2dLeftCenter.setPos(self.a2dLeft, 0, 0)
self.a2dRightCenter.setPos(self.a2dRight, 0, 0)
self.a2dTopLeft.setPos(self.a2dLeft, 0, self.a2dTop)
self.a2dTopRight.setPos(self.a2dRight, 0, self.a2dTop)
self.a2dBottomLeft.setPos(self.a2dLeft, 0, self.a2dBottom)
self.a2dBottomRight.setPos(self.a2dRight, 0, self.a2dBottom)
# Reposition the aspect2d marker nodes
self.a2dTopCenterNs.setPos(0, 0, self.a2dTop)
self.a2dBottomCenterNs.setPos(0, 0, self.a2dBottom)
self.a2dLeftCenterNs.setPos(self.a2dLeft, 0, 0)
self.a2dRightCenterNs.setPos(self.a2dRight, 0, 0)
self.a2dTopLeftNs.setPos(self.a2dLeft, 0, self.a2dTop)
self.a2dTopRightNs.setPos(self.a2dRight, 0, self.a2dTop)
self.a2dBottomLeftNs.setPos(self.a2dLeft, 0, self.a2dBottom)
self.a2dBottomRightNs.setPos(self.a2dRight, 0, self.a2dBottom)
# Reposition the aspect2dp marker nodes
self.a2dpTopCenter.setPos(0, 0, self.a2dpTop)
self.a2dpBottomCenter.setPos(0, 0, self.a2dpBottom)
self.a2dpLeftCenter.setPos(self.a2dpLeft, 0, 0)
self.a2dpRightCenter.setPos(self.a2dpRight, 0, 0)
self.a2dpTopLeft.setPos(self.a2dpLeft, 0, self.a2dpTop)
self.a2dpTopRight.setPos(self.a2dpRight, 0, self.a2dpTop)
self.a2dpBottomLeft.setPos(self.a2dpLeft, 0, self.a2dpBottom)
self.a2dpBottomRight.setPos(self.a2dpRight, 0, self.a2dpBottom)
# If anybody needs to update their GUI, put a callback on this event
messenger.send("aspectRatioChanged")
def userExit(self):
# The user has requested we exit the program. Deal with this.
if self.exitFunc: