Drag'n'Drop and MouseWatcher.isOverRegion()


I’m implementing a drag’n’drop system and want to detect if the drop happens over a gui element or over the 3d world.

Let me explain some more:

I have a bunch of gui elements (basically frames with sub frames, buttons, labels, etc.) on the screen.
All these elements have been set up so to react to mouse events (state set to DGG.NORMAL, suppressMouse set to 0)
This way I easily can detect if I’m over a gui element or not:

base.mouseWatcherNode.isOverRegion() returns 1 if the mouse is over a gui element. (or I can use base.mouseWatcherNode.getOverRegion())

So far it all worked fine and felt like a very elegant solution.
However, as soon as I start a real drag operation it stops working:

My drag source region again is a DirectFrame which was enabled for mouse events. I bind the B1PRESS and B1RELEASE events to detect the sart/stop of the dragging.
But after I’ve pressed the mouse over the DirectFrame, the mouseWatcher remembers the frame region as being special, and from now on isOverRegion() only returns 1 if the mouse is over the region that was clicked in the first place.
So in effect I cannot detect anymore if I’m over any other gui region than the one I clicked in the first place.

Is there a way for me to tell the mouseWatcher to again consider all regions and to forget about the click origin region?

As a workaround I could monitor the WITHIN/WITHOUT events on all gui elements and so keep track of wether I’m over gui or not, but I’m not happy with that solution. It really feels as if the mouseWatcher already is so close to giving me the answer directly…

Btw., I also tried using isMouseOpen() but that didn’t work for me at all. Regardles of where I point the mouse, it always returns 0 for me.



Hmm. You could try mouseWatcher.getOverRegion(mouseWatcher.getMouseX(), mouseWatcher.getMouseY()).


Thanks Dave, that worked!

Hmm… It seems not to be documented that one can pass x,y into the isOverRegion() or getOverRegion() calls on the MouseWatcher.
Or did I look in the wrong place?
(I looked here)



It’s a minor problem with our generated API docs that they don’t always pick up the different variants of the function in the prototype list. They do pick up the comment blocks, so this line:

refers to the variant that receives an (x, y) point. Since you can’t see that association, though, the description is confusing and easily overlooked.


The generated API doc had fooled me too much. It obviously doesn’t even know about the runtime-generated methods by pandac/libpandaModules.py as well.
Fortunately, I had a little (unfortunate) chance to start building the pain killer.

or just use other IDE that understands Python+P3D.

Arg , every time i see a screen shot of your P3D IDE, i’m playing the joy bunny…

:laughing: Is it your baby’s belonging ?