If you change the window size pictures and gui elements will not be scaled to match the size of the window automatically (if the aspect ratio changes, size will be changed).
This small script will change a image (like a startscreen, gui element etc.) to scale accordingly to the window aspect ratio.
import direct.directbase.DirectStart
from direct.gui.OnscreenImage import OnscreenImage
from direct.showbase.DirectObject import DirectObject
class aspectRatioScaler( DirectObject ):
def __init__( self ):
self.startImage = OnscreenImage(image = 'image.jpg')
self.windowEventSetup()
def windowEventSetup( self ):
# accept the window event's
self.accept( 'window-event', self.windowEventHandler)
# create a window event yourself
messenger.send( 'window-event', [base.win] )
def windowEventHandler( self, window=None ):
"""
This is a special callback.
It is called when the panda window is modified.
"""
if window is not None: # window is none if panda3d is not started
wp = window.getProperties()
wpXSize = wp.getXSize()
wpYSize = wp.getYSize()
if wpXSize > wpYSize:
height = 1.0
width = wpXSize / float(wpYSize)
else:
height = wpYSize / float(wpXSize)
width = 1.0
self.startImage.setScale( width, 1, height )
if __name__ == '__main__':
a = aspectRatioScaler()
run()