44 #include <OgreVector3.h> 45 #include <OgreQuaternion.h> 47 #include <OgreCamera.h> 48 #include <OgreSceneNode.h> 49 #include <OgreMaterialManager.h> 50 #include <OgreHardwareBufferManager.h> 51 #include <Overlay/OgreFontManager.h> 52 #include <Overlay/OgreFont.h> 53 #include <OgreUTFString.h> 59 #define POS_TEX_BINDING 0 60 #define COLOUR_BINDING 1 64 MovableText::MovableText(
const String& caption,
65 const String& fontName,
67 const ColourValue& color)
69 , mType(
"MovableText")
71 , mHorizontalAlignment(H_LEFT)
72 , mVerticalAlignment(V_BELOW)
74 , mCharHeight(charHeight)
79 , mTimeUntilNextToggle(0)
80 , mGlobalTranslation(0.0)
81 , mLocalTranslation(0.0)
88 ss <<
"MovableText" << count++;
102 MaterialManager::getSingletonPtr()->remove(
mpMaterial->getName());
107 if ((Ogre::MaterialManager::getSingletonPtr()->resourceExists(
mName +
"Material")))
109 Ogre::MaterialManager::getSingleton().remove(
mName +
"Material");
115 mpFont = (Font*)FontManager::getSingleton().getByName(
mFontName).getPointer();
117 throw Exception(Exception::ERR_ITEM_NOT_FOUND,
"Could not find font " + fontName,
118 "MovableText::setFontName");
121 mpFont->addCodePointRange(std::make_pair<Ogre::Font::CodePoint>(0, 999));
125 MaterialManager::getSingletonPtr()->remove(
mpMaterial->getName());
224 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;
457 mAABB = Ogre::AxisAlignedBox(min, max);
459 Ogre::Math::Sqrt(std::max(
mAABB.getMinimum().squaredLength(),
mAABB.getMaximum().squaredLength()));
474 Root::getSingleton().convertColourValue(
mColor, &color);
475 HardwareVertexBufferSharedPtr vbuf =
477 RGBA* pDest =
static_cast<RGBA*
>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
478 for (
int i = 0; i < (int)
mRenderOp.vertexData->vertexCount; ++i)
487 return const_cast<Quaternion&
>(
mpCam->getDerivedOrientation());
490 #if ((OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 6) || OGRE_VERSION_MAJOR >= 2) 491 void MovableText::visitRenderables(Ogre::Renderable::Visitor* visitor,
bool )
493 visitor->visit(
this, 0,
false);
500 return mParentNode->_getDerivedPosition();
507 Matrix3 rot3x3, scale3x3 = Matrix3::IDENTITY;
510 mpCam->getDerivedOrientation().ToRotationMatrix(rot3x3);
517 scale3x3[0][0] = mParentNode->_getDerivedScale().x;
518 scale3x3[1][1] = mParentNode->_getDerivedScale().y;
519 scale3x3[2][2] = mParentNode->_getDerivedScale().z;
522 *xform = (rot3x3 * scale3x3);
523 xform->setTrans(ppos);
553 queue->addRenderable(
this, mRenderQueueID, OGRE_RENDERABLE_DEFAULT_PRIORITY);
void getWorldTransforms(Ogre::Matrix4 *xform) const override
void showOnTop(bool show=true)
const Ogre::Quaternion & getWorldOrientation() const
void setGlobalTranslation(Ogre::Vector3 trans)
Ogre::RenderOperation mRenderOp
Ogre::AxisAlignedBox mAABB
void setCharacterHeight(Ogre::Real height)
void setLocalTranslation(Ogre::Vector3 trans)
void getRenderOperation(Ogre::RenderOperation &op) override
void _notifyCurrentCamera(Ogre::Camera *cam) override
VerticalAlignment mVerticalAlignment
Ogre::Vector3 mGlobalTranslation
HorizontalAlignment mHorizontalAlignment
void setCaption(const Ogre::String &caption)
void setSpaceWidth(Ogre::Real width)
double min(double a, double b)
void setTextAlignment(const HorizontalAlignment &horizontalAlignment, const VerticalAlignment &verticalAlignment)
void setLineSpacing(Ogre::Real height)
void setColor(const Ogre::ColourValue &color)
Ogre::Vector3 mLocalTranslation
Ogre::MaterialPtr mpMaterial
bool isVisible(PanelDockWidget *widget)
void setFontName(const Ogre::String &fontName)
void _updateRenderQueue(Ogre::RenderQueue *queue) override
double max(double a, double b)
const Ogre::Vector3 & getWorldPosition() const