Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
b102370364
3 changed files with 107 additions and 45 deletions
  1. 68 37
      direct/src/gui/Button.py
  2. 33 6
      direct/src/gui/Label.py
  3. 6 2
      direct/src/gui/ListBox.py

+ 68 - 37
direct/src/gui/Button.py

@@ -15,7 +15,11 @@ class Button(DirectObject):
                  font = getDefaultFont(),
                  font = getDefaultFont(),
                  pos = (0, 0),
                  pos = (0, 0),
                  geomRect = None,
                  geomRect = None,
-                 style = Label.ButtonUp):
+                 supportInactive = 0,
+                 upStyle = Label.ButtonUp,
+                 litStyle = Label.ButtonLit,
+                 downStyle = Label.ButtonDown,
+                 inactiveStyle = Label.ButtonInactive):
         self.name = name
         self.name = name
         self.width = width
         self.width = width
         # if no label given, use the button name
         # if no label given, use the button name
@@ -27,40 +31,62 @@ class Button(DirectObject):
             # text label, make text button
             # text label, make text button
             self.label = label
             self.label = label
 
 
-            self.l1 = Label.textLabel(self.label, style,
-                                      scale, width, drawOrder, font)
+            self.lUp = Label.textLabel(self.label, upStyle,
+                                       scale, width, drawOrder, font)
 
 
             if width == None:
             if width == None:
-                width = self.l1.getWidth() / scale
+                width = self.lUp.getWidth() / scale
                 self.width = width
                 self.width = width
             
             
-            self.l2 = Label.textLabel(self.label, Label.ButtonLit,
-                                      scale, width, drawOrder, font)
-            self.l3 = Label.textLabel(self.label, Label.ButtonDown,
-                                      scale, width, drawOrder, font)
+            self.lLit = Label.textLabel(self.label, litStyle,
+                                        scale, width, drawOrder, font)
+            self.lDown = Label.textLabel(self.label, downStyle,
+                                         scale, width, drawOrder, font)
+
+            if supportInactive:
+                self.lInactive = Label.textLabel(self.label, inactiveStyle,
+                                                 scale, width, drawOrder, font)
 
 
         elif (isinstance(label, NodePath)):
         elif (isinstance(label, NodePath)):
             # If it's a NodePath, assume it's a little texture card.
             # If it's a NodePath, assume it's a little texture card.
-            self.l1 = Label.modelLabel(label,
-                                       geomRect = geomRect,
-                                       scale = scale,
-                                       drawOrder = drawOrder)
+            self.lUp = Label.modelLabel(label,
+                                        geomRect = geomRect,
+                                        style = upStyle,
+                                        scale = scale,
+                                        drawOrder = drawOrder)
 
 
             if width == None:
             if width == None:
-                width = self.l1.getWidth() / scale
+                width = self.lUp.getWidth() / scale
                 self.width = width
                 self.width = width
-            
-            self.l2 = self.l1
-            self.l3 = self.l1
+
+            self.lLit = Label.modelLabel(label,
+                                         geomRect = geomRect,
+                                         style = litStyle,
+                                         scale = scale,
+                                         drawOrder = drawOrder)
+            self.lDown = Label.modelLabel(label,
+                                          geomRect = geomRect,
+                                          style = downStyle,
+                                          scale = scale,
+                                          drawOrder = drawOrder)
+            if supportInactive:
+                self.lInactive = Label.modelLabel(label,
+                                                  geomRect = geomRect,
+                                                  style = inactiveStyle,
+                                                  scale = scale,
+                                                  drawOrder = drawOrder)
             
             
         else:
         else:
             # label provided, use it for all labels
             # label provided, use it for all labels
-            self.l1 = self.l2 = self.l3 = label
+            self.lUp = self.lLit = self.lDown = self.lInactive = label
             if width == None:
             if width == None:
-                width = self.l1.getWidth()
+                width = self.lUp.getWidth()
+
+        if not supportInactive:
+            self.lInactive = self.lUp
 
 
-        self.button = GuiButton.GuiButton(self.name, self.l1, self.l2,
-                                          self.l3, self.l3, self.l1)
+        self.button = GuiButton.GuiButton(self.name, self.lUp, self.lLit,
+                                          self.lDown, self.lDown, self.lInactive)
         self.button.setDrawOrder(drawOrder)
         self.button.setDrawOrder(drawOrder)
         self.setPos(pos[0], pos[1])
         self.setPos(pos[0], pos[1])
         self.managed = 0
         self.managed = 0
@@ -70,8 +96,10 @@ class Button(DirectObject):
     def cleanup(self):
     def cleanup(self):
         if (self.managed):
         if (self.managed):
             self.unmanage()
             self.unmanage()
-        self.l1 = None
-        self.l2 = None
+        self.lUp = None
+        self.lLit = None
+        self.lDown = None
+        self.lInactive = None
         self.button = None
         self.button = None
 	return None
 	return None
         
         
@@ -92,21 +120,24 @@ class Button(DirectObject):
         return self.width
         return self.width
     
     
     def setWidth(self, width):
     def setWidth(self, width):
-        self.l1.setWidth(width)
-        self.l2.setWidth(width)
-        self.l3.setWidth(width)
-
-    def freeze(self):
-        self.l1.freeze()
-        self.l2.freeze()
-        self.l3.freeze()
-        self.button.freeze()
-
-    def thaw(self):
-        self.l1.thaw()
-        self.l2.thaw()
-        self.l3.thaw()
-        self.button.thaw()
+        self.lUp.setWidth(width)
+        self.lLit.setWidth(width)
+        self.lDown.setWidth(width)
+        self.lInactive.setWidth(width)
+
+##     def freeze(self):
+##         self.lUp.freeze()
+##         self.lLit.freeze()
+##         self.lDown.freeze()
+##         self.lInactive.freeze()
+##         self.button.freeze()
+
+##     def thaw(self):
+##         self.lUp.thaw()
+##         self.lLit.thaw()
+##         self.lDown.thaw()
+##         self.lInactive.thaw()
+##         self.button.thaw()
         
         
     def manage(self, nodepath = aspect2d):
     def manage(self, nodepath = aspect2d):
         if nodepath:
         if nodepath:

+ 33 - 6
direct/src/gui/Label.py

@@ -6,12 +6,13 @@ from GuiGlobals import *
 ## the way the label looks.
 ## the way the label looks.
 
 
 ButtonUp = 1
 ButtonUp = 1
-ButtonLit = 2
-ButtonDown = 3
-Sign = 4
-ScrollTitle = 5
-ScrollItem = 6
-ButtonUpGui = 7
+ButtonUpGui = 2
+ButtonLit = 3
+ButtonDown = 4
+ButtonInactive = 5
+Sign = 6
+ScrollTitle = 7
+ScrollItem = 8
 
 
 def textLabel(string, style,
 def textLabel(string, style,
               scale = 0.1,
               scale = 0.1,
@@ -80,6 +81,11 @@ def textLabelAndText(string, style,
         text.setTextColor(1.0, 1.0, 1.0, 1.0)
         text.setTextColor(1.0, 1.0, 1.0, 1.0)
         text.setCardColor(0.0, 0.0, 0.0, 1.0)
         text.setCardColor(0.0, 0.0, 0.0, 1.0)
         
         
+    elif style == ButtonInactive:
+        # When the button is inactive, it's gray on gray.
+        text.setTextColor(0.4, 0.4, 0.4, 1.0)
+        text.setCardColor(0.6, 0.6, 0.6, 1.0)
+        
     elif style == Sign:
     elif style == Sign:
         # For a sign, we want red text with no background card.
         # For a sign, we want red text with no background card.
         text.setTextColor(1., 0., 0., 1.)
         text.setTextColor(1., 0., 0., 1.)
@@ -122,6 +128,7 @@ def textLabelAndText(string, style,
 
 
 def modelLabel(model,
 def modelLabel(model,
                geomRect = None,
                geomRect = None,
+               style = None,
                scale = 0.1,
                scale = 0.1,
                drawOrder = getDefaultDrawOrder()):
                drawOrder = getDefaultDrawOrder()):
 
 
@@ -132,6 +139,26 @@ def modelLabel(model,
     mi.setScale(scale)
     mi.setScale(scale)
     mi.setBin('fixed', drawOrder)
     mi.setBin('fixed', drawOrder)
 
 
+    if style != None:
+        # For a modelLabel, the style determines the color that may be
+        # applied.
+        color = None
+        
+        # The style might *itself* be a four-component color.
+        if (isinstance(style, types.TupleType) or
+            isinstance(style, VBase4)):
+            color = style
+
+        # Otherwise, there might be a predefined default color for one
+        # of the canned styles.  Most don't have a default color,
+        # though.
+        elif style == ButtonInactive:
+            color = (0.5, 0.5, 0.5, 1.0)
+            
+        if color != None:
+            mi.setColor(color[0], color[1], color[2], color[3])
+        
+
     if geomRect == None:
     if geomRect == None:
         geomRect = (1, 1)
         geomRect = (1, 1)
 
 

+ 6 - 2
direct/src/gui/ListBox.py

@@ -28,12 +28,16 @@ class ListBox(DirectObject):
         self.up = Button.Button(name + '-up', arrow,
         self.up = Button.Button(name + '-up', arrow,
                                 geomRect = (-1, 1, 0, 0.5),
                                 geomRect = (-1, 1, 0, 0.5),
                                 scale = arrowScale,
                                 scale = arrowScale,
-                                drawOrder = drawOrder)
+                                drawOrder = drawOrder,
+                                downStyle = (0.5, 0, 0, 1),
+                                supportInactive = 1)
         arrow.setR(180)
         arrow.setR(180)
         self.down = Button.Button(name + '-down', arrow,
         self.down = Button.Button(name + '-down', arrow,
                                   geomRect = (-1, 1, -0.5, 0),
                                   geomRect = (-1, 1, -0.5, 0),
                                   scale = arrowScale,
                                   scale = arrowScale,
-                                  drawOrder = drawOrder)
+                                  drawOrder = drawOrder,
+                                  downStyle = (0.5, 0, 0, 1),
+                                  supportInactive = 1)
         arrow.removeNode()
         arrow.removeNode()
 
 
         self.listBox = GuiListBox(self.name + '-lb', self.numSlots,
         self.listBox = GuiListBox(self.name + '-lb', self.numSlots,