MyGUI
3.2.0
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
MyGUIEngine
src
MyGUI_SubSkin.cpp
Go to the documentation of this file.
1
6
/*
7
This file is part of MyGUI.
8
9
MyGUI is free software: you can redistribute it and/or modify
10
it under the terms of the GNU Lesser General Public License as published by
11
the Free Software Foundation, either version 3 of the License, or
12
(at your option) any later version.
13
14
MyGUI is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public License
20
along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21
*/
22
#include "
MyGUI_Precompiled.h
"
23
#include "
MyGUI_SubSkin.h
"
24
#include "
MyGUI_RenderItem.h
"
25
#include "
MyGUI_SkinManager.h
"
26
#include "
MyGUI_LanguageManager.h
"
27
#include "
MyGUI_LayerNode.h
"
28
#include "
MyGUI_CommonStateInfo.h
"
29
#include "
MyGUI_RenderManager.h
"
30
#include "
MyGUI_TextureUtility.h
"
31
32
namespace
MyGUI
33
{
34
35
SubSkin::SubSkin
() :
36
ISubWidgetRect
(),
37
mEmptyView(false),
38
mCurrentColour(0xFFFFFFFF),
39
mNode(
nullptr
),
40
mRenderItem(
nullptr
),
41
mSeparate(false)
42
{
43
mVertexFormat
=
RenderManager::getInstance
().
getVertexFormat
();
44
}
45
46
SubSkin::~SubSkin
()
47
{
48
}
49
50
void
SubSkin::setVisible
(
bool
_visible)
51
{
52
if
(
mVisible
== _visible)
return
;
53
mVisible
= _visible;
54
55
if
(
nullptr
!=
mNode
)
mNode
->
outOfDate
(
mRenderItem
);
56
}
57
58
void
SubSkin::setAlpha
(
float
_alpha)
59
{
60
uint32
alpha = ((
uint8
)(_alpha * 255) << 24);
61
mCurrentColour
= (
mCurrentColour
& 0x00FFFFFF) | (alpha & 0xFF000000);
62
63
if
(
nullptr
!=
mNode
)
64
mNode
->
outOfDate
(
mRenderItem
);
65
}
66
67
void
SubSkin::_correctView
()
68
{
69
if
(
nullptr
!=
mNode
)
mNode
->
outOfDate
(
mRenderItem
);
70
}
71
72
void
SubSkin::_setAlign
(
const
IntSize
& _oldsize)
73
{
74
// необходимо разобраться
75
bool
need_update =
true
;
//_update;
76
77
// первоначальное выравнивание
78
if
(
mAlign
.
isHStretch
())
79
{
80
// растягиваем
81
mCoord
.
width
=
mCoord
.
width
+ (
mCroppedParent
->
getWidth
() - _oldsize.
width
);
82
need_update =
true
;
83
mIsMargin
=
true
;
// при изменении размеров все пересчитывать
84
}
85
else
if
(
mAlign
.
isRight
())
86
{
87
// двигаем по правому краю
88
mCoord
.
left
=
mCoord
.
left
+ (
mCroppedParent
->
getWidth
() - _oldsize.
width
);
89
need_update =
true
;
90
}
91
else
if
(
mAlign
.
isHCenter
())
92
{
93
// выравнивание по горизонтали без растяжения
94
mCoord
.
left
= (
mCroppedParent
->
getWidth
() -
mCoord
.
width
) / 2;
95
need_update =
true
;
96
}
97
98
if
(
mAlign
.
isVStretch
())
99
{
100
// растягиваем
101
mCoord
.
height
=
mCoord
.
height
+ (
mCroppedParent
->
getHeight
() - _oldsize.
height
);
102
need_update =
true
;
103
mIsMargin
=
true
;
// при изменении размеров все пересчитывать
104
}
105
else
if
(
mAlign
.
isBottom
())
106
{
107
// двигаем по нижнему краю
108
mCoord
.
top
=
mCoord
.
top
+ (
mCroppedParent
->
getHeight
() - _oldsize.
height
);
109
need_update =
true
;
110
}
111
else
if
(
mAlign
.
isVCenter
())
112
{
113
// выравнивание по вертикали без растяжения
114
mCoord
.
top
= (
mCroppedParent
->
getHeight
() -
mCoord
.
height
) / 2;
115
need_update =
true
;
116
}
117
118
if
(need_update)
119
{
120
mCurrentCoord
=
mCoord
;
121
_updateView
();
122
}
123
124
}
125
126
void
SubSkin::_updateView
()
127
{
128
//mAbsolutePosition = mCroppedParent->getAbsolutePosition() + mCoord.point();
129
bool
margin =
_checkMargin
();
130
131
mEmptyView
= ((0 >=
_getViewWidth
()) || (0 >=
_getViewHeight
()));
132
133
mCurrentCoord
.
left
=
mCoord
.
left
+
mMargin
.
left
;
134
mCurrentCoord
.
top
=
mCoord
.
top
+
mMargin
.
top
;
135
136
// вьюпорт стал битым
137
if
(margin)
138
{
139
// проверка на полный выход за границу
140
if
(
_checkOutside
())
141
{
142
143
// запоминаем текущее состояние
144
mIsMargin
= margin;
145
146
// обновить перед выходом
147
if
(
nullptr
!=
mNode
)
mNode
->
outOfDate
(
mRenderItem
);
148
return
;
149
}
150
}
151
152
// мы обрезаны или были обрезаны
153
if
(
mIsMargin
|| margin )
154
{
155
mCurrentCoord
.
width
=
_getViewWidth
();
156
mCurrentCoord
.
height
=
_getViewHeight
();
157
158
if
( (
mCurrentCoord
.
width
> 0) && (
mCurrentCoord
.
height
> 0) )
159
{
160
// теперь смещаем текстуру
161
float
UV_lft =
mMargin
.
left
/ (float)
mCoord
.
width
;
162
float
UV_top =
mMargin
.
top
/ (
float
)
mCoord
.
height
;
163
float
UV_rgt = (
mCoord
.
width
-
mMargin
.
right
) / (
float
)
mCoord
.
width
;
164
float
UV_btm = (
mCoord
.
height
-
mMargin
.
bottom
) / (
float
)
mCoord
.
height
;
165
166
float
UV_sizeX =
mRectTexture
.
right
-
mRectTexture
.
left
;
167
float
UV_sizeY =
mRectTexture
.
bottom
-
mRectTexture
.
top
;
168
169
float
UV_lft_total =
mRectTexture
.
left
+ UV_lft * UV_sizeX;
170
float
UV_top_total =
mRectTexture
.
top
+ UV_top * UV_sizeY;
171
float
UV_rgt_total =
mRectTexture
.
right
- (1 - UV_rgt) * UV_sizeX;
172
float
UV_btm_total =
mRectTexture
.
bottom
- (1 - UV_btm) * UV_sizeY;
173
174
mCurrentTexture
.
set
(UV_lft_total, UV_top_total, UV_rgt_total, UV_btm_total);
175
}
176
}
177
178
if
(
mIsMargin
&& !margin)
179
{
180
// мы не обрезаны, но были, ставим базовые координаты
181
mCurrentTexture
=
mRectTexture
;
182
}
183
184
// запоминаем текущее состояние
185
mIsMargin
= margin;
186
187
if
(
nullptr
!=
mNode
)
mNode
->
outOfDate
(
mRenderItem
);
188
}
189
190
void
SubSkin::createDrawItem
(
ITexture
* _texture,
ILayerNode
* _node)
191
{
192
MYGUI_ASSERT
(!
mRenderItem
,
"mRenderItem must be nullptr"
);
193
194
mNode
= _node;
195
mRenderItem
=
mNode
->
addToRenderItem
(_texture,
true
,
mSeparate
);
196
mRenderItem
->
addDrawItem
(
this
,
VertexQuad::VertexCount
);
197
}
198
199
void
SubSkin::destroyDrawItem
()
200
{
201
MYGUI_ASSERT
(
mRenderItem
,
"mRenderItem must be not nullptr"
);
202
203
mNode
=
nullptr
;
204
mRenderItem
->
removeDrawItem
(
this
);
205
mRenderItem
=
nullptr
;
206
}
207
208
void
SubSkin::_setUVSet
(
const
FloatRect
& _rect)
209
{
210
if
(
mRectTexture
== _rect)
return
;
211
mRectTexture
= _rect;
212
213
// если обрезаны, то просчитываем с учето обрезки
214
if
(
mIsMargin
)
215
{
216
float
UV_lft =
mMargin
.
left
/ (float)
mCoord
.
width
;
217
float
UV_top =
mMargin
.
top
/ (
float
)
mCoord
.
height
;
218
float
UV_rgt = (
mCoord
.
width
-
mMargin
.
right
) / (
float
)
mCoord
.
width
;
219
float
UV_btm = (
mCoord
.
height
-
mMargin
.
bottom
) / (
float
)
mCoord
.
height
;
220
221
float
UV_sizeX =
mRectTexture
.
right
-
mRectTexture
.
left
;
222
float
UV_sizeY =
mRectTexture
.
bottom
-
mRectTexture
.
top
;
223
224
float
UV_lft_total =
mRectTexture
.
left
+ UV_lft * UV_sizeX;
225
float
UV_top_total =
mRectTexture
.
top
+ UV_top * UV_sizeY;
226
float
UV_rgt_total =
mRectTexture
.
right
- (1 - UV_rgt) * UV_sizeX;
227
float
UV_btm_total =
mRectTexture
.
bottom
- (1 - UV_btm) * UV_sizeY;
228
229
mCurrentTexture
.
set
(UV_lft_total, UV_top_total, UV_rgt_total, UV_btm_total);
230
}
231
232
// мы не обрезаны, базовые координаты
233
else
234
{
235
mCurrentTexture
=
mRectTexture
;
236
}
237
238
if
(
nullptr
!=
mNode
)
mNode
->
outOfDate
(
mRenderItem
);
239
}
240
241
void
SubSkin::doRender
()
242
{
243
if
(!
mVisible
||
mEmptyView
)
return
;
244
245
VertexQuad
* quad = (
VertexQuad
*)
mRenderItem
->
getCurrentVertexBuffer
();
246
247
const
RenderTargetInfo
& info =
mRenderItem
->
getRenderTarget
()->
getInfo
();
248
249
float
vertex_z = info.
maximumDepth
;
250
251
float
vertex_left = ((info.
pixScaleX
* (float)(
mCurrentCoord
.
left
+
mCroppedParent
->
getAbsoluteLeft
() - info.
leftOffset
) + info.
hOffset
) * 2) - 1;
252
float
vertex_right = vertex_left + (info.
pixScaleX
* (float)
mCurrentCoord
.
width
* 2);
253
float
vertex_top = -(((info.
pixScaleY
* (float)(
mCurrentCoord
.
top
+
mCroppedParent
->
getAbsoluteTop
() - info.
topOffset
) + info.
vOffset
) * 2) - 1);
254
float
vertex_bottom = vertex_top - (info.
pixScaleY
* (float)
mCurrentCoord
.
height
* 2);
255
256
quad->
set
(
257
vertex_left,
258
vertex_top,
259
vertex_right,
260
vertex_bottom,
261
vertex_z,
262
mCurrentTexture
.
left
,
263
mCurrentTexture
.
top
,
264
mCurrentTexture
.
right
,
265
mCurrentTexture
.
bottom
,
266
mCurrentColour
267
);
268
269
mRenderItem
->
setLastVertexCount
(
VertexQuad::VertexCount
);
270
}
271
272
void
SubSkin::_setColour
(
const
Colour
& _value)
273
{
274
uint32
colour =
texture_utility::toColourARGB
(_value);
275
texture_utility::convertColour
(colour,
mVertexFormat
);
276
mCurrentColour
= (colour & 0x00FFFFFF) | (
mCurrentColour
& 0xFF000000);
277
278
if
(
nullptr
!=
mNode
)
279
mNode
->
outOfDate
(
mRenderItem
);
280
}
281
282
void
SubSkin::setStateData
(
IStateInfo
* _data)
283
{
284
_setUVSet
(_data->
castType
<
SubSkinStateInfo
>()->
getRect
());
285
}
286
287
}
// namespace MyGUI
Generated on Tue Apr 30 2013 23:15:05 for MyGUI by
1.8.3.1