Custom widget creation


27-04-2011 15:28:01

Hello! I want to create my custom widget (a special type of button) but I cannot find any help/tutorials on how to do this. I searched google, this forum and the Ogre wiki.

I know there is the "StrangeButton" thing, but it does not really help me. Do I really need a factory class, a parser, and a plugin to wrap the Widget in? Can't I just create one class derived from MyGUI::Widget (or MyGUI::Button in my case)? And what methods would this class need, where would I implement the way the Widget is displayed and it behaves? /edit: I found the factory and parser thing in the SVN rev. 430 or so, seems to be outdated.

I'd appreciate any help as well as links to tutorials etc. if there are any.



27-04-2011 16:44:09

You need to create new class, like StrangeButton and register it with single command:
and unregister before you deinitialise Gui
And that's all.

Also could you explain what you want to implement? In most cases you don't need to create custom widget.
Also usually we create layout wrapper, derived from BaseLayout for complex widgets or panels (good example is ColourPanel).


27-04-2011 16:54:57

Thanks! So I do not need a plugin...

Do I have to write "Widget" in the Register method or the name of my widget? And what methods do i need to inherit from MyGUI::Widget so it works?

What I want is somehow complicated, so I dont think a new Layout would be enough. It will be for displaying a slot in an inventory (making an RPG) so it can be empty or have an item/stack assigned. Should also be drag-droppable (later). Also I want it to display a background texture, then the icon with an alpha mask and a foreground texture above. So I have to somehow render these textures based on the state above each other...


27-04-2011 19:32:00

Yes, "Widget" is type of factory. And you also need next line in your widget:
class MyNewWidget : public Widget

But you don't need to create your own widget for all this stuff. In ItemBox demo we use layout wrappers for items. In demo items is not very complex (image and text), but in some applications we use much more complex items with similar BaseLayout derived classes.