MyGUI
3.4.3
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
/*
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
"
11
#include "
MyGUI_LanguageManager.h
"
12
#include "
MyGUI_LayerNode.h
"
13
#include "
MyGUI_CommonStateInfo.h
"
14
#include "
MyGUI_RenderManager.h
"
15
#include "
MyGUI_TextureUtility.h
"
16
17
namespace
MyGUI
18
{
19
20
SubSkin::SubSkin
()
21
{
22
mVertexFormat
=
RenderManager::getInstance
().
getVertexFormat
();
23
}
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
44
void
SubSkin::_correctView
()
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
87
mCurrentCoord
=
mCoord
;
88
_updateView
();
89
}
90
91
void
SubSkin::_updateView
()
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
{
120
mCurrentCoord
.width =
_getViewWidth
();
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
// мы не обрезаны, но были, ставим базовые координаты
146
mCurrentTexture
=
mRectTexture
;
147
}
148
149
// запоминаем текущее состояние
150
mIsMargin
= margin;
151
152
if
(
nullptr
!=
mNode
)
153
mNode
->outOfDate(
mRenderItem
);
154
}
155
156
void
SubSkin::createDrawItem
(
ITexture
* _texture,
ILayerNode
* _node)
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
165
void
SubSkin::destroyDrawItem
()
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
{
201
mCurrentTexture
=
mRectTexture
;
202
}
203
204
if
(
nullptr
!=
mNode
)
205
mNode
->outOfDate(
mRenderItem
);
206
}
207
208
void
SubSkin::doRender
()
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,
242
mCurrentColour
);
243
244
mRenderItem
->setLastVertexCount(
VertexQuad::VertexCount
);
245
}
246
247
void
SubSkin::_setColour
(
const
Colour
& _value)
248
{
249
uint32
colour =
texture_utility::toNativeColour
(_value,
mVertexFormat
);
250
mCurrentColour
= (colour & 0x00FFFFFF) | (
mCurrentColour
& 0xFF000000);
251
252
if
(
nullptr
!=
mNode
)
253
mNode
->outOfDate(
mRenderItem
);
254
}
255
256
void
SubSkin::setStateData
(
IStateInfo
* _data)
257
{
258
_setUVSet
(_data->
castType
<
SubSkinStateInfo
>()->
getRect
());
259
}
260
261
}
// namespace MyGUI
MyGUI_CommonStateInfo.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition
MyGUI_Diagnostic.h:31
MyGUI_LanguageManager.h
MyGUI_LayerNode.h
MyGUI_Precompiled.h
MyGUI_RenderItem.h
MyGUI_RenderManager.h
MyGUI_SkinManager.h
MyGUI_SubSkin.h
MyGUI_TextureUtility.h
MyGUI::ICroppedRectangle::mIsMargin
bool mIsMargin
Definition
MyGUI_ICroppedRectangle.h:248
MyGUI::ICroppedRectangle::mCoord
IntCoord mCoord
Definition
MyGUI_ICroppedRectangle.h:245
MyGUI::ICroppedRectangle::mMargin
IntRect mMargin
Definition
MyGUI_ICroppedRectangle.h:244
MyGUI::ICroppedRectangle::_checkMargin
bool _checkMargin()
Definition
MyGUI_ICroppedRectangle.h:184
MyGUI::ICroppedRectangle::_checkOutside
bool _checkOutside() const
Definition
MyGUI_ICroppedRectangle.h:234
MyGUI::ICroppedRectangle::mCroppedParent
ICroppedRectangle * mCroppedParent
Definition
MyGUI_ICroppedRectangle.h:249
MyGUI::ICroppedRectangle::_getViewWidth
int _getViewWidth() const
Definition
MyGUI_ICroppedRectangle.h:148
MyGUI::ICroppedRectangle::_getViewHeight
int _getViewHeight() const
Definition
MyGUI_ICroppedRectangle.h:152
MyGUI::ILayerNode
Definition
MyGUI_ILayerNode.h:29
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition
MyGUI_IObject.h:18
MyGUI::IStateInfo
Definition
MyGUI_IStateInfo.h:17
MyGUI::ISubWidget::mAlign
Align mAlign
Definition
MyGUI_ISubWidget.h:67
MyGUI::ISubWidget::mVisible
bool mVisible
Definition
MyGUI_ISubWidget.h:68
MyGUI::ITexture
Definition
MyGUI_ITexture.h:28
MyGUI::RenderManager::getVertexFormat
virtual VertexColourType getVertexFormat() const =0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::SubSkin::destroyDrawItem
void destroyDrawItem() override
Definition
MyGUI_SubSkin.cpp:165
MyGUI::SubSkin::mSeparate
bool mSeparate
Definition
MyGUI_SubSkin.h:64
MyGUI::SubSkin::setVisible
void setVisible(bool _visible) override
Definition
MyGUI_SubSkin.cpp:25
MyGUI::SubSkin::mCurrentTexture
FloatRect mCurrentTexture
Definition
MyGUI_SubSkin.h:58
MyGUI::SubSkin::mEmptyView
bool mEmptyView
Definition
MyGUI_SubSkin.h:53
MyGUI::SubSkin::mCurrentCoord
IntCoord mCurrentCoord
Definition
MyGUI_SubSkin.h:59
MyGUI::SubSkin::mNode
ILayerNode * mNode
Definition
MyGUI_SubSkin.h:61
MyGUI::SubSkin::setStateData
void setStateData(IStateInfo *_data) override
Definition
MyGUI_SubSkin.cpp:256
MyGUI::SubSkin::_updateView
void _updateView() override
Definition
MyGUI_SubSkin.cpp:91
MyGUI::SubSkin::mVertexFormat
VertexColourType mVertexFormat
Definition
MyGUI_SubSkin.h:55
MyGUI::SubSkin::doRender
void doRender() override
Definition
MyGUI_SubSkin.cpp:208
MyGUI::SubSkin::_setUVSet
void _setUVSet(const FloatRect &_rect) override
Definition
MyGUI_SubSkin.cpp:174
MyGUI::SubSkin::SubSkin
SubSkin()
Definition
MyGUI_SubSkin.cpp:20
MyGUI::SubSkin::_setColour
void _setColour(const Colour &_value) override
Definition
MyGUI_SubSkin.cpp:247
MyGUI::SubSkin::_correctView
void _correctView() override
Definition
MyGUI_SubSkin.cpp:44
MyGUI::SubSkin::mRenderItem
RenderItem * mRenderItem
Definition
MyGUI_SubSkin.h:62
MyGUI::SubSkin::mRectTexture
FloatRect mRectTexture
Definition
MyGUI_SubSkin.h:52
MyGUI::SubSkin::setAlpha
void setAlpha(float _alpha) override
Definition
MyGUI_SubSkin.cpp:35
MyGUI::SubSkin::mCurrentColour
uint32 mCurrentColour
Definition
MyGUI_SubSkin.h:56
MyGUI::SubSkin::createDrawItem
void createDrawItem(ITexture *_texture, ILayerNode *_node) override
Definition
MyGUI_SubSkin.cpp:156
MyGUI::SubSkin::_setAlign
void _setAlign(const IntSize &_oldsize) override
Definition
MyGUI_SubSkin.cpp:50
MyGUI::SubSkinStateInfo
Definition
MyGUI_CommonStateInfo.h:20
MyGUI::SubSkinStateInfo::getRect
const FloatRect & getRect() const
Definition
MyGUI_CommonStateInfo.h:24
MyGUI::texture_utility::toNativeColour
uint32 toNativeColour(const Colour &_colour, VertexColourType _format)
Convert Colour to 32-bit representation.
Definition
MyGUI_TextureUtility.cpp:63
MyGUI
Definition
MyGUI_ActionController.h:15
MyGUI::uint32
uint32_t uint32
Definition
MyGUI_Types.h:48
MyGUI::uint8
uint8_t uint8
Definition
MyGUI_Types.h:46
MyGUI::FloatRect
types::TRect< float > FloatRect
Definition
MyGUI_Types.h:34
MyGUI::IntSize
types::TSize< int > IntSize
Definition
MyGUI_Types.h:30
MyGUI::Colour
Definition
MyGUI_Colour.h:17
MyGUI::RenderTargetInfo
Definition
MyGUI_RenderTargetInfo.h:16
MyGUI::RenderTargetInfo::vOffset
float vOffset
Definition
MyGUI_RenderTargetInfo.h:29
MyGUI::RenderTargetInfo::topOffset
int topOffset
Definition
MyGUI_RenderTargetInfo.h:33
MyGUI::RenderTargetInfo::hOffset
float hOffset
Definition
MyGUI_RenderTargetInfo.h:28
MyGUI::RenderTargetInfo::pixScaleX
float pixScaleX
Definition
MyGUI_RenderTargetInfo.h:26
MyGUI::RenderTargetInfo::leftOffset
int leftOffset
Definition
MyGUI_RenderTargetInfo.h:32
MyGUI::RenderTargetInfo::pixScaleY
float pixScaleY
Definition
MyGUI_RenderTargetInfo.h:27
MyGUI::VertexQuad
Definition
MyGUI_VertexData.h:34
MyGUI::VertexQuad::VertexCount
@ VertexCount
Definition
MyGUI_VertexData.h:43
MyGUI::VertexQuad::set
void set(float _l, float _t, float _r, float _b, float _z, float _u1, float _v1, float _u2, float _v2, uint32 _colour)
Definition
MyGUI_VertexData.h:46
MyGUI::types::TSize::width
T width
Definition
MyGUI_TSize.h:19
MyGUI::types::TSize::height
T height
Definition
MyGUI_TSize.h:20
Generated by
1.14.0