the display region under the mouse

Hi,

I have multiple display regions. Different ones are under the mouse at different times. Unfortunately they overlap.

Is there a handy function to determine which DR is under the mouse at any given time? Either the one with the highest sort value or the entire list would be OK.

Thanks.

I don’t think there’s anything built-in to determine that. But you could examine the DR coordinates yourself and write a simple program to determine it; or, you could create a series of MouseWatcherRegions that correspond to the DisplayRegions, and let Panda do the math each frame for you.

MouseWatcherRegions were originally devised to implement onscreen gui systems such as DirectGui; each MWR is a rectangular region onscreen that Panda can automatically detect the mouse’s presence over. When they overlap, you can get the topmost. It will also generate events at transition points, as the mouse moves around the screen; and if you listen to the events, you can keep track of the entire set of MWR’s under the mouse.

The MouseWatcher is the class that monitors the set of MWR’s, and you can get the default MouseWatcher in base.mouseWatchers[0]. Then you can call addRegion() for each region you create.

David

I wasn’t able to call

base.mouseWatchers[0].addRegion

This call did succeed:

base.mouseWatcherNode.addRegion( self.mousereg )

But this call:

		reg= base.mouseWatcherNode.getOverRegion( )

Was taking the right half of the screen to be the whole screen. It was interpreting the left half of the right half to be the entire left half.

This at least started selecting the right region.

		x=base.mouseWatcherNode.getMouseX()/ 2+ .5
		y=base.mouseWatcherNode.getMouseY()/ 2+ .5
		reg= base.mouseWatcherNode.getOverRegion( x, y )

But then all the calls to determine the mouse position:

		self.mouse1x1=base.mouseWatcherNode.getMouseX()
		self.mouse1y1=base.mouseWatcherNode.getMouseY()

seemed to need the same. And that can’t be right.

I’m sure you have to transform something something or other, but I’m pleased I just found ‘getOverRegion’. So. Someone encourage me. :wink:

Note that the space of the MouseWatcherRegion is different than the space of a DisplayRegion. When you define a DisplayRegion, (0, 0) is the lower-left corner of the screen, and (1, 1) is the upper-right corner.

However, all mouse coordinate operations are in a different space, with (-1, -1) in the lower-left, (0, 0) in the center, and (1, 1) in the upper-right. This includes MouseWatcherRegion; you have to be sure you create your MouseWatcherRegions to reflect the space you actually intend.

The reason for this difference is historical: the DisplayRegion space was defined first, and was made to be similar to UV mapping a texture to the whole screen; but when we added the mouse coordinates later it seemed better to put (0, 0) in the center.

David

That was certainly easier than my strategy was going to be.

self.mousereg= MouseWatcherRegion( 'region-%i'%i, *[ x*2-1 for x in rect ] )

Due to bad planning on the part of the OP, this thread was accidentally moved to:

https://discourse.panda3d.org/viewtopic.php?t=8739&start=30

  • a drag box for selecting an area.

Maybe it should be removed back here.