osgEarth 2.1.1
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends

osgEarth::Util::Controls::Control Class Reference

Inheritance diagram for osgEarth::Util::Controls::Control:
Collaboration diagram for osgEarth::Util::Controls::Control:

List of all members.

Public Types

enum  Alignment {
  ALIGN_NONE, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT,
  ALIGN_TOP, ALIGN_BOTTOM
}
enum  Dock {
  DOCK_NONE, DOCK_LEFT, DOCK_RIGHT, DOCK_TOP,
  DOCK_BOTTOM, DOCK_FILL
}

Public Member Functions

 Control ()
void setX (float value)
const osgEarth::optional< float > & x () const
void clearX ()
void setY (float value)
const osgEarth::optional< float > & y () const
void clearY ()
void setPosition (float x, float y)
void setWidth (float value)
const osgEarth::optional< float > & width () const
void clearWidth ()
void setHeight (float value)
const osgEarth::optional< float > & height () const
void clearHeight ()
void setSize (float w, float h)
void setMargin (const Gutter &value)
const Guttermargin () const
void setPadding (const Gutter &value)
void setPadding (float globalValue)
const Gutterpadding () const
void setVertAlign (const Alignment &value)
const optional< Alignment > & vertAlign () const
void setHorizAlign (const Alignment &value)
const optional< Alignment > & horizAlign () const
void setHorizFill (bool value, float minWidth=0.0f)
bool horizFill () const
void setVertFill (bool value, float minHeight=0.0f)
const bool vertFill () const
void setVisible (bool value)
const bool visible () const
void setForeColor (const osg::Vec4f &value)
void setForeColor (float r, float g, float b, float a)
const osgEarth::optional
< osg::Vec4f > 
foreColor () const
void clearForeColor ()
void setBackColor (const osg::Vec4f &value)
void setBackColor (float r, float g, float b, float a)
const osgEarth::optional
< osg::Vec4f > & 
backColor () const
void clearBackColor ()
void setActiveColor (const osg::Vec4f &value)
void setActiveColor (float r, float g, float b, float a)
const osgEarth::optional
< osg::Vec4f > & 
activeColor () const
void clearActiveColor ()
bool getParent (osg::ref_ptr< Control > &out) const
void setActive (bool value)
bool getActive () const
void setAbsorbEvents (bool value)
bool getAbsorbEvents () const
void addEventHandler (ControlEventHandler *handler)
virtual void dirty ()
bool isDirty () const
virtual void calcSize (const ControlContext &context, osg::Vec2f &out_size)
virtual void calcFill (const ControlContext &context)
virtual void calcPos (const ControlContext &context, const osg::Vec2f &cursor, const osg::Vec2f &parentSize)
virtual void draw (const ControlContext &context, DrawableList &out_drawables)
const osg::Vec2f & renderPos () const
const osg::Vec2f & renderSize () const
bool intersects (float x, float y) const
void setParent (class Control *c)

Protected Member Functions

void align ()
virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, ControlContext &cx)

Protected Attributes

bool _dirty
osg::Vec2f _renderPos
osg::Vec2f _renderSize
ControlEventHandlerList _eventHandlers

Private Attributes

osgEarth::optional< float > _x
osgEarth::optional< float > _y
osgEarth::optional< float > _width
osgEarth::optional< float > _height
bool _hfill
bool _vfill
Gutter _margin
Gutter _padding
bool _visible
optional< Alignment_valign
optional< Alignment_halign
optional< osg::Vec4f > _backColor
optional< osg::Vec4f > _foreColor
optional< osg::Vec4f > _activeColor
osg::observer_ptr< Control_parent
bool _active
bool _absorbEvents
osg::ref_ptr< osg::Geometry > _geom

Friends

class ControlCanvas
class Container

Detailed Description

Base class for all controls. You can actually use a Control directly and it will just render as a rectangle.

Definition at line 126 of file Controls.


Member Enumeration Documentation

Enumerator:
ALIGN_NONE 
ALIGN_LEFT 
ALIGN_CENTER 
ALIGN_RIGHT 
ALIGN_TOP 
ALIGN_BOTTOM 

Definition at line 129 of file Controls.

Enumerator:
DOCK_NONE 
DOCK_LEFT 
DOCK_RIGHT 
DOCK_TOP 
DOCK_BOTTOM 
DOCK_FILL 

Definition at line 134 of file Controls.


Constructor & Destructor Documentation

Control::Control ( )

Definition at line 120 of file Controls.cpp.

                 :
_x(0), _y(0), _width(1), _height(1),
_margin( Gutter(0) ),
_padding( Gutter(2) ),
_visible( true ),
_valign( ALIGN_NONE ),
_halign( ALIGN_NONE ),
_backColor( osg::Vec4f(0,0,0,0) ),
_foreColor( osg::Vec4f(1,1,1,1) ),
_activeColor( osg::Vec4f(.4,.4,.4,1) ),
_active( false ),
_absorbEvents( false ),
_hfill( false ),
_vfill( false )
{
    //nop
}

Member Function Documentation

const osgEarth::optional<osg::Vec4f>& osgEarth::Util::Controls::Control::activeColor ( ) const [inline]

Definition at line 197 of file Controls.

{ return _activeColor; }
void Control::addEventHandler ( ControlEventHandler handler)

Definition at line 284 of file Controls.cpp.

{
    _eventHandlers.push_back( handler );
}

Here is the caller graph for this function:

void osgEarth::Util::Controls::Control::align ( ) [protected]
const osgEarth::optional<osg::Vec4f>& osgEarth::Util::Controls::Control::backColor ( ) const [inline]

Definition at line 192 of file Controls.

{ return _backColor; }

Here is the caller graph for this function:

virtual void osgEarth::Util::Controls::Control::calcFill ( const ControlContext context) [inline, virtual]

Reimplemented in osgEarth::Util::Controls::Container, osgEarth::Util::Controls::VBox, osgEarth::Util::Controls::HBox, and osgEarth::Util::Controls::Grid.

Definition at line 217 of file Controls.

{ }

Here is the caller graph for this function:

void Control::calcPos ( const ControlContext context,
const osg::Vec2f &  cursor,
const osg::Vec2f &  parentSize 
) [virtual]

Reimplemented in osgEarth::Util::Controls::Frame, osgEarth::Util::Controls::Container, osgEarth::Util::Controls::VBox, osgEarth::Util::Controls::HBox, and osgEarth::Util::Controls::Grid.

Definition at line 337 of file Controls.cpp.

{
    if ( _x.isSet() )
    {
        _renderPos.x() = cursor.x() + margin().left() + padding().left() + *x();
    }
    else
    {
        if ( _halign == ALIGN_CENTER )
        {
            _renderPos.x() = cursor.x() + 0.5*(parentSize.x() - _renderSize.x());
        }
        else if ( _halign == ALIGN_RIGHT )
        {
            _renderPos.x() = cursor.x() + parentSize.x() - margin().right() - _renderSize.x() + padding().left();
        }
        else
        {
            _renderPos.x() = cursor.x() + margin().left() + padding().left();
        }
    }

    if ( _y.isSet() )
    {
        _renderPos.y() = cursor.y() + margin().top() + padding().top() + *y();
    }
    else
    {
        if ( _valign == ALIGN_CENTER )
        {
            //_renderPos.y() = cursor.y() + 0.5*(parentSize.y() - _renderSize.y());
            _renderPos.y() = cursor.y() + 0.5*parentSize.y() - 0.5*(_renderSize.y() - padding().y());
        }
        else if ( _valign == ALIGN_BOTTOM )
        {
            _renderPos.y() = cursor.y() + parentSize.y() - margin().bottom() - _renderSize.y() + padding().top();
        }
        else
        {
            _renderPos.y() = cursor.y() + margin().top() + padding().top();
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::calcSize ( const ControlContext context,
osg::Vec2f &  out_size 
) [virtual]

Reimplemented in osgEarth::Util::Controls::LabelControl, osgEarth::Util::Controls::ImageControl, osgEarth::Util::Controls::Container, osgEarth::Util::Controls::VBox, osgEarth::Util::Controls::HBox, and osgEarth::Util::Controls::Grid.

Definition at line 318 of file Controls.cpp.

{
    if ( visible() == true )
    {
        _renderSize.set( 
            width().value()  + padding().x(),
            height().value() + padding().y() );

        out_size.set(
            _renderSize.x() + margin().x(),
            _renderSize.y() + margin().y() );
    }
    else
    {
        out_size.set(0,0);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void osgEarth::Util::Controls::Control::clearActiveColor ( ) [inline]

Definition at line 198 of file Controls.

void osgEarth::Util::Controls::Control::clearBackColor ( ) [inline]

Definition at line 193 of file Controls.

void osgEarth::Util::Controls::Control::clearForeColor ( ) [inline]

Definition at line 188 of file Controls.

void osgEarth::Util::Controls::Control::clearHeight ( ) [inline]

Definition at line 158 of file Controls.

{ _height.unset(); dirty(); }
void osgEarth::Util::Controls::Control::clearWidth ( ) [inline]

Definition at line 154 of file Controls.

{ _width.unset(); dirty(); }
void osgEarth::Util::Controls::Control::clearX ( ) [inline]

Definition at line 144 of file Controls.

{ _x.unset(); dirty(); }
void osgEarth::Util::Controls::Control::clearY ( ) [inline]

Definition at line 148 of file Controls.

{ _y.unset(); dirty(); }
void Control::dirty ( ) [virtual]

Definition at line 306 of file Controls.cpp.

{
    _dirty = true;
    osg::ref_ptr<Control> parent;
    if ( getParent( parent ) )
    {
        parent->dirty();
        parent.release();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::draw ( const ControlContext context,
DrawableList out_drawables 
) [virtual]

Reimplemented in osgEarth::Util::Controls::LabelControl, osgEarth::Util::Controls::ImageControl, osgEarth::Util::Controls::HSliderControl, osgEarth::Util::Controls::CheckBoxControl, osgEarth::Util::Controls::Frame, osgEarth::Util::Controls::RoundedFrame, osgEarth::Util::Controls::Container, osgEarth::Util::Controls::VBox, osgEarth::Util::Controls::HBox, and osgEarth::Util::Controls::Grid.

Definition at line 390 of file Controls.cpp.

{
    // by default, rendering a Control directly results in a colored quad. Usually however
    // you will not render a Control directly, but rather one of its subclasses.
    if ( visible() == true )
    {
        if ( !(_backColor.isSet() && _backColor->a() == 0) && _renderSize.x() > 0 && _renderSize.y() > 0 )
        {
            float vph = cx._vp->height(); // - padding().bottom();

            _geom = new osg::Geometry();

            float rx = _renderPos.x() - padding().left();
            float ry = _renderPos.y() - padding().top();

            osg::Vec3Array* verts = new osg::Vec3Array(4);
            _geom->setVertexArray( verts );
            (*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 );
            _geom->addPrimitiveSet( new osg::DrawArrays( GL_QUADS, 0, 4 ) );

            osg::Vec4Array* colors = new osg::Vec4Array(1);
            (*colors)[0] = _active && _activeColor.isSet() ? _activeColor.value() : _backColor.value();
            _geom->setColorArray( colors );
            _geom->setColorBinding( osg::Geometry::BIND_OVERALL );

            out.push_back( _geom.get() );
        }

        _dirty = false;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const osgEarth::optional<osg::Vec4f> osgEarth::Util::Controls::Control::foreColor ( ) const [inline]

Definition at line 187 of file Controls.

{ return _foreColor; }

Here is the caller graph for this function:

bool osgEarth::Util::Controls::Control::getAbsorbEvents ( ) const [inline]

Definition at line 206 of file Controls.

{ return _absorbEvents; }
bool osgEarth::Util::Controls::Control::getActive ( ) const [inline]

Definition at line 203 of file Controls.

{ return _active; }
bool Control::getParent ( osg::ref_ptr< Control > &  out) const

Definition at line 290 of file Controls.cpp.

{
    out = _parent.get();
    return out.valid();
}

Here is the caller graph for this function:

bool Control::handle ( const osgGA::GUIEventAdapter &  ea,
osgGA::GUIActionAdapter &  aa,
ControlContext cx 
) [protected, virtual]

Reimplemented in osgEarth::Util::Controls::HSliderControl, osgEarth::Util::Controls::CheckBoxControl, and osgEarth::Util::Controls::Container.

Definition at line 426 of file Controls.cpp.

{
    bool handled = false;    

    if ( _eventHandlers.size() > 0 )
    {    
        handled = true;

        if ( !_active )
        {
            if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE )
            {
                cx._active.push( this );
            }
        }
        else 
        {            
            if ( ea.getEventType() == osgGA::GUIEventAdapter::RELEASE )
            {
                for( ControlEventHandlerList::const_iterator i = _eventHandlers.begin(); i != _eventHandlers.end(); ++i )
                {
                    osg::Vec2f relXY( ea.getX() - _renderPos.x(), cx._vp->height() - ea.getY() - _renderPos.y() );
                    i->get()->onClick( this, relXY, ea.getButtonMask() );
                }
            }
        }
    }

    return handled || _absorbEvents;
}

Here is the caller graph for this function:

const osgEarth::optional<float>& osgEarth::Util::Controls::Control::height ( ) const [inline]

Definition at line 157 of file Controls.

{ return _height; }

Here is the caller graph for this function:

const optional<Alignment>& osgEarth::Util::Controls::Control::horizAlign ( ) const [inline]

Definition at line 174 of file Controls.

{ return _halign; }

Here is the caller graph for this function:

bool osgEarth::Util::Controls::Control::horizFill ( ) const [inline]

Definition at line 177 of file Controls.

{ return _hfill; }

Here is the caller graph for this function:

bool Control::intersects ( float  x,
float  y 
) const

Definition at line 382 of file Controls.cpp.

{
    return
        x >= _renderPos.x() - padding().left() && x <= _renderPos.x() - padding().left() + _renderSize.x() &&
        y >= _renderPos.y() - padding().top() && y <= _renderPos.y() - padding().top() + _renderSize.y();
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool osgEarth::Util::Controls::Control::isDirty ( ) const [inline]

Definition at line 214 of file Controls.

{ return _dirty; }

Here is the caller graph for this function:

const Gutter& osgEarth::Util::Controls::Control::margin ( ) const [inline]

Definition at line 163 of file Controls.

{ return _margin; }

Here is the caller graph for this function:

const Gutter& osgEarth::Util::Controls::Control::padding ( ) const [inline]

Definition at line 168 of file Controls.

{ return _padding; }

Here is the caller graph for this function:

const osg::Vec2f& osgEarth::Util::Controls::Control::renderPos ( ) const [inline]

Definition at line 222 of file Controls.

{ return _renderPos; }
const osg::Vec2f& osgEarth::Util::Controls::Control::renderSize ( ) const [inline]

Definition at line 223 of file Controls.

{ return _renderSize; }

Here is the caller graph for this function:

void osgEarth::Util::Controls::Control::setAbsorbEvents ( bool  value) [inline]

Definition at line 205 of file Controls.

{ _absorbEvents = value; }

Here is the caller graph for this function:

void Control::setActive ( bool  value)

Definition at line 297 of file Controls.cpp.

                               {
    if ( value != _active ) {
        _active = value;
        if ( _activeColor.isSet() )
            dirty();
    }
}

Here is the call graph for this function:

void Control::setActiveColor ( const osg::Vec4f &  value)

Definition at line 275 of file Controls.cpp.

                                               {
    if ( value != _activeColor.value() ) {
        _activeColor = value;
        if ( _active )
            dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void osgEarth::Util::Controls::Control::setActiveColor ( float  r,
float  g,
float  b,
float  a 
) [inline]

Definition at line 196 of file Controls.

{ setActiveColor( osg::Vec4f(r,g,b,a) ); }

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setBackColor ( const osg::Vec4f &  value)

Definition at line 267 of file Controls.cpp.

                                             {
    if ( value != _backColor.value() ) {
        _backColor = value;
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void osgEarth::Util::Controls::Control::setBackColor ( float  r,
float  g,
float  b,
float  a 
) [inline]

Definition at line 191 of file Controls.

{ setBackColor( osg::Vec4f(r,g,b,a) ); }

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setForeColor ( const osg::Vec4f &  value)

Definition at line 259 of file Controls.cpp.

                                             {
    if ( value != _foreColor.value() ) {
        _foreColor = value;
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void osgEarth::Util::Controls::Control::setForeColor ( float  r,
float  g,
float  b,
float  a 
) [inline]

Definition at line 186 of file Controls.

{ setForeColor( osg::Vec4f(r,g,b,a) ); }

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setHeight ( float  value)

Definition at line 177 of file Controls.cpp.

                                {
    if ( value != _height.value() ) {
        _height = value;
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setHorizAlign ( const Alignment value)

Definition at line 217 of file Controls.cpp.

                                               {
    if ( !_halign.isSetTo( value ) ) {
        _halign = value;
        _x.unset();  // horiz align is mutex with abs positioning
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setHorizFill ( bool  value,
float  minWidth = 0.0f 
)

Definition at line 235 of file Controls.cpp.

                                                  {
    if ( hfill != _hfill || !_width.isSetTo(minWidth) ) { //minWidth != _width.value() ) {
        _hfill = hfill;
        if ( hfill )
            setWidth( minWidth );
        else
            _width.unset();
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setMargin ( const Gutter value)

Definition at line 191 of file Controls.cpp.

                                        {
    if ( value != _margin ) {
        _margin = value;
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setPadding ( float  globalValue)

Definition at line 208 of file Controls.cpp.

                                 {
    Gutter g(value);
    if ( g != _padding ) {
        _padding = g;
        dirty();
    }
}

Here is the call graph for this function:

void Control::setPadding ( const Gutter value)

Definition at line 199 of file Controls.cpp.

{
    if ( value != _padding ) {
        _padding = value;
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void osgEarth::Util::Controls::Control::setParent ( class Control c) [inline]

Definition at line 228 of file Controls.

{ _parent = c; }

Here is the caller graph for this function:

void Control::setPosition ( float  x,
float  y 
)

Definition at line 163 of file Controls.cpp.

                                       {
    setX( x );
    setY( y );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setSize ( float  w,
float  h 
)

Definition at line 185 of file Controls.cpp.

                                   {
    setWidth( w );
    setHeight( h );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setVertAlign ( const Alignment value)

Definition at line 226 of file Controls.cpp.

                                              {
    if ( !_valign.isSetTo( value ) ) {
        _valign = value;
        _y.unset(); // vert align is mutex with abs positioning
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setVertFill ( bool  value,
float  minHeight = 0.0f 
)

Definition at line 247 of file Controls.cpp.

                                                  {
    if ( vfill != _hfill || minHeight != _height.value() ) {
        _vfill = vfill;
        if ( vfill )
            setHeight( minHeight );
        else
            _height.unset();
        dirty();
    }
}

Here is the call graph for this function:

void Control::setVisible ( bool  value)

Definition at line 139 of file Controls.cpp.

                                {
    if ( value != _visible ) {
        _visible = value;
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setWidth ( float  value)

Definition at line 169 of file Controls.cpp.

                               {
    if ( value != _width.value() ) {
        _width = value;
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setX ( float  value)

Definition at line 147 of file Controls.cpp.

                           {
    if ( value != _x.value() ) {
        _x = value;
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Control::setY ( float  value)

Definition at line 155 of file Controls.cpp.

                           {
    if ( value != _y.value() ) {
        _y = value;
        dirty();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const optional<Alignment>& osgEarth::Util::Controls::Control::vertAlign ( ) const [inline]

Definition at line 171 of file Controls.

{ return _valign; }

Here is the caller graph for this function:

const bool osgEarth::Util::Controls::Control::vertFill ( ) const [inline]

Definition at line 180 of file Controls.

{ return _vfill; }

Here is the caller graph for this function:

const bool osgEarth::Util::Controls::Control::visible ( ) const [inline]

Definition at line 183 of file Controls.

{ return _visible; }

Here is the caller graph for this function:

const osgEarth::optional<float>& osgEarth::Util::Controls::Control::width ( ) const [inline]

Definition at line 153 of file Controls.

{ return _width; }

Here is the caller graph for this function:

const osgEarth::optional<float>& osgEarth::Util::Controls::Control::x ( ) const [inline]

Definition at line 143 of file Controls.

{ return _x; }

Here is the caller graph for this function:

const osgEarth::optional<float>& osgEarth::Util::Controls::Control::y ( ) const [inline]

Definition at line 147 of file Controls.

{ return _y; }

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class Container [friend]

Definition at line 239 of file Controls.

friend class ControlCanvas [friend]

Definition at line 238 of file Controls.


Member Data Documentation

Definition at line 255 of file Controls.

Definition at line 254 of file Controls.

Definition at line 252 of file Controls.

Definition at line 252 of file Controls.

Definition at line 231 of file Controls.

Definition at line 243 of file Controls.

Definition at line 252 of file Controls.

osg::ref_ptr<osg::Geometry> osgEarth::Util::Controls::Control::_geom [private]

Reimplemented in osgEarth::Util::Controls::ImageControl.

Definition at line 256 of file Controls.

Definition at line 251 of file Controls.

Definition at line 246 of file Controls.

Definition at line 247 of file Controls.

Definition at line 248 of file Controls.

Definition at line 249 of file Controls.

Definition at line 253 of file Controls.

Definition at line 232 of file Controls.

Definition at line 233 of file Controls.

Definition at line 251 of file Controls.

Definition at line 247 of file Controls.

Definition at line 250 of file Controls.

Definition at line 246 of file Controls.

Definition at line 246 of file Controls.

Definition at line 246 of file Controls.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines