Page 1 of 1

How to inject only when over frame window?

Posted: Wed Apr 18, 2007 03:52
by some_name
I'm using CEGUI with Ogre. I have a number of frame windows that are all children of a GuiSheet that is loaded as a GuiLayout. I'm using OIS (the Ogre input system) in buffered mode, and injecting the events (mousemove, mousedown, etc).

What I want to do is know whether the event actually happened over a FrameWindow or not. If the event (mouse down or mouse move) was not over a frame window, I'd like to go ahead and do things to the 3D scene in Ogre instead.

I know how to do this with modes -- press escape to get the cursor, which sends all events to CEGUI. Press escape again to deactivate the GUI, and send all the events to the scene. But that's not good enough -- I want the best of both worlds!

What's the best way to do this? Is there some return status I can get for an event injection? Or do I have to separately ask CEGUI what window the cursor would be over?

Posted: Wed Apr 18, 2007 07:47
by scriptkid

what should work is putting all your frames into a fullscreen helper DefaultWindow (which is invisible) and have that listen to the mouse events (too) and pass them to Ogre. So the layout becomes:

--DefaultWindow (size of 1,1!)

Another option is to -as you suggest- ask CEGUI which window has the mouse. This can be done by calling 'getWindowContainingMouse()' on the System object and then act accordingly. But the first option might be cleaner.

Good luck! :)

Posted: Wed Apr 18, 2007 14:45
by Pompei2
If you take a look at the API reference, you can read this:

Code: Select all

bool CEGUI::System::inject........

        * true if the input was processed by the gui system.
        * false if the input was not processed by the gui system.

Posted: Wed Apr 18, 2007 17:02
by madmark

That works fine for stuff the mouse does that gets acted upon, but not for stuff that no widget claims, like whitespace in a dialog box.


So, to be clear on this idea (which I really like) only mouse events that get to the DefaultWindow would get passed into the 3D scene's mouse event handler. Do you think this will work for the above situation (whitespace)

Posted: Thu Apr 19, 2007 06:57
by scriptkid
I am not sure about the exact 'return behaviour' of InjectInput, but the solution with capturing events in a default window would work. Empty spaces in a dialog are still that dialog, so you would only get events in your defaultwindow when the mouse exceeds the dialogs' boundaries.

Good luck :)

Posted: Thu Apr 19, 2007 21:43
by Pompei2
madmark wrote:@Pompei2

That works fine for stuff the mouse does that gets acted upon, but not for stuff that no widget claims, like whitespace in a dialog box.

Oh, sorry, I misunderstood your problem :)

Posted: Sun Apr 22, 2007 16:22
by some_name
Thanks for the help. Passing it on from the DefaultWindow might work. Meanwhile, the solution I found when mucking around, was to call

Code: Select all

CEGUI::Window *win = CEGUI::System::getSingleton().getWindowContainingMouse();

Then I test whether the getType() of that window is DefaultWindow, and if so, don't inject the event.

Posted: Sun Apr 22, 2007 17:35
by lindquist
A (probably) better way to use that function would be to test if the returned Window* equals the return value of System::getGUISheet.

e.g. if the gui sheet contains the cursor, you're not inside any other windows. checking for type is prone to errors, as DefaultWindow is often used a packing container and not only as gui sheet.

also note that the getWindowContainingMouse method is updated when mouse motion is injected... so you should generally always inject. then decide whether to pass on the input to your app/game after...