Mouselook and my tool windows

My main view uses the middle button to toggle mouselook. When you press it goes into mouselook mode, when you release it goes out of mouselook mode.

But if one of my tool windows is at or near the center of the screen, then when in mouselook, the mouse is transported to the center, over that tool window, and it is the tool window (a tcastleshape) that receives the release callback instead of the main view. This leaves me stuck in mouselook mode. Is there a way to lock all interface events to the MainViewport when it is in mouselook mode?

Hm, we have a mechanism already to “capture” input – if you handle “Press” event for a mouse button over some control (make sure to return true from the Press override to let CGE know it is handled), then we make sure that that control will receive the Release event, even if at the point of release the mouse is over something else. It was written looking at X (Unix window system) similar mechanism.

So, obviously it fails for some reason for your case – because, from the description, it should exactly deal with your problem.

Can you make a testcase to reproduce the problem? I will happily take a look :slight_smile:

It doesn’t happen with other sorts of clicks… if I right click and drag to move the view around and the mouse goes over the window, it doesn’t do anything unexpected. But the middle click and drag with mouselook behaves differently. Perhaps this has to do with mouselook centering the mouse? The window is also handling middle click events for a mouselook on the building in its view.

I started to make a test case from the terrain demo code. I then realized that code does the mouselook more cleanly, instead of handling press and release events to set the mouselook state, it just checks if the right mouse button is down on update to enable/disable mouselook.

I changed my code to work that way using middle button. This prevents the chance of getting locked in mouselook state when middle button release where you can’t use mouse. But still the tool window and the main scene interfered with each other. Sort of mouselooking in both, but alternating. I then made a global variable to keep track of which TCastleUserInterface is ‘active’ based on button down. And then used that to insure events are ignored by inactive TCastleUserInterface. This improved it, so that if the middle button is pressed in the tool window, you can then mouselook that model cleanly. But if you press the middle button on the main view, making that active, it still interferes with the tool window if the tool window is in the middle of the screen. So that there is no movement when the mouse is over the toolwindow (even though mouse is invisible). This is because mouselook is moving the mouse to the center of the screen when it is enabled on the TCastleView. But on the TCastleImageControl that is the tool window, mouselook doesn’t center the mouse. I hope this make sense. It is hard to describe.

So I am not sure that my problem really is ‘focus’ now, so much as how mouselook behaves between the two cases. I guess I still need to make a test case, but it is hard to keep it simple.

I solved my problem. It was in my code. The tool window’s base class had a motion handler for dragging that was setting Handled to true even when not dragging. This was causing it to ‘steal’ the motion event from the main view so that it wasn’t mouse looking when the mouse was over the tool window.

1 Like

Thank you, I’m happy this is solved :slight_smile: