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

osgEarth::Util::Controls::ControlCanvas Class Reference

Collaboration diagram for osgEarth::Util::Controls::ControlCanvas:

List of all members.

Public Member Functions

void addControl (Control *control)
void removeControl (Control *control)
ControlgetControlAtMouse (float x, float y) const
void setAllowControlNodeOverlap (bool value)
void update (const osg::FrameStamp *frameStamp)
void setControlContext (const ControlContext &)
virtual void traverse (osg::NodeVisitor &nv)
virtual ~ControlCanvas ()
 ControlCanvas (osgViewer::View *view)

Static Public Member Functions

static ControlCanvasget (osg::View *view, bool installCanvasInSceneData=false)

Protected Attributes

ControlList _controls
GeodeTable _geodeTable
ControlContext _context
bool _contextDirty
osg::ref_ptr< ControlNodeBin_controlNodeBin

Private Types

typedef std::map< osg::View
*, ControlCanvas * > 
ViewCanvasMap

Private Member Functions

 ControlCanvas (osgViewer::View *view, bool registerCanvas)
void init (osgViewer::View *view, bool registerCanvas)
bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
ControlNodeBingetControlNodeBin ()

Static Private Attributes

static ViewCanvasMap _viewCanvasMap
static OpenThreads::Mutex _viewCanvasMapMutex

Friends

struct ControlCanvasEventHandler
class ControlNode

Detailed Description

Associates controls with an OSG View.

Definition at line 662 of file Controls.


Member Typedef Documentation

Definition at line 718 of file Controls.


Constructor & Destructor Documentation

ControlCanvas::~ControlCanvas ( ) [virtual]

Definition at line 2203 of file Controls.cpp.

{
    OpenThreads::ScopedLock<OpenThreads::Mutex> lock( _viewCanvasMapMutex );
    _viewCanvasMap.erase( _context._view );
}
ControlCanvas::ControlCanvas ( osgViewer::View *  view)

Constructs a new canvas and attaches it to a view. Call getOrCreateControlCanvas(view) to create one.

Definition at line 2154 of file Controls.cpp.

                                                  :
_contextDirty(true)
{
    init( view, true );
}

Here is the call graph for this function:

Here is the caller graph for this function:

ControlCanvas::ControlCanvas ( osgViewer::View *  view,
bool  registerCanvas 
) [private]

Definition at line 2160 of file Controls.cpp.

                                                                       :
_contextDirty( true )
{
    init( view, registerCanvas );
}

Here is the call graph for this function:


Member Function Documentation

void ControlCanvas::addControl ( Control control)

adds a top-level control to this surface.

Definition at line 2216 of file Controls.cpp.

{
    osg::Geode* geode = new osg::Geode();
    _geodeTable[control] = geode;
    addChild( geode );
    control->dirty();    
    _controls.push_back( control );
}

Here is the call graph for this function:

Here is the caller graph for this function:

ControlCanvas * ControlCanvas::get ( osg::View *  view,
bool  installCanvasInSceneData = false 
) [static]

Accesses the control canvas attached the the specified view.

Definition at line 2121 of file Controls.cpp.

{
    ControlCanvas* canvas = 0L;

    OpenThreads::ScopedLock<OpenThreads::Mutex> lock( _viewCanvasMapMutex );

    ViewCanvasMap::iterator i = _viewCanvasMap.find( view );
    if ( i != _viewCanvasMap.end() )
    {
        canvas = i->second;
    }

    else
    {
        // Not found, so create one. If requested, add a callback that will
        // automatically install it in the view's scene data during the 
        // next update traversal.
        osgViewer::View* view2 = dynamic_cast<osgViewer::View*>(view);
        if ( view2 )
        {
            canvas = new ControlCanvas( view2, false );
            _viewCanvasMap[view] = canvas;

            if ( installInSceneData )
                new CanvasInstaller( canvas, view->getCamera() );
        }
    }

    return canvas;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Control * ControlCanvas::getControlAtMouse ( float  x,
float  y 
) const

gets the top-most control that intersects the specified position.

Definition at line 2240 of file Controls.cpp.

{
    for( ControlList::const_iterator i = _controls.begin(); i != _controls.end(); ++i )
    {
        Control* control = i->get();
        if ( control->intersects( x, _context._vp->height() - y ) )
            return control;
    }
    return 0L;
}

Here is the call graph for this function:

ControlNodeBin* osgEarth::Util::Controls::ControlCanvas::getControlNodeBin ( ) [inline, private]

Accesses the priority rendering bin for this canvas.

Definition at line 723 of file Controls.

{ return _controlNodeBin.get(); }

Here is the caller graph for this function:

bool ControlCanvas::handle ( const osgGA::GUIEventAdapter &  ea,
osgGA::GUIActionAdapter &  aa 
) [private]

Definition at line 2252 of file Controls.cpp.

{
        for (ControlList::reverse_iterator i = _controls.rbegin(); i != _controls.rend(); ++i)
        {
                Control* control = i->get();
                if (control->isDirty())
                {
                        aa.requestRedraw();
                        break;
                }
        }

        bool handled = false;
    //Send a frame event to all controls
    if ( ea.getEventType() == osgGA::GUIEventAdapter::FRAME )
    {
        for( ControlList::const_reverse_iterator i = _controls.rbegin(); i != _controls.rend(); ++i )
        {
            i->get()->handle(ea, aa, _context);
        }
        return handled;
    }


    float invY = _context._vp->height() - ea.getY();

    for( ControlList::reverse_iterator i = _controls.rbegin(); i != _controls.rend(); ++i )
    {
        Control* control = i->get();
        if ( control->intersects( ea.getX(), invY ) )
        {
            handled = control->handle( ea, aa, _context );
            if ( handled )
                break;
        }
    }

    if ( _context._active.size() > 1 )
    {
        _context._active.front()->setActive( false );
        _context._active.pop();
    }

    if ( _context._active.size() > 0 )
    {
        bool hit = _context._active.front()->intersects( ea.getX(), invY );
        _context._active.front()->setActive( hit );
        if ( !hit )
            _context._active.pop();
    }

    return handled; //_context._active.size() > 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ControlCanvas::init ( osgViewer::View *  view,
bool  registerCanvas 
) [private]

Definition at line 2167 of file Controls.cpp.

{
    this->setDataVariance( osg::Object::DYNAMIC );

    view->addEventHandler( new ViewportHandler(this) );
    view->addEventHandler( new ControlCanvasEventHandler(this) );

    setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    setViewMatrix(osg::Matrix::identity());
    setClearMask(GL_DEPTH_BUFFER_BIT);
    setRenderOrder(osg::Camera::POST_RENDER); 
    setAllowEventFocus( true );
    
    // activate the update traversal
    ADJUST_UPDATE_TRAV_COUNT( this, 1 );

    osg::StateSet* ss = getOrCreateStateSet();
    ss->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE );
    ss->setMode( GL_BLEND, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
    ss->setAttributeAndModes( new osg::Depth( osg::Depth::LEQUAL, 0, 1, false ) );

    // this is necessary b/c osgText puts things in this bin too and we can't override that
    ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
    ss->setBinNumber(999999);

    _controlNodeBin = new ControlNodeBin();
    this->addChild( _controlNodeBin->getControlGroup() );

    // register this canvas.
    if ( registerCanvas )
    {
        OpenThreads::ScopedLock<OpenThreads::Mutex> lock( _viewCanvasMapMutex );
        _viewCanvasMap[view] = this;
    }
}

Here is the caller graph for this function:

void ControlCanvas::removeControl ( Control control)

removes a top-level control.

Definition at line 2226 of file Controls.cpp.

{
    GeodeTable::iterator i = _geodeTable.find( control );
    if ( i != _geodeTable.end() )
    {
         removeChild( i->second );
         _geodeTable.erase( i );
    }
    ControlList::iterator j = std::find( _controls.begin(), _controls.end(), control );
    if ( j != _controls.end() )
        _controls.erase( j );
}
void ControlCanvas::setAllowControlNodeOverlap ( bool  value)

Toggles whether ControlNodes are allowed to overlap.

Definition at line 2210 of file Controls.cpp.

Here is the call graph for this function:

void ControlCanvas::setControlContext ( const ControlContext cx)

Definition at line 2358 of file Controls.cpp.

{
    _context = cx;
    _contextDirty = true;
}

Here is the caller graph for this function:

void ControlCanvas::traverse ( osg::NodeVisitor &  nv) [virtual]

Definition at line 2347 of file Controls.cpp.

{
    if ( nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR )
    {
        update( nv.getFrameStamp() );
    }

    osg::Camera::traverse( nv );
}

Here is the call graph for this function:

void ControlCanvas::update ( const osg::FrameStamp *  frameStamp)

Definition at line 2307 of file Controls.cpp.

{
    _context._frameStamp = frameStamp;

    int bin = 0;
    for( ControlList::iterator i = _controls.begin(); i != _controls.end(); ++i )
    {
        Control* control = i->get();
        if ( control->isDirty() || _contextDirty )
        {
            osg::Vec2f size;
            control->calcSize( _context, size );
            control->calcFill( _context );

            osg::Vec2f surfaceSize( _context._vp->width(), _context._vp->height() );
            control->calcPos( _context, osg::Vec2f(0,0), surfaceSize );

            osg::Geode* geode = _geodeTable[control];
            geode->removeDrawables( 0, geode->getNumDrawables() );
            DrawableList drawables;
            control->draw( _context, drawables );

            for( DrawableList::iterator j = drawables.begin(); j != drawables.end(); ++j )
            {
                j->get()->setDataVariance( osg::Object::DYNAMIC );
                j->get()->getOrCreateStateSet()->setBinNumber( bin++ );
                geode->addDrawable( j->get() );
            }
        }
    }

    if ( _controlNodeBin.valid() )
    {
        _controlNodeBin->draw( _context, _contextDirty, bin );
    }

    _contextDirty = false;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend struct ControlCanvasEventHandler [friend]

Definition at line 709 of file Controls.

friend class ControlNode [friend]

Definition at line 710 of file Controls.


Member Data Documentation

Definition at line 703 of file Controls.

Definition at line 704 of file Controls.

Definition at line 706 of file Controls.

Definition at line 701 of file Controls.

Definition at line 702 of file Controls.

Definition at line 719 of file Controls.

OpenThreads::Mutex ControlCanvas::_viewCanvasMapMutex [static, private]

Definition at line 720 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