Mouse click on text overlay implemented. Removed 'm' keybinding for overlay toggle. White lines not visible by default.

loadfix
cc9cii 10 years ago
parent 85d93807c5
commit dbb2781817

@ -3,10 +3,13 @@
#include <sstream> #include <sstream>
#include <QMouseEvent>
#include <OgreCamera.h> #include <OgreCamera.h>
#include <OgreSceneManager.h> #include <OgreSceneManager.h>
#include <OgreManualObject.h> #include <OgreManualObject.h>
#include <Overlay/OgreOverlayContainer.h> // FIXME
#include <OgreSceneQuery.h> // FIXME
#include <OgreEntity.h> #include <OgreEntity.h>
#include "../../../../components/esm/loadland.hpp" #include "../../../../components/esm/loadland.hpp"
@ -78,7 +81,6 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
mCells.insert (std::make_pair (*iter, mCells.insert (std::make_pair (*iter,
new Cell (mDocument.getData(), getSceneManager(), iter->getId (mWorldspace)))); new Cell (mDocument.getData(), getSceneManager(), iter->getId (mWorldspace))));
// FIXME: delete this later
Ogre::ManualObject* manual = getSceneManager()->createManualObject("manual" + iter->getId(mWorldspace)); Ogre::ManualObject* manual = getSceneManager()->createManualObject("manual" + iter->getId(mWorldspace));
manual->begin("BaseWhite", Ogre::RenderOperation::OT_LINE_LIST); manual->begin("BaseWhite", Ogre::RenderOperation::OT_LINE_LIST);
@ -93,8 +95,9 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
Ogre::MeshPtr meshPtr = manual->convertToMesh("vLine" + iter->getId(mWorldspace)); Ogre::MeshPtr meshPtr = manual->convertToMesh("vLine" + iter->getId(mWorldspace));
Ogre::Entity* entity = getSceneManager()->createEntity(meshPtr); Ogre::Entity* entity = getSceneManager()->createEntity(meshPtr);
getSceneManager()->getRootSceneNode()->createChildSceneNode()->attachObject(entity); getSceneManager()->getRootSceneNode()->createChildSceneNode()->attachObject(entity);
//entity->setVisible(false); entity->setVisible(false);
// keep pointers so that they can be deleted later
mEntities.insert(std::make_pair(iter->getId(mWorldspace), entity)); mEntities.insert(std::make_pair(iter->getId(mWorldspace), entity));
CSVRender::TextOverlay *textDisp = new CSVRender::TextOverlay(entity, getCamera(), iter->getId(mWorldspace)); CSVRender::TextOverlay *textDisp = new CSVRender::TextOverlay(entity, getCamera(), iter->getId(mWorldspace));
@ -110,31 +113,41 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
return modified; return modified;
} }
void CSVRender::PagedWorldspaceWidget::updateOverlay(bool toggleOverlay) void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
{ {
if(!mTextOverlays.empty()) //std::cout << "Qt x: " + std::to_string(event->x()) << ", y: " + std::to_string(event->y()) << std::endl;
int viewportWidth = getCamera()->getViewport()->getActualWidth();
int viewportHeight = getCamera()->getViewport()->getActualHeight();
Ogre::Ray mouseRay = getCamera()->getCameraToViewportRay(event->x()/viewportWidth, event->y()/viewportHeight);
Ogre::RaySceneQuery *rayScnQuery = getSceneManager()->createRayQuery(Ogre::Ray());
rayScnQuery->setRay(mouseRay);
Ogre::RaySceneQueryResult &result = rayScnQuery->execute();
Ogre::RaySceneQueryResult::iterator it = result.begin();
std::list<TextOverlay *>::iterator iter = mTextOverlays.begin();
for(; iter != mTextOverlays.end(); ++iter)
{ {
std::list<CSVRender::TextOverlay *>::iterator it = mTextOverlays.begin(); if((*iter)->isEnabled() && (*iter)->container().contains(event->x(), event->y()))
for(; it != mTextOverlays.end(); ++it)
{ {
(*it)->update(toggleOverlay); std::cout << "clicked: " << (*iter)->getCaption() << std::endl;
(*iter)->enable(false);
} }
std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin()); }
SceneWidget::mouseReleaseEvent(event);
}
#if 0 void CSVRender::PagedWorldspaceWidget::updateOverlay()
if(toggleOverlay) {
if(!mTextOverlays.empty())
{
std::list<CSVRender::TextOverlay *>::iterator it = mTextOverlays.begin();
for(; it != mTextOverlays.end(); ++it)
{ {
while (iter!=mCells.end()) (*it)->update();
{
std::map<std::string, Ogre::Entity *>::iterator it = mEntities.find(iter->first.getId(mWorldspace));
if(it != mEntities.end())
{
it->second->setVisible(!it->second->isVisible());
}
++iter;
}
} }
#endif
} }
} }

@ -77,7 +77,9 @@ namespace CSVRender
protected: protected:
virtual void updateOverlay(bool toggleOverlay = false); virtual void updateOverlay();
virtual void mouseReleaseEvent (QMouseEvent *event);
signals: signals:

@ -287,8 +287,6 @@ namespace CSVRender
break; break;
case Qt::Key_M: updateOverlay(true);
default: QWidget::keyReleaseEvent (event); default: QWidget::keyReleaseEvent (event);
} }
} }
@ -387,7 +385,7 @@ namespace CSVRender
} }
} }
void SceneWidget::updateOverlay(bool toggleOverlay) void SceneWidget::updateOverlay()
{ } { }
void SceneWidget::setLighting (Lighting *lighting) void SceneWidget::setLighting (Lighting *lighting)

@ -59,7 +59,9 @@ namespace CSVRender
void setDefaultAmbient (const Ogre::ColourValue& colour); void setDefaultAmbient (const Ogre::ColourValue& colour);
///< \note The actual ambient colour may differ based on lighting settings. ///< \note The actual ambient colour may differ based on lighting settings.
virtual void updateOverlay(bool toggleOverlay = false); virtual void updateOverlay();
virtual void mouseReleaseEvent (QMouseEvent *event);
private: private:
void paintEvent(QPaintEvent* e); void paintEvent(QPaintEvent* e);
@ -78,8 +80,6 @@ namespace CSVRender
void mouseMoveEvent (QMouseEvent *event); void mouseMoveEvent (QMouseEvent *event);
void mouseReleaseEvent (QMouseEvent *event);
void updateOgreWindow(); void updateOgreWindow();
void setLighting (Lighting *lighting); void setLighting (Lighting *lighting);

@ -11,20 +11,16 @@
#include <OgreEntity.h> #include <OgreEntity.h>
#include <OgreViewport.h> #include <OgreViewport.h>
#include <OgreRoot.h> #include <OgreRoot.h>
#include "OgreHardwarePixelBuffer.h" #include <OgreHardwarePixelBuffer.h>
namespace CSVRender namespace CSVRender
{ {
static const int sMargin = 5; // margin around overlay text in pixels
// Things to do: // Things to do:
// - configurable font size in pixels (automatically calulate everything else from it) // - configurable font size in pixels (automatically calulate everything else from it)
// - configurable texture to use // - configurable texture to use
// - configurable toggle key to enable/disable the text overlays (currntly fixed 'm') // - configurable toggle key to enable/disable the text overlays (currntly fixed 'm')
// - try material script // - try material script
// - setup common resources such as font in a central place, so that they are not
// repeated for each text overlay (also destroy once)
// - decide whether to use QPaint // - decide whether to use QPaint
// http://www.ogre3d.org/tikiwiki/tiki-index.php?page=ObjectTextDisplay // http://www.ogre3d.org/tikiwiki/tiki-index.php?page=ObjectTextDisplay
@ -32,7 +28,7 @@ static const int sMargin = 5; // margin around overlay text in pixels
// http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Creating+dynamic+textures // http://www.ogre3d.org/tikiwiki/tiki-index.php?page=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(""), mEnabled(false), mCamera(camera), mObj(obj), mId(id), mOnScreen(false) : mOverlay(0), mCaption(""), mEnabled(true), mCamera(camera), mObj(obj), mId(id), mOnScreen(false)
, mFontHeight(16) // FIXME: make this configurable , mFontHeight(16) // FIXME: make this configurable
{ {
if(id == "" || !camera || !obj) if(id == "" || !camera || !obj)
@ -120,7 +116,7 @@ TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* cam
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);
mElement->setPosition(sMargin*2, sMargin*1.3); // 1.3 & 2 = fudge factor mElement->setPosition(2*fontHeight()/3, 1.3*fontHeight()/3); // 1.3 & 2 = fudge factor
mElement->setFontName("DejaVuLGC"); mElement->setFontName("DejaVuLGC");
mElement->setCharHeight(fontHeight()); // NOTE: seems that this is required as well as font->setTrueTypeSize() mElement->setCharHeight(fontHeight()); // NOTE: seems that this is required as well as font->setTrueTypeSize()
@ -214,11 +210,21 @@ TextOverlay::~TextOverlay()
void TextOverlay::enable(bool enable) void TextOverlay::enable(bool enable)
{ {
if(enable == mContainer->isVisible())
return;
mEnabled = enable; mEnabled = enable;
if (enable) if (enable)
mOverlay->show(); mContainer->show();
else else
mOverlay->hide(); mContainer->hide();
Ogre::Root::getSingleton().renderOneFrame();
}
bool TextOverlay::isEnabled()
{
return mEnabled;
} }
void TextOverlay::setCaption(const Ogre::String& text) void TextOverlay::setCaption(const Ogre::String& text)
@ -287,15 +293,27 @@ void TextOverlay::update(bool toggleOverlay)
float viewportWidth = std::max(overlayMgr.getViewportWidth(), 1); // zero at the start float viewportWidth = std::max(overlayMgr.getViewportWidth(), 1); // zero at the start
float viewportHeight = std::max(overlayMgr.getViewportHeight(), 1); // zero at the start float viewportHeight = std::max(overlayMgr.getViewportHeight(), 1); // zero at the start
float relTextWidth = (2*sMargin + textWidth() + sMargin) / viewportWidth; // 2 = fudge factor int width = 2*fontHeight()/3 + textWidth() + fontHeight()/3; // 2 = fudge factor
float relTextHeight = (sMargin + fontHeight() + sMargin) / viewportHeight; int height = fontHeight()/3 + fontHeight() + fontHeight()/3;
mContainer->setMetricsMode(Ogre::GMM_RELATIVE); float relTextWidth = width / viewportWidth;
mContainer->setPosition(1-(min_x + max_x + relTextWidth)/2, 1-max_y-(relTextHeight-sMargin/viewportHeight)); float relTextHeight = height / viewportHeight;
float posX = 1 - (min_x + max_x + relTextWidth)/2;
float posY = 1 - max_y - (relTextHeight-fontHeight()/3/viewportHeight);
mContainer->setMetricsMode(Ogre::GMM_RELATIVE);
mContainer->setPosition(posX, posY);
mContainer->setDimensions(relTextWidth, relTextHeight); mContainer->setDimensions(relTextWidth, relTextHeight);
mPos = QRect(posX*viewportWidth, posY*viewportHeight, width, height);
Ogre::Root::getSingleton().renderOneFrame(); Ogre::Root::getSingleton().renderOneFrame();
} }
QRect TextOverlay::container()
{
return mPos;
}
} }

@ -1,6 +1,8 @@
#ifndef OPENCS_VIEW_TEXTOVERLAY_H #ifndef OPENCS_VIEW_TEXTOVERLAY_H
#define OPENCS_VIEW_TEXTOVERLAY_H #define OPENCS_VIEW_TEXTOVERLAY_H
#include <QRect>
#include <OgreString.h> #include <OgreString.h>
#include <Overlay/OgreFont.h> #include <Overlay/OgreFont.h>
@ -29,6 +31,7 @@ namespace CSVRender
Ogre::FontPtr mFont; Ogre::FontPtr mFont;
int mFontHeight; // in pixels int mFontHeight; // in pixels
Ogre::String mId; Ogre::String mId;
QRect mPos;
bool mEnabled; bool mEnabled;
bool mOnScreen; // not used bool mOnScreen; // not used
@ -45,8 +48,11 @@ namespace CSVRender
virtual ~TextOverlay(); virtual ~TextOverlay();
void enable(bool enable); void enable(bool enable);
bool isEnabled();
void setCaption(const Ogre::String& text); void setCaption(const Ogre::String& text);
void update(bool toggleOverlay = false); void update(bool toggleOverlay = false);
QRect container();
Ogre::String getCaption() { return mCaption; } // FIXME: debug
}; };
} }

@ -314,6 +314,3 @@ void CSVRender::WorldspaceWidget::elementSelectionChanged()
setVisibilityMask (getElementMask()); setVisibilityMask (getElementMask());
flagAsModified(); flagAsModified();
} }
void CSVRender::WorldspaceWidget::updateOverlay(bool toggleOverlay)
{ }

@ -88,8 +88,6 @@ namespace CSVRender
CSMDoc::Document& getDocument(); CSMDoc::Document& getDocument();
virtual void updateOverlay(bool toggleOverlay = false);
private: private:
void dragEnterEvent(QDragEnterEvent *event); void dragEnterEvent(QDragEnterEvent *event);

Loading…
Cancel
Save