Simple Gui events

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
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Simple Gui events

Post by trollger »

I am now trying to learn irrlicht inbuilt GUI system 8)
and everything is going smooth except for setting up GUI events.

This is what I have so far (well part of it and it does work) but my problem is in the if statement I only see isPressed (). How would I extend this to isReleased () or isHover () ? I looked through the Api and I dont see anything simular to this if any one can help me or has some tips about the GUI sytem in genral please let me know :D


IGUIButton * MyButton = env->addButton(rect<s32>(10,240,110,240 + 32), 0);
MyButton->setText(L"button");

//this is in the game loop
if(MyButton->isPressed()) // would like a few alternative events
{
ISceneNode* Billboard = smgr->addBillboardSceneNode();
Billboard->setPosition(vector3df(0,0,45));
Billboard->setMaterialFlag(video::EMF_LIGHTING, false);
Billboard->setMaterialTexture(0, driver->getTexture("../../media/particle.bmp"));
}
mager
Posts: 24
Joined: Thu Jul 22, 2010 11:55 pm

Post by mager »

you could right a small function like this

Code: Select all

bool hasDown = false;

bool isReleased()
{
if(hasDown)
{
   if(MyButton.isPressed())
   {
       hasDown = true;
       return false;
   }
}
else
{
   if(!MyButton.isPressed() && hasDown)
   {
       hasDown = false;
       return true;
   }
}
       
}

Note - I did not check the API for functionality, i was just showing a way you could similate that functionality in the event that there wasn't one
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Post by trollger »

hm.... I'll try it out,
thanks :)
CuteAlien
Admin
Posts: 9934
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Do you want to catch the state (getting "pressed" each frame) or the event (only getting it once the button is pressed)?

If you only need the event and want to react on that, then you should use an eventreceiver. Check the examples - many of those use one.
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
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Post by trollger »

I looked at the events receivers but didn't quite understand how they work I suppose I will have to take another look at it.
Iyad
Posts: 140
Joined: Sat Mar 07, 2009 1:18 am
Location: Montreal, Canada

Post by Iyad »

All you have to do is a class that inherit of IEventReceiver that overload the OnEvent(const SEvent &event) method, then instanciate the receiver and from the device pointer, call setEventReceiver(YourReceiver).

Note : you OnEvent method should return always return false.
#include <Iyad.h>
Post Reply