MyGUI  3.4.0
MyGUI_SubSkin.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_SubSkin.h"
9 #include "MyGUI_RenderItem.h"
10 #include "MyGUI_SkinManager.h"
11 #include "MyGUI_LanguageManager.h"
12 #include "MyGUI_LayerNode.h"
13 #include "MyGUI_CommonStateInfo.h"
14 #include "MyGUI_RenderManager.h"
15 #include "MyGUI_TextureUtility.h"
16 
17 namespace MyGUI
18 {
19 
22  mEmptyView(false),
23  mCurrentColour(0xFFFFFFFF),
24  mNode(nullptr),
25  mRenderItem(nullptr),
26  mSeparate(false)
27  {
29  }
30 
31  void SubSkin::setVisible(bool _visible)
32  {
33  if (mVisible == _visible)
34  return;
35  mVisible = _visible;
36 
37  if (nullptr != mNode)
39  }
40 
41  void SubSkin::setAlpha(float _alpha)
42  {
43  uint32 alpha = ((uint8)(_alpha * 255) << 24);
44  mCurrentColour = (mCurrentColour & 0x00FFFFFF) | (alpha & 0xFF000000);
45 
46  if (nullptr != mNode)
48  }
49 
51  {
52  if (nullptr != mNode)
54  }
55 
56  void SubSkin::_setAlign(const IntSize& _oldsize)
57  {
58  // необходимо разобраться
59  bool need_update = true;//_update;
60 
61  // первоначальное выравнивание
62  if (mAlign.isHStretch())
63  {
64  // растягиваем
65  mCoord.width = mCoord.width + (mCroppedParent->getWidth() - _oldsize.width);
66  need_update = true;
67  mIsMargin = true; // при изменении размеров все пересчитывать
68  }
69  else if (mAlign.isRight())
70  {
71  // двигаем по правому краю
72  mCoord.left = mCoord.left + (mCroppedParent->getWidth() - _oldsize.width);
73  need_update = true;
74  }
75  else if (mAlign.isHCenter())
76  {
77  // выравнивание по горизонтали без растяжения
79  need_update = true;
80  }
81 
82  if (mAlign.isVStretch())
83  {
84  // растягиваем
86  need_update = true;
87  mIsMargin = true; // при изменении размеров все пересчитывать
88  }
89  else if (mAlign.isBottom())
90  {
91  // двигаем по нижнему краю
92  mCoord.top = mCoord.top + (mCroppedParent->getHeight() - _oldsize.height);
93  need_update = true;
94  }
95  else if (mAlign.isVCenter())
96  {
97  // выравнивание по вертикали без растяжения
99  need_update = true;
100  }
101 
102  if (need_update)
103  {
105  _updateView();
106  }
107  }
108 
110  {
111  //mAbsolutePosition = mCroppedParent->getAbsolutePosition() + mCoord.point();
112  bool margin = _checkMargin();
113 
114  mEmptyView = ((0 >= _getViewWidth()) || (0 >= _getViewHeight()));
115 
118 
119  // вьюпорт стал битым
120  if (margin)
121  {
122  // проверка на полный выход за границу
123  if (_checkOutside())
124  {
125  // запоминаем текущее состояние
126  mIsMargin = margin;
127 
128  // обновить перед выходом
129  if (nullptr != mNode)
131  return;
132  }
133  }
134 
135  // мы обрезаны или были обрезаны
136  if (mIsMargin || margin)
137  {
140 
141  if ((mCurrentCoord.width > 0) && (mCurrentCoord.height > 0))
142  {
143  // теперь смещаем текстуру
144  float UV_lft = mMargin.left / (float)mCoord.width;
145  float UV_top = mMargin.top / (float)mCoord.height;
146  float UV_rgt = (mCoord.width - mMargin.right) / (float)mCoord.width;
147  float UV_btm = (mCoord.height - mMargin.bottom) / (float)mCoord.height;
148 
149  float UV_sizeX = mRectTexture.right - mRectTexture.left;
150  float UV_sizeY = mRectTexture.bottom - mRectTexture.top;
151 
152  float UV_lft_total = mRectTexture.left + UV_lft * UV_sizeX;
153  float UV_top_total = mRectTexture.top + UV_top * UV_sizeY;
154  float UV_rgt_total = mRectTexture.right - (1 - UV_rgt) * UV_sizeX;
155  float UV_btm_total = mRectTexture.bottom - (1 - UV_btm) * UV_sizeY;
156 
157  mCurrentTexture.set(UV_lft_total, UV_top_total, UV_rgt_total, UV_btm_total);
158  }
159  }
160 
161  if (mIsMargin && !margin)
162  {
163  // мы не обрезаны, но были, ставим базовые координаты
165  }
166 
167  // запоминаем текущее состояние
168  mIsMargin = margin;
169 
170  if (nullptr != mNode)
172  }
173 
175  {
176  MYGUI_ASSERT(!mRenderItem, "mRenderItem must be nullptr");
177 
178  mNode = _node;
179  mRenderItem = mNode->addToRenderItem(_texture, true, mSeparate);
181  }
182 
184  {
185  MYGUI_ASSERT(mRenderItem, "mRenderItem must be not nullptr");
186 
187  mNode = nullptr;
189  mRenderItem = nullptr;
190  }
191 
192  void SubSkin::_setUVSet(const FloatRect& _rect)
193  {
194  if (mRectTexture == _rect)
195  return;
196  mRectTexture = _rect;
197 
198  // если обрезаны, то просчитываем с учето обрезки
199  if (mIsMargin)
200  {
201  float UV_lft = mMargin.left / (float)mCoord.width;
202  float UV_top = mMargin.top / (float)mCoord.height;
203  float UV_rgt = (mCoord.width - mMargin.right) / (float)mCoord.width;
204  float UV_btm = (mCoord.height - mMargin.bottom) / (float)mCoord.height;
205 
206  float UV_sizeX = mRectTexture.right - mRectTexture.left;
207  float UV_sizeY = mRectTexture.bottom - mRectTexture.top;
208 
209  float UV_lft_total = mRectTexture.left + UV_lft * UV_sizeX;
210  float UV_top_total = mRectTexture.top + UV_top * UV_sizeY;
211  float UV_rgt_total = mRectTexture.right - (1 - UV_rgt) * UV_sizeX;
212  float UV_btm_total = mRectTexture.bottom - (1 - UV_btm) * UV_sizeY;
213 
214  mCurrentTexture.set(UV_lft_total, UV_top_total, UV_rgt_total, UV_btm_total);
215  }
216  // мы не обрезаны, базовые координаты
217  else
218  {
220  }
221 
222  if (nullptr != mNode)
224  }
225 
227  {
228  if (!mVisible || mEmptyView)
229  return;
230 
231  VertexQuad* quad = reinterpret_cast<VertexQuad*>(mRenderItem->getCurrentVertexBuffer());
232 
234 
235  float vertex_z = mNode->getNodeDepth();
236 
237  float vertex_left = ((info.pixScaleX * (float)(mCurrentCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) + info.hOffset) * 2) - 1;
238  float vertex_right = vertex_left + (info.pixScaleX * (float)mCurrentCoord.width * 2);
239  float vertex_top = -(((info.pixScaleY * (float)(mCurrentCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) + info.vOffset) * 2) - 1);
240  float vertex_bottom = vertex_top - (info.pixScaleY * (float)mCurrentCoord.height * 2);
241 
242  quad->set(
243  vertex_left,
244  vertex_top,
245  vertex_right,
246  vertex_bottom,
247  vertex_z,
253 
255  }
256 
257  void SubSkin::_setColour(const Colour& _value)
258  {
259  uint32 colour = texture_utility::toColourARGB(_value);
261  mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
262 
263  if (nullptr != mNode)
265  }
266 
268  {
270  }
271 
272 } // namespace MyGUI
MyGUI::Singleton< RenderManager >::getInstance
static RenderManager & getInstance()
Definition: MyGUI_Singleton.h:44
MyGUI::types::TRect::bottom
T bottom
Definition: MyGUI_TRect.h:23
MyGUI::SubSkin::mCurrentTexture
FloatRect mCurrentTexture
Definition: MyGUI_SubSkin.h:59
MyGUI::RenderItem::setLastVertexCount
void setLastVertexCount(size_t _count)
Definition: MyGUI_RenderItem.cpp:235
MyGUI::RenderTargetInfo::vOffset
float vOffset
Definition: MyGUI_RenderTargetInfo.h:41
MyGUI::RenderTargetInfo::leftOffset
int leftOffset
Definition: MyGUI_RenderTargetInfo.h:44
MyGUI::Align::isHCenter
bool isHCenter() const
Definition: MyGUI_Align.h:44
MyGUI::RenderTargetInfo::topOffset
int topOffset
Definition: MyGUI_RenderTargetInfo.h:45
MyGUI::types::TSize::height
T height
Definition: MyGUI_TSize.h:21
MyGUI::VertexQuad::set
void set(float _l, float _t, float _r, float _b, float _z, float _u1, float _v1, float _u2, float _v2, uint32 _colour)
Definition: MyGUI_VertexData.h:46
MyGUI::types::TCoord::left
T left
Definition: MyGUI_TCoord.h:22
MyGUI::ICroppedRectangle::mIsMargin
bool mIsMargin
Definition: MyGUI_ICroppedRectangle.h:248
MyGUI::SubSkin::setStateData
void setStateData(IStateInfo *_data) override
Definition: MyGUI_SubSkin.cpp:267
MyGUI::texture_utility::convertColour
void convertColour(uint32 &_colour, VertexColourType _format)
Definition: MyGUI_TextureUtility.h:23
MyGUI::ICroppedRectangle::_getViewHeight
int _getViewHeight() const
Definition: MyGUI_ICroppedRectangle.h:153
MyGUI::types::TCoord::top
T top
Definition: MyGUI_TCoord.h:23
MyGUI::types::TRect::set
void set(T const &_left, T const &_top, T const &_right, T const &_bottom)
Definition: MyGUI_TRect.h:121
MyGUI::ICroppedRectangle::getAbsoluteTop
int getAbsoluteTop() const
Definition: MyGUI_ICroppedRectangle.h:88
MyGUI::uint8
unsigned char uint8
Definition: MyGUI_Types.h:44
MyGUI::types::TRect< float >
MyGUI::ILayerNode::addToRenderItem
virtual RenderItem * addToRenderItem(ITexture *_texture, bool _firstQueue, bool _separate)=0
MyGUI::SubSkin::mVertexFormat
VertexColourType mVertexFormat
Definition: MyGUI_SubSkin.h:56
MyGUI::ILayerNode::outOfDate
virtual void outOfDate(RenderItem *_item)=0
MyGUI::types::TRect::right
T right
Definition: MyGUI_TRect.h:22
MyGUI::ILayerNode
Definition: MyGUI_ILayerNode.h:30
MyGUI::SubSkin::_correctView
void _correctView() override
Definition: MyGUI_SubSkin.cpp:50
MyGUI::SubSkinStateInfo::getRect
const FloatRect & getRect() const
Definition: MyGUI_CommonStateInfo.h:25
MyGUI::ICroppedRectangle::getAbsoluteLeft
int getAbsoluteLeft() const
Definition: MyGUI_ICroppedRectangle.h:83
MyGUI::ICroppedRectangle::mMargin
IntRect mMargin
Definition: MyGUI_ICroppedRectangle.h:244
MyGUI::Align::isVCenter
bool isVCenter() const
Definition: MyGUI_Align.h:49
MyGUI_CommonStateInfo.h
MyGUI::RenderTargetInfo::hOffset
float hOffset
Definition: MyGUI_RenderTargetInfo.h:40
MyGUI::types::TSize::width
T width
Definition: MyGUI_TSize.h:20
MyGUI_LayerNode.h
MyGUI::types::TRect::left
T left
Definition: MyGUI_TRect.h:20
MyGUI::ISubWidget::mVisible
bool mVisible
Definition: MyGUI_ISubWidget.h:60
MyGUI::ILayerNode::getNodeDepth
virtual float getNodeDepth()=0
MyGUI::IStateInfo
Definition: MyGUI_IStateInfo.h:18
MyGUI_Precompiled.h
MyGUI::ICroppedRectangle::_checkOutside
bool _checkOutside() const
Definition: MyGUI_ICroppedRectangle.h:235
MyGUI::SubSkin::SubSkin
SubSkin()
Definition: MyGUI_SubSkin.cpp:20
MyGUI_SubSkin.h
MyGUI::SubSkin::doRender
void doRender() override
Definition: MyGUI_SubSkin.cpp:226
MyGUI::ICroppedRectangle::mCroppedParent
ICroppedRectangle * mCroppedParent
Definition: MyGUI_ICroppedRectangle.h:249
MyGUI::SubSkin::mCurrentCoord
IntCoord mCurrentCoord
Definition: MyGUI_SubSkin.h:60
MyGUI::SubSkin::mCurrentColour
uint32 mCurrentColour
Definition: MyGUI_SubSkin.h:57
MyGUI::ICroppedRectangle::mCoord
IntCoord mCoord
Definition: MyGUI_ICroppedRectangle.h:245
MyGUI::SubSkin::setAlpha
void setAlpha(float _alpha) override
Definition: MyGUI_SubSkin.cpp:41
MyGUI::SubSkin::_updateView
void _updateView() override
Definition: MyGUI_SubSkin.cpp:109
MyGUI::uint32
unsigned int uint32
Definition: MyGUI_Types.h:46
MyGUI::SubSkin::_setColour
void _setColour(const Colour &_value) override
Definition: MyGUI_SubSkin.cpp:257
MyGUI::RenderTargetInfo::pixScaleX
float pixScaleX
Definition: MyGUI_RenderTargetInfo.h:38
MyGUI::IRenderTarget::getInfo
virtual const RenderTargetInfo & getInfo()=0
MyGUI::SubSkin::mEmptyView
bool mEmptyView
Definition: MyGUI_SubSkin.h:54
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:34
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
MyGUI::SubSkin::destroyDrawItem
void destroyDrawItem() override
Definition: MyGUI_SubSkin.cpp:183
MyGUI::VertexQuad::VertexCount
@ VertexCount
Definition: MyGUI_VertexData.h:43
MyGUI::Align::isVStretch
bool isVStretch() const
Definition: MyGUI_Align.h:84
MyGUI::SubSkinStateInfo
Definition: MyGUI_CommonStateInfo.h:21
MyGUI::SubSkin::mRenderItem
RenderItem * mRenderItem
Definition: MyGUI_SubSkin.h:63
MyGUI::RenderItem::getRenderTarget
IRenderTarget * getRenderTarget()
Definition: MyGUI_RenderItem.cpp:240
MyGUI::VertexQuad
Definition: MyGUI_VertexData.h:34
MyGUI_LanguageManager.h
MyGUI::RenderTargetInfo::pixScaleY
float pixScaleY
Definition: MyGUI_RenderTargetInfo.h:39
MyGUI_TextureUtility.h
MyGUI::SubSkin::_setAlign
void _setAlign(const IntSize &_oldsize) override
Definition: MyGUI_SubSkin.cpp:56
MyGUI::SubSkin::_setUVSet
void _setUVSet(const FloatRect &_rect) override
Definition: MyGUI_SubSkin.cpp:192
MyGUI::types::TSize< int >
MyGUI_RenderItem.h
MyGUI::ISubWidget::mAlign
Align mAlign
Definition: MyGUI_ISubWidget.h:59
MyGUI::SubSkin::mNode
ILayerNode * mNode
Definition: MyGUI_SubSkin.h:62
MyGUI::ISubWidgetRect
Definition: MyGUI_ISubWidgetRect.h:19
MyGUI::Align::isRight
bool isRight() const
Definition: MyGUI_Align.h:64
MyGUI::SubSkin::setVisible
void setVisible(bool _visible) override
Definition: MyGUI_SubSkin.cpp:31
MyGUI::ITexture
Definition: MyGUI_ITexture.h:28
MyGUI::Colour
Definition: MyGUI_Colour.h:17
MyGUI::types::TRect::top
T top
Definition: MyGUI_TRect.h:21
MyGUI::SubSkin::mRectTexture
FloatRect mRectTexture
Definition: MyGUI_SubSkin.h:53
MyGUI::RenderTargetInfo
Definition: MyGUI_RenderTargetInfo.h:16
MyGUI_RenderManager.h
MyGUI::Align::isBottom
bool isBottom() const
Definition: MyGUI_Align.h:79
MyGUI::types::TCoord::width
T width
Definition: MyGUI_TCoord.h:24
MyGUI_SkinManager.h
MyGUI::RenderItem::removeDrawItem
void removeDrawItem(ISubWidget *_item)
Definition: MyGUI_RenderItem.cpp:100
MyGUI::ICroppedRectangle::_checkMargin
bool _checkMargin()
Definition: MyGUI_ICroppedRectangle.h:185
MyGUI::ICroppedRectangle::_getViewWidth
int _getViewWidth() const
Definition: MyGUI_ICroppedRectangle.h:149
MyGUI::RenderManager::getVertexFormat
virtual VertexColourType getVertexFormat()=0
MyGUI::ICroppedRectangle::getHeight
int getHeight() const
Definition: MyGUI_ICroppedRectangle.h:119
MyGUI::RenderItem::addDrawItem
void addDrawItem(ISubWidget *_item, size_t _count)
Definition: MyGUI_RenderItem.cpp:125
MyGUI::RenderItem::getCurrentVertexBuffer
Vertex * getCurrentVertexBuffer() const
Definition: MyGUI_RenderItem.cpp:230
MyGUI::ICroppedRectangle::getWidth
int getWidth() const
Definition: MyGUI_ICroppedRectangle.h:114
MyGUI::types::TCoord::height
T height
Definition: MyGUI_TCoord.h:25
MyGUI
Definition: MyGUI_ActionController.h:15
MyGUI::Align::isHStretch
bool isHStretch() const
Definition: MyGUI_Align.h:69
MyGUI::texture_utility::toColourARGB
uint32 toColourARGB(const Colour &_colour)
Definition: MyGUI_TextureUtility.cpp:68
MyGUI::SubSkin::createDrawItem
void createDrawItem(ITexture *_texture, ILayerNode *_node) override
Definition: MyGUI_SubSkin.cpp:174
MyGUI::SubSkin::mSeparate
bool mSeparate
Definition: MyGUI_SubSkin.h:65