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); }
// 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; }
void Window::_removeFromGeode(Widget* widget) { if(!widget) return; widget->_index = 0; _setParented(widget, true); _geode()->removeDrawable(widget); }
Window::Window(const std::string& name): _parent (0), _wm (0), _index (0), _x (0.0f), _y (0.0f), _z (0.0f), _zRange (0.0f), _strata (STRATA_NONE), _vis (VM_FULL), _r (0.0f), _s (1.0f), _scaleDenom (100.0f), _vAnchor (VA_NONE), _hAnchor (HA_NONE) { _name = name.size() ? name : generateRandomName("Window"); // TODO: Fix the "bg" name. osg::Geode* geode = new osg::Geode(); Widget* bg = new Widget(name + "bg", 0.0f, 0.0f); bg->setLayer(Widget::LAYER_BG); bg->setColor(1.0f, 1.0f, 1.0f, 1.0f); _setParented(bg); geode->addDrawable(bg); addChild(geode); setDataVariance(osg::Object::DYNAMIC); setEventMask(EVENT_ALL); getOrCreateStateSet()->setAttributeAndModes( new osg::Scissor(0, 0, 0, 0), osg::StateAttribute::ON ); }