From 199506296ade93a80dc421da996be739f9752885 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 30 May 2014 16:44:36 +0000 Subject: [PATCH] Implemented basic frame graphic --- include/osgUI/Style | 2 +- src/osgUI/Dialog.cpp | 11 +--- src/osgUI/LineEdit.cpp | 22 +++++++- src/osgUI/Popup.cpp | 3 + src/osgUI/PushButton.cpp | 22 ++++++-- src/osgUI/Style.cpp | 116 ++++++++++++++++++++++++++++++++++++++- 6 files changed, 158 insertions(+), 18 deletions(-) diff --git a/include/osgUI/Style b/include/osgUI/Style index 714550544..8fe891dc5 100644 --- a/include/osgUI/Style +++ b/include/osgUI/Style @@ -48,7 +48,7 @@ public: virtual osg::Node* createDepthSetPanel(const osg::BoundingBox& extents); virtual osg::Node* createPanel(const osg::BoundingBox& extents, const osg::Vec4& colour); - virtual osg::Node* createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings); + virtual osg::Node* createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings, const osg::Vec4& colour); 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); diff --git a/src/osgUI/Dialog.cpp b/src/osgUI/Dialog.cpp index b1de85d18..47bb99b0c 100644 --- a/src/osgUI/Dialog.cpp +++ b/src/osgUI/Dialog.cpp @@ -41,14 +41,6 @@ bool Dialog::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event) case(osgGA::GUIEventAdapter::KEYUP): OSG_NOTICE<<"Key pressed : "<getKey()<getKey()=='c') - { - setVisible(false); - ea->setHandled(true); - - return true; - } - break; default: break; @@ -75,6 +67,9 @@ void Dialog::createGraphicsImplementation() osg::BoundingBox dialogWithTileExtents(_extents); dialogWithTileExtents.expandBy(titleBarExents); + bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape()!=osgUI::FrameSettings::NO_FRAME); + if (requiresFrame) { _group->addChild(style->createFrame(dialogWithTileExtents, getFrameSettings(), dialogBackgroundColor)); } + OSG_NOTICE<<"Dialog::_extents ("<<_extents.xMin()<<", "<<_extents.yMin()<<", "<<_extents.zMin()<<"), ("<<_extents.xMax()<<", "<<_extents.yMax()<<", "<<_extents.zMax()<<")"< node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text); + + osg::ref_ptr group = new osg::Group; + + osg::BoundingBox extents(_extents); + osg::Vec4 frameColor(0.75f,0.75f,0.75f,1.0f); + + bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape()!=osgUI::FrameSettings::NO_FRAME); + if (requiresFrame) + { + group->addChild(style->createFrame(_extents, getFrameSettings(), frameColor)); + extents.xMin() += getFrameSettings()->getLineWidth(); + extents.xMax() -= getFrameSettings()->getLineWidth(); + extents.yMin() += getFrameSettings()->getLineWidth(); + extents.yMax() -= getFrameSettings()->getLineWidth(); + } + + + osg::ref_ptr node = style->createText(extents, getAlignmentSettings(), getTextSettings(), _text); _textDrawable = dynamic_cast(node.get()); _textDrawable->setDataVariance(osg::Object::DYNAMIC); + group->addChild(node.get()); style->setupClipStateSet(_extents, getOrCreateStateSet()); - setGraphicsSubgraph(0, _textDrawable.get()); + setGraphicsSubgraph(0, group.get()); } diff --git a/src/osgUI/Popup.cpp b/src/osgUI/Popup.cpp index 6082968a3..3c3d639d2 100644 --- a/src/osgUI/Popup.cpp +++ b/src/osgUI/Popup.cpp @@ -74,6 +74,9 @@ void Popup::createGraphicsImplementation() _transform->addChild( style->createPanel(_extents, dialogBackgroundColor) ); + bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape()!=osgUI::FrameSettings::NO_FRAME); + if (requiresFrame) { _transform->addChild(style->createFrame(_extents, getFrameSettings(), dialogBackgroundColor)); } + style->setupDialogStateSet(getOrCreateStateSet()); style->setupClipStateSet(_extents, getOrCreateStateSet()); diff --git a/src/osgUI/PushButton.cpp b/src/osgUI/PushButton.cpp index 2b100654a..fed21bd84 100644 --- a/src/osgUI/PushButton.cpp +++ b/src/osgUI/PushButton.cpp @@ -81,15 +81,29 @@ void PushButton::createGraphicsImplementation() 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))); + osg::Vec4 frameColor(0.75f,0.75f,0.75f,1.0f); + + osg::BoundingBox extents(_extents); + + bool requiresFrame = (getFrameSettings() && getFrameSettings()->getShape()!=osgUI::FrameSettings::NO_FRAME); + if (requiresFrame) + { + group->addChild(style->createFrame(_extents, getFrameSettings(), frameColor)); + extents.xMin() += getFrameSettings()->getLineWidth(); + extents.xMax() -= getFrameSettings()->getLineWidth(); + extents.yMin() += getFrameSettings()->getLineWidth(); + extents.yMax() -= getFrameSettings()->getLineWidth(); + } + + _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()); // create label. - osg::ref_ptr node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text); + osg::ref_ptr node = style->createText(extents, getAlignmentSettings(), getTextSettings(), _text); _textDrawable = dynamic_cast(node.get()); _textDrawable->setDataVariance(osg::Object::DYNAMIC); diff --git a/src/osgUI/Style.cpp b/src/osgUI/Style.cpp index 8eab21003..25d22c2d4 100644 --- a/src/osgUI/Style.cpp +++ b/src/osgUI/Style.cpp @@ -37,7 +37,7 @@ Style::Style() _clipTexture = new osg::Texture2D; _clipTexture->setImage(image.get()); - _clipTexture->setBorderColor(osg::Vec4f(1.0f,1.0f,0.5f,0.0f)); + _clipTexture->setBorderColor(osg::Vec4f(1.0f,1.0f,1.0f,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); @@ -101,9 +101,119 @@ osg::Node* Style::createDepthSetPanel(const osg::BoundingBox& extents) return geometry.release(); } -osg::Node* Style::createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings) +osg::Node* Style::createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings, const osg::Vec4& color) { - return 0; + osg::ref_ptr geometry = new osg::Geometry; + + float topScale = 1.0f; + float bottomScale = 1.0f; + float leftScale = 1.0f; + float rightScale = 1.0f; + + if (frameSettings) + { + switch(frameSettings->getShadow()) + { + case(FrameSettings::PLAIN): + // default settings are appropriate for PLAIN + break; + case(FrameSettings::SUNKEN): + topScale = 0.6f; + bottomScale = 1.2f; + leftScale = 0.8f; + rightScale = 0.8f; + break; + case(FrameSettings::RAISED): + topScale = 1.2f; + bottomScale = 0.6f; + leftScale = 0.8f; + rightScale = 0.8f; + break; + } + } + + osg::Vec4 topColor(osg::minimum(color.r()*topScale,1.0f), osg::minimum(color.g()*topScale,1.0f), osg::minimum(color.b()*topScale,1.0f), color.a()); + osg::Vec4 bottomColor(osg::minimum(color.r()*bottomScale,1.0f), osg::minimum(color.g()*bottomScale,1.0f), osg::minimum(color.b()*bottomScale,1.0f), color.a()); + osg::Vec4 leftColor(osg::minimum(color.r()*leftScale,1.0f), osg::minimum(color.g()*leftScale,1.0f), osg::minimum(color.b()*leftScale,1.0f), color.a()); + osg::Vec4 rightColor(osg::minimum(color.r()*rightScale,1.0f), osg::minimum(color.g()*rightScale,1.0f), osg::minimum(color.b()*rightScale,1.0f), color.a()); + + float lineWidth = frameSettings ? frameSettings->getLineWidth() : 1.0f; + + osg::Vec3 outerBottomLeft(extents.xMin(), extents.yMin(), extents.zMin()); + osg::Vec3 outerBottomRight(extents.xMax(), extents.yMin(), extents.zMin()); + osg::Vec3 outerTopLeft(extents.xMin(), extents.yMax(), extents.zMin()); + osg::Vec3 outerTopRight(extents.xMax(), extents.yMax(), extents.zMin()); + + osg::Vec3 innerBottomLeft(extents.xMin()+lineWidth, extents.yMin()+lineWidth, extents.zMin()); + osg::Vec3 innerBottomRight(extents.xMax()-lineWidth, extents.yMin()+lineWidth, extents.zMin()); + osg::Vec3 innerTopLeft(extents.xMin()+lineWidth, extents.yMax()-lineWidth, extents.zMin()); + osg::Vec3 innerTopRight(extents.xMax()-lineWidth, extents.yMax()-lineWidth, extents.zMin()); + + osg::ref_ptr vertices = new osg::Vec3Array; + geometry->setVertexArray(vertices.get()); + + vertices->push_back( outerBottomLeft ); // 0 + vertices->push_back( outerBottomRight ); // 1 + vertices->push_back( outerTopLeft ); // 2 + vertices->push_back( outerTopRight ); // 3 + + vertices->push_back( innerBottomLeft ); // 4 + vertices->push_back( innerBottomRight ); // 5 + vertices->push_back( innerTopLeft ); // 6 + vertices->push_back( innerTopRight ); // 7 + + osg::ref_ptr colours = new osg::Vec4Array; + geometry->setColorArray(colours.get(), osg::Array::BIND_PER_PRIMITIVE_SET); + + // bottom + { + colours->push_back(bottomColor); + + osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_TRIANGLE_STRIP); + geometry->addPrimitiveSet(primitives.get()); + primitives->push_back(4); + primitives->push_back(0); + primitives->push_back(5); + primitives->push_back(1); + } + + // top + { + colours->push_back(topColor); + + osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_TRIANGLE_STRIP); + geometry->addPrimitiveSet(primitives.get()); + primitives->push_back(2); + primitives->push_back(6); + primitives->push_back(3); + primitives->push_back(7); + } + + // left + { + colours->push_back(leftColor); + + osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_TRIANGLE_STRIP); + geometry->addPrimitiveSet(primitives.get()); + primitives->push_back(2); + primitives->push_back(0); + primitives->push_back(6); + primitives->push_back(4); + } + + // right + { + colours->push_back(rightColor); + + osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_TRIANGLE_STRIP); + geometry->addPrimitiveSet(primitives.get()); + primitives->push_back(7); + primitives->push_back(5); + primitives->push_back(3); + primitives->push_back(1); + } + + return geometry.release(); } osg::Node* Style::createText(const osg::BoundingBox& extents, const AlignmentSettings* as, const TextSettings* ts, const std::string& text)