clicking a 2d image... how to?
-
- Posts: 7
- Joined: Sun Mar 02, 2008 11:22 pm
clicking a 2d image... how to?
Hi. I would just like to know how to be able to click a rendered 2D image to get the window to close (for example). I'm guessing I need to create some sort of box around my texture and when the mouse clicks it something executes (like the window closing, for example). I'm new and would just like some help. Could someone post an example or something for me on how to do this? Muchly appreciated.
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
-
- Posts: 7
- Joined: Sun Mar 02, 2008 11:22 pm
http://irrlicht.sourceforge.net/docu/cl ... on.html#a6
Has code plus everything else you may need regarding buttons.[/url]
Has code plus everything else you may need regarding buttons.[/url]
-
- Posts: 7
- Joined: Sun Mar 02, 2008 11:22 pm
I can do an event receiver but what would the 'get mouse position' and see if 'mouse is in rectangle' code look like? Sorry i'm new..monkeycracks wrote:Check and see if the mouse is inside the rectangle.
To do this you'll need :
The mouse position,
the rectangle to be clicked,
an event receiver
I'm trying to help without giving away the code
Don't recreate the wheel by coding a IGUIButton yourself. Just use the IGUIButton provided by Irrlicht. Vitek clearly, and politely, pointed that out to you, and I hope you take his advice. If you don't know what I mean, then use the following line of code and look it up in the API.unreal3149 wrote:I can do an event receiver but what would the 'get mouse position' and see if 'mouse is in rectangle' code look like? Sorry i'm new..monkeycracks wrote:Check and see if the mouse is inside the rectangle.
To do this you'll need :
The mouse position,
the rectangle to be clicked,
an event receiver
I'm trying to help without giving away the code
Code: Select all
IGUIButton* myButton = guienv->addButton(...)
TheQuestion = 2B || !2B
-
- Posts: 914
- Joined: Fri Aug 03, 2007 12:43 pm
- Location: South Africa
- Contact:
Code: Select all
bool g_sprite::isMouseInside(core::position2di mousepos)
{
bool answer = false;
core::rect<s32> spriteRect;
spriteRect.UpperLeftCorner.X = this->pos.X;
spriteRect.UpperLeftCorner.Y = this->pos.Y;
spriteRect.LowerRightCorner.X = this->pos.X + this->size.Width;
spriteRect.LowerRightCorner.Y = this->pos.Y + this->size.Height;
answer = spriteRect.isPointInside(mousepos);
return answer;
}
Code: Select all
this->size = texture->getOriginalSize();
But, as the IGUIImage is an IGUIElement, it has the following :
Code: Select all
if(event.EventType == EET_GUI_EVENT)
{
if(event.GUIEvent.EventType == EGET_ELEMENT_HOVERED)
{
if(event.GUIEvent.Caller->getID() == 1001)
{
//change the image to the mouse overed one?
}
}
}
This is easier by making a click boolean variable. Then inside THIS check you can say if clicked == true, do whatever. its harder doing code for clicks without a class!, so try getting that right.
If people are struggling with this, there is http://old.owned.co.za to look at, i released it here on the forums too, its jsut a test and has mouse over as well as a click class, its all that you need i think. hope it helps