i want to get the button pointer from a xml based gui. The reason for this is wanting to configure the image of mouse_over image of button. But getElemenFromId returns an IGUIElement * type so i cant do what i want. i found the code below to do my will but it doesn't work.
Did you check that the pointer without a cast is != 0? Also, dynamic_cast will only work if RTTI is enabled, otherwise the pointer will be casted to 0.
yes i checked the pointer. nothing works!!! maybe i couldn't do, but for controlling xml base guis, there must be a way to get a pointer from specified element.
actually there is no error, i was answerind so i used the word:).
The problem is that i must get a pointer to the element type i want, but the function return (iguielement *), and i cant convert it to anytype of elements.
gui::IGUIElement* element = env->getRootGUIElement()->getElementFromId(i);
if (element && element->getType() == gui::EGUIET_BUTTON)
{
gui::IGUIButton* button = (gui::IGUIButton*)element;
// use button here
}
Of course you shouldn't really need to do the null pointer or type check if you have carefully built your gui, but it is the safe way to make sure you don't have code with undefined behavior.