I think that if there is no parent the function should do nothing.
If a user wanna to remove a parent he can do
setParent(0).
as it is, your code will setup a unwanted parent (root), so can happen to users to see a unwanted element drawed.
also setting parent again is redundant since is already done in addChild(), and also calling remove().
- cpp Code: Select all
virtual void setParent(IGUIElement *newparent)
{
if(newParent)
{
newParent->addChild(this);
}
}
I don't know why no one added "setParent" method. But is not really needed.
instead of doing
- cpp Code: Select all
element1->setParent(element2);
//you can still do
element2->addChild(element1);
probably having only addChild will make the code more consistent and requires 1 less virtual method (in the case some user re-implement addChild, is also forced to re-implement setParent for keep consistency, so I think that could be one of the reasons that method hasn't been added before).
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.