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