diff --git a/include/osgUI/Callbacks b/include/osgUI/Callbacks index c1c3ffbc7..b82060d8d 100644 --- a/include/osgUI/Callbacks +++ b/include/osgUI/Callbacks @@ -22,6 +22,20 @@ namespace osgUI { + +class OSGUI_EXPORT CloseCallback : public osg::CallbackObject +{ +public: + CloseCallback(const std::string& callbackName=std::string("close")); + CloseCallback(const CloseCallback& hc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + META_Object(osgUI, CloseCallback); + + virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const; + +protected: + virtual ~CloseCallback() {} +}; + class OSGUI_EXPORT HandleCallback : public osg::CallbackObject { public: @@ -36,7 +50,6 @@ protected: virtual ~HandleCallback() {} }; - class OSGUI_EXPORT DragCallback : public HandleCallback { public: diff --git a/src/osgUI/Callbacks.cpp b/src/osgUI/Callbacks.cpp index 167a04596..9ee64ee4e 100644 --- a/src/osgUI/Callbacks.cpp +++ b/src/osgUI/Callbacks.cpp @@ -13,12 +13,51 @@ #include #include +#include + #include #include #include using namespace osgUI; +CloseCallback::CloseCallback(const std::string& callbackName) +{ + setName(callbackName); +} + +CloseCallback::CloseCallback(const CloseCallback& hc, const osg::CopyOp& copyop) +{ +} + +bool CloseCallback::run(osg::Object* object, osg::Parameters&, osg::Parameters&) const +{ + osg::Node* node = dynamic_cast(object); + if (node) + { + osg::NodePathList nodePathList = node->getParentalNodePaths(); + for(osg::NodePathList::iterator itr = nodePathList.begin(); + itr != nodePathList.end(); + ++itr) + { + osg::NodePath& nodePath = *itr; + for(osg::NodePath::reverse_iterator ritr = nodePath.rbegin(); + ritr != nodePath.rend(); + ++ritr) + { + osgUI::Dialog* dialog = dynamic_cast(*ritr); + if (dialog) + { + dialog->setVisible(false); + break; + } + } + } + return true; + } + return false; +} + HandleCallback::HandleCallback() { setName("handle"); diff --git a/src/osgUI/Dialog.cpp b/src/osgUI/Dialog.cpp index cd0378970..6819f3723 100644 --- a/src/osgUI/Dialog.cpp +++ b/src/osgUI/Dialog.cpp @@ -60,34 +60,53 @@ void Dialog::createGraphicsImplementation() Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get(); float titleHeight = 10.0; - osg::BoundingBox titleBarExents(_extents.xMin(), _extents.yMax(), _extents.zMin(), _extents.xMax(), _extents.yMax()+titleHeight, _extents.zMin()); + osg::BoundingBox titleBarExtents(_extents.xMin(), _extents.yMax(), _extents.zMin(), _extents.xMax()-titleHeight, _extents.yMax()+titleHeight, _extents.zMin()); + osg::BoundingBox closeButtonExtents(_extents.xMax()-titleHeight, _extents.yMax(), _extents.zMin(), _extents.xMax(), _extents.yMax()+titleHeight, _extents.zMin()); osg::Vec4 dialogBackgroundColor(0.84,0.82,0.82,1.0); osg::Vec4 dialogTitleBackgroundColor(0.5,0.5,1.0,1.0); _group->addChild( style->createPanel(_extents, dialogBackgroundColor) ); - _group->addChild( style->createPanel(titleBarExents, dialogTitleBackgroundColor) ); + _group->addChild( style->createPanel(titleBarExtents, dialogTitleBackgroundColor) ); osg::BoundingBox dialogWithTitleExtents(_extents); - dialogWithTitleExtents.expandBy(titleBarExents); + dialogWithTitleExtents.expandBy(titleBarExtents); + dialogWithTitleExtents.expandBy(closeButtonExtents); bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape()!=osgUI::FrameSettings::NO_FRAME); - if (requiresFrame) { _group->addChild(style->createFrame(dialogWithTitleExtents, getFrameSettings(), dialogBackgroundColor)); } + if (requiresFrame) + { + _group->addChild(style->createFrame(dialogWithTitleExtents, getFrameSettings(), dialogBackgroundColor)); + + titleBarExtents.xMin() += getFrameSettings()->getLineWidth(); + titleBarExtents.yMax() -= getFrameSettings()->getLineWidth(); + closeButtonExtents.xMax() -= getFrameSettings()->getLineWidth(); + closeButtonExtents.yMax() -= getFrameSettings()->getLineWidth(); + } OSG_NOTICE<<"Dialog::_extents ("<<_extents.xMin()<<", "<<_extents.yMin()<<", "<<_extents.zMin()<<"), ("<<_extents.xMax()<<", "<<_extents.yMax()<<", "<<_extents.zMax()<<")"< node = style->createText(titleBarExents, getAlignmentSettings(), getTextSettings(), _title); + osg::ref_ptr node = style->createText(titleBarExtents, getAlignmentSettings(), getTextSettings(), _title); _titleDrawable = dynamic_cast(node.get()); _titleDrawable->setDataVariance(osg::Object::DYNAMIC); _group->addChild(_titleDrawable.get()); #endif + osg::ref_ptr closeButton = new osgUI::PushButton; + closeButton->setExtents(closeButtonExtents); + closeButton->setText("x"); + closeButton->setAlignmentSettings(getAlignmentSettings()); + closeButton->setTextSettings(getTextSettings()); + //closeButton->setFrameSettings(getFrameSettings()); + closeButton->getOrCreateUserDataContainer()->addUserObject(new osgUI::CloseCallback("released")); + addChild(closeButton.get()); + osg::ref_ptr