1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright 2000-2005 The OGRE Team |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreStableHeaders.h" |
---|
30 | |
---|
31 | #include "OgreBorderPanelOverlayElement.h" |
---|
32 | #include "OgreMaterialManager.h" |
---|
33 | #include "OgreMaterial.h" |
---|
34 | #include "OgreStringConverter.h" |
---|
35 | #include "OgreOverlayManager.h" |
---|
36 | #include "OgreHardwareBufferManager.h" |
---|
37 | #include "OgreHardwareVertexBuffer.h" |
---|
38 | #include "OgreHardwareIndexBuffer.h" |
---|
39 | #include "OgreException.h" |
---|
40 | #include "OgreRenderQueue.h" |
---|
41 | #include "OgreRoot.h" |
---|
42 | #include "OgreRenderSystem.h" |
---|
43 | |
---|
44 | namespace Ogre { |
---|
45 | //--------------------------------------------------------------------- |
---|
46 | String BorderPanelOverlayElement::msTypeName = "BorderPanel"; |
---|
47 | BorderPanelOverlayElement::CmdBorderSize BorderPanelOverlayElement::msCmdBorderSize; |
---|
48 | BorderPanelOverlayElement::CmdBorderMaterial BorderPanelOverlayElement::msCmdBorderMaterial; |
---|
49 | BorderPanelOverlayElement::CmdBorderLeftUV BorderPanelOverlayElement::msCmdBorderLeftUV; |
---|
50 | BorderPanelOverlayElement::CmdBorderTopUV BorderPanelOverlayElement::msCmdBorderTopUV; |
---|
51 | BorderPanelOverlayElement::CmdBorderBottomUV BorderPanelOverlayElement::msCmdBorderBottomUV; |
---|
52 | BorderPanelOverlayElement::CmdBorderRightUV BorderPanelOverlayElement::msCmdBorderRightUV; |
---|
53 | BorderPanelOverlayElement::CmdBorderTopLeftUV BorderPanelOverlayElement::msCmdBorderTopLeftUV; |
---|
54 | BorderPanelOverlayElement::CmdBorderBottomLeftUV BorderPanelOverlayElement::msCmdBorderBottomLeftUV; |
---|
55 | BorderPanelOverlayElement::CmdBorderTopRightUV BorderPanelOverlayElement::msCmdBorderTopRightUV; |
---|
56 | BorderPanelOverlayElement::CmdBorderBottomRightUV BorderPanelOverlayElement::msCmdBorderBottomRightUV; |
---|
57 | |
---|
58 | #define BCELL_UV(x) (x * 4 * 2) |
---|
59 | #define POSITION_BINDING 0 |
---|
60 | #define TEXCOORD_BINDING 1 |
---|
61 | //--------------------------------------------------------------------- |
---|
62 | BorderPanelOverlayElement::BorderPanelOverlayElement(const String& name) |
---|
63 | : PanelOverlayElement(name), |
---|
64 | mLeftBorderSize(0), |
---|
65 | mRightBorderSize(0), |
---|
66 | mTopBorderSize(0), |
---|
67 | mBottomBorderSize(0), |
---|
68 | mPixelLeftBorderSize(0), |
---|
69 | mPixelRightBorderSize(0), |
---|
70 | mPixelTopBorderSize(0), |
---|
71 | mPixelBottomBorderSize(0), |
---|
72 | mpBorderMaterial(0), |
---|
73 | mBorderRenderable(0) |
---|
74 | { |
---|
75 | if (createParamDictionary("BorderPanelOverlayElement")) |
---|
76 | { |
---|
77 | addBaseParameters(); |
---|
78 | } |
---|
79 | } |
---|
80 | //--------------------------------------------------------------------- |
---|
81 | BorderPanelOverlayElement::~BorderPanelOverlayElement() |
---|
82 | { |
---|
83 | delete mRenderOp2.vertexData; |
---|
84 | delete mRenderOp2.indexData; |
---|
85 | delete mBorderRenderable; |
---|
86 | } |
---|
87 | //--------------------------------------------------------------------- |
---|
88 | void BorderPanelOverlayElement::initialise(void) |
---|
89 | { |
---|
90 | bool init = !mInitialised; |
---|
91 | |
---|
92 | PanelOverlayElement::initialise(); |
---|
93 | |
---|
94 | // superclass will handle the interior panel area |
---|
95 | |
---|
96 | if (init) |
---|
97 | { |
---|
98 | // Setup render op in advance |
---|
99 | mRenderOp2.vertexData = new VertexData(); |
---|
100 | mRenderOp2.vertexData->vertexCount = 4 * 8; // 8 cells, can't necessarily share vertices cos |
---|
101 | // texcoords may differ |
---|
102 | mRenderOp2.vertexData->vertexStart = 0; |
---|
103 | |
---|
104 | // Vertex declaration |
---|
105 | VertexDeclaration* decl = mRenderOp2.vertexData->vertexDeclaration; |
---|
106 | // Position and texture coords each have their own buffers to allow |
---|
107 | // each to be edited separately with the discard flag |
---|
108 | decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION); |
---|
109 | decl->addElement(TEXCOORD_BINDING, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0); |
---|
110 | |
---|
111 | // Vertex buffer #1, position |
---|
112 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton() |
---|
113 | .createVertexBuffer( |
---|
114 | decl->getVertexSize(POSITION_BINDING), |
---|
115 | mRenderOp2.vertexData->vertexCount, |
---|
116 | HardwareBuffer::HBU_STATIC_WRITE_ONLY); |
---|
117 | // bind position |
---|
118 | VertexBufferBinding* binding = mRenderOp2.vertexData->vertexBufferBinding; |
---|
119 | binding->setBinding(POSITION_BINDING, vbuf); |
---|
120 | |
---|
121 | // Vertex buffer #2, texcoords |
---|
122 | vbuf = HardwareBufferManager::getSingleton() |
---|
123 | .createVertexBuffer( |
---|
124 | decl->getVertexSize(TEXCOORD_BINDING), |
---|
125 | mRenderOp2.vertexData->vertexCount, |
---|
126 | HardwareBuffer::HBU_STATIC_WRITE_ONLY, true); |
---|
127 | // bind texcoord |
---|
128 | binding->setBinding(TEXCOORD_BINDING, vbuf); |
---|
129 | |
---|
130 | mRenderOp2.operationType = RenderOperation::OT_TRIANGLE_LIST; |
---|
131 | mRenderOp2.useIndexes = true; |
---|
132 | // Index data |
---|
133 | mRenderOp2.indexData = new IndexData(); |
---|
134 | mRenderOp2.indexData->indexCount = 8 * 6; |
---|
135 | mRenderOp2.indexData->indexStart = 0; |
---|
136 | |
---|
137 | /* Each cell is |
---|
138 | 0-----2 |
---|
139 | | /| |
---|
140 | | / | |
---|
141 | |/ | |
---|
142 | 1-----3 |
---|
143 | */ |
---|
144 | mRenderOp2.indexData->indexBuffer = HardwareBufferManager::getSingleton(). |
---|
145 | createIndexBuffer( |
---|
146 | HardwareIndexBuffer::IT_16BIT, |
---|
147 | mRenderOp2.indexData->indexCount, |
---|
148 | HardwareBuffer::HBU_STATIC_WRITE_ONLY); |
---|
149 | |
---|
150 | ushort* pIdx = static_cast<ushort*>( |
---|
151 | mRenderOp2.indexData->indexBuffer->lock( |
---|
152 | 0, |
---|
153 | mRenderOp2.indexData->indexBuffer->getSizeInBytes(), |
---|
154 | HardwareBuffer::HBL_DISCARD) ); |
---|
155 | |
---|
156 | for (int cell = 0; cell < 8; ++cell) |
---|
157 | { |
---|
158 | ushort base = cell * 4; |
---|
159 | *pIdx++ = base; |
---|
160 | *pIdx++ = base + 1; |
---|
161 | *pIdx++ = base + 2; |
---|
162 | |
---|
163 | *pIdx++ = base + 2; |
---|
164 | *pIdx++ = base + 1; |
---|
165 | *pIdx++ = base + 3; |
---|
166 | } |
---|
167 | |
---|
168 | mRenderOp2.indexData->indexBuffer->unlock(); |
---|
169 | |
---|
170 | // Create sub-object for rendering border |
---|
171 | mBorderRenderable = new BorderRenderable(this); |
---|
172 | |
---|
173 | mInitialised = true; |
---|
174 | } |
---|
175 | } |
---|
176 | //--------------------------------------------------------------------- |
---|
177 | void BorderPanelOverlayElement::addBaseParameters(void) |
---|
178 | { |
---|
179 | PanelOverlayElement::addBaseParameters(); |
---|
180 | ParamDictionary* dict = getParamDictionary(); |
---|
181 | |
---|
182 | dict->addParameter(ParameterDef("border_size", |
---|
183 | "The sizes of the borders relative to the screen size, in the order " |
---|
184 | "left, right, top, bottom." |
---|
185 | , PT_STRING), |
---|
186 | &msCmdBorderSize); |
---|
187 | dict->addParameter(ParameterDef("border_material", |
---|
188 | "The material to use for the border." |
---|
189 | , PT_STRING), |
---|
190 | &msCmdBorderMaterial); |
---|
191 | dict->addParameter(ParameterDef("border_topleft_uv", |
---|
192 | "The texture coordinates for the top-left corner border texture. 2 sets of uv values, " |
---|
193 | "one for the top-left corner, the other for the bottom-right corner." |
---|
194 | , PT_STRING), |
---|
195 | &msCmdBorderTopLeftUV); |
---|
196 | dict->addParameter(ParameterDef("border_topright_uv", |
---|
197 | "The texture coordinates for the top-right corner border texture. 2 sets of uv values, " |
---|
198 | "one for the top-left corner, the other for the bottom-right corner." |
---|
199 | , PT_STRING), |
---|
200 | &msCmdBorderTopRightUV); |
---|
201 | dict->addParameter(ParameterDef("border_bottomright_uv", |
---|
202 | "The texture coordinates for the bottom-right corner border texture. 2 sets of uv values, " |
---|
203 | "one for the top-left corner, the other for the bottom-right corner." |
---|
204 | , PT_STRING), |
---|
205 | &msCmdBorderBottomRightUV); |
---|
206 | dict->addParameter(ParameterDef("border_bottomleft_uv", |
---|
207 | "The texture coordinates for the bottom-left corner border texture. 2 sets of uv values, " |
---|
208 | "one for the top-left corner, the other for the bottom-right corner." |
---|
209 | , PT_STRING), |
---|
210 | &msCmdBorderBottomLeftUV); |
---|
211 | dict->addParameter(ParameterDef("border_left_uv", |
---|
212 | "The texture coordinates for the left edge border texture. 2 sets of uv values, " |
---|
213 | "one for the top-left corner, the other for the bottom-right corner." |
---|
214 | , PT_STRING), |
---|
215 | &msCmdBorderLeftUV); |
---|
216 | dict->addParameter(ParameterDef("border_top_uv", |
---|
217 | "The texture coordinates for the top edge border texture. 2 sets of uv values, " |
---|
218 | "one for the top-left corner, the other for the bottom-right corner." |
---|
219 | , PT_STRING), |
---|
220 | &msCmdBorderTopUV); |
---|
221 | dict->addParameter(ParameterDef("border_right_uv", |
---|
222 | "The texture coordinates for the right edge border texture. 2 sets of uv values, " |
---|
223 | "one for the top-left corner, the other for the bottom-right corner." |
---|
224 | , PT_STRING), |
---|
225 | &msCmdBorderRightUV); |
---|
226 | dict->addParameter(ParameterDef("border_bottom_uv", |
---|
227 | "The texture coordinates for the bottom edge border texture. 2 sets of uv values, " |
---|
228 | "one for the top-left corner, the other for the bottom-right corner." |
---|
229 | , PT_STRING), |
---|
230 | &msCmdBorderBottomUV); |
---|
231 | |
---|
232 | } |
---|
233 | //--------------------------------------------------------------------- |
---|
234 | void BorderPanelOverlayElement::setBorderSize(Real size) |
---|
235 | { |
---|
236 | if (mMetricsMode != GMM_RELATIVE) |
---|
237 | { |
---|
238 | mPixelLeftBorderSize = mPixelRightBorderSize = |
---|
239 | mPixelTopBorderSize = mPixelBottomBorderSize = static_cast<unsigned>(size); |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | mLeftBorderSize = mRightBorderSize = |
---|
244 | mTopBorderSize = mBottomBorderSize = size; |
---|
245 | } |
---|
246 | mGeomPositionsOutOfDate = true; |
---|
247 | } |
---|
248 | //--------------------------------------------------------------------- |
---|
249 | void BorderPanelOverlayElement::setBorderSize(Real sides, Real topAndBottom) |
---|
250 | { |
---|
251 | if (mMetricsMode != GMM_RELATIVE) |
---|
252 | { |
---|
253 | mPixelLeftBorderSize = mPixelRightBorderSize = static_cast<unsigned>(sides); |
---|
254 | mPixelTopBorderSize = mPixelBottomBorderSize = static_cast<unsigned>(topAndBottom); |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | mLeftBorderSize = mRightBorderSize = sides; |
---|
259 | mTopBorderSize = mBottomBorderSize = topAndBottom; |
---|
260 | } |
---|
261 | mGeomPositionsOutOfDate = true; |
---|
262 | |
---|
263 | |
---|
264 | } |
---|
265 | //--------------------------------------------------------------------- |
---|
266 | void BorderPanelOverlayElement::setBorderSize(Real left, Real right, Real top, Real bottom) |
---|
267 | { |
---|
268 | if (mMetricsMode != GMM_RELATIVE) |
---|
269 | { |
---|
270 | mPixelLeftBorderSize = static_cast<unsigned>(left); |
---|
271 | mPixelRightBorderSize = static_cast<unsigned>(right); |
---|
272 | mPixelTopBorderSize = static_cast<unsigned>(top); |
---|
273 | mPixelBottomBorderSize = static_cast<unsigned>(bottom); |
---|
274 | } |
---|
275 | else |
---|
276 | { |
---|
277 | mLeftBorderSize = left; |
---|
278 | mRightBorderSize = right; |
---|
279 | mTopBorderSize = top; |
---|
280 | mBottomBorderSize = bottom; |
---|
281 | } |
---|
282 | mGeomPositionsOutOfDate = true; |
---|
283 | } |
---|
284 | //--------------------------------------------------------------------- |
---|
285 | Real BorderPanelOverlayElement::getLeftBorderSize(void) const |
---|
286 | { |
---|
287 | if (mMetricsMode == GMM_PIXELS) |
---|
288 | { |
---|
289 | return mPixelLeftBorderSize; |
---|
290 | } |
---|
291 | else |
---|
292 | { |
---|
293 | return mLeftBorderSize; |
---|
294 | } |
---|
295 | } |
---|
296 | //--------------------------------------------------------------------- |
---|
297 | Real BorderPanelOverlayElement::getRightBorderSize(void) const |
---|
298 | { |
---|
299 | if (mMetricsMode == GMM_PIXELS) |
---|
300 | { |
---|
301 | return mPixelRightBorderSize; |
---|
302 | } |
---|
303 | else |
---|
304 | { |
---|
305 | return mRightBorderSize; |
---|
306 | } |
---|
307 | } |
---|
308 | //--------------------------------------------------------------------- |
---|
309 | Real BorderPanelOverlayElement::getTopBorderSize(void) const |
---|
310 | { |
---|
311 | if (mMetricsMode == GMM_PIXELS) |
---|
312 | { |
---|
313 | return mPixelTopBorderSize; |
---|
314 | } |
---|
315 | else |
---|
316 | { |
---|
317 | return mTopBorderSize; |
---|
318 | } |
---|
319 | } |
---|
320 | //--------------------------------------------------------------------- |
---|
321 | Real BorderPanelOverlayElement::getBottomBorderSize(void) const |
---|
322 | { |
---|
323 | if (mMetricsMode == GMM_PIXELS) |
---|
324 | { |
---|
325 | return mPixelBottomBorderSize; |
---|
326 | } |
---|
327 | else |
---|
328 | { |
---|
329 | return mBottomBorderSize; |
---|
330 | } |
---|
331 | } |
---|
332 | //--------------------------------------------------------------------- |
---|
333 | void BorderPanelOverlayElement::updateTextureGeometry() |
---|
334 | { |
---|
335 | PanelOverlayElement::updateTextureGeometry(); |
---|
336 | /* Each cell is |
---|
337 | 0-----2 |
---|
338 | | /| |
---|
339 | | / | |
---|
340 | |/ | |
---|
341 | 1-----3 |
---|
342 | */ |
---|
343 | // No choice but to lock / unlock each time here, but lock only small sections |
---|
344 | |
---|
345 | HardwareVertexBufferSharedPtr vbuf = |
---|
346 | mRenderOp2.vertexData->vertexBufferBinding->getBuffer(TEXCOORD_BINDING); |
---|
347 | // Can't use discard since this discards whole buffer |
---|
348 | float* pUV = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
349 | |
---|
350 | for (uint i = 0; i < 8; ++i) |
---|
351 | { |
---|
352 | *pUV++ = mBorderUV[i].u1; *pUV++ = mBorderUV[i].v1; |
---|
353 | *pUV++ = mBorderUV[i].u1; *pUV++ = mBorderUV[i].v2; |
---|
354 | *pUV++ = mBorderUV[i].u2; *pUV++ = mBorderUV[i].v1; |
---|
355 | *pUV++ = mBorderUV[i].u2; *pUV++ = mBorderUV[i].v2; |
---|
356 | } |
---|
357 | |
---|
358 | vbuf->unlock(); |
---|
359 | } |
---|
360 | //--------------------------------------------------------------------- |
---|
361 | String BorderPanelOverlayElement::getCellUVString(BorderCellIndex idx) const |
---|
362 | { |
---|
363 | String ret = StringConverter::toString(mBorderUV[idx].u1) + " " + |
---|
364 | StringConverter::toString(mBorderUV[idx].v1) + " " + |
---|
365 | StringConverter::toString(mBorderUV[idx].u2) + " " + |
---|
366 | StringConverter::toString(mBorderUV[idx].v2); |
---|
367 | return ret; |
---|
368 | } |
---|
369 | //--------------------------------------------------------------------- |
---|
370 | void BorderPanelOverlayElement::setLeftBorderUV(Real u1, Real v1, Real u2, Real v2) |
---|
371 | { |
---|
372 | mBorderUV[BCELL_LEFT].u1 = u1; |
---|
373 | mBorderUV[BCELL_LEFT].u2 = u2; |
---|
374 | mBorderUV[BCELL_LEFT].v1 = v1; |
---|
375 | mBorderUV[BCELL_LEFT].v2 = v2; |
---|
376 | mGeomUVsOutOfDate = true; |
---|
377 | } |
---|
378 | //--------------------------------------------------------------------- |
---|
379 | void BorderPanelOverlayElement::setRightBorderUV(Real u1, Real v1, Real u2, Real v2) |
---|
380 | { |
---|
381 | mBorderUV[BCELL_RIGHT].u1 = u1; |
---|
382 | mBorderUV[BCELL_RIGHT].u2 = u2; |
---|
383 | mBorderUV[BCELL_RIGHT].v1 = v1; |
---|
384 | mBorderUV[BCELL_RIGHT].v2 = v2; |
---|
385 | mGeomUVsOutOfDate = true; |
---|
386 | } |
---|
387 | //--------------------------------------------------------------------- |
---|
388 | void BorderPanelOverlayElement::setTopBorderUV(Real u1, Real v1, Real u2, Real v2) |
---|
389 | { |
---|
390 | mBorderUV[BCELL_TOP].u1 = u1; |
---|
391 | mBorderUV[BCELL_TOP].u2 = u2; |
---|
392 | mBorderUV[BCELL_TOP].v1 = v1; |
---|
393 | mBorderUV[BCELL_TOP].v2 = v2; |
---|
394 | mGeomUVsOutOfDate = true; |
---|
395 | } |
---|
396 | //--------------------------------------------------------------------- |
---|
397 | void BorderPanelOverlayElement::setBottomBorderUV(Real u1, Real v1, Real u2, Real v2) |
---|
398 | { |
---|
399 | mBorderUV[BCELL_BOTTOM].u1 = u1; |
---|
400 | mBorderUV[BCELL_BOTTOM].u2 = u2; |
---|
401 | mBorderUV[BCELL_BOTTOM].v1 = v1; |
---|
402 | mBorderUV[BCELL_BOTTOM].v2 = v2; |
---|
403 | mGeomUVsOutOfDate = true; |
---|
404 | } |
---|
405 | //--------------------------------------------------------------------- |
---|
406 | void BorderPanelOverlayElement::setTopLeftBorderUV(Real u1, Real v1, Real u2, Real v2) |
---|
407 | { |
---|
408 | mBorderUV[BCELL_TOP_LEFT].u1 = u1; |
---|
409 | mBorderUV[BCELL_TOP_LEFT].u2 = u2; |
---|
410 | mBorderUV[BCELL_TOP_LEFT].v1 = v1; |
---|
411 | mBorderUV[BCELL_TOP_LEFT].v2 = v2; |
---|
412 | mGeomUVsOutOfDate = true; |
---|
413 | } |
---|
414 | //--------------------------------------------------------------------- |
---|
415 | void BorderPanelOverlayElement::setTopRightBorderUV(Real u1, Real v1, Real u2, Real v2) |
---|
416 | { |
---|
417 | mBorderUV[BCELL_TOP_RIGHT].u1 = u1; |
---|
418 | mBorderUV[BCELL_TOP_RIGHT].u2 = u2; |
---|
419 | mBorderUV[BCELL_TOP_RIGHT].v1 = v1; |
---|
420 | mBorderUV[BCELL_TOP_RIGHT].v2 = v2; |
---|
421 | mGeomUVsOutOfDate = true; |
---|
422 | } |
---|
423 | //--------------------------------------------------------------------- |
---|
424 | void BorderPanelOverlayElement::setBottomLeftBorderUV(Real u1, Real v1, Real u2, Real v2) |
---|
425 | { |
---|
426 | mBorderUV[BCELL_BOTTOM_LEFT].u1 = u1; |
---|
427 | mBorderUV[BCELL_BOTTOM_LEFT].u2 = u2; |
---|
428 | mBorderUV[BCELL_BOTTOM_LEFT].v1 = v1; |
---|
429 | mBorderUV[BCELL_BOTTOM_LEFT].v2 = v2; |
---|
430 | mGeomUVsOutOfDate = true; |
---|
431 | } |
---|
432 | //--------------------------------------------------------------------- |
---|
433 | void BorderPanelOverlayElement::setBottomRightBorderUV(Real u1, Real v1, Real u2, Real v2) |
---|
434 | { |
---|
435 | mBorderUV[BCELL_BOTTOM_RIGHT].u1 = u1; |
---|
436 | mBorderUV[BCELL_BOTTOM_RIGHT].u2 = u2; |
---|
437 | mBorderUV[BCELL_BOTTOM_RIGHT].v1 = v1; |
---|
438 | mBorderUV[BCELL_BOTTOM_RIGHT].v2 = v2; |
---|
439 | mGeomUVsOutOfDate = true; |
---|
440 | } |
---|
441 | |
---|
442 | //--------------------------------------------------------------------- |
---|
443 | String BorderPanelOverlayElement::getLeftBorderUVString() const |
---|
444 | { |
---|
445 | return getCellUVString(BCELL_LEFT); |
---|
446 | } |
---|
447 | //--------------------------------------------------------------------- |
---|
448 | String BorderPanelOverlayElement::getRightBorderUVString() const |
---|
449 | { |
---|
450 | return getCellUVString(BCELL_RIGHT); |
---|
451 | } |
---|
452 | //--------------------------------------------------------------------- |
---|
453 | String BorderPanelOverlayElement::getTopBorderUVString() const |
---|
454 | { |
---|
455 | return getCellUVString(BCELL_TOP); |
---|
456 | } |
---|
457 | //--------------------------------------------------------------------- |
---|
458 | String BorderPanelOverlayElement::getBottomBorderUVString() const |
---|
459 | { |
---|
460 | return getCellUVString(BCELL_BOTTOM); |
---|
461 | } |
---|
462 | //--------------------------------------------------------------------- |
---|
463 | String BorderPanelOverlayElement::getTopLeftBorderUVString() const |
---|
464 | { |
---|
465 | return getCellUVString(BCELL_TOP_LEFT); |
---|
466 | } |
---|
467 | //--------------------------------------------------------------------- |
---|
468 | String BorderPanelOverlayElement::getTopRightBorderUVString() const |
---|
469 | { |
---|
470 | return getCellUVString(BCELL_TOP_RIGHT); |
---|
471 | } |
---|
472 | //--------------------------------------------------------------------- |
---|
473 | String BorderPanelOverlayElement::getBottomLeftBorderUVString() const |
---|
474 | { |
---|
475 | return getCellUVString(BCELL_BOTTOM_LEFT); |
---|
476 | } |
---|
477 | //--------------------------------------------------------------------- |
---|
478 | String BorderPanelOverlayElement::getBottomRightBorderUVString() const |
---|
479 | { |
---|
480 | return getCellUVString(BCELL_BOTTOM_RIGHT); |
---|
481 | } |
---|
482 | |
---|
483 | |
---|
484 | |
---|
485 | |
---|
486 | |
---|
487 | //--------------------------------------------------------------------- |
---|
488 | void BorderPanelOverlayElement::setBorderMaterialName(const String& name) |
---|
489 | { |
---|
490 | mBorderMaterialName = name; |
---|
491 | mpBorderMaterial = MaterialManager::getSingleton().getByName(name); |
---|
492 | if (mpBorderMaterial.isNull()) |
---|
493 | OGRE_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "Could not find material " + name, |
---|
494 | "BorderPanelOverlayElement::setBorderMaterialName" ); |
---|
495 | mpBorderMaterial->load(); |
---|
496 | // Set some prerequisites to be sure |
---|
497 | mpBorderMaterial->setLightingEnabled(false); |
---|
498 | mpBorderMaterial->setDepthCheckEnabled(false); |
---|
499 | |
---|
500 | } |
---|
501 | //--------------------------------------------------------------------- |
---|
502 | const String& BorderPanelOverlayElement::getBorderMaterialName(void) const |
---|
503 | { |
---|
504 | return mBorderMaterialName; |
---|
505 | } |
---|
506 | //--------------------------------------------------------------------- |
---|
507 | void BorderPanelOverlayElement::updatePositionGeometry(void) |
---|
508 | { |
---|
509 | /* |
---|
510 | Grid is like this: |
---|
511 | +--+---------------+--+ |
---|
512 | |0 | 1 |2 | |
---|
513 | +--+---------------+--+ |
---|
514 | | | | | |
---|
515 | | | | | |
---|
516 | |3 | center |4 | |
---|
517 | | | | | |
---|
518 | +--+---------------+--+ |
---|
519 | |5 | 6 |7 | |
---|
520 | +--+---------------+--+ |
---|
521 | */ |
---|
522 | // Convert positions into -1, 1 coordinate space (homogenous clip space) |
---|
523 | // Top / bottom also need inverting since y is upside down |
---|
524 | Real left[8], right[8], top[8], bottom[8]; |
---|
525 | // Horizontal |
---|
526 | left[0] = left[3] = left[5] = _getDerivedLeft() * 2 - 1; |
---|
527 | left[1] = left[6] = right[0] = right[3] = right[5] = left[0] + (mLeftBorderSize * 2); |
---|
528 | right[2] = right[4] = right[7] = left[0] + (mWidth * 2); |
---|
529 | left[2] = left[4] = left[7] = right[1] = right[6] = right[2] - (mRightBorderSize * 2); |
---|
530 | // Vertical |
---|
531 | top[0] = top[1] = top[2] = -((_getDerivedTop() * 2) - 1); |
---|
532 | top[3] = top[4] = bottom[0] = bottom[1] = bottom[2] = top[0] - (mTopBorderSize * 2); |
---|
533 | bottom[5] = bottom[6] = bottom[7] = top[0] - (mHeight * 2); |
---|
534 | top[5] = top[6] = top[7] = bottom[3] = bottom[4] = bottom[5] + (mBottomBorderSize * 2); |
---|
535 | |
---|
536 | // Lock the whole position buffer in discard mode |
---|
537 | HardwareVertexBufferSharedPtr vbuf = |
---|
538 | mRenderOp2.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING); |
---|
539 | float* pPos = static_cast<float*>( |
---|
540 | vbuf->lock(HardwareBuffer::HBL_DISCARD) ); |
---|
541 | // Use the furthest away depth value, since materials should have depth-check off |
---|
542 | // This initialised the depth buffer for any 3D objects in front |
---|
543 | Real zValue = Root::getSingleton().getRenderSystem()->getMaximumDepthInputValue(); |
---|
544 | for (ushort cell = 0; cell < 8; ++cell) |
---|
545 | { |
---|
546 | /* |
---|
547 | 0-----2 |
---|
548 | | /| |
---|
549 | | / | |
---|
550 | |/ | |
---|
551 | 1-----3 |
---|
552 | */ |
---|
553 | *pPos++ = left[cell]; |
---|
554 | *pPos++ = top[cell]; |
---|
555 | *pPos++ = zValue; |
---|
556 | |
---|
557 | *pPos++ = left[cell]; |
---|
558 | *pPos++ = bottom[cell]; |
---|
559 | *pPos++ = zValue; |
---|
560 | |
---|
561 | *pPos++ = right[cell]; |
---|
562 | *pPos++ = top[cell]; |
---|
563 | *pPos++ = zValue; |
---|
564 | |
---|
565 | *pPos++ = right[cell]; |
---|
566 | *pPos++ = bottom[cell]; |
---|
567 | *pPos++ = zValue; |
---|
568 | |
---|
569 | } |
---|
570 | vbuf->unlock(); |
---|
571 | |
---|
572 | // Also update center geometry |
---|
573 | // NB don't use superclass because we need to make it smaller because of border |
---|
574 | vbuf = mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING); |
---|
575 | pPos = static_cast<float*>( |
---|
576 | vbuf->lock(HardwareBuffer::HBL_DISCARD) ); |
---|
577 | // Use cell 1 and 3 to determine positions |
---|
578 | *pPos++ = left[1]; |
---|
579 | *pPos++ = top[3]; |
---|
580 | *pPos++ = zValue; |
---|
581 | |
---|
582 | *pPos++ = left[1]; |
---|
583 | *pPos++ = bottom[3]; |
---|
584 | *pPos++ = zValue; |
---|
585 | |
---|
586 | *pPos++ = right[1]; |
---|
587 | *pPos++ = top[3]; |
---|
588 | *pPos++ = zValue; |
---|
589 | |
---|
590 | *pPos++ = right[1]; |
---|
591 | *pPos++ = bottom[3]; |
---|
592 | *pPos++ = zValue; |
---|
593 | |
---|
594 | vbuf->unlock(); |
---|
595 | } |
---|
596 | //--------------------------------------------------------------------- |
---|
597 | void BorderPanelOverlayElement::_updateRenderQueue(RenderQueue* queue) |
---|
598 | { |
---|
599 | // Add self twice to the queue |
---|
600 | // Have to do this to allow 2 materials |
---|
601 | if (mVisible) |
---|
602 | { |
---|
603 | |
---|
604 | // Add outer |
---|
605 | queue->addRenderable(mBorderRenderable, RENDER_QUEUE_OVERLAY, mZOrder); |
---|
606 | |
---|
607 | // do inner last so the border artifacts don't overwrite the children |
---|
608 | // Add inner |
---|
609 | PanelOverlayElement::_updateRenderQueue(queue); |
---|
610 | } |
---|
611 | } |
---|
612 | //----------------------------------------------------------------------- |
---|
613 | void BorderPanelOverlayElement::setMetricsMode(GuiMetricsMode gmm) |
---|
614 | { |
---|
615 | PanelOverlayElement::setMetricsMode(gmm); |
---|
616 | if (gmm != GMM_RELATIVE) |
---|
617 | { |
---|
618 | mPixelBottomBorderSize = static_cast<unsigned>(mBottomBorderSize); |
---|
619 | mPixelLeftBorderSize = static_cast<unsigned>(mLeftBorderSize); |
---|
620 | mPixelRightBorderSize = static_cast<unsigned>(mRightBorderSize); |
---|
621 | mPixelTopBorderSize = static_cast<unsigned>(mTopBorderSize); |
---|
622 | } |
---|
623 | } |
---|
624 | //----------------------------------------------------------------------- |
---|
625 | void BorderPanelOverlayElement::_update(void) |
---|
626 | { |
---|
627 | if (mMetricsMode != GMM_RELATIVE && |
---|
628 | (OverlayManager::getSingleton().hasViewportChanged() || mGeomPositionsOutOfDate)) |
---|
629 | { |
---|
630 | mLeftBorderSize = mPixelLeftBorderSize * mPixelScaleX; |
---|
631 | mRightBorderSize = mPixelRightBorderSize * mPixelScaleX; |
---|
632 | mTopBorderSize = mPixelTopBorderSize * mPixelScaleY; |
---|
633 | mBottomBorderSize = mPixelBottomBorderSize * mPixelScaleY; |
---|
634 | mGeomPositionsOutOfDate = true; |
---|
635 | } |
---|
636 | PanelOverlayElement::_update(); |
---|
637 | } |
---|
638 | //----------------------------------------------------------------------- |
---|
639 | //--------------------------------------------------------------------- |
---|
640 | //--------------------------------------------------------------------- |
---|
641 | // Command objects |
---|
642 | //--------------------------------------------------------------------- |
---|
643 | //----------------------------------------------------------------------- |
---|
644 | String BorderPanelOverlayElement::CmdBorderSize::doGet(const void* target) const |
---|
645 | { |
---|
646 | const BorderPanelOverlayElement* t = static_cast<const BorderPanelOverlayElement*>(target); |
---|
647 | return String( |
---|
648 | StringConverter::toString(t->getLeftBorderSize()) + " " + |
---|
649 | StringConverter::toString(t->getRightBorderSize()) + " " + |
---|
650 | StringConverter::toString(t->getTopBorderSize()) + " " + |
---|
651 | StringConverter::toString(t->getBottomBorderSize()) ); |
---|
652 | } |
---|
653 | void BorderPanelOverlayElement::CmdBorderSize::doSet(void* target, const String& val) |
---|
654 | { |
---|
655 | std::vector<String> vec = StringUtil::split(val); |
---|
656 | |
---|
657 | static_cast<BorderPanelOverlayElement*>(target)->setBorderSize( |
---|
658 | StringConverter::parseReal(vec[0]), |
---|
659 | StringConverter::parseReal(vec[1]), |
---|
660 | StringConverter::parseReal(vec[2]), |
---|
661 | StringConverter::parseReal(vec[3]) |
---|
662 | ); |
---|
663 | } |
---|
664 | //----------------------------------------------------------------------- |
---|
665 | String BorderPanelOverlayElement::CmdBorderMaterial::doGet(const void* target) const |
---|
666 | { |
---|
667 | // No need right now.. |
---|
668 | return static_cast<const BorderPanelOverlayElement*>(target)->getBorderMaterialName(); |
---|
669 | } |
---|
670 | void BorderPanelOverlayElement::CmdBorderMaterial::doSet(void* target, const String& val) |
---|
671 | { |
---|
672 | std::vector<String> vec = StringUtil::split(val); |
---|
673 | |
---|
674 | static_cast<BorderPanelOverlayElement*>(target)->setBorderMaterialName(val); |
---|
675 | } |
---|
676 | //----------------------------------------------------------------------- |
---|
677 | String BorderPanelOverlayElement::CmdBorderBottomLeftUV::doGet(const void* target) const |
---|
678 | { |
---|
679 | // No need right now.. |
---|
680 | return static_cast<const BorderPanelOverlayElement*>(target)->getBottomLeftBorderUVString(); |
---|
681 | } |
---|
682 | void BorderPanelOverlayElement::CmdBorderBottomLeftUV::doSet(void* target, const String& val) |
---|
683 | { |
---|
684 | std::vector<String> vec = StringUtil::split(val); |
---|
685 | |
---|
686 | static_cast<BorderPanelOverlayElement*>(target)->setBottomLeftBorderUV( |
---|
687 | StringConverter::parseReal(vec[0]), |
---|
688 | StringConverter::parseReal(vec[1]), |
---|
689 | StringConverter::parseReal(vec[2]), |
---|
690 | StringConverter::parseReal(vec[3]) |
---|
691 | ); |
---|
692 | } |
---|
693 | //----------------------------------------------------------------------- |
---|
694 | String BorderPanelOverlayElement::CmdBorderBottomRightUV::doGet(const void* target) const |
---|
695 | { |
---|
696 | // No need right now.. |
---|
697 | return static_cast<const BorderPanelOverlayElement*>(target)->getBottomRightBorderUVString(); |
---|
698 | } |
---|
699 | void BorderPanelOverlayElement::CmdBorderBottomRightUV::doSet(void* target, const String& val) |
---|
700 | { |
---|
701 | std::vector<String> vec = StringUtil::split(val); |
---|
702 | |
---|
703 | static_cast<BorderPanelOverlayElement*>(target)->setBottomRightBorderUV( |
---|
704 | StringConverter::parseReal(vec[0]), |
---|
705 | StringConverter::parseReal(vec[1]), |
---|
706 | StringConverter::parseReal(vec[2]), |
---|
707 | StringConverter::parseReal(vec[3]) |
---|
708 | ); |
---|
709 | } |
---|
710 | //----------------------------------------------------------------------- |
---|
711 | String BorderPanelOverlayElement::CmdBorderTopLeftUV::doGet(const void* target) const |
---|
712 | { |
---|
713 | // No need right now.. |
---|
714 | return static_cast<const BorderPanelOverlayElement*>(target)->getTopLeftBorderUVString(); |
---|
715 | } |
---|
716 | void BorderPanelOverlayElement::CmdBorderTopLeftUV::doSet(void* target, const String& val) |
---|
717 | { |
---|
718 | std::vector<String> vec = StringUtil::split(val); |
---|
719 | |
---|
720 | static_cast<BorderPanelOverlayElement*>(target)->setTopLeftBorderUV( |
---|
721 | StringConverter::parseReal(vec[0]), |
---|
722 | StringConverter::parseReal(vec[1]), |
---|
723 | StringConverter::parseReal(vec[2]), |
---|
724 | StringConverter::parseReal(vec[3]) |
---|
725 | ); |
---|
726 | } |
---|
727 | //----------------------------------------------------------------------- |
---|
728 | String BorderPanelOverlayElement::CmdBorderTopRightUV::doGet(const void* target) const |
---|
729 | { |
---|
730 | // No need right now.. |
---|
731 | return static_cast<const BorderPanelOverlayElement*>(target)->getTopRightBorderUVString(); |
---|
732 | } |
---|
733 | void BorderPanelOverlayElement::CmdBorderTopRightUV::doSet(void* target, const String& val) |
---|
734 | { |
---|
735 | std::vector<String> vec = StringUtil::split(val); |
---|
736 | |
---|
737 | static_cast<BorderPanelOverlayElement*>(target)->setTopRightBorderUV( |
---|
738 | StringConverter::parseReal(vec[0]), |
---|
739 | StringConverter::parseReal(vec[1]), |
---|
740 | StringConverter::parseReal(vec[2]), |
---|
741 | StringConverter::parseReal(vec[3]) |
---|
742 | ); |
---|
743 | } |
---|
744 | //----------------------------------------------------------------------- |
---|
745 | String BorderPanelOverlayElement::CmdBorderLeftUV::doGet(const void* target) const |
---|
746 | { |
---|
747 | // No need right now.. |
---|
748 | return static_cast<const BorderPanelOverlayElement*>(target)->getLeftBorderUVString(); |
---|
749 | } |
---|
750 | void BorderPanelOverlayElement::CmdBorderLeftUV::doSet(void* target, const String& val) |
---|
751 | { |
---|
752 | std::vector<String> vec = StringUtil::split(val); |
---|
753 | |
---|
754 | static_cast<BorderPanelOverlayElement*>(target)->setLeftBorderUV( |
---|
755 | StringConverter::parseReal(vec[0]), |
---|
756 | StringConverter::parseReal(vec[1]), |
---|
757 | StringConverter::parseReal(vec[2]), |
---|
758 | StringConverter::parseReal(vec[3]) |
---|
759 | ); |
---|
760 | } |
---|
761 | //----------------------------------------------------------------------- |
---|
762 | String BorderPanelOverlayElement::CmdBorderRightUV::doGet(const void* target) const |
---|
763 | { |
---|
764 | // No need right now.. |
---|
765 | return static_cast<const BorderPanelOverlayElement*>(target)->getRightBorderUVString(); |
---|
766 | } |
---|
767 | void BorderPanelOverlayElement::CmdBorderRightUV::doSet(void* target, const String& val) |
---|
768 | { |
---|
769 | std::vector<String> vec = StringUtil::split(val); |
---|
770 | |
---|
771 | static_cast<BorderPanelOverlayElement*>(target)->setRightBorderUV( |
---|
772 | StringConverter::parseReal(vec[0]), |
---|
773 | StringConverter::parseReal(vec[1]), |
---|
774 | StringConverter::parseReal(vec[2]), |
---|
775 | StringConverter::parseReal(vec[3]) |
---|
776 | ); |
---|
777 | } |
---|
778 | //----------------------------------------------------------------------- |
---|
779 | String BorderPanelOverlayElement::CmdBorderTopUV::doGet(const void* target) const |
---|
780 | { |
---|
781 | // No need right now.. |
---|
782 | return static_cast<const BorderPanelOverlayElement*>(target)->getTopBorderUVString(); |
---|
783 | } |
---|
784 | void BorderPanelOverlayElement::CmdBorderTopUV::doSet(void* target, const String& val) |
---|
785 | { |
---|
786 | std::vector<String> vec = StringUtil::split(val); |
---|
787 | |
---|
788 | static_cast<BorderPanelOverlayElement*>(target)->setTopBorderUV( |
---|
789 | StringConverter::parseReal(vec[0]), |
---|
790 | StringConverter::parseReal(vec[1]), |
---|
791 | StringConverter::parseReal(vec[2]), |
---|
792 | StringConverter::parseReal(vec[3]) |
---|
793 | ); |
---|
794 | } |
---|
795 | //----------------------------------------------------------------------- |
---|
796 | String BorderPanelOverlayElement::CmdBorderBottomUV::doGet(const void* target) const |
---|
797 | { |
---|
798 | // No need right now.. |
---|
799 | return static_cast<const BorderPanelOverlayElement*>(target)->getBottomBorderUVString(); |
---|
800 | } |
---|
801 | void BorderPanelOverlayElement::CmdBorderBottomUV::doSet(void* target, const String& val) |
---|
802 | { |
---|
803 | std::vector<String> vec = StringUtil::split(val); |
---|
804 | |
---|
805 | static_cast<BorderPanelOverlayElement*>(target)->setBottomBorderUV( |
---|
806 | StringConverter::parseReal(vec[0]), |
---|
807 | StringConverter::parseReal(vec[1]), |
---|
808 | StringConverter::parseReal(vec[2]), |
---|
809 | StringConverter::parseReal(vec[3]) |
---|
810 | ); |
---|
811 | } |
---|
812 | //--------------------------------------------------------------------- |
---|
813 | const String& BorderPanelOverlayElement::getTypeName(void) const |
---|
814 | { |
---|
815 | return msTypeName; |
---|
816 | } |
---|
817 | |
---|
818 | |
---|
819 | |
---|
820 | } |
---|
821 | |
---|