This is a transparent mask to disable DirectGuis below when you open an in-game window or dialog
A big transparent DirectButton did the job but it would eat mouse events such as ‘wheel-up’ and ‘wheel-down’. So if your custom dialog requires mouse events, you can use this class
from panda3d.core import PGButton,MouseButton
from direct.gui.DirectButton import DirectButton
class DialogMask(DirectButton):
'''used to generate a full-screen mask to prevent button-clicking below the focused window/dialog
Added some tricks to make panda3d mouse events still available
'''
B1PRESS = PGButton.getPressPrefix() + MouseButton.one().getName() + '-'
B2PRESS = PGButton.getPressPrefix() + MouseButton.two().getName() + '-'
B3PRESS = PGButton.getPressPrefix() + MouseButton.three().getName() + '-'
B4PRESS = PGButton.getPressPrefix() + MouseButton.four().getName() + '-'
B5PRESS = PGButton.getPressPrefix() + MouseButton.five().getName() + '-'
WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName() + '-'
WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName() + '-'
WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName() + '-'
WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight().getName() + '-'
B1RELEASE = PGButton.getReleasePrefix() + MouseButton.one().getName() + '-'
B2RELEASE = PGButton.getReleasePrefix() + MouseButton.two().getName() + '-'
B3RELEASE = PGButton.getReleasePrefix() + MouseButton.three().getName() + '-'
B4RELEASE = PGButton.getReleasePrefix() + MouseButton.four().getName() + '-'
B5RELEASE = PGButton.getReleasePrefix() + MouseButton.five().getName() + '-'
def __init__(self):
DirectButton.__init__(self,parent = aspect2d, frameColor =(1,1,1,0), relief = DGG.FLAT,commandButtons = [])
self.accept('window-event', self.windowResize)
self.windowResize(None)
#throw mouse events again
self.bind(self.B1PRESS, self.rethrowEvent,['mouse1'])
self.bind(self.B2PRESS, self.rethrowEvent,['mouse2'])
self.bind(self.B3PRESS, self.rethrowEvent,['mouse3'])
self.bind(self.B4PRESS, self.rethrowEvent,['mouse4'])
self.bind(self.B5PRESS, self.rethrowEvent,['mouse5'])
self.bind(self.WHEELUP, self.rethrowEvent, ['wheel_up'])
self.bind(self.WHEELDOWN, self.rethrowEvent, ['wheel_down'])
self.bind(self.WHEELLEFT, self.rethrowEvent, ['wheel_left'])
self.bind(self.WHEELRIGHT, self.rethrowEvent, ['wheel_right'])
self.bind(self.B1RELEASE, self.rethrowEvent,['mouse1-up'])
self.bind(self.B2RELEASE, self.rethrowEvent,['mouse2-up'])
self.bind(self.B3RELEASE, self.rethrowEvent,['mouse3-up'])
self.bind(self.B4RELEASE, self.rethrowEvent,['mouse4-up'])
self.bind(self.B5RELEASE, self.rethrowEvent,['mouse5-up'])
def windowResize(self,arg):
#fill the screen
aspect = base.getAspectRatio()
if aspect > 1:
self['frameSize'] = (-aspect,aspect,-1,1)
elif aspect:
hh = 1.0/aspect
self['frameSize'] = (-1,1,-hh,hh)
def setCommandButtons(self, *args, **kwargs):
pass
def rethrowEvent(self,sevent,event):
messenger.send(sevent)
def destroy(self):
self.ignoreAll()
DirectButton.destroy(self)
all you need to create a DialogMask behind your custom pop-up, and call mask.show() before your custom dialog appears and call mask.hide() when you want to close your dialog