MyGUI 3.4.1
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 {
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 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 // запоминаем текущее состояние
114 mIsMargin = margin;
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
137 float UV_sizeX = mRectTexture.right - mRectTexture.left;
138 float UV_sizeY = mRectTexture.bottom - mRectTexture.top;
139
140 float UV_lft_total = mRectTexture.left + UV_lft * UV_sizeX;
141 float UV_top_total = mRectTexture.top + UV_top * UV_sizeY;
142 float UV_rgt_total = mRectTexture.right - (1 - UV_rgt) * UV_sizeX;
143 float UV_btm_total = mRectTexture.bottom - (1 - UV_btm) * UV_sizeY;
144
145 mCurrentTexture.set(UV_lft_total, UV_top_total, UV_rgt_total, UV_btm_total);
146 }
147 }
148
149 if (mIsMargin && !margin)
150 {
151 // мы не обрезаны, но были, ставим базовые координаты
153 }
154
155 // запоминаем текущее состояние
156 mIsMargin = margin;
157
158 if (nullptr != mNode)
160 }
161
163 {
164 MYGUI_ASSERT(!mRenderItem, "mRenderItem must be nullptr");
165
166 mNode = _node;
167 mRenderItem = mNode->addToRenderItem(_texture, true, mSeparate);
169 }
170
172 {
173 MYGUI_ASSERT(mRenderItem, "mRenderItem must be not nullptr");
174
175 mNode = nullptr;
177 mRenderItem = nullptr;
178 }
179
180 void SubSkin::_setUVSet(const FloatRect& _rect)
181 {
182 if (mRectTexture == _rect)
183 return;
184 mRectTexture = _rect;
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
194 float UV_sizeX = mRectTexture.right - mRectTexture.left;
195 float UV_sizeY = mRectTexture.bottom - mRectTexture.top;
196
197 float UV_lft_total = mRectTexture.left + UV_lft * UV_sizeX;
198 float UV_top_total = mRectTexture.top + UV_top * UV_sizeY;
199 float UV_rgt_total = mRectTexture.right - (1 - UV_rgt) * UV_sizeX;
200 float UV_btm_total = mRectTexture.bottom - (1 - UV_btm) * UV_sizeY;
201
202 mCurrentTexture.set(UV_lft_total, UV_top_total, UV_rgt_total, UV_btm_total);
203 }
204 // мы не обрезаны, базовые координаты
205 else
206 {
208 }
209
210 if (nullptr != mNode)
212 }
213
215 {
216 if (!mVisible || mEmptyView)
217 return;
218
219 VertexQuad* quad = reinterpret_cast<VertexQuad*>(mRenderItem->getCurrentVertexBuffer());
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(
231 vertex_left,
232 vertex_top,
233 vertex_right,
234 vertex_bottom,
235 vertex_z,
241
243 }
244
245 void SubSkin::_setColour(const Colour& _value)
246 {
247 uint32 colour = texture_utility::toColourARGB(_value);
249 mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
250
251 if (nullptr != mNode)
253 }
254
256 {
258 }
259
260} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
ICroppedRectangle * mCroppedParent
virtual float getNodeDepth() const =0
virtual void outOfDate(RenderItem *_item)=0
virtual RenderItem * addToRenderItem(ITexture *_texture, bool _firstQueue, bool _separate)=0
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
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)
virtual VertexColourType getVertexFormat() const =0
static RenderManager & getInstance()
void destroyDrawItem() override
void setVisible(bool _visible) override
FloatRect mCurrentTexture
Definition: MyGUI_SubSkin.h:59
IntCoord mCurrentCoord
Definition: MyGUI_SubSkin.h:60
ILayerNode * mNode
Definition: MyGUI_SubSkin.h:62
void setStateData(IStateInfo *_data) override
void _updateView() override
VertexColourType mVertexFormat
Definition: MyGUI_SubSkin.h:56
void doRender() override
void _setUVSet(const FloatRect &_rect) override
void _setColour(const Colour &_value) override
void _correctView() override
RenderItem * mRenderItem
Definition: MyGUI_SubSkin.h:63
FloatRect mRectTexture
Definition: MyGUI_SubSkin.h:53
void setAlpha(float _alpha) override
uint32 mCurrentColour
Definition: MyGUI_SubSkin.h:57
void createDrawItem(ITexture *_texture, ILayerNode *_node) override
void _setAlign(const IntSize &_oldsize) override
const FloatRect & getRect() const
void convertColour(uint32 &_colour, VertexColourType _format)
uint32 toColourARGB(const Colour &_colour)
uint8_t uint8
Definition: MyGUI_Types.h:45
uint32_t uint32
Definition: MyGUI_Types.h:47
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(float _l, float _t, float _r, float _b, float _z, float _u1, float _v1, float _u2, float _v2, uint32 _colour)
void set(T const &_left, T const &_top, T const &_right, T const &_bottom)
Definition: MyGUI_TRect.h:121