Various fixes as per feedback comments.

pull/300/head
cc9cii 10 years ago
parent 809b8c6d5b
commit 758ce0ed98

@ -272,7 +272,8 @@ endif ()
endif(OGRE_STATIC) endif(OGRE_STATIC)
include_directories("." include_directories("."
${OGRE_INCLUDE_DIR} ${OGRE_INCLUDE_DIR}/Ogre ${OGRE_INCLUDE_DIR}/OGRE ${OGRE_INCLUDE_DIRS} ${OGRE_PLUGIN_INCLUDE_DIRS} ${OGRE_INCLUDE_DIR}/Overlay ${OGRE_INCLUDE_DIR} ${OGRE_INCLUDE_DIR}/Ogre ${OGRE_INCLUDE_DIR}/OGRE ${OGRE_INCLUDE_DIRS} ${OGRE_PLUGIN_INCLUDE_DIRS}
${OGRE_INCLUDE_DIR}/Ogre/Overlay ${OGRE_INCLUDE_DIR}/OGRE/Overlay ${OGRE_Overlay_INCLUDE_DIRS}
${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR}
${Boost_INCLUDE_DIR} ${Boost_INCLUDE_DIR}
${PLATFORM_INCLUDE_DIR} ${PLATFORM_INCLUDE_DIR}

@ -8,13 +8,13 @@
#include <OgreCamera.h> #include <OgreCamera.h>
#include <OgreSceneManager.h> #include <OgreSceneManager.h>
#include <OgreManualObject.h> #include <OgreManualObject.h>
#include <OGRE/Overlay/OgreOverlayContainer.h> #include <OgreOverlayContainer.h>
#include <OGRE/Overlay/OgreOverlayManager.h> #include <OgreOverlayManager.h>
#include <OgreRoot.h> #include <OgreRoot.h>
#include <OgreSceneQuery.h> #include <OgreSceneQuery.h>
#include <OgreEntity.h> #include <OgreEntity.h>
#include "../../../../components/esm/loadland.hpp" #include <components/esm/loadland.hpp>
#include "textoverlay.hpp" #include "textoverlay.hpp"
#include "../../model/world/tablemimedata.hpp" #include "../../model/world/tablemimedata.hpp"
@ -195,24 +195,13 @@ void CSVRender::PagedWorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event
void CSVRender::PagedWorldspaceWidget::updateOverlay() void CSVRender::PagedWorldspaceWidget::updateOverlay()
{ {
Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton(); if(getCamera()->getViewport())
Ogre::Overlay* overlay = overlayMgr.getByName("CellIDPanel");
if(overlay && !mTextOverlays.empty())
{ {
if(getCamera()->getViewport()) if((uint32_t)getCamera()->getViewport()->getVisibilityMask()
{ & (uint32_t)CSVRender::Element_CellMarker)
if((uint32_t)getCamera()->getViewport()->getVisibilityMask() mDisplayCellCoord = true;
& (uint32_t)CSVRender::Element_CellMarker) else
{ mDisplayCellCoord = false;
mDisplayCellCoord = true;
overlay->show();
}
else
{
mDisplayCellCoord = false;
overlay->hide();
}
}
} }
if(!mTextOverlays.empty()) if(!mTextOverlays.empty())
@ -220,6 +209,7 @@ void CSVRender::PagedWorldspaceWidget::updateOverlay()
std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator it = mTextOverlays.begin(); std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator it = mTextOverlays.begin();
for(; it != mTextOverlays.end(); ++it) for(; it != mTextOverlays.end(); ++it)
{ {
it->second->enable(mDisplayCellCoord);
it->second->update(); it->second->update();
} }
} }
@ -324,14 +314,21 @@ CSVRender::PagedWorldspaceWidget::~PagedWorldspaceWidget()
{ {
delete iter->second; delete iter->second;
std::map<CSMWorld::CellCoordinates, Ogre::Entity *>::iterator it = mEntities.find(iter->first);
if(it != mEntities.end())
{
getSceneManager()->destroyEntity(it->second);
mEntities.erase(it);
}
getSceneManager()->destroyManualObject("manual"+iter->first.getId(mWorldspace)); getSceneManager()->destroyManualObject("manual"+iter->first.getId(mWorldspace));
} }
for (std::map<CSMWorld::CellCoordinates, Ogre::Entity *>::iterator iter (mEntities.begin());
iter != mEntities.end(); ++iter)
{
getSceneManager()->destroyEntity(iter->second);
mEntities.erase(iter);
}
for (std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator iter (mTextOverlays.begin());
iter != mTextOverlays.end(); ++iter)
{
delete iter->second;
}
} }
void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint) void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)

@ -11,7 +11,7 @@
#include <OgreCamera.h> #include <OgreCamera.h>
#include <OgreSceneNode.h> #include <OgreSceneNode.h>
#include <OgreViewport.h> #include <OgreViewport.h>
#include <OGRE/Overlay/OgreOverlaySystem.h> #include <OgreOverlaySystem.h>
#include "../widget/scenetoolmode.hpp" #include "../widget/scenetoolmode.hpp"
#include "../../model/settings/usersettings.hpp" #include "../../model/settings/usersettings.hpp"
@ -21,6 +21,8 @@
namespace CSVRender namespace CSVRender
{ {
Ogre::OverlaySystem *SceneWidget::mOverlaySystem = NULL;
SceneWidget::SceneWidget(QWidget *parent) SceneWidget::SceneWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, mCamera(NULL) , mCamera(NULL)
@ -60,7 +62,8 @@ namespace CSVRender
setLighting (&mLightingDay); setLighting (&mLightingDay);
Ogre::OverlaySystem *mOverlaySystem = new Ogre::OverlaySystem(); if(!mOverlaySystem)
mOverlaySystem = new Ogre::OverlaySystem();
mSceneMgr->addRenderQueueListener(mOverlaySystem); mSceneMgr->addRenderQueueListener(mOverlaySystem);
QTimer *timer = new QTimer (this); QTimer *timer = new QTimer (this);
@ -164,11 +167,8 @@ namespace CSVRender
if (mWindow) if (mWindow)
Ogre::Root::getSingleton().destroyRenderTarget (mWindow); Ogre::Root::getSingleton().destroyRenderTarget (mWindow);
if (mOverlaySystem) if (mSceneMgr)
{ mSceneMgr->removeRenderQueueListener (mOverlaySystem);
if (mSceneMgr)
mSceneMgr->removeRenderQueueListener (mOverlaySystem);
}
if (mSceneMgr) if (mSceneMgr)
Ogre::Root::getSingleton().destroySceneManager (mSceneMgr); Ogre::Root::getSingleton().destroySceneManager (mSceneMgr);

@ -90,7 +90,7 @@ namespace CSVRender
Ogre::SceneManager* mSceneMgr; Ogre::SceneManager* mSceneMgr;
Ogre::RenderWindow* mWindow; Ogre::RenderWindow* mWindow;
Ogre::Viewport *mViewport; Ogre::Viewport *mViewport;
Ogre::OverlaySystem *mOverlaySystem; static Ogre::OverlaySystem *mOverlaySystem;
Navigation *mNavigation; Navigation *mNavigation;
Lighting *mLighting; Lighting *mLighting;

@ -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,24 +98,32 @@ 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(
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true ); "TransOverlayMaterial");
Ogre::Pass *pass = mQuadMaterial->getTechnique( 0 )->getPass( 0 ); if(mQuadMaterial.isNull())
pass->setLightingEnabled( false ); {
pass->setDepthWriteEnabled( false ); Ogre::MaterialPtr mQuadMaterial = Ogre::MaterialManager::getSingleton().create(
pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA ); "TransOverlayMaterial",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true );
Ogre::TextureUnitState *tex = pass->createTextureUnitState("MyCustomState", 0); Ogre::Pass *pass = mQuadMaterial->getTechnique( 0 )->getPass( 0 );
tex->setTextureName("DynamicTransBlue"); pass->setLightingEnabled( false );
tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC ); pass->setDepthWriteEnabled( false );
mQuadMaterial->load(); pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
mContainer = static_cast<Ogre::OverlayContainer*>(overlayMgr.createOverlayElement("Panel", "container"+mId)); Ogre::TextureUnitState *tex = pass->createTextureUnitState("MyCustomState", 0);
tex->setTextureName("DynamicTransBlue");
tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC );
mQuadMaterial->load();
}
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()

@ -4,7 +4,7 @@
#include <QRect> #include <QRect>
#include <OgreString.h> #include <OgreString.h>
#include <OGRE/Overlay/OgreFont.h> #include <OgreFont.h>
namespace Ogre namespace Ogre
{ {
@ -36,6 +36,7 @@ namespace CSVRender
bool mEnabled; bool mEnabled;
bool mOnScreen; // not used bool mOnScreen; // not used
int mInstance;
Ogre::FontPtr getFont(); Ogre::FontPtr getFont();
int textWidth(); int textWidth();

@ -364,6 +364,9 @@ macro(ogre_find_component COMPONENT HEADER)
make_library_set(OGRE_${COMPONENT}_LIBRARY) make_library_set(OGRE_${COMPONENT}_LIBRARY)
findpkg_finish(OGRE_${COMPONENT}) findpkg_finish(OGRE_${COMPONENT})
if (OGRE_${COMPONENT}_FOUND) if (OGRE_${COMPONENT}_FOUND)
if (OGRE_${COMPONENT}_INCLUDE_DIR)
set(OGRE_${COMPONENT}_INCLUDE_DIRS ${OGRE_${COMPONENT}_INCLUDE_DIR})
endif()
# find binaries # find binaries
if (NOT OGRE_STATIC) if (NOT OGRE_STATIC)
if (WIN32) if (WIN32)

Loading…
Cancel
Save