浏览代码

directgui: Add default release sounds for buttons

DTM1218 5 月之前
父节点
当前提交
062e3365fd
共有 3 个文件被更改,包括 31 次插入7 次删除
  1. 21 6
      direct/src/gui/DirectButton.py
  2. 1 0
      direct/src/gui/DirectCheckBox.py
  3. 9 1
      direct/src/gui/DirectGuiGlobals.py

+ 21 - 6
direct/src/gui/DirectButton.py

@@ -44,6 +44,7 @@ class DirectButton(DirectFrame):
             # Sounds to be used for button events
             ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
             ('clickSound',    DGG.getDefaultClickSound(),    self.setClickSound),
+            ('releaseSound',  DGG.getDefaultReleaseSound(),  self.setReleaseSound),
             # Can only be specified at time of widget contruction
             # Do the text/graphics appear to move when the button is clicked
             ('pressEffect',     1,         DGG.INITOPT),
@@ -108,6 +109,13 @@ class DirectButton(DirectFrame):
             # Pass any extra args to command
             self['command'](*self['extraArgs'])
 
+    def setRolloverSound(self):
+        rolloverSound = self['rolloverSound']
+        if rolloverSound:
+            self.guiItem.setSound(DGG.ENTER + self.guiId, rolloverSound)
+        else:
+            self.guiItem.clearSound(DGG.ENTER + self.guiId)
+
     def setClickSound(self):
         clickSound = self['clickSound']
         # Clear out sounds
@@ -122,9 +130,16 @@ class DirectButton(DirectFrame):
             if DGG.RMB in self['commandButtons']:
                 self.guiItem.setSound(DGG.B3PRESS + self.guiId, clickSound)
 
-    def setRolloverSound(self):
-        rolloverSound = self['rolloverSound']
-        if rolloverSound:
-            self.guiItem.setSound(DGG.ENTER + self.guiId, rolloverSound)
-        else:
-            self.guiItem.clearSound(DGG.ENTER + self.guiId)
+    def setReleaseSound(self):
+        releaseSound = self['releaseSound']
+        # Clear out sounds
+        self.guiItem.clearSound(DGG.B1RELEASE + self.guiId)
+        self.guiItem.clearSound(DGG.B2RELEASE + self.guiId)
+        self.guiItem.clearSound(DGG.B3RELEASE + self.guiId)
+        if releaseSound:
+            if DGG.LMB in self['commandButtons']:
+                self.guiItem.setSound(DGG.B1RELEASE + self.guiId, releaseSound)
+            if DGG.MMB in self['commandButtons']:
+                self.guiItem.setSound(DGG.B2RELEASE + self.guiId, releaseSound)
+            if DGG.RMB in self['commandButtons']:
+                self.guiItem.setSound(DGG.B3RELEASE + self.guiId, releaseSound)

+ 1 - 0
direct/src/gui/DirectCheckBox.py

@@ -28,6 +28,7 @@ class DirectCheckBox(DirectButton):
             # Sounds to be used for button events
             ('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
             ('clickSound',    DGG.getDefaultClickSound(),    self.setClickSound),
+            ('releaseSound',  DGG.getDefaultReleaseSound(),  self.setReleaseSound),
             # Can only be specified at time of widget contruction
             # Do the text/graphics appear to move when the button is clicked
             ('pressEffect',     1,         DGG.INITOPT),

+ 9 - 1
direct/src/gui/DirectGuiGlobals.py

@@ -17,8 +17,9 @@ from panda3d.core import (
 
 defaultFont = None
 defaultFontFunc = TextNode.getDefaultFont
-defaultClickSound = None
 defaultRolloverSound = None
+defaultClickSound = None
+defaultReleaseSound = None
 defaultDialogGeom = None
 defaultDialogRelief = PGFrameStyle.TBevelOut
 drawOrder = 100
@@ -129,6 +130,13 @@ def setDefaultClickSound(newSound):
     global defaultClickSound
     defaultClickSound = newSound
 
+def getDefaultReleaseSound():
+    return defaultReleaseSound
+
+def setDefaultReleaseSound(newSound):
+    global defaultReleaseSound
+    defaultReleaseSound = newSound
+
 def getDefaultFont():
     global defaultFont
     if defaultFont is None: