照例列出WidgetManager的全部家当:
mDelegates 用来存储parse XML的delegate
重头在于
mFactoryList obsolete
mVectorIUnlinkWidget
mUnlinkWidgets
这里只是大战前的猜测:
mFactoryList 中存放的是IWidgetFactory
重点分析:
引入代码:
这种模式在MyGUI中应该是过时的:
因为关于IWidgetFactory的操作都是
//TODO正如FactoryManager中提到的Manager类之沟通与子类的协调者,
负责employer之间的注册于与离退,
对于:mUnlinkWidgets 注册,
void WidgetManager::addWidgetToUnlink(Widget* _widget) { if (_widget) mUnlinkWidgets.push_back(_widget); }
void WidgetManager::unlinkFromUnlinkers(Widget* _widget) { for (VectorIUnlinkWidget::iterator iter = mVectorIUnlinkWidget.begin(); iter!=mVectorIUnlinkWidget.end(); ++iter) { (*iter)->_unlinkWidget(_widget); } // вызывать последним, обнулится removeWidgetFromUnlink(_widget); }
void WidgetManager::removeWidgetFromUnlink(Widget*& _widget) { VectorWidgetPtr::iterator iter = std::find(mUnlinkWidgets.begin(), mUnlinkWidgets.end(), _widget); if (iter != mUnlinkWidgets.end()) { (*iter) = mUnlinkWidgets.back(); mUnlinkWidgets.pop_back(); } else { _widget = nullptr; } }对于:mVectorIUnlinkWidget
这个有点儿复杂,是说,对于Widget向每个IUnlinkWidget manager 注册的控件而言,
Widget Manager 使得其退注册。
void WidgetManager::registerUnlinker(IUnlinkWidget * _unlink) { unregisterUnlinker(_unlink); mVectorIUnlinkWidget.push_back(_unlink); }unregisterUnlinker
void WidgetManager::unregisterUnlinker(IUnlinkWidget * _unlink) { for (size_t pos=0; pos<mVectorIUnlinkWidget.size(); pos++) { if (mVectorIUnlinkWidget[pos] == _unlink) { mVectorIUnlinkWidget[pos] = mVectorIUnlinkWidget[mVectorIUnlinkWidget.size()-1]; mVectorIUnlinkWidget.pop_back(); break; } } }
createWidget 创建Widget分两步:
1)通过FacotryManager 创建Widget
2)然后再初始化:
_style, _coord, _align, skin, _parent, _cropeedParent, _creator, _name
返回 widget
Widget* WidgetManager::createWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, Widget* _parent, ICroppedRectangle * _cropeedParent, IWidgetCreator * _creator, const std::string& _name)
{ IObject* object = FactoryManager::getInstance().createObject("Widget", _type); if (object != nullptr) { Widget* widget = object->castType<Widget>(); ResourceSkin* skin = SkinManager::getInstance().getByName(_skin); widget->_initialise(_style, _coord, _align, skin, _parent, _cropeedParent, _creator, _name); return widget; } // старый вариант создания这句的意思是Obsolete for (SetWidgetFactory::iterator factory = mFactoryList.begin(); factory != mFactoryList.end(); ++factory) { if ((*factory)->getTypeName() == _type) { Widget* widget = (*factory)->createWidget(_style, _skin, _coord, _align, _parent, _cropeedParent, _creator, _name); return widget; } } MYGUI_EXCEPT("factory '" << _type << "' not found"); return nullptr; }
Widget 至少完成三种职能:
1,被调用来创建Widget 并对其初始化, skin之类的操作
2,被其他Manager(//TODO 在后续拔出后幕)所调用
来注册,Widget 和 IUnlinkWidget(对于每个manager 而言)
对于Initialize
void WidgetManager::initialise() { MYGUI_ASSERT(!mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice"); MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME); //registerUnlinker(this); FactoryManager& factory = FactoryManager::getInstance(); factory.registerFactory<Button>("Widget"); factory.registerFactory<Canvas>("Widget"); factory.registerFactory<ComboBox>("Widget"); factory.registerFactory<DDContainer>("Widget"); factory.registerFactory<Edit>("Widget"); factory.registerFactory<HScroll>("Widget"); factory.registerFactory<ItemBox>("Widget"); factory.registerFactory<List>("Widget"); factory.registerFactory<ListBox>("Widget"); factory.registerFactory<ListCtrl>("Widget"); factory.registerFactory<MenuBar>("Widget"); factory.registerFactory<MenuCtrl>("Widget"); factory.registerFactory<MenuItem>("Widget"); factory.registerFactory<Message>("Widget"); factory.registerFactory<MultiList>("Widget"); factory.registerFactory<PopupMenu>("Widget"); factory.registerFactory<Progress>("Widget"); factory.registerFactory<ScrollView>("Widget"); factory.registerFactory<StaticImage>("Widget"); factory.registerFactory<StaticText>("Widget"); factory.registerFactory<Tab>("Widget"); factory.registerFactory<TabItem>("Widget"); factory.registerFactory<VScroll>("Widget"); factory.registerFactory<Widget>("Widget"); factory.registerFactory<Window>("Widget"); #ifndef MYGUI_DONT_USE_OBSOLETE factory.registerFactory<RenderBox>("Widget"); factory.registerFactory<Sheet>("Widget"); #endif // MYGUI_DONT_USE_OBSOLETE MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized"); mIsInitialise = true; }
FactoryManager 类觉得应该叫WidgetCreateFactoryManager
因为它的职能是用来注册MyGUI 所支持Widget的所用种类:
觉得这里是个亮点,因为全部都是hard code 将来MyGUI插件化肯定是要用来动态加载。
值得一提的是MyGUI 将一些控件该成更人性化。
摘自MyGUI 官网:
http://redmine.mygui.info/repositories/entry/mygui/tags/MyGUI3.2/ChangeLog.txt
78 | -- Widgets --79 - VScroll and HScroll replaced with single ScrollBar class.80 - Edit renamed into EditBox.81 - List renamed into ListBox.82 - MenuCtrl renamed into MenuControl.83 - MultiList renamed into MultiListBox.84 - Progress renamed into ProgressBar.85 - StaticImage renamed into ImageBox.86 - StaticText renamed into TextBox.87 - Tab renamed into TabControl.88 - New Window property Moveable.89 - Message moved from Core to Common.90 - MultiListBox now support different modes of columns resizing.91 - Button properties StateCheck and ButtonPressed replaced with single property StateSelected.92 - ListBox and ComboBox now support ToolTip.93 - Menu items can be checked now, tick icon appears.94 - Property AlignVert renamed into VerticalAlignment.95 - Hidden widget lose input and focus.96 - Active elements visualisation in list now properly respond to changes in the list.97 - All text related properties was moved from Widget to TextBox.
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
geometry_
|
---|