osgEarth 2.1.1
|
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 Gutter & | margin () const |
void | setPadding (const Gutter &value) |
void | setPadding (float globalValue) |
const Gutter & | padding () 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 |
Base class for all controls. You can actually use a Control directly and it will just render as a rectangle.
Definition at line 134 of file Controls.
{ DOCK_NONE, DOCK_LEFT, DOCK_RIGHT, DOCK_TOP, DOCK_BOTTOM, DOCK_FILL };
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 }
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 ); }
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; }
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.
{ }
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(); } } }
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); } }
void osgEarth::Util::Controls::Control::clearActiveColor | ( | ) | [inline] |
Definition at line 198 of file Controls.
{ _activeColor.unset(); dirty(); }
void osgEarth::Util::Controls::Control::clearBackColor | ( | ) | [inline] |
Definition at line 193 of file Controls.
{ _backColor.unset(); dirty(); }
void osgEarth::Util::Controls::Control::clearForeColor | ( | ) | [inline] |
Definition at line 188 of file Controls.
{ _foreColor.unset(); dirty(); }
void osgEarth::Util::Controls::Control::clearHeight | ( | ) | [inline] |
void osgEarth::Util::Controls::Control::clearWidth | ( | ) | [inline] |
void osgEarth::Util::Controls::Control::clearX | ( | ) | [inline] |
void osgEarth::Util::Controls::Control::clearY | ( | ) | [inline] |
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(); } }
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; } }
const osgEarth::optional<osg::Vec4f> osgEarth::Util::Controls::Control::foreColor | ( | ) | const [inline] |
Definition at line 187 of file Controls.
{ return _foreColor; }
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] |
bool Control::getParent | ( | osg::ref_ptr< Control > & | out | ) | const |
Definition at line 290 of file Controls.cpp.
{ out = _parent.get(); return out.valid(); }
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; }
const osgEarth::optional<float>& osgEarth::Util::Controls::Control::height | ( | ) | const [inline] |
bool osgEarth::Util::Controls::Control::horizFill | ( | ) | const [inline] |
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(); }
bool osgEarth::Util::Controls::Control::isDirty | ( | ) | const [inline] |
const Gutter& osgEarth::Util::Controls::Control::margin | ( | ) | const [inline] |
const Gutter& osgEarth::Util::Controls::Control::padding | ( | ) | const [inline] |
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; }
void osgEarth::Util::Controls::Control::setAbsorbEvents | ( | bool | value | ) | [inline] |
Definition at line 205 of file Controls.
{ _absorbEvents = value; }
void Control::setActive | ( | bool | value | ) |
Definition at line 297 of file Controls.cpp.
{ if ( value != _active ) { _active = value; if ( _activeColor.isSet() ) dirty(); } }
void Control::setActiveColor | ( | const osg::Vec4f & | value | ) |
Definition at line 275 of file Controls.cpp.
{ if ( value != _activeColor.value() ) { _activeColor = value; if ( _active ) dirty(); } }
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) ); }
void Control::setBackColor | ( | const osg::Vec4f & | value | ) |
Definition at line 267 of file Controls.cpp.
{ if ( value != _backColor.value() ) { _backColor = value; dirty(); } }
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) ); }
void Control::setForeColor | ( | const osg::Vec4f & | value | ) |
Definition at line 259 of file Controls.cpp.
{ if ( value != _foreColor.value() ) { _foreColor = value; dirty(); } }
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) ); }
void Control::setHeight | ( | float | value | ) |
void Control::setHorizAlign | ( | const Alignment & | value | ) |
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(); } }
void Control::setMargin | ( | const Gutter & | value | ) |
Definition at line 191 of file Controls.cpp.
void Control::setPadding | ( | float | globalValue | ) |
void Control::setPadding | ( | const Gutter & | value | ) |
Definition at line 199 of file Controls.cpp.
void osgEarth::Util::Controls::Control::setParent | ( | class Control * | c | ) | [inline] |
void Control::setPosition | ( | float | x, |
float | y | ||
) |
void Control::setSize | ( | float | w, |
float | h | ||
) |
Definition at line 185 of file Controls.cpp.
void Control::setVertAlign | ( | const Alignment & | value | ) |
void Control::setVertFill | ( | bool | value, |
float | minHeight = 0.0f |
||
) |
void Control::setVisible | ( | bool | value | ) |
Definition at line 139 of file Controls.cpp.
void Control::setWidth | ( | float | value | ) |
void Control::setX | ( | float | value | ) |
void Control::setY | ( | float | value | ) |
const bool osgEarth::Util::Controls::Control::vertFill | ( | ) | const [inline] |
const bool osgEarth::Util::Controls::Control::visible | ( | ) | const [inline] |
const osgEarth::optional<float>& osgEarth::Util::Controls::Control::width | ( | ) | const [inline] |
const osgEarth::optional<float>& osgEarth::Util::Controls::Control::x | ( | ) | const [inline] |
const osgEarth::optional<float>& osgEarth::Util::Controls::Control::y | ( | ) | const [inline] |
friend class ControlCanvas [friend] |
bool osgEarth::Util::Controls::Control::_absorbEvents [private] |
bool osgEarth::Util::Controls::Control::_active [private] |
optional<osg::Vec4f> osgEarth::Util::Controls::Control::_activeColor [private] |
optional<osg::Vec4f> osgEarth::Util::Controls::Control::_backColor [private] |
bool osgEarth::Util::Controls::Control::_dirty [protected] |
optional<osg::Vec4f> osgEarth::Util::Controls::Control::_foreColor [private] |
osg::ref_ptr<osg::Geometry> osgEarth::Util::Controls::Control::_geom [private] |
Reimplemented in osgEarth::Util::Controls::ImageControl.
osgEarth::optional<float> osgEarth::Util::Controls::Control::_height [private] |
bool osgEarth::Util::Controls::Control::_hfill [private] |
osg::observer_ptr<Control> osgEarth::Util::Controls::Control::_parent [private] |
osg::Vec2f osgEarth::Util::Controls::Control::_renderPos [protected] |
osg::Vec2f osgEarth::Util::Controls::Control::_renderSize [protected] |
bool osgEarth::Util::Controls::Control::_vfill [private] |
bool osgEarth::Util::Controls::Control::_visible [private] |
osgEarth::optional<float> osgEarth::Util::Controls::Control::_width [private] |
osgEarth::optional<float> osgEarth::Util::Controls::Control::_x [private] |
osgEarth::optional<float> osgEarth::Util::Controls::Control::_y [private] |