MyGUI: MyGUI_SkinItem.cpp Source File

MyGUI 3.4.2

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

- File List
- Globals

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"
9#include "MyGUI_FactoryManager.h"
10#include "MyGUI_Widget.h"
11#include "MyGUI_RenderManager.h"
12#include "MyGUI_SubWidgetManager.h"
13
14namespace MyGUI
15{
16 SkinItem::SkinItem() :
17 mText(nullptr),
18 mMainSkin(nullptr),
19 mTexture(nullptr),
20 mSubSkinsVisible(true)
21 {
22 }
23
24 void SkinItem::_setSkinItemAlign(const IntSize& _size)
25 {
26 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
27 (*skin)->_setAlign(_size);
28 }
29
30 void SkinItem::_setSkinItemVisible(bool _value)
31 {
32 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
33 (*skin)->setVisible(_value);
34 }
35
36 void SkinItem::_setSkinItemColour(const Colour& _value)
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
52 void SkinItem::_correctSkinItemView()
53 {
54 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin)
55 (*skin)->_correctView();
56 }
57
58 void SkinItem::_updateSkinItemView()
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
80 void SkinItem::_createSkinItem(ResourceSkin* _info)
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 // загружаем кирпичики виджета
92 FactoryManager& factory = FactoryManager::getInstance();
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
117 void SkinItem::_deleteSkinItem()
118 {
119 mTexture = nullptr;
120
121 mStateInfo.clear();
122
123 removeAllRenderItems();
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
146 void SkinItem::_setSubSkinVisible(bool _visible)
147 {
148 if (mSubSkinsVisible == _visible)
149 return;
150 mSubSkinsVisible = _visible;
151
152 _updateSkinItemView();
153 }
154
155 ISubWidgetText* SkinItem::getSubWidgetText() const
156 {
157 return mText;
158 }
159
160 ISubWidgetRect* SkinItem::getSubWidgetMain() const
161 {
162 return mMainSkin;
163 }
164
165} // namespace MyGUI
MyGUI_FactoryManager.h
MyGUI_Precompiled.h
MyGUI_RenderManager.h
MyGUI_SkinItem.h
MyGUI_SubWidgetManager.h
MyGUI_Widget.h
MyGUI::FactoryManager
Definition MyGUI_FactoryManager.h:19
MyGUI::FactoryManager::getInstance
static FactoryManager & getInstance()
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition MyGUI_FactoryManager.cpp:72
MyGUI::ICroppedRectangle::setCoord
virtual void setCoord(const IntCoord &_value)
Definition MyGUI_ICroppedRectangle.h:45
MyGUI::ICroppedRectangle::_setCroppedParent
void _setCroppedParent(ICroppedRectangle *_parent)
Definition MyGUI_ICroppedRectangle.h:158
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::IStateInfo
Definition MyGUI_IStateInfo.h:18
MyGUI::ISubWidget
Definition MyGUI_ISubWidget.h:27
MyGUI::ISubWidget::setAlign
virtual void setAlign(Align _value)
Definition MyGUI_ISubWidget.h:42
MyGUI::ISubWidgetRect
Definition MyGUI_ISubWidgetRect.h:19
MyGUI::ISubWidgetRect::_setColour
virtual void _setColour(const Colour &)
Definition MyGUI_ISubWidgetRect.h:24
MyGUI::ISubWidgetText
Definition MyGUI_ISubWidgetText.h:20
MyGUI::LayerItem::removeAllRenderItems
void removeAllRenderItems()
Definition MyGUI_LayerItem.cpp:61
MyGUI::LayerItem::addRenderItem
void addRenderItem(ISubWidget *_item)
Definition MyGUI_LayerItem.cpp:56
MyGUI::LayerItem::setRenderItemTexture
void setRenderItemTexture(ITexture *_texture)
Definition MyGUI_LayerItem.cpp:67
MyGUI::RenderManager::getTexture
virtual ITexture * getTexture(const std::string &_name)=0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::ResourceSkin
Definition MyGUI_ResourceSkin.h:23
MyGUI::ResourceSkin::getStateInfo
const MapWidgetStateInfo & getStateInfo() const
Definition MyGUI_ResourceSkin.cpp:280
MyGUI::ResourceSkin::getBasisInfo
const VectorSubWidgetInfo & getBasisInfo() const
Definition MyGUI_ResourceSkin.cpp:275
MyGUI::ResourceSkin::getTextureName
const std::string & getTextureName() const
Definition MyGUI_ResourceSkin.cpp:270
MyGUI::SkinItem::getSubWidgetMain
ISubWidgetRect * getSubWidgetMain() const
Definition MyGUI_SkinItem.cpp:160
MyGUI::SkinItem::_correctSkinItemView
void _correctSkinItemView()
Definition MyGUI_SkinItem.cpp:52
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText() const
Definition MyGUI_SkinItem.cpp:155
MyGUI::SkinItem::_setSkinItemAlpha
void _setSkinItemAlpha(float _value)
Definition MyGUI_SkinItem.cpp:46
MyGUI::SkinItem::_createSkinItem
void _createSkinItem(ResourceSkin *_info)
Definition MyGUI_SkinItem.cpp:80
MyGUI::SkinItem::_setSkinItemColour
void _setSkinItemColour(const Colour &_value)
Definition MyGUI_SkinItem.cpp:36
MyGUI::SkinItem::_getTextureName
const std::string & _getTextureName() const
Definition MyGUI_SkinItem.cpp:141
MyGUI::SkinItem::_deleteSkinItem
void _deleteSkinItem()
Definition MyGUI_SkinItem.cpp:117
MyGUI::SkinItem::_setSkinItemState
bool _setSkinItemState(const std::string &_state)
Definition MyGUI_SkinItem.cpp:64
MyGUI::SkinItem::_updateSkinItemView
void _updateSkinItemView()
Definition MyGUI_SkinItem.cpp:58
MyGUI::SkinItem::_setSubSkinVisible
void _setSubSkinVisible(bool _visible)
Definition MyGUI_SkinItem.cpp:146
MyGUI::SkinItem::_setSkinItemAlign
void _setSkinItemAlign(const IntSize &_size)
Definition MyGUI_SkinItem.cpp:24
MyGUI::SkinItem::_setTextureName
void _setTextureName(const std::string &_texture)
Definition MyGUI_SkinItem.cpp:133
MyGUI::SkinItem::SkinItem
SkinItem()
Definition MyGUI_SkinItem.cpp:16
MyGUI::SkinItem::_setSkinItemVisible
void _setSkinItemVisible(bool _value)
Definition MyGUI_SkinItem.cpp:30
MyGUI::SubWidgetManager::getInstance
static SubWidgetManager & getInstance()
MyGUI::SubWidgetManager::getCategoryName
const std::string & getCategoryName() const
Definition MyGUI_SubWidgetManager.cpp:87
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:37
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::Colour
Definition MyGUI_Colour.h:17
MyGUI::types::TSize< int >