MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #ifndef __MYGUI_WIDGET_H__ 00023 #define __MYGUI_WIDGET_H__ 00024 00025 #include "MyGUI_Prerequest.h" 00026 #include "MyGUI_Any.h" 00027 #include "MyGUI_ICroppedRectangle.h" 00028 #include "MyGUI_WidgetUserData.h" 00029 #include "MyGUI_WidgetInput.h" 00030 #include "MyGUI_ResourceSkin.h" 00031 #include "MyGUI_ResourceLayout.h" 00032 #include "MyGUI_IObject.h" 00033 #include "MyGUI_SkinItem.h" 00034 #include "MyGUI_BackwardCompatibility.h" 00035 00036 namespace MyGUI 00037 { 00038 00039 typedef delegates::CMultiDelegate3<Widget*, const std::string&, const std::string&> EventHandle_WidgetStringString; 00040 00041 class MYGUI_EXPORT Widget : 00042 public IObject, 00043 public ICroppedRectangle, 00044 public UserData, 00045 public WidgetInput, 00046 public delegates::IDelegateUnlink, 00047 public SkinItem, 00048 public MemberObsolete<Widget> 00049 { 00050 // для вызова закрытых деструкторов 00051 friend class WidgetManager; 00052 00053 MYGUI_RTTI_DERIVED( Widget ) 00054 00055 public: 00056 Widget(); 00057 00065 Widget* createWidgetT(const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = ""); 00066 00068 Widget* createWidgetT(const std::string& _type, const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = ""); 00069 00071 Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = ""); 00072 00074 Widget* createWidgetRealT(const std::string& _type, const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = ""); 00075 00076 // templates for creating widgets by type 00078 template <typename T> 00079 T* createWidget(const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = "") 00080 { 00081 return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, _coord, _align, _name)); 00082 } 00083 00085 template <typename T> 00086 T* createWidget(const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = "") 00087 { 00088 return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, IntCoord(_left, _top, _width, _height), _align, _name)); 00089 } 00090 00092 template <typename T> 00093 T* createWidgetReal(const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = "") 00094 { 00095 return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _coord, _align, _name)); 00096 } 00097 00099 template <typename T> 00100 T* createWidgetReal(const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = "") 00101 { 00102 return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _left, _top, _width, _height, _align, _name)); 00103 } 00104 00114 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 = ""); 00115 00117 template <typename T> 00118 T* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = "") 00119 { 00120 return static_cast<T*>(createWidgetT(_style, T::getClassTypeName(), _skin, _coord, _align, _layer, _name)); 00121 } 00122 00124 virtual void setPosition(const IntPoint& _value); 00126 virtual void setSize(const IntSize& _value); 00128 virtual void setCoord(const IntCoord& _value); 00129 00131 void setPosition(int _left, int _top); 00133 void setSize(int _width, int _height); 00135 void setCoord(int _left, int _top, int _width, int _height); 00136 00138 void setRealPosition(const FloatPoint& _value); 00140 void setRealSize(const FloatSize& _value); 00142 void setRealCoord(const FloatCoord& _value); 00143 00145 void setRealPosition(float _left, float _top); 00147 void setRealSize(float _width, float _height); 00149 void setRealCoord(float _left, float _top, float _width, float _height); 00150 00152 const std::string& getName() const; 00153 00155 virtual void setVisible(bool _value); 00157 bool getVisible() const; 00158 00160 bool getInheritedVisible() const; 00161 00163 virtual void setAlign(Align _value); 00165 Align getAlign() const; 00166 00168 void setAlpha(float _value); 00170 float getAlpha() const; 00171 00182 void setInheritsAlpha(bool _value); 00184 bool getInheritsAlpha() const; 00185 00186 void setColour(const Colour& _value); 00187 00188 // являемся ли мы рутовым виджетом 00190 bool isRootWidget() const; 00191 00193 Widget* getParent() const; 00194 00195 IntSize getParentSize() const; 00196 00198 EnumeratorWidgetPtr getEnumerator() const; 00199 00201 size_t getChildCount(); 00202 00204 Widget* getChildAt(size_t _index); 00205 00210 Widget* findWidget(const std::string& _name); 00211 00215 void findWidgets(const std::string& _name, VectorWidgetPtr& _result); 00216 00218 virtual void setEnabled(bool _value); 00220 void setEnabledSilent(bool _value); 00222 bool getEnabled() const; 00223 00225 bool getInheritedEnabled() const; 00226 00228 IntCoord getClientCoord(); 00229 00231 Widget* getClientWidget(); 00232 00236 void detachFromWidget(const std::string& _layer = ""); 00237 00243 void attachToWidget(Widget* _parent, WidgetStyle _style = WidgetStyle::Child, const std::string& _layer = ""); 00244 00246 void changeWidgetSkin(const std::string& _skinName); 00247 00253 void setWidgetStyle(WidgetStyle _style, const std::string& _layer = ""); 00255 WidgetStyle getWidgetStyle() const; 00256 00261 void setProperty(const std::string& _key, const std::string& _value); 00262 00263 00270 EventHandle_WidgetStringString 00271 eventChangeProperty; 00272 00273 /*internal:*/ 00274 // метод для запроса номера айтема и контейнера 00275 virtual size_t _getItemIndex(Widget* _item); 00276 00277 // дает приоритет виджету при пиккинге 00278 void _forcePick(Widget* _widget); 00279 00280 void _initialise(WidgetStyle _style, const IntCoord& _coord, const std::string& _skinName, Widget* _parent, ICroppedRectangle* _croppedParent, const std::string& _name); 00281 void _shutdown(); 00282 00283 // удяляет неудачника 00284 void _destroyChildWidget(Widget* _widget); 00285 00286 void _setContainer(Widget* _value); 00287 Widget* _getContainer(); 00288 00289 void _setAlign(const IntSize& _oldsize, const IntSize& _newSize); 00290 bool _checkPoint(int _left, int _top) const; 00291 00292 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 = ""); 00293 00294 // сброс всех данных контейнера, тултипы и все остальное 00295 virtual void _resetContainer(bool _update); 00296 00297 bool _setWidgetState(const std::string& _value); 00298 00299 protected: 00300 // все создание только через фабрику 00301 virtual ~Widget(); 00302 00303 virtual void shutdownOverride(); 00304 virtual void initialiseOverride(); 00305 00306 void _updateView(); // обновления себя и детей 00307 00308 // создает виджет 00309 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); 00310 00311 // удаляет всех детей 00312 void _destroyAllChildWidget(); 00313 00314 // запрашиваем у конейтера айтем по позиции мыши 00315 virtual size_t _getContainerIndex(const IntPoint& _point); 00316 00317 virtual void baseUpdateEnable(); 00318 00319 // наследуемся он LayerInfo 00320 virtual ILayerItem* getLayerItemByPoint(int _left, int _top) const; 00321 virtual const IntCoord& getLayerItemCoord() const; 00322 00323 template <typename T> 00324 void assignWidget(T * & _widget, const std::string& _name) 00325 { 00326 _widget = nullptr; 00327 for (VectorWidgetPtr::iterator iter = mWidgetChildSkin.begin(); iter != mWidgetChildSkin.end(); ++iter) 00328 { 00329 Widget* find = (*iter)->findWidget(_name); 00330 if (nullptr != find) 00331 { 00332 _widget = find->castType<T>(false); 00333 break; 00334 } 00335 } 00336 } 00337 00338 VectorWidgetPtr getSkinWidgetsByName(const std::string& _name); 00339 00340 void destroySkinWidget(Widget* _widget); 00341 00342 virtual void onWidgetCreated(Widget* _widget); 00343 virtual void onWidgetDestroy(Widget* _widget); 00344 00345 void setWidgetClient(Widget* _widget); 00346 00347 virtual void setPropertyOverride(const std::string& _key, const std::string& _value); 00348 00349 private: 00350 void frameEntered(float _frame); 00351 00352 const WidgetInfo* initialiseWidgetSkinBase(ResourceSkin* _info, ResourceLayout* _templateInfo); 00353 void shutdownWidgetSkinBase(); 00354 00355 void _updateAlpha(); 00356 void _updateAbsolutePoint(); 00357 00358 // для внутреннего использования 00359 void _updateVisible(); 00360 00361 void _updateEnabled(); 00362 00363 float _getRealAlpha() const; 00364 00365 void _createChildSkinWidget(ResourceSkin* _info); 00366 void _destroyChildSkinWidget(); 00367 00368 void _parseSkinProperties(ResourceSkin* _info); 00369 void _checkInheristProperties(); 00370 00371 void _linkChildWidget(Widget* _widget); 00372 void _unlinkChildWidget(Widget* _widget); 00373 00374 void setSkinProperty(ResourceSkin* _info); 00375 00376 virtual void resizeLayerItemView(const IntSize& _oldView, const IntSize& _newView); 00377 00378 private: 00379 // клиентская зона окна 00380 // если виджет имеет пользовательские окна не в себе 00381 // то обязательно проинициализировать Client 00382 Widget* mWidgetClient; 00383 00384 // вектор всех детей виджетов 00385 VectorWidgetPtr mWidgetChild; 00386 00387 // вектор детей скина 00388 VectorWidgetPtr mWidgetChildSkin; 00389 00390 // доступен ли на виджет 00391 bool mEnabled; 00392 bool mInheritsEnabled; 00393 // для иерархического скрытия 00394 bool mInheritsVisible; 00395 // прозрачность и флаг наследования альфы нашего оверлея 00396 float mAlpha; 00397 float mRealAlpha; 00398 bool mInheritsAlpha; 00399 // имя виджета 00400 std::string mName; 00401 00402 // наш отец в иерархии виджетов 00403 Widget* mParent; 00404 00405 // поведение виджета, перекрывающийся дочерний или всплывающий 00406 WidgetStyle mWidgetStyle; 00407 00408 Widget* mContainer; 00409 00410 Align mAlign; 00411 bool mVisible; 00412 }; 00413 00414 } // namespace MyGUI 00415 00416 #endif // __MYGUI_WIDGET_H__