MyGUI 3.4.3
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
24
25 void SubSkin::setVisible(bool _visible)
26 {
27 if (mVisible == _visible)
28 return;
29 mVisible = _visible;
30
31 if (nullptr != mNode)
32 mNode->outOfDate(mRenderItem);
33 }
34
35 void SubSkin::setAlpha(float _alpha)
36 {
37 uint32 alpha = ((uint8)(_alpha * 255) << 24);
38 mCurrentColour = (mCurrentColour & 0x00FFFFFF) | (alpha & 0xFF000000);
39
40 if (nullptr != mNode)
41 mNode->outOfDate(mRenderItem);
42 }
43
45 {
46 if (nullptr != mNode)
47 mNode->outOfDate(mRenderItem);
48 }
49
50 void SubSkin::_setAlign(const IntSize& _oldsize)
51 {
52 // первоначальное выравнивание
53 if (mAlign.isHStretch())
54 {
55 // растягиваем
56 mCoord.width = mCoord.width + (mCroppedParent->getWidth() - _oldsize.width);
57 mIsMargin = true; // при изменении размеров все пересчитывать
58 }
59 else if (mAlign.isRight())
60 {
61 // двигаем по правому краю
62 mCoord.left = mCoord.left + (mCroppedParent->getWidth() - _oldsize.width);
63 }
64 else if (mAlign.isHCenter())
65 {
66 // выравнивание по горизонтали без растяжения
67 mCoord.left = (mCroppedParent->getWidth() - mCoord.width) / 2;
68 }
69
70 if (mAlign.isVStretch())
71 {
72 // растягиваем
73 mCoord.height = mCoord.height + (mCroppedParent->getHeight() - _oldsize.height);
74 mIsMargin = true; // при изменении размеров все пересчитывать
75 }
76 else if (mAlign.isBottom())
77 {
78 // двигаем по нижнему краю
79 mCoord.top = mCoord.top + (mCroppedParent->getHeight() - _oldsize.height);
80 }
81 else if (mAlign.isVCenter())
82 {
83 // выравнивание по вертикали без растяжения
84 mCoord.top = (mCroppedParent->getHeight() - mCoord.height) / 2;
85 }
86
89 }
90
92 {
93 //mAbsolutePosition = mCroppedParent->getAbsolutePosition() + mCoord.point();
94 bool margin = _checkMargin();
95
96 mEmptyView = ((0 >= _getViewWidth()) || (0 >= _getViewHeight()));
97
98 mCurrentCoord.left = mCoord.left + mMargin.left;
99 mCurrentCoord.top = mCoord.top + mMargin.top;
100
101 // вьюпорт стал битым
102 if (margin)
103 {
104 // проверка на полный выход за границу
105 if (_checkOutside())
106 {
107 // запоминаем текущее состояние
108 mIsMargin = margin;
109
110 // обновить перед выходом
111 if (nullptr != mNode)
112 mNode->outOfDate(mRenderItem);
113 return;
114 }
115 }
116
117 // мы обрезаны или были обрезаны
118 if (mIsMargin || margin)
119 {
121 mCurrentCoord.height = _getViewHeight();
122
123 if ((mCurrentCoord.width > 0) && (mCurrentCoord.height > 0))
124 {
125 // теперь смещаем текстуру
126 float UV_lft = mMargin.left / (float)mCoord.width;
127 float UV_top = mMargin.top / (float)mCoord.height;
128 float UV_rgt = (mCoord.width - mMargin.right) / (float)mCoord.width;
129 float UV_btm = (mCoord.height - mMargin.bottom) / (float)mCoord.height;
130
131 float UV_sizeX = mRectTexture.right - mRectTexture.left;
132 float UV_sizeY = mRectTexture.bottom - mRectTexture.top;
133
134 float UV_lft_total = mRectTexture.left + UV_lft * UV_sizeX;
135 float UV_top_total = mRectTexture.top + UV_top * UV_sizeY;
136 float UV_rgt_total = mRectTexture.right - (1 - UV_rgt) * UV_sizeX;
137 float UV_btm_total = mRectTexture.bottom - (1 - UV_btm) * UV_sizeY;
138
139 mCurrentTexture.set(UV_lft_total, UV_top_total, UV_rgt_total, UV_btm_total);
140 }
141 }
142
143 if (mIsMargin && !margin)
144 {
145 // мы не обрезаны, но были, ставим базовые координаты
147 }
148
149 // запоминаем текущее состояние
150 mIsMargin = margin;
151
152 if (nullptr != mNode)
153 mNode->outOfDate(mRenderItem);
154 }
155
157 {
158 MYGUI_ASSERT(!mRenderItem, "mRenderItem must be nullptr");
159
160 mNode = _node;
161 mRenderItem = mNode->addToRenderItem(_texture, true, mSeparate);
162 mRenderItem->addDrawItem(this, VertexQuad::VertexCount);
163 }
164
166 {
167 MYGUI_ASSERT(mRenderItem, "mRenderItem must be not nullptr");
168
169 mNode = nullptr;
170 mRenderItem->removeDrawItem(this);
171 mRenderItem = nullptr;
172 }
173
174 void SubSkin::_setUVSet(const FloatRect& _rect)
175 {
176 if (mRectTexture == _rect)
177 return;
178 mRectTexture = _rect;
179
180 // если обрезаны, то просчитываем с учето обрезки
181 if (mIsMargin)
182 {
183 float UV_lft = mMargin.left / (float)mCoord.width;
184 float UV_top = mMargin.top / (float)mCoord.height;
185 float UV_rgt = (mCoord.width - mMargin.right) / (float)mCoord.width;
186 float UV_btm = (mCoord.height - mMargin.bottom) / (float)mCoord.height;
187
188 float UV_sizeX = mRectTexture.right - mRectTexture.left;
189 float UV_sizeY = mRectTexture.bottom - mRectTexture.top;
190
191 float UV_lft_total = mRectTexture.left + UV_lft * UV_sizeX;
192 float UV_top_total = mRectTexture.top + UV_top * UV_sizeY;
193 float UV_rgt_total = mRectTexture.right - (1 - UV_rgt) * UV_sizeX;
194 float UV_btm_total = mRectTexture.bottom - (1 - UV_btm) * UV_sizeY;
195
196 mCurrentTexture.set(UV_lft_total, UV_top_total, UV_rgt_total, UV_btm_total);
197 }
198 // мы не обрезаны, базовые координаты
199 else
200 {
202 }
203
204 if (nullptr != mNode)
205 mNode->outOfDate(mRenderItem);
206 }
207
209 {
210 if (!mVisible || mEmptyView)
211 return;
212
213 VertexQuad* quad = reinterpret_cast<VertexQuad*>(mRenderItem->getCurrentVertexBuffer());
214
215 const RenderTargetInfo& info = mRenderItem->getRenderTarget()->getInfo();
216
217 float vertex_z = mNode->getNodeDepth();
218
219 float vertex_left =
220 ((info.pixScaleX * (float)(mCurrentCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) +
221 info.hOffset) *
222 2) -
223 1;
224 float vertex_right = vertex_left + (info.pixScaleX * (float)mCurrentCoord.width * 2);
225 float vertex_top =
226 -(((info.pixScaleY * (float)(mCurrentCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) +
227 info.vOffset) *
228 2) -
229 1);
230 float vertex_bottom = vertex_top - (info.pixScaleY * (float)mCurrentCoord.height * 2);
231
232 quad->set(
233 vertex_left,
234 vertex_top,
235 vertex_right,
236 vertex_bottom,
237 vertex_z,
238 mCurrentTexture.left,
239 mCurrentTexture.top,
240 mCurrentTexture.right,
241 mCurrentTexture.bottom,
243
244 mRenderItem->setLastVertexCount(VertexQuad::VertexCount);
245 }
246
247 void SubSkin::_setColour(const Colour& _value)
248 {
250 mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
251
252 if (nullptr != mNode)
253 mNode->outOfDate(mRenderItem);
254 }
255
257 {
259 }
260
261} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
Type * castType(bool _throw=true)
virtual VertexColourType getVertexFormat() const =0
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.
uint32_t uint32
Definition MyGUI_Types.h:48
uint8_t uint8
Definition MyGUI_Types.h:46
types::TRect< float > FloatRect
Definition MyGUI_Types.h:34
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
void set(float _l, float _t, float _r, float _b, float _z, float _u1, float _v1, float _u2, float _v2, uint32 _colour)