Implemented basic frame graphic

This commit is contained in:
Robert Osfield 2014-05-30 16:44:36 +00:00
parent 189c0b3477
commit 199506296a
6 changed files with 158 additions and 18 deletions

View File

@ -48,7 +48,7 @@ public:
virtual osg::Node* createDepthSetPanel(const osg::BoundingBox& extents); virtual osg::Node* createDepthSetPanel(const osg::BoundingBox& extents);
virtual osg::Node* createPanel(const osg::BoundingBox& extents, const osg::Vec4& colour); 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* 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 osg::Node* createIcon(const osg::BoundingBox& extents, const std::string& filename);
virtual void setupDialogStateSet(osg::StateSet* stateset); virtual void setupDialogStateSet(osg::StateSet* stateset);

View File

@ -41,14 +41,6 @@ bool Dialog::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event)
case(osgGA::GUIEventAdapter::KEYUP): case(osgGA::GUIEventAdapter::KEYUP):
OSG_NOTICE<<"Key pressed : "<<ea->getKey()<<std::endl; OSG_NOTICE<<"Key pressed : "<<ea->getKey()<<std::endl;
if (ea->getKey()=='c')
{
setVisible(false);
ea->setHandled(true);
return true;
}
break; break;
default: default:
break; break;
@ -75,6 +67,9 @@ void Dialog::createGraphicsImplementation()
osg::BoundingBox dialogWithTileExtents(_extents); osg::BoundingBox dialogWithTileExtents(_extents);
dialogWithTileExtents.expandBy(titleBarExents); 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()<<")"<<std::endl; 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::titleBarExents ("<<titleBarExents.xMin()<<", "<<titleBarExents.yMin()<<", "<<titleBarExents.zMin()<<"), ("<<titleBarExents.xMax()<<", "<<titleBarExents.yMax()<<", "<<titleBarExents.zMax()<<")"<<std::endl;
OSG_NOTICE<<"Dialog::dialogWithTileExtents ("<<dialogWithTileExtents.xMin()<<", "<<dialogWithTileExtents.yMin()<<", "<<dialogWithTileExtents.zMin()<<"), ("<<dialogWithTileExtents.xMax()<<", "<<dialogWithTileExtents.yMax()<<", "<<dialogWithTileExtents.zMax()<<")"<<std::endl; OSG_NOTICE<<"Dialog::dialogWithTileExtents ("<<dialogWithTileExtents.xMin()<<", "<<dialogWithTileExtents.yMin()<<", "<<dialogWithTileExtents.zMin()<<"), ("<<dialogWithTileExtents.xMax()<<", "<<dialogWithTileExtents.yMax()<<", "<<dialogWithTileExtents.zMax()<<")"<<std::endl;

View File

@ -77,11 +77,29 @@ void LineEdit::setText(const std::string& text)
void LineEdit::createGraphicsImplementation() void LineEdit::createGraphicsImplementation()
{ {
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get(); Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
osg::ref_ptr<Node> node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text);
osg::ref_ptr<osg::Group> 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> node = style->createText(extents, getAlignmentSettings(), getTextSettings(), _text);
_textDrawable = dynamic_cast<osgText::Text*>(node.get()); _textDrawable = dynamic_cast<osgText::Text*>(node.get());
_textDrawable->setDataVariance(osg::Object::DYNAMIC); _textDrawable->setDataVariance(osg::Object::DYNAMIC);
group->addChild(node.get());
style->setupClipStateSet(_extents, getOrCreateStateSet()); style->setupClipStateSet(_extents, getOrCreateStateSet());
setGraphicsSubgraph(0, _textDrawable.get()); setGraphicsSubgraph(0, group.get());
} }

View File

@ -74,6 +74,9 @@ void Popup::createGraphicsImplementation()
_transform->addChild( style->createPanel(_extents, dialogBackgroundColor) ); _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->setupDialogStateSet(getOrCreateStateSet());
style->setupClipStateSet(_extents, getOrCreateStateSet()); style->setupClipStateSet(_extents, getOrCreateStateSet());

View File

@ -81,15 +81,29 @@ void PushButton::createGraphicsImplementation()
float withFocus = 0.8; float withFocus = 0.8;
float pressed = 0.5; float pressed = 0.5;
_buttonSwitch->addChild(style->createPanel(_extents, osg::Vec4(unFocused, unFocused,unFocused, 1.0))); osg::Vec4 frameColor(0.75f,0.75f,0.75f,1.0f);
_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::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); _buttonSwitch->setSingleChildOn(0);
group->addChild(_buttonSwitch.get()); group->addChild(_buttonSwitch.get());
// create label. // create label.
osg::ref_ptr<Node> node = style->createText(_extents, getAlignmentSettings(), getTextSettings(), _text); osg::ref_ptr<Node> node = style->createText(extents, getAlignmentSettings(), getTextSettings(), _text);
_textDrawable = dynamic_cast<osgText::Text*>(node.get()); _textDrawable = dynamic_cast<osgText::Text*>(node.get());
_textDrawable->setDataVariance(osg::Object::DYNAMIC); _textDrawable->setDataVariance(osg::Object::DYNAMIC);

View File

@ -37,7 +37,7 @@ Style::Style()
_clipTexture = new osg::Texture2D; _clipTexture = new osg::Texture2D;
_clipTexture->setImage(image.get()); _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_S, osg::Texture::CLAMP_TO_BORDER);
_clipTexture->setWrap(osg::Texture::WRAP_T, 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::MIN_FILTER, osg::Texture::NEAREST);
@ -101,9 +101,119 @@ osg::Node* Style::createDepthSetPanel(const osg::BoundingBox& extents)
return geometry.release(); 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<osg::Geometry> 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<osg::Vec3Array> 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<osg::Vec4Array> colours = new osg::Vec4Array;
geometry->setColorArray(colours.get(), osg::Array::BIND_PER_PRIMITIVE_SET);
// bottom
{
colours->push_back(bottomColor);
osg::ref_ptr<osg::DrawElementsUShort> 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<osg::DrawElementsUShort> 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<osg::DrawElementsUShort> 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<osg::DrawElementsUShort> 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) osg::Node* Style::createText(const osg::BoundingBox& extents, const AlignmentSettings* as, const TextSettings* ts, const std::string& text)