MyGUI_SkinItem.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_SkinItem.h"
#include "MyGUI_FactoryManager.h"
#include "MyGUI_Widget.h"
#include "MyGUI_RenderManager.h"
#include "MyGUI_SubWidgetManager.h"
namespace MyGUI
{
void SkinItem::_setSkinItemAlign(const IntSize& _size)
{
for (auto& skin : mSubSkinChild)
skin->_setAlign(_size);
}
void SkinItem::_setSkinItemVisible(bool _value)
{
for (auto& skin : mSubSkinChild)
skin->setVisible(_value);
}
void SkinItem::_setSkinItemColour(const Colour& _value)
{
for (auto& skin : mSubSkinChild)
{
ISubWidgetRect* rect = skin->castType<ISubWidgetRect>(false);
if (rect)
rect->_setColour(_value);
}
}
void SkinItem::_setSkinItemAlpha(float _value)
{
for (auto& skin : mSubSkinChild)
skin->setAlpha(_value);
}
void SkinItem::_correctSkinItemView()
{
for (auto& skin : mSubSkinChild)
skin->_correctView();
}
void SkinItem::_updateSkinItemView()
{
for (auto& skin : mSubSkinChild)
skin->_updateView();
}
bool SkinItem::_setSkinItemState(std::string_view _state)
{
MapWidgetStateInfo::const_iterator iter = mStateInfo.find(_state);
if (iter == mStateInfo.end())
return false;
size_t index = 0;
for (VectorSubWidget::iterator skin = mSubSkinChild.begin(); skin != mSubSkinChild.end(); ++skin, ++index)
{
IStateInfo* data = (*iter).second[index];
if (data != nullptr)
(*skin)->setStateData(data);
}
return true;
}
void SkinItem::_createSkinItem(ResourceSkin* _info)
{
mStateInfo = _info->getStateInfo();
// все что с текстурой можно тоже перенести в скин айтем и setRenderItemTexture
mTextureName = _info->getTextureName();
mTexture = RenderManager::getInstance().getTexture(mTextureName);
setRenderItemTexture(mTexture);
const std::string& categoryName = SubWidgetManager::getInstance().getCategoryName();
// загружаем кирпичики виджета
FactoryManager& factory = FactoryManager::getInstance();
for (const auto& iter : _info->getBasisInfo())
{
IObject* object = factory.createObject(categoryName, iter.type);
if (object == nullptr)
continue;
ISubWidget* sub = object->castType<ISubWidget>();
sub->_setCroppedParent(static_cast<Widget*>(this));
sub->setCoord(iter.coord);
sub->setAlign(iter.align);
mSubSkinChild.push_back(sub);
addRenderItem(sub);
// ищем дефолтные сабвиджеты
if (mMainSkin == nullptr)
mMainSkin = sub->castType<ISubWidgetRect>(false);
if (mText == nullptr)
mText = sub->castType<ISubWidgetText>(false);
}
_setSkinItemState("normal");
}
void SkinItem::_deleteSkinItem()
{
mTexture = nullptr;
mStateInfo.clear();
removeAllRenderItems();
// удаляем все сабскины
mMainSkin = nullptr;
mText = nullptr;
for (auto& skin : mSubSkinChild)
delete skin;
mSubSkinChild.clear();
}
void SkinItem::_setTextureName(std::string_view _texture)
{
mTextureName = _texture;
mTexture = RenderManager::getInstance().getTexture(mTextureName);
setRenderItemTexture(mTexture);
}
const std::string& SkinItem::_getTextureName() const
{
return mTextureName;
}
void SkinItem::_setSubSkinVisible(bool _visible)
{
if (mSubSkinsVisible == _visible)
return;
mSubSkinsVisible = _visible;
_updateSkinItemView();
}
ISubWidgetText* SkinItem::getSubWidgetText() const
{
return mText;
}
ISubWidgetRect* SkinItem::getSubWidgetMain() const
{
return mMainSkin;
}
} // 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