~ubuntu-branches/ubuntu/vivid/mygui/vivid

« back to all changes in this revision

Viewing changes to MyGUIEngine/src/MyGUI_TileRect.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard, Bret Curtis, Scott Howard
  • Date: 2014-09-18 17:57:48 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140918175748-dd8va78mvpw1jbes
Tags: 3.2.1-1
[ Bret Curtis ]
* Updated license for majority of files from LGPL to Expat (MIT)

[ Scott Howard ]
* New upstream release
* Updated patch to add build option for system GLEW libraries
* All patches accepted upstream except shared_libraries.patch
* Bumped SONAME due to dropped symbols, updated *.symbols and package
  names
* Updated license of debian/* to Expat with permission of all authors
* Don't install Doxygen autogenerated md5 and map files (thanks
  lintian)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*!
2
 
        @file
3
 
        @author         Albert Semenov
4
 
        @date           05/2008
5
 
*/
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_TileRect.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
 
        const size_t TILERECT_COUNT_VERTEX = 16 * VertexQuad::VertexCount;
36
 
 
37
 
        TileRect::TileRect() :
38
 
                mEmptyView(false),
39
 
                mCurrentColour(0xFFFFFFFF),
40
 
                mNode(nullptr),
41
 
                mRenderItem(nullptr),
42
 
                mCountVertex(TILERECT_COUNT_VERTEX),
43
 
                mRealTileWidth(0),
44
 
                mRealTileHeight(0),
45
 
                mTextureHeightOne(0),
46
 
                mTextureWidthOne(0),
47
 
                mTileH(true),
48
 
                mTileV(true)
49
 
        {
50
 
                mVertexFormat = RenderManager::getInstance().getVertexFormat();
51
 
        }
52
 
 
53
 
        TileRect::~TileRect()
54
 
        {
55
 
        }
56
 
 
57
 
        void TileRect::setVisible(bool _visible)
58
 
        {
59
 
                if (mVisible == _visible) return;
60
 
                mVisible = _visible;
61
 
 
62
 
                if (nullptr != mNode) mNode->outOfDate(mRenderItem);
63
 
        }
64
 
 
65
 
        void TileRect::setAlpha(float _alpha)
66
 
        {
67
 
                uint32 alpha = ((uint8)(_alpha * 255) << 24);
68
 
                mCurrentColour = (mCurrentColour & 0x00FFFFFF) | (alpha & 0xFF000000);
69
 
 
70
 
                if (nullptr != mNode)
71
 
                        mNode->outOfDate(mRenderItem);
72
 
        }
73
 
 
74
 
        void TileRect::_correctView()
75
 
        {
76
 
                if (nullptr != mNode) mNode->outOfDate(mRenderItem);
77
 
        }
78
 
 
79
 
        void TileRect::_setAlign(const IntSize& _oldsize)
80
 
        {
81
 
                // необходимо разобраться
82
 
                bool need_update = true;
83
 
 
84
 
                // первоначальное выравнивание
85
 
                if (mAlign.isHStretch())
86
 
                {
87
 
                        // растягиваем
88
 
                        mCoord.width = mCoord.width + (mCroppedParent->getWidth() - _oldsize.width);
89
 
                        need_update = true;
90
 
                        mIsMargin = true; // при изменении размеров все пересчитывать
91
 
                }
92
 
                else if (mAlign.isRight())
93
 
                {
94
 
                        // двигаем по правому краю
95
 
                        mCoord.left = mCoord.left + (mCroppedParent->getWidth() - _oldsize.width);
96
 
                        need_update = true;
97
 
                }
98
 
                else if (mAlign.isHCenter())
99
 
                {
100
 
                        // выравнивание по горизонтали без растяжения
101
 
                        mCoord.left = (mCroppedParent->getWidth() - mCoord.width) / 2;
102
 
                        need_update = true;
103
 
                }
104
 
 
105
 
                if (mAlign.isVStretch())
106
 
                {
107
 
                        // растягиваем
108
 
                        mCoord.height = mCoord.height + (mCroppedParent->getHeight() - _oldsize.height);
109
 
                        need_update = true;
110
 
                        mIsMargin = true; // при изменении размеров все пересчитывать
111
 
                }
112
 
                else if (mAlign.isBottom())
113
 
                {
114
 
                        // двигаем по нижнему краю
115
 
                        mCoord.top = mCoord.top + (mCroppedParent->getHeight() - _oldsize.height);
116
 
                        need_update = true;
117
 
                }
118
 
                else if (mAlign.isVCenter())
119
 
                {
120
 
                        // выравнивание по вертикали без растяжения
121
 
                        mCoord.top = (mCroppedParent->getHeight() - mCoord.height) / 2;
122
 
                        need_update = true;
123
 
                }
124
 
 
125
 
                if (need_update)
126
 
                {
127
 
                        mCurrentCoord = mCoord;
128
 
                        if (!mTileH) mTileSize.width = mCoord.width;
129
 
                        if (!mTileV) mTileSize.height = mCoord.height;
130
 
                        _updateView();
131
 
                }
132
 
 
133
 
        }
134
 
 
135
 
        void TileRect::_updateView()
136
 
        {
137
 
                bool margin = _checkMargin();
138
 
 
139
 
                mEmptyView = ((0 >= _getViewWidth()) || (0 >= _getViewHeight()));
140
 
 
141
 
                mCurrentCoord.left = mCoord.left + mMargin.left;
142
 
                mCurrentCoord.top = mCoord.top + mMargin.top;
143
 
                mCurrentCoord.width = _getViewWidth();
144
 
                mCurrentCoord.height = _getViewHeight();
145
 
 
146
 
                // подсчитываем необходимое колличество тайлов
147
 
                if (!mEmptyView)
148
 
                {
149
 
                        size_t count = 0;
150
 
                        if (!mTileSize.empty())
151
 
                        {
152
 
                                size_t count_x = mCoord.width / mTileSize.width;
153
 
                                if ((mCoord.width % mTileSize.width) > 0) count_x ++;
154
 
                                size_t count_y = mCoord.height / mTileSize.height;
155
 
                                if ((mCoord.height % mTileSize.height) > 0) count_y ++;
156
 
                                count = count_y * count_x * VertexQuad::VertexCount;
157
 
                        }
158
 
 
159
 
                        // нужно больше вершин
160
 
                        if (count > mCountVertex)
161
 
                        {
162
 
                                mCountVertex = count + TILERECT_COUNT_VERTEX;
163
 
                                if (nullptr != mRenderItem) mRenderItem->reallockDrawItem(this, mCountVertex);
164
 
                        }
165
 
                }
166
 
 
167
 
                // вьюпорт стал битым
168
 
                if (margin)
169
 
                {
170
 
                        // проверка на полный выход за границу
171
 
                        if (_checkOutside())
172
 
                        {
173
 
                                // запоминаем текущее состояние
174
 
                                mIsMargin = margin;
175
 
 
176
 
                                // обновить перед выходом
177
 
                                if (nullptr != mNode) mNode->outOfDate(mRenderItem);
178
 
                                return;
179
 
                        }
180
 
                }
181
 
 
182
 
                // запоминаем текущее состояние
183
 
                mIsMargin = margin;
184
 
 
185
 
                if (nullptr != mNode) mNode->outOfDate(mRenderItem);
186
 
        }
187
 
 
188
 
        void TileRect::_setUVSet(const FloatRect& _rect)
189
 
        {
190
 
                mCurrentTexture = _rect;
191
 
                if (nullptr != mNode) mNode->outOfDate(mRenderItem);
192
 
        }
193
 
 
194
 
        void TileRect::doRender()
195
 
        {
196
 
                if (!mVisible || mEmptyView || mTileSize.empty()) return;
197
 
 
198
 
                VertexQuad* quad = (VertexQuad*)mRenderItem->getCurrentVertexBuffer();
199
 
 
200
 
                const RenderTargetInfo& info = mRenderItem->getRenderTarget()->getInfo();
201
 
 
202
 
                // размер одного тайла
203
 
                mRealTileWidth = info.pixScaleX * (float)(mTileSize.width) * 2;
204
 
                mRealTileHeight = info.pixScaleY * (float)(mTileSize.height) * 2;
205
 
 
206
 
                mTextureHeightOne = (mCurrentTexture.bottom - mCurrentTexture.top) / mRealTileHeight;
207
 
                mTextureWidthOne = (mCurrentTexture.right - mCurrentTexture.left) / mRealTileWidth;
208
 
 
209
 
                float vertex_z = info.maximumDepth;
210
 
 
211
 
                // абсолютный размер окна
212
 
                float window_left = ((info.pixScaleX * (float)(mCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) + info.hOffset) * 2) - 1;
213
 
                float window_top = -(((info.pixScaleY * (float)(mCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) + info.vOffset) * 2) - 1);
214
 
 
215
 
                // размер вьюпорта
216
 
                float real_left = ((info.pixScaleX * (float)(mCurrentCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) + info.hOffset) * 2) - 1;
217
 
                float real_right = real_left + (info.pixScaleX * (float)mCurrentCoord.width * 2);
218
 
                float real_top = -(((info.pixScaleY * (float)(mCurrentCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) + info.vOffset) * 2) - 1);
219
 
                float real_bottom = real_top - (info.pixScaleY * (float)mCurrentCoord.height * 2);
220
 
 
221
 
                size_t count = 0;
222
 
 
223
 
                float left = window_left;
224
 
                float right = window_left;
225
 
                float top = window_top;
226
 
                float bottom = window_top;
227
 
 
228
 
                for (int y = 0; y < mCoord.height; y += mTileSize.height)
229
 
                {
230
 
                        top = bottom;
231
 
                        bottom -= mRealTileHeight;
232
 
                        right = window_left;
233
 
 
234
 
                        float vertex_top = top;
235
 
                        float vertex_bottom = bottom;
236
 
                        bool texture_crop_height  = false;
237
 
 
238
 
                        if (vertex_top > real_top)
239
 
                        {
240
 
                                // проверка на полный выход
241
 
                                if (vertex_bottom > real_top)
242
 
                                {
243
 
                                        continue;
244
 
                                }
245
 
                                // обрезаем
246
 
                                vertex_top = real_top;
247
 
                                texture_crop_height = true;
248
 
                        }
249
 
                        if (vertex_bottom < real_bottom)
250
 
                        {
251
 
                                // вообще вниз ушли
252
 
                                if (vertex_top < real_bottom)
253
 
                                {
254
 
                                        continue;
255
 
                                }
256
 
                                // обрезаем
257
 
                                vertex_bottom = real_bottom;
258
 
                                texture_crop_height = true;
259
 
                        }
260
 
 
261
 
                        for (int x = 0; x < mCoord.width; x += mTileSize.width)
262
 
                        {
263
 
                                left = right;
264
 
                                right += mRealTileWidth;
265
 
 
266
 
                                float vertex_left = left;
267
 
                                float vertex_right = right;
268
 
                                bool texture_crop_width  = false;
269
 
 
270
 
 
271
 
                                if (vertex_left < real_left)
272
 
                                {
273
 
                                        // проверка на полный выход
274
 
                                        if (vertex_right < real_left)
275
 
                                        {
276
 
                                                continue;
277
 
                                        }
278
 
                                        // обрезаем
279
 
                                        vertex_left = real_left;
280
 
                                        texture_crop_width = true;
281
 
                                }
282
 
 
283
 
                                if (vertex_right > real_right)
284
 
                                {
285
 
                                        // вообще строку до конца не нуна
286
 
                                        if (vertex_left > real_right)
287
 
                                        {
288
 
                                                continue;
289
 
                                        }
290
 
                                        // обрезаем
291
 
                                        vertex_right = real_right;
292
 
                                        texture_crop_width = true;
293
 
                                }
294
 
 
295
 
                                // текущие текстурные координаты
296
 
                                float texture_left = mCurrentTexture.left;
297
 
                                float texture_right = mCurrentTexture.right;
298
 
                                float texture_top = mCurrentTexture.top;
299
 
                                float texture_bottom = mCurrentTexture.bottom;
300
 
 
301
 
                                // смещение текстуры по вертикили
302
 
                                if (texture_crop_height)
303
 
                                {
304
 
                                        // прибавляем размер смещения в текстурных координатах
305
 
                                        texture_top += (top - vertex_top) * mTextureHeightOne;
306
 
                                        // отнимаем размер смещения в текстурных координатах
307
 
                                        texture_bottom -= (vertex_bottom - bottom) * mTextureHeightOne;
308
 
                                }
309
 
 
310
 
                                // смещение текстуры по горизонтали
311
 
                                if (texture_crop_width)
312
 
                                {
313
 
                                        // прибавляем размер смещения в текстурных координатах
314
 
                                        texture_left += (vertex_left - left) * mTextureWidthOne;
315
 
                                        // отнимаем размер смещения в текстурных координатах
316
 
                                        texture_right -= (right - vertex_right) * mTextureWidthOne;
317
 
                                }
318
 
 
319
 
                                quad[count].set(
320
 
                                        vertex_left,
321
 
                                        vertex_top,
322
 
                                        vertex_right,
323
 
                                        vertex_bottom,
324
 
                                        vertex_z,
325
 
                                        texture_left,
326
 
                                        texture_top,
327
 
                                        texture_right,
328
 
                                        texture_bottom,
329
 
                                        mCurrentColour
330
 
                                );
331
 
 
332
 
                                count ++;
333
 
                        }
334
 
                }
335
 
 
336
 
                mRenderItem->setLastVertexCount(VertexQuad::VertexCount * count);
337
 
        }
338
 
 
339
 
        void TileRect::createDrawItem(ITexture* _texture, ILayerNode* _node)
340
 
        {
341
 
                MYGUI_ASSERT(!mRenderItem, "mRenderItem must be nullptr");
342
 
 
343
 
                mNode = _node;
344
 
                mRenderItem = mNode->addToRenderItem(_texture, true, false);
345
 
                mRenderItem->addDrawItem(this, mCountVertex);
346
 
        }
347
 
 
348
 
        void TileRect::destroyDrawItem()
349
 
        {
350
 
                MYGUI_ASSERT(mRenderItem, "mRenderItem must be not nullptr");
351
 
 
352
 
                mNode = nullptr;
353
 
                mRenderItem->removeDrawItem(this);
354
 
                mRenderItem = nullptr;
355
 
        }
356
 
 
357
 
        void TileRect::setStateData(IStateInfo* _data)
358
 
        {
359
 
                TileRectStateInfo* data = _data->castType<TileRectStateInfo>();
360
 
 
361
 
                mTileSize = data->getTileSize();
362
 
                mTileH = data->getTileH();
363
 
                mTileV = data->getTileV();
364
 
                _setUVSet(data->getRect());
365
 
        }
366
 
 
367
 
        void TileRect::_setColour(const Colour& _value)
368
 
        {
369
 
                uint32 colour = texture_utility::toColourARGB(_value);
370
 
                texture_utility::convertColour(colour, mVertexFormat);
371
 
                mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
372
 
 
373
 
                if (nullptr != mNode)
374
 
                        mNode->outOfDate(mRenderItem);
375
 
        }
376
 
 
377
 
} // namespace MyGUI
 
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
 
 
20
        const size_t TILERECT_COUNT_VERTEX = 16 * VertexQuad::VertexCount;
 
21
 
 
22
        TileRect::TileRect() :
 
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
        {
 
35
                mVertexFormat = RenderManager::getInstance().getVertexFormat();
 
36
        }
 
37
 
 
38
        TileRect::~TileRect()
 
39
        {
 
40
        }
 
41
 
 
42
        void TileRect::setVisible(bool _visible)
 
43
        {
 
44
                if (mVisible == _visible)
 
45
                        return;
 
46
                mVisible = _visible;
 
47
 
 
48
                if (nullptr != mNode)
 
49
                        mNode->outOfDate(mRenderItem);
 
50
        }
 
51
 
 
52
        void TileRect::setAlpha(float _alpha)
 
53
        {
 
54
                uint32 alpha = ((uint8)(_alpha * 255) << 24);
 
55
                mCurrentColour = (mCurrentColour & 0x00FFFFFF) | (alpha & 0xFF000000);
 
56
 
 
57
                if (nullptr != mNode)
 
58
                        mNode->outOfDate(mRenderItem);
 
59
        }
 
60
 
 
61
        void TileRect::_correctView()
 
62
        {
 
63
                if (nullptr != mNode)
 
64
                        mNode->outOfDate(mRenderItem);
 
65
        }
 
66
 
 
67
        void TileRect::_setAlign(const IntSize& _oldsize)
 
68
        {
 
69
                // необходимо разобраться
 
70
                bool need_update = true;
 
71
 
 
72
                // первоначальное выравнивание
 
73
                if (mAlign.isHStretch())
 
74
                {
 
75
                        // растягиваем
 
76
                        mCoord.width = mCoord.width + (mCroppedParent->getWidth() - _oldsize.width);
 
77
                        need_update = true;
 
78
                        mIsMargin = true; // при изменении размеров все пересчитывать
 
79
                }
 
80
                else if (mAlign.isRight())
 
81
                {
 
82
                        // двигаем по правому краю
 
83
                        mCoord.left = mCoord.left + (mCroppedParent->getWidth() - _oldsize.width);
 
84
                        need_update = true;
 
85
                }
 
86
                else if (mAlign.isHCenter())
 
87
                {
 
88
                        // выравнивание по горизонтали без растяжения
 
89
                        mCoord.left = (mCroppedParent->getWidth() - mCoord.width) / 2;
 
90
                        need_update = true;
 
91
                }
 
92
 
 
93
                if (mAlign.isVStretch())
 
94
                {
 
95
                        // растягиваем
 
96
                        mCoord.height = mCoord.height + (mCroppedParent->getHeight() - _oldsize.height);
 
97
                        need_update = true;
 
98
                        mIsMargin = true; // при изменении размеров все пересчитывать
 
99
                }
 
100
                else if (mAlign.isBottom())
 
101
                {
 
102
                        // двигаем по нижнему краю
 
103
                        mCoord.top = mCoord.top + (mCroppedParent->getHeight() - _oldsize.height);
 
104
                        need_update = true;
 
105
                }
 
106
                else if (mAlign.isVCenter())
 
107
                {
 
108
                        // выравнивание по вертикали без растяжения
 
109
                        mCoord.top = (mCroppedParent->getHeight() - mCoord.height) / 2;
 
110
                        need_update = true;
 
111
                }
 
112
 
 
113
                if (need_update)
 
114
                {
 
115
                        mCurrentCoord = mCoord;
 
116
                        if (!mTileH) mTileSize.width = mCoord.width;
 
117
                        if (!mTileV) mTileSize.height = mCoord.height;
 
118
                        _updateView();
 
119
                }
 
120
        }
 
121
 
 
122
        void TileRect::_updateView()
 
123
        {
 
124
                bool margin = _checkMargin();
 
125
 
 
126
                mEmptyView = ((0 >= _getViewWidth()) || (0 >= _getViewHeight()));
 
127
 
 
128
                mCurrentCoord.left = mCoord.left + mMargin.left;
 
129
                mCurrentCoord.top = mCoord.top + mMargin.top;
 
130
                mCurrentCoord.width = _getViewWidth();
 
131
                mCurrentCoord.height = _getViewHeight();
 
132
 
 
133
                // подсчитываем необходимое колличество тайлов
 
134
                if (!mEmptyView)
 
135
                {
 
136
                        size_t count = 0;
 
137
                        if (!mTileSize.empty())
 
138
                        {
 
139
                                size_t count_x = mCoord.width / mTileSize.width;
 
140
                                if ((mCoord.width % mTileSize.width) > 0)
 
141
                                        count_x ++;
 
142
 
 
143
                                size_t count_y = mCoord.height / mTileSize.height;
 
144
                                if ((mCoord.height % mTileSize.height) > 0)
 
145
                                        count_y ++;
 
146
 
 
147
                                count = count_y * count_x * VertexQuad::VertexCount;
 
148
                        }
 
149
 
 
150
                        // нужно больше вершин
 
151
                        if (count > mCountVertex)
 
152
                        {
 
153
                                mCountVertex = count + TILERECT_COUNT_VERTEX;
 
154
                                if (nullptr != mRenderItem)
 
155
                                        mRenderItem->reallockDrawItem(this, mCountVertex);
 
156
                        }
 
157
                }
 
158
 
 
159
                // вьюпорт стал битым
 
160
                if (margin)
 
161
                {
 
162
                        // проверка на полный выход за границу
 
163
                        if (_checkOutside())
 
164
                        {
 
165
                                // запоминаем текущее состояние
 
166
                                mIsMargin = margin;
 
167
 
 
168
                                // обновить перед выходом
 
169
                                if (nullptr != mNode)
 
170
                                        mNode->outOfDate(mRenderItem);
 
171
                                return;
 
172
                        }
 
173
                }
 
174
 
 
175
                // запоминаем текущее состояние
 
176
                mIsMargin = margin;
 
177
 
 
178
                if (nullptr != mNode)
 
179
                        mNode->outOfDate(mRenderItem);
 
180
        }
 
181
 
 
182
        void TileRect::_setUVSet(const FloatRect& _rect)
 
183
        {
 
184
                mCurrentTexture = _rect;
 
185
                if (nullptr != mNode)
 
186
                        mNode->outOfDate(mRenderItem);
 
187
        }
 
188
 
 
189
        void TileRect::doRender()
 
190
        {
 
191
                if (!mVisible || mEmptyView || mTileSize.empty())
 
192
                        return;
 
193
 
 
194
                VertexQuad* quad = reinterpret_cast<VertexQuad*>(mRenderItem->getCurrentVertexBuffer());
 
195
 
 
196
                const RenderTargetInfo& info = mRenderItem->getRenderTarget()->getInfo();
 
197
 
 
198
                // размер одного тайла
 
199
                mRealTileWidth = info.pixScaleX * (float)(mTileSize.width) * 2;
 
200
                mRealTileHeight = info.pixScaleY * (float)(mTileSize.height) * 2;
 
201
 
 
202
                mTextureHeightOne = (mCurrentTexture.bottom - mCurrentTexture.top) / mRealTileHeight;
 
203
                mTextureWidthOne = (mCurrentTexture.right - mCurrentTexture.left) / mRealTileWidth;
 
204
 
 
205
                float vertex_z = mNode->getNodeDepth();
 
206
 
 
207
                // абсолютный размер окна
 
208
                float window_left = ((info.pixScaleX * (float)(mCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) + info.hOffset) * 2) - 1;
 
209
                float window_top = -(((info.pixScaleY * (float)(mCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) + info.vOffset) * 2) - 1);
 
210
 
 
211
                // размер вьюпорта
 
212
                float real_left = ((info.pixScaleX * (float)(mCurrentCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) + info.hOffset) * 2) - 1;
 
213
                float real_right = real_left + (info.pixScaleX * (float)mCurrentCoord.width * 2);
 
214
                float real_top = -(((info.pixScaleY * (float)(mCurrentCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) + info.vOffset) * 2) - 1);
 
215
                float real_bottom = real_top - (info.pixScaleY * (float)mCurrentCoord.height * 2);
 
216
 
 
217
                size_t count = 0;
 
218
 
 
219
                float left = window_left;
 
220
                float right = window_left;
 
221
                float top = window_top;
 
222
                float bottom = window_top;
 
223
 
 
224
                for (int y = 0; y < mCoord.height; y += mTileSize.height)
 
225
                {
 
226
                        top = bottom;
 
227
                        bottom -= mRealTileHeight;
 
228
                        right = window_left;
 
229
 
 
230
                        float vertex_top = top;
 
231
                        float vertex_bottom = bottom;
 
232
                        bool texture_crop_height  = false;
 
233
 
 
234
                        if (vertex_top > real_top)
 
235
                        {
 
236
                                // проверка на полный выход
 
237
                                if (vertex_bottom > real_top)
 
238
                                {
 
239
                                        continue;
 
240
                                }
 
241
                                // обрезаем
 
242
                                vertex_top = real_top;
 
243
                                texture_crop_height = true;
 
244
                        }
 
245
                        if (vertex_bottom < real_bottom)
 
246
                        {
 
247
                                // вообще вниз ушли
 
248
                                if (vertex_top < real_bottom)
 
249
                                {
 
250
                                        continue;
 
251
                                }
 
252
                                // обрезаем
 
253
                                vertex_bottom = real_bottom;
 
254
                                texture_crop_height = true;
 
255
                        }
 
256
 
 
257
                        for (int x = 0; x < mCoord.width; x += mTileSize.width)
 
258
                        {
 
259
                                left = right;
 
260
                                right += mRealTileWidth;
 
261
 
 
262
                                float vertex_left = left;
 
263
                                float vertex_right = right;
 
264
                                bool texture_crop_width = false;
 
265
 
 
266
 
 
267
                                if (vertex_left < real_left)
 
268
                                {
 
269
                                        // проверка на полный выход
 
270
                                        if (vertex_right < real_left)
 
271
                                        {
 
272
                                                continue;
 
273
                                        }
 
274
                                        // обрезаем
 
275
                                        vertex_left = real_left;
 
276
                                        texture_crop_width = true;
 
277
                                }
 
278
 
 
279
                                if (vertex_right > real_right)
 
280
                                {
 
281
                                        // вообще строку до конца не нуна
 
282
                                        if (vertex_left > real_right)
 
283
                                        {
 
284
                                                continue;
 
285
                                        }
 
286
                                        // обрезаем
 
287
                                        vertex_right = real_right;
 
288
                                        texture_crop_width = true;
 
289
                                }
 
290
 
 
291
                                // текущие текстурные координаты
 
292
                                float texture_left = mCurrentTexture.left;
 
293
                                float texture_right = mCurrentTexture.right;
 
294
                                float texture_top = mCurrentTexture.top;
 
295
                                float texture_bottom = mCurrentTexture.bottom;
 
296
 
 
297
                                // смещение текстуры по вертикили
 
298
                                if (texture_crop_height)
 
299
                                {
 
300
                                        // прибавляем размер смещения в текстурных координатах
 
301
                                        texture_top += (top - vertex_top) * mTextureHeightOne;
 
302
                                        // отнимаем размер смещения в текстурных координатах
 
303
                                        texture_bottom -= (vertex_bottom - bottom) * mTextureHeightOne;
 
304
                                }
 
305
 
 
306
                                // смещение текстуры по горизонтали
 
307
                                if (texture_crop_width)
 
308
                                {
 
309
                                        // прибавляем размер смещения в текстурных координатах
 
310
                                        texture_left += (vertex_left - left) * mTextureWidthOne;
 
311
                                        // отнимаем размер смещения в текстурных координатах
 
312
                                        texture_right -= (right - vertex_right) * mTextureWidthOne;
 
313
                                }
 
314
 
 
315
                                quad[count].set(
 
316
                                        vertex_left,
 
317
                                        vertex_top,
 
318
                                        vertex_right,
 
319
                                        vertex_bottom,
 
320
                                        vertex_z,
 
321
                                        texture_left,
 
322
                                        texture_top,
 
323
                                        texture_right,
 
324
                                        texture_bottom,
 
325
                                        mCurrentColour);
 
326
 
 
327
                                count ++;
 
328
                        }
 
329
                }
 
330
 
 
331
                mRenderItem->setLastVertexCount(VertexQuad::VertexCount * count);
 
332
        }
 
333
 
 
334
        void TileRect::createDrawItem(ITexture* _texture, ILayerNode* _node)
 
335
        {
 
336
                MYGUI_ASSERT(!mRenderItem, "mRenderItem must be nullptr");
 
337
 
 
338
                mNode = _node;
 
339
                mRenderItem = mNode->addToRenderItem(_texture, true, false);
 
340
                mRenderItem->addDrawItem(this, mCountVertex);
 
341
        }
 
342
 
 
343
        void TileRect::destroyDrawItem()
 
344
        {
 
345
                MYGUI_ASSERT(mRenderItem, "mRenderItem must be not nullptr");
 
346
 
 
347
                mNode = nullptr;
 
348
                mRenderItem->removeDrawItem(this);
 
349
                mRenderItem = nullptr;
 
350
        }
 
351
 
 
352
        void TileRect::setStateData(IStateInfo* _data)
 
353
        {
 
354
                TileRectStateInfo* data = _data->castType<TileRectStateInfo>();
 
355
 
 
356
                mTileSize = data->getTileSize();
 
357
                mTileH = data->getTileH();
 
358
                mTileV = data->getTileV();
 
359
                _setUVSet(data->getRect());
 
360
        }
 
361
 
 
362
        void TileRect::_setColour(const Colour& _value)
 
363
        {
 
364
                uint32 colour = texture_utility::toColourARGB(_value);
 
365
                texture_utility::convertColour(colour, mVertexFormat);
 
366
                mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
 
367
 
 
368
                if (nullptr != mNode)
 
369
                        mNode->outOfDate(mRenderItem);
 
370
        }
 
371
 
 
372
} // namespace MyGUI