Mouse click but only if GUI is not clicked?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
danielmccarthy
Posts: 51
Joined: Fri May 30, 2014 12:55 am

Mouse click but only if GUI is not clicked?

Post by danielmccarthy »

Hi,

My mouse click code works perfectly fine but my problem is when they click on the chat window it still moves the character? How can I check to see if any GUI is selected this way I can prevent my code being called? Here it is at the moment.

Code: Select all

 
 if (event.EventType == EET_MOUSE_INPUT_EVENT)
    {
        switch(event.MouseInput.Event)
        {
        case EMIE_LMOUSE_PRESSED_DOWN:
 
            Mouse.down = true;
            Mouse.cursorX = event.MouseInput.X;
            Mouse.cursorY = event.MouseInput.Y;
 
            if (_inGame)
                game->MouseLClicked(event.MouseInput.X, event.MouseInput.Y);
 
            break;
 
        case EMIE_RMOUSE_PRESSED_DOWN:
            Mouse.cursorX = event.MouseInput.X;
            Mouse.cursorY = event.MouseInput.Y;
            if (_inGame)
                game->MouseRClicked(event.MouseInput.X, event.MouseInput.Y);
            break;
 
        case EMIE_LMOUSE_LEFT_UP:
        case EMIE_RMOUSE_LEFT_UP:
            Mouse.down = false;
            break;
 
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Mouse click but only if GUI is not clicked?

Post by CuteAlien »

With something like IGUIEnvironment::getRootGUIElement() ->getElementFromPoint(mousePos) you can find the element below the current mouse-position (you certainly need an instance of IGUIEnvironment).
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
danielmccarthy
Posts: 51
Joined: Fri May 30, 2014 12:55 am

Re: Mouse click but only if GUI is not clicked?

Post by danielmccarthy »

Thats great can't believe I didn't think of that thanks mate
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Mouse click but only if GUI is not clicked?

Post by Seven »

I use the hover message to do this by setting a bool flag in the 'level' class.
If the bool variable is set, then no events get sent to the character or camera.

switch the event and react to the hover.
hover tells me when the mouse is over a gui element.

case EGET_ELEMENT_HOVERED: return OnElementHovered(e);
Post Reply