Widget* Window::_getBackground() const { const osg::Geode* geode = _geode(); // lol... if(geode) return dynamic_cast<Widget*>(const_cast<osg::Drawable*>(geode->getDrawable(0))); return 0; }
unsigned int Window::addDrawableAndGetIndex(osg::Drawable* drawable) { osg::Geode* geode = _geode(); if(geode->addDrawable(drawable)) return geode->getDrawableIndex(drawable); // 0 is a valid error return code here, since our background widget should be // the first child. return 0; }
void Window::_removeFromGeode(Widget* widget) { if(!widget) return; widget->_index = 0; _setParented(widget, true); _geode()->removeDrawable(widget); }
// This is a somewhat complicated function designed to only be called by derived classes, // allowing them to insert Widgets (which can be added to the Window in any way the derived // class sees fit) into the REAL internal _objects container. // TODO: This doesn't handle insertion properly!!! bool Window::_setWidget(Widget* widget, int index) { if(!widget) { warn() << "Window [" << _name << "] called addWidget with NULL." << std::endl; return false; } if(widget->_parent) { warn() << "Window [" << _name << "] attempted to parent Widget [" << widget->getName() << "], which is already parented by [" << widget->_parent->getName() << "]." << std::endl ; return false; } if(index >= 0 && index >= static_cast<int>(size())) { warn() << "Window [" << _name << "] attempted to manually insert the Widget [" << widget->getName() << "] at position " << index << ", but there is not enough space available." << std::endl ; return false; } // If we're just appending another widget... if(index < 0) _objects.push_back(widget); // Otherwise, we're inserting and need to call removeWidget on the old // one (if valid)... else { if(_objects[index].valid()) _removeFromGeode(_objects[index].get()); _objects[index] = widget; } osg::Geode* geode = _geode(); widget->_index = geode->getNumDrawables(); geode->addDrawable(widget); _setParented(widget); _setManaged(widget); _setStyled(widget); // We make sure and resize after every added Widget. This ensures the most // accurate geometry... resize(); return true; }
Window::Window(const Window& window, const osg::CopyOp& co): MatrixTransform (window, co), EventInterface (window), StyleInterface (window), _parent (0), _wm (0), _index (0), _x (window._x), _y (window._y), _z (window._z), _zRange (window._zRange), _strata (window._strata), _vis (window._vis), _r (window._r), _s (window._s), _scaleDenom (window._scaleDenom), _width (window._width), _height (window._height), _vAnchor (window._vAnchor), _hAnchor (window._hAnchor), _visibleArea (window._visibleArea) { // Construct our vector of Widgets for easier use. :) // TODO: I almost certainly will need to use the getPosition() thing here eventually // for things to work 100% properly. For example, some Geodes may contain labels, // etc. Also, any widget that doesn't support simple addWidget probably won't // work (Table?) osg::Geode* geode = _geode(); Widget* bg = dynamic_cast<Widget*>(geode->getDrawable(0)); if(bg) { _setParented(bg); // TODO: This is silly... bg->setName(_name + "bg"); } for(unsigned int i = 1; i < geode->getNumDrawables(); i++) { Widget* widget = dynamic_cast<Widget*>(geode->getDrawable(i)); if(!widget) continue; // TODO: Properly test this... if(!widget->canClone()) { // geode->removeDrawable(widget); continue; } _setParented(widget); _objects.push_back(widget); } geode->setName(_name); }