mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
showbase: allow attaching default MouseWatcher in attachInputDevice
This makes it easier to control GUIs using a gamepad.
This commit is contained in:
parent
ea0210640c
commit
541a2a73f0
@ -1677,13 +1677,17 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
return self.mouseWatcherNode.getModifierButtons().isDown(
|
return self.mouseWatcherNode.getModifierButtons().isDown(
|
||||||
KeyboardButton.meta())
|
KeyboardButton.meta())
|
||||||
|
|
||||||
def attachInputDevice(self, device, prefix=None):
|
def attachInputDevice(self, device, prefix=None, gui=False):
|
||||||
"""
|
"""
|
||||||
This function attaches an input device to the data graph, which will
|
This function attaches an input device to the data graph, which will
|
||||||
cause the device to be polled and generate events. If a prefix is
|
cause the device to be polled and generate events. If a prefix is
|
||||||
given and not None, it is used to prefix events generated by this
|
given and not None, it is used to prefix events generated by this
|
||||||
device, separated by a hyphen.
|
device, separated by a hyphen.
|
||||||
|
|
||||||
|
The gui argument can be set to True (as of Panda3D 1.10.3) to set up
|
||||||
|
the default MouseWatcher to receive inputs from this device, allowing
|
||||||
|
it to control user interfaces.
|
||||||
|
|
||||||
If you call this, you should consider calling detachInputDevice when
|
If you call this, you should consider calling detachInputDevice when
|
||||||
you are done with the device or when it is disconnected.
|
you are done with the device or when it is disconnected.
|
||||||
"""
|
"""
|
||||||
@ -1694,13 +1698,17 @@ class ShowBase(DirectObject.DirectObject):
|
|||||||
idn = self.dataRoot.attachNewNode(InputDeviceNode(device, device.name))
|
idn = self.dataRoot.attachNewNode(InputDeviceNode(device, device.name))
|
||||||
|
|
||||||
# Setup the button thrower to generate events for the device.
|
# Setup the button thrower to generate events for the device.
|
||||||
|
if prefix is not None or not gui:
|
||||||
bt = idn.attachNewNode(ButtonThrower(device.name))
|
bt = idn.attachNewNode(ButtonThrower(device.name))
|
||||||
if prefix is not None:
|
if prefix is not None:
|
||||||
bt.node().setPrefix(prefix + '-')
|
bt.node().setPrefix(prefix + '-')
|
||||||
|
self.deviceButtonThrowers.append(bt)
|
||||||
|
|
||||||
assert self.notify.debug("Attached input device {0} with prefix {1}".format(device, prefix))
|
assert self.notify.debug("Attached input device {0} with prefix {1}".format(device, prefix))
|
||||||
self.__inputDeviceNodes[device] = idn
|
self.__inputDeviceNodes[device] = idn
|
||||||
self.deviceButtonThrowers.append(bt)
|
|
||||||
|
if gui:
|
||||||
|
idn.node().addChild(self.mouseWatcherNode)
|
||||||
|
|
||||||
def detachInputDevice(self, device):
|
def detachInputDevice(self, device):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user