Skip to content

Commit 541a2a7

Browse files
committed
showbase: allow attaching default MouseWatcher in attachInputDevice
This makes it easier to control GUIs using a gamepad.
1 parent ea02106 commit 541a2a7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

direct/src/showbase/ShowBase.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,13 +1677,17 @@ def getMeta(self):
16771677
return self.mouseWatcherNode.getModifierButtons().isDown(
16781678
KeyboardButton.meta())
16791679

1680-
def attachInputDevice(self, device, prefix=None):
1680+
def attachInputDevice(self, device, prefix=None, gui=False):
16811681
"""
16821682
This function attaches an input device to the data graph, which will
16831683
cause the device to be polled and generate events. If a prefix is
16841684
given and not None, it is used to prefix events generated by this
16851685
device, separated by a hyphen.
16861686
1687+
The gui argument can be set to True (as of Panda3D 1.10.3) to set up
1688+
the default MouseWatcher to receive inputs from this device, allowing
1689+
it to control user interfaces.
1690+
16871691
If you call this, you should consider calling detachInputDevice when
16881692
you are done with the device or when it is disconnected.
16891693
"""
@@ -1694,13 +1698,17 @@ def attachInputDevice(self, device, prefix=None):
16941698
idn = self.dataRoot.attachNewNode(InputDeviceNode(device, device.name))
16951699

16961700
# Setup the button thrower to generate events for the device.
1697-
bt = idn.attachNewNode(ButtonThrower(device.name))
1698-
if prefix is not None:
1699-
bt.node().setPrefix(prefix + '-')
1701+
if prefix is not None or not gui:
1702+
bt = idn.attachNewNode(ButtonThrower(device.name))
1703+
if prefix is not None:
1704+
bt.node().setPrefix(prefix + '-')
1705+
self.deviceButtonThrowers.append(bt)
17001706

17011707
assert self.notify.debug("Attached input device {0} with prefix {1}".format(device, prefix))
17021708
self.__inputDeviceNodes[device] = idn
1703-
self.deviceButtonThrowers.append(bt)
1709+
1710+
if gui:
1711+
idn.node().addChild(self.mouseWatcherNode)
17041712

17051713
def detachInputDevice(self, device):
17061714
"""

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy