MyGUI  3.2.0
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 
37  mEmptyView(false),
38  mCurrentColour(0xFFFFFFFF),
39  mNode(nullptr),
40  mRenderItem(nullptr),
41  mSeparate(false)
42  {
44  }
45 
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)
65  }
66 
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  // выравнивание по горизонтали без растяжения
95  need_update = true;
96  }
97 
98  if (mAlign.isVStretch())
99  {
100  // растягиваем
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  // выравнивание по вертикали без растяжения
115  need_update = true;
116  }
117 
118  if (need_update)
119  {
121  _updateView();
122  }
123 
124  }
125 
127  {
128  //mAbsolutePosition = mCroppedParent->getAbsolutePosition() + mCoord.point();
129  bool margin = _checkMargin();
130 
131  mEmptyView = ((0 >= _getViewWidth()) || (0 >= _getViewHeight()));
132 
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  {
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  // мы не обрезаны, но были, ставим базовые координаты
182  }
183 
184  // запоминаем текущее состояние
185  mIsMargin = margin;
186 
187  if (nullptr != mNode) mNode->outOfDate(mRenderItem);
188  }
189 
191  {
192  MYGUI_ASSERT(!mRenderItem, "mRenderItem must be nullptr");
193 
194  mNode = _node;
195  mRenderItem = mNode->addToRenderItem(_texture, true, mSeparate);
197  }
198 
200  {
201  MYGUI_ASSERT(mRenderItem, "mRenderItem must be not nullptr");
202 
203  mNode = nullptr;
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  {
236  }
237 
238  if (nullptr != mNode) mNode->outOfDate(mRenderItem);
239  }
240 
242  {
243  if (!mVisible || mEmptyView) return;
244 
246 
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,
267  );
268 
270  }
271 
272  void SubSkin::_setColour(const Colour& _value)
273  {
274  uint32 colour = texture_utility::toColourARGB(_value);
276  mCurrentColour = (colour & 0x00FFFFFF) | (mCurrentColour & 0xFF000000);
277 
278  if (nullptr != mNode)
280  }
281 
283  {
285  }
286 
287 } // namespace MyGUI