Visibility mask implemented. For testing rigged up 'M' and 'N' keys for show/hide.

The scenewidget doesn't receive any mouse events for about a second after toggling the visibility flag.  No idea what is causing this.
loadfix
cc9cii 10 years ago
parent dbb2781817
commit e38417e662

@ -8,8 +8,10 @@
#include <OgreCamera.h>
#include <OgreSceneManager.h>
#include <OgreManualObject.h>
#include <Overlay/OgreOverlayContainer.h> // FIXME
#include <OgreSceneQuery.h> // FIXME
#include <Overlay/OgreOverlayContainer.h>
#include <Overlay/OgreOverlayManager.h>
#include <OgreRoot.h>
#include <OgreSceneQuery.h>
#include <OgreEntity.h>
#include "../../../../components/esm/loadland.hpp"
@ -115,32 +117,88 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
{
//std::cout << "Qt x: " + std::to_string(event->x()) << ", y: " + std::to_string(event->y()) << std::endl;
std::list<TextOverlay *>::iterator iter = mTextOverlays.begin();
for(; iter != mTextOverlays.end(); ++iter)
{
if(mDisplayCellCoord &&
(*iter)->isEnabled() && (*iter)->container().contains(event->x(), event->y()))
{
std::cout << "clicked: " << (*iter)->getCaption() << std::endl;
//(*iter)->enable(false); // FIXME: for testing only
}
}
#if 0
// mouse picking
int viewportWidth = getCamera()->getViewport()->getActualWidth();
int viewportHeight = getCamera()->getViewport()->getActualHeight();
Ogre::Ray mouseRay = getCamera()->getCameraToViewportRay(event->x()/viewportWidth, event->y()/viewportHeight);
Ogre::Ray mouseRay = getCamera()->getCameraToViewportRay((float)(event->x()/viewportWidth),
(float)(event->y()/viewportHeight));
Ogre::RaySceneQuery *rayScnQuery = getSceneManager()->createRayQuery(Ogre::Ray());
rayScnQuery->setRay(mouseRay);
Ogre::RaySceneQueryResult &result = rayScnQuery->execute();
Ogre::RaySceneQueryResult::iterator it = result.begin();
rayScnQuery->setSortByDistance(true);
Ogre::RaySceneQueryResult result = rayScnQuery->execute();
std::list<TextOverlay *>::iterator iter = mTextOverlays.begin();
for(; iter != mTextOverlays.end(); ++iter)
Ogre::RaySceneQueryResult::iterator it = result.begin();
for (; it != result.end(); it++)
{
if((*iter)->isEnabled() && (*iter)->container().contains(event->x(), event->y()))
if(it->worldFragment)
{
std::cout << "clicked: " << (*iter)->getCaption() << std::endl;
(*iter)->enable(false);
// FIXME: just testing
std::string str;
if (it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_NONE)
str = "no world geometry hits";
else if (it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_PLANE_BOUNDED_REGION)
str = "pointers to convex plane-bounded regions";
else if (it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_SINGLE_INTERSECTION)
str = "single intersection point";
else if(it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_CUSTOM_GEOMETRY)
str = "custom geometry";
else if (it->worldFragment->fragmentType == Ogre::SceneQuery::WorldFragmentType::WFT_RENDER_OPERATION)
str = "general render operation structure";
std::cout << "fragment type: " << str << std::endl;
}
else if (it->movable)
{
// FIXME: just testing
it->movable->getParentSceneNode()->showBoundingBox(true);
std::cout << "movable object: " + it->movable->getName() << std::endl;
}
else
std::cout << "nothing: " << std::endl;
}
getSceneManager()->destroyQuery(rayScnQuery);
#endif
SceneWidget::mouseReleaseEvent(event);
}
void CSVRender::PagedWorldspaceWidget::updateOverlay()
{
Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton();
Ogre::Overlay* overlay = overlayMgr.getByName("CellIDPanel");
if(overlay && !mTextOverlays.empty())
{
if(getCamera()->getViewport())
{
if((uint32_t)getCamera()->getViewport()->getVisibilityMask()
& (uint32_t)CSVRender::Elements::Element_CellMarker)
{
mDisplayCellCoord = true;
overlay->show();
}
else
{
mDisplayCellCoord = false;
overlay->hide();
}
}
}
if(!mTextOverlays.empty())
{
std::list<CSVRender::TextOverlay *>::iterator it = mTextOverlays.begin();
@ -229,7 +287,8 @@ std::string CSVRender::PagedWorldspaceWidget::getStartupInstruction()
}
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc::Document& document)
: WorldspaceWidget(document, parent), mDocument(document), mWorldspace("std::default"), mTextOverlays(0)
: WorldspaceWidget(document, parent), mDocument(document), mWorldspace("std::default"), mDisplayCellCoord(true)
, mTextOverlays(0)
{
QAbstractItemModel *cells =
document.getData().getTableModel (CSMWorld::UniversalId::Type_Cells);

@ -22,6 +22,7 @@ namespace CSVRender
std::map<CSMWorld::CellCoordinates, Cell *> mCells;
std::string mWorldspace;
CSVWidget::SceneToolToggle *mControlElements;
bool mDisplayCellCoord;
std::list<TextOverlay *> mTextOverlays;
std::map<std::string, Ogre::Entity*> mEntities;

@ -18,6 +18,7 @@
#include "navigation.hpp"
#include "lighting.hpp"
#include "elements.hpp" // FIXME: for testing only
namespace CSVRender
{
@ -58,7 +59,7 @@ namespace CSVRender
setLighting (&mLightingDay);
Ogre::OverlaySystem *mOverlaySystem = new Ogre::OverlaySystem(); // FIXME: delete
Ogre::OverlaySystem *mOverlaySystem = new Ogre::OverlaySystem();
mSceneMgr->addRenderQueueListener(mOverlaySystem);
QTimer *timer = new QTimer (this);
@ -162,8 +163,17 @@ namespace CSVRender
if (mWindow)
Ogre::Root::getSingleton().destroyRenderTarget (mWindow);
if (mOverlaySystem)
{
if (mSceneMgr)
mSceneMgr->removeRenderQueueListener (mOverlaySystem);
delete mOverlaySystem;
}
if (mSceneMgr)
Ogre::Root::getSingleton().destroySceneManager (mSceneMgr);
}
void SceneWidget::setVisibilityMask (unsigned int mask)
@ -287,6 +297,20 @@ namespace CSVRender
break;
//FIXME: for testing only
case Qt::Key_N:
setVisibilityMask((uint32_t)mViewport->getVisibilityMask()
& ~(uint32_t)CSVRender::Elements::Element_CellMarker);
updateOverlay();
break;
//FIXME: for testing only
case Qt::Key_M:
setVisibilityMask((uint32_t)mViewport->getVisibilityMask()
| (uint32_t)CSVRender::Elements::Element_CellMarker);
updateOverlay();
break;
default: QWidget::keyReleaseEvent (event);
}
}

@ -15,6 +15,7 @@ namespace Ogre
class SceneManager;
class RenderWindow;
class Viewport;
class OverlaySystem;
}
namespace CSVWidget
@ -89,6 +90,7 @@ namespace CSVRender
Ogre::SceneManager* mSceneMgr;
Ogre::RenderWindow* mWindow;
Ogre::Viewport *mViewport;
Ogre::OverlaySystem *mOverlaySystem;
Navigation *mNavigation;
Lighting *mLighting;

@ -259,20 +259,8 @@ int TextOverlay::fontHeight()
return mFontHeight;
}
void TextOverlay::update(bool toggleOverlay)
void TextOverlay::update()
{
if(toggleOverlay)
mEnabled = !mEnabled;
if (!mEnabled)
{
mOverlay->hide();
Ogre::Root::getSingleton().renderOneFrame();
return;
}
else
mOverlay->show();
float min_x, max_x, min_y, max_y;
getMinMaxEdgesOfTopAABBIn2D(min_x, min_y, max_x, max_y);

@ -50,7 +50,7 @@ namespace CSVRender
void enable(bool enable);
bool isEnabled();
void setCaption(const Ogre::String& text);
void update(bool toggleOverlay = false);
void update();
QRect container();
Ogre::String getCaption() { return mCaption; } // FIXME: debug
};

Loading…
Cancel
Save