mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
dgui: allow creating DirectOptionMenu without ShowBase
This commit is contained in:
parent
69e8b4ed3c
commit
2e3b350510
@ -7,11 +7,13 @@ in-depth explanation and an example of how to use this class.
|
|||||||
__all__ = ['DirectOptionMenu']
|
__all__ = ['DirectOptionMenu']
|
||||||
|
|
||||||
from panda3d.core import *
|
from panda3d.core import *
|
||||||
|
from direct.showbase import ShowBaseGlobal
|
||||||
from . import DirectGuiGlobals as DGG
|
from . import DirectGuiGlobals as DGG
|
||||||
from .DirectButton import *
|
from .DirectButton import *
|
||||||
from .DirectLabel import *
|
from .DirectLabel import *
|
||||||
from .DirectFrame import *
|
from .DirectFrame import *
|
||||||
|
|
||||||
|
|
||||||
class DirectOptionMenu(DirectButton):
|
class DirectOptionMenu(DirectButton):
|
||||||
"""
|
"""
|
||||||
DirectOptionMenu(parent) - Create a DirectButton which pops up a
|
DirectOptionMenu(parent) - Create a DirectButton which pops up a
|
||||||
@ -222,27 +224,27 @@ class DirectOptionMenu(DirectButton):
|
|||||||
self.popupMenu.setZ(
|
self.popupMenu.setZ(
|
||||||
self, self.minZ + (self.selectedIndex + 1)*self.maxHeight)
|
self, self.minZ + (self.selectedIndex + 1)*self.maxHeight)
|
||||||
# Make sure the whole popup menu is visible
|
# Make sure the whole popup menu is visible
|
||||||
pos = self.popupMenu.getPos(render2d)
|
pos = self.popupMenu.getPos(ShowBaseGlobal.render2d)
|
||||||
scale = self.popupMenu.getScale(render2d)
|
scale = self.popupMenu.getScale(ShowBaseGlobal.render2d)
|
||||||
# How are we doing relative to the right side of the screen
|
# How are we doing relative to the right side of the screen
|
||||||
maxX = pos[0] + fb[1] * scale[0]
|
maxX = pos[0] + fb[1] * scale[0]
|
||||||
if maxX > 1.0:
|
if maxX > 1.0:
|
||||||
# Need to move menu to the left
|
# Need to move menu to the left
|
||||||
self.popupMenu.setX(render2d, pos[0] + (1.0 - maxX))
|
self.popupMenu.setX(ShowBaseGlobal.render2d, pos[0] + (1.0 - maxX))
|
||||||
# How about up and down?
|
# How about up and down?
|
||||||
minZ = pos[2] + fb[2] * scale[2]
|
minZ = pos[2] + fb[2] * scale[2]
|
||||||
maxZ = pos[2] + fb[3] * scale[2]
|
maxZ = pos[2] + fb[3] * scale[2]
|
||||||
if minZ < -1.0:
|
if minZ < -1.0:
|
||||||
# Menu too low, move it up
|
# Menu too low, move it up
|
||||||
self.popupMenu.setZ(render2d, pos[2] + (-1.0 - minZ))
|
self.popupMenu.setZ(ShowBaseGlobal.render2d, pos[2] + (-1.0 - minZ))
|
||||||
elif maxZ > 1.0:
|
elif maxZ > 1.0:
|
||||||
# Menu too high, move it down
|
# Menu too high, move it down
|
||||||
self.popupMenu.setZ(render2d, pos[2] + (1.0 - maxZ))
|
self.popupMenu.setZ(ShowBaseGlobal.render2d, pos[2] + (1.0 - maxZ))
|
||||||
# Also display cancel frame to catch clicks outside of the popup
|
# Also display cancel frame to catch clicks outside of the popup
|
||||||
self.cancelFrame.show()
|
self.cancelFrame.show()
|
||||||
# Position and scale cancel frame to fill entire window
|
# Position and scale cancel frame to fill entire window
|
||||||
self.cancelFrame.setPos(render2d, 0, 0, 0)
|
self.cancelFrame.setPos(ShowBaseGlobal.render2d, 0, 0, 0)
|
||||||
self.cancelFrame.setScale(render2d, 1, 1, 1)
|
self.cancelFrame.setScale(ShowBaseGlobal.render2d, 1, 1, 1)
|
||||||
|
|
||||||
def hidePopupMenu(self, event = None):
|
def hidePopupMenu(self, event = None):
|
||||||
""" Put away popup and cancel frame """
|
""" Put away popup and cancel frame """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user