From 41ea76fd836eb956b9a7517c2181181c7c8ea115 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 Sep 2015 18:31:05 +0200 Subject: [PATCH] OpenCS: Add selection outline effect to CSVRender::Object --- apps/opencs/view/render/object.cpp | 26 +++++++++++++++++++++++++- apps/opencs/view/render/object.hpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index 973893a71..f05e311f9 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -10,6 +10,8 @@ #include #include +#include + #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) { diff --git a/apps/opencs/view/render/object.hpp b/apps/opencs/view/render/object.hpp index 9f411ffc6..9b3749069 100644 --- a/apps/opencs/view/render/object.hpp +++ b/apps/opencs/view/render/object.hpp @@ -6,6 +6,7 @@ #include #include +#include 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 mBaseNode; + osg::ref_ptr 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,