Added support for ComboBox::currentIndexChanged*(uint) callback API.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14409 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -72,8 +72,12 @@ public:
|
||||
Items& getItems() { return _items; }
|
||||
const Items& getItems() const { return _items; }
|
||||
|
||||
void setCurrentItem(unsigned int i);
|
||||
unsigned int getCurrentItem() const { return _currentItem; }
|
||||
void setCurrentIndex(unsigned int i);
|
||||
unsigned int getCurrentIndex() const { return _currentIndex; }
|
||||
|
||||
virtual void currrentIndexChanged(unsigned int i);
|
||||
virtual void currentIndexChangedImplementation(unsigned int i);
|
||||
|
||||
|
||||
virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
|
||||
virtual void createGraphicsImplementation();
|
||||
@@ -84,7 +88,7 @@ protected:
|
||||
virtual ~ComboBox() {}
|
||||
|
||||
Items _items;
|
||||
unsigned int _currentItem;
|
||||
unsigned int _currentIndex;
|
||||
|
||||
osg::ref_ptr<osg::Switch> _buttonSwitch;
|
||||
osg::ref_ptr<osg::Switch> _backgroundSwitch;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
using namespace osgUI;
|
||||
|
||||
ComboBox::ComboBox():
|
||||
_currentItem(0)
|
||||
_currentIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ bool ComboBox::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event
|
||||
case(osgGA::GUIEventAdapter::SCROLL):
|
||||
if (ea->getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_DOWN)
|
||||
{
|
||||
if (getCurrentItem()<getNumItems()-1) setCurrentItem(getCurrentItem()+1);
|
||||
if (getCurrentIndex()<getNumItems()-1) setCurrentIndex(getCurrentIndex()+1);
|
||||
return true;
|
||||
}
|
||||
else if (ea->getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_UP)
|
||||
{
|
||||
if (getCurrentItem()>0) setCurrentItem(getCurrentItem()-1);
|
||||
if (getCurrentIndex()>0) setCurrentIndex(getCurrentIndex()-1);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -69,12 +69,12 @@ bool ComboBox::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
if (ea->getKey()==osgGA::GUIEventAdapter::KEY_Down)
|
||||
{
|
||||
if (getCurrentItem()<getNumItems()-1) setCurrentItem(getCurrentItem()+1);
|
||||
if (getCurrentIndex()<getNumItems()-1) setCurrentIndex(getCurrentIndex()+1);
|
||||
return true;
|
||||
}
|
||||
else if (ea->getKey()==osgGA::GUIEventAdapter::KEY_Up)
|
||||
{
|
||||
if (getCurrentItem()>0) setCurrentItem(getCurrentItem()-1);
|
||||
if (getCurrentIndex()>0) setCurrentIndex(getCurrentIndex()-1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ bool ComboBox::handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event
|
||||
if (index<_items.size())
|
||||
{
|
||||
OSG_NOTICE<<" index selected "<<index<<std::endl;
|
||||
setCurrentItem(index);
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -167,13 +167,39 @@ void ComboBox::leaveImplementation()
|
||||
if (_backgroundSwitch.valid()) _backgroundSwitch->setSingleChildOn(0);
|
||||
}
|
||||
|
||||
void ComboBox::setCurrentItem(unsigned int i)
|
||||
void ComboBox::setCurrentIndex(unsigned int i)
|
||||
{
|
||||
OSG_NOTICE << "ComboBox::setCurrentItem("<<i<<")"<<std::endl;
|
||||
_currentItem = i;
|
||||
if (_buttonSwitch.valid()) _buttonSwitch->setSingleChildOn(_currentItem);
|
||||
// OSG_NOTICE << "ComboBox::setCurrentIndex("<<i<<")"<<std::endl;
|
||||
if (_currentIndex==i) return;
|
||||
|
||||
_currentIndex = i;
|
||||
if (_buttonSwitch.valid()) _buttonSwitch->setSingleChildOn(_currentIndex);
|
||||
|
||||
currrentIndexChanged(_currentIndex);
|
||||
}
|
||||
|
||||
void ComboBox::currrentIndexChanged(unsigned int i)
|
||||
{
|
||||
osg::CallbackObject* co = getCallbackObject(this, "currentIndexChanged");
|
||||
if (co)
|
||||
{
|
||||
osg::Parameters inputParameters, outputParameters;
|
||||
inputParameters.push_back(new osg::UIntValueObject("index",i));
|
||||
if (co->run(this, inputParameters, outputParameters))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
currentIndexChangedImplementation(i);
|
||||
}
|
||||
|
||||
void ComboBox::currentIndexChangedImplementation(unsigned int i)
|
||||
{
|
||||
OSG_NOTICE<<"ComboBox::currentIndexChangedImplementation("<<i<<")"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ComboBox::createGraphicsImplementation()
|
||||
{
|
||||
Style* style = (getStyle()!=0) ? getStyle() : Style::instance().get();
|
||||
@@ -303,7 +329,7 @@ void ComboBox::createGraphicsImplementation()
|
||||
_buttonSwitch->addChild( style->createPanel(_extents, frameColor) );
|
||||
}
|
||||
|
||||
_buttonSwitch->setSingleChildOn(_currentItem);
|
||||
_buttonSwitch->setSingleChildOn(_currentIndex);
|
||||
|
||||
style->setupClipStateSet(_extents, getOrCreateStateSet());
|
||||
|
||||
|
||||
@@ -4,12 +4,35 @@
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
struct ComboBoxCurrentIndexChangedImplementation : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
if (inputParameters.empty()) return false;
|
||||
|
||||
osg::Object* indexObject = inputParameters[0].get();
|
||||
|
||||
unsigned int index = 0;
|
||||
osg::DoubleValueObject* dvo = dynamic_cast<osg::DoubleValueObject*>(indexObject);
|
||||
if (dvo) index = static_cast<unsigned int>(dvo->getValue());
|
||||
else
|
||||
{
|
||||
osg::UIntValueObject* uivo = dynamic_cast<osg::UIntValueObject*>(indexObject);
|
||||
if (uivo) index = uivo->getValue();
|
||||
}
|
||||
osgUI::ComboBox* cb = reinterpret_cast<osgUI::ComboBox*>(objectPtr);
|
||||
cb->currentIndexChangedImplementation(index);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( ComboBox,
|
||||
new osgUI::ComboBox,
|
||||
osgUI::ComboBox,
|
||||
"osg::Object osg::Node osg::Group osgUI::Widget osgUI::ComboBox" )
|
||||
{
|
||||
ADD_UINT_SERIALIZER(CurrentItem, 0);
|
||||
ADD_UINT_SERIALIZER(CurrentIndex, 0);
|
||||
ADD_VECTOR_SERIALIZER( Items, osgUI::ComboBox::Items, osgDB::BaseSerializer::RW_OBJECT, 0 );
|
||||
ADD_METHOD_OBJECT( "currentIndexChangedImplementation", ComboBoxCurrentIndexChangedImplementation );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user