Hi to all,
I’m attempting to listen to mouse events when the mouse cursor is within a display region but it appears as if the events are not being recorded then. For example:
...
def dpMenuZoneMouseZoomSettings(self,key,value):
self.dpLinkMouseZoomKeys[key]=value
...
self.dpLinkMouseZoomKeys={"wheel-in":0,"wheel-out":0}
base.accept("wheel_up", self.dpMenuZoneMouseZoomSettings, ["wheel-in", 1])
...
Restricting it further to act only when the mouse cursor is within the display region yields nothing:
...
def dpMenuZoneMouseZoomSettings(self,key,value):
if(self.displayRegionMouseWatcher.hasMouse()):
self.dpLinkMouseZoomKeys[key]=value
...
Whenever the mouse cursor is outside the display region in question, the event “wheel_up” is heard and the value of “wheel-in” changes to 1. However, whenever the mouse cursor is inside the display region in question, the event “wheel_up” is not heard and no change occurs.
So how would one go about ensuring that the mouse-based events (mouse1,mouse2,mouse3,wheel_up,wheel_down) are heard when the mouse cursor is within an active display region in the scene?
Thanks in advance.
Hi!
Did you follow this page in the manual to create a new DisplayRegion with its own MouseWatcher? If so, note that it doesn’t mention that you will also need to attach a ButtonThrower to that MouseWatcher if you want it to generate mouse button events:
btn_thrower = ButtonThrower("my_btn_thrower")
mouse_watcher.attachNewNode(btn_thrower)
If that doesn’t fix it, could you elaborate a bit on how you set things up?
Hi,
I never knew that so I didn’t attach a ButtonThrower to it, however attempting to do this:
self.dpRegionLinkMouseWatcher = MouseWatcher()
base.mouseWatcher.getParent().attachNewNode(self.dpRegionLinkMouseWatcher)
self.dpRegionLinkMouseWatcher.setDisplayRegion(self.mounterMountedRelationsLinkDisplayRegion)
btn_thrower = ButtonThrower("my_btn_thrower")
self.dpRegionLinkMouseWatcher.attachNewNode(btn_thrower)
Yields this error:
...
AttributeError: 'panda3d.core.MouseWatcher' object has no attribute 'attachNewNode'
...
So I’ve been unable to test whether or not your solution would work…
Ah, I didn’t make it clear that it’s not the MouseWatcher itself (a PandaNode) but a NodePath referencing the MouseWatcher that the ButtonThrower needs to be attached to.
So it should be something like this:
self.dpRegionLinkMouseWatcher = MouseWatcher()
# we need a NodePath referencing the MouseWatcher PandaNode, so we can attach
# a ButtonThrower to it later on
mw = base.mouseWatcher.getParent().attachNewNode(self.dpRegionLinkMouseWatcher)
self.dpRegionLinkMouseWatcher.setDisplayRegion(self.mounterMountedRelationsLinkDisplayRegion)
btn_thrower = ButtonThrower("my_btn_thrower")
mw.attachNewNode(btn_thrower)
Thanks a lot as always! That worked perfectly.