Browse Source

showbase: make render2d available to GUI items without ShowBase

rdb 6 years ago
parent
commit
69e8b4ed3c
2 changed files with 9 additions and 3 deletions
  1. 7 2
      direct/src/showbase/ShowBase.py
  2. 2 1
      direct/src/showbase/ShowBaseGlobal.py

+ 7 - 2
direct/src/showbase/ShowBase.py

@@ -544,6 +544,8 @@ class ShowBase(DirectObject.DirectObject):
                 del ShowBaseGlobal.base
                 del ShowBaseGlobal.base
 
 
         self.aspect2d.node().removeAllChildren()
         self.aspect2d.node().removeAllChildren()
+        self.render2d.node().removeAllChildren()
+        self.aspect2d.reparent_to(self.render2d)
 
 
         # [gjeon] restore sticky key settings
         # [gjeon] restore sticky key settings
         if self.config.GetBool('disable-sticky-keys', 0):
         if self.config.GetBool('disable-sticky-keys', 0):
@@ -1108,8 +1110,12 @@ class ShowBase(DirectObject.DirectObject):
         2-d objects and gui elements that are superimposed over the
         2-d objects and gui elements that are superimposed over the
         3-d geometry in the window.
         3-d geometry in the window.
         """
         """
+        # We've already created aspect2d in ShowBaseGlobal, for the
+        # benefit of creating DirectGui elements before ShowBase.
+        from . import ShowBaseGlobal
+
         ## This is the root of the 2-D scene graph.
         ## This is the root of the 2-D scene graph.
-        self.render2d = NodePath('render2d')
+        self.render2d = ShowBaseGlobal.render2d
 
 
         # Set up some overrides to turn off certain properties which
         # Set up some overrides to turn off certain properties which
         # we probably won't need for 2-d objects.
         # we probably won't need for 2-d objects.
@@ -1140,7 +1146,6 @@ class ShowBase(DirectObject.DirectObject):
         ## aspect2d, which scales things back to the right aspect
         ## aspect2d, which scales things back to the right aspect
         ## ratio along the X axis (Z is still from -1 to 1)
         ## ratio along the X axis (Z is still from -1 to 1)
         self.aspect2d = ShowBaseGlobal.aspect2d
         self.aspect2d = ShowBaseGlobal.aspect2d
-        self.aspect2d.reparentTo(self.render2d)
 
 
         aspectRatio = self.getAspectRatio()
         aspectRatio = self.getAspectRatio()
         self.aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0)
         self.aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0)

+ 2 - 1
direct/src/showbase/ShowBaseGlobal.py

@@ -26,7 +26,8 @@ cvMgr = ConfigVariableManager.getGlobalPtr()
 pandaSystem = PandaSystem.getGlobalPtr()
 pandaSystem = PandaSystem.getGlobalPtr()
 
 
 # This is defined here so GUI elements can be instantiated before ShowBase.
 # This is defined here so GUI elements can be instantiated before ShowBase.
-aspect2d = NodePath(PGTop("aspect2d"))
+render2d = NodePath("render2d")
+aspect2d = render2d.attachNewNode(PGTop("aspect2d"))
 hidden = NodePath("hidden")
 hidden = NodePath("hidden")
 
 
 # Set direct notify categories now that we have config
 # Set direct notify categories now that we have config