adding a feature

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
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

adding a feature

Post by Masdus »

With irrlicht 0.3 i added a image button by duplicating the button files, changing the draw method and placing a new add button routine into the environment files. Now that 0.4 is out i wanted to use these buttons but i don't want to edit the engine again. Is there anyway to derive the button from within my application?
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Just don't edit the engine's source. Derive your own class from IGUIElement (you might do this by simply copying my code) and use this class in your your source. Works just perfectly. I think I'll extend the user interface tutorial a little bit later, showing how to do this.
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

do i have to modify the environment.h and cpp files to contain a new add button routine for the image buttons?
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

No, not at all. No changes to the engine necessary. To add your own button to the environment, just instantiate it.

Your class will look like this:

Code: Select all

class CGUIYourClass : public IGUIElement
{
public:
	//! constructor
	CGUIYourClass(IGUIEnvironment* environment,
	       IGUIElement* parent, s32 id, core::rect<s32> rectangle)
		: IGUIElement(environment, parent, id, rectangle) 
	{
	 // do something here
	}

	// blablabla...
And for adding it do this:

Code: Select all

CGUIYourClass* c = new CGUIYourClass(device->getGUIEnvironment()
   0, -1, aRectangle);
c->drop();
This works. :)
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

thanks niko
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

okay i have a new problem now involving recieving events. I included in my class a standard OnEvent(SEvent event) to recieve mouse clicks etc for the button. However it seems the function is never called. The follwing is from a file i've named CGUIImageButton which implements the new class

//! called if an event happened.
bool CGUIImageButton::OnEvent(SEvent event)
{
setVisible(false);
if (!IsEnabled)
return Parent ? Parent->OnEvent(event) : false;

switch(event.EventType)
{
case EET_GUI_EVENT:
if (event.GUIEvent.EventType == EGET_ELEMENT_MOUSE_FOCUS_LOST)
{
Pressed = false;
return true;
}
break;
case EET_MOUSE_INPUT_EVENT:
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
Pressed = true;
Environment->setMouseFocus(this);
return true;
}
else
if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
{
bool wasPressed = Pressed;
Environment->removeMouseFocus(this);
Pressed = false;

if (wasPressed && Parent)
{
SEvent event;
event.EventType = EET_GUI_EVENT;
event.GUIEvent.Caller = this;
event.GUIEvent.EventType = EGET_BUTTON_CLICKED;
Parent->OnEvent(event);
}

return true;
}
break;
}

return Parent ? Parent->OnEvent(event) : false;
}

at first i thought maybe the events weren't registered as GUIEvents, but it seems that no event is registered at all. Any ideas?
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

one other thing, to draw my item i had to call the draw function explicitly, the drawall for the gui environment did not draw the item.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

I think the problem is that you set "0" as parent, did you? Unfortunately there is currently no access to the root gui element. You should set some existing gui element as parent.
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

i'll give that a try
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

I have had some success with this. I have used a standard guibutton for the parent. The problem now seems to be that i can only display the image button within the bounds of the parent, and the parent must be visible for the child to function. I moved the image button using IGUIElement->move. The image is not displayed when moved, however the region where the button should be does act like a button
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

okay i fixed the display issue by using updateAbsolutePosition instead of move, but i still have the problem that the image button will only work if the parent is visible.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

That's very annoing you're right. I'll fix it as soon as possible.
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

thanks niko
Post Reply