1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
19#include <osgText/Text>
24class OSGUI_EXPORT Item : public osg::Object
28 Item() : _color(1.0f,1.0f,1.0f,0.0f) {}
29 Item(const std::string& str) : _text(str), _color(1.0f,1.0f,1.0f,0.0f) {}
30 Item(const std::string& str, const osg::Vec4& col) : _text(str), _color(col) {}
31 Item(const osg::Vec4& col) : _color(col) {}
33 Item(const Item& item, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(item,copyop), _text(item._text), _color(item._color) {}
35 META_Object(osgUI, Item);
37 void setText(const std::string& text) { _text = text; }
38 std::string& getText() { return _text; }
39 const std::string& getText() const { return _text; }
41 void setColor(const osg::Vec4f& color) { _color = color; }
42 osg::Vec4f& getColor() { return _color; }
43 const osg::Vec4f& getColor() const { return _color; }
52class OSGUI_EXPORT ComboBox : public osgUI::Widget
56 ComboBox(const ComboBox& combobox, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
57 META_Node(osgUI, ComboBox);
59 void addItem(Item* item) { _items.push_back(item); dirty(); }
61 void setItem(unsigned int i, Item* item) { _items[i] = item; dirty(); }
62 Item* getItem(unsigned int i) { return _items[i].get(); }
63 const Item* getItem(unsigned int i) const { return _items[i].get(); }
65 void clear() { _items.clear(); dirty(); }
66 void removeItem(unsigned int i) { _items.erase(_items.begin()+i); dirty(); }
67 unsigned int getNumItems() { return static_cast<unsigned int>(_items.size()); }
69 typedef std::vector< osg::ref_ptr<Item> > Items;
71 void setItems(const Items& items) { _items = items; }
72 Items& getItems() { return _items; }
73 const Items& getItems() const { return _items; }
75 void setCurrentIndex(unsigned int i);
76 unsigned int getCurrentIndex() const { return _currentIndex; }
78 virtual void currrentIndexChanged(unsigned int i);
79 virtual void currentIndexChangedImplementation(unsigned int i);
82 virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
83 virtual void createGraphicsImplementation();
84 virtual void enterImplementation();
85 virtual void leaveImplementation();
88 virtual ~ComboBox() {}
91 unsigned int _currentIndex;
92 osg::Vec3d _popupItemOrigin;
93 osg::Vec3d _popupItemSize;
95 osg::ref_ptr<osg::Switch> _buttonSwitch;
96 osg::ref_ptr<osg::Switch> _backgroundSwitch;
97 osg::ref_ptr<osgUI::Popup> _popup;