Feature request!!

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Feature request!!

Post by rogerdv »

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
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post 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.
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Post by rogerdv »

I mean buttons mainly, but also other components.
ru guo ni yao ai, ni jiang bu hui shi qu
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post 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.
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Post by rogerdv »

Sorry, I can't find nothing about it in the docs. Can you post some minimal example to see how it works?
ru guo ni yao ai, ni jiang bu hui shi qu
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post 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 :).
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Post 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.
ru guo ni yao ai, ni jiang bu hui shi qu
Razed
Posts: 9
Joined: Mon May 10, 2004 9:43 am

Post 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.
Post Reply