Want to make a change to every widget on creation.

Piko

18-06-2009 20:42:14

Here is my problem. I want to make a change to every widget that is created by MyGui, it's not the example I give, but I want to know if I have this figured out.

So assume that if I create a class that inherits IWidgetFactory called MyWidgetFactory, and simply create my own createWidget function that goes a little like this,


WidgetPtr MyWidgetFactory::createWidget (WidgetStyle _style, const std::string &_skin, const IntCoord &_coord, Align _align, WidgetPtr _parent, ICroppedRectangle *_croppedParent, IWidgetCreator *_creator, const std::string &_name)
{
WidgetPtr tempWidget = IWidgetFactory::createWidget(_style, _skin, _coord, _align, _parent, _croppedParent, _creator, _name);
tempWidget->setAlpha(0.0f);
return tempWidget;
}


Then register the new factory to WidgetManager, will every single widget created by MyGui regardless of how it was created will have an alpha value of 0.0f?

Am I right in thinking this is how it works.

Piko

19-06-2009 04:10:22

Never mind, widget factory is only if you wish to create a custom widget type.

Piko

19-06-2009 04:29:17

Ok, I think I know how to do this.

I can unregister all the default factories that WidgetManager inserts on initialization, and replace them with my own factories that inherit the original factories. So unregister factory::WidgetFactory() with my own class that is set up like this class MyWidgetFactory : public factory::WidgetFactory, ok I think I have this figured out.

Now if I register another factory that has the same type name as a factory already registered, will it take the factory that was registered first, or last?

Altren

19-06-2009 13:10:17

Now if I register another factory that has the same type name as a factory already registered, will it take the factory that was registered first, or last?It will take first.

Can you explain why do you need this? May be I know better solution for your task.

Piko

19-06-2009 18:56:16

I want all the gui events that every widget can create sent to a single set of functions that will insert the gui events into my event system that can be accessed by my embedded/extended python scripting system. Because I do not, and can not have the gui events hard coded in C++. I simply need to inform my event system the name of the widget that created the event, and the kind of event it created, that way my external python scripts can take the appropriate actions.

Creating inherited factories seemed the best way I could make sure every widget would set their event handlers correctly.