46 #include <OgreQuaternion.h>
48 #include <OgreCamera.h>
49 #include <OgreSceneNode.h>
50 #include <OgreMaterialManager.h>
51 #include <OgreHardwareBufferManager.h>
52 #include <Overlay/OgreFontManager.h>
53 #include <Overlay/OgreFont.h>
54 #if (OGRE_VERSION < OGRE_VERSION_CHECK(13, 0, 0))
55 #include <OgreUTFString.h>
62 #define POS_TEX_BINDING 0
63 #define COLOUR_BINDING 1
67 MovableText::MovableText(
const String& caption,
68 const String& fontName,
70 const ColourValue& color)
72 , mType(
"MovableText")
74 , mHorizontalAlignment(H_LEFT)
75 , mVerticalAlignment(V_BELOW)
77 , mCharHeight(charHeight)
82 , mTimeUntilNextToggle(0)
83 , mGlobalTranslation(0.0)
84 , mLocalTranslation(0.0)
91 ss <<
"MovableText" << count++;
103 MaterialManager::getSingletonPtr()->remove(
mpMaterial->getName());
111 mpFont =
static_cast<Font*
>(
112 FontManager::getSingleton()
113 .getByName(
mFontName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
116 throw Exception(Exception::ERR_ITEM_NOT_FOUND,
"Could not find font " + fontName,
117 "MovableText::setFontName");
120 mpFont->addCodePointRange(std::make_pair<Ogre::Font::CodePoint>(0, 999));
124 MaterialManager::getSingletonPtr()->remove(
mpMaterial->getName());
220 #if (OGRE_VERSION >= OGRE_VERSION_CHECK(13, 0, 0))
223 Ogre::UTFString::utf32string utfCaption(Ogre::UTFString(
mCaption).asUTF32());
229 unsigned int vertexCount = 0;
232 for (
auto ch : utfCaption)
234 if ((ch !=
' ') && (ch !=
'\n'))
247 if (vertexCount == 0)
257 mRenderOp.vertexData->vertexCount = vertexCount;
258 mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
261 VertexDeclaration* decl =
mRenderOp.vertexData->vertexDeclaration;
262 VertexBufferBinding* bind =
mRenderOp.vertexData->vertexBufferBinding;
266 if (!decl->findElementBySemantic(VES_POSITION))
269 offset += VertexElement::getTypeSize(VET_FLOAT3);
271 if (!decl->findElementBySemantic(VES_TEXTURE_COORDINATES))
272 decl->addElement(
POS_TEX_BINDING, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
274 HardwareVertexBufferSharedPtr ptbuf =
275 HardwareBufferManager::getSingleton().createVertexBuffer(decl->getVertexSize(
POS_TEX_BINDING),
277 HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
281 if (!decl->findElementBySemantic(VES_DIFFUSE))
284 HardwareVertexBufferSharedPtr cbuf =
285 HardwareBufferManager::getSingleton().createVertexBuffer(decl->getVertexSize(
COLOUR_BINDING),
287 HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
290 float* pPCBuff =
static_cast<float*
>(ptbuf->lock(HardwareBuffer::HBL_DISCARD));
298 float total_width = 0.0f;
299 float current_width = 0.0f;
300 for (
auto ch : utfCaption)
306 if (current_width > total_width)
308 total_width = current_width;
314 current_width += spaceWidth;
322 if (current_width > total_width)
324 total_width = current_width;
334 top = 0.5 * total_height;
341 float starting_left = 0.0f;
345 starting_left = 0.0f;
348 starting_left = -total_width / 2.0f;
352 float left = starting_left;
355 Ogre::Vector3 currPos(0.0
f);
356 Ogre::Vector3
min(starting_left, top - total_height, 0.0
f);
357 Ogre::Vector3 max(starting_left + total_width, top, 0.0
f);
358 auto iend = utfCaption.end();
359 for (
auto i = utfCaption.begin(); i != iend; ++i)
363 left = starting_left;
377 Ogre::Font::UVRect utmp;
378 utmp =
mpFont->getGlyphTexCoords(*i);
389 currPos = Ogre::Vector3(left, top, 0.0);
391 *pPCBuff++ = currPos.x;
392 *pPCBuff++ = currPos.y;
393 *pPCBuff++ = currPos.z;
400 currPos = Ogre::Vector3(left, top, 0.0);
401 *pPCBuff++ = currPos.x;
402 *pPCBuff++ = currPos.y;
403 *pPCBuff++ = currPos.z;
411 currPos = Ogre::Vector3(left, top, 0.0);
412 *pPCBuff++ = currPos.x;
413 *pPCBuff++ = currPos.y;
414 *pPCBuff++ = currPos.z;
422 currPos = Ogre::Vector3(left, top, 0.0);
423 *pPCBuff++ = currPos.x;
424 *pPCBuff++ = currPos.y;
425 *pPCBuff++ = currPos.z;
433 currPos = Ogre::Vector3(left, top, 0.0);
434 *pPCBuff++ = currPos.x;
435 *pPCBuff++ = currPos.y;
436 *pPCBuff++ = currPos.z;
443 currPos = Ogre::Vector3(left, top, 0.0);
444 *pPCBuff++ = currPos.x;
445 *pPCBuff++ = currPos.y;
446 *pPCBuff++ = currPos.z;
459 Ogre::Math::Sqrt(std::max(
mAABB.getMinimum().squaredLength(),
mAABB.getMaximum().squaredLength()));
475 Root::getSingleton().convertColourValue(
mColor, &color);
476 HardwareVertexBufferSharedPtr vbuf =
478 RGBA* pDest =
static_cast<RGBA*
>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
479 for (
int i = 0; i < (int)
mRenderOp.vertexData->vertexCount; ++i)
488 return const_cast<Quaternion&
>(
mpCam->getDerivedOrientation());
493 visitor->visit(
this, 0,
false);
499 return mParentNode->_getDerivedPosition();
504 if (this->isVisible() &&
mpCam)
506 Matrix3 rot3x3, scale3x3 = Matrix3::IDENTITY;
509 mpCam->getDerivedOrientation().ToRotationMatrix(rot3x3);
516 scale3x3[0][0] = mParentNode->_getDerivedScale().x;
517 scale3x3[1][1] = mParentNode->_getDerivedScale().y;
518 scale3x3[2][2] = mParentNode->_getDerivedScale().z;
521 *xform = (rot3x3 * scale3x3);
522 xform->setTrans(ppos);
528 if (this->isVisible())
544 #if OGRE_VERSION < OGRE_VERSION_CHECK(1, 11, 0)
546 m.makeTransform(Ogre::Vector3::ZERO, Ogre::Vector3::UNIT_SCALE,
mpCam->getDerivedOrientation());
550 m.makeTransform(Ogre::Vector3::ZERO, Ogre::Vector3::UNIT_SCALE,
mpCam->getDerivedOrientation());
557 if (this->isVisible())
564 queue->addRenderable(
this, mRenderQueueID, OGRE_RENDERABLE_DEFAULT_PRIORITY);