Hello!
I’ve got a question about the eternal problem of keeping aspect2d ratio while resizing window.
I created a little code that work perfectly under linux, no worries.
But under windows, there is a bug. If i resize the window, nothing works ( it is still going through my code.) But if I move the window ( or lose focus, gain focus, etc… ) everything returns to normal.
As if there were a resizing function after my code that breaks everything.
Does that ring a bell anyone ?
class WindowHandler(DirectObject):
def __init__(self):
self.accept('window-event', self.first_activation)
def first_activation(self,win):
x = win.getXSize()
y = win.getYSize()
self.ratio2d = aspect2d.getScale()[0] , aspect2d.getScale()[1]
self.first_size = x,y
self.ratioX = x /float(base.cam.node().getLens().getHfov())
self.ratioY = y /float(base.cam.node().getLens().getVfov())
#=
base.cam.node().getLens().setFilmSize(x,y)
self.ignore('window-event')
self.accept('window-event', self.resize_window)
def resize_window(self,win):
x = win.getXSize()
y = win.getYSize()
self.size = (x,y)
self.resize_aspect2d()
def resize_aspect2d(self):
scaleX = self.ratio2d[0] * self.first_size[0] / float(self.size[0])
scaleY = self.ratio2d[1] * self.first_size[1] / float(self.size[1])
aspect2d.setScale(scaleX,0,scaleY)