MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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
MyGUI::ICroppedRectangle::getAbsoluteLeft
int getAbsoluteLeft() const
Definition: MyGUI_ICroppedRectangle.h:98
MyGUI_TextureUtility.h
MyGUI::SubSkin::mEmptyView
bool mEmptyView
Definition: MyGUI_SubSkin.h:70
MyGUI::Align::isVStretch
bool isVStretch() const
Definition: MyGUI_Align.h:99
MyGUI::uint32
unsigned int uint32
Definition: MyGUI_Types.h:63
MyGUI::ILayerNode::outOfDate
virtual void outOfDate(RenderItem *_item)=0
MyGUI::RenderTargetInfo::pixScaleY
float pixScaleY
Definition: MyGUI_RenderTargetInfo.h:54
MyGUI::ILayerNode
Definition: MyGUI_ILayerNode.h:42
MyGUI::ISubWidgetRect
Definition: MyGUI_ISubWidgetRect.h:32
MyGUI::RenderItem::removeDrawItem
void removeDrawItem(ISubWidget *_item)
Definition: MyGUI_RenderItem.cpp:113
MyGUI::RenderTargetInfo::maximumDepth
float maximumDepth
Definition: MyGUI_RenderTargetInfo.h:52
MyGUI::VertexQuad
Definition: MyGUI_VertexData.h:48
MyGUI::SubSkin::~SubSkin
virtual ~SubSkin()
Definition: MyGUI_SubSkin.cpp:46
MyGUI::types::TRect::top
T top
Definition: MyGUI_TRect.h:36
MyGUI::RenderItem::addDrawItem
void addDrawItem(ISubWidget *_item, size_t _count)
Definition: MyGUI_RenderItem.cpp:138
MyGUI_Precompiled.h
MyGUI::RenderTargetInfo::leftOffset
int leftOffset
Definition: MyGUI_RenderTargetInfo.h:59
MyGUI::ICroppedRectangle::_getViewHeight
int _getViewHeight() const
Definition: MyGUI_ICroppedRectangle.h:168
MyGUI::ICroppedRectangle::mIsMargin
bool mIsMargin
Definition: MyGUI_ICroppedRectangle.h:263
MyGUI::ICroppedRectangle::getHeight
int getHeight() const
Definition: MyGUI_ICroppedRectangle.h:134
MyGUI::RenderItem::getRenderTarget
IRenderTarget * getRenderTarget()
Definition: MyGUI_RenderItem.cpp:250
MyGUI::Align::isBottom
bool isBottom() const
Definition: MyGUI_Align.h:94
MyGUI::SubSkin::createDrawItem
virtual void createDrawItem(ITexture *_texture, ILayerNode *_node)
Definition: MyGUI_SubSkin.cpp:190
MyGUI::texture_utility::convertColour
__inline void convertColour(uint32 &_colour, VertexColourType _format)
Definition: MyGUI_TextureUtility.h:38
MyGUI::IStateInfo
Definition: MyGUI_IStateInfo.h:31
MyGUI::types::TSize< int >
MyGUI::SubSkin::mNode
ILayerNode * mNode
Definition: MyGUI_SubSkin.h:78
MyGUI::SubSkin::setStateData
virtual void setStateData(IStateInfo *_data)
Definition: MyGUI_SubSkin.cpp:282
MyGUI::Singleton< RenderManager >::getInstance
static RenderManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::Align::isVCenter
bool isVCenter() const
Definition: MyGUI_Align.h:64
MyGUI::SubSkin::mRenderItem
RenderItem * mRenderItem
Definition: MyGUI_SubSkin.h:79
MyGUI::RenderTargetInfo::topOffset
int topOffset
Definition: MyGUI_RenderTargetInfo.h:60
MyGUI::SubSkin::mRectTexture
FloatRect mRectTexture
Definition: MyGUI_SubSkin.h:69
MyGUI::ICroppedRectangle::mCroppedParent
ICroppedRectangle * mCroppedParent
Definition: MyGUI_ICroppedRectangle.h:264
MyGUI::RenderManager::getVertexFormat
virtual VertexColourType getVertexFormat()=0
MyGUI::ICroppedRectangle::getAbsoluteTop
int getAbsoluteTop() const
Definition: MyGUI_ICroppedRectangle.h:103
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:61
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:47
MyGUI::Align::isHCenter
bool isHCenter() const
Definition: MyGUI_Align.h:59
MyGUI::types::TCoord::width
T width
Definition: MyGUI_TCoord.h:39
MyGUI_LanguageManager.h
MyGUI::SubSkin::setAlpha
virtual void setAlpha(float _alpha)
Definition: MyGUI_SubSkin.cpp:58
MyGUI::ILayerNode::addToRenderItem
virtual RenderItem * addToRenderItem(ITexture *_texture, bool _firstQueue, bool _separate)=0
MyGUI::ICroppedRectangle::mCoord
IntCoord mCoord
Definition: MyGUI_ICroppedRectangle.h:260
MyGUI::types::TCoord::top
T top
Definition: MyGUI_TCoord.h:38
MyGUI::SubSkin::_setColour
virtual void _setColour(const Colour &_value)
Definition: MyGUI_SubSkin.cpp:272
MyGUI::SubSkin::_setUVSet
virtual void _setUVSet(const FloatRect &_rect)
Definition: MyGUI_SubSkin.cpp:208
MyGUI::types::TRect::left
T left
Definition: MyGUI_TRect.h:35
MyGUI_RenderManager.h
MyGUI::ICroppedRectangle::mMargin
IntRect mMargin
Definition: MyGUI_ICroppedRectangle.h:259
MyGUI::RenderItem::getCurrentVertexBuffer
Vertex * getCurrentVertexBuffer() const
Definition: MyGUI_RenderItem.cpp:240
MyGUI::VertexQuad::VertexCount
Definition: MyGUI_VertexData.h:58
MyGUI::SubSkin::mCurrentTexture
FloatRect mCurrentTexture
Definition: MyGUI_SubSkin.h:75
MyGUI::ICroppedRectangle::getWidth
int getWidth() const
Definition: MyGUI_ICroppedRectangle.h:129
MyGUI::types::TRect< float >
MyGUI::ICroppedRectangle::_getViewWidth
int _getViewWidth() const
Definition: MyGUI_ICroppedRectangle.h:164
MyGUI::types::TSize::width
T width
Definition: MyGUI_TSize.h:35
MyGUI::ISubWidget::mVisible
bool mVisible
Definition: MyGUI_ISubWidget.h:76
MyGUI::RenderTargetInfo::pixScaleX
float pixScaleX
Definition: MyGUI_RenderTargetInfo.h:53
MyGUI::SubSkin::mSeparate
bool mSeparate
Definition: MyGUI_SubSkin.h:81
MyGUI::SubSkin::_setAlign
virtual void _setAlign(const IntSize &_oldsize)
Definition: MyGUI_SubSkin.cpp:72
MyGUI_CommonStateInfo.h
MyGUI_RenderItem.h
MyGUI::Align::isRight
bool isRight() const
Definition: MyGUI_Align.h:79
MyGUI::ICroppedRectangle::_checkOutside
bool _checkOutside() const
Definition: MyGUI_ICroppedRectangle.h:250
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::ITexture
Definition: MyGUI_ITexture.h:41
MyGUI::IRenderTarget::getInfo
virtual const RenderTargetInfo & getInfo()=0
MyGUI::texture_utility::toColourARGB
uint32 toColourARGB(const Colour &_colour)
Definition: MyGUI_TextureUtility.cpp:83
MyGUI::RenderTargetInfo::hOffset
float hOffset
Definition: MyGUI_RenderTargetInfo.h:55
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
MyGUI::types::TRect::set
void set(T const &_left, T const &_top, T const &_right, T const &_bottom)
Definition: MyGUI_TRect.h:136
MyGUI::SubSkinStateInfo
Definition: MyGUI_CommonStateInfo.h:34
MyGUI::SubSkin::mVertexFormat
VertexColourType mVertexFormat
Definition: MyGUI_SubSkin.h:72
MyGUI_LayerNode.h
MyGUI::ISubWidget::mAlign
Align mAlign
Definition: MyGUI_ISubWidget.h:75
MyGUI::SubSkin::setVisible
virtual void setVisible(bool _visible)
Definition: MyGUI_SubSkin.cpp:50
MyGUI::SubSkin::doRender
virtual void doRender()
Definition: MyGUI_SubSkin.cpp:241
MyGUI::SubSkinStateInfo::getRect
const FloatRect & getRect() const
Definition: MyGUI_CommonStateInfo.h:42
MyGUI::RenderTargetInfo
Definition: MyGUI_RenderTargetInfo.h:30
MyGUI::SubSkin::destroyDrawItem
virtual void destroyDrawItem()
Definition: MyGUI_SubSkin.cpp:199
MyGUI::Colour
Definition: MyGUI_Colour.h:31
MyGUI::RenderTargetInfo::vOffset
float vOffset
Definition: MyGUI_RenderTargetInfo.h:56
MyGUI::types::TSize::height
T height
Definition: MyGUI_TSize.h:36
MyGUI::types::TCoord::left
T left
Definition: MyGUI_TCoord.h:37
MyGUI::types::TRect::right
T right
Definition: MyGUI_TRect.h:37
MyGUI::Align::isHStretch
bool isHStretch() const
Definition: MyGUI_Align.h:84
MyGUI::SubSkin::SubSkin
SubSkin()
Definition: MyGUI_SubSkin.cpp:35
MyGUI::uint8
unsigned char uint8
Definition: MyGUI_Types.h:61
MyGUI::types::TRect::bottom
T bottom
Definition: MyGUI_TRect.h:38
MyGUI::ICroppedRectangle::_checkMargin
bool _checkMargin()
Definition: MyGUI_ICroppedRectangle.h:200
MyGUI_SubSkin.h
MyGUI::RenderItem::setLastVertexCount
void setLastVertexCount(size_t _count)
Definition: MyGUI_RenderItem.cpp:245
MyGUI_SkinManager.h
MyGUI::SubSkin::mCurrentCoord
IntCoord mCurrentCoord
Definition: MyGUI_SubSkin.h:76
MyGUI::types::TCoord::height
T height
Definition: MyGUI_TCoord.h:40
MyGUI::SubSkin::mCurrentColour
uint32 mCurrentColour
Definition: MyGUI_SubSkin.h:73
MyGUI::SubSkin::_correctView
virtual void _correctView()
Definition: MyGUI_SubSkin.cpp:67
MyGUI::SubSkin::_updateView
virtual void _updateView()
Definition: MyGUI_SubSkin.cpp:126