InjectMouseDown returns strange values?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Pfhreak
Just popping in
Just popping in
Posts: 4
Joined: Fri Jun 13, 2008 05:35

InjectMouseDown returns strange values?

Postby Pfhreak » Thu Jun 26, 2008 14:58

Ok, perhaps this is just my misunderstanding of when it should return true and when it should return false, but I'm getting some strange effects.

I've got a menu strip with three buttons on it, arranged like the image below.
Image

What I want is for any click inside the grey area (the menu bar) to be consumed, and any click outside that area to be passed to the game. I thought I could accomplish this by simply checking the return value of InjectMouseButtonDown. If it was false, then I didn't click on the GUI.

Here's the code I'm using:

Code: Select all

if (_mouseState.LeftPressed)
      if (CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton) == false)
        OnLeftPressed();
    if (_mouseState.RightPressed)
      if (CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton) == false)
        OnRightPressed();


_mouseState is just a small struct to hold information about the mouse.
Well, it doesn't seem to work correctly. When I click on the buttons (the empty squares) everything works correctly, and no click is passed to the game. But when I click on the grey area, the click is sometimes passed on and sometimes consumed. It seems to consume the first click, and pass on every subsequent one.

Is there a better way to check to see if my mouse is over a visibile GUI element? Would I have to maintain a list of rectangles and check every one before handling click events? Am I missing something obvious?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Thu Jun 26, 2008 17:58

Hi,

The original idea of the return value was as you describe, however it's very broken. If you browse the forum for a while you'll likely see many posts that mention this type of thing, and it's an area of the system that I will be addressing in the future to resolve the issue once and for all (the current, extremely flaky, version of this is largely due to 'bug fixes' to some areas that have wreaked havoc elsewhere).

The best bet to overcome these issues is probably to subscribe event handlers to the grey area window (for mouse and key inputs as required) that return true, and thus cause the injector to return true. (Hope you get the idea, there).

CE.

Pfhreak
Just popping in
Just popping in
Posts: 4
Joined: Fri Jun 13, 2008 05:35

Postby Pfhreak » Fri Jun 27, 2008 00:13

Ok, I think I understand, but could you make sure I've got the right idea here?

Here's how I am picturing CEGUI working in my mind. First, I inject a mouse down into CEGUI. CEGUI then gets all the windows that the mouse is over, and sends the click event to the top most layer. The on click event for that top layer window does whatever it does (which may be nothing) and returns true if it consumed the click, and false if it did not. If it returns false, the window immediately under that window gets an opportunity to consume the click, and this continues until all the windows have had their events called or a true value is returned. (Similar to the chain of command pattern.)

If none of the windows consumed the click, then false is returned from injection, but once a window consumes a click, true is returned.

The problem I am running into is some windows (like the menubar) don't expressly consume clicks (or don't always consume them correctly) which is why I am getting false from my injection.

The solution is to explicitly subscribe to the on click events for all my misbehaving windows, and simply return true. Thus preventing the click from being passed back to the engine for consumption.

Is that correct?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Fri Jun 27, 2008 05:23

Yes, this is all largely correct.

BTW, at least some of the issues with windows not consuming clicks is because from a purely technical standpoint they have done nothing with the click. Take any window, it's not active. You click it, it becomes active and the event is consumed. Click it again, it's already active CEGUI does nothing with the event, and so the event is not consumed. This is right, but obviously wrong too ;) I'll be addressing it for the 0.7.x releases.

CE


Return to “Help”

Who is online

Users browsing this forum: No registered users and 27 guests