|
|
@ -4,10 +4,10 @@
|
|
|
|
#include <OgreMaterialManager.h>
|
|
|
|
#include <OgreMaterialManager.h>
|
|
|
|
#include <OgreTechnique.h>
|
|
|
|
#include <OgreTechnique.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <OGRE/Overlay/OgreOverlayManager.h>
|
|
|
|
#include <OgreOverlayManager.h>
|
|
|
|
#include <OGRE/Overlay/OgreOverlayContainer.h>
|
|
|
|
#include <OgreOverlayContainer.h>
|
|
|
|
#include <OGRE/Overlay/OgreFontManager.h>
|
|
|
|
#include <OgreFontManager.h>
|
|
|
|
#include <OGRE/Overlay/OgreTextAreaOverlayElement.h>
|
|
|
|
#include <OgreTextAreaOverlayElement.h>
|
|
|
|
#include <OgreEntity.h>
|
|
|
|
#include <OgreEntity.h>
|
|
|
|
#include <OgreViewport.h>
|
|
|
|
#include <OgreViewport.h>
|
|
|
|
#include <OgreRoot.h>
|
|
|
|
#include <OgreRoot.h>
|
|
|
@ -27,18 +27,19 @@ namespace CSVRender
|
|
|
|
// http://www.ogre3d.org/tikiwiki/Creating+dynamic+textures
|
|
|
|
// http://www.ogre3d.org/tikiwiki/Creating+dynamic+textures
|
|
|
|
// http://www.ogre3d.org/tikiwiki/ManualObject
|
|
|
|
// http://www.ogre3d.org/tikiwiki/ManualObject
|
|
|
|
TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* camera, const Ogre::String& id)
|
|
|
|
TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* camera, const Ogre::String& id)
|
|
|
|
: mOverlay(0), mCaption(""), mDesc(""), mEnabled(true), mCamera(camera), mObj(obj), mId(id), mOnScreen(false)
|
|
|
|
: mOverlay(0), mCaption(""), mDesc(""), mEnabled(true), mCamera(camera), mObj(obj), mId(id)
|
|
|
|
, mFontHeight(16) // FIXME: make font height configurable
|
|
|
|
, mOnScreen(false) , mInstance(0), mFontHeight(16) // FIXME: make font height configurable
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(id == "" || !camera || !obj)
|
|
|
|
if(id == "" || !camera || !obj)
|
|
|
|
throw std::runtime_error("TextOverlay could not be created.");
|
|
|
|
throw std::runtime_error("TextOverlay could not be created.");
|
|
|
|
|
|
|
|
|
|
|
|
// setup font
|
|
|
|
// setup font
|
|
|
|
if (Ogre::FontManager::getSingleton().resourceExists("DejaVuLGC"))
|
|
|
|
Ogre::FontManager &fontMgr = Ogre::FontManager::getSingleton();
|
|
|
|
mFont = Ogre::FontManager::getSingleton().getByName("DejaVuLGC","General");
|
|
|
|
if (fontMgr.resourceExists("DejaVuLGC"))
|
|
|
|
|
|
|
|
mFont = fontMgr.getByName("DejaVuLGC","General");
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mFont = Ogre::FontManager::getSingleton().create("DejaVuLGC","General");
|
|
|
|
mFont = fontMgr.create("DejaVuLGC","General");
|
|
|
|
mFont->setType(Ogre::FT_TRUETYPE);
|
|
|
|
mFont->setType(Ogre::FT_TRUETYPE);
|
|
|
|
mFont->setSource("DejaVuLGCSansMono.ttf");
|
|
|
|
mFont->setSource("DejaVuLGCSansMono.ttf");
|
|
|
|
mFont->setTrueTypeSize(mFontHeight);
|
|
|
|
mFont->setTrueTypeSize(mFontHeight);
|
|
|
@ -51,9 +52,13 @@ TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* cam
|
|
|
|
|
|
|
|
|
|
|
|
// setup overlay
|
|
|
|
// setup overlay
|
|
|
|
Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton();
|
|
|
|
Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton();
|
|
|
|
mOverlay = overlayMgr.getByName("CellIDPanel");
|
|
|
|
mOverlay = overlayMgr.getByName("CellIDPanel"+mId+Ogre::StringConverter::toString(mInstance));
|
|
|
|
if(!mOverlay)
|
|
|
|
while(mOverlay != NULL)
|
|
|
|
mOverlay = overlayMgr.create("CellIDPanel");
|
|
|
|
{
|
|
|
|
|
|
|
|
mInstance++;
|
|
|
|
|
|
|
|
mOverlay = overlayMgr.getByName("CellIDPanel"+mId+Ogre::StringConverter::toString(mInstance));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mOverlay = overlayMgr.create("CellIDPanel"+mId+Ogre::StringConverter::toString(mInstance));
|
|
|
|
|
|
|
|
|
|
|
|
// create texture
|
|
|
|
// create texture
|
|
|
|
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName("DynamicTransBlue");
|
|
|
|
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName("DynamicTransBlue");
|
|
|
@ -93,7 +98,12 @@ TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* cam
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// setup material for containers
|
|
|
|
// setup material for containers
|
|
|
|
Ogre::MaterialPtr mQuadMaterial = Ogre::MaterialManager::getSingleton().create("TransOverlayMaterial",
|
|
|
|
Ogre::MaterialPtr mQuadMaterial = Ogre::MaterialManager::getSingleton().getByName(
|
|
|
|
|
|
|
|
"TransOverlayMaterial");
|
|
|
|
|
|
|
|
if(mQuadMaterial.isNull())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Ogre::MaterialPtr mQuadMaterial = Ogre::MaterialManager::getSingleton().create(
|
|
|
|
|
|
|
|
"TransOverlayMaterial",
|
|
|
|
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true );
|
|
|
|
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true );
|
|
|
|
Ogre::Pass *pass = mQuadMaterial->getTechnique( 0 )->getPass( 0 );
|
|
|
|
Ogre::Pass *pass = mQuadMaterial->getTechnique( 0 )->getPass( 0 );
|
|
|
|
pass->setLightingEnabled( false );
|
|
|
|
pass->setLightingEnabled( false );
|
|
|
@ -104,13 +114,16 @@ TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* cam
|
|
|
|
tex->setTextureName("DynamicTransBlue");
|
|
|
|
tex->setTextureName("DynamicTransBlue");
|
|
|
|
tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC );
|
|
|
|
tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC );
|
|
|
|
mQuadMaterial->load();
|
|
|
|
mQuadMaterial->load();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mContainer = static_cast<Ogre::OverlayContainer*>(overlayMgr.createOverlayElement("Panel", "container"+mId));
|
|
|
|
mContainer = static_cast<Ogre::OverlayContainer*>(overlayMgr.createOverlayElement(
|
|
|
|
|
|
|
|
"Panel", "container"+mId +"#"+Ogre::StringConverter::toString(mInstance)));
|
|
|
|
mContainer->setMaterialName("TransOverlayMaterial");
|
|
|
|
mContainer->setMaterialName("TransOverlayMaterial");
|
|
|
|
mOverlay->add2D(mContainer);
|
|
|
|
mOverlay->add2D(mContainer);
|
|
|
|
|
|
|
|
|
|
|
|
// setup text area overlay element
|
|
|
|
// setup text area overlay element
|
|
|
|
mElement = static_cast<Ogre::TextAreaOverlayElement*>(overlayMgr.createOverlayElement("TextArea", "text"+mId));
|
|
|
|
mElement = static_cast<Ogre::TextAreaOverlayElement*>(overlayMgr.createOverlayElement(
|
|
|
|
|
|
|
|
"TextArea", "text"+mId +"#"+Ogre::StringConverter::toString(mInstance)));
|
|
|
|
mElement->setMetricsMode(Ogre::GMM_RELATIVE);
|
|
|
|
mElement->setMetricsMode(Ogre::GMM_RELATIVE);
|
|
|
|
mElement->setDimensions(1.0, 1.0);
|
|
|
|
mElement->setDimensions(1.0, 1.0);
|
|
|
|
mElement->setMetricsMode(Ogre::GMM_PIXELS);
|
|
|
|
mElement->setMetricsMode(Ogre::GMM_PIXELS);
|
|
|
@ -197,10 +210,8 @@ TextOverlay::~TextOverlay()
|
|
|
|
mOverlay->hide();
|
|
|
|
mOverlay->hide();
|
|
|
|
|
|
|
|
|
|
|
|
Ogre::OverlayManager *overlayMgr = Ogre::OverlayManager::getSingletonPtr();
|
|
|
|
Ogre::OverlayManager *overlayMgr = Ogre::OverlayManager::getSingletonPtr();
|
|
|
|
mContainer->removeChild("text"+mId);
|
|
|
|
mContainer->removeChild("text"+mId+"#"+Ogre::StringConverter::toString(mInstance));
|
|
|
|
mOverlay->remove2D(mContainer);
|
|
|
|
mOverlay->remove2D(mContainer);
|
|
|
|
overlayMgr->destroyOverlayElement(mElement);
|
|
|
|
|
|
|
|
overlayMgr->destroyOverlayElement(mContainer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!iter.hasMoreElements())
|
|
|
|
if(!iter.hasMoreElements())
|
|
|
|
overlayMgr->destroy(mOverlay);
|
|
|
|
overlayMgr->destroy(mOverlay);
|
|
|
@ -208,14 +219,14 @@ TextOverlay::~TextOverlay()
|
|
|
|
|
|
|
|
|
|
|
|
void TextOverlay::enable(bool enable)
|
|
|
|
void TextOverlay::enable(bool enable)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(enable == mContainer->isVisible())
|
|
|
|
if(enable == mOverlay->isVisible())
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
mEnabled = enable;
|
|
|
|
mEnabled = enable;
|
|
|
|
if (enable)
|
|
|
|
if (enable)
|
|
|
|
mContainer->show();
|
|
|
|
mOverlay->show();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
mContainer->hide();
|
|
|
|
mOverlay->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TextOverlay::isEnabled()
|
|
|
|
bool TextOverlay::isEnabled()
|
|
|
@ -282,7 +293,6 @@ void TextOverlay::update()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mOnScreen = false;
|
|
|
|
mOnScreen = false;
|
|
|
|
mContainer->hide();
|
|
|
|
mContainer->hide();
|
|
|
|
Ogre::Root::getSingleton().renderOneFrame();
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -306,8 +316,6 @@ void TextOverlay::update()
|
|
|
|
mContainer->setDimensions(relTextWidth, relTextHeight);
|
|
|
|
mContainer->setDimensions(relTextWidth, relTextHeight);
|
|
|
|
|
|
|
|
|
|
|
|
mPos = QRect(posX*viewportWidth, posY*viewportHeight, width, height);
|
|
|
|
mPos = QRect(posX*viewportWidth, posY*viewportHeight, width, height);
|
|
|
|
|
|
|
|
|
|
|
|
Ogre::Root::getSingleton().renderOneFrame();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QRect TextOverlay::container()
|
|
|
|
QRect TextOverlay::container()
|
|
|
|