From 189c0b3477dde88dd7fc65b78a3215895c10b381 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 29 May 2014 15:21:42 +0000 Subject: [PATCH] Futher work on ComboBox/Popup --- src/osgUI/ComboBox.cpp | 22 ++++++++++++---------- src/osgUI/Popup.cpp | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/osgUI/ComboBox.cpp b/src/osgUI/ComboBox.cpp index 237f3c115..2a0fbdfd6 100644 --- a/src/osgUI/ComboBox.cpp +++ b/src/osgUI/ComboBox.cpp @@ -68,6 +68,8 @@ bool ComboBox::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event break; case(osgGA::GUIEventAdapter::PUSH): OSG_NOTICE<<"Button pressed "<setVisible(!_popup->getVisible()); break; case(osgGA::GUIEventAdapter::RELEASE): OSG_NOTICE<<"Button release "<setVisible(true); + _popup->setVisible(false); if (!_items.empty()) { - float itemWidth = (_extents.xMax()-_extents.xMin()); - float itemHeight = (_extents.yMax()-_extents.yMin()); - float popupHeight = itemHeight * _items.size(); - float gap = (_extents.yMax()-_extents.yMin())*0.1f; - float popupTop = _extents.yMin()-gap; + float margin = (_extents.yMax()-_extents.yMin())*0.1f; + float itemWidth = (_extents.xMax()-_extents.xMin())-2.0f*margin; + float itemHeight = (_extents.yMax()-_extents.yMin())-margin; + float popupHeight = itemHeight * _items.size() + 2.0f*margin; + float popupTop = _extents.yMin()-margin; - osg::BoundingBox popupExtents(_extents.xMin(), popupTop-popupHeight, _extents.zMin(), _extents.xMin()+itemWidth, popupTop, _extents.zMax()); + osg::BoundingBox popupExtents(_extents.xMin(), popupTop-popupHeight, _extents.zMin(), _extents.xMin()+itemWidth+2*margin, popupTop, _extents.zMax()); _popup->setExtents(popupExtents); - osg::BoundingBox popupItemExtents(_extents.xMin(), popupTop-itemHeight, _extents.zMin(), _extents.xMin()+itemWidth, popupTop, _extents.zMax()); + osg::BoundingBox popupItemExtents(_extents.xMin()+margin, popupTop-margin-itemHeight, _extents.zMin(), _extents.xMin()+itemWidth, popupTop-margin, _extents.zMax()); for(Items::iterator itr = _items.begin(); itr != _items.end(); @@ -141,8 +143,8 @@ void ComboBox::createGraphicsImplementation() if (!item->getText().empty()) group->addChild( style->createText(popupItemExtents, getAlignmentSettings(), getTextSettings(), item->getText()) ); _popup->addChild(group.get()); - popupItemExtents.yMin() -= itemHeight; - popupItemExtents.yMax() -= itemHeight; + popupItemExtents.yMin() -= (itemHeight+margin); + popupItemExtents.yMax() -= (itemHeight+margin); } } diff --git a/src/osgUI/Popup.cpp b/src/osgUI/Popup.cpp index cf6af1604..6082968a3 100644 --- a/src/osgUI/Popup.cpp +++ b/src/osgUI/Popup.cpp @@ -61,7 +61,7 @@ bool Popup::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event) void Popup::leaveImplementation() { - setVisible(false); +// setVisible(false); } void Popup::createGraphicsImplementation()