MyGUI  3.0.1
MyGUI_IWidgetFactory.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_I_WIDGET_FACTORY_H__
24 #define __MYGUI_I_WIDGET_FACTORY_H__
25 
26 #include "MyGUI_Prerequest.h"
27 #include "MyGUI_Types.h"
28 #include "MyGUI_WidgetStyle.h"
29 #include "MyGUI_WidgetDefines.h"
31 
32 #include "MyGUI_WidgetManager.h"
33 #include "MyGUI_SkinManager.h"
34 
35 namespace MyGUI
36 {
37 
38  //OBSOLETE
40  {
41  public:
42  virtual ~IWidgetFactory() { }
43 
44  virtual const std::string& getTypeName() = 0;
45  virtual Widget* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name) = 0;
46  };
47 
48  namespace factory
49  {
50 
51  //OBSOLETE
52  template <typename T>
54  {
55  public:
57  {
58  // регестрируем себя
60  manager.registerFactory(this);
61  }
62 
64  {
65  // удаляем себя
67  manager.unregisterFactory(this);
68  }
69 
70  const std::string& getTypeName()
71  {
72  return T::getClassTypeName();
73  }
74 
75  Widget* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name)
76  {
77  T* instance = new T(_style, _coord, _align, SkinManager::getInstance().getByName(_skin), _parent, _croppedParent, _creator, _name);
78  return instance;
79  }
80 
81  bool isFalseType(Widget* _ptr, const std::string &_key)
82  {
83  if (!_ptr->isType<T>())
84  {
85  MYGUI_LOG(Error, "Property '" << _key << "' is not supported by '" << _ptr->getTypeName() << "' widget");
86  return true;
87  }
88  return false;
89  }
90  };
91 
92  } // namespace factory
93 } // namespace MyGUI
94 
95 #endif // __MYGUI_I_WIDGET_FACTORY_H__