MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #ifndef __MYGUI_WIDGET_H__ 00008 #define __MYGUI_WIDGET_H__ 00009 00010 #include "MyGUI_Prerequest.h" 00011 #include "MyGUI_Any.h" 00012 #include "MyGUI_ICroppedRectangle.h" 00013 #include "MyGUI_WidgetUserData.h" 00014 #include "MyGUI_WidgetInput.h" 00015 #include "MyGUI_ResourceSkin.h" 00016 #include "MyGUI_ResourceLayout.h" 00017 #include "MyGUI_IObject.h" 00018 #include "MyGUI_SkinItem.h" 00019 #include "MyGUI_BackwardCompatibility.h" 00020 00021 namespace MyGUI 00022 { 00023 00024 typedef delegates::CMultiDelegate3<Widget*, const std::string&, const std::string&> EventHandle_WidgetStringString; 00025 00029 class MYGUI_EXPORT Widget : 00030 public IObject, 00031 public ICroppedRectangle, 00032 public UserData, 00033 public WidgetInput, 00034 public delegates::IDelegateUnlink, 00035 public SkinItem, 00036 public MemberObsolete<Widget> 00037 { 00038 // для вызова закрытых деструкторов 00039 friend class WidgetManager; 00040 00041 MYGUI_RTTI_DERIVED( Widget ) 00042 00043 public: 00044 Widget(); 00045 00053 Widget* createWidgetT(const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = ""); 00054 00056 Widget* createWidgetT(const std::string& _type, const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = ""); 00057 00059 Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = ""); 00060 00062 Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = ""); 00063 00064 // templates for creating widgets by type 00066 template <typename T> 00067 T* createWidget(const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = "") 00068 { 00069 return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, _coord, _align, _name)); 00070 } 00071 00073 template <typename T> 00074 T* createWidget(const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = "") 00075 { 00076 return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, IntCoord(_left, _top, _width, _height), _align, _name)); 00077 } 00078 00080 template <typename T> 00081 T* createWidgetReal(const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = "") 00082 { 00083 return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _coord, _align, _name)); 00084 } 00085 00087 template <typename T> 00088 T* createWidgetReal(const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = "") 00089 { 00090 return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _left, _top, _width, _height, _align, _name)); 00091 } 00092 00102 Widget* createWidgetT(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = ""); 00103 00105 template <typename T> 00106 T* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = "") 00107 { 00108 return static_cast<T*>(createWidgetT(_style, T::getClassTypeName(), _skin, _coord, _align, _layer, _name)); 00109 } 00110 00112 virtual void setPosition(const IntPoint& _value); 00114 virtual void setSize(const IntSize& _value); 00116 virtual void setCoord(const IntCoord& _value); 00117 00119 void setPosition(int _left, int _top); 00121 void setSize(int _width, int _height); 00123 void setCoord(int _left, int _top, int _width, int _height); 00124 00126 void setRealPosition(const FloatPoint& _value); 00128 void setRealSize(const FloatSize& _value); 00130 void setRealCoord(const FloatCoord& _value); 00131 00133 void setRealPosition(float _left, float _top); 00135 void setRealSize(float _width, float _height); 00137 void setRealCoord(float _left, float _top, float _width, float _height); 00138 00140 const std::string& getName() const; 00141 00143 virtual void setVisible(bool _value); 00145 bool getVisible() const; 00146 00151 void setDepth(int _value); 00153 int getDepth() const; 00154 00156 bool getInheritedVisible() const; 00157 00159 virtual void setAlign(Align _value); 00161 Align getAlign() const; 00162 00164 void setAlpha(float _value); 00166 float getAlpha() const; 00167 00178 void setInheritsAlpha(bool _value); 00180 bool getInheritsAlpha() const; 00181 00182 void setColour(const Colour& _value); 00183 00184 // являемся ли мы рутовым виджетом 00186 bool isRootWidget() const; 00187 00189 Widget* getParent() const; 00190 00191 IntSize getParentSize() const; 00192 00194 EnumeratorWidgetPtr getEnumerator() const; 00195 00197 size_t getChildCount(); 00198 00200 Widget* getChildAt(size_t _index); 00201 00206 Widget* findWidget(const std::string& _name); 00207 00211 void findWidgets(const std::string& _name, VectorWidgetPtr& _result); 00212 00214 virtual void setEnabled(bool _value); 00216 void setEnabledSilent(bool _value); 00218 bool getEnabled() const; 00219 00221 bool getInheritedEnabled() const; 00222 00224 IntCoord getClientCoord(); 00225 00227 Widget* getClientWidget(); 00228 00232 void detachFromWidget(const std::string& _layer = ""); 00233 00239 void attachToWidget(Widget* _parent, WidgetStyle _style = WidgetStyle::Child, const std::string& _layer = ""); 00240 00242 void changeWidgetSkin(const std::string& _skinName); 00243 00249 void setWidgetStyle(WidgetStyle _style, const std::string& _layer = ""); 00251 WidgetStyle getWidgetStyle() const; 00252 00257 void setProperty(const std::string& _key, const std::string& _value); 00258 00259 00266 EventHandle_WidgetStringString eventChangeProperty; 00267 00272 EventHandle_WidgetVoid eventChangeCoord; 00273 00274 /*internal:*/ 00275 // метод для запроса номера айтема и контейнера 00276 virtual size_t _getItemIndex(Widget* _item); 00277 00278 // дает приоритет виджету при пиккинге 00279 void _forcePick(Widget* _widget); 00280 00281 void _initialise(WidgetStyle _style, const IntCoord& _coord, const std::string& _skinName, Widget* _parent, ICroppedRectangle* _croppedParent, const std::string& _name); 00282 void _shutdown(); 00283 00284 // удяляет неудачника 00285 void _destroyChildWidget(Widget* _widget); 00286 00287 void _setContainer(Widget* _value); 00288 Widget* _getContainer(); 00289 00290 void _setAlign(const IntSize& _oldsize, const IntSize& _newSize); 00291 bool _checkPoint(int _left, int _top) const; 00292 00293 Widget* _createSkinWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = ""); 00294 00295 // сброс всех данных контейнера, тултипы и все остальное 00296 virtual void _resetContainer(bool _update); 00297 00298 bool _setWidgetState(const std::string& _value); 00299 00300 // перерисовывает детей 00301 void _updateChilds(); 00302 00303 protected: 00304 // все создание только через фабрику 00305 virtual ~Widget(); 00306 00307 virtual void shutdownOverride(); 00308 virtual void initialiseOverride(); 00309 00310 void _updateView(); // обновления себя и детей 00311 00312 // создает виджет 00313 Widget* baseCreateWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name, bool _template); 00314 00315 // удаляет всех детей 00316 void _destroyAllChildWidget(); 00317 00318 // запрашиваем у конейтера айтем по позиции мыши 00319 virtual size_t _getContainerIndex(const IntPoint& _point); 00320 00321 virtual void baseUpdateEnable(); 00322 00323 // наследуемся он LayerInfo 00324 virtual ILayerItem* getLayerItemByPoint(int _left, int _top) const; 00325 virtual const IntCoord& getLayerItemCoord() const; 00326 00327 template <typename T> 00328 void assignWidget(T*& _widget, const std::string& _name) 00329 { 00330 _widget = nullptr; 00331 for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter) 00332 { 00333 Widget* find = (*iter)->findWidget(_name); 00334 if (nullptr != find) 00335 { 00336 _widget = find->castType<T>(false); 00337 break; 00338 } 00339 } 00340 } 00341 00342 VectorWidgetPtr getSkinWidgetsByName(const std::string& _name); 00343 00344 void destroySkinWidget(Widget* _widget); 00345 00346 virtual void onWidgetCreated(Widget* _widget); 00347 virtual void onWidgetDestroy(Widget* _widget); 00348 00349 void setWidgetClient(Widget* _widget); 00350 00351 virtual void setPropertyOverride(const std::string& _key, const std::string& _value); 00352 00353 private: 00354 void frameEntered(float _frame); 00355 00356 const WidgetInfo* initialiseWidgetSkinBase(ResourceSkin* _info, ResourceLayout* _templateInfo); 00357 void shutdownWidgetSkinBase(); 00358 00359 void _updateAlpha(); 00360 void _updateAbsolutePoint(); 00361 00362 // для внутреннего использования 00363 void _updateVisible(); 00364 00365 void _updateEnabled(); 00366 00367 float _getRealAlpha() const; 00368 00369 void _createChildSkinWidget(ResourceSkin* _info); 00370 void _destroyChildSkinWidget(); 00371 00372 void _parseSkinProperties(ResourceSkin* _info); 00373 void _checkInheristProperties(); 00374 00375 void _linkChildWidget(Widget* _widget); 00376 void _unlinkChildWidget(Widget* _widget); 00377 00378 void setSkinProperty(ResourceSkin* _info); 00379 00380 virtual void resizeLayerItemView(const IntSize& _oldView, const IntSize& _newView); 00381 00382 void addWidget(Widget* _widget); 00383 00384 private: 00385 // клиентская зона окна 00386 // если виджет имеет пользовательские окна не в себе 00387 // то обязательно проинициализировать Client 00388 Widget* mWidgetClient; 00389 00390 // вектор всех детей виджетов 00391 VectorWidgetPtr mWidgetChild; 00392 00393 // вектор детей скина 00394 VectorWidgetPtr mWidgetChildSkin; 00395 00396 // доступен ли на виджет 00397 bool mEnabled; 00398 bool mInheritsEnabled; 00399 // для иерархического скрытия 00400 bool mInheritsVisible; 00401 // прозрачность и флаг наследования альфы нашего оверлея 00402 float mAlpha; 00403 float mRealAlpha; 00404 bool mInheritsAlpha; 00405 // имя виджета 00406 std::string mName; 00407 00408 // наш отец в иерархии виджетов 00409 Widget* mParent; 00410 00411 // поведение виджета, перекрывающийся дочерний или всплывающий 00412 WidgetStyle mWidgetStyle; 00413 00414 Widget* mContainer; 00415 00416 Align mAlign; 00417 bool mVisible; 00418 int mDepth; 00419 }; 00420 00421 } // namespace MyGUI 00422 00423 #endif // __MYGUI_WIDGET_H__