MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_SkinItem.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_SkinItem.h"
25 #include "MyGUI_FactoryManager.h"
26 #include "MyGUI_Widget.h"
27 #include "MyGUI_RenderManager.h"
28
29 namespace MyGUI
30 {
31 SkinItem::SkinItem() :
32 mText(nullptr),
33 mMainSkin(nullptr),
34 mTexture(nullptr),
35 mSubSkinsVisible(true)
36 {
37 }
38
39 void SkinItem::_setSkinItemAlign(const IntSize& _size)
40 {
41 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
42 (*skin)->_setAlign(_size);
43 }
44
45 void SkinItem::_setSkinItemVisible(bool _value)
46 {
47 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
48 (*skin)->setVisible(_value);
49 }
50
51 void SkinItem::_setSkinItemColour(const Colour& _value)
52 {
53 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
54 {
55 ISubWidgetRect* rect = (*skin)->castType<ISubWidgetRect>(false);
56 if (rect)
57 rect->_setColour(_value);
58 }
59 }
60
61 void SkinItem::_setSkinItemAlpha(float _value)
62 {
63 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
64 (*skin)->setAlpha(_value);
65 }
66
67 void SkinItem::_correctSkinItemView()
68 {
69 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
70 (*skin)->_correctView();
71 }
72
73 void SkinItem::_updateSkinItemView()
74 {
75 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
76 (*skin)->_updateView();
77 }
78
79 bool SkinItem::_setSkinItemState(const std::string& _state)
80 {
81 MapWidgetStateInfo::const_iterator iter = mStateInfo.find(_state);
82 if (iter == mStateInfo.end())
83 return false;
84
85 size_t index = 0;
86 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin, ++index)
87 {
88 IStateInfo* data = (*iter).second[index];
89 if (data != nullptr)
90 (*skin)->setStateData(data);
91 }
92 return true;
93 }
94
95 void SkinItem::_createSkinItem(ResourceSkin* _info)
96 {
97 mStateInfo = _info->getStateInfo();
98
99 // все что с текстурой можно тоже перенести в скин айтем и setRenderItemTexture
100 mTextureName = _info->getTextureName();
101 mTexture = RenderManager::getInstance().getTexture(mTextureName);
102
103 setRenderItemTexture(mTexture);
104
105 // загружаем кирпичики виджета
106 FactoryManager& factory = FactoryManager::getInstance();
107 for (VectorSubWidgetInfo::const_iterator iter = _info->getBasisInfo().begin(); iter != _info->getBasisInfo().end(); ++iter)
108 {
109 IObject* object = factory.createObject("BasisSkin", (*iter).type);
110 if (object == nullptr)
111 continue;
112
113 ISubWidget* sub = object->castType<ISubWidget>();
114 sub->_setCroppedParent(static_cast<Widget*>(this));
115 sub->setCoord((*iter).coord);
116 sub->setAlign((*iter).align);
117
118 mSubSkinChild.push_back(sub);
119 addRenderItem(sub);
120
121 // ищем дефолтные сабвиджеты
122 if (mMainSkin == nullptr)
123 mMainSkin = sub->castType<ISubWidgetRect>(false);
124 if (mText == nullptr)
125 mText = sub->castType<ISubWidgetText>(false);
126 }
127
128 _setSkinItemState("normal");
129 }
130
131 void SkinItem::_deleteSkinItem()
132 {
133 mTexture = nullptr;
134
135 mStateInfo.clear();
136
137 removeAllRenderItems();
138 // удаляем все сабскины
139 mMainSkin = nullptr;
140 mText = nullptr;
141
142 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
143 delete (*skin);
144 mSubSkinChild.clear();
145 }
146
147 void SkinItem::_setTextureName(const std::string& _texture)
148 {
149 mTextureName = _texture;
150 mTexture = RenderManager::getInstance().getTexture(mTextureName);
151
152 setRenderItemTexture(mTexture);
153 }
154
155 const std::string& SkinItem::_getTextureName() const
156 {
157 return mTextureName;
158 }
159
160 void SkinItem::_setSubSkinVisible(bool _visible)
161 {
162 if (mSubSkinsVisible == _visible)
163 return;
164 mSubSkinsVisible = _visible;
165
166 _updateSkinItemView();
167 }
168
169 ISubWidgetText* SkinItem::getSubWidgetText()
170 {
171 return mText;
172 }
173
174 ISubWidgetRect* SkinItem::getSubWidgetMain()
175 {
176 return mMainSkin;
177 }
178
179 } // namespace MyGUI
MyGUI_SkinItem.h
MyGUI_FactoryManager.h
MyGUI::SkinItem::_setSkinItemVisible
void _setSkinItemVisible(bool _value)
Definition: MyGUI_SkinItem.cpp:45
MyGUI::ResourceSkin
Definition: MyGUI_ResourceSkin.h:36
MyGUI::ISubWidgetRect
Definition: MyGUI_ISubWidgetRect.h:32
MyGUI::ISubWidget::setAlign
virtual void setAlign(Align _value)
Definition: MyGUI_ISubWidget.h:58
MyGUI_Precompiled.h
MyGUI::IStateInfo
Definition: MyGUI_IStateInfo.h:31
MyGUI::types::TSize< int >
MyGUI::ResourceSkin::getTextureName
const std::string & getTextureName() const
Definition: MyGUI_ResourceSkin.cpp:270
MyGUI::ISubWidgetRect::_setColour
virtual void _setColour(const Colour &_value)
Definition: MyGUI_ISubWidgetRect.h:41
MyGUI::Singleton< RenderManager >::getInstance
static RenderManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::SkinItem::_setSkinItemAlpha
void _setSkinItemAlpha(float _value)
Definition: MyGUI_SkinItem.cpp:61
MyGUI::RenderManager::getTexture
virtual ITexture * getTexture(const std::string &_name)=0
MyGUI::LayerItem::setRenderItemTexture
void setRenderItemTexture(ITexture *_texture)
Definition: MyGUI_LayerItem.cpp:86
MyGUI::SkinItem::_deleteSkinItem
void _deleteSkinItem()
Definition: MyGUI_SkinItem.cpp:131
MyGUI::SkinItem::_getTextureName
const std::string & _getTextureName() const
Definition: MyGUI_SkinItem.cpp:155
MyGUI::ISubWidget
Definition: MyGUI_ISubWidget.h:39
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:47
MyGUI::SkinItem::_setTextureName
void _setTextureName(const std::string &_texture)
Definition: MyGUI_SkinItem.cpp:147
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText()
Definition: MyGUI_SkinItem.cpp:169
MyGUI::SkinItem::_updateSkinItemView
void _updateSkinItemView()
Definition: MyGUI_SkinItem.cpp:73
MyGUI::FactoryManager
Definition: MyGUI_FactoryManager.h:33
MyGUI::SkinItem::getSubWidgetMain
ISubWidgetRect * getSubWidgetMain()
Definition: MyGUI_SkinItem.cpp:174
MyGUI_RenderManager.h
MyGUI::ICroppedRectangle::_setCroppedParent
void _setCroppedParent(ICroppedRectangle *_parent)
Definition: MyGUI_ICroppedRectangle.h:173
MyGUI::ICroppedRectangle::setCoord
virtual void setCoord(const IntCoord &_value)
Definition: MyGUI_ICroppedRectangle.h:60
MyGUI::ResourceSkin::getBasisInfo
const VectorSubWidgetInfo & getBasisInfo() const
Definition: MyGUI_ResourceSkin.cpp:275
MyGUI::ResourceSkin::getStateInfo
const MapWidgetStateInfo & getStateInfo() const
Definition: MyGUI_ResourceSkin.cpp:280
MyGUI::LayerItem::removeAllRenderItems
void removeAllRenderItems()
Definition: MyGUI_LayerItem.cpp:80
MyGUI::SkinItem::_setSubSkinVisible
void _setSubSkinVisible(bool _visible)
Definition: MyGUI_SkinItem.cpp:160
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
MyGUI::SkinItem::_createSkinItem
void _createSkinItem(ResourceSkin *_info)
Definition: MyGUI_SkinItem.cpp:95
MyGUI::IObject
Definition: MyGUI_IObject.h:31
MyGUI::LayerItem::addRenderItem
void addRenderItem(ISubWidget *_item)
Definition: MyGUI_LayerItem.cpp:75
MyGUI_Widget.h
MyGUI::ISubWidgetText
Definition: MyGUI_ISubWidgetText.h:32
MyGUI::SkinItem::_setSkinItemAlign
void _setSkinItemAlign(const IntSize &_size)
Definition: MyGUI_SkinItem.cpp:39
MyGUI::Colour
Definition: MyGUI_Colour.h:31
MyGUI::SkinItem::_setSkinItemState
bool _setSkinItemState(const std::string &_state)
Definition: MyGUI_SkinItem.cpp:79
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:87
MyGUI::SkinItem::_correctSkinItemView
void _correctSkinItemView()
Definition: MyGUI_SkinItem.cpp:67
MyGUI::SkinItem::SkinItem
SkinItem()
Definition: MyGUI_SkinItem.cpp:31
MyGUI::SkinItem::_setSkinItemColour
void _setSkinItemColour(const Colour &_value)
Definition: MyGUI_SkinItem.cpp:51