Added close button on Dialog title bar
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14435 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -13,12 +13,51 @@
|
||||
|
||||
#include <osgUI/Callbacks>
|
||||
#include <osgUI/Widget>
|
||||
#include <osgUI/Dialog>
|
||||
|
||||
#include <osg/ValueObject>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/io_utils>
|
||||
|
||||
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<osg::Node*>(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<osgUI::Dialog*>(*ritr);
|
||||
if (dialog)
|
||||
{
|
||||
dialog->setVisible(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
HandleCallback::HandleCallback()
|
||||
{
|
||||
setName("handle");
|
||||
|
||||
@@ -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()<<")"<<std::endl;
|
||||
OSG_NOTICE<<"Dialog::titleBarExents ("<<titleBarExents.xMin()<<", "<<titleBarExents.yMin()<<", "<<titleBarExents.zMin()<<"), ("<<titleBarExents.xMax()<<", "<<titleBarExents.yMax()<<", "<<titleBarExents.zMax()<<")"<<std::endl;
|
||||
OSG_NOTICE<<"Dialog::titleBarExtents ("<<titleBarExtents.xMin()<<", "<<titleBarExtents.yMin()<<", "<<titleBarExtents.zMin()<<"), ("<<titleBarExtents.xMax()<<", "<<titleBarExtents.yMax()<<", "<<titleBarExtents.zMax()<<")"<<std::endl;
|
||||
OSG_NOTICE<<"Dialog::dialogWithTitleExtents ("<<dialogWithTitleExtents.xMin()<<", "<<dialogWithTitleExtents.yMin()<<", "<<dialogWithTitleExtents.zMin()<<"), ("<<dialogWithTitleExtents.xMax()<<", "<<dialogWithTitleExtents.yMax()<<", "<<dialogWithTitleExtents.zMax()<<")"<<std::endl;
|
||||
|
||||
#if 0
|
||||
osg::ref_ptr<Node> node = style->createText(titleBarExents, getAlignmentSettings(), getTextSettings(), _title);
|
||||
osg::ref_ptr<Node> node = style->createText(titleBarExtents, getAlignmentSettings(), getTextSettings(), _title);
|
||||
_titleDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
_titleDrawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
_group->addChild(_titleDrawable.get());
|
||||
#endif
|
||||
|
||||
osg::ref_ptr<PushButton> 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<Label> titleLabel = new osgUI::Label;
|
||||
titleLabel->setExtents(titleBarExents);
|
||||
titleLabel->setExtents(titleBarExtents);
|
||||
titleLabel->setText(_title);
|
||||
titleLabel->setAlignmentSettings(getAlignmentSettings());
|
||||
titleLabel->setTextSettings(getTextSettings());
|
||||
|
||||
@@ -78,6 +78,7 @@ void PushButton::createGraphicsImplementation()
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
|
||||
|
||||
float pressed = 0.88;
|
||||
float unFocused = 0.92;
|
||||
float withFocus = 0.97;
|
||||
|
||||
@@ -98,6 +99,7 @@ void PushButton::createGraphicsImplementation()
|
||||
_buttonSwitch = new osg::Switch;
|
||||
_buttonSwitch->addChild(style->createPanel(extents, osg::Vec4(unFocused, unFocused,unFocused, 1.0)));
|
||||
_buttonSwitch->addChild(style->createPanel(extents, osg::Vec4(withFocus,withFocus,withFocus,1.0)));
|
||||
_buttonSwitch->addChild(style->createPanel(extents, osg::Vec4(pressed,pressed,pressed,1.0)));
|
||||
_buttonSwitch->setSingleChildOn(0);
|
||||
|
||||
group->addChild(_buttonSwitch.get());
|
||||
|
||||
Reference in New Issue
Block a user