• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

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_RTTI.h"
00028 #include "MyGUI_Any.h"
00029 #include "MyGUI_ICroppedRectangle.h"
00030 #include "MyGUI_ISubWidgetRect.h"
00031 #include "MyGUI_ISubWidgetText.h"
00032 #include "MyGUI_LayerItem.h"
00033 #include "MyGUI_WidgetUserData.h"
00034 #include "MyGUI_WidgetEvent.h"
00035 #include "MyGUI_IWidgetCreator.h"
00036 #include "MyGUI_ResourceSkin.h"
00037 #include "MyGUI_IObject.h"
00038 
00039 namespace MyGUI
00040 {
00041 
00042     class MYGUI_EXPORT Widget :
00043         public IObject,
00044         public ICroppedRectangle,
00045         public LayerItem,
00046         public UserData,
00047         public WidgetEvent,
00048         public IWidgetCreator,
00049         public delegates::IDelegateUnlink
00050     {
00051         // для вызова закрытых деструкторов
00052         friend class IWidgetCreator;
00053 
00054         MYGUI_RTTI_BASE( Widget );
00055 
00056     public:
00057         Widget();
00058 
00066         WidgetPtr createWidgetT(const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = "");
00067 
00069         WidgetPtr createWidgetT(const std::string& _type, const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = "");
00070 
00072         WidgetPtr createWidgetRealT(const std::string& _type, const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = "");
00073 
00075         WidgetPtr createWidgetRealT(const std::string& _type, const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = "");
00076 
00077         // templates for creating widgets by type
00079         template <typename T>
00080         T* createWidget(const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _name = "")
00081         {
00082             return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, _coord, _align, _name));
00083         }
00084 
00086         template <typename T>
00087         T* createWidget(const std::string& _skin, int _left, int _top, int _width, int _height, Align _align, const std::string& _name = "")
00088         {
00089             return static_cast<T*>(createWidgetT(T::getClassTypeName(), _skin, IntCoord(_left, _top, _width, _height), _align, _name));
00090         }
00091 
00093         template <typename T>
00094         T* createWidgetReal(const std::string& _skin, const FloatCoord& _coord, Align _align, const std::string& _name = "")
00095         {
00096             return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _coord, _align, _name));
00097         }
00098 
00100         template <typename T>
00101         T* createWidgetReal(const std::string& _skin, float _left, float _top, float _width, float _height, Align _align, const std::string& _name = "")
00102         {
00103             return static_cast<T*>(createWidgetRealT(T::getClassTypeName(), _skin, _left, _top, _width, _height, _align, _name));
00104         }
00105 
00114         WidgetPtr 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         const std::string& getName() { return mName; }
00125 
00126 
00128         virtual void setPosition(const IntPoint& _value);
00130         virtual void setSize(const IntSize& _value);
00132         virtual void setCoord(const IntCoord& _value);
00133 
00135         void setPosition(int _left, int _top) { setPosition(IntPoint(_left, _top)); }
00137         void setSize(int _width, int _height) { setSize(IntSize(_width, _height)); }
00139         void setCoord(int _left, int _top, int _width, int _height) { setCoord(IntCoord(_left, _top, _width, _height)); }
00140 
00142         void setRealPosition(const FloatPoint& _value);
00144         void setRealSize(const FloatSize& _value);
00146         void setRealCoord(const FloatCoord& _value);
00147 
00149         void setRealPosition(float _left, float _top) { setRealPosition(FloatPoint(_left, _top)); }
00151         void setRealSize(float _width, float _height) { setRealSize(FloatSize(_width, _height)); }
00153         void setRealCoord(float _left, float _top, float _width, float _height) { setRealCoord(FloatCoord(_left, _top, _width, _height)); }
00154 
00156         virtual void setVisible(bool _value);
00157 
00159         virtual void setAlign(Align _value);
00160 
00162         virtual void setCaption(const UString& _value);
00164         virtual const UString& getCaption();
00165 
00167         void setAlpha(float _value);
00169         float getAlpha() { return mAlpha; }
00170 
00172         void setInheritsAlpha(bool _value);
00174         bool isInheritsAlpha() { return mInheritsAlpha; }
00175 
00177         bool setState(const std::string& _value);
00178 
00179         // являемся ли мы рутовым виджетом
00181         bool isRootWidget() { return nullptr == mCroppedParent; }
00182 
00184         WidgetPtr getParent() { return mParent; }
00185 
00187         EnumeratorWidgetPtr getEnumerator();
00188 
00190         size_t getChildCount();
00191 
00193         WidgetPtr getChildAt(size_t _index);
00194 
00196         WidgetPtr findWidget(const std::string& _name);
00197 
00199         void setNeedKeyFocus(bool _value) { mNeedKeyFocus = _value; }
00204         bool isNeedKeyFocus() { return mNeedKeyFocus; }
00205 
00207         void setNeedMouseFocus(bool _value) { mNeedMouseFocus = _value; }
00212         bool isNeedMouseFocus() { return mNeedMouseFocus; }
00213 
00219         void setInheritsPick(bool _value) { mInheritsPick = _value; }
00221         bool isInheritsPick() { return mInheritsPick; }
00222 
00224         void setMaskPick(const std::string& _filename);
00225 
00227         virtual void setEnabled(bool _value);
00229         void setEnabledSilent(bool _value) { mEnabled = _value; }
00231         bool isEnabled() { return mEnabled; }
00232 
00234         void setPointer(const std::string& _value) { mPointer = _value; }
00236         const std::string& getPointer();
00237 
00239         const std::string& getLayerName();
00240 
00242         IntCoord getClientCoord();
00243 
00245         WidgetPtr getClientWidget() { return mWidgetClient; }
00246 
00248         ISubWidgetText * getSubWidgetText() { return mText; }
00250         ISubWidgetRect * getSubWidgetMain() { return mMainSkin; }
00251 
00253         void setNeedToolTip(bool _value);
00255         bool getNeedToolTip() { return mNeedToolTip; }
00256 
00258         void setEnableToolTip(bool _value);
00260         bool getEnableToolTip() { return mEnableToolTip; }
00261 
00262         //DESCRIBEME
00264         void detachFromWidget(const std::string& _layer = "");
00265 
00266         //DESCRIBEME
00271         void attachToWidget(WidgetPtr _parent, WidgetStyle _style = WidgetStyle::Child, const std::string& _layer = "");
00272 
00274         void changeWidgetSkin(const std::string& _skinname);
00275 
00276         //DESCRIBEME
00281         void setWidgetStyle(WidgetStyle _style, const std::string& _layer = "");
00283         WidgetStyle getWidgetStyle() { return mWidgetStyle; }
00284 
00285 
00286         //DESCRIBEME
00287         // устанавливаем свойство
00288         virtual void setProperty(const std::string& _key, const std::string& _value);
00289 
00290 
00291     /*internal:*/
00292         // метод для запроса номера айтема и контейнера
00293         virtual void _getContainer(WidgetPtr& _container, size_t& _index);
00294 
00295         // дает приоритет виджету при пиккинге
00296         void _forcePeek(WidgetPtr _widget);
00297 
00298         void _setUVSet(const FloatRect& _rect);
00299 
00300         virtual void _setTextureName(const std::string& _texture);
00301         virtual const std::string& _getTextureName();
00302 
00303         IWidgetCreator * _getIWidgetCreator() { return mIWidgetCreator; }
00304 
00305         IntCoord _getTextRegion();
00306         IntSize _getTextSize();
00307         void _setFontName(const std::string& _font);
00308         const std::string& _getFontName();
00309         void _setFontHeight(int _height);
00310         int _getFontHeight();
00311         void _setTextAlign(Align _align);
00312         Align _getTextAlign();
00313         void _setTextColour(const Colour& _colour);
00314         const Colour& _getTextColour();
00315 
00316         // наследуемся он LayerInfo
00317         virtual ILayerItem * getLayerItemByPoint(int _left, int _top);
00318         virtual const IntCoord& getLayerItemCoord() { return mCoord; }
00319 
00320         // устанавливает строку заменив /n на реальный перенос
00321         void setCaptionWithNewLine(const std::string& _value);
00322         virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, WidgetPtr _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::setTextColour(const Colour& _colour)")
00350         void setColour(const Colour& _colour) { _setTextColour(_colour); }
00351         MYGUI_OBSOLETE("use : const Colour& StaticText::getTextColour()")
00352         const Colour& getColour() { return _getTextColour(); }
00353 
00354         MYGUI_OBSOLETE("use : void StaticText::setFontName(const std::string& _font)")
00355         void setFontName(const std::string& _font) { _setFontName(_font); }
00356         MYGUI_OBSOLETE("use : const std::string& StaticText::getFontName()")
00357         const std::string& getFontName() { return _getFontName(); }
00358 
00359         MYGUI_OBSOLETE("use : void StaticText::setFontHeight(int _height)")
00360         void setFontHeight(int _height) { _setFontHeight(_height); }
00361         MYGUI_OBSOLETE("use : int StaticText::getFontHeight()")
00362         int getFontHeight() { return _getFontHeight(); }
00363 
00364         MYGUI_OBSOLETE("use : void StaticText::setTextAlign(Align _align)")
00365         void setTextAlign(Align _align) { _setTextAlign(_align); }
00366         MYGUI_OBSOLETE("use : Align StaticText::getTextAlign()")
00367         Align getTextAlign() { return _getTextAlign(); }
00368 
00369         MYGUI_OBSOLETE("use : void StaticText::setTextColour(const Colour& _colour)")
00370         void setTextColour(const Colour& _colour) { _setTextColour(_colour); }
00371         MYGUI_OBSOLETE("use : const Colour& StaticText::getTextColour()")
00372         const Colour& getTextColour() { return _getTextColour(); }
00373 
00374 #endif // MYGUI_DONT_USE_OBSOLETE
00375 
00376     protected:
00377         // все создание только через фабрику
00378         Widget(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, WidgetPtr _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name);
00379         virtual ~Widget();
00380 
00381         virtual void baseChangeWidgetSkin(ResourceSkin* _info);
00382 
00383         void _updateView(); // обновления себя и детей
00384 
00385         void _setAlign(const IntSize& _oldsize, bool _update);
00386         void _setAlign(const IntCoord& _oldcoord, bool _update);
00387 
00388         // создает виджет
00389         virtual WidgetPtr baseCreateWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name);
00390 
00391         // удяляет неудачника
00392         virtual void _destroyChildWidget(WidgetPtr _widget);
00393 
00394         // удаляет всех детей
00395         virtual void _destroyAllChildWidget();
00396 
00397         // запрашиваем у конейтера айтем по позиции мыши
00398         virtual size_t _getContainerIndex(const IntPoint& _point) { return ITEM_NONE; }
00399 
00400         // сброс всех данных контейнера, тултипы и все остальное
00401         virtual void _resetContainer(bool _update);
00402 
00403         virtual void baseUpdateEnable();
00404 
00405     private:
00406 
00407         void frameEntered(float _frame);
00408 
00409         void initialiseWidgetSkin(ResourceSkin* _info, const IntSize& _size);
00410         void shutdownWidgetSkin(bool _deep = false);
00411 
00412         void _updateAlpha();
00413         void _updateAbsolutePoint();
00414 
00415         // для внутреннего использования
00416         void _setInheritsVisible(bool _value);
00417         bool _isInheritsVisible() { return mInheritsVisible; }
00418 
00419         void _setInheritsEnable(bool _value);
00420         bool _isInheritsEnable() { return mInheritsEnabled; }
00421 
00422         // показывает скрывает все сабскины
00423         void _setSubSkinVisible(bool _visible);
00424 
00425         float _getRealAlpha() { return mRealAlpha; }
00426 
00427         // добавляет в список виджет
00428         virtual void _linkChildWidget(WidgetPtr _widget);
00429         // удаляет из списка
00430         virtual void _unlinkChildWidget(WidgetPtr _widget);
00431 
00432     protected:
00433         // список всех стейтов
00434         MapWidgetStateInfo mStateInfo;
00435         // информация о маске для пикинга
00436         MaskPickInfo const * mMaskPickInfo;
00437         MaskPickInfo mOwnMaskPickInfo;
00438 
00439         // вектор всех детей виджетов
00440         VectorWidgetPtr mWidgetChild;
00441         // вектор детей скина
00442         VectorWidgetPtr mWidgetChildSkin;
00443         // вектор всех детей сабскинов
00444         VectorSubWidget mSubSkinChild;
00445 
00446         // указатель на окно текста
00447         ISubWidgetText * mText;
00448         // указатель на первый не текстовой сабскин
00449         ISubWidgetRect * mMainSkin;
00450 
00451         // доступен ли на виджет
00452         bool mEnabled;
00453         bool mInheritsEnabled;
00454         // скрыты ли все сабскины при выходе за границу
00455         bool mSubSkinsVisible;
00456         // для иерархического скрытия
00457         bool mInheritsVisible;
00458         // прозрачность и флаг наследования альфы нашего оверлея
00459         float mAlpha;
00460         float mRealAlpha;
00461         bool mInheritsAlpha;
00462         // имя виджета
00463         std::string mName;
00464         // курсор который будет показан при наведении
00465         std::string mPointer;
00466         std::string mTexture;
00467 
00468         // наш отец в иерархии виджетов
00469         WidgetPtr mParent;
00470 
00471         // это тот кто нас создал, и кто нас будет удалять
00472         IWidgetCreator * mIWidgetCreator;
00473 
00474         // нужен ли виджету ввод с клавы
00475         bool mNeedKeyFocus;
00476         // нужен ли виджету фокус мыши
00477         bool mNeedMouseFocus;
00478         bool mInheritsPick;
00479 
00480         // клиентская зона окна
00481         // если виджет имеет пользовательские окна не в себе
00482         // то обязательно проинициализировать Client
00483         WidgetPtr 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         size_t mOldToolTipIndex;
00493 
00494         // поведение виджета, перекрывающийся дочерний или всплывающий
00495         WidgetStyle mWidgetStyle;
00496 
00497         FloatCoord mRelativeCoord;
00498         bool mDisableUpdateRelative;
00499 
00500     };
00501 
00502 } // namespace MyGUI
00503 
00504 #endif // __MYGUI_WIDGET_H__

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1