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 <QMouseEvent>
#include <OgreCamera.h>
#include <OgreSceneManager.h>
#include <OgreManualObject.h>
#include <Overlay/OgreOverlayContainer.h> // FIXME
#include <OgreSceneQuery.h> // FIXME
#include <OgreEntity.h>
#include "../../../../components/esm/loadland.hpp"
@ -78,7 +81,6 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
mCells.insert (std::make_pair (*iter,
new Cell (mDocument.getData(), getSceneManager(), iter->getId (mWorldspace))));
// FIXME: delete this later
Ogre::ManualObject* manual = getSceneManager()->createManualObject("manual" + iter->getId(mWorldspace));
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::Entity* entity = getSceneManager()->createEntity(meshPtr);
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));
CSVRender::TextOverlay *textDisp = new CSVRender::TextOverlay(entity, getCamera(), iter->getId(mWorldspace));
@ -110,31 +113,41 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
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();
for(; it != mTextOverlays.end(); ++it)
if((*iter)->isEnabled() && (*iter)->container().contains(event->x(), event->y()))
{
(*it)->update(toggleOverlay);
std::cout << "clicked: " << (*iter)->getCaption() << std::endl;
(*iter)->enable(false);
}
}
std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
#if 0
if(toggleOverlay)
{
while (iter!=mCells.end())
SceneWidget::mouseReleaseEvent(event);
}
void CSVRender::PagedWorldspaceWidget::updateOverlay()
{
if(!mTextOverlays.empty())
{
std::map<std::string, Ogre::Entity *>::iterator it = mEntities.find(iter->first.getId(mWorldspace));
if(it != mEntities.end())
std::list<CSVRender::TextOverlay *>::iterator it = mTextOverlays.begin();
for(; it != mTextOverlays.end(); ++it)
{
it->second->setVisible(!it->second->isVisible());
}
++iter;
}
(*it)->update();
}
#endif
}
}

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

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

@ -59,7 +59,9 @@ namespace CSVRender
void setDefaultAmbient (const Ogre::ColourValue& colour);
///< \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:
void paintEvent(QPaintEvent* e);
@ -78,8 +80,6 @@ namespace CSVRender
void mouseMoveEvent (QMouseEvent *event);
void mouseReleaseEvent (QMouseEvent *event);
void updateOgreWindow();
void setLighting (Lighting *lighting);

@ -11,20 +11,16 @@
#include <OgreEntity.h>
#include <OgreViewport.h>
#include <OgreRoot.h>
#include "OgreHardwarePixelBuffer.h"
#include <OgreHardwarePixelBuffer.h>
namespace CSVRender
{
static const int sMargin = 5; // margin around overlay text in pixels
// Things to do:
// - configurable font size in pixels (automatically calulate everything else from it)
// - configurable texture to use
// - configurable toggle key to enable/disable the text overlays (currntly fixed 'm')
// - 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
// 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/ManualObject
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
{
if(id == "" || !camera || !obj)
@ -120,7 +116,7 @@ TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* cam
mElement->setMetricsMode(Ogre::GMM_RELATIVE);
mElement->setDimensions(1.0, 1.0);
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->setCharHeight(fontHeight()); // NOTE: seems that this is required as well as font->setTrueTypeSize()
@ -214,11 +210,21 @@ TextOverlay::~TextOverlay()
void TextOverlay::enable(bool enable)
{
if(enable == mContainer->isVisible())
return;
mEnabled = enable;
if (enable)
mOverlay->show();
mContainer->show();
else
mOverlay->hide();
mContainer->hide();
Ogre::Root::getSingleton().renderOneFrame();
}
bool TextOverlay::isEnabled()
{
return mEnabled;
}
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 viewportHeight = std::max(overlayMgr.getViewportHeight(), 1); // zero at the start
float relTextWidth = (2*sMargin + textWidth() + sMargin) / viewportWidth; // 2 = fudge factor
float relTextHeight = (sMargin + fontHeight() + sMargin) / viewportHeight;
int width = 2*fontHeight()/3 + textWidth() + fontHeight()/3; // 2 = fudge factor
int height = fontHeight()/3 + fontHeight() + fontHeight()/3;
mContainer->setMetricsMode(Ogre::GMM_RELATIVE);
mContainer->setPosition(1-(min_x + max_x + relTextWidth)/2, 1-max_y-(relTextHeight-sMargin/viewportHeight));
float relTextWidth = width / viewportWidth;
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);
mPos = QRect(posX*viewportWidth, posY*viewportHeight, width, height);
Ogre::Root::getSingleton().renderOneFrame();
}
QRect TextOverlay::container()
{
return mPos;
}
}

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

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

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

Loading…
Cancel
Save