29 #include <Overlay/OgreFontManager.h>
34 #define POS_TEX_BINDING 0
35 #define COLOUR_BINDING 1
37 MovableText::MovableText(
const UTFString& name,
const UTFString& caption,
const UTFString& fontName, Real charHeight,
const ColourValue& color)
44 , mCharHeight(charHeight)
46 , mType(
"MovableText")
47 , mTimeUntilNextToggle(0)
51 , mHorizontalAlignment(H_LEFT)
52 , mVerticalAlignment(V_BELOW)
53 , mAdditionalHeight(0.0)
56 throw Exception(Exception::ERR_INVALIDPARAMS,
"Trying to create MovableText without name",
"MovableText::MovableText");
75 if ((Ogre::MaterialManager::getSingletonPtr()->resourceExists(
mName +
"Material")))
77 Ogre::MaterialManager::getSingleton().remove(
mName +
"Material");
83 mpFont = (Ogre::Font *)FontManager::getSingleton().getResourceByName(
mFontName).getPointer();
86 throw Exception(Exception::ERR_ITEM_NOT_FOUND,
"Could not find font " + fontName,
"MovableText::setFontName");
91 MaterialManager::getSingletonPtr()->remove(
mpMaterial->getName());
183 uint vertexCount =
static_cast<uint
>(
mCaption.size() * 6);
203 mRenderOp.vertexData->vertexCount = vertexCount;
204 mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
207 VertexDeclaration* decl =
mRenderOp.vertexData->vertexDeclaration;
208 VertexBufferBinding* bind =
mRenderOp.vertexData->vertexBufferBinding;
212 if (!decl->findElementBySemantic(VES_POSITION))
215 offset += VertexElement::getTypeSize(VET_FLOAT3);
217 if (!decl->findElementBySemantic(VES_TEXTURE_COORDINATES))
218 decl->addElement(
POS_TEX_BINDING, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
220 HardwareVertexBufferSharedPtr ptbuf = HardwareBufferManager::getSingleton().createVertexBuffer(decl->getVertexSize(
POS_TEX_BINDING),
222 HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
226 if (!decl->findElementBySemantic(VES_DIFFUSE))
229 HardwareVertexBufferSharedPtr cbuf = HardwareBufferManager::getSingleton().createVertexBuffer(decl->getVertexSize(
COLOUR_BINDING),
231 HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
235 Real* pPCBuff = (Real*)malloc(ptbuf->getSizeInBytes());
236 Real* oPCBuff = pPCBuff;
238 float largestWidth = 0;
239 float left = 0 * 2.0 - 1.0;
240 float top = -((0 * 2.0) - 1.0);
247 Ogre::Vector3 min = Ogre::Vector3::ZERO, max = Ogre::Vector3::ZERO, currPos = Ogre::Vector3::ZERO;
248 Ogre::Real maxSquaredRadius = 0.0f;
252 UTFString::iterator i, iend;
261 for (i =
mCaption.begin(); i != iend; ++i)
268 for (i =
mCaption.begin(); i != iend; ++i)
273 for (UTFString::iterator j = i; j != iend && *j !=
'\n'; j++)
285 left = 0 * 2.0 - 1.0;
300 Real horiz_height =
mpFont->getGlyphAspectRatio(*i);
302 Ogre::Font::UVRect utmp;
303 utmp =
mpFont->getGlyphTexCoords(*i);
317 *pPCBuff++ = left - (len / 2);
325 currPos = Ogre::Vector3(left, top, -1.0);
327 currPos = Ogre::Vector3(left - (len / 2), top, -1.0);
331 maxSquaredRadius = currPos.squaredLength();
336 min.makeFloor(currPos);
337 max.makeCeil(currPos);
338 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
347 *pPCBuff++ = left - (len / 2);
355 currPos = Ogre::Vector3(left, top, -1.0);
357 currPos = Ogre::Vector3(left - (len / 2), top, -1.0);
358 min.makeFloor(currPos);
359 max.makeCeil(currPos);
360 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
369 *pPCBuff++ = left - (len / 2);
378 currPos = Ogre::Vector3(left, top, -1.0);
380 currPos = Ogre::Vector3(left - (len / 2), top, -1.0);
381 min.makeFloor(currPos);
382 max.makeCeil(currPos);
383 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
392 *pPCBuff++ = left - (len / 2);
398 currPos = Ogre::Vector3(left, top, -1.0);
399 min.makeFloor(currPos);
400 max.makeCeil(currPos);
401 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
410 *pPCBuff++ = left - (len / 2);
416 currPos = Ogre::Vector3(left, top, -1.0);
417 min.makeFloor(currPos);
418 max.makeCeil(currPos);
419 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
427 *pPCBuff++ = left - (len / 2);
434 currPos = Ogre::Vector3(left, top, -1.0);
435 min.makeFloor(currPos);
436 max.makeCeil(currPos);
437 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
442 float currentWidth = (left + 1) / 2 - 0;
443 if (currentWidth > largestWidth)
444 largestWidth = currentWidth;
449 ptbuf->writeData(0, ptbuf->getSizeInBytes(), oPCBuff,
true);
453 mAABB = Ogre::AxisAlignedBox(min, max);
454 mRadius = Ogre::Math::Sqrt(maxSquaredRadius);
469 Root::getSingleton().convertColourValue(
mColor, &color);
472 RGBA* pDest = (RGBA*)malloc(vbuf->getSizeInBytes());
474 for (uint i = 0; i <
mRenderOp.vertexData->vertexCount; ++i)
477 vbuf->writeData(0, vbuf->getSizeInBytes(), oDest,
true);
485 return const_cast<Quaternion&
>(
mpCam->getDerivedOrientation());
491 return mParentNode->_getDerivedPosition();
496 if (this->isVisible() &&
mpCam)
498 Matrix3 rot3x3, scale3x3 = Matrix3::IDENTITY;
501 mpCam->getDerivedOrientation().ToRotationMatrix(rot3x3);
504 Vector3 ppos = mParentNode->_getDerivedPosition() + Vector3::UNIT_Y *
mAdditionalHeight;
507 scale3x3[0][0] = mParentNode->_getDerivedScale().x / 2;
508 scale3x3[1][1] = mParentNode->_getDerivedScale().y / 2;
509 scale3x3[2][2] = mParentNode->_getDerivedScale().z / 2;
512 *xform = (rot3x3 * scale3x3);
513 xform->setTrans(ppos);
519 if (this->isVisible())
536 if (this->isVisible())
543 queue->addRenderable(
this, mRenderQueueID, OGRE_RENDERABLE_DEFAULT_PRIORITY);