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