inheritence

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

inheritence

Post by dehseth »

I would like to extend CGUIButton with some new features, then I saw CGUIButton elements are declared as private:

Code: Select all

private:

		struct ButtonSprite
		{
			s32 Index;
			video::SColor Color;
			bool Loop;
		};

		ButtonSprite ButtonSprites[EGBS_COUNT];

		IGUISpriteBank* SpriteBank;
		IGUIFont* OverrideFont;
...
Do you guys consider changing private to protected so that we can use them instead of copying whole class to create a new one?

Thank you :)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

They are not meant to be derived from. You derive from the interface classes - not from the implementation classes.

If you want to copy the implementation, then the easiest way it to copy those the files, rename the files and rename the class.
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
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

Post by dehseth »

I just dont get this approach :) It would be much more flexible.. May you tell me the idea behind this? I just want to add some elemets, and some function to CGUIButton and override draw and onevent functions that's all. It would be nicer if I can derive my new class from CGUIButton, instead of copying whole class...

And you can seal some classes if you don't want them to be derived from..

2.Well at this point I see no choice to copy class and I did it. So how can I add my CGUICustomButtom to IGUIEnviroment? I tried this:

Code: Select all

m_customButton = reinterpret_cast<CGUICustomButton*>(g_gui->addButton(irr::core::recti(200,2000,300,300)));

	m_customButton->setRelativePosition(irr::core::position2di(150, 150));
	m_customButton->setVisible(true);
but it does not render anything... I don't see any drawing...

I guess we need a new addGUIElement function which takes IGUIelement pointer object e.g:

Code: Select all

void IGUIEnviroment::addIGUIElement(IGUIElement* element)
{

}
[/code]
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You only have access to the interface classes and some simple structural classes. All other things are hidden in the library. It's just the way the engine was designed. No way to derive from internal classes.
You cannot use addButton, except when you also changes the GUI environment. Otherwise simply use new MyButton()
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

Post by dehseth »

:oops: my mistake... CGUICustomButton constructor already take enviroment pointer sorry :roll:
Post Reply