Browse Source

Added example to direct scrolled list
Added ability to rotate button with hpr option

Mark Mine 22 years ago
parent
commit
4308dea1af
2 changed files with 63 additions and 2 deletions
  1. 10 2
      direct/src/gui/DirectGuiBase.py
  2. 53 0
      direct/src/gui/DirectScrolledList.py

+ 10 - 2
direct/src/gui/DirectGuiBase.py

@@ -691,6 +691,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
             ('guiId',          None,         INITOPT),
             # Initial pos/scale of the widget
             ('pos',            None,         INITOPT),
+            ('hpr',            None,         INITOPT),
             ('scale',          None,         INITOPT),
             ('color',          None,         INITOPT),
             # Do events pass through this widget?
@@ -715,11 +716,18 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
         # Update pose to initial values
         if self['pos']:
             pos = self['pos']
-            # Can either be a Point3 or a tuple of 3 values
-            if isinstance(pos, Point3):
+            # Can either be a VBase3 or a tuple of 3 values
+            if isinstance(pos, VBase3):
                 self.setPos(pos)
             else:
                 apply(self.setPos, pos)
+        if self['hpr']:
+            hpr = self['hpr']
+            # Can either be a VBase3 or a tuple of 3 values
+            if isinstance(hpr, VBase3):
+                self.setHpr(hpr)
+            else:
+                apply(self.setHpr, hpr)
         if self['scale']:
             scale = self['scale']
             # Can either be a Vec3 or a tuple of 3 values

+ 53 - 0
direct/src/gui/DirectScrolledList.py

@@ -288,3 +288,56 @@ class DirectScrolledList(DirectFrame):
     def getSelectedText(self):
         return self['items'][self.index]['text']
     
+
+
+"""
+from DirectGui import *
+
+def makeButton(itemName, itemNum, *extraArgs):
+    def buttonCommand():
+        print itemName, itemNum
+    return DirectButton(text = itemName,
+                        relief = RAISED,
+                        frameSize = (-3.5,3.5,-0.2,0.8),
+                        scale = 0.85,
+                        command = buttonCommand)
+
+s = scrollList = DirectScrolledList(
+    parent = aspect2d,
+    relief = None,
+    # Use the default dialog box image as the background
+    image = getDefaultDialogGeom(),
+    # Scale it to fit around everyting
+    image_scale = (0.7,1,.8),
+    # Give it a label
+    text = "Scrolled List Example",
+    text_scale = 0.06,
+    text_align = TextNode.ACenter,
+    text_pos = (0,0.3),
+    text_fg = (0,0,0,1),
+    # inc and dec are DirectButtons
+    # They can contain a combination of text, geometry and images
+    # Just a simple text one for now
+    incButton_text = 'Increment',
+    incButton_relief = RAISED,
+    incButton_pos = (0.0, 0.0, -0.36),
+    incButton_scale = 0.1,
+    # Same for the decrement button
+    decButton_text = 'Decrement',
+    decButton_relief = RAISED,
+    decButton_pos = (0.0, 0.0, 0.175),
+    decButton_scale = 0.1,
+    # each item is a button with text on it
+    numItemsVisible = 4,
+    itemMakeFunction = makeButton, 
+    items = ['Able', 'Baker', 'Charlie', 'Delta', 'Echo', 'Foxtrot',
+             'Golf', 'Hotel', 'India', 'Juliet', 'Kilo', 'Lima'],
+    # itemFrame is a DirectFrame
+    # Use it to scale up or down the items and to place it relative
+    # to eveything else
+    itemFrame_pos = (0, 0, 0.06),
+    itemFrame_scale = 0.1,
+    itemFrame_frameSize = (-3.1,3.1,-3.3,0.8),
+    itemFrame_relief = GROOVE,
+    )
+"""