MyGUI  3.4.1
MyGUI_TileRect.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_TileRect.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 
21 
23  mEmptyView(false),
24  mCurrentColour(0xFFFFFFFF),
25  mNode(nullptr),
26  mRenderItem(nullptr),
27  mCountVertex(TILERECT_COUNT_VERTEX),
28  mRealTileWidth(0),
29  mRealTileHeight(0),
30  mTextureHeightOne(0),
31  mTextureWidthOne(0),
32  mTileH(true),
33  mTileV(true)
34  {
36  }
37 
38  void TileRect::setVisible(bool _visible)
39  {
40  if (mVisible == _visible)
41  return;
42  mVisible = _visible;
43 
44  if (nullptr != mNode)
46  }
47 
48  void TileRect::setAlpha(float _alpha)
49  {
50  uint32 alpha = ((uint8)(_alpha * 255) << 24);
51  mCurrentColour = (mCurrentColour & 0x00FFFFFF) | (alpha & 0xFF000000);
52 
53  if (nullptr != mNode)
55  }
56 
58  {
59  if (nullptr != mNode)
61  }
62 
63  void TileRect::_setAlign(const IntSize& _oldsize)
64  {
65  // первоначальное выравнивание
66  if (mAlign.isHStretch())
67  {
68  // растягиваем
69  mCoord.width = mCoord.width + (mCroppedParent->getWidth() - _oldsize.width);
70  mIsMargin = true; // при изменении размеров все пересчитывать
71  }
72  else if (mAlign.isRight())
73  {
74  // двигаем по правому краю
75  mCoord.left = mCoord.left + (mCroppedParent->getWidth() - _oldsize.width);
76  }
77  else if (mAlign.isHCenter())
78  {
79  // выравнивание по горизонтали без растяжения
81  }
82 
83  if (mAlign.isVStretch())
84  {
85  // растягиваем
87  mIsMargin = true; // при изменении размеров все пересчитывать
88  }
89  else if (mAlign.isBottom())
90  {
91  // двигаем по нижнему краю
92  mCoord.top = mCoord.top + (mCroppedParent->getHeight() - _oldsize.height);
93  }
94  else if (mAlign.isVCenter())
95  {
96  // выравнивание по вертикали без растяжения
98  }
99 
103  _updateView();
104  }
105 
107  {
108  bool margin = _checkMargin();
109 
110  mEmptyView = ((0 >= _getViewWidth()) || (0 >= _getViewHeight()));
111 
116 
117  // подсчитываем необходимое колличество тайлов
118  if (!mEmptyView)
119  {
120  size_t count = 0;
121  if (!mTileSize.empty())
122  {
123  size_t count_x = mCoord.width / mTileSize.width;
124  if ((mCoord.width % mTileSize.width) > 0)
125  count_x ++;
126 
127  size_t count_y = mCoord.height / mTileSize.height;
128  if ((mCoord.height % mTileSize.height) > 0)
129  count_y ++;
130 
131  count = count_y * count_x * VertexQuad::VertexCount;
132  }
133 
134  // нужно больше вершин
135  if (count > mCountVertex)
136  {
138  if (nullptr != mRenderItem)
140  }
141  }
142 
143  // вьюпорт стал битым
144  if (margin)
145  {
146  // проверка на полный выход за границу
147  if (_checkOutside())
148  {
149  // запоминаем текущее состояние
150  mIsMargin = margin;
151 
152  // обновить перед выходом
153  if (nullptr != mNode)
155  return;
156  }
157  }
158 
159  // запоминаем текущее состояние
160  mIsMargin = margin;
161 
162  if (nullptr != mNode)
164  }
165 
166  void TileRect::_setUVSet(const FloatRect& _rect)
167  {
168  mCurrentTexture = _rect;
169  if (nullptr != mNode)
171  }
172 
174  {
175  if (!mVisible || mEmptyView || mTileSize.empty())
176  return;
177 
178  VertexQuad* quad = reinterpret_cast<VertexQuad*>(mRenderItem->getCurrentVertexBuffer());
179 
181 
182  // размер одного тайла
183  mRealTileWidth = info.pixScaleX * (float)(mTileSize.width) * 2;
184  mRealTileHeight = info.pixScaleY * (float)(mTileSize.height) * 2;
185 
188 
189  float vertex_z = mNode->getNodeDepth();
190 
191  // абсолютный размер окна
192  float window_left = ((info.pixScaleX * (float)(mCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) + info.hOffset) * 2) - 1;
193  float window_top = -(((info.pixScaleY * (float)(mCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) + info.vOffset) * 2) - 1);
194 
195  // размер вьюпорта
196  float real_left = ((info.pixScaleX * (float)(mCurrentCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) + info.hOffset) * 2) - 1;
197  float real_right = real_left + (info.pixScaleX * (float)mCurrentCoord.width * 2);
198  float real_top = -(((info.pixScaleY * (float)(mCurrentCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) + info.vOffset) * 2) - 1);
199  float real_bottom = real_top - (info.pixScaleY * (float)mCurrentCoord.height * 2);
200 
201  size_t count = 0;
202 
203  float left = window_left;
204  float right = window_left;
205  float top = window_top;
206  float bottom = window_top;
207 
208  for (int y = 0; y < mCoord.height; y += mTileSize.height)
209  {
210  top = bottom;
211  bottom -= mRealTileHeight;
212  right = window_left;
213 
214  float vertex_top = top;
215  float vertex_bottom = bottom;
216  bool texture_crop_height = false;
217 
218  if (vertex_top > real_top)
219  {
220  // проверка на полный выход
221  if (vertex_bottom > real_top)
222  {
223  continue;
224  }
225  // обрезаем
226  vertex_top = real_top;
227  texture_crop_height = true;
228  }
229  if (vertex_bottom < real_bottom)
230  {
231  // вообще вниз ушли
232  if (vertex_top < real_bottom)
233  {
234  continue;
235  }
236  // обрезаем
237  vertex_bottom = real_bottom;
238  texture_crop_height = true;
239  }
240 
241  for (int x = 0; x < mCoord.width; x += mTileSize.width)
242  {
243  left = right;
244  right += mRealTileWidth;
245 
246  float vertex_left = left;
247  float vertex_right = right;
248  bool texture_crop_width = false;
249 
250 
251  if (vertex_left < real_left)
252  {
253  // проверка на полный выход
254  if (vertex_right < real_left)
255  {
256  continue;
257  }
258  // обрезаем
259  vertex_left = real_left;
260  texture_crop_width = true;
261  }
262 
263  if (vertex_right > real_right)
264  {
265  // вообще строку до конца не нуна
266  if (vertex_left > real_right)
267  {
268  continue;
269  }
270  // обрезаем
271  vertex_right = real_right;
272  texture_crop_width = true;
273  }
274 
275  // текущие текстурные координаты
276  float texture_left = mCurrentTexture.left;
277  float texture_right = mCurrentTexture.right;
278  float texture_top = mCurrentTexture.top;
279  float texture_bottom = mCurrentTexture.bottom;
280 
281  // смещение текстуры по вертикили
282  if (texture_crop_height)
283  {
284  // прибавляем размер смещения в текстурных координатах
285  texture_top += (top - vertex_top) * mTextureHeightOne;
286  // отнимаем размер смещения в текстурных координатах
287  texture_bottom -= (vertex_bottom - bottom) * mTextureHeightOne;
288  }
289 
290  // смещение текстуры по горизонтали
291  if (texture_crop_width)
292  {
293  // прибавляем размер смещения в текстурных координатах
294  texture_left += (vertex_left - left) * mTextureWidthOne;
295  // отнимаем размер смещения в текстурных координатах
296  texture_right -= (right - vertex_right) * mTextureWidthOne;
297  }
298 
299  quad[count].set(
300  vertex_left,
301  vertex_top,
302  vertex_right,
303  vertex_bottom,
304  vertex_z,
305  texture_left,
306  texture_top,
307  texture_right,
308  texture_bottom,
310 
311  count ++;
312  }
313  }
314 
316  }
317 
319  {
320  MYGUI_ASSERT(!mRenderItem, "mRenderItem must be nullptr");
321 
322  mNode = _node;
323  mRenderItem = mNode->addToRenderItem(_texture, true, false);
325  }
326 
328  {
329  MYGUI_ASSERT(mRenderItem, "mRenderItem must be not nullptr");
330 
331  mNode = nullptr;
333  mRenderItem = nullptr;
334  }
335 
337  {
338  TileRectStateInfo* data = _data->castType<TileRectStateInfo>();
339 
340  mTileSize = data->getTileSize();
341  mTileH = data->getTileH();
342  mTileV = data->getTileV();
343  _setUVSet(data->getRect());
344  }
345 
346  void TileRect::_setColour(const Colour& _value)
347  {
348  uint32 colour = texture_utility::toColourARGB(_value);
350  mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
351 
352  if (nullptr != mNode)
354  }
355 
356 } // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
ICroppedRectangle * mCroppedParent
virtual RenderItem * addToRenderItem(ITexture *_texture, bool _firstQueue, bool _separate)=0
virtual float getNodeDepth() const =0
virtual void outOfDate(RenderItem *_item)=0
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
virtual const RenderTargetInfo & getInfo() const =0
void addDrawItem(ISubWidget *_item, size_t _count)
IRenderTarget * getRenderTarget()
void reallockDrawItem(ISubWidget *_item, size_t _count)
void removeDrawItem(ISubWidget *_item)
Vertex * getCurrentVertexBuffer() const
void setLastVertexCount(size_t _count)
virtual VertexColourType getVertexFormat() const =0
static RenderManager & getInstance()
void _setAlign(const IntSize &_oldsize) override
RenderItem * mRenderItem
FloatRect mCurrentTexture
void _setUVSet(const FloatRect &_rect) override
IntCoord mCurrentCoord
void setVisible(bool _visible) override
void createDrawItem(ITexture *_texture, ILayerNode *_node) override
void _setColour(const Colour &_value) override
void setStateData(IStateInfo *_data) override
void _correctView() override
ILayerNode * mNode
void setAlpha(float _alpha) override
void doRender() override
VertexColourType mVertexFormat
void destroyDrawItem() override
void _updateView() override
const FloatRect & getRect() const
const IntSize & getTileSize() const
void convertColour(uint32 &_colour, VertexColourType _format)
uint32 toColourARGB(const Colour &_colour)
const size_t TILERECT_COUNT_VERTEX
uint8_t uint8
Definition: MyGUI_Types.h:45
uint32_t uint32
Definition: MyGUI_Types.h:47
bool isHStretch() const
Definition: MyGUI_Align.h:69
bool isVCenter() const
Definition: MyGUI_Align.h:49
bool isVStretch() const
Definition: MyGUI_Align.h:84
bool isRight() const
Definition: MyGUI_Align.h:64
bool isHCenter() const
Definition: MyGUI_Align.h:44
bool isBottom() const
Definition: MyGUI_Align.h:79
void set(float _l, float _t, float _r, float _b, float _z, float _u1, float _v1, float _u2, float _v2, uint32 _colour)
bool empty() const
Definition: MyGUI_TSize.h:108