Disabled gui elements block mouse events?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Mloren
Posts: 114
Joined: Mon Aug 07, 2006 2:30 am
Location: Australia
Contact:

Disabled gui elements block mouse events?

Post by Mloren »

I'm making a main menu for my game.
I have a bunch of screen, each a separate object.
I create them all during a loading screen at the start and then when I want a particular screen to appear I call a function on it that enables all its gui elements and they are then drawn.
Screens not current displayed have all their elements disabled and are not drawn.

The problem with this approach is that only the elements closest to the front are catching mouse clicks.
Other screens that are further back aren't getting input because there are other (disabled and invisible) elements in front of them.

I had thought that disabling an element would stop it processing input but apparently not.

I don't really want to create and destroy the elements as the screens are shown because some use large textures and involve a lot of setup and there is a noticeable delay when they are created which is why I'm creating them all up front behind a loading screen.

I guess I could just shift all the disabled elements off screen and bring them back when the screen is shown but this feels like a hack.

Is there a better way to do this?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The function used to find the element on top is IGUIElement::getElementFromPoint in IGUIElement.h. If you look at it you can see that visibility is indeed checked so an invisible element shouldn't be able to catch events.

I also do hide gui-dialogs which are not used by setting them invisible in my own programs and haven't noticed yet a problem with that.

So I would need a test-case reproducing your bug to see what exactly is the problem in your case.

Edit: Note that diabled gui-elements will indeed still catch the events, but only if they are visible. But I think that also makes sense - if you have any disabled element in front of other elements then you don't want the elements hidden behind it to catch those events.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Post by teto »

You should use setVisible(false/true); instead of disabling the element and not drawing it.
Even if you don't call element->draw() it will still be checked when you click if you haven't set setVisibile() to false.

I think that behaviour is a bit weird but that's how it works.
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
Post Reply