diff --git a/include/osgUI/Style b/include/osgUI/Style index 0d006ab23..f165024d4 100644 --- a/include/osgUI/Style +++ b/include/osgUI/Style @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -48,10 +49,13 @@ public: virtual osg::Node* createText(const osg::BoundingBox& extents, const AlignmentSettings* as, const TextSettings* textSettings, const std::string& text); virtual osg::Node* createIcon(const osg::BoundingBox& extents, const std::string& filename); virtual void setupDialogStateSet(osg::StateSet* stateset); - + virtual void setupClipStateSet(const osg::BoundingBox& extents, osg::StateSet* stateset); + protected: virtual ~Style() {} + osg::ref_ptr _clipTexture; + osg::Vec4 _backgroundColor; osg::Vec4 _textColor; osg::Vec4 _disabledTextColor; diff --git a/src/osgUI/ComboBox.cpp b/src/osgUI/ComboBox.cpp index db12e3c97..7ac4c3888 100644 --- a/src/osgUI/ComboBox.cpp +++ b/src/osgUI/ComboBox.cpp @@ -99,43 +99,31 @@ void ComboBox::setCurrentItem(unsigned int i) void ComboBox::createGraphicsImplementation() { + Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get(); - if (_switch.valid() && _switch->getNumChildren()==_items.size()) + _switch = new osg::Switch; + + if (!_items.empty()) { - OSG_NOTICE<<"Need to update existing scene graph"<get(); + OSG_NOTICE<<"Creating item "<getText()<<", "<getColor()< group = new osg::Group; + if (item->getColor().a()!=0.0f) group->addChild( style->createPanel(_extents, item->getColor()) ); + if (!item->getText().empty()) group->addChild( style->createText(_extents, getAlignmentSettings(), getTextSettings(), item->getText()) ); + _switch->addChild(group.get()); + } } else { - OSG_NOTICE<<"ComboBox::createGraphicsImplementation()"<get(); - OSG_NOTICE<<"Creating item "<getText()<<", "<getColor()< group = new osg::Group; - if (item->getColor().a()!=0.0f) group->addChild( style->createPanel(_extents, item->getColor()) ); - if (!item->getText().empty()) group->addChild( style->createText(_extents, getAlignmentSettings(), getTextSettings(), item->getText()) ); - _switch->addChild(group.get()); - } - } - else - { - _switch->addChild( style->createPanel(_extents, osg::Vec4(1.0f,1.0f,1.0f,1.0f)) ); - } - - _switch->setSingleChildOn(_currentItem); - - setGraphicsSubgraph(_switch.get()); + _switch->addChild( style->createPanel(_extents, osg::Vec4(1.0f,1.0f,1.0f,1.0f)) ); } + + _switch->setSingleChildOn(_currentItem); + + style->setupClipStateSet(_extents, getOrCreateStateSet()); + setGraphicsSubgraph(_switch.get()); } diff --git a/src/osgUI/Dialog.cpp b/src/osgUI/Dialog.cpp index 8a9a8bf85..f9348bfab 100644 --- a/src/osgUI/Dialog.cpp +++ b/src/osgUI/Dialog.cpp @@ -69,28 +69,33 @@ void Dialog::open() void Dialog::createGraphicsImplementation() { - OSG_NOTICE<<"Dialog::createGraphicsImplementation()"<addChild( style->createPanel(_extents, dialogBackgroundColor) ); _transform->addChild( style->createPanel(titleBarExents, dialogTitleBackgroundColor) ); + osg::BoundingBox dialogWithTileExtents(_extents); + dialogWithTileExtents.expandBy(titleBarExents); + + OSG_NOTICE<<"Dialog::_extents ("<<_extents.xMin()<<", "<<_extents.yMin()<<", "<<_extents.zMin()<<"), ("<<_extents.xMax()<<", "<<_extents.yMax()<<", "<<_extents.zMax()<<")"< node = style->createText(titleBarExents, getAlignmentSettings(), getTextSettings(), _title); _titleDrawable = dynamic_cast(node.get()); _titleDrawable->setDataVariance(osg::Object::DYNAMIC); _transform->addChild(_titleDrawable.get()); style->setupDialogStateSet(getOrCreateStateSet()); + style->setupClipStateSet(dialogWithTileExtents, getOrCreateStateSet()); setGraphicsSubgraph(_transform.get()); } diff --git a/src/osgUI/LineEdit.cpp b/src/osgUI/LineEdit.cpp index a765fe3b9..a66462db2 100644 --- a/src/osgUI/LineEdit.cpp +++ b/src/osgUI/LineEdit.cpp @@ -32,8 +32,6 @@ LineEdit::LineEdit(const osgUI::LineEdit& label, const osg::CopyOp& copyop): bool LineEdit::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event) { - OSG_NOTICE<<"LineEdit::handleImplementation"<asGUIEventAdapter(); if (!ea) return false; @@ -78,12 +76,12 @@ void LineEdit::setText(const std::string& text) void LineEdit::createGraphicsImplementation() { - OSG_NOTICE<<"LineEdit::createGraphicsImplementation()"< node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text); _textDrawable = dynamic_cast(node.get()); _textDrawable->setDataVariance(osg::Object::DYNAMIC); + style->setupClipStateSet(_extents, getOrCreateStateSet()); + setGraphicsSubgraph(_textDrawable.get()); } diff --git a/src/osgUI/Popup.cpp b/src/osgUI/Popup.cpp index b7a2615ac..4c6f64739 100644 --- a/src/osgUI/Popup.cpp +++ b/src/osgUI/Popup.cpp @@ -76,9 +76,7 @@ void Popup::leaveImplementation() void Popup::createGraphicsImplementation() { - OSG_NOTICE<<"Popup::createGraphicsImplementation()"<addChild( style->createPanel(_extents, dialogBackgroundColor) ); style->setupDialogStateSet(getOrCreateStateSet()); + style->setupClipStateSet(_extents, getOrCreateStateSet()); setGraphicsSubgraph(_transform.get()); } diff --git a/src/osgUI/PushButton.cpp b/src/osgUI/PushButton.cpp index bc4cae696..9264abd46 100644 --- a/src/osgUI/PushButton.cpp +++ b/src/osgUI/PushButton.cpp @@ -71,8 +71,6 @@ void PushButton::leaveImplementation() void PushButton::createGraphicsImplementation() { - OSG_NOTICE<<"PushButton::createGraphicsImplementation()"< group = new osg::Group; Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get(); @@ -97,6 +95,8 @@ void PushButton::createGraphicsImplementation() group->addChild(_textDrawable.get()); + style->setupClipStateSet(_extents, getOrCreateStateSet()); + setGraphicsSubgraph(group.get()); } diff --git a/src/osgUI/Style.cpp b/src/osgUI/Style.cpp index 3ee754ab2..143586300 100644 --- a/src/osgUI/Style.cpp +++ b/src/osgUI/Style.cpp @@ -14,7 +14,10 @@ #include #include #include +#include +#include #include +#include using namespace osgUI; @@ -28,10 +31,25 @@ OSG_INIT_SINGLETON_PROXY(StyleSingletonProxy, Style::instance()) Style::Style() { + osg::ref_ptr image = new osg::Image; + image->allocateImage(1,1,1,GL_RGBA, GL_FLOAT); + *(reinterpret_cast(image->data(0,0,0))) = osg::Vec4f(1.0f, 1.0f, 1.0f, 1.0f); + + _clipTexture = new osg::Texture2D; + _clipTexture->setImage(image.get()); + _clipTexture->setBorderColor(osg::Vec4f(1.0f,1.0f,0.5f,0.0f)); + _clipTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER); + _clipTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER); + _clipTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST); + _clipTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST); + + //image = osgDB::readImageFile("Images/lz.rgb"); + //_clipTexture->setImage(image.get()); } Style::Style(const Style& style, const osg::CopyOp& copyop): - osg::Object(style, copyop) + osg::Object(style, copyop), + _clipTexture(style._clipTexture) { } @@ -93,6 +111,23 @@ osg::Node* Style::createIcon(const osg::BoundingBox& extents, const std::string& void Style::setupDialogStateSet(osg::StateSet* stateset) { stateset->setRenderBinDetails(5, "TraversalOrderBin", osg::StateSet::OVERRIDE_RENDERBIN_DETAILS); - stateset->setAttributeAndModes( new osg::Depth(osg::Depth::LESS,0.0, 1.0,false), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE ); stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); + stateset->setAttributeAndModes( new osg::Depth(osg::Depth::LESS,0.0, 1.0,false), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE ); +} + +void Style::setupClipStateSet(const osg::BoundingBox& extents, osg::StateSet* stateset) +{ + unsigned int clipTextureUnit = 1; + + stateset->setAttributeAndModes( new osg::AlphaFunc(osg::AlphaFunc::GREATER, 0.0f), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); + + stateset->setTextureAttributeAndModes( clipTextureUnit, _clipTexture.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); + + osg::Matrixd matrix = osg::Matrixd::translate(osg::Vec3(-extents.xMin(), -extents.yMin(), -extents.zMin()))* + osg::Matrixd::scale(osg::Vec3(1.0f/(extents.xMax()-extents.xMin()), 1.0f/(extents.yMax()-extents.yMin()), 1.0f)); + + osg::ref_ptr texgen = new osg::TexGen; + texgen->setPlanesFromMatrix(matrix); + texgen->setMode(osg::TexGen::OBJECT_LINEAR); + stateset->setTextureAttributeAndModes( clipTextureUnit, texgen.get(), osg::StateAttribute::ON); }