Feature request!!
Feature request!!
Please Niko, can you implement some improvement in the event system to know what mouse button was clicked over a widget?
ru guo ni yao ai, ni jiang bu hui shi qu
In your global def's:
___________________
In you OnEvent loop
____________________
In your draw loop
________________
____________________
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
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 .
___________________
Code: Select all
bool lmb_pressed;
In you OnEvent loop
____________________
Code: Select all
case irr::EMIE_LMOUSE_PRESSED_DOWN
{
lmb_pressed = true;
}
________________
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;
}
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.
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.