Moved the diaglog title bar widgets into the Widget::GraphicsSubgraph map to avoid them poluting the Dialog's children list and to prevent them from being serialized.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14441 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2014-09-09 15:14:35 +00:00
parent e93e7ca1f2
commit 57a42aac39
4 changed files with 41 additions and 4 deletions

View File

@@ -18,6 +18,7 @@
#include <osgGA/EventVisitor>
#include <osgUI/Export>
#include <osgUI/Widget>
namespace osgUI
{
@@ -26,14 +27,19 @@ namespace osgUI
class OSGUI_EXPORT CloseCallback : public osg::CallbackObject
{
public:
CloseCallback(const std::string& callbackName=std::string("close"));
CloseCallback(const std::string& callbackName=std::string("close"), osgUI::Widget* closeWidget=0);
CloseCallback(const CloseCallback& hc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgUI, CloseCallback);
void setCloseWidget(osgUI::Widget* widget) { _closeWidget = widget; }
osgUI::Widget* getCloseWidget() { return _closeWidget.get(); }
const osgUI::Widget* getCloseWidget() const { return _closeWidget.get(); }
virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
protected:
virtual ~CloseCallback() {}
osg::observer_ptr<osgUI::Widget> _closeWidget;
};
class OSGUI_EXPORT HandleCallback : public osg::CallbackObject

View File

@@ -21,7 +21,8 @@
using namespace osgUI;
CloseCallback::CloseCallback(const std::string& callbackName)
CloseCallback::CloseCallback(const std::string& callbackName, osgUI::Widget* closeWidget):
_closeWidget(closeWidget)
{
setName(callbackName);
}
@@ -32,6 +33,11 @@ CloseCallback::CloseCallback(const CloseCallback& hc, const osg::CopyOp& copyop)
bool CloseCallback::run(osg::Object* object, osg::Parameters&, osg::Parameters&) const
{
if (_closeWidget.valid())
{
_closeWidget->setVisible(false);
}
osg::Node* node = dynamic_cast<osg::Node*>(object);
if (node)
{

View File

@@ -102,8 +102,7 @@ void Dialog::createGraphicsImplementation()
closeButton->setAlignmentSettings(getAlignmentSettings());
closeButton->setTextSettings(getTextSettings());
//closeButton->setFrameSettings(getFrameSettings());
closeButton->getOrCreateUserDataContainer()->addUserObject(new osgUI::CloseCallback("released"));
addChild(closeButton.get());
closeButton->getOrCreateUserDataContainer()->addUserObject(new osgUI::CloseCallback("released", this));
osg::ref_ptr<Label> titleLabel = new osgUI::Label;
titleLabel->setExtents(titleBarExtents);
@@ -112,7 +111,19 @@ void Dialog::createGraphicsImplementation()
titleLabel->setTextSettings(getTextSettings());
titleLabel->setFrameSettings(getFrameSettings());
titleLabel->getOrCreateUserDataContainer()->addUserObject(new osgUI::DragCallback);
#if 1
#if 0
_group->addChild(closeButton.get());
_group->addChild(titleLabel.get());
#else
setGraphicsSubgraph(-3, closeButton.get());
setGraphicsSubgraph(-2, titleLabel.get());
#endif
#else
addChild(closeButton.get());
addChild(titleLabel.get());
#endif
style->setupDialogStateSet(getOrCreateWidgetStateSet(), 5);
style->setupClipStateSet(dialogWithTitleExtents, getOrCreateWidgetStateSet());

View File

@@ -235,7 +235,21 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv)
}
}
GraphicsSubgraphMap::iterator itr = _graphicsSubgraphMap.begin();
while(itr!= _graphicsSubgraphMap.end() && itr->first<=0)
{
itr->second->accept(nv);
++itr;
}
osg::Group::traverse(nv);
while(itr!= _graphicsSubgraphMap.end())
{
itr->second->accept(nv);
++itr;
}
}
}
else if (_visible ||