MyGUI  3.0.1
MyGUI_RawRect.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_RawRect.h"
25 #include "MyGUI_RenderItem.h"
26 #include "MyGUI_RenderManager.h"
27 #include "MyGUI_SkinManager.h"
28 #include "MyGUI_LanguageManager.h"
29 #include "MyGUI_CommonStateInfo.h"
30 
31 namespace MyGUI
32 {
33 
35  {
36  if (_format == VertexColourType::ColourABGR)
37  _colour = ((_colour & 0x00FF0000) >> 16) | ((_colour & 0x000000FF) << 16) | (_colour & 0xFF00FF00);
38  }
39 
41  SubSkin(),
42  mRectTextureLT(FloatPoint(0, 0)),
43  mRectTextureRT(FloatPoint(1, 0)),
44  mRectTextureLB(FloatPoint(0, 1)),
45  mRectTextureRB(FloatPoint(1, 1)),
46  mColourLT(Colour::White),
47  mColourRT(Colour::White),
48  mColourLB(Colour::White),
49  mColourRB(Colour::White),
50  mRenderColourLT(0xFFFFFFFF),
51  mRenderColourRT(0xFFFFFFFF),
52  mRenderColourLB(0xFFFFFFFF),
53  mRenderColourRB(0xFFFFFFFF)
54  {
55  mVertexFormat = RenderManager::getInstance().getVertexFormat();
56  }
57 
59  {
60  }
61 
62  void RawRect::setAlpha(float _alpha)
63  {
64  mCurrentColour = ((uint8)(_alpha*255) << 24);
65 
66  mRenderColourLT = mCurrentColour | (mRenderColourLT & 0x00FFFFFF);
67  mRenderColourRT = mCurrentColour | (mRenderColourRT & 0x00FFFFFF);
68  mRenderColourLB = mCurrentColour | (mRenderColourLB & 0x00FFFFFF);
69  mRenderColourRB = mCurrentColour | (mRenderColourRB & 0x00FFFFFF);
70 
71  if (nullptr != mNode) mNode->outOfDate(mRenderItem);
72  }
73 
74  void RawRect::setRectColour(const Colour& _colourLT, const Colour& _colourRT, const Colour& _colourLB, const Colour& _colourRB)
75  {
76  mColourLT = _colourLT;
77  mRenderColourLT = texture_utility::toColourARGB(mColourLT);
78  ConvertColour(mRenderColourLT, mVertexFormat);
79  mRenderColourLT = mCurrentColour | (mRenderColourLT & 0x00FFFFFF);
80 
81  mColourRT = _colourRT;
82  mRenderColourRT = texture_utility::toColourARGB(mColourRT);
83  ConvertColour(mRenderColourRT, mVertexFormat);
84  mRenderColourRT = mCurrentColour | (mRenderColourRT & 0x00FFFFFF);
85 
86  mColourLB = _colourLB;
87  mRenderColourLB = texture_utility::toColourARGB(mColourLB);
88  ConvertColour(mRenderColourLB, mVertexFormat);
89  mRenderColourLB = mCurrentColour | (mRenderColourLB & 0x00FFFFFF);
90 
91  mColourRB = _colourRB;
92  mRenderColourRB = texture_utility::toColourARGB(mColourRB);
93  ConvertColour(mRenderColourRB, mVertexFormat);
94  mRenderColourRB = mCurrentColour | (mRenderColourRB & 0x00FFFFFF);
95 
96  if (nullptr != mNode) mNode->outOfDate(mRenderItem);
97  }
98 
99  void RawRect::setRectTexture(const FloatPoint& _pointLT, const FloatPoint& _pointRT, const FloatPoint& _pointLB, const FloatPoint& _pointRB)
100  {
101  mRectTextureLT = _pointLT;
102  mRectTextureRT = _pointRT;
103  mRectTextureLB = _pointLB;
104  mRectTextureRB = _pointRB;
105  }
106 
108  {
109  if (!mVisible || mEmptyView) return;
110 
112 
114 
115  float vertex_z = info.maximumDepth;
116 
117  float vertex_left = ((info.pixScaleX * (float)(mCurrentCoord.left + mCroppedParent->getAbsoluteLeft() - info.leftOffset) + info.hOffset) * 2) - 1;
118  float vertex_right = vertex_left + (info.pixScaleX * (float)mCurrentCoord.width * 2);
119  float vertex_top = -(((info.pixScaleY * (float)(mCurrentCoord.top + mCroppedParent->getAbsoluteTop() - info.topOffset) + info.vOffset) * 2) - 1);
120  float vertex_bottom = vertex_top - (info.pixScaleY * (float)mCurrentCoord.height * 2);
121 
122  // first triangle - left top
123  _vertex[0].x = vertex_left;
124  _vertex[0].y = vertex_top;
125  _vertex[0].z = vertex_z;
126  _vertex[0].colour = mRenderColourLT;
127  _vertex[0].u = mRectTextureLT.left;
128  _vertex[0].v = mRectTextureLT.top;
129 
130  // first triangle - left bottom
131  _vertex[1].x = vertex_left;
132  _vertex[1].y = vertex_bottom;
133  _vertex[1].z = vertex_z;
134  _vertex[1].colour = mRenderColourLB;
135  _vertex[1].u = mRectTextureLB.left;
136  _vertex[1].v = mRectTextureLB.top;
137 
138  // first triangle - right top
139  _vertex[2].x = vertex_right;
140  _vertex[2].y = vertex_top;
141  _vertex[2].z = vertex_z;
142  _vertex[2].colour = mRenderColourRT;
143  _vertex[2].u = mRectTextureRT.left;
144  _vertex[2].v = mRectTextureRT.top;
145 
146  // second triangle - right top
147  _vertex[3].x = vertex_right;
148  _vertex[3].y = vertex_top;
149  _vertex[3].z = vertex_z;
150  _vertex[3].colour = mRenderColourRT;
151  _vertex[3].u = mRectTextureRT.left;
152  _vertex[3].v = mRectTextureRT.top;
153 
154  // second triangle = left bottom
155  _vertex[4].x = vertex_left;
156  _vertex[4].y = vertex_bottom;
157  _vertex[4].z = vertex_z;
158  _vertex[4].colour = mRenderColourLB;
159  _vertex[4].u = mRectTextureLB.left;
160  _vertex[4].v = mRectTextureLB.top;
161 
162  // second triangle - right botton
163  _vertex[5].x = vertex_right;
164  _vertex[5].y = vertex_bottom;
165  _vertex[5].z = vertex_z;
166  _vertex[5].colour = mRenderColourRB;
167  _vertex[5].u = mRectTextureRB.left;
168  _vertex[5].v = mRectTextureRB.top;
169 
171  }
172 
174  {
175  SubSkinStateInfo* data = _data->castType<SubSkinStateInfo>();
176  const FloatRect& rect = data->getRect();
177  mRectTextureLT.set(rect.left, rect.top);
178  mRectTextureRT.set(rect.right, rect.top);
179  mRectTextureLB.set(rect.left, rect.bottom);
180  mRectTextureRB.set(rect.right, rect.bottom);
181  }
182 
183 } // namespace MyGUI