MyGUI 3.0.1
MyGUI_Widget.h
Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #ifndef __MYGUI_WIDGET_H__
00024 #define __MYGUI_WIDGET_H__
00025 
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Any.h"
00028 #include "MyGUI_ICroppedRectangle.h"
00029 #include "MyGUI_ISubWidgetRect.h"
00030 #include "MyGUI_ISubWidgetText.h"
00031 #include "MyGUI_LayerItem.h"
00032 #include "MyGUI_WidgetUserData.h"
00033 #include "MyGUI_WidgetEvent.h"
00034 #include "MyGUI_IWidgetCreator.h"
00035 #include "MyGUI_ResourceSkin.h"
00036 #include "MyGUI_IObject.h"
00037 
00038 namespace MyGUI
00039 {
00040 
00041     class MYGUI_EXPORT Widget :
00042         public IObject,
00043         public ICroppedRectangle,
00044         public LayerItem,
00045         public UserData,
00046         public WidgetEvent,
00047         public IWidgetCreator,
00048         public delegates::IDelegateUnlink
00049     {
00050         // для вызова закрытых деструкторов
00051         friend class IWidgetCreator;
00052 
00053         MYGUI_RTTI_BASE( 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 
00113         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 = "");
00114 
00116         template <typename T>
00117         T* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer = "", const std::string& _name = "")
00118         {
00119             return static_cast<T*>(createWidgetT(_style, T::getClassTypeName(), _skin, _coord, _align, _layer, _name));
00120         }
00121 
00123         const std::string& getName() const { return mName; }
00124 
00125 
00127         virtual void setPosition(const IntPoint& _value);
00129         virtual void setSize(const IntSize& _value);
00131         virtual void setCoord(const IntCoord& _value);
00132 
00134         void setPosition(int _left, int _top) { setPosition(IntPoint(_left, _top)); }
00136         void setSize(int _width, int _height) { setSize(IntSize(_width, _height)); }
00138         void setCoord(int _left, int _top, int _width, int _height) { setCoord(IntCoord(_left, _top, _width, _height)); }
00139 
00141         void setRealPosition(const FloatPoint& _value);
00143         void setRealSize(const FloatSize& _value);
00145         void setRealCoord(const FloatCoord& _value);
00146 
00148         void setRealPosition(float _left, float _top) { setRealPosition(FloatPoint(_left, _top)); }
00150         void setRealSize(float _width, float _height) { setRealSize(FloatSize(_width, _height)); }
00152         void setRealCoord(float _left, float _top, float _width, float _height) { setRealCoord(FloatCoord(_left, _top, _width, _height)); }
00153 
00155         virtual void setVisible(bool _value);
00156 
00158         virtual void setAlign(Align _value);
00159 
00161         virtual void setCaption(const UString& _value);
00163         virtual const UString& getCaption();
00164 
00166         void setAlpha(float _value);
00168         float getAlpha() { return mAlpha; }
00169 
00171         void setInheritsAlpha(bool _value);
00173         bool isInheritsAlpha() { return mInheritsAlpha; }
00174 
00176         bool setState(const std::string& _value);
00177 
00178         void setColour(const Colour& _value);
00179 
00180         // являемся ли мы рутовым виджетом
00182         bool isRootWidget() { return nullptr == mCroppedParent; }
00183 
00185         Widget* getParent() { return mParent; }
00186 
00188         EnumeratorWidgetPtr getEnumerator();
00189 
00191         size_t getChildCount();
00192 
00194         Widget* getChildAt(size_t _index);
00195 
00197         Widget* findWidget(const std::string& _name);
00198 
00200         void setNeedKeyFocus(bool _value) { mNeedKeyFocus = _value; }
00205         bool isNeedKeyFocus() { return mNeedKeyFocus; }
00206 
00208         void setNeedMouseFocus(bool _value) { mNeedMouseFocus = _value; }
00213         bool isNeedMouseFocus() { return mNeedMouseFocus; }
00214 
00220         void setInheritsPick(bool _value) { mInheritsPick = _value; }
00222         bool isInheritsPick() { return mInheritsPick; }
00223 
00225         void setMaskPick(const std::string& _filename);
00226 
00228         virtual void setEnabled(bool _value);
00230         void setEnabledSilent(bool _value) { mEnabled = _value; }
00232         bool isEnabled() { return mEnabled; }
00233 
00235         void setPointer(const std::string& _value) { mPointer = _value; }
00237         const std::string& getPointer();
00238 
00240         const std::string& getLayerName();
00241 
00243         IntCoord getClientCoord();
00244 
00246         Widget* getClientWidget() { return mWidgetClient; }
00247 
00249         ISubWidgetText * getSubWidgetText() { return mText; }
00251         ISubWidgetRect * getSubWidgetMain() { return mMainSkin; }
00252 
00254         void setNeedToolTip(bool _value);
00256         bool getNeedToolTip() { return mNeedToolTip; }
00257 
00259         void setEnableToolTip(bool _value);
00261         bool getEnableToolTip() { return mEnableToolTip; }
00262 
00266         void detachFromWidget(const std::string& _layer = "");
00267 
00274         void attachToWidget(Widget* _parent, WidgetStyle _style = WidgetStyle::Child, const std::string& _layer = "");
00275 
00277         void changeWidgetSkin(const std::string& _skinname);
00278 
00284         void setWidgetStyle(WidgetStyle _style, const std::string& _layer = "");
00286         WidgetStyle getWidgetStyle() { return mWidgetStyle; }
00287 
00292         virtual void setProperty(const std::string& _key, const std::string& _value);
00293 
00294 
00295     /*internal:*/
00296         // метод для запроса номера айтема и контейнера
00297         virtual void _getContainer(Widget*& _container, size_t& _index);
00298 
00299         // дает приоритет виджету при пиккинге
00300         void _forcePeek(Widget* _widget);
00301 
00302         void _setUVSet(const FloatRect& _rect);
00303 
00304         virtual void _setTextureName(const std::string& _texture);
00305         virtual const std::string& _getTextureName();
00306 
00307         IWidgetCreator * _getIWidgetCreator() { return mIWidgetCreator; }
00308 
00309         IntCoord _getTextRegion();
00310         IntSize _getTextSize();
00311         void _setFontName(const std::string& _font);
00312         const std::string& _getFontName();
00313         void _setFontHeight(int _height);
00314         int _getFontHeight();
00315         void _setTextAlign(Align _align);
00316         Align _getTextAlign();
00317         void _setTextColour(const Colour& _colour);
00318         const Colour& _getTextColour();
00319 
00320         // устанавливает строку заменив /n на реальный перенос
00321         void setCaptionWithNewLine(const std::string& _value);
00322         virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name);
00323 
00324 
00325     /*obsolete:*/
00326 #ifndef MYGUI_DONT_USE_OBSOLETE
00327 
00328         MYGUI_OBSOLETE("use : void Widget::setCoord(const IntCoord& _coord)")
00329         void setPosition(const IntCoord& _coord) { setCoord(_coord); }
00330         MYGUI_OBSOLETE("use : void Widget::setCoord(int _left, int _top, int _width, int _height)")
00331         void setPosition(int _left, int _top, int _width, int _height) { setCoord(_left, _top, _width, _height); }
00332 
00333         MYGUI_OBSOLETE("use : void Widget::setEnableToolTip")
00334         void enableToolTip(bool _enable) { setEnableToolTip(_enable); }
00335 
00336         MYGUI_OBSOLETE("use : void setInheritsPick(bool _inherits)")
00337         void setInheritsPeek(bool _inherits) { setInheritsPick(_inherits); }
00338         MYGUI_OBSOLETE("use : bool isInheritsPick()")
00339         bool isInheritsPeek() { return isInheritsPick(); }
00340 
00341         MYGUI_OBSOLETE("use : void setMaskPick(const std::string& _filename)")
00342         void setMaskPeek(const std::string& _filename) { setMaskPick(_filename); }
00343 
00344         MYGUI_OBSOLETE("use : const IntCoord& StaticText::getTextRegion()")
00345         IntCoord getTextCoord() { return _getTextRegion(); }
00346         MYGUI_OBSOLETE("use : IntSize StaticText::getTextSize()")
00347         IntSize getTextSize() { return _getTextSize(); }
00348 
00349         MYGUI_OBSOLETE("use : void StaticText::setFontName(const std::string& _font)")
00350         void setFontName(const std::string& _font) { _setFontName(_font); }
00351         MYGUI_OBSOLETE("use : const std::string& StaticText::getFontName()")
00352         const std::string& getFontName() { return _getFontName(); }
00353 
00354         MYGUI_OBSOLETE("use : void StaticText::setFontHeight(int _height)")
00355         void setFontHeight(int _height) { _setFontHeight(_height); }
00356         MYGUI_OBSOLETE("use : int StaticText::getFontHeight()")
00357         int getFontHeight() { return _getFontHeight(); }
00358 
00359         MYGUI_OBSOLETE("use : void StaticText::setTextAlign(Align _align)")
00360         void setTextAlign(Align _align) { _setTextAlign(_align); }
00361         MYGUI_OBSOLETE("use : Align StaticText::getTextAlign()")
00362         Align getTextAlign() { return _getTextAlign(); }
00363 
00364         MYGUI_OBSOLETE("use : void StaticText::setTextColour(const Colour& _colour)")
00365         void setTextColour(const Colour& _colour) { _setTextColour(_colour); }
00366         MYGUI_OBSOLETE("use : const Colour& StaticText::getTextColour()")
00367         const Colour& getTextColour() { return _getTextColour(); }
00368 
00369 #endif // MYGUI_DONT_USE_OBSOLETE
00370 
00371     protected:
00372         // все создание только через фабрику
00373         Widget(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name);
00374         virtual ~Widget();
00375 
00376         virtual void baseChangeWidgetSkin(ResourceSkin* _info);
00377 
00378         void _updateView(); // обновления себя и детей
00379 
00380         void _setAlign(const IntSize& _oldsize, bool _update);
00381         void _setAlign(const IntCoord& _oldcoord, bool _update);
00382 
00383         // создает виджет
00384         virtual 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);
00385 
00386         // удяляет неудачника
00387         virtual void _destroyChildWidget(Widget* _widget);
00388 
00389         // удаляет всех детей
00390         virtual void _destroyAllChildWidget();
00391 
00392         // запрашиваем у конейтера айтем по позиции мыши
00393         virtual size_t _getContainerIndex(const IntPoint& _point) { return ITEM_NONE; }
00394 
00395         // сброс всех данных контейнера, тултипы и все остальное
00396         virtual void _resetContainer(bool _update);
00397 
00398         virtual void baseUpdateEnable();
00399 
00400         // наследуемся он LayerInfo
00401         virtual ILayerItem * getLayerItemByPoint(int _left, int _top);
00402         virtual const IntCoord& getLayerItemCoord() { return mCoord; }
00403 
00404     private:
00405 
00406         void frameEntered(float _frame);
00407 
00408         void initialiseWidgetSkin(ResourceSkin* _info, const IntSize& _size);
00409         void shutdownWidgetSkin(bool _deep = false);
00410 
00411         void _updateAlpha();
00412         void _updateAbsolutePoint();
00413 
00414         // для внутреннего использования
00415         void _setInheritsVisible(bool _value);
00416         bool _isInheritsVisible() { return mInheritsVisible; }
00417 
00418         void _setInheritsEnable(bool _value);
00419         bool _isInheritsEnable() { return mInheritsEnabled; }
00420 
00421         // показывает скрывает все сабскины
00422         void _setSubSkinVisible(bool _visible);
00423 
00424         float _getRealAlpha() { return mRealAlpha; }
00425 
00426         // добавляет в список виджет
00427         virtual void _linkChildWidget(Widget* _widget);
00428         // удаляет из списка
00429         virtual void _unlinkChildWidget(Widget* _widget);
00430 
00431     protected:
00432         // список всех стейтов
00433         MapWidgetStateInfo mStateInfo;
00434         // информация о маске для пикинга
00435         MaskPickInfo const * mMaskPickInfo;
00436         MaskPickInfo mOwnMaskPickInfo;
00437 
00438         // вектор всех детей виджетов
00439         VectorWidgetPtr mWidgetChild;
00440         // вектор детей скина
00441         VectorWidgetPtr mWidgetChildSkin;
00442         // вектор всех детей сабскинов
00443         VectorSubWidget mSubSkinChild;
00444 
00445         // указатель на окно текста
00446         ISubWidgetText * mText;
00447         // указатель на первый не текстовой сабскин
00448         ISubWidgetRect * mMainSkin;
00449 
00450         // доступен ли на виджет
00451         bool mEnabled;
00452         bool mInheritsEnabled;
00453         // скрыты ли все сабскины при выходе за границу
00454         bool mSubSkinsVisible;
00455         // для иерархического скрытия
00456         bool mInheritsVisible;
00457         // прозрачность и флаг наследования альфы нашего оверлея
00458         float mAlpha;
00459         float mRealAlpha;
00460         bool mInheritsAlpha;
00461         // имя виджета
00462         std::string mName;
00463         // курсор который будет показан при наведении
00464         std::string mPointer;
00465         std::string mTextureName;
00466         ITexture* mTexture;
00467 
00468         // наш отец в иерархии виджетов
00469         Widget* mParent;
00470 
00471         // это тот кто нас создал, и кто нас будет удалять
00472         IWidgetCreator * mIWidgetCreator;
00473 
00474         // нужен ли виджету ввод с клавы
00475         bool mNeedKeyFocus;
00476         // нужен ли виджету фокус мыши
00477         bool mNeedMouseFocus;
00478         bool mInheritsPick;
00479 
00480         // клиентская зона окна
00481         // если виджет имеет пользовательские окна не в себе
00482         // то обязательно проинициализировать Client
00483         Widget* mWidgetClient;
00484 
00485         bool mNeedToolTip;
00486         bool mEnableToolTip;
00487         bool mToolTipVisible;
00488         float mToolTipCurrentTime;
00489         IntPoint mToolTipOldPoint;
00490         size_t mToolTipOldIndex;
00491         IntPoint m_oldMousePoint;
00492 
00493         // поведение виджета, перекрывающийся дочерний или всплывающий
00494         WidgetStyle mWidgetStyle;
00495 
00496         FloatCoord mRelativeCoord;
00497         bool mDisableUpdateRelative;
00498 
00499     };
00500 
00501 } // namespace MyGUI
00502 
00503 #endif // __MYGUI_WIDGET_H__