MyGUI: MyGUI_SkinItem.cpp Source File

MyGUI 3.4.3

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
17 void SkinItem::_setSkinItemAlign(const IntSize& _size)
18 {
19 for (auto& skin : mSubSkinChild)
20 skin->_setAlign(_size);
21 }
22
23 void SkinItem::_setSkinItemVisible(bool _value)
24 {
25 for (auto& skin : mSubSkinChild)
26 skin->setVisible(_value);
27 }
28
29 void SkinItem::_setSkinItemColour(const Colour& _value)
30 {
31 for (auto& skin : mSubSkinChild)
32 {
33 ISubWidgetRect* rect = skin->castType<ISubWidgetRect>(false);
34 if (rect)
35 rect->_setColour(_value);
36 }
37 }
38
39 void SkinItem::_setSkinItemAlpha(float _value)
40 {
41 for (auto& skin : mSubSkinChild)
42 skin->setAlpha(_value);
43 }
44
45 void SkinItem::_correctSkinItemView()
46 {
47 for (auto& skin : mSubSkinChild)
48 skin->_correctView();
49 }
50
51 void SkinItem::_updateSkinItemView()
52 {
53 for (auto& skin : mSubSkinChild)
54 skin->_updateView();
55 }
56
57 bool SkinItem::_setSkinItemState(std::string_view _state)
58 {
59 MapWidgetStateInfo::const_iterator iter = mStateInfo.find(_state);
60 if (iter == mStateInfo.end())
61 return false;
62
63 size_t index = 0;
64 for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin, ++index)
65 {
66 IStateInfo* data = (*iter).second[index];
67 if (data != nullptr)
68 (*skin)->setStateData(data);
69 }
70 return true;
71 }
72
73 void SkinItem::_createSkinItem(ResourceSkin* _info)
74 {
75 mStateInfo = _info->getStateInfo();
76
77 // все что с текстурой можно тоже перенести в скин айтем и setRenderItemTexture
78 mTextureName = _info->getTextureName();
79 mTexture = RenderManager::getInstance().getTexture(mTextureName);
80
81 setRenderItemTexture(mTexture);
82
83 const std::string& categoryName = SubWidgetManager::getInstance().getCategoryName();
84 // загружаем кирпичики виджета
85 FactoryManager& factory = FactoryManager::getInstance();
86 for (const auto& iter : _info->getBasisInfo())
87 {
88 IObject* object = factory.createObject(categoryName, iter.type);
89 if (object == nullptr)
90 continue;
91
92 ISubWidget* sub = object->castType<ISubWidget>();
93 sub->_setCroppedParent(static_cast<Widget*>(this));
94 sub->setCoord(iter.coord);
95 sub->setAlign(iter.align);
96
97 mSubSkinChild.push_back(sub);
98 addRenderItem(sub);
99
100 // ищем дефолтные сабвиджеты
101 if (mMainSkin == nullptr)
102 mMainSkin = sub->castType<ISubWidgetRect>(false);
103 if (mText == nullptr)
104 mText = sub->castType<ISubWidgetText>(false);
105 }
106
107 _setSkinItemState("normal");
108 }
109
110 void SkinItem::_deleteSkinItem()
111 {
112 mTexture = nullptr;
113
114 mStateInfo.clear();
115
116 removeAllRenderItems();
117 // удаляем все сабскины
118 mMainSkin = nullptr;
119 mText = nullptr;
120
121 for (auto& skin : mSubSkinChild)
122 delete skin;
123 mSubSkinChild.clear();
124 }
125
126 void SkinItem::_setTextureName(std::string_view _texture)
127 {
128 mTextureName = _texture;
129 mTexture = RenderManager::getInstance().getTexture(mTextureName);
130
131 setRenderItemTexture(mTexture);
132 }
133
134 const std::string& SkinItem::_getTextureName() const
135 {
136 return mTextureName;
137 }
138
139 void SkinItem::_setSubSkinVisible(bool _visible)
140 {
141 if (mSubSkinsVisible == _visible)
142 return;
143 mSubSkinsVisible = _visible;
144
145 _updateSkinItemView();
146 }
147
148 ISubWidgetText* SkinItem::getSubWidgetText() const
149 {
150 return mText;
151 }
152
153 ISubWidgetRect* SkinItem::getSubWidgetMain() const
154 {
155 return mMainSkin;
156 }
157
158} // 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(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:80
MyGUI::ICroppedRectangle::setCoord
virtual void setCoord(const IntCoord &_value)
Definition MyGUI_ICroppedRectangle.h:40
MyGUI::ICroppedRectangle::_setCroppedParent
void _setCroppedParent(ICroppedRectangle *_parent)
Definition MyGUI_ICroppedRectangle.h:157
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:17
MyGUI::ISubWidget
Definition MyGUI_ISubWidget.h:25
MyGUI::ISubWidget::setAlign
virtual void setAlign(Align _value)
Definition MyGUI_ISubWidget.h:42
MyGUI::ISubWidgetRect
Definition MyGUI_ISubWidgetRect.h:18
MyGUI::ISubWidgetRect::_setColour
virtual void _setColour(const Colour &)
Definition MyGUI_ISubWidgetRect.h:25
MyGUI::ISubWidgetText
Definition MyGUI_ISubWidgetText.h:19
MyGUI::LayerItem::removeAllRenderItems
void removeAllRenderItems()
Definition MyGUI_LayerItem.cpp:53
MyGUI::LayerItem::addRenderItem
void addRenderItem(ISubWidget *_item)
Definition MyGUI_LayerItem.cpp:48
MyGUI::LayerItem::setRenderItemTexture
void setRenderItemTexture(ITexture *_texture)
Definition MyGUI_LayerItem.cpp:59
MyGUI::RenderManager::getTexture
virtual ITexture * getTexture(const std::string &_name)=0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::ResourceSkin
Definition MyGUI_ResourceSkin.h:22
MyGUI::ResourceSkin::getStateInfo
const MapWidgetStateInfo & getStateInfo() const
Definition MyGUI_ResourceSkin.cpp:274
MyGUI::ResourceSkin::getBasisInfo
const VectorSubWidgetInfo & getBasisInfo() const
Definition MyGUI_ResourceSkin.cpp:269
MyGUI::ResourceSkin::getTextureName
const std::string & getTextureName() const
Definition MyGUI_ResourceSkin.cpp:264
MyGUI::SkinItem::getSubWidgetMain
ISubWidgetRect * getSubWidgetMain() const
Definition MyGUI_SkinItem.cpp:153
MyGUI::SkinItem::_correctSkinItemView
void _correctSkinItemView()
Definition MyGUI_SkinItem.cpp:45
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText() const
Definition MyGUI_SkinItem.cpp:148
MyGUI::SkinItem::_setSkinItemAlpha
void _setSkinItemAlpha(float _value)
Definition MyGUI_SkinItem.cpp:39
MyGUI::SkinItem::_createSkinItem
void _createSkinItem(ResourceSkin *_info)
Definition MyGUI_SkinItem.cpp:73
MyGUI::SkinItem::_setTextureName
void _setTextureName(std::string_view _texture)
Definition MyGUI_SkinItem.cpp:126
MyGUI::SkinItem::_setSkinItemColour
void _setSkinItemColour(const Colour &_value)
Definition MyGUI_SkinItem.cpp:29
MyGUI::SkinItem::_setSkinItemState
bool _setSkinItemState(std::string_view _state)
Definition MyGUI_SkinItem.cpp:57
MyGUI::SkinItem::_getTextureName
const std::string & _getTextureName() const
Definition MyGUI_SkinItem.cpp:134
MyGUI::SkinItem::_deleteSkinItem
void _deleteSkinItem()
Definition MyGUI_SkinItem.cpp:110
MyGUI::SkinItem::_updateSkinItemView
void _updateSkinItemView()
Definition MyGUI_SkinItem.cpp:51
MyGUI::SkinItem::_setSubSkinVisible
void _setSubSkinVisible(bool _visible)
Definition MyGUI_SkinItem.cpp:139
MyGUI::SkinItem::_setSkinItemAlign
void _setSkinItemAlign(const IntSize &_size)
Definition MyGUI_SkinItem.cpp:17
MyGUI::SkinItem::_setSkinItemVisible
void _setSkinItemVisible(bool _value)
Definition MyGUI_SkinItem.cpp:23
MyGUI::SubWidgetManager::getInstance
static SubWidgetManager & getInstance()
MyGUI::SubWidgetManager::getCategoryName
const std::string & getCategoryName() const
Definition MyGUI_SubWidgetManager.cpp:86
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::Colour
Definition MyGUI_Colour.h:17