Added osgUI::Widget::set/getGraphicsSubgraph() to hold the subgraph that does the rendering portion of widgets
This commit is contained in:
parent
0b5b3213fe
commit
bda5ec4875
@ -42,7 +42,18 @@ public:
|
||||
|
||||
virtual void dirty();
|
||||
|
||||
|
||||
/** Set the subgraph to be used to erndering the widget.*/
|
||||
void setGraphicsSubgraph(osg::Node* node) { _graphicsSubgraph = node; _graphicsInitialized = true; }
|
||||
/** Get the subgraph to be used to erndering the widget.*/
|
||||
osg::Node* getGraphicsSubgraph() { return _graphicsSubgraph.get(); }
|
||||
/** Get the const subgraph to be used to erndering the widget.*/
|
||||
const osg::Node* getGraphicsSubgraph() const { return _graphicsSubgraph.get(); }
|
||||
|
||||
/** createGraphics entry method, calls either callback object named "createGraphics" or the createGraphicsImplementation() method.*/
|
||||
virtual void createGraphics();
|
||||
|
||||
/** createGraphicsImplementation method that creates the subgraph that will render the widget and assigns it to the Widget via the Widet::setGraphicsSubgraph() method.*/
|
||||
virtual void createGraphicsImplementation();
|
||||
|
||||
|
||||
@ -104,6 +115,10 @@ public:
|
||||
virtual void leave();
|
||||
virtual void leaveImplementation();
|
||||
|
||||
/** resize all GLObjectBuffers.*/
|
||||
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
||||
/** resize all GLObjectBuffers.*/
|
||||
virtual void releaseGLObjects(osg::State* = 0) const;
|
||||
|
||||
protected:
|
||||
virtual ~Widget() {}
|
||||
@ -112,6 +127,8 @@ protected:
|
||||
bool _hasEventFocus;
|
||||
bool _graphicsInitialized;
|
||||
|
||||
osg::ref_ptr<osg::Node> _graphicsSubgraph;
|
||||
|
||||
osg::BoundingBoxf _extents;
|
||||
|
||||
osg::ref_ptr<Style> _style;
|
||||
|
@ -114,7 +114,6 @@ void ComboBox::createGraphicsImplementation()
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
|
||||
_switch = new osg::Switch;
|
||||
addChild(_switch.get());
|
||||
|
||||
if (!_items.empty())
|
||||
{
|
||||
@ -136,5 +135,7 @@ void ComboBox::createGraphicsImplementation()
|
||||
}
|
||||
|
||||
_switch->setSingleChildOn(_currentItem);
|
||||
|
||||
setGraphicsSubgraph(_switch.get());
|
||||
}
|
||||
}
|
||||
|
@ -71,36 +71,25 @@ void Dialog::open()
|
||||
|
||||
void Dialog::createGraphicsImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"Dialog::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
if (_titleDrawable.valid())
|
||||
{
|
||||
OSG_NOTICE<<"Dialog::createGraphicsImplementation() updating existing TextDrawable"<<std::endl;
|
||||
_titleDrawable->setText(_title);
|
||||
_graphicsInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"Dialog::createGraphicsImplementation()"<<std::endl;
|
||||
_transform = new osg::PositionAttitudeTransform;
|
||||
|
||||
Widget::createGraphicsImplementation();
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
|
||||
_transform = new osg::PositionAttitudeTransform;
|
||||
addChild(_transform.get());
|
||||
float titleHeight = 1.0;
|
||||
osg::BoundingBox titleBarExents(_extents.xMin(), _extents.yMax(), _extents.zMin(), _extents.xMax(), _extents.yMax()+titleHeight, _extents.zMin());
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
osg::ref_ptr<Node> node = style->createText(titleBarExents, getAlignmentSettings(), getTextSettings(), _title);
|
||||
_titleDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
_titleDrawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
_transform->addChild(_titleDrawable.get());
|
||||
|
||||
float titleHeight = 1.0;
|
||||
osg::BoundingBox titleBarExents(_extents.xMin(), _extents.yMax(), _extents.zMin(), _extents.xMax(), _extents.yMax()+titleHeight, _extents.zMin());
|
||||
osg::Vec4 dialogBackgroundColor(0.8,0.8,0.8,1.0);
|
||||
osg::Vec4 dialogTitleBackgroundColor(0.5,0.5,1.0,1.0);
|
||||
|
||||
osg::ref_ptr<Node> node = style->createText(titleBarExents, getAlignmentSettings(), getTextSettings(), _title);
|
||||
_titleDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
_titleDrawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
_transform->addChild(_titleDrawable.get());
|
||||
_transform->addChild( style->createPanel(_extents, dialogBackgroundColor) );
|
||||
_transform->addChild( style->createPanel(titleBarExents, dialogTitleBackgroundColor) );
|
||||
|
||||
osg::Vec4 dialogBackgroundColor(0.8,0.8,0.8,1.0);
|
||||
osg::Vec4 dialogTitleBackgroundColor(0.5,0.5,1.0,1.0);
|
||||
|
||||
_transform->addChild( style->createPanel(_extents, dialogBackgroundColor) );
|
||||
_transform->addChild( style->createPanel(titleBarExents, dialogTitleBackgroundColor) );
|
||||
}
|
||||
setGraphicsSubgraph(_transform.get());
|
||||
}
|
||||
|
@ -78,29 +78,12 @@ void LineEdit::setText(const std::string& text)
|
||||
|
||||
void LineEdit::createGraphicsImplementation()
|
||||
{
|
||||
OSG_NOTICE<<"LineEdit::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
if (_textDrawable.valid())
|
||||
{
|
||||
OSG_NOTICE<<"LineEdit::createGraphicsImplementation() updating existing TextDrawable"<<std::endl;
|
||||
_textDrawable->setText(_text);
|
||||
_graphicsInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"LineEdit::createGraphicsImplementation()"<<std::endl;
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
osg::ref_ptr<Node> node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text);
|
||||
_textDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
_textDrawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
|
||||
Widget::createGraphicsImplementation();
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
osg::ref_ptr<Node> node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text);
|
||||
_textDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
_textDrawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
#if 0
|
||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
||||
geode->addDrawable(_textDrawable.get());
|
||||
addChild(geode.get());
|
||||
#else
|
||||
addChild(_textDrawable.get());
|
||||
#endif
|
||||
}
|
||||
setGraphicsSubgraph(_textDrawable.get());
|
||||
}
|
||||
|
@ -76,17 +76,15 @@ void Popup::leaveImplementation()
|
||||
|
||||
void Popup::createGraphicsImplementation()
|
||||
{
|
||||
|
||||
OSG_NOTICE<<"Popup::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
Widget::createGraphicsImplementation();
|
||||
|
||||
_transform = new osg::PositionAttitudeTransform;
|
||||
addChild(_transform.get());
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
|
||||
osg::Vec4 dialogBackgroundColor(0.8,0.8,0.8,1.0);
|
||||
|
||||
_transform->addChild( style->createPanel(_extents, dialogBackgroundColor) );
|
||||
|
||||
setGraphicsSubgraph(_transform.get());
|
||||
}
|
||||
|
@ -71,39 +71,31 @@ void PushButton::leaveImplementation()
|
||||
|
||||
void PushButton::createGraphicsImplementation()
|
||||
{
|
||||
if (_textDrawable.valid())
|
||||
{
|
||||
OSG_NOTICE<<"PushButton::createGraphicsImplementation() updating existing TextDrawable"<<std::endl;
|
||||
_textDrawable->setText(_text);
|
||||
_graphicsInitialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"PushButton::createGraphicsImplementation()"<<std::endl;
|
||||
OSG_NOTICE<<"PushButton::createGraphicsImplementation()"<<std::endl;
|
||||
|
||||
Widget::createGraphicsImplementation();
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
||||
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
osg::ref_ptr<Node> node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text);
|
||||
_textDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
_textDrawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
osg::ref_ptr<Node> node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text);
|
||||
_textDrawable = dynamic_cast<osgText::Text*>(node.get());
|
||||
_textDrawable->setDataVariance(osg::Object::DYNAMIC);
|
||||
|
||||
addChild(_textDrawable.get());
|
||||
group->addChild(_textDrawable.get());
|
||||
|
||||
_buttonSwitch = new osg::Switch;
|
||||
_buttonSwitch = new osg::Switch;
|
||||
|
||||
float unFocused = 0.7;
|
||||
float withFocus = 0.8;
|
||||
float pressed = 0.5;
|
||||
float unFocused = 0.7;
|
||||
float withFocus = 0.8;
|
||||
float pressed = 0.5;
|
||||
|
||||
_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);
|
||||
_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);
|
||||
|
||||
addChild(_buttonSwitch.get());
|
||||
group->addChild(_buttonSwitch.get());
|
||||
|
||||
}
|
||||
setGraphicsSubgraph(group.get());
|
||||
}
|
||||
|
||||
void PushButton::pressedImplementation()
|
||||
|
@ -215,9 +215,13 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osg::Group::traverse(nv);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_graphicsSubgraph.valid()) _graphicsSubgraph->accept(nv);
|
||||
|
||||
osg::Group::traverse(nv);
|
||||
}
|
||||
}
|
||||
@ -285,3 +289,16 @@ osg::BoundingSphere Widget::computeBound() const
|
||||
if (_extents.valid()) return osg::BoundingSphere(_extents);
|
||||
else return osg::Group::computeBound();
|
||||
}
|
||||
|
||||
void Widget::resizeGLObjectBuffers(unsigned int maxSize)
|
||||
{
|
||||
if (_graphicsSubgraph.valid()) _graphicsSubgraph->resizeGLObjectBuffers(maxSize);
|
||||
Group::resizeGLObjectBuffers(maxSize);
|
||||
}
|
||||
|
||||
|
||||
void Widget::releaseGLObjects(osg::State* state) const
|
||||
{
|
||||
if (_graphicsSubgraph.valid()) _graphicsSubgraph->releaseGLObjects(state);
|
||||
Group::releaseGLObjects(state);
|
||||
}
|
||||
|
@ -69,6 +69,8 @@ REGISTER_OBJECT_WRAPPER( Widget,
|
||||
|
||||
ADD_BOOL_SERIALIZER(HasEventFocus, false);
|
||||
|
||||
ADD_OBJECT_SERIALIZER( GraphicsSubgraph, osg::Node, NULL );
|
||||
|
||||
ADD_BOUNDINGBOXF_SERIALIZER(Extents, osg::BoundingBoxf());
|
||||
|
||||
ADD_OBJECT_SERIALIZER( FrameSettings, osgUI::FrameSettings, NULL );
|
||||
|
Loading…
Reference in New Issue
Block a user