Checking for an image press?

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

Checking for an image press?

Post by danielmccarthy »

Checking for a button press is easy enough but how can I do it for an image? What is the event type?
I looked through irrlicht header files and their doesn't appear to be an event type for an image click? Is their another way around this ?

Code: Select all

     int invItemX = 0;
    int invItemY = 0;
    IGUIImage* invItem = guienv->addImage(driver->getTexture("./media/Graphics/Items/coins.png"), core::position2d<s32>(invItemX, invItemY), true, 0, 907, L"Coins");
    invItem->setName("inventory_item");
Thanks
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Checking for an image press?

Post by CuteAlien »

You can catch mouse-click events (see example 19) and then go through the IGUIEnvironment::getRootGUIElement()->getElementFromPoint and compare the result to your image.
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: Checking for an image press?

Post by danielmccarthy »

Thanks for your reply

My solution is a IGUIButton with its border removed

Code: Select all

 
 int invItemX = 0;
    int invItemY = 0;
    int invItemWidth = 40;
    int invItemHeight = 40;
    IGUIButton* invItem = guienv->addButton(rect<s32>(invItemX, invItemY, invItemX + invItemWidth, invItemY + invItemHeight), 0, 907, L"", L"Coins");
    invItem->setName("inventory_item");
    invItem->setImage(driver->getTexture("./media/Graphics/Items/coins.png"));
    invItem->setUseAlphaChannel(true);
    invItem->setDrawBorder(false);
    IGUIStaticText* itemStackTxt = guienv->addStaticText(L"300", core::rect<s32>(0, 0, 50, 20), false, false, invItem, -1);
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Checking for an image press?

Post by CuteAlien »

That certainly also works :-)
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
Post Reply