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