2014-05-12 19:27:54 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osgUI/Style>
|
|
|
|
#include <osg/Geode>
|
2014-05-23 23:00:49 +08:00
|
|
|
#include <osg/Depth>
|
2014-05-24 02:59:16 +08:00
|
|
|
#include <osg/TexGen>
|
|
|
|
#include <osg/AlphaFunc>
|
2014-05-12 19:27:54 +08:00
|
|
|
#include <osgText/Text>
|
2014-05-24 02:59:16 +08:00
|
|
|
#include <osgDB/ReadFile>
|
2014-05-12 19:27:54 +08:00
|
|
|
|
|
|
|
using namespace osgUI;
|
|
|
|
|
|
|
|
osg::ref_ptr<Style>& Style::instance()
|
|
|
|
{
|
|
|
|
static osg::ref_ptr<Style> s_style = new Style;
|
|
|
|
return s_style;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSG_INIT_SINGLETON_PROXY(StyleSingletonProxy, Style::instance())
|
|
|
|
|
|
|
|
Style::Style()
|
|
|
|
{
|
2014-05-24 02:59:16 +08:00
|
|
|
osg::ref_ptr<osg::Image> image = new osg::Image;
|
|
|
|
image->allocateImage(1,1,1,GL_RGBA, GL_FLOAT);
|
|
|
|
*(reinterpret_cast<osg::Vec4f*>(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());
|
2014-05-12 19:27:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Style::Style(const Style& style, const osg::CopyOp& copyop):
|
2014-05-24 02:59:16 +08:00
|
|
|
osg::Object(style, copyop),
|
|
|
|
_clipTexture(style._clipTexture)
|
2014-05-12 19:27:54 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node* Style::createPanel(const osg::BoundingBox& extents, const osg::Vec4& colour)
|
|
|
|
{
|
2014-05-16 18:38:40 +08:00
|
|
|
OSG_NOTICE<<"Creating Panel"<<std::endl;
|
|
|
|
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
|
|
|
geometry->setVertexArray(vertices.get());
|
|
|
|
|
|
|
|
vertices->push_back( osg::Vec3(extents.xMin(), extents.yMin(), extents.zMin()) );
|
|
|
|
vertices->push_back( osg::Vec3(extents.xMin(), extents.yMax(), extents.zMin()) );
|
|
|
|
vertices->push_back( osg::Vec3(extents.xMax(), extents.yMin(), extents.zMin()) );
|
|
|
|
vertices->push_back( osg::Vec3(extents.xMax(), extents.yMax(), extents.zMin()) );
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Vec4Array> colours = new osg::Vec4Array;
|
|
|
|
geometry->setColorArray(colours, osg::Array::BIND_OVERALL);
|
|
|
|
|
|
|
|
colours->push_back( colour );
|
|
|
|
|
|
|
|
geometry->addPrimitiveSet( new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4) );
|
|
|
|
|
|
|
|
return geometry.release();
|
2014-05-12 19:27:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node* Style::createFrame(const osg::BoundingBox& extents, const FrameSettings* frameSettings)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node* Style::createText(const osg::BoundingBox& extents, const AlignmentSettings* as, const TextSettings* ts, const std::string& text)
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osgText::Text> textDrawable = new osgText::Text;
|
|
|
|
|
|
|
|
textDrawable->setText(text);
|
2014-05-16 18:38:40 +08:00
|
|
|
textDrawable->setPosition( osg::Vec3(extents.xMin(), extents.yMin(), extents.zMin()) );
|
2014-05-12 19:27:54 +08:00
|
|
|
|
2014-05-27 22:14:51 +08:00
|
|
|
|
|
|
|
textDrawable->setEnableDepthWrites(false);
|
|
|
|
|
2014-05-12 19:27:54 +08:00
|
|
|
if (ts)
|
|
|
|
{
|
|
|
|
textDrawable->setFont(ts->getFont());
|
|
|
|
textDrawable->setCharacterSize(ts->getCharacterSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (as)
|
|
|
|
{
|
|
|
|
osgText::TextBase::AlignmentType alignmentType = static_cast<osgText::TextBase::AlignmentType>(as->getAlignment());
|
|
|
|
textDrawable->setAlignment(alignmentType);
|
|
|
|
}
|
|
|
|
|
2014-05-16 18:38:40 +08:00
|
|
|
return textDrawable.release();
|
2014-05-12 19:27:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
osg::Node* Style::createIcon(const osg::BoundingBox& extents, const std::string& filename)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-23 23:00:49 +08:00
|
|
|
void Style::setupDialogStateSet(osg::StateSet* stateset)
|
|
|
|
{
|
|
|
|
stateset->setRenderBinDetails(5, "TraversalOrderBin", osg::StateSet::OVERRIDE_RENDERBIN_DETAILS);
|
|
|
|
stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
|
2014-05-24 02:59:16 +08:00
|
|
|
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<osg::TexGen> texgen = new osg::TexGen;
|
|
|
|
texgen->setPlanesFromMatrix(matrix);
|
|
|
|
texgen->setMode(osg::TexGen::OBJECT_LINEAR);
|
|
|
|
stateset->setTextureAttributeAndModes( clipTextureUnit, texgen.get(), osg::StateAttribute::ON);
|
2014-05-23 23:00:49 +08:00
|
|
|
}
|