2
0
Эх сурвалжийг харах

*** empty log message ***

David Rose 24 жил өмнө
parent
commit
53b75fb7a9

+ 19 - 4
direct/src/gui/Label.py

@@ -20,7 +20,8 @@ def textLabel(string, style,
               scale = 0.1,
               scale = 0.1,
               width = None,
               width = None,
               drawOrder = getDefaultDrawOrder(),
               drawOrder = getDefaultDrawOrder(),
-              font = getDefaultFont()):
+              font = getDefaultFont(),
+              mayChange = 0):
     """textLabel(string, int style, float scale, float width,
     """textLabel(string, int style, float scale, float width,
                  int drawOrder, Node font)
                  int drawOrder, Node font)
 
 
@@ -30,14 +31,16 @@ def textLabel(string, style,
     """
     """
     
     
     (label, text) = \
     (label, text) = \
-            textLabelAndText(string, style, scale, width, drawOrder, font)
+            textLabelAndText(string, style, scale, width, drawOrder,
+                             font, mayChange)
     return label
     return label
     
     
 def textLabelAndText(string, style,
 def textLabelAndText(string, style,
                      scale = 0.1,
                      scale = 0.1,
                      width = None,
                      width = None,
                      drawOrder = getDefaultDrawOrder(),
                      drawOrder = getDefaultDrawOrder(),
-                     font = getDefaultFont()):
+                     font = getDefaultFont(),
+                     mayChange = 0):
     """textLabelAndText(string, int style, float scale, float width,
     """textLabelAndText(string, int style, float scale, float width,
                         int drawOrder, Node font)
                         int drawOrder, Node font)
 
 
@@ -129,7 +132,19 @@ def textLabelAndText(string, style,
 
 
     # Now we're completely done setting up the text, and we can safely
     # Now we're completely done setting up the text, and we can safely
     # thaw it.
     # thaw it.
-    text.thaw()
+    if mayChange:
+        # If we might change the text later, we have to keep the
+        # TextNode around.
+        text.thaw()
+    else:
+        # Otherwise, we can throw it away.
+        node = text.generate()
+
+        #*** Temporary for old Pandas
+        if node == None:
+            node = NamedNode()
+            
+        text = node
 
 
     # Now create a GuiLabel containing this text.
     # Now create a GuiLabel containing this text.
     label = GuiLabel.makeModelLabel(text, v[0] * scale, v[1] * scale,
     label = GuiLabel.makeModelLabel(text, v[0] * scale, v[1] * scale,

+ 4 - 2
direct/src/gui/OnscreenPanel.py

@@ -323,7 +323,8 @@ class OnscreenPanel(PandaObject.PandaObject, NodePath):
                  wordwrap = None,
                  wordwrap = None,
                  drawOrder = None,
                  drawOrder = None,
                  font = None,
                  font = None,
-                 parent = None):
+                 parent = None,
+                 mayChange = 0):
         """makeText(self, ...)
         """makeText(self, ...)
 
 
         Creates some text on the panel.  The return value is an
         Creates some text on the panel.  The return value is an
@@ -356,7 +357,8 @@ class OnscreenPanel(PandaObject.PandaObject, NodePath):
                                          wordwrap = wordwrap,
                                          wordwrap = wordwrap,
                                          drawOrder = drawOrder,
                                          drawOrder = drawOrder,
                                          font = font,
                                          font = font,
-                                         parent = parent)
+                                         parent = parent,
+                                         mayChange = mayChange)
         
         
         self.panelText.append(text)
         self.panelText.append(text)
         return text
         return text

+ 29 - 5
direct/src/gui/OnscreenText.py

@@ -28,7 +28,8 @@ class OnscreenText(PandaObject, NodePath):
                  wordwrap = None,
                  wordwrap = None,
                  drawOrder = GuiGlobals.getDefaultDrawOrder(),
                  drawOrder = GuiGlobals.getDefaultDrawOrder(),
                  font = GuiGlobals.getDefaultFont(),
                  font = GuiGlobals.getDefaultFont(),
-                 parent = aspect2d):
+                 parent = aspect2d,
+                 mayChange = 0):
         """__init__(self, ...)
         """__init__(self, ...)
 
 
         Make a text node from string, put it into the 2d sg and set it
         Make a text node from string, put it into the 2d sg and set it
@@ -81,6 +82,10 @@ class OnscreenText(PandaObject, NodePath):
           font: the font to use for the text.
           font: the font to use for the text.
 
 
           parent: the NodePath to parent the text to initially.
           parent: the NodePath to parent the text to initially.
+
+          mayChange: pass true if the text or its properties may need
+              to be changed at runtime, false if it is static once
+              created (which leads to better memory optimization).
         
         
         """
         """
 
 
@@ -88,8 +93,8 @@ class OnscreenText(PandaObject, NodePath):
         textNode = TextNode()
         textNode = TextNode()
         self.textNode = textNode
         self.textNode = textNode
 
 
-        # We ARE the node path that references this text node.
-        NodePath.__init__(self, parent.attachNewNode(textNode))
+        # We ARE a node path.  Initially, we're an empty node path.
+        NodePath.__init__(self)
 
 
         # Choose the default parameters according to the selected
         # Choose the default parameters according to the selected
         # style.
         # style.
@@ -181,10 +186,29 @@ class OnscreenText(PandaObject, NodePath):
 
 
         textNode.setText(text)
         textNode.setText(text)
 
 
-        # Ok, now update the node
-        textNode.thaw()
+        if not text:
+            # If we don't have any text, assume we'll be changing it later.
+            mayChange = 1
+
+        # Ok, now update the node.
+        if mayChange:
+            # If we might change the text later, we have to keep the
+            # TextNode around.
+            textNode.thaw()
+        else:
+            # Otherwise, we can throw it away.
+            self.textNode = textNode.generate()
+
+            #*** Temporary for old Pandas.
+            if self.textNode == None:
+                self.textNode = NamedNode()
+        
+        
 	self.isClean = 0
 	self.isClean = 0
 
 
+        # Set ourselves up as the NodePath that points to this node.
+        self.assign(parent.attachNewNode(self.textNode))
+
     def __del__(self):
     def __del__(self):
         # Make sure the node is removed when we delete the
         # Make sure the node is removed when we delete the
         # OnscreenText object.  This means we don't have to explicitly
         # OnscreenText object.  This means we don't have to explicitly