MyGUI 3.4.1
MyGUI_SkinItem.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_SkinItem.h"
10#include "MyGUI_Widget.h"
11#include "MyGUI_RenderManager.h"
13
14namespace MyGUI
15{
17 mText(nullptr),
18 mMainSkin(nullptr),
19 mTexture(nullptr),
20 mSubSkinsVisible(true)
21 {
22 }
23
25 {
26 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
27 (*skin)->_setAlign(_size);
28 }
29
31 {
32 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
33 (*skin)->setVisible(_value);
34 }
35
37 {
38 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
39 {
40 ISubWidgetRect* rect = (*skin)->castType<ISubWidgetRect>(false);
41 if (rect)
42 rect->_setColour(_value);
43 }
44 }
45
46 void SkinItem::_setSkinItemAlpha(float _value)
47 {
48 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
49 (*skin)->setAlpha(_value);
50 }
51
53 {
54 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
55 (*skin)->_correctView();
56 }
57
59 {
60 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
61 (*skin)->_updateView();
62 }
63
64 bool SkinItem::_setSkinItemState(const std::string& _state)
65 {
66 MapWidgetStateInfo::const_iterator iter = mStateInfo.find(_state);
67 if (iter == mStateInfo.end())
68 return false;
69
70 size_t index = 0;
71 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin, ++index)
72 {
73 IStateInfo* data = (*iter).second[index];
74 if (data != nullptr)
75 (*skin)->setStateData(data);
76 }
77 return true;
78 }
79
81 {
82 mStateInfo = _info->getStateInfo();
83
84 // все что с текстурой можно тоже перенести в скин айтем и setRenderItemTexture
85 mTextureName = _info->getTextureName();
86 mTexture = RenderManager::getInstance().getTexture(mTextureName);
87
88 setRenderItemTexture(mTexture);
89
90 std::string categoryName = SubWidgetManager::getInstance().getCategoryName();
91 // загружаем кирпичики виджета
93 for (VectorSubWidgetInfo::const_iterator iter = _info->getBasisInfo().begin(); iter != _info->getBasisInfo().end(); ++iter)
94 {
95 IObject* object = factory.createObject(categoryName, (*iter).type);
96 if (object == nullptr)
97 continue;
98
99 ISubWidget* sub = object->castType<ISubWidget>();
100 sub->_setCroppedParent(static_cast<Widget*>(this));
101 sub->setCoord((*iter).coord);
102 sub->setAlign((*iter).align);
103
104 mSubSkinChild.push_back(sub);
105 addRenderItem(sub);
106
107 // ищем дефолтные сабвиджеты
108 if (mMainSkin == nullptr)
109 mMainSkin = sub->castType<ISubWidgetRect>(false);
110 if (mText == nullptr)
111 mText = sub->castType<ISubWidgetText>(false);
112 }
113
114 _setSkinItemState("normal");
115 }
116
118 {
119 mTexture = nullptr;
120
121 mStateInfo.clear();
122
124 // удаляем все сабскины
125 mMainSkin = nullptr;
126 mText = nullptr;
127
128 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
129 delete (*skin);
130 mSubSkinChild.clear();
131 }
132
133 void SkinItem::_setTextureName(const std::string& _texture)
134 {
135 mTextureName = _texture;
136 mTexture = RenderManager::getInstance().getTexture(mTextureName);
137
138 setRenderItemTexture(mTexture);
139 }
140
141 const std::string& SkinItem::_getTextureName() const
142 {
143 return mTextureName;
144 }
145
147 {
148 if (mSubSkinsVisible == _visible)
149 return;
150 mSubSkinsVisible = _visible;
151
153 }
154
156 {
157 return mText;
158 }
159
161 {
162 return mMainSkin;
163 }
164
165} // namespace MyGUI
static FactoryManager & getInstance()
IObject * createObject(const std::string &_category, const std::string &_type)
virtual void setCoord(const IntCoord &_value)
void _setCroppedParent(ICroppedRectangle *_parent)
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
virtual void setAlign(Align _value)
virtual void _setColour(const Colour &_value)
void addRenderItem(ISubWidget *_item)
void setRenderItemTexture(ITexture *_texture)
virtual ITexture * getTexture(const std::string &_name)=0
static RenderManager & getInstance()
const MapWidgetStateInfo & getStateInfo() const
const VectorSubWidgetInfo & getBasisInfo() const
const std::string & getTextureName() const
ISubWidgetRect * getSubWidgetMain() const
void _correctSkinItemView()
ISubWidgetText * getSubWidgetText() const
void _setSkinItemAlpha(float _value)
void _createSkinItem(ResourceSkin *_info)
void _setSkinItemColour(const Colour &_value)
const std::string & _getTextureName() const
bool _setSkinItemState(const std::string &_state)
void _updateSkinItemView()
void _setSubSkinVisible(bool _visible)
void _setSkinItemAlign(const IntSize &_size)
void _setTextureName(const std::string &_texture)
void _setSkinItemVisible(bool _value)
static SubWidgetManager & getInstance()
const std::string & getCategoryName() const
widget description should be here.
Definition: MyGUI_Widget.h:37