Page 1 of 1

Feature request!!

Posted: Sat May 08, 2004 2:33 pm
by rogerdv
Please Niko, can you implement some improvement in the event system to know what mouse button was clicked over a widget?

Posted: Sat May 08, 2004 5:18 pm
by Tyn
You can do this yourself with a use of bools for when the mouse button is clicked, no need to ask Niko to implement it. By widget I take it you mean tabs? You just need to think about how you want to do it a little. Using mouse states for when a certain button is clicked will work fine here.

Posted: Sat May 08, 2004 7:11 pm
by rogerdv
I mean buttons mainly, but also other components.

Posted: Sat May 08, 2004 7:15 pm
by Tyn
Still possible. The OnEvent has a LMB and RMB return from which you can set a pressed bool. Set the bool to true when it happens and you have whatever mouse button was pressed last. Since you have to press the button to send the event then you have the feature you require.

Posted: Sun May 09, 2004 12:16 pm
by rogerdv
Sorry, I can't find nothing about it in the docs. Can you post some minimal example to see how it works?

Posted: Sun May 09, 2004 12:38 pm
by Tyn
In your global def's:
___________________

Code: Select all

bool lmb_pressed;

In you OnEvent loop
____________________

Code: Select all

case irr::EMIE_LMOUSE_PRESSED_DOWN
{
       lmb_pressed = true;
}
In your draw loop
________________

Code: Select all

while(device->run())
{
      driver->beginScene(true, true, video::SColor(0,100,100,100));
      smgr->drawAll();
      driver->endScene();
     lmb_pressed = false;
}
____________________

You will now have a bool that is true when the mouse button is pressed down, and then resets this bool at the end of the frame. You can then set an if statement in your button pressed function ( inside the OnEvent function ).

In theory this should work but you may have to fiddle where you put the lmb_pressed = false, I'm not sure where the event receiever looks for events in that loop but it should be way before the driver->endScene() is called.

It could also be a problem if the event receiver only picks up when the button is pressed down, not constantly checking it's state. You could use the

Code: Select all

case irr::EMIE_LMOUSE_LEFT_UP
{
      lmb_pressed = false;
}
function to do that if it doesn't work. It could also be considered to be cleaner code if you use the above function, it's up to you. There's always more than one way to skin a cat :).

Posted: Sun May 09, 2004 12:55 pm
by rogerdv
Well, it is a solution, Ill try that. Anyway, I still think that event structure should rprovide some more info for GUI events.

Posted: Mon May 10, 2004 9:50 am
by Razed
You can record what the mouse is over by listening to hover/left events, and storing the IGUIElement pointer in the app code. Then when you get the event, you will know what has been clicked.

However, having IGUIEnvironment do this would be a preferable arrangement, particularly since it could then deal with the situation where elements are removed by safely wiping its pointer.