OpenCS: Add selection outline effect to CSVRender::Object

sceneinput
scrawl 9 years ago
parent dac3b33efb
commit 41ea76fd83

@ -10,6 +10,8 @@
#include <osg/Shape>
#include <osg/Geode>
#include <osgFX/Scribe>
#include "../../model/world/data.hpp"
#include "../../model/world/ref.hpp"
#include "../../model/world/refidcollection.hpp"
@ -116,9 +118,14 @@ const CSMWorld::CellRef& CSVRender::Object::getReference() const
CSVRender::Object::Object (CSMWorld::Data& data, osg::Group* parentNode,
const std::string& id, bool referenceable, bool forceBaseToZero)
: mData (data), mBaseNode(0), mParentNode(parentNode), mResourceSystem(data.getResourceSystem().get()), mForceBaseToZero (forceBaseToZero)
: mData (data), mBaseNode(0), mSelected(false), mParentNode(parentNode), mResourceSystem(data.getResourceSystem().get()), mForceBaseToZero (forceBaseToZero)
{
mBaseNode = new osg::PositionAttitudeTransform;
mOutline = new osgFX::Scribe;
mOutline->addChild(mBaseNode);
mBaseNode->setUserData(new ObjectHolder(this));
parentNode->addChild(mBaseNode);
// 0x1 reserved for separating cull and update visitors
@ -145,6 +152,23 @@ CSVRender::Object::~Object()
mParentNode->removeChild(mBaseNode);
}
void CSVRender::Object::setSelected(bool selected)
{
mSelected = selected;
mParentNode->removeChild(mOutline);
mParentNode->removeChild(mBaseNode);
if (selected)
mParentNode->addChild(mOutline);
else
mParentNode->addChild(mBaseNode);
}
bool CSVRender::Object::getSelected() const
{
return mSelected;
}
bool CSVRender::Object::referenceableDataChanged (const QModelIndex& topLeft,
const QModelIndex& bottomRight)
{

@ -6,6 +6,7 @@
#include <boost/shared_ptr.hpp>
#include <osg/ref_ptr>
#include <osg/Referenced>
class QModelIndex;
@ -16,6 +17,11 @@ namespace osg
class Group;
}
namespace osgFX
{
class Scribe;
}
namespace Resource
{
class ResourceSystem;
@ -29,12 +35,29 @@ namespace CSMWorld
namespace CSVRender
{
class Object;
// An object to attach as user data to the osg::Node, allows us to get an Object back from a Node when we are doing a ray query
class ObjectHolder : public osg::Referenced
{
public:
ObjectHolder(Object* obj)
: mObject(obj)
{
}
Object* mObject;
};
class Object
{
const CSMWorld::Data& mData;
std::string mReferenceId;
std::string mReferenceableId;
osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
osg::ref_ptr<osgFX::Scribe> mOutline;
bool mSelected;
osg::Group* mParentNode;
Resource::ResourceSystem* mResourceSystem;
bool mForceBaseToZero;
@ -68,6 +91,11 @@ namespace CSVRender
~Object();
/// Mark the object as selected, selected objects show an outline effect
void setSelected(bool selected);
bool getSelected() const;
/// \return Did this call result in a modification of the visual representation of
/// this object?
bool referenceableDataChanged (const QModelIndex& topLeft,

Loading…
Cancel
Save