MyGUI 3.4.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"
12#include "MyGUI_LayerNode.h"
14#include "MyGUI_RenderManager.h"
16
17namespace MyGUI
18{
19
22 mEmptyView(false),
23 mCurrentColour(0xFFFFFFFF),
24 mNode(nullptr),
25 mRenderItem(nullptr),
26 mSeparate(false)
27 {
28 mVertexFormat = RenderManager::getInstance().getVertexFormat();
29 }
30
32 {
33 if (mVisible == _visible)
34 return;
36
37 if (nullptr != mNode)
39 }
40
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
57 {
58 // первоначальное выравнивание
59 if (mAlign.isHStretch())
60 {
61 // растягиваем
63 mIsMargin = true; // при изменении размеров все пересчитывать
64 }
65 else if (mAlign.isRight())
66 {
67 // двигаем по правому краю
69 }
70 else if (mAlign.isHCenter())
71 {
72 // выравнивание по горизонтали без растяжения
74 }
75
76 if (mAlign.isVStretch())
77 {
78 // растягиваем
80 mIsMargin = true; // при изменении размеров все пересчитывать
81 }
82 else if (mAlign.isBottom())
83 {
84 // двигаем по нижнему краю
86 }
87 else if (mAlign.isVCenter())
88 {
89 // выравнивание по вертикали без растяжения
91 }
92
95 }
96
98 {
99 //mAbsolutePosition = mCroppedParent->getAbsolutePosition() + mCoord.point();
100 bool margin = _checkMargin();
101
102 mEmptyView = ((0 >= _getViewWidth()) || (0 >= _getViewHeight()));
103
106
107 // вьюпорт стал битым
108 if (margin)
109 {
110 // проверка на полный выход за границу
111 if (_checkOutside())
112 {
113 // запоминаем текущее состояние
115
116 // обновить перед выходом
117 if (nullptr != mNode)
119 return;
120 }
121 }
122
123 // мы обрезаны или были обрезаны
124 if (mIsMargin || margin)
125 {
128
129 if ((mCurrentCoord.width > 0) && (mCurrentCoord.height > 0))
130 {
131 // теперь смещаем текстуру
132 float UV_lft = mMargin.left / (float)mCoord.width;
133 float UV_top = mMargin.top / (float)mCoord.height;
134 float UV_rgt = (mCoord.width - mMargin.right) / (float)mCoord.width;
135 float UV_btm = (mCoord.height - mMargin.bottom) / (float)mCoord.height;
136
139
144
146 }
147 }
148
149 if (mIsMargin && !margin)
150 {
151 // мы не обрезаны, но были, ставим базовые координаты
153 }
154
155 // запоминаем текущее состояние
157
158 if (nullptr != mNode)
160 }
161
163 {
164 MYGUI_ASSERT(!mRenderItem, "mRenderItem must be nullptr");
165
166 mNode = _node;
169 }
170
172 {
173 MYGUI_ASSERT(mRenderItem, "mRenderItem must be not nullptr");
174
175 mNode = nullptr;
177 mRenderItem = nullptr;
178 }
179
181 {
182 if (mRectTexture == _rect)
183 return;
185
186 // если обрезаны, то просчитываем с учето обрезки
187 if (mIsMargin)
188 {
189 float UV_lft = mMargin.left / (float)mCoord.width;
190 float UV_top = mMargin.top / (float)mCoord.height;
191 float UV_rgt = (mCoord.width - mMargin.right) / (float)mCoord.width;
192 float UV_btm = (mCoord.height - mMargin.bottom) / (float)mCoord.height;
193
196
201
203 }
204 // мы не обрезаны, базовые координаты
205 else
206 {
208 }
209
210 if (nullptr != mNode)
212 }
213
215 {
216 if (!mVisible || mEmptyView)
217 return;
218
220
222
223 float vertex_z = mNode->getNodeDepth();
224
225 float vertex_left = ((info.pixScaleX * (float)(mCurrentCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) + info.hOffset) * 2) - 1;
226 float vertex_right = vertex_left + (info.pixScaleX * (float)mCurrentCoord.width * 2);
227 float vertex_top = -(((info.pixScaleY * (float)(mCurrentCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) + info.vOffset) * 2) - 1);
228 float vertex_bottom = vertex_top - (info.pixScaleY * (float)mCurrentCoord.height * 2);
229
230 quad->set(
235 vertex_z,
241
243 }
244
246 {
248 mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
249
250 if (nullptr != mNode)
252 }
253
255 {
256 _setUVSet(_data->castType<SubSkinStateInfo>()->getRect());
257 }
258
259} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
virtual float getNodeDepth() const =0
virtual void outOfDate(RenderItem *_item)=0
virtual RenderItem * addToRenderItem(ITexture *_texture, bool _firstQueue, bool _separate)=0
virtual const RenderTargetInfo & getInfo() const =0
void addDrawItem(ISubWidget *_item, size_t _count)
IRenderTarget * getRenderTarget()
void removeDrawItem(ISubWidget *_item)
Vertex * getCurrentVertexBuffer() const
void setLastVertexCount(size_t _count)
static RenderManager & getInstance()
void destroyDrawItem() override
void setVisible(bool _visible) override
FloatRect mCurrentTexture
IntCoord mCurrentCoord
ILayerNode * mNode
void setStateData(IStateInfo *_data) override
void _updateView() override
VertexColourType mVertexFormat
void doRender() override
void _setUVSet(const FloatRect &_rect) override
void _setColour(const Colour &_value) override
void _correctView() override
RenderItem * mRenderItem
FloatRect mRectTexture
void setAlpha(float _alpha) override
uint32 mCurrentColour
void createDrawItem(ITexture *_texture, ILayerNode *_node) override
void _setAlign(const IntSize &_oldsize) override
const FloatRect & getRect() const
uint32 toNativeColour(const Colour &_colour, VertexColourType _format)
Convert Colour to 32-bit representation.
uint8_t uint8
Definition MyGUI_Types.h:46
bool isHStretch() const
Definition MyGUI_Align.h:69
bool isVCenter() const
Definition MyGUI_Align.h:49
bool isVStretch() const
Definition MyGUI_Align.h:84
bool isRight() const
Definition MyGUI_Align.h:64
bool isHCenter() const
Definition MyGUI_Align.h:44
bool isBottom() const
Definition MyGUI_Align.h:79
void set(T const &_left, T const &_top, T const &_right, T const &_bottom)