Page 1 of 1

MenuItem Fail with "new" Keyword

Posted: Fri Jul 22, 2011 08:54
by belkacem
hi again !!

the menu widget is one of the control that contain item like list box and combobox
and to create item for menu we use CEGUI::MenuItem .
OK

if i create a menu item like this

Code: Select all

MenuItem *_item = static_cast <MenuItem*> (CEGUI::WindowManager::getSingletonPtr()->createWindow ("TaharezLook/MenuItem" , Name)


and succeeded to create the item but if i change my code to something like this

Code: Select all

CEGUI::MenuItem *_item = new MenuItem ( "TaharezLook/MenuItem" , Name);


i fail to create the menu item

my question is : what's the diferrent between first code and the second
and why i fail to create the item in the second way , and thank you .

CEGUI.log
http://pastebin.com/raw.php?i=JvYTJHm7

Re: MenuItem Fail with "new" Keyword

Posted: Fri Jul 22, 2011 19:03
by Jamarr
Because WindowManager::createWindow takes a TargetType and MenuItem::MenuItem takes a WindowType. These are not the same thing and these two methods are not equivalent. The WindowManager uses the TargetType to look up the FalagardType, which it uses to assign the appropriate Renderer and LookNFeel references. All of these types are mapped via the .scheme file.

Why do you want to use 'new' instead of the provided WindowManager which encapsulates this whole process? You would need to re-write the functionality of the WindowManager, but why do this when it already exists? Stick with WindowManager::createWindow.

And for future reference, if you want to know how some code works please just look at the source-code yourself. Only then, after looking at the code yourself, should you come to the forums and ask questions if you still need help. That is exactly what we, the helpful community members have to do anyway. Please be considerate of our time, we do not get paid to help people ;)