|
osgEarth 2.1.1
|
Inheritance diagram for osgEarth::Util::Controls::ImageControl:
Collaboration diagram for osgEarth::Util::Controls::ImageControl:Public Member Functions | |
| ImageControl (osg::Image *image=0L) | |
| void | setImage (osg::Image *image) |
| osg::Image * | getImage () const |
| void | setRotation (const Angular &angle) |
| const Angular & | getRotation () const |
| void | setFixSizeForRotation (bool value) |
| bool | getFixSizeForRotation () const |
| virtual void | calcSize (const ControlContext &context, osg::Vec2f &out_size) |
| virtual void | draw (const ControlContext &cx, DrawableList &out) |
Private Attributes | |
| osg::ref_ptr< osg::Image > | _image |
| Angular | _rotation |
| bool | _fixSizeForRot |
| osg::Geometry * | _geom |
| ImageControl::ImageControl | ( | osg::Image * | image = 0L | ) |
Definition at line 607 of file Controls.cpp.
: _rotation( 0.0, Units::RADIANS ), _fixSizeForRot( false ) { setImage( image ); }
Here is the call graph for this function:| void ImageControl::calcSize | ( | const ControlContext & | context, |
| osg::Vec2f & | out_size | ||
| ) | [virtual] |
Reimplemented from osgEarth::Util::Controls::Control.
Definition at line 642 of file Controls.cpp.
{
if ( visible() == true )
{
_renderSize.set( 0, 0 );
//First try the explicit settings
if (width().isSet() && height().isSet())
{
_renderSize.set(width().value(), height().value());
}
//Second try the size of the image itself
else if (_image.valid())
{
_renderSize.set( _image->s(), _image->t() );
}
//Lastly just use the default values for width and height
else
{
_renderSize.set( width().value(), height().value());
}
//if there's a rotation angle, rotate
float rot = _fixSizeForRot ? osg::PI_4 : _rotation.as(Units::RADIANS);
if ( rot != 0.0f )
{
calculateRotatedSize(
_renderSize.x(), _renderSize.y(),
rot,
_renderSize.x(), _renderSize.y() );
}
out_size.set(
margin().left() + margin().right() + _renderSize.x(),
margin().top() + margin().bottom() + _renderSize.y() );
//_dirty = false;
}
else
{
out_size.set(0,0);
}
}
Here is the call graph for this function:| void ImageControl::draw | ( | const ControlContext & | cx, |
| DrawableList & | out | ||
| ) | [virtual] |
Reimplemented from osgEarth::Util::Controls::Control.
Reimplemented in osgEarth::Util::Controls::Frame, and osgEarth::Util::Controls::RoundedFrame.
Definition at line 689 of file Controls.cpp.
{
if ( visible() == true && _image.valid() )
{
//TODO: this is not precisely correct..images get deformed slightly..
osg::Geometry* g = new osg::Geometry();
float rx = osg::round( _renderPos.x() );
float ry = osg::round( _renderPos.y() );
float vph = cx._vp->height();
osg::Vec3Array* verts = new osg::Vec3Array(4);
g->setVertexArray( verts );
if ( _rotation.as(Units::RADIANS) != 0.0f || _fixSizeForRot == true )
{
osg::Vec2f rc( rx+_renderSize.x()/2, (vph-ry)-_renderSize.y()/2 );
float ra = osg::PI - _rotation.as(Units::RADIANS);
rx += 0.5*_renderSize.x() - 0.5*(float)_image->s();
ry += 0.5*_renderSize.y() - 0.5*(float)_image->t();
rot( rx, vph-ry, rc, ra, (*verts)[0] );
rot( rx, vph-ry-_image->t(), rc, ra, (*verts)[1] );
rot( rx+_image->s(), vph-ry-_image->t(), rc, ra, (*verts)[2] );
rot( rx+_image->s(), vph-ry, rc, ra, (*verts)[3] );
}
else
{
(*verts)[0].set( rx, vph - ry, 0 );
(*verts)[1].set( rx, vph - ry - _renderSize.y(), 0 );
(*verts)[2].set( rx + _renderSize.x(), vph - ry - _renderSize.y(), 0 );
(*verts)[3].set( rx + _renderSize.x(), vph - ry, 0 );
}
g->addPrimitiveSet( new osg::DrawArrays( GL_QUADS, 0, 4 ) );
osg::Vec4Array* c = new osg::Vec4Array(1);
(*c)[0] = osg::Vec4f(1,1,1,1);
g->setColorArray( c );
g->setColorBinding( osg::Geometry::BIND_OVERALL );
bool flip = _image->getOrigin()==osg::Image::TOP_LEFT;
osg::Vec2Array* t = new osg::Vec2Array(4);
#ifdef IMAGECONTROL_TEXRECT
(*t)[0].set( 0, flip? 0: _image->t()-1 );
(*t)[1].set( 0, flip? _image->t()-1: 0 );
(*t)[2].set( _image->s()-1, flip? _image->t()-1: 0 );
(*t)[3].set( _image->s()-1, flip? 0: _image->t()-1 );
osg::TextureRectangle* tex = new osg::TextureRectangle( _image.get() );
#else
(*t)[0].set( 0, flip? 0 : 1 );
(*t)[1].set( 0, flip? 1 : 0 );
(*t)[2].set( 1, flip? 1 : 0 );
(*t)[3].set( 1, flip? 0 : 1 );
osg::Texture2D* tex = new osg::Texture2D( _image.get() );
#endif
g->setTexCoordArray( 0, t );
tex->setResizeNonPowerOfTwoHint(false);
tex->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST );
tex->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
g->getOrCreateStateSet()->setTextureAttributeAndModes( 0, tex, osg::StateAttribute::ON );
osg::TexEnv* texenv = new osg::TexEnv( osg::TexEnv::MODULATE );
g->getStateSet()->setTextureAttributeAndModes( 0, texenv, osg::StateAttribute::ON );
#ifndef IMAGECONTROL_TEXRECT
osg::Program* program = new osg::Program();
program->addShader( new osg::Shader( osg::Shader::VERTEX, s_controlVertexShader ) );
program->addShader( new osg::Shader( osg::Shader::FRAGMENT, s_imageControlFragmentShader ) );
g->getStateSet()->setAttributeAndModes( program, osg::StateAttribute::ON );
#endif
out.push_back( g );
_dirty = false;
}
}
Here is the call graph for this function:| bool osgEarth::Util::Controls::ImageControl::getFixSizeForRotation | ( | ) | const [inline] |
Definition at line 320 of file Controls.
{ return _fixSizeForRot; }
| osg::Image* osgEarth::Util::Controls::ImageControl::getImage | ( | ) | const [inline] |
| const Angular& osgEarth::Util::Controls::ImageControl::getRotation | ( | ) | const [inline] |
| void ImageControl::setFixSizeForRotation | ( | bool | value | ) |
Tells the control to fix its minimum size to account to rotation. Otherwise the control will auto-size its width/height based on the rotation angle.
Definition at line 633 of file Controls.cpp.
{
if ( _fixSizeForRot != value ) {
_fixSizeForRot = value;
dirty();
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| void ImageControl::setImage | ( | osg::Image * | image | ) |
Definition at line 615 of file Controls.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:| void ImageControl::setRotation | ( | const Angular & | angle | ) |
Rotates the image.
Definition at line 624 of file Controls.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:bool osgEarth::Util::Controls::ImageControl::_fixSizeForRot [private] |
osg::Geometry* osgEarth::Util::Controls::ImageControl::_geom [private] |
Reimplemented from osgEarth::Util::Controls::Control.
osg::ref_ptr<osg::Image> osgEarth::Util::Controls::ImageControl::_image [private] |
1.7.3