MyGUI
3.4.2
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
ISubWidgetRect
(),
22
mEmptyView(
false
),
23
mCurrentColour(0xFFFFFFFF),
24
mNode(
nullptr
),
25
mRenderItem(
nullptr
),
26
mSeparate(
false
)
27
{
28
mVertexFormat
=
RenderManager::getInstance
().getVertexFormat();
29
}
30
31
void
SubSkin::setVisible
(
bool
_visible
)
32
{
33
if
(
mVisible
==
_visible
)
34
return
;
35
mVisible
=
_visible
;
36
37
if
(
nullptr
!=
mNode
)
38
mNode
->
outOfDate
(
mRenderItem
);
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
)
47
mNode
->
outOfDate
(
mRenderItem
);
48
}
49
50
void
SubSkin::_correctView
()
51
{
52
if
(
nullptr
!=
mNode
)
53
mNode
->
outOfDate
(
mRenderItem
);
54
}
55
56
void
SubSkin::_setAlign
(
const
IntSize
&
_oldsize
)
57
{
58
// первоначальное выравнивание
59
if
(
mAlign
.
isHStretch
())
60
{
61
// растягиваем
62
mCoord
.
width
=
mCoord
.
width
+ (
mCroppedParent
->
getWidth
() -
_oldsize
.width);
63
mIsMargin
=
true
;
// при изменении размеров все пересчитывать
64
}
65
else
if
(
mAlign
.
isRight
())
66
{
67
// двигаем по правому краю
68
mCoord
.
left
=
mCoord
.
left
+ (
mCroppedParent
->
getWidth
() -
_oldsize
.width);
69
}
70
else
if
(
mAlign
.
isHCenter
())
71
{
72
// выравнивание по горизонтали без растяжения
73
mCoord
.
left
= (
mCroppedParent
->
getWidth
() -
mCoord
.
width
) / 2;
74
}
75
76
if
(
mAlign
.
isVStretch
())
77
{
78
// растягиваем
79
mCoord
.
height
=
mCoord
.
height
+ (
mCroppedParent
->
getHeight
() -
_oldsize
.height);
80
mIsMargin
=
true
;
// при изменении размеров все пересчитывать
81
}
82
else
if
(
mAlign
.
isBottom
())
83
{
84
// двигаем по нижнему краю
85
mCoord
.
top
=
mCoord
.
top
+ (
mCroppedParent
->
getHeight
() -
_oldsize
.height);
86
}
87
else
if
(
mAlign
.
isVCenter
())
88
{
89
// выравнивание по вертикали без растяжения
90
mCoord
.
top
= (
mCroppedParent
->
getHeight
() -
mCoord
.
height
) / 2;
91
}
92
93
mCurrentCoord
=
mCoord
;
94
_updateView
();
95
}
96
97
void
SubSkin::_updateView
()
98
{
99
//mAbsolutePosition = mCroppedParent->getAbsolutePosition() + mCoord.point();
100
bool
margin
=
_checkMargin
();
101
102
mEmptyView
= ((0 >=
_getViewWidth
()) || (0 >=
_getViewHeight
()));
103
104
mCurrentCoord
.
left
=
mCoord
.
left
+
mMargin
.
left
;
105
mCurrentCoord
.
top
=
mCoord
.
top
+
mMargin
.
top
;
106
107
// вьюпорт стал битым
108
if
(
margin
)
109
{
110
// проверка на полный выход за границу
111
if
(
_checkOutside
())
112
{
113
// запоминаем текущее состояние
114
mIsMargin
=
margin
;
115
116
// обновить перед выходом
117
if
(
nullptr
!=
mNode
)
118
mNode
->
outOfDate
(
mRenderItem
);
119
return
;
120
}
121
}
122
123
// мы обрезаны или были обрезаны
124
if
(
mIsMargin
||
margin
)
125
{
126
mCurrentCoord
.
width
=
_getViewWidth
();
127
mCurrentCoord
.
height
=
_getViewHeight
();
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
// мы не обрезаны, но были, ставим базовые координаты
152
mCurrentTexture
=
mRectTexture
;
153
}
154
155
// запоминаем текущее состояние
156
mIsMargin
=
margin
;
157
158
if
(
nullptr
!=
mNode
)
159
mNode
->
outOfDate
(
mRenderItem
);
160
}
161
162
void
SubSkin::createDrawItem
(
ITexture
*
_texture
,
ILayerNode
*
_node
)
163
{
164
MYGUI_ASSERT
(!
mRenderItem
,
"mRenderItem must be nullptr"
);
165
166
mNode
=
_node
;
167
mRenderItem
=
mNode
->
addToRenderItem
(
_texture
,
true
,
mSeparate
);
168
mRenderItem
->
addDrawItem
(
this
,
VertexQuad::VertexCount
);
169
}
170
171
void
SubSkin::destroyDrawItem
()
172
{
173
MYGUI_ASSERT
(
mRenderItem
,
"mRenderItem must be not nullptr"
);
174
175
mNode
=
nullptr
;
176
mRenderItem
->
removeDrawItem
(
this
);
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
{
207
mCurrentTexture
=
mRectTexture
;
208
}
209
210
if
(
nullptr
!=
mNode
)
211
mNode
->
outOfDate
(
mRenderItem
);
212
}
213
214
void
SubSkin::doRender
()
215
{
216
if
(!
mVisible
||
mEmptyView
)
217
return
;
218
219
VertexQuad
*
quad
=
reinterpret_cast<
VertexQuad
*
>
(
mRenderItem
->
getCurrentVertexBuffer
());
220
221
const
RenderTargetInfo
&
info
=
mRenderItem
->
getRenderTarget
()->
getInfo
();
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
,
236
mCurrentTexture
.
left
,
237
mCurrentTexture
.
top
,
238
mCurrentTexture
.
right
,
239
mCurrentTexture
.
bottom
,
240
mCurrentColour
);
241
242
mRenderItem
->
setLastVertexCount
(
VertexQuad::VertexCount
);
243
}
244
245
void
SubSkin::_setColour
(
const
Colour
&
_value
)
246
{
247
uint32
colour =
texture_utility::toNativeColour
(
_value
,
mVertexFormat
);
248
mCurrentColour
= (colour & 0x00FFFFFF) | (
mCurrentColour
& 0xFF000000);
249
250
if
(
nullptr
!=
mNode
)
251
mNode
->
outOfDate
(
mRenderItem
);
252
}
253
254
void
SubSkin::setStateData
(
IStateInfo
*
_data
)
255
{
256
_setUVSet
(
_data
->castType<
SubSkinStateInfo
>()->
getRect
());
257
}
258
259
}
// namespace MyGUI
MyGUI_CommonStateInfo.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition
MyGUI_Diagnostic.h:29
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::Enumerator
Definition
MyGUI_Enumerator.h:49
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::getAbsoluteLeft
int getAbsoluteLeft() const
Definition
MyGUI_ICroppedRectangle.h:83
MyGUI::ICroppedRectangle::_checkMargin
bool _checkMargin()
Definition
MyGUI_ICroppedRectangle.h:185
MyGUI::ICroppedRectangle::getWidth
int getWidth() const
Definition
MyGUI_ICroppedRectangle.h:114
MyGUI::ICroppedRectangle::_checkOutside
bool _checkOutside() const
Definition
MyGUI_ICroppedRectangle.h:235
MyGUI::ICroppedRectangle::getHeight
int getHeight() const
Definition
MyGUI_ICroppedRectangle.h:119
MyGUI::ICroppedRectangle::mCroppedParent
ICroppedRectangle * mCroppedParent
Definition
MyGUI_ICroppedRectangle.h:249
MyGUI::ICroppedRectangle::getAbsoluteTop
int getAbsoluteTop() const
Definition
MyGUI_ICroppedRectangle.h:88
MyGUI::ICroppedRectangle::_getViewWidth
int _getViewWidth() const
Definition
MyGUI_ICroppedRectangle.h:149
MyGUI::ICroppedRectangle::_getViewHeight
int _getViewHeight() const
Definition
MyGUI_ICroppedRectangle.h:153
MyGUI::ILayerNode
Definition
MyGUI_ILayerNode.h:30
MyGUI::ILayerNode::getNodeDepth
virtual float getNodeDepth() const =0
MyGUI::ILayerNode::outOfDate
virtual void outOfDate(RenderItem *_item)=0
MyGUI::ILayerNode::addToRenderItem
virtual RenderItem * addToRenderItem(ITexture *_texture, bool _firstQueue, bool _separate)=0
MyGUI::IRenderTarget::getInfo
virtual const RenderTargetInfo & getInfo() const =0
MyGUI::IStateInfo
Definition
MyGUI_IStateInfo.h:18
MyGUI::ISubWidget::mAlign
Align mAlign
Definition
MyGUI_ISubWidget.h:59
MyGUI::ISubWidget::mVisible
bool mVisible
Definition
MyGUI_ISubWidget.h:60
MyGUI::ISubWidgetRect
Definition
MyGUI_ISubWidgetRect.h:19
MyGUI::ITexture
Definition
MyGUI_ITexture.h:28
MyGUI::RenderItem::addDrawItem
void addDrawItem(ISubWidget *_item, size_t _count)
Definition
MyGUI_RenderItem.cpp:125
MyGUI::RenderItem::getRenderTarget
IRenderTarget * getRenderTarget()
Definition
MyGUI_RenderItem.cpp:240
MyGUI::RenderItem::removeDrawItem
void removeDrawItem(ISubWidget *_item)
Definition
MyGUI_RenderItem.cpp:100
MyGUI::RenderItem::getCurrentVertexBuffer
Vertex * getCurrentVertexBuffer() const
Definition
MyGUI_RenderItem.cpp:230
MyGUI::RenderItem::setLastVertexCount
void setLastVertexCount(size_t _count)
Definition
MyGUI_RenderItem.cpp:235
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::SubSkin::destroyDrawItem
void destroyDrawItem() override
Definition
MyGUI_SubSkin.cpp:171
MyGUI::SubSkin::mSeparate
bool mSeparate
Definition
MyGUI_SubSkin.h:65
MyGUI::SubSkin::setVisible
void setVisible(bool _visible) override
Definition
MyGUI_SubSkin.cpp:31
MyGUI::SubSkin::mCurrentTexture
FloatRect mCurrentTexture
Definition
MyGUI_SubSkin.h:59
MyGUI::SubSkin::mEmptyView
bool mEmptyView
Definition
MyGUI_SubSkin.h:54
MyGUI::SubSkin::mCurrentCoord
IntCoord mCurrentCoord
Definition
MyGUI_SubSkin.h:60
MyGUI::SubSkin::mNode
ILayerNode * mNode
Definition
MyGUI_SubSkin.h:62
MyGUI::SubSkin::setStateData
void setStateData(IStateInfo *_data) override
Definition
MyGUI_SubSkin.cpp:254
MyGUI::SubSkin::_updateView
void _updateView() override
Definition
MyGUI_SubSkin.cpp:97
MyGUI::SubSkin::mVertexFormat
VertexColourType mVertexFormat
Definition
MyGUI_SubSkin.h:56
MyGUI::SubSkin::doRender
void doRender() override
Definition
MyGUI_SubSkin.cpp:214
MyGUI::SubSkin::_setUVSet
void _setUVSet(const FloatRect &_rect) override
Definition
MyGUI_SubSkin.cpp:180
MyGUI::SubSkin::SubSkin
SubSkin()
Definition
MyGUI_SubSkin.cpp:20
MyGUI::SubSkin::_setColour
void _setColour(const Colour &_value) override
Definition
MyGUI_SubSkin.cpp:245
MyGUI::SubSkin::_correctView
void _correctView() override
Definition
MyGUI_SubSkin.cpp:50
MyGUI::SubSkin::mRenderItem
RenderItem * mRenderItem
Definition
MyGUI_SubSkin.h:63
MyGUI::SubSkin::mRectTexture
FloatRect mRectTexture
Definition
MyGUI_SubSkin.h:53
MyGUI::SubSkin::setAlpha
void setAlpha(float _alpha) override
Definition
MyGUI_SubSkin.cpp:41
MyGUI::SubSkin::mCurrentColour
uint32 mCurrentColour
Definition
MyGUI_SubSkin.h:57
MyGUI::SubSkin::createDrawItem
void createDrawItem(ITexture *_texture, ILayerNode *_node) override
Definition
MyGUI_SubSkin.cpp:162
MyGUI::SubSkin::_setAlign
void _setAlign(const IntSize &_oldsize) override
Definition
MyGUI_SubSkin.cpp:56
MyGUI::SubSkinStateInfo
Definition
MyGUI_CommonStateInfo.h:21
MyGUI::SubSkinStateInfo::getRect
const FloatRect & getRect() const
Definition
MyGUI_CommonStateInfo.h:25
MyGUI::texture_utility::toNativeColour
uint32 toNativeColour(const Colour &_colour, VertexColourType _format)
Convert Colour to 32-bit representation.
Definition
MyGUI_TextureUtility.cpp:68
MyGUI
Definition
MyGUI_ActionController.h:15
MyGUI::uint8
uint8_t uint8
Definition
MyGUI_Types.h:46
MyGUI::Align::isHStretch
bool isHStretch() const
Definition
MyGUI_Align.h:69
MyGUI::Align::isVCenter
bool isVCenter() const
Definition
MyGUI_Align.h:49
MyGUI::Align::isVStretch
bool isVStretch() const
Definition
MyGUI_Align.h:84
MyGUI::Align::isRight
bool isRight() const
Definition
MyGUI_Align.h:64
MyGUI::Align::isHCenter
bool isHCenter() const
Definition
MyGUI_Align.h:44
MyGUI::Align::isBottom
bool isBottom() const
Definition
MyGUI_Align.h:79
MyGUI::Colour
Definition
MyGUI_Colour.h:17
MyGUI::RenderTargetInfo
Definition
MyGUI_RenderTargetInfo.h:16
MyGUI::VertexQuad
Definition
MyGUI_VertexData.h:34
MyGUI::VertexQuad::VertexCount
@ VertexCount
Definition
MyGUI_VertexData.h:43
MyGUI::types::TCoord::height
T height
Definition
MyGUI_TCoord.h:25
MyGUI::types::TCoord::width
T width
Definition
MyGUI_TCoord.h:24
MyGUI::types::TCoord::top
T top
Definition
MyGUI_TCoord.h:23
MyGUI::types::TCoord::left
T left
Definition
MyGUI_TCoord.h:22
MyGUI::types::TRect< float >
MyGUI::types::TRect::right
T right
Definition
MyGUI_TRect.h:22
MyGUI::types::TRect::set
void set(T const &_left, T const &_top, T const &_right, T const &_bottom)
Definition
MyGUI_TRect.h:121
MyGUI::types::TRect::left
T left
Definition
MyGUI_TRect.h:20
MyGUI::types::TRect::bottom
T bottom
Definition
MyGUI_TRect.h:23
MyGUI::types::TRect::top
T top
Definition
MyGUI_TRect.h:21
MyGUI::types::TSize< int >
Generated by
1.9.8